2020 _construct_url ,
2121)
2222from sagemaker .serve .utils .exceptions import ModelBuilderException , LocalModelOutOfMemoryException
23+ from sagemaker .utils import pysdk_version
2324
2425MOCK_SESSION = Mock ()
2526MOCK_FUNC_NAME = "Mock.deploy"
3233)
3334MOCK_HUGGINGFACE_ID = "meta-llama/Llama-2-7b-hf"
3435MOCK_EXCEPTION = LocalModelOutOfMemoryException ("mock raise ex" )
36+ MOCK_ENDPOINT_ARN = (
37+ "arn:aws:sagemaker:us-west-2:123456789012:endpoint/huggingface-pytorch-tgi-inference-2024-02-06"
38+ "-04-06-23-819"
39+ )
3540
3641
3742class ModelBuilderMock :
@@ -72,14 +77,17 @@ def test_capture_telemetry_decorator_djl_success(self, mock_send_telemetry):
7277 mock_model_builder .model = MOCK_HUGGINGFACE_ID
7378 mock_model_builder .mode = Mode .LOCAL_CONTAINER
7479 mock_model_builder .model_server = ModelServer .DJL_SERVING
80+ mock_model_builder .sagemaker_session .endpoint_arn = MOCK_ENDPOINT_ARN
7581
7682 mock_model_builder .mock_deploy ()
7783
7884 expected_extra_str = (
7985 f"{ MOCK_FUNC_NAME } "
8086 "&x-modelServer=4"
8187 "&x-imageTag=djl-inference:0.25.0-deepspeed0.11.0-cu118"
88+ f"&x-pySdkVersion={ pysdk_version ()} "
8289 f"&x-modelName={ MOCK_HUGGINGFACE_ID } "
90+ f"&x-endpointArn={ MOCK_ENDPOINT_ARN } "
8391 )
8492 mock_send_telemetry .assert_called_once_with (
8593 "1" , 2 , MOCK_SESSION , None , None , expected_extra_str
@@ -93,14 +101,17 @@ def test_capture_telemetry_decorator_tgi_success(self, mock_send_telemetry):
93101 mock_model_builder .model = MOCK_HUGGINGFACE_ID
94102 mock_model_builder .mode = Mode .LOCAL_CONTAINER
95103 mock_model_builder .model_server = ModelServer .TGI
104+ mock_model_builder .sagemaker_session .endpoint_arn = MOCK_ENDPOINT_ARN
96105
97106 mock_model_builder .mock_deploy ()
98107
99108 expected_extra_str = (
100109 f"{ MOCK_FUNC_NAME } "
101110 "&x-modelServer=6"
102111 "&x-imageTag=huggingface-pytorch-inference:2.0.0-transformers4.28.1-cpu-py310-ubuntu20.04"
112+ f"&x-pySdkVersion={ pysdk_version ()} "
103113 f"&x-modelName={ MOCK_HUGGINGFACE_ID } "
114+ f"&x-endpointArn={ MOCK_ENDPOINT_ARN } "
104115 )
105116 mock_send_telemetry .assert_called_once_with (
106117 "1" , 2 , MOCK_SESSION , None , None , expected_extra_str
@@ -126,6 +137,7 @@ def test_capture_telemetry_decorator_handle_exception_success(self, mock_send_te
126137 mock_model_builder .model = MOCK_HUGGINGFACE_ID
127138 mock_model_builder .mode = Mode .LOCAL_CONTAINER
128139 mock_model_builder .model_server = ModelServer .DJL_SERVING
140+ mock_model_builder .sagemaker_session .endpoint_arn = MOCK_ENDPOINT_ARN
129141
130142 mock_exception = Mock ()
131143 mock_exception_obj = MOCK_EXCEPTION
@@ -138,7 +150,9 @@ def test_capture_telemetry_decorator_handle_exception_success(self, mock_send_te
138150 f"{ MOCK_FUNC_NAME } "
139151 "&x-modelServer=4"
140152 "&x-imageTag=djl-inference:0.25.0-deepspeed0.11.0-cu118"
153+ f"&x-pySdkVersion={ pysdk_version ()} "
141154 f"&x-modelName={ MOCK_HUGGINGFACE_ID } "
155+ f"&x-endpointArn={ MOCK_ENDPOINT_ARN } "
142156 )
143157 mock_send_telemetry .assert_called_once_with (
144158 "0" ,
0 commit comments