You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Sagemaker部署PyTorch模型调用predict时遇SSL协议错误求助

Sagemaker部署PyTorch模型后调用推理触发SSL验证失败错误

部署预训练PyTorch模型到Sagemaker Notebook环境后,执行response = predictor.predict(serialized_data)调用推理时,遇到如下SSL错误:

SSLError: SSL validation failed for https://runtime.sagemaker.us-east-1.amazonaws.com/endpoints/pytorch-inference-2024-06-11-13-39-50-210/invocations EOF occurred in violation of protocol (_ssl.c:2426)

预期行为

未部署模型时,直接从S3桶加载权重,执行以下代码可正常得到推理结果:

input_data = (interaction_data, mt_data)
results = predict_fn(input_data, model)

输出示例:Iteration at 0: auc 0.964, map 0.439

当前情况

模型定义与部署步骤均正常完成:

pytorch_model = PyTorchModel(model_data=f's3://{model_bucket}/{model_key}', 
                             role=role, 
                             entry_point='inference.py', 
                             framework_version='1.8.1', 
                             py_version='py3', 
                             sagemaker_session=sagemaker_session)
predictor = pytorch_model.deploy(instance_type='ml.m5.large', initial_instance_count=1)

但调用predictor.predict(serialized_data)时触发上述SSL错误。

复现步骤

  • 定义数据路径:
    interaction_data = "s3://path_to_pkl/interaction.pkl"
    auxiliary_data = "s3://path_to_pkl/auxiliary.pkl"
    
  • 定义模型存储桶:
    model_bucket = 'path_to_model_bucket'
    model_key = 'Model-Structure/model.tar.gz'
    
  • 处理数据:
    with open("interaction.pkl", 'rb') as f:
        data1 = CPU_Unpickler(f).load()
    with open("auxiliary.pkl", 'rb') as f:
        data2= CPU_Unpickler(f).load()
    serialized_data = pickle.dumps({ 'data1': data1, 'data2': data2 })
    
  • 定义并部署模型:
    pytorch_model = PyTorchModel(model_data=f's3://{model_bucket}/{model_key}', 
                                 role=role, 
                                 entry_point='inference.py', 
                                 framework_version='1.8.1', 
                                 py_version='py3', 
                                 sagemaker_session=sagemaker_session)
    predictor = pytorch_model.deploy(instance_type='ml.m5.large', initial_instance_count=1)
    
  • 调用推理:
    response = predictor.predict(serialized_data)
    

已使用Sagemaker环境通用的inference.py文件进行模型评估和响应获取。


内容的提问来源于stack exchange,提问作者Dhruv Shah

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.22 10:53:24