Configuration¶
Everything the controller does can be set in a YAML file or a Python dict instead of code, which makes runs easy to version and reproduce. AutoTuneNet can be configured from a YAML file or a Python dict. Both go through the same schema (autotunenet.config.schema.AutoTuneConfig), and invalid values raise ValueError when the adapter is built.
Example config¶
parameter_space:
lr: {low: 1e-4, high: 1e-1, log: true} # continuous range, log scale
weight_decay: {low: 1e-5, high: 1e-3, log: true}
# momentum: [0.8, 0.99] # continuous range, linear scale (SGD only)
# or categorical: momentum: {choices: [0.8, 0.9, 0.95]}
tuning:
tune_n_steps: 1
warmup_epochs: 2
warmup_metric_threshold: 0.5 # optional
max_delta: 0.5
search:
n_startup_trials: 3 # random proposals before TPE uses its model
metrics:
smoothing_window: 3
stability:
max_regression: 0.2
patience: 2
cooldown: 3
Parameter space syntax¶
Every tuned name must be a setting of the optimizer's param groups (lr, weight_decay, momentum for SGD, eps, and so on). An unknown name, such as momentum with Adam, raises an error that lists the settings that exist.
| Form | Meaning |
|---|---|
name: [low, high] |
Continuous range. The list must have exactly two numbers. |
name: {low: a, high: b} |
Continuous range (explicit form). |
name: {low: a, high: b, log: true} |
Continuous range sampled on a log scale (needs low > 0). Use this for learning rate and weight decay. |
name: {choices: [v1, v2, ...]} |
Categorical choices. |
Numbers in scientific notation such as 1e-4 are accepted. PyYAML reads them as strings, so the schema coerces them to floats. A list with more or fewer than two values is rejected, so that a categorical intent is never silently treated as a range.
A linear range spanning two or more orders of magnitude (for example [1e-4, 1e-1]) puts about 90% of samples in the top decade. AutoTuneNet warns when it sees one; use log: true instead.
In the Python ParameterSpace API used directly (not through a config), a tuple (low, high) is a linear range, {"low": a, "high": b, "log": True} is a log-scale range, and a list is categorical.
Options¶
| Section | Key | Default | Constraint | Description |
|---|---|---|---|---|
tuning |
tune_n_steps |
1 |
int > 0 | Tune every n adapter calls |
tuning |
warmup_epochs |
2 |
int ≥ 0 | Epochs before tuning starts |
tuning |
warmup_metric_threshold |
None |
number > 0 | Tuning starts once the validation loss is at or below this value (the adapter receives -val_loss) |
tuning |
max_delta |
0.5 |
0 < x < 1, or null |
Max relative change per tuning step; null applies proposals unclipped |
tuning |
score |
level |
level or progress |
What TPE learns from: the metric reached, or its relative improvement during the interval. The stability guard always judges the level |
tuning |
spike_factor |
None |
number > 1 | Turns on the divergence guard in on_batch_end: a batch loss above this × the median of the last 20 and above the starting loss (or NaN/Inf) cuts the learning rate at once, down to the bottom of its range at most |
search |
n_startup_trials |
3 |
int ≥ 0 | Trials TPE samples at random before using its model (Optuna's default of 10 would be most of an online run) |
search |
history_window |
None |
int > n_startup_trials |
TPE learns only from the last n scored configurations; None keeps all |
metrics |
smoothing_window |
3 |
int > 0 | Moving-average window over observed metrics |
stability |
max_regression |
0.2 |
number ≥ 0 | Relative drop from best smoothed score counted as a regression |
stability |
patience |
2 |
int > 0 | Consecutive regressions before rollback |
stability |
cooldown |
3 |
int ≥ 0 | Tuning steps with rollback suppressed after a rollback |
Using a config¶
From a YAML file:
from autotunenet.adapters.pytorch.adapter import PyTorchHyperParameterAdapter
adapter = PyTorchHyperParameterAdapter.from_config(
torch_optimizer=optimizer,
config_path="autotune.yaml",
seed=42,
)
From a dict:
from autotunenet.factory import build_pytorch_autotunenet
adapter = build_pytorch_autotunenet(optimizer, raw_config={...}, seed=42)
Runnable: examples/from_config.py with examples/autotune.yaml. Keys you leave out take the defaults in the table above; nothing else is merged in. src/autotunenet/config/defaults.yaml writes out these defaults as a config file to copy; only its parameter_space is an example.
Without a config¶
The same settings as constructor arguments:
| Config key | Python |
|---|---|
parameter_space |
ParameterSpace({...}) |
tuning.* |
PyTorchHyperParameterAdapter(..., tune_n_steps=, warmup_epochs=, warmup_metric_threshold=, max_delta=) |
search.n_startup_trials, metrics.smoothing_window |
BayesianOptimizer(space, seed=, smoothing_window=, n_startup_trials=) |
stability.* |
tuner.guard = StabilityMonitor(max_regression=, patience=, cooldown=) |