in src/sagemaker_huggingface_inference_toolkit/handler_service.py [0:0]
def transform_fn(self, model, input_data, content_type, accept, context=None):
"""
Transform function ("transform_fn") can be used to write one function with pre/post-processing steps and predict step in it.
This fuction can't be mixed with "input_fn", "output_fn" or "predict_fn".
Args:
model: Model returned by the model_fn above
input_data: Data received for inference
content_type: The content type of the inference data
accept: The response accept type.
context (obj): metadata on the incoming request data (default: None).
Returns: Response in the "accept" format type.
"""
# run pipeline
start_time = time.time()
processed_data = self.preprocess(*([input_data, content_type] + self.preprocess_extra_arg))
preprocess_time = time.time() - start_time
predictions = self.predict(*([processed_data, model] + self.predict_extra_arg))
predict_time = time.time() - preprocess_time - start_time
response = self.postprocess(*([predictions, accept] + self.postprocess_extra_arg))
postprocess_time = time.time() - predict_time - preprocess_time - start_time
logger.info(
f"Preprocess time - {preprocess_time * 1000} ms\n"
f"Predict time - {predict_time * 1000} ms\n"
f"Postprocess time - {postprocess_time * 1000} ms"
)
return response