multi-algorithm HPO tuning via HyperparameterTuner.create()#5794
Open
ucegbe wants to merge 2 commits intoaws:masterfrom
Open
multi-algorithm HPO tuning via HyperparameterTuner.create()#5794ucegbe wants to merge 2 commits intoaws:masterfrom
ucegbe wants to merge 2 commits intoaws:masterfrom
Conversation
updated tuner to accept multi algo tuning
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
Multi-algorithm HPO via
HyperparameterTuner.create()is brokenWhen using
HyperparameterTuner.create()with amodel_trainer_dictcontaining multiple trainers, callingtuner.tune()fails with:Root cause:
_start_tuning_jobunconditionally calls_build_training_job_definition, which accessesself.model_trainer. For multi-algo tuners created viaHyperparameterTuner.create(),self.model_trainerisNone— onlyself.model_trainer_dictis populated.Additionally, the SageMaker
CreateHyperParameterTuningJobAPI expects multi-algo jobs to use theTrainingJobDefinitionsparameter (a list) rather thanTrainingJobDefinition(singular). The existing code only ever passes the singular form.Changes
All changes are in
sagemaker-train/src/sagemaker/train/tuner.py._start_tuning_jobself.model_trainerisNoneandself.model_trainer_dictis populated.training_job_definition(singular)._build_training_job_definitionsand passestraining_job_definitions(plural) in the tuning request. The underlyingHyperParameterTuningJob.createinsagemaker.core.resourcesalready accepts both parameters._build_training_job_definitions(new method)self.model_trainer_dictand builds a list ofHyperParameterTrainingJobDefinitionobjects, one per trainer.definition_name— the trainer key from the dicttuning_objective— per-trainer objective fromobjective_metric_name_dicthyper_parameter_ranges— per-trainer ranges from_hyperparameter_ranges_dictstatic_hyper_parameters— per-trainer static params fromstatic_hyperparameters_dictmetric_definitions— per-trainer metrics frommetric_definitions_dictOutputDataConfig(includingcompression_type),ResourceConfig,StoppingCondition, environment variables, and VPC config from eachModelTrainer.str,dict,list[Channel],list[InputData], and includes internal ModelTrainer channels (code, sm_drivers).Testing
Manual validation: Verified that multi-algorithm HPO tuning with
HyperparameterTuner.create()using twoModelTrainerinstances (XGBoost and LightGBM) successfully launches a tuning job viatuner.tune(). Single-algo tuning behavior is unchanged.Unit tests: Added
tests/unit/train/test_tuner_multi_algo.py(30 tests) covering:TestStartTuningJobBranching(4 tests): Verifies_start_tuning_jobroutes to_build_training_job_definition(singular) for single-algo and_build_training_job_definitions(plural) for multi-algo, and that the correct key (training_job_definitionvstraining_job_definitions) is passed in the API request.TestBuildTrainingJobDefinitions(20 tests): Covers the new multi-algo method — one definition per trainer, correctdefinition_name, per-trainer training images/objectives/HP ranges/static HPs/resource config/stopping condition/role, all input types (string, dict,InputDatalist,Channellist), internal channel inclusion, deduplication, metric definitions, VPC config, and environment passthrough.TestCompressionTypePassthrough(7 tests): Verifiescompression_type(NONE,GZIP) is correctly carried through in both single-algo and multi-algoOutputDataConfig, and thatMagicMockvalues do not leak through theisinstanceguard.All 30 new tests pass. All pre-existing tuner tests continue to pass.