Tuning Hyperparameters with SageMaker Automatic Model Tuning
This lesson explains SageMaker AI automatic model tuning (AMT), which runs many training jobs with different hyperparameter values and searches for the combination that optimises an objective metric.
Learning outcomes
After completing this lesson, you will be able to:
- Configure a tuning job with an objective metric and ranges.
- Choose between Bayesian, random, grid and Hyperband search.
- Reduce tuning cost with warm start and early stopping.
Configuring a tuning job
A tuning job needs an estimator, an objective metric and whether to maximise or minimise it (for example, maximise validation:auc), parameter ranges and limits on the total number of training jobs and on parallel jobs. Ranges are continuous, integer or categorical, with a scaling type: linear, logarithmic (for values spanning orders of magnitude, such as a learning rate from 0.0001 to 0.1) or reverse logarithmic (for values close to 1, such as momentum).
Tuning job settings
Search strategies
Bayesian optimisation (the default) builds a model of how hyperparameters affect the metric and chooses promising values based on earlier results; it usually needs the fewest jobs. Random search samples values independently, so it runs many jobs in parallel efficiently. Grid search tries every combination of categorical values. Hyperband starts many configurations and stops weak ones early based on intermediate results, which makes it efficient for large searches of iterative algorithms. Bayesian search learns only from completed jobs, so running fewer jobs in parallel gives it more information per round.
The following table compares the strategies.
| Strategy | How it searches | Best for |
|---|---|---|
| Bayesian (default) | Learns from previous results | Limited budget, expensive jobs |
| Random | Independent samples | Many parallel jobs |
| Grid | Every categorical combination | Small categorical spaces |
| Hyperband | Early-stops weak configurations | Large searches of iterative training |
The following diagram compares four parallel jobs over ten rounds with forty jobs at once.

Choose the search strategy
Warm start and early stopping
Hyperparameter tuning can be expensive, and two features reduce its cost. Warm start uses one or more previous tuning jobs as a starting point, so knowledge is not thrown away when tuning continues or the data is updated. IdenticalDataAndAlgorithm continues tuning with the same data and algorithm, and TransferLearning reuses results after the data or algorithm has changed.
Training job early stopping, set to Auto, stops individual training jobs whose intermediate metric shows they are unlikely to beat the best job so far, so the tuning job does not pay for runs that will not win.
Reuse earlier tuning
Tuning XGBoost
A team tunes an XGBoost model with a budget of 40 training jobs.
from sagemaker.tuner import HyperparameterTuner, ContinuousParameter, IntegerParameter
ranges = {
"eta": ContinuousParameter(0.01, 0.3, scaling_type="Logarithmic"),
"max_depth": IntegerParameter(3, 10),
"subsample": ContinuousParameter(0.5, 1.0),
"min_child_weight": ContinuousParameter(1, 10),
}
tuner = HyperparameterTuner(xgb_estimator, objective_metric_name="validation:auc",
objective_type="Maximize", hyperparameter_ranges=ranges,
strategy="Bayesian", max_jobs=40, max_parallel_jobs=4,
early_stopping_type="Auto")
tuner.fit({"train": train_s3, "validation": val_s3})Logarithmic scaling on eta samples small values as often as large ones, Bayesian search with four parallel jobs learns between rounds, and early stopping ends weak jobs. Running all 40 jobs in parallel would finish sooner but would give Bayesian search nothing to learn from.
Which scaling suits a hyperparameter whose values span orders of magnitude?
Show answer
Logarithmic scaling.
Exam Tips
Remember for the exam
- Default and most budget-efficient: Bayesian optimisation.
- Values spanning orders of magnitude: logarithmic scaling.
- Large searches of iterative models: Hyperband.
- Continue from previous tuning: warm start.
- Fewer parallel jobs help Bayesian search learn.