Skip to content

fix(train): write sm_train.sh with LF line endings - #6255

Open
MohammedAlkindi wants to merge 1 commit into
aws:masterfrom
MohammedAlkindi:fix/train-script-lf-line-endings
Open

fix(train): write sm_train.sh with LF line endings#6255
MohammedAlkindi wants to merge 1 commit into
aws:masterfrom
MohammedAlkindi:fix/train-script-lf-line-endings

Conversation

@MohammedAlkindi

Copy link
Copy Markdown

Closes #5904.

_prepare_train_script opens sm_train.sh in text mode, so on a Windows host Python writes CRLF. The file is tarred, uploaded and executed inside the Linux training container, where bash rejects it at line 1:

sm_train.sh: line 1: $'\r': command not found
set: -#015: invalid option

The job fails before any user code runs, and the user cannot fix it: the SDK generates the script. Nothing reads it back on the host, so nothing catches it locally. newline="\n" makes the write LF regardless of host; the file is only ever consumed by Linux. This is the fix proposed in the issue.

The added test writes the script to a real temp dir and asserts no CRLF in the bytes. It fails on unmodified master and passes with the change. test_model_trainer.py goes 57 to 58 passed with an identical set of 7 pre-existing failures, all nova_recipe and llmft_recipe cases untouched by this change.

Not run: the wider sagemaker-train suite and tox, which is not installed here, so this is pytest against the one file the change affects. Also not run: black, flake8 and pylint.

AI-assisted; I reproduced the CRLF output and ran the tests before and after myself.

_prepare_train_script opened the file in text mode, so on a Windows host
Python translated every newline to CRLF. The script is packaged and run
inside the Linux training container, where bash rejects it at line 1 with
"$'\r': command not found" before any user code executes. Nothing in the
SDK reads the file back on the host, so the corruption is invisible until
the job fails.

Pass newline="\n" so the file is LF regardless of the host.

Closes aws#5904.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ModelTrainer generates sm_train.sh with CRLF line endings on Windows causing training job failure

1 participant