簡體   English   中英

為 PyTorch Model 調用 SageMaker 端點

[英]Invoking SageMaker Endpoint for PyTorch Model

我正在嘗試從 Postman 和 AWS CLI 調用我的 SageMaker model 端點。 端點的狀態是“服務中”,但每當我嘗試調用它時,它都會給我一個錯誤。 當我嘗試在 SageMaker 筆記本中使用預測 function 並為其提供一個 numpy 數組(例如np.array([1,2,3,4]) )時,它成功地為我提供了一個 output。我不確定我是什么做錯了

$ aws2 sagemaker-runtime invoke-endpoint \
$ --endpoint-name=pytorch-model \
$ --body=1,2 \
$ --content-type=text/csv \
$ --cli-binary-format=raw-in-base64-out \
$ output.json

An error occurred (ModelError) when calling the InvokeEndpoint operation: Received server error (500) from model with message "tensors used as indices must be long, byte or bool tensors
Traceback (most recent call last):
  File "/opt/conda/lib/python3.6/site-packages/sagemaker_inference/transformer.py", line 125, in transform
    result = self._transform_fn(self._model, input_data, content_type, accept)
  File "/opt/conda/lib/python3.6/site-packages/sagemaker_inference/transformer.py", line 215, in _default_transform_fn
    prediction = self._predict_fn(data, model)
  File "/opt/ml/model/code/pytorch-model-reco.py", line 268, in predict_fn
    return torch.argsort(- final_matrix[input_data, :], dim = 1)
IndexError: tensors used as indices must be long, byte or bool tensors

線索在堆棧跟蹤的最后幾行中:

  File "/opt/ml/model/code/pytorch-model-reco.py", line 268, in predict_fn
    return torch.argsort(- final_matrix[input_data, :], dim = 1)
IndexError: tensors used as indices must be long, byte or bool tensors

在第 268 行的predict_fn中的pytorch-model-reco.py中,您嘗試使用input_data作為final_matrix的索引,但input_data是錯誤的類型。

我猜想當輸入類型為text/csv時,您的predict_fn應該進行某種類型轉換。 當您的輸入類型是predict_fn數據時,這種類型轉換發生在 predict_fn 之外。 查看sagemaker_inference源代碼可能會揭示更多信息。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM