繁体   English   中英

SageMaker 推理未找到模型 pkl

[英]Model pkl not found by SageMaker inference

我有以下 model.tar.gz 结构(如此所述):

model
|- cuts34.pkl
|- code
  |- inference.py
  |- requirements.txt

我在本地部署我训练过的模型(用于推理),如下所示:

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)

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

当调用sagemaker.local.LocalSagemakerRuntimeClient()

response = runtime.invoke_endpoint(
    EndpointName=endpoint_name,
    ContentType=content_type,
    Body=payload
)

我不断收到以下错误:

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'

似乎找不到模型 pkl。 关于为什么不的任何想法?

请确认您的模型 tar 球结构与此处的文档一致。

即没有父model目录。

我还建议在推理脚本中使用ls命令来查看调试时文件的位置。

print(os.system("ls"))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM