简体   繁体   English

SageMaker 推理未找到模型 pkl

[英]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.

相关问题 在本地加载 Amazon Sagemaker NTM 模型以进行推理 - Load Amazon Sagemaker NTM model locally for inference Sagemaker 使用推理代码和要求部署模型 - Sagemaker deploy model with inference code and requirements 在 SageMaker 的处理过程中,在 source_dir 中使用 requirements.txt 重新打包推理 model 而无需安装它们 - Repack inference model with requirements.txt inside source_dir without installing them during the process in SageMaker 使用 Sagemaker 调用具有预训练自定义端点的调用超时 PyTorch model [推理] - Invocation timed out using Sagemaker to invoke endpoints with pretrained custom PyTorch model [Inference] 我想知道 Sagemaker 的 model.tar.gz 是否可以用于在另一个笔记本中进行推理? - I wonder if model.tar.gz from Sagemaker can be used for inference in another notebook? 如何在 SageMaker Inference 中返回所有标签和分数? - How to return all labels and scores in SageMaker Inference? AWS Sagemaker 推理端点未使用所有 vCPU - AWS Sagemaker inference endpoint not utilizing all vCPUs 使用 Blazingtext 预处理 Sagemaker 推理管道的数据 - Preprocessing data for Sagemaker Inference Pipeline with Blazingtext Sagemaker:部署时的弹性推理问题 - Sagemaker: Problem with elastic inference when deploying SageMaker 端点 AWS Lambda 推理问题 - SageMaker endpoint AWS Lambda inference Issue
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM