为了账号安全,请及时绑定邮箱和手机立即绑定

为 PyTorch 模型调用 SageMaker 端点

为 PyTorch 模型调用 SageMaker 端点

慕的地8271018 2023-04-25 17:31:10
我正在尝试从 Postman 和 AWS CLI 调用我的 SageMaker 模型终端节点。端点的状态是“服务中”,但每当我尝试调用它时,它都会给我一个错误。当我尝试在 SageMaker notebook 中使用预测函数并为其提供一个 numpy 数组(例如np.array([1,2,3,4]))时,它成功地为我提供了一个输出。我不确定我做错了什么。$ aws2 sagemaker-runtime invoke-endpoint \$ --endpoint-name=pytorch-model \$ --body=1,2 \$ --content-type=text/csv \$ --cli-binary-format=raw-in-base64-out \$ output.jsonAn 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 tensorsTraceback (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
查看完整描述

1 回答

?
萧十郎

TA贡献1815条经验 获得超12个赞

线索在堆栈跟踪的最后几行中:


  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

在第 268predict_fn行中pytorch-model-reco.py,您尝试将 用作input_data的索引final_matrix,但input_data类型错误。


我猜想当predict_fn输入类型为 时,您应该进行一些类型转换text/csv。当您的输入类型是 numpy 数据时,这种类型转换发生在外部predict_fn。


查看完整回答
反对 回复 2023-04-25
  • 1 回答
  • 0 关注
  • 99 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信