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

使用XGBoost容器在SageMaker训练时触发TypeError故障求排查

问题根因

该TypeError完全来源于container变量的定义错误:

  • 定义container时你用逗号分隔了两个字符串,最终得到的是一个长度为2的元组,而非SageMaker Estimator构造参数要求的镜像URI字符串,这就是触发expected string or bytes-like object报错的直接原因
  • 额外问题:你填写的XGBoost镜像URI中存在多余空格,sagemaker- xgboost中间的空格会导致后续镜像拉取失败
修复方案

直接修改container变量的赋值语句即可,修复后的完整代码段如下:

# 去掉多余的区域字符串、删除镜像URI中的空格
container = '783357654285.dkr.ecr.ap-southeast-2.amazonaws.com/sagemaker-xgboost:latest'

train_input = TrainingInput(s3_data='s3://{}/train'.format(bucket, prefix), content_type='csv')
validation_input = TrainingInput(s3_data='s3://{}/validation/'.format(bucket, prefix), content_type='csv')

sess = sagemaker.Session()

xgb = sagemaker.estimator.Estimator(
container,
role, 
instance_count=1,
instance_type='ml.t2.medium',
output_path='s3://{}/output'.format(bucket, prefix),
sagemaker_session=sess
)

xgb.set_hyperparameters(
max_depth=5,
eta=0.1,
gamma=4,
min_child_weight=6,
subsample=0.8,
silent=0,
objective="binary:logistic",
num_round=25,
)

xgb.fit({"train": train_input, "validation": validation_input})

修改后重新运行代码,SageMaker Estimator可以正常读取镜像URI字符串,生成训练任务名称后即可正常发起训练。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.23 16:24:02