Add support for JSON encoding torch.tensor
to keep it consistent with sagemaker-inference-toolkit
#84
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
With
HuggingFaceModel
:mms.service.PredictionException: Object of type Tensor is not JSON serializable : 400
With
PyTorchModel
: Works fineBy submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.