Skip to content

Commit fd566bd

Browse files
mohamedzeidan2021Mohamed Zeidan
andauthored
Feature/js mlops telemetry (#5268)
* removed log statement * added telemetry for js and mlops * added for js estimator * fixed unit tests --------- Co-authored-by: Mohamed Zeidan <[email protected]>
1 parent 5bfa29b commit fd566bd

File tree

7 files changed

+35
-8
lines changed

7 files changed

+35
-8
lines changed

src/sagemaker/experiments/experiment.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
from sagemaker.experiments.trial import _Trial
2222
from sagemaker.experiments.trial_component import _TrialComponent
2323
from sagemaker.utils import format_tags
24+
from sagemaker.telemetry.telemetry_logging import _telemetry_emitter
25+
from sagemaker.telemetry.constants import Feature
2426

2527

2628
class Experiment(_base_types.Record):
@@ -93,6 +95,7 @@ def load(cls, experiment_name, sagemaker_session=None):
9395
)
9496

9597
@classmethod
98+
@_telemetry_emitter(feature=Feature.MLOPS, func_name="experiment.create")
9699
def create(
97100
cls,
98101
experiment_name,

src/sagemaker/jumpstart/estimator.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252

5353
from sagemaker.serverless.serverless_inference_config import ServerlessInferenceConfig
5454
from sagemaker.workflow.entities import PipelineVariable
55+
from sagemaker.telemetry.telemetry_logging import _telemetry_emitter
56+
from sagemaker.telemetry.constants import Feature
5557

5658

5759
class JumpStartEstimator(Estimator):
@@ -60,6 +62,7 @@ class JumpStartEstimator(Estimator):
6062
This class sets defaults based on the model ID and version.
6163
"""
6264

65+
@_telemetry_emitter(feature=Feature.JUMPSTART, func_name="jumpstart_estimator.create")
6366
def __init__(
6467
self,
6568
model_id: Optional[str] = None,
@@ -646,6 +649,7 @@ def _validate_model_id_and_get_type_hook():
646649

647650
super(JumpStartEstimator, self).__init__(**estimator_init_kwargs.to_kwargs_dict())
648651

652+
@_telemetry_emitter(feature=Feature.JUMPSTART, func_name="jumpstart_estimator.fit")
649653
def fit(
650654
self,
651655
inputs: Optional[Union[str, Dict, TrainingInput, FileSystemInput]] = None,
@@ -833,6 +837,7 @@ def attach(
833837
additional_kwargs=additional_kwargs,
834838
)
835839

840+
@_telemetry_emitter(feature=Feature.JUMPSTART, func_name="jumpstart_estimator.deploy")
836841
def deploy(
837842
self,
838843
initial_instance_count: Optional[int] = None,

src/sagemaker/jumpstart/model.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,17 @@
7676
from sagemaker.drift_check_baselines import DriftCheckBaselines
7777
from sagemaker.compute_resource_requirements.resource_requirements import ResourceRequirements
7878

79+
from sagemaker.telemetry.telemetry_logging import _telemetry_emitter
80+
from sagemaker.telemetry.constants import Feature
81+
7982

8083
class JumpStartModel(Model):
8184
"""JumpStartModel class.
8285
8386
This class sets defaults based on the model ID and version.
8487
"""
8588

89+
@_telemetry_emitter(feature=Feature.JUMPSTART, func_name="jumpstart_model.create")
8690
def __init__(
8791
self,
8892
model_id: Optional[str] = None,
@@ -639,6 +643,7 @@ def _create_sagemaker_model(
639643
**kwargs,
640644
)
641645

646+
@_telemetry_emitter(feature=Feature.JUMPSTART, func_name="jumpstart_model.deploy")
642647
def deploy(
643648
self,
644649
initial_instance_count: Optional[int] = None,

src/sagemaker/telemetry/constants.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ class Feature(Enum):
2828
MODEL_TRAINER = 4
2929
ESTIMATOR = 5
3030
HYPERPOD = 6 # Added to support telemetry in sagemaker-hyperpod-cli
31+
# Note: HyperPod CLI uses codes 6 and 7
32+
JUMPSTART = 8 # Added to support JumpStart telemetry
33+
MLOPS = 9 # Added to support MLOps telemetry
3134

3235
def __str__(self): # pylint: disable=E0307
3336
"""Return the feature name."""

src/sagemaker/telemetry/telemetry_logging.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@
5656
str(Feature.MODEL_TRAINER): 4,
5757
str(Feature.ESTIMATOR): 5,
5858
str(Feature.HYPERPOD): 6, # Added to support telemetry in sagemaker-hyperpod-cli
59+
# Note: HyperPod CLI uses codes 6 and 7
60+
str(Feature.JUMPSTART): 8,
61+
str(Feature.MLOPS): 9,
5962
}
6063

6164
STATUS_TO_CODE = {

src/sagemaker/workflow/pipeline.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@
6464
)
6565
from sagemaker.workflow.utilities import list_to_request
6666
from sagemaker.workflow._steps_compiler import StepsCompiler
67+
from sagemaker.telemetry.telemetry_logging import _telemetry_emitter
68+
from sagemaker.telemetry.constants import Feature
6769

6870
logger = logging.getLogger(__name__)
6971

@@ -134,6 +136,7 @@ def latest_pipeline_version_id(self):
134136
else:
135137
return summaries[0].get("PipelineVersionId")
136138

139+
@_telemetry_emitter(feature=Feature.MLOPS, func_name="pipeline.create")
137140
def create(
138141
self,
139142
role_arn: str = None,
@@ -342,6 +345,7 @@ def delete(self) -> Dict[str, Any]:
342345
)
343346
return self.sagemaker_session.sagemaker_client.delete_pipeline(PipelineName=self.name)
344347

348+
@_telemetry_emitter(feature=Feature.MLOPS, func_name="pipeline.start")
345349
def start(
346350
self,
347351
parameters: Dict[str, Union[str, bool, int, float]] = None,

tests/unit/sagemaker/jumpstart/estimator/test_sagemaker_config.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from sagemaker.config.config_schema import (
1919
MODEL_ENABLE_NETWORK_ISOLATION_PATH,
2020
MODEL_EXECUTION_ROLE_ARN_PATH,
21+
TELEMETRY_OPT_OUT_PATH,
2122
TRAINING_JOB_ENABLE_NETWORK_ISOLATION_PATH,
2223
TRAINING_JOB_INTER_CONTAINER_ENCRYPTION_PATH,
2324
TRAINING_JOB_ROLE_ARN_PATH,
@@ -75,6 +76,9 @@ def config_value_impl(sagemaker_session: Session, config_path: str, sagemaker_co
7576
if config_path == MODEL_ENABLE_NETWORK_ISOLATION_PATH:
7677
return config_inference_enable_network_isolation
7778

79+
if config_path == TELEMETRY_OPT_OUT_PATH:
80+
return False # Default to telemetry enabled for tests
81+
7882
raise AssertionError(f"Bad config path: {config_path}")
7983

8084

@@ -130,7 +134,7 @@ def test_without_arg_overwrites_without_kwarg_collisions_with_config(
130134

131135
estimator.deploy()
132136

133-
self.assertEqual(mock_get_sagemaker_config_value.call_count, 3)
137+
self.assertEqual(mock_get_sagemaker_config_value.call_count, 4)
134138

135139
self.assertEqual(mock_estimator_deploy.call_args[1].get("role"), config_inference_role)
136140

@@ -200,7 +204,7 @@ def test_without_arg_overwrites_with_kwarg_collisions_with_config(
200204

201205
estimator.deploy()
202206

203-
self.assertEqual(mock_get_sagemaker_config_value.call_count, 6)
207+
self.assertEqual(mock_get_sagemaker_config_value.call_count, 7)
204208

205209
self.assertEqual(mock_estimator_deploy.call_args[1].get("role"), config_inference_role)
206210

@@ -280,7 +284,7 @@ def test_with_arg_overwrites_with_kwarg_collisions_with_config(
280284
enable_network_isolation=override_inference_enable_network_isolation,
281285
)
282286

283-
self.assertEqual(mock_get_sagemaker_config_value.call_count, 3)
287+
self.assertEqual(mock_get_sagemaker_config_value.call_count, 4)
284288

285289
self.assertEqual(
286290
mock_estimator_deploy.call_args[1].get("role"), mock_inference_override_role
@@ -355,7 +359,7 @@ def test_with_arg_overwrites_without_kwarg_collisions_with_config(
355359
enable_network_isolation=override_inference_enable_network_isolation,
356360
)
357361

358-
self.assertEqual(mock_get_sagemaker_config_value.call_count, 3)
362+
self.assertEqual(mock_get_sagemaker_config_value.call_count, 4)
359363

360364
self.assertEqual(
361365
mock_estimator_deploy.call_args[1].get("role"), mock_inference_override_role
@@ -421,7 +425,7 @@ def test_without_arg_overwrites_without_kwarg_collisions_without_config(
421425

422426
mock_retrieve_model_init_kwargs.return_value = {}
423427

424-
self.assertEqual(mock_get_sagemaker_config_value.call_count, 3)
428+
self.assertEqual(mock_get_sagemaker_config_value.call_count, 4)
425429

426430
self.assertEqual(mock_estimator_deploy.call_args[1].get("role"), execution_role)
427431

@@ -492,7 +496,7 @@ def test_without_arg_overwrites_with_kwarg_collisions_without_config(
492496

493497
estimator.deploy()
494498

495-
self.assertEqual(mock_get_sagemaker_config_value.call_count, 6)
499+
self.assertEqual(mock_get_sagemaker_config_value.call_count, 7)
496500

497501
self.assertEqual(mock_estimator_deploy.call_args[1].get("role"), execution_role)
498502

@@ -568,7 +572,7 @@ def test_with_arg_overwrites_with_kwarg_collisions_without_config(
568572
enable_network_isolation=override_inference_enable_network_isolation,
569573
)
570574

571-
self.assertEqual(mock_get_sagemaker_config_value.call_count, 3)
575+
self.assertEqual(mock_get_sagemaker_config_value.call_count, 4)
572576

573577
self.assertEqual(mock_estimator_deploy.call_args[1].get("role"), override_inference_role)
574578

@@ -634,7 +638,7 @@ def test_with_arg_overwrites_without_kwarg_collisions_without_config(
634638
enable_network_isolation=override_enable_network_isolation,
635639
)
636640

637-
self.assertEqual(mock_get_sagemaker_config_value.call_count, 3)
641+
self.assertEqual(mock_get_sagemaker_config_value.call_count, 4)
638642

639643
self.assertEqual(mock_estimator_deploy.call_args[1].get("role"), override_inference_role)
640644

0 commit comments

Comments
 (0)