[英]Model pkl not found by SageMaker inference
I have the following model.tar.gz structure (as described here ):我有以下 model.tar.gz 结构(如此处所述):
model
|- cuts34.pkl
|- code
|- inference.py
|- requirements.txt
I deploy locally my trained model (for inference) like this:我在本地部署我训练过的模型(用于推理),如下所示:
class Predictor(RealTimePredictor):
def __init__(self, endpoint_name, sagemaker_session):
super().__init__(endpoint_name,
sagemaker_session=sagemaker_session,
serializer=None,
deserializer=None,
content_type='text/plain'
)
entry_point = './model/code/inference.py'
model_data = 'model.tar.gz'
model = PyTorchModel(model_data=model_data,
framework_version="1.5.0",
py_version="py3",
role=role,
entry_point=entry_point
)
serverless_config = ServerlessInferenceConfig()
predictor = model.deploy(instance_type="local", initial_instance_count=1)
model_fn
in inference.py
looks like this: inference.py
中的model_fn
如下所示:
def model_fn(model_dir):
logger.info("*** Loading the model ...")
path = os.path.join(model_dir, "cuts34.pkl")
learner = load_learner(path)
return learner
When invoking the sagemaker.local.LocalSagemakerRuntimeClient()
with当调用
sagemaker.local.LocalSagemakerRuntimeClient()
时
response = runtime.invoke_endpoint(
EndpointName=endpoint_name,
ContentType=content_type,
Body=payload
)
I keep getting the following error:我不断收到以下错误:
b'[Errno 2] No such file or directory: \'/.sagemaker/mms/models/model/cuts34.pkl\'\nTraceback (most recent call last):\n File "/opt/conda/lib/python3.6/site-packages/sagemaker_inference/transformer.py", line 110, in transform\n self.validate_and_initialize(model_dir=model_dir)\n File "/opt/conda/lib/python3.6/site-packages/sagemaker_inference/transformer.py", line 158, in validate_and_initialize\n self._model = self._model_fn(model_dir)\n File "/opt/ml/model/code/inference.py", line 265, in model_fn\n learner = torch.load(path, map_location=device)\n File "/opt/conda/lib/python3.6/site-packages/torch/serialization.py", line 584, in load\n with _open_file_like(f, \'rb\') as opened_file:\n File "/opt/conda/lib/python3.6/site-packages/torch/serialization.py", line 234, in _open_file_like\n return _open_file(name_or_buffer, mode)\n File "/opt/conda/lib/python3.6/site-packages/torch/serialization.py", line 215, in __init__\n super(_open_file, self).__init__(open(name, mode))\nFileNotFoundError: [Errno 2] No such file or directory: \'/.sagemaker/mms/models/model/cuts34.pkl\'\n'
It seems that the model pkl cannot be found.似乎找不到模型 pkl。 Any thoughts on why not?
关于为什么不的任何想法?
Kindly confirm your model tar ball structure is inline with the documentation here .请确认您的模型 tar 球结构与此处的文档一致。
Ie No parent model
directory.即没有父
model
目录。
I would also suggest making use of ls
commands in your inference script to see where the files are located when debugging.我还建议在推理脚本中使用
ls
命令来查看调试时文件的位置。
print(os.system("ls"))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.