@@ -94,15 +94,38 @@ def wrapper(self, *args, **kwargs):
94
94
logger .info (TELEMETRY_OPT_OUT_MESSAGING )
95
95
response = None
96
96
caught_ex = None
97
-
97
+ status = "1"
98
+ failure_reason = None
99
+ failure_type = None
98
100
extra = f"{ func_name } "
99
101
102
+ start_timer = perf_counter ()
103
+ try :
104
+ response = func (self , * args , ** kwargs )
105
+ except (
106
+ ModelBuilderException ,
107
+ exceptions .CapacityError ,
108
+ exceptions .UnexpectedStatusException ,
109
+ exceptions .AsyncInferenceError ,
110
+ ) as e :
111
+ status = "0"
112
+ caught_ex = e
113
+ failure_reason = str (e )
114
+ failure_type = e .__class__ .__name__
115
+ except Exception as e : # pylint: disable=W0703
116
+ raise e
117
+
118
+ stop_timer = perf_counter ()
119
+ elapsed = stop_timer - start_timer
120
+
100
121
if self .model_server :
101
122
extra += f"&x-modelServer={ MODEL_SERVER_TO_CODE [str (self .model_server )]} "
102
123
103
124
if self .image_uri :
104
125
image_uri_tail = self .image_uri .split ("/" )[1 ]
105
- image_uri_option = _get_image_uri_option (self .image_uri , self ._is_custom_image_uri )
126
+ image_uri_option = _get_image_uri_option (
127
+ self .image_uri , getattr (self , "_is_custom_image_uri" , False )
128
+ )
106
129
107
130
if self .image_uri :
108
131
extra += f"&x-imageTag={ image_uri_tail } "
@@ -128,63 +151,36 @@ def wrapper(self, *args, **kwargs):
128
151
129
152
if getattr (self , "is_fine_tuned" , False ):
130
153
extra += "&x-fineTuned=1"
131
- if getattr (self , "is_gated" , False ):
132
- extra += "&x-gated=1"
133
154
134
- if kwargs . get ( "compilation_config" ):
155
+ if getattr ( self , "is_compiled" , False ):
135
156
extra += "&x-compiled=1"
136
- if kwargs . get ( "quantization_config" ):
157
+ if getattr ( self , "is_quantized" , False ):
137
158
extra += "&x-quantized=1"
138
- if kwargs .get ("speculative_decoding_config" ):
139
- model_provider = kwargs ["speculative_decoding_config" ]["ModelProvider" ]
159
+ if getattr (self , "speculative_decoding_draft_model_source" , False ):
140
160
model_provider_enum = (
141
161
SpeculativeDecodingDraftModelSource .SAGEMAKER
142
- if model_provider . lower () == "sagemaker"
162
+ if self . speculative_decoding_draft_model_source == "sagemaker"
143
163
else SpeculativeDecodingDraftModelSource .CUSTOM
144
164
)
145
165
model_provider_value = SD_DRAFT_MODEL_SOURCE_TO_CODE [str (model_provider_enum )]
146
166
extra += f"&x-sdDraftModelSource={ model_provider_value } "
147
167
148
- start_timer = perf_counter ()
149
- try :
150
- response = func (self , * args , ** kwargs )
151
- stop_timer = perf_counter ()
152
- elapsed = stop_timer - start_timer
153
- extra += f"&x-latency={ round (elapsed , 2 )} "
154
- if not self .serve_settings .telemetry_opt_out :
155
- _send_telemetry (
156
- "1" ,
157
- MODE_TO_CODE [str (self .mode )],
158
- self .sagemaker_session ,
159
- None ,
160
- None ,
161
- extra ,
162
- )
163
- except (
164
- ModelBuilderException ,
165
- exceptions .CapacityError ,
166
- exceptions .UnexpectedStatusException ,
167
- exceptions .AsyncInferenceError ,
168
- ) as e :
169
- stop_timer = perf_counter ()
170
- elapsed = stop_timer - start_timer
171
- extra += f"&x-latency={ round (elapsed , 2 )} "
172
- if not self .serve_settings .telemetry_opt_out :
173
- _send_telemetry (
174
- "0" ,
175
- MODE_TO_CODE [str (self .mode )],
176
- self .sagemaker_session ,
177
- str (e ),
178
- e .__class__ .__name__ ,
179
- extra ,
180
- )
181
- caught_ex = e
182
- except Exception as e : # pylint: disable=W0703
183
- caught_ex = e
184
- finally :
185
- if caught_ex :
186
- raise caught_ex
187
- return response # pylint: disable=W0150
168
+ extra += f"&x-latency={ round (elapsed , 2 )} "
169
+
170
+ if not self .serve_settings .telemetry_opt_out :
171
+ _send_telemetry (
172
+ status ,
173
+ MODE_TO_CODE [str (self .mode )],
174
+ self .sagemaker_session ,
175
+ failure_reason ,
176
+ failure_type ,
177
+ extra ,
178
+ )
179
+
180
+ if caught_ex :
181
+ raise caught_ex
182
+
183
+ return response
188
184
189
185
return wrapper
190
186
0 commit comments