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

Sagemaker TensorFlow Estimator未加载requirements.txt依赖求助

解决建议

1. 清理冲突的依赖配置

你的requirements.txt存在多处问题,直接导致依赖安装失败:

  • 移除tensorflow==2.13.0:你指定的framework_version="1.15.2",SageMaker的TensorFlow容器已自带对应版本的TensorFlow,强制安装高版本会破坏容器环境,中断依赖安装流程。
  • 删除random:这是Python内置模块,无需通过pip安装,尝试安装不存在的包会导致pip报错。
  • 修正Keras版本:TF 1.15仅兼容Keras 2.3.x版本,将keras==2.13.1改为keras==2.3.1。

修改后的requirements.txt:

sagemaker==2.65.0
pandas==1.2.4
scikit-learn==0.23.1
awswrangler==2.12.1
boto3==1.19.1
numpy~=1.19.2
opencv-python
keras==2.3.1

2. 简化Estimator的依赖参数配置

TensorFlow Estimator无需同时配置多个依赖参数,重复配置会导致逻辑混乱,保留requirements_file即可:

  • 移除env中的SAGEMAKER_REQUIREMENTS配置。
  • dependencies仅用于传递额外代码文件,移除其中的requirements.txt。

修改后的Estimator代码:

from sagemaker.tensorflow.estimator import TensorFlow

keras_estimator = TensorFlow(
    entry_point=sm_script,
    role=workflow_execution_role,
    instance_count=1,
    instance_type=training_instance,
    dependencies=[sm_script],
    requirements_file='requirements.txt',
    sagemaker_session=sm_sess,
    framework_version="1.15.2",
    base_job_name='{}-training'.format(base_name),
    py_version="py3",
    distribution={"parameter_server": {"enabled": True}},
    metric_definitions=[
        {'Name': 'validation_accuracy', 'Regex': "Belt Vision accuracy = ([0-9.]+)"},
        {'Name': 'validation_f1', 'Regex': "Belt Vision f1 = ([0-9.]+)"}]
)

3. 验证文件路径正确性

确保requirements.txt与sm_script在本地工作目录下,若文件在子目录,需调整requirements_file的路径(比如source_dir='src'时,路径改为src/requirements.txt)。

4. 排查安装日志

若问题仍存在,去CloudWatch训练日志的/aws/sagemaker/TrainingJobs/[你的训练任务名]/algo-1路径下,查找包含pip install、ERROR的日志行,确认依赖安装失败的具体原因。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.15 15:12:53