Based on the MLA-C01 exam guideReport an error
early_stopping_type='Auto') cuts off hopeless training midway to reduce compute cost.IDENTICAL_DATA_AND_ALGORITHM for identical conditions, TRANSFER_LEARNING when the data has changed.max_parallel_jobs too high actually lowers efficiency.The algorithm you picked yesterday has knobs such as max_depth, eta, and num_round. With dozens or hundreds of combinations it is hard to try them by hand, and SageMaker Automatic Model Tuning (AMT) automates this search. It automatically launches multiple training jobs, trains each with a different combination, and finds the combination with the best objective metric.
There are three key components.
[Hyperparameter ranges] + [Objective metric] + [Search strategy]
│
▼
① Select next combination ◀─────┐
│ │
▼ │ ④ Feed the result back to the strategy
② Run Training Job │ (the core of the Bayesian family)
(max_parallel_jobs at a time) │
│ │
▼ │
③ Emit objective metric ─────────┘
│
├─ Lagging training is stopped by early stopping
│
└─ max_jobs exhausted → BestTrainingJob is fixed
│
▼
(Warm start) Reused as the starting point of the next tuning jobfrom sagemaker.tuner import (
HyperparameterTuner, ContinuousParameter, IntegerParameter
)
tuner = HyperparameterTuner(
estimator=estimator,
objective_metric_name='validation:auc', # objective metric
objective_type='Maximize', # maximize
hyperparameter_ranges={
'eta': ContinuousParameter(0.01, 0.3), # continuous range
'max_depth': IntegerParameter(3, 10), # integer range
'num_round': IntegerParameter(50, 300),
},
max_jobs=20, # total number of training jobs
max_parallel_jobs=3, # number running concurrently
strategy='Bayesian', # search strategy
)
tuner.fit({'train': train_s3, 'validation': val_s3})There are three parameter types for specifying ranges, and which type you use even affects the search method.
| Range Type | What it expresses | Example |
|---|---|---|
| ContinuousParameter | Real-number interval | Learning rate eta 0.01 ~ 0.3 |
| IntegerParameter | Integer interval | Tree depth max_depth 3 ~ 10 |
| CategoricalParameter | A fixed list of values | objective = binary:logistic / reg:squarederror |
For values where the order of magnitude matters, like a learning rate, the difference between 0.001 and 0.01 is far larger than the difference between 0.1 and 0.11. So such parameters are better searched on a log scale rather than a linear one. AMT lets you specify the scale with scaling_type, and the default Auto looks at the range and chooses the appropriate one. Also remember that if you set the range too wide the search scatters, and if too narrow the optimum stays outside the range.
Hyperparameter tuning is a "black-box optimization" problem. You put in inputs (hyperparameters) and get an output (validation performance), but you do not know the formula of the function in between, and a single evaluation (= one training run) is expensive. So rather than blindly trying everything, a strategy that smartly finds good regions with few evaluations is important. This is why Bayesian optimization appears.
The exam requires you to distinguish the differences among search strategies. Distinguish four.
| Strategy | Behavior | Characteristics |
|---|---|---|
| Grid Search | Tries every combination on a grid | Thorough but combinatorial explosion; used only with categorical |
| Random Search | Draws randomly within the ranges and tries | Simple, easy to parallelize, relies on luck |
| Bayesian | Smartly chooses the next trial using previous results | Good values with few runs, most recommended |
| Hyperband | Cuts off poorly performing training early and reallocates resources | Efficient for large-scale and deep learning |
Bayesian is the key. From the results of the trials so far, it builds a probabilistic model of "which region is promising" and picks the next combination to try where the information value is highest. In other words, it reflects earlier training results in the next choice, so it finds good values faster with the same budget. Because of this sequential dependency, setting concurrent execution (max_parallel_jobs) too high reduces the benefit.
The strategy ultimately splits on three conditions: budget, parallelism, and training length.
| Clue in the situation | Strategy to pick | Reason |
|---|---|---|
| "Efficiently with a limited budget" | Bayesian | Narrows to promising regions with few runs |
| "As many in parallel as possible, no dependence between trials" | Random | Each trial is independent, so parallel scaling is free |
| "Only a few values, so check them all" | Grid | Exhaustive search is possible and reproducibility is high |
| "Deep learning where one training run takes hours" | Hyperband | Cuts bad configurations early and reallocates resources |
| "Continue the tuning I ran yesterday" | Bayesian + warm start | Previous trials become prior knowledge for the probabilistic model |
⚠️ Pitfall: The default answer to "I want to efficiently find good hyperparameters with a limited budget" is Bayesian. However, if it is "try as many as possible quickly in parallel without depending on previous trial results", Random fits better, and if "like deep learning, training is long and I want to save resources by cutting bad configurations early", Hyperband fits better. The strategy choice splits on budget, parallelism, and training length.
Tuning runs training jobs many times, so it is costly. Early stopping is a key feature for reducing this. If, during training, the objective metric is judged hopeless compared with other trials, that training job is cut off midway.
tuner = HyperparameterTuner(
estimator=estimator,
objective_metric_name='validation:auc',
objective_type='Maximize',
hyperparameter_ranges=ranges,
early_stopping_type='Auto', # enable early stopping
...
)When enabled with early_stopping_type='Auto', SageMaker looks at the intermediate metrics of in-progress training and cuts off jobs that are clearly lagging, saving compute time. This works only if the algorithm emits the metric at every epoch/round (most built-ins support this).
Early stopping touches on the resource allocation problem of "exploration-exploitation". Spending the same resources on every trial is wasteful. It is reasonable to give up quickly on hopeless candidates (stop them) and concentrate resources on promising ones. The Hyperband strategy itself is an active implementation of this idea, and early stopping in ordinary tuning is a lighter version of the same philosophy.
Sometimes you have already run a tuning job once, and now the data has grown a little or you want to widen the ranges slightly and tune again. Searching from scratch each time throws away the knowledge gained earlier. Warm start continues a new tuning by using the results of a previous tuning job as the starting point.
from sagemaker.tuner import WarmStartConfig, WarmStartTypes
warm_config = WarmStartConfig(
warm_start_type=WarmStartTypes.IDENTICAL_DATA_AND_ALGORITHM,
parents={'previous-tuning-job-name'}, # parent tuning job
)
tuner = HyperparameterTuner(
estimator=estimator, objective_metric_name='validation:auc',
objective_type='Maximize', hyperparameter_ranges=ranges,
warm_start_config=warm_config,
)There are two warm start types.
| Type | Precondition | When to use |
|---|---|---|
| IDENTICAL_DATA_AND_ALGORITHM | Data and algorithm identical to before | When continuing the search by adjusting only the hyperparameter ranges |
| TRANSFER_LEARNING | Data or conditions may differ | When new data has been added or the algorithm changed and you only want to reference previous knowledge |
When tuning ends, retrieve the best combination from the job description.
import boto3
sm = boto3.client('sagemaker')
desc = sm.describe_hyper_parameter_tuning_job(
HyperParameterTuningJobName='my-tuning-job'
)
best = desc['BestTrainingJob']
print(best['TrainingJobName']) # best-performing training job
print(best['FinalHyperParameterTuningJobObjectiveMetric']) # metric name and value
print(best['TunedHyperParameters']) # best hyperparameter combination
print(desc['TrainingJobStatusCounters']) # completed·failed·stopped countsBy looking at the number of stopped jobs in TrainingJobStatusCounters, you can check how much early stopping actually intervened.
⚠️ Pitfall: If you "want to use the results of a previous tuning job to make a new tuning converge faster", it is warm start. If the data and algorithm are unchanged, choose IDENTICAL_DATA_AND_ALGORITHM; if data was added/changed, choose TRANSFER_LEARNING. Warm start shines especially when combined with the Bayesian strategy — because previous trials enter the probabilistic model as prior knowledge.
With tuning, the situation of "it runs but the results are poor" is common, and the exam presents that situation as a question stem.
| Symptom | Common cause | Action |
|---|---|---|
| Performance does not improve even after many jobs | The search range does not contain the optimum | Widen the range, and search values where order of magnitude matters on a log scale |
| It is Bayesian but barely different from Random | max_parallel_jobs is too high, so the sequential-learning benefit is lost | Lower the parallelism so earlier results feed into the next choice |
| Early stopping does not work at all | The algorithm does not emit intermediate metrics | Log the objective metric periodically in the training script and verify the regex match |
| Tuning cost is not under control | max_jobs is large and early stopping is off | Adjust the max_jobs ceiling + early_stopping_type='Auto' |
| Validation performance is the best but real performance is poor | Overfitting from repeated optimization on the same validation set | Do a final check with a separate test set, introduce cross-validation |
| Rerunning with slightly changed conditions searches from scratch | Warm start not configured | Specify the previous tuning job as the parent with WarmStartConfig |
The last row is especially confusing. Because tuning picks combinations to maximize the validation metric, it can overfit to the validation set itself. To trust the tuning result, a final check on data never used in tuning is required. The cause of a scenario like "the validation score rose greatly after tuning, but performance dropped when deployed" is usually this.
In the next post, we look at JumpStart and transfer learning, which use pre-trained models instead of training from scratch, and at training cost optimization.
Click a choice to reveal the answer and explanation.
Question 1
With a limited compute budget, you want to find a good hyperparameter combination with as few training runs as possible. Which strategy uses the results of previous trials to choose the next trials intelligently?
Question 2
A tuning job runs many training jobs and is costly. How can you reduce compute cost by automatically stopping training jobs whose objective metric is clearly hopeless while in progress?
Question 3
You finished one tuning job yesterday with the same data and algorithm, and today you want to widen only the hyperparameter ranges slightly and converge faster by reusing the previous results. What are the most suitable feature and type?
Question 4
While tuning a deep learning model where a single training run takes several hours, you want a strategy that stops poorly performing configurations early in training and concentrates resources on promising ones. Which search strategy is most suitable?
Question 5
In HyperparameterTuner, which is correct about the meaning of max_jobs and max_parallel_jobs?