Skip to content

fix(train): use valid shell identifiers for channel and hyperparameter env names - #6439

Open
AkshayShah03 wants to merge 1 commit into
aws:masterfrom
AkshayShah03:fix/training-env-file-quoting
Open

AkshayShah03 wants to merge 1 commit into
aws:masterfrom
AkshayShah03:fix/training-env-file-quoting

Conversation

@AkshayShah03

@AkshayShah03 AkshayShah03 commented Oct 12, 2026 •

Copy link
Copy Markdown

Issue #, if available: N/A

Description of changes:

Narrowed after #6517, which shell-quotes the values written to sm_training.env. Variable names were still a problem.

The training container sources /opt/ml/input/sm_training.env under set -e with an ERR trap. Channel names and hyperparameter keys may contain - or . (allowed by the API, e.g. channel train-data or key model.lr), which produces:

export: `SM_CHANNEL_TRAIN-DATA=/opt/ml/input/data/train-data': not a valid identifier

That kills the job before the entry script runs.

This change maps characters that aren't valid in a shell identifier to _ in the variable names; SM_HP_* already did this for -. It's applied to both the sagemaker-train and the sagemaker-core copies of environment.py.

Testing:

  • A new test in each package writes the file with a train-data channel, a model.lr key and an it's a test value, then sources it with bash -c 'set -e; trap ... ERR; source ...' and checks the values. Both fail on master.
  • container_drivers tests: 36 passed (train) and 82 passed (core).

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

…r env names

The training container's script sources /opt/ml/input/sm_training.env under
'set -e' with an ERR trap. Channel names and hyperparameter keys may contain
'-' or '.' (allowed by the API, e.g. channel 'train-data' or key 'model.lr'),
which produced exports such as SM_CHANNEL_TRAIN-DATA=... that bash rejects
('not a valid identifier'), killing the job before the entry script ran.

Map non-identifier characters in variable names to '_' (SM_HP_* already did
this for '-'). aws#6517 already shell-quotes the values. Applied to the
sagemaker-train and sagemaker-core copies.
@AkshayShah03
AkshayShah03 force-pushed the fix/training-env-file-quoting branch from 132f985 to 6692a68 Compare November 9, 2026 03:44
@AkshayShah03 AkshayShah03 changed the title fix(train): write a sourceable sm_training.env for quotes and non-identifier names fix(train): use valid shell identifiers for channel and hyperparameter env names Nov 9, 2026

This branch is waiting to be deployed

1 waiting deployment
manual-approval — 6692a689 Waiting Nov 9, 2026 by AkshayShah03 via wait-for-approval #1923
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.

1 participant