fix: accept a PipelineVariable for HyperparameterTuner random_seed - #6320
Open
mohamedzeidan2021 wants to merge 2 commits into
Open
mohamedzeidan2021 wants to merge 2 commits into
mohamedzeidan2021 wants to merge 2 commits into
Conversation
added 2 commits
September 24, 2026 14:28
HyperParameterTuningJobConfig.random_seed was typed Optional[int]; assigning a pipeline variable (e.g. ParameterInteger) raised ValidationError under the shape's validate_assignment. Type it Optional[IntPipeVar] (via the codegen PIPE_VAR_OVERRIDES source of truth + the generated shapes.py), matching sibling fields like instance_count. Also broaden the ModelTrainer-facing tuner random_seed signature to Optional[Union[int, PipelineVariable]]. Fixes aws#5614 (random_seed part), aws#6171
|
Claude finished @mohamedzeidan2021's task in 1m 12s —— View job Review: PR #6320 — accept a
|
This branch was successfully 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
Fixes #6171. Addresses the
random_seedhalf of #5614.Passing a pipeline variable (e.g. a
ParameterInteger) asHyperparameterTuner(random_seed=...)raises:Root cause
HyperparameterTuner._build_tuning_job_configassignsconfig.random_seed = self.random_seedon aHyperParameterTuningJobConfigcore shape, whoseBasemodel setsvalidate_assignment=True. That field was typedOptional[int], so aPipelineVariablefails validation — even though sibling fields in the same shape (strategy: StrPipeVar,instance_count: IntPipeVar, ...) already accept pipeline variables.Fix
Type
HyperParameterTuningJobConfig.random_seedasOptional[IntPipeVar](IntPipeVar = Union[int, PipelineVariable]), matching the sibling fields.shapes.pyis code-generated, so the change is made in both:sagemaker-core/src/sagemaker/core/tools/constants.py— the codegenPIPE_VAR_OVERRIDESsource of truth (HyperParameterTuningJobConfig.RandomSeed -> IntPipeVar), so a regen stays consistent.sagemaker-core/src/sagemaker/core/shapes/shapes.py— the generated line (verified identical to what the override emits).Also broadened the
HyperparameterTunerrandom_seedsignature/docstrings toOptional[Union[int, PipelineVariable]]for consistency with its other pipeline-variable params.Testing
sagemaker-train/tests/unit/train/test_tuner.py::test_random_seed_accepts_pipeline_variable: builds a tuner withrandom_seed=ParameterInteger(...)and calls_build_tuning_job_config()(thevalidate_assignmentpath). Fails on master (exact issue error), passes with the fix. APipelineVariablerandom_seedserializes to its pipeline expression ({'Get': 'Parameters.RandomState'}), and a plainintis still accepted.All 44 tuner unit tests pass; sagemaker-core shape/serialize tests green;
black(100) andflake8(120) clean.Backwards compatibility
Widening only (
int→int | PipelineVariable); plain ints are unaffected. No public signature narrowed.Follow-up (out of scope)
ResourceLimits.{max_parallel_training_jobs, max_number_of_training_jobs, max_runtime_in_seconds}are still bare ints, thoughHyperparameterTunertypesmax_jobs/max_parallel_jobs/max_runtime_in_secondsasUnion[int, PipelineVariable]— so parameterizing those would hit the same error. Not required by this issue's repro; worth a follow-up with the samePIPE_VAR_OVERRIDEStreatment.