Hi folks, we’re trying to deploy an ASR model to sagemaker, but getting hung up on how to pass pipeline parameters to the endpoint when using DataSerializer
(as seems to be necessary).
For example, to deploy and call an ASR model (in this case HUBERT), we can do it as:
# create a serializer for the data
audio_serializer = DataSerializer(content_type='audio/x-audio') # using x-audio to support multiple audio formats
# deploy model to SageMaker Inference
predictor = huggingface_model.deploy(
initial_instance_count=1, # number of instances
instance_type='ml.m5.xlarge', # ec2 instance type
serializer=audio_serializer, # serializer for our audio data.
)
res = predictor.predict(data = "sample1.flac")
print(res)
{'text': "GOING ALONG SLUSHY COUNTRY ROADS AND SPEAKING TO DAMP AUDIENCES IN DRAUGHTY SCHOOLROOMS DAY AFTER DAY FOR A FORTNIGHT HE'LL HAVE TO PUT IN AN APPEARANCE AT SOME PLACE OF WORSHIP ON SUNDAY MORNING AND HE CAN COME TO US IMMEDIATELY AFTERWARDS"}
So far so good, but in our case we’re dealing with longer audio files, and need to be able to pass the chunk_length_s
and stride_length_s
parameters.
If you’re not using a serializer, it appears to be as simple as e.g.
payload = {"inputs": input, "parameters": params}
response = sagemaker_runtime.invoke_endpoint(
EndpointName=endpoint_name,
ContentType='application/json',
Body=json.dumps(payload)
)
But because we’re using a serializer, we have to pass e.g. predictor.predict(data = "sample1.flac")
and this does not seem to provide a way to include pipeline parameters like we need?
For example, if we try:
payload = {
"inputs": "sample1.flac",
"parameters": {
"chunk_length_s" : 5
}
}
res = predictor.predict(payload)
We receive error message ValueError: Object of type <class 'dict'> is not Data serializable
. This makes sense since DataSerializer expects a file path or raw bytes.
So, how do we solve this? How do we correctly pass audio data into the sagemaker endpoint but also include pipeline parameters like chunk_length_s
and stride_length_s
so that the model operates correctly?
Perhaps @philschmid or @marshmellow77 would be willing to chime in?
Help!