我已在 S3 存储桶中上传了变压器 roberta 模型。我现在尝试使用 Pytorch 和 SageMaker Python SDK 对模型进行推理。我指定了模型目录s3://snet101/sent.tar.gz,它是模型 (pytorch_model.bin) 及其所有依赖项的压缩文件。这是代码
model = PyTorchModel(model_data=model_artifact,
name=name_from_base('roberta-model'),
role=role,
entry_point='torchserve-predictor2.py',
source_dir='source_dir',
framework_version='1.4.0',
py_version = 'py3',
predictor_cls=SentimentAnalysis)
predictor = model.deploy(initial_instance_count = 1, instance_type = 'ml.m4.xlarge')
test_data = {"text": "How many cows are in the farm ?"}
prediction = predictor.predict(test_data)
Run Code Online (Sandbox Code Playgroud)
我在预测器对象的预测方法上收到以下错误:
ModelError Traceback (most recent call last)
<ipython-input-6-bc621eb2e056> in <module>
----> 1 prediction = predictor.predict(test_data)
~/anaconda3/envs/python3/lib/python3.6/site-packages/sagemaker/predictor.py in predict(self, data, initial_args, target_model, target_variant)
123
124 request_args = self._create_request_args(data, initial_args, target_model, target_variant)
--> …Run Code Online (Sandbox Code Playgroud)