Repository navigation
fix(train): write a sourceable sm_training.env for quotes and non-identifier names - #6439
Open
AkshayShah03 wants to merge 1 commit into
Open
AkshayShah03 wants to merge 1 commit into
AkshayShah03 wants to merge 1 commit into
Conversation
…ntifier names The training container's bash script sources /opt/ml/input/sm_training.env under 'set -e' with an ERR trap. set_env wrote every variable as export NAME='value', so: - a single quote in any value (e.g. a hyperparameter 'it's', which also appears in SM_HPS and SM_TRAINING_ENV) broke the file's quoting, and - a channel name or hyperparameter key with '-' or '.' (allowed by the API, e.g. channel 'train-data' or key 'model.lr') produced an invalid identifier such as SM_CHANNEL_TRAIN-DATA, making 'export' fail, either of which killed the job before the entry script ran. Map non-identifier characters in names to '_' (as SM_HP_* already does for '-') and escape single quotes in values. Output for ordinary values is unchanged. Applied to the sagemaker-train and sagemaker-core copies.
AkshayShah03
requested a deployment
to
manual-approval
October 12, 2026 17:59 — with
GitHub Actions
Waiting
AkshayShah03
requested a deployment
to
manual-approval
October 12, 2026 17:59 — with
GitHub Actions
Waiting
AkshayShah03
requested a deployment
to
manual-approval
October 12, 2026 17:59 — with
GitHub Actions
Waiting
This branch is waiting to be deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue #, if available: N/A
Description of changes:
The training container's script runs
set -ewith an ERR trap and sources/opt/ml/input/sm_training.env.set_envwrites every variable asexport NAME='value', which breaks in two cases:it'salso ends up inSM_HPSandSM_TRAINING_ENV:-or., both allowed by the API (e.g. channeltrain-data, keymodel.lr), produces an invalid identifier:Either one kills the job before the entry script runs.
This change maps non-identifier characters in names to
_;SM_HP_*already did this for-. It also escapes single quotes in values with the standard'"'"'sequence. The output for ordinary values is unchanged; the existing byte-for-bytetest_set_envstill passes. The fix is applied to both the sagemaker-train and the sagemaker-core copies ofenvironment.py.Testing:
train-datachannel, amodel.lrkey and anit's a testvalue, then sources it withbash -c 'set -e; trap ... ERR; source ...'and checks the values. It fails before this change.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.