ModelTrainer generates sm_train.sh with CRLF line endings on Windows causing training job failure
Maintainer thường phản hồi trong vòng 2 ngày
@MohammedAlkindi đang làm issue này rồi.
Từ ngày 10/9/2026.
Đánh giá
- Độ khó
- 1/5
- Thời gian dự kiến
- Dưới một giờ
- Mức phù hợp với người mới
- 88/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Ít trao đổi
- Công nghệ
- aws, python
- Lĩnh vực
- machine-learning
Hướng nghiên cứu
Mở model_trainer.py và kiểm tra phương thức _prepare_train_script, nơi sm_train.sh được ghi. Xác minh rằng script được tạo sử dụng ký tự kết thúc dòng LF trên Windows, sau đó chạy các kiểm tra ModelTrainer liên quan hoặc tái hiện đường dẫn tạo trên Windows để xác nhận rằng script có thể thực thi trong container Linux.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Python
- Star
- 2.3k
- Fork
- 1.3k
- Merge trung bình
- 3 ngày 6 giờ
- Pull request đã merge (30 ngày)
- 83
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của aws/sagemaker-python-sdk
-
Cannot use spark_event_logs_s3_uri in PySparkProcessor jobCó thể đã có người làm @rsareddy0329 đã nhận 12 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
aws/sagemaker-python-sdk#6253 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
[Bug] ModelTrainer with no input channels emits InputDataConfig: [], which CreatePipeline rejects (min=1) — v2 omitted the keyCó thể đã có người làm @sagemaker-bot đã nhận 12 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
aws/sagemaker-python-sdk#6156 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
sagemaker-train should depend on mlflow-skinny, following sagemaker-mlflow 0.5.0Có thể đã có người làm @mohamedzeidan2021 đã nhận 13 ngày trước. Đang mở
Độ khó 2/5 Nửa ngày Mức phù hợp với người mới 72/100
aws/sagemaker-python-sdk#6152 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
[Bug] ModelTrainer drops TrainingJobName for PipelineSession, breaking use_custom_job_prefix on TrainingStepCó thể đã có người làm @mohamedzeidan2021 đã nhận 17 ngày trước. Đang mởcomponent: pipelines type: bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
aws/sagemaker-python-sdk#5776 · 1 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 2 ngày
-
`ModelTrainer` bug with method to load hyperparameters from file for Amazon Nova RecipeCó thể đã có người làm @sagemaker-bot đã nhận 12 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
aws/sagemaker-python-sdk#5770 ·
Maintainer thường phản hồi trong vòng 2 ngày
Tất cả issue của aws/sagemaker-python-sdk
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
KalicoCrew/kalico#1012 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 82/100
esphome/esphome.io#7657 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
VNG-Realisatie/gemma-zaken#2658 ·
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 75/100
Maintainer thường phản hồi trong vòng 1 ngày
-
comp/gateway comp/plugins duplicate P3 type/bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
NousResearch/hermes-agent#137019 ·
Maintainer thường phản hồi trong vòng 1 ngày