Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for JSON encoding torch.tensor to keep it consistent with sagemaker-inference-toolkit #84

Merged
merged 2 commits into from
May 10, 2023

Conversation

maaquib
Copy link
Contributor

@maaquib maaquib commented May 8, 2023

Diff in encoding logic:

Sagemaker base toolkit: https://github.com/aws/sagemaker-inference-toolkit/blob/e602335fd9a4db08216d1f58ded2861cccb64f7d/src/sagemaker_inference/encoder.py#L25_L44
HF inference toolkit: https://github.com/aws/sagemaker-huggingface-inference-toolkit/blob/27275f40a2bbff85bb507646e6a3ef866d0599af/src/sagemaker_huggingface_inference_toolkit/decoder_encoder.py#L80_L114

This is similar to JSON encoding of numpy data.

Issue #, if available: N/A

Description of changes:
Inference script:

...
def predict_fn(input_data, model):
    return [torch.tensor(42)]
...

With HuggingFaceModel: mms.service.PredictionException: Object of type Tensor is not JSON serializable : 400
With PyTorchModel: Works fine

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Copy link
Collaborator

@philschmid philschmid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for adding!

Copy link
Contributor

@davidthomas426 davidthomas426 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@maaquib maaquib merged commit 02ba035 into aws:main May 10, 2023
@maaquib maaquib deleted the decoder branch May 10, 2023 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants