ModelTrainer generates sm_train.sh with CRLF line endings on Windows causing training job failure
维护者通常 2 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 1/5
- 预计耗时
- 1 小时以内
- 新手友好度
- 88/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 冷清
- 技术栈
- aws, python
调研方向
打开 model_trainer.py,检查写入 sm_train.sh 的 _prepare_train_script 方法。确认生成的脚本在 Windows 上使用 LF 换行符,然后运行相关的 ModelTrainer 检查,或复现 Windows 生成路径,以确认该脚本可以在 Linux 容器中执行。
由索引模型根据 Issue 内容生成。
描述
PySDK Version
- PySDK V3 (3.x)
Describe the bug
When using ModelTrainer with SourceCode on Windows, the SDK internally generates sm_train.sh with CRLF (\r\n) line endings. This causes the training job to fail immediately when the Linux container tries to execute it.
The root cause is in model_trainer.py in the _prepare_train_script method:
with open(os.path.join(tmp_dir.name, TRAIN_SCRIPT), "w") as f:
f.write(train_script)
To reproduce
from sagemaker.train import ModelTrainer
from sagemaker.train.configs import SourceCode, Compute, InputData, OutputDataConfig
source_code = SourceCode(
source_dir="src",
entry_script="train.py",
requirements="requirements.txt"
)
compute = Compute(
instance_type="ml.m5.xlarge",
instance_count=1
)
model_trainer = ModelTrainer(
training_image="",
role="",
source_code=source_code,
compute=compute,
)
train_data = InputData(channel_name="train", data_source="s3://bucket/train/")
val_data = InputData(channel_name="validation", data_source="s3://bucket/val/")
model_trainer.train(input_data_config=[train_data, val_data], wait=True)
Expected behavior
sm_train.sh should always be written with LF (\n) line endings regardless of the host OS, since it will always be executed inside a Linux container.
Error in CloudWatch Logs
/opt/ml/input/data/sm_drivers/sm_train.sh: line 1: $'\r': command not found
/opt/ml/input/data/sm_drivers/sm_train.sh: line 3: set: -#015: invalid option
set: usage: set [-abefhkmnptuvxBCHP] [-o option-name] [--] [arg ...]
/opt/ml/input/data/sm_drivers/sm_train.sh: line 6: syntax error near unexpected token $'{\r'' /opt/ml/input/data/sm_drivers/sm_train.sh: line 6: handle_error() {#015'
Proposed Fix
Current code (line in _prepare_train_script):
with open(os.path.join(tmp_dir.name, TRAIN_SCRIPT), "w") as f:
Fix — force LF line endings:
with open(os.path.join(tmp_dir.name, TRAIN_SCRIPT), "w", newline="\n") as f:
System information
A description of your system. Please provide:
- SageMaker Python SDK version:3.x
- **Framework name or algorithm **:XgBoost
- Framework version:1.7-1
- Python version:3.11.5
- CPU or GPU:CPU (ml.m5.xlarge)
- Custom Docker image (Y/N):N
Additional context
This issue affects all Windows users of the new ModelTrainer API (PySDK V3). The sm_train.sh file is generated entirely by the SDK on the client machine and is never touched by the user, making it impossible to fix without either patching the SDK or switching to the older Estimator API. The fix is a single-character change adding newline="\n" to the open() call.
- 主要语言
- Python
- 星标
- 2.3k
- 派生
- 1.3k
- 平均合并
- 3 天 4 小时
- 30 天内合并 PR
- 70
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
aws/sagemaker-python-sdk 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
aws/sagemaker-python-sdk#6253 ·
维护者通常 2 天内回复
-
难度 1/5 1 小时以内 新手友好度 93/100
aws/sagemaker-python-sdk#6232 ·
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
aws/sagemaker-python-sdk#6156 · 2 条评论 ·
维护者通常 2 天内回复
-
难度 2/5 半天 新手友好度 72/100
aws/sagemaker-python-sdk#6152 ·
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
aws/sagemaker-python-sdk#5897 ·
维护者通常 2 天内回复
查看 aws/sagemaker-python-sdk 的全部 Issue
相似的 Issue
-
adr
难度 2/5 1-3 小时 新手友好度 72/100
kristofdegrave/homeassistant-smart-charging#1607 ·
维护者通常 1 天内回复
-
namespace operations
难度 2/5 1-3 小时 新手友好度 64/100
EclipseFdn/open-vsx.org#13665 ·
维护者通常 1 天内回复
-
doc good first issue help wanted
难度 2/5 1-3 小时 新手友好度 68/100
collective/icalendar#1865 · 2 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
canonical/opentelemetry-collector-operator#409 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 85/100
mozilla/addons-release-tests#1243 ·
维护者通常 1 天内回复