-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding INF2 (transformers-neuronx) compilation latencies to SageMaker…
… Health Metrics (#1185) Co-authored-by: Tyler Osterberg <[email protected]>
- Loading branch information
1 parent
182ae0e
commit 1da14b1
Showing
6 changed files
with
134 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/usr/bin/env python | ||
# | ||
# Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file | ||
# except in compliance with the License. A copy of the License is located at | ||
# | ||
# http://aws.amazon.com/apache2.0/ | ||
# | ||
# or in the "LICENSE.txt" file accompanying this file. This file is distributed on an "AS IS" | ||
# BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, express or implied. See the License for | ||
# the specific language governing permissions and limitations under the License. | ||
|
||
|
||
import copy | ||
from collections import defaultdict | ||
from djl_python import __version__ | ||
import logging | ||
|
||
|
||
# https://docs.aws.amazon.com/deep-learning-containers/latest/devguide/logging-and-monitoring.html | ||
class SMLogFilter(logging.Filter): | ||
sm_log_markers = ['ModelServerError', 'UserScriptError', 'SysHealth'] | ||
counter = defaultdict(int) | ||
|
||
def filter(self, record): | ||
try: | ||
if isinstance(record.msg, str): | ||
for i in self.sm_log_markers: | ||
if record.msg.startswith(i+':'): | ||
altered_record = copy.deepcopy(record) | ||
tag, metric_name, metric = [i.strip() for i in altered_record.msg.split(':')] | ||
value, units = metric.split(' ') | ||
altered_metric_name = ''.join([word[0].upper()+word[1:] for word in metric_name.split(' ')]) | ||
altered_record.msg = f"{tag}.Count:{self.count(altered_metric_name)}|#DJLServing:{__version__},{altered_metric_name}:{value} {units}" | ||
return altered_record | ||
return False | ||
else: | ||
return False | ||
except Exception as exc: | ||
logging.warning(f"Forwarding {str(record)} failed due to {str(exc)}") | ||
return False | ||
|
||
def count(self, key): | ||
self.counter[key] += 1 | ||
return self.counter[key] |
43 changes: 43 additions & 0 deletions
43
engines/python/setup/djl_python/tests/test_sm_log_filter.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import unittest | ||
from unittest.mock import MagicMock | ||
from djl_python.sm_log_filter import SMLogFilter | ||
import logging | ||
|
||
|
||
class TestSMLogFilter(unittest.TestCase): | ||
|
||
def test_filter_hit(self): | ||
filter = SMLogFilter() | ||
|
||
record = MagicMock() | ||
record.msg = f"SysHealth: LLM sharding and compilation latency: 845.62 secs" | ||
actual = filter.filter(record).msg | ||
expected = "SysHealth.Count:1|#DJLServing:0.24.0,LLMShardingAndCompilationLatency:845.62 secs" | ||
self.assertEqual(actual.split('|')[0], expected.split('|')[0]) | ||
self.assertEqual(actual.split(':')[1], expected.split(':')[1]) | ||
self.assertEqual(actual.split(',')[1], expected.split(',')[1]) | ||
|
||
record = MagicMock() | ||
record.msg = f"SysHealth: LLM sharding and compilation latency: 845.62 secs" | ||
actual = filter.filter(record).msg | ||
expected = "SysHealth.Count:2|#DJLServing:0.24.0,LLMShardingAndCompilationLatency:845.62 secs" | ||
self.assertEqual(actual.split('|')[0], expected.split('|')[0]) | ||
self.assertEqual(actual.split(':')[1], expected.split(':')[1]) | ||
self.assertEqual(actual.split(',')[1], expected.split(',')[1]) | ||
|
||
def test_filter_warning(self): | ||
filter = SMLogFilter() | ||
record = MagicMock() | ||
record.msg = f"SysHealth: LLM sharding and compilation latency: 845.62 : secs" | ||
actual = filter.filter(record) | ||
|
||
with self.assertLogs(level=logging.WARNING): | ||
filter.filter(record) | ||
|
||
def test_filter_miss(self): | ||
filter = SMLogFilter() | ||
record = MagicMock() | ||
record.msg = f"LLM sharding and compilation latency: 845.62 : secs" | ||
actual = filter.filter(record) | ||
self.assertFalse(actual) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters