20
20
_construct_url ,
21
21
)
22
22
from sagemaker .serve .utils .exceptions import ModelBuilderException , LocalModelOutOfMemoryException
23
+ from sagemaker .utils import pysdk_version
23
24
24
25
MOCK_SESSION = Mock ()
25
26
MOCK_FUNC_NAME = "Mock.deploy"
32
33
)
33
34
MOCK_HUGGINGFACE_ID = "meta-llama/Llama-2-7b-hf"
34
35
MOCK_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
+ )
35
40
36
41
37
42
class ModelBuilderMock :
@@ -72,14 +77,17 @@ def test_capture_telemetry_decorator_djl_success(self, mock_send_telemetry):
72
77
mock_model_builder .model = MOCK_HUGGINGFACE_ID
73
78
mock_model_builder .mode = Mode .LOCAL_CONTAINER
74
79
mock_model_builder .model_server = ModelServer .DJL_SERVING
80
+ mock_model_builder .sagemaker_session .endpoint_arn = MOCK_ENDPOINT_ARN
75
81
76
82
mock_model_builder .mock_deploy ()
77
83
78
84
expected_extra_str = (
79
85
f"{ MOCK_FUNC_NAME } "
80
86
"&x-modelServer=4"
81
87
"&x-imageTag=djl-inference:0.25.0-deepspeed0.11.0-cu118"
88
+ f"&x-pySdkVersion={ pysdk_version ()} "
82
89
f"&x-modelName={ MOCK_HUGGINGFACE_ID } "
90
+ f"&x-endpointArn={ MOCK_ENDPOINT_ARN } "
83
91
)
84
92
mock_send_telemetry .assert_called_once_with (
85
93
"1" , 2 , MOCK_SESSION , None , None , expected_extra_str
@@ -93,14 +101,17 @@ def test_capture_telemetry_decorator_tgi_success(self, mock_send_telemetry):
93
101
mock_model_builder .model = MOCK_HUGGINGFACE_ID
94
102
mock_model_builder .mode = Mode .LOCAL_CONTAINER
95
103
mock_model_builder .model_server = ModelServer .TGI
104
+ mock_model_builder .sagemaker_session .endpoint_arn = MOCK_ENDPOINT_ARN
96
105
97
106
mock_model_builder .mock_deploy ()
98
107
99
108
expected_extra_str = (
100
109
f"{ MOCK_FUNC_NAME } "
101
110
"&x-modelServer=6"
102
111
"&x-imageTag=huggingface-pytorch-inference:2.0.0-transformers4.28.1-cpu-py310-ubuntu20.04"
112
+ f"&x-pySdkVersion={ pysdk_version ()} "
103
113
f"&x-modelName={ MOCK_HUGGINGFACE_ID } "
114
+ f"&x-endpointArn={ MOCK_ENDPOINT_ARN } "
104
115
)
105
116
mock_send_telemetry .assert_called_once_with (
106
117
"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
126
137
mock_model_builder .model = MOCK_HUGGINGFACE_ID
127
138
mock_model_builder .mode = Mode .LOCAL_CONTAINER
128
139
mock_model_builder .model_server = ModelServer .DJL_SERVING
140
+ mock_model_builder .sagemaker_session .endpoint_arn = MOCK_ENDPOINT_ARN
129
141
130
142
mock_exception = Mock ()
131
143
mock_exception_obj = MOCK_EXCEPTION
@@ -138,7 +150,9 @@ def test_capture_telemetry_decorator_handle_exception_success(self, mock_send_te
138
150
f"{ MOCK_FUNC_NAME } "
139
151
"&x-modelServer=4"
140
152
"&x-imageTag=djl-inference:0.25.0-deepspeed0.11.0-cu118"
153
+ f"&x-pySdkVersion={ pysdk_version ()} "
141
154
f"&x-modelName={ MOCK_HUGGINGFACE_ID } "
155
+ f"&x-endpointArn={ MOCK_ENDPOINT_ARN } "
142
156
)
143
157
mock_send_telemetry .assert_called_once_with (
144
158
"0" ,
0 commit comments