Benchmark extension points¶
The classes you use to add tasks, scenarios, methods and runtimes. See Extending the benchmark for worked examples.
Tasks¶
TaskSpec
dataclass
¶
TaskSpec(name: str, build_loaders: Callable[[int, int], tuple[DataLoader, DataLoader]], build_test_loader: Callable[[int], DataLoader], build_model: Callable[[], Module], batch_size: int, lr: float, lr_range: tuple[float, float], data_paths: tuple[str, ...] = (), prepare_data: Callable[[], None] | None = None)
A dataset and model pair, with its training defaults.
Register one with TASKS.add(name, TaskSpec(...)), in a plugin file or
in autotunenet.bench.tasks.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Task name, as used in experiment files. |
build_loaders |
Callable[[int, int], tuple[DataLoader, DataLoader]]
|
|
build_test_loader |
Callable[[int], DataLoader]
|
|
build_model |
Callable[[], Module]
|
|
batch_size |
int
|
Batch size used by every method. |
lr |
float
|
Default initial learning rate. |
lr_range |
tuple[float, float]
|
|
data_paths |
tuple[str, ...]
|
Files or folders the task reads, relative to the data
directory ( |
prepare_data |
Callable[[], None] | None
|
|
Examples:
>>> TASKS.add("my_task", TaskSpec(
... name="my_task", build_loaders=my_loaders, build_test_loader=my_test_loader,
... build_model=MyModel, batch_size=64, lr=0.01, lr_range=(1e-4, 1e-1),
... data_paths=("my_task",), prepare_data=download_my_task,
... ))
Scenarios¶
Scenario ¶
What happens to a training run besides the method's own decisions.
Examples are label noise or gradient noise starting mid-run, or a bad
initial learning rate. Register a subclass with
@SCENARIOS.register("name"); its constructor keyword arguments come from
the experiment file, and a seed argument receives the run's seed.
Attributes:
| Name | Type | Description |
|---|---|---|
shift_epoch |
int | None
|
First epoch trained under a shift, or |
overrides_initial_lr |
bool
|
|
Methods¶
Method ¶
Bases: ABC
A way of choosing the learning rate, compared by the benchmarks.
Register a subclass with @METHODS.register("name"). Its constructor
keyword arguments come from the method's entry in the experiment file.
Subclass SingleRunMethod instead when the method trains one model.
run
abstractmethod
¶
Train for one cell and report the chosen model.
Create models with ctx.new_trainer() and ctx.new_scenario(), record
every epoch of every model in ledger, and evaluate the test split
only once, for the reported model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
RunContext
|
The cell to run. |
required |
ledger
|
ComputeLedger
|
Compute accounting to update. |
required |
Returns:
| Type | Description |
|---|---|
RunOutcome
|
The reported model's test metrics and per-epoch history. |
Source code in src/autotunenet/bench/core/method.py
SingleRunMethod ¶
Bases: Method
A method that trains one model and adjusts it after each epoch.
The model is trained with Adam from the scenario's initial learning rate
for ctx.epochs epochs; the Controller from make_controller runs
after every epoch, and the test split is evaluated once at the end.
make_controller
abstractmethod
¶
Build the controller for one run.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
optimizer
|
Optimizer
|
The Adam optimizer training the model; the controller may
change its |
required |
ctx
|
RunContext
|
The cell being run. |
required |
Source code in src/autotunenet/bench/core/method.py
Controller ¶
Bases: ABC
Per-epoch decision logic of a single-run method (e.g. a scheduler step).
Only on_epoch_end is required; the other hooks do nothing unless overridden.
on_train_start ¶
on_batch_end ¶
on_train_end ¶
on_epoch_end
abstractmethod
¶
Called after each epoch's validation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
epoch
|
int
|
Index of the epoch just trained (from 0). |
required |
val_loss
|
float
|
Validation loss after that epoch. |
required |
Source code in src/autotunenet/bench/core/method.py
RunContext
dataclass
¶
RunContext(task: Any, scenario_name: str, scenario_params: dict[str, Any], seed: int, device: device, epochs: int, options: dict[str, Any] = dict())
Everything a method needs to train one cell (method x task x scenario x seed).
Attributes:
| Name | Type | Description |
|---|---|---|
task |
Any
|
The |
scenario_name |
str
|
Registered name of the scenario. |
scenario_params |
dict[str, Any]
|
Scenario arguments from the experiment file. |
seed |
int
|
The run's seed; fixes the data split and initial weights. |
device |
device
|
Torch device to train on. |
epochs |
int
|
Epochs per trained model (the experiment's |
options |
dict[str, Any]
|
Extra options. |
new_scenario ¶
A fresh scenario instance (each trained model needs its own).
Scenarios that take a seed get the run seed unless the experiment
pins one, so noise differs across seeds but is reproducible.
Source code in src/autotunenet/bench/core/method.py
new_trainer ¶
A Trainer on the run's split; init_seed varies the initial weights and data order.
train_single_run ¶
One model from the scenario's initial learning rate, then the test split once.
Source code in src/autotunenet/bench/core/method.py
train_epochs ¶
train_epochs(ctx: RunContext, ledger: ComputeLedger, trainer: Trainer, optimizer, scenario, controller: Controller) -> list[dict[str, Any]]
Train trainer.model for ctx.epochs, calling the scenario before and the
controller after every epoch. Returns the per-epoch history. The test
split is not touched here.
Source code in src/autotunenet/bench/core/method.py
ComputeLedger
dataclass
¶
ComputeLedger(epochs_trained: int = 0, max_parallel_models: int = 1, trials: int = 1, restarts: int = 0, wall_time_sec: float = 0.0, controller_time_sec: float = 0.0)
Registries¶
METHODS, TASKS and SCENARIOS in autotunenet.bench.core.registry are instances of Registry.
Registry ¶
Bases: Generic[T]
A name-to-object table for one kind of component (method, task or scenario).
Attributes:
| Name | Type | Description |
|---|---|---|
kind |
The kind, used in error messages. |
Source code in src/autotunenet/bench/core/registry.py
register ¶
Decorator that registers a class or function under name.
Raises:
| Type | Description |
|---|---|
ValueError
|
|
Source code in src/autotunenet/bench/core/registry.py
add ¶
Register obj under name and return it.
Raises:
| Type | Description |
|---|---|
ValueError
|
|
get ¶
Return what is registered under name.
Raises:
| Type | Description |
|---|---|
KeyError
|
Unknown name; the message lists the registered names. |
Source code in src/autotunenet/bench/core/registry.py
Results¶
RunOutcome
dataclass
¶
RunOutcome(test_loss: float, test_accuracy: float, history: list[dict[str, Any]], extra: dict[str, Any] = dict())
What a method returns: test metrics, per-epoch history, method extras.
RunResult
dataclass
¶
RunResult(experiment: str, method: str, task: str, scenario: str, seed: int, test_loss: float, test_accuracy: float, history: list[dict[str, Any]], shift_epoch: int | None, compute: dict[str, Any], environment: dict[str, Any], config: dict[str, Any], extra: dict[str, Any] = dict(), schema_version: int = SCHEMA_VERSION)
The result of one cell, stored as JSON at
<results>/<experiment>/<method>/<task>/<scenario>/seed_<seed>.json.
Attributes:
| Name | Type | Description |
|---|---|---|
experiment |
str
|
Experiment name. |
method |
str
|
Method name. |
task |
str
|
Task name. |
scenario |
str
|
Scenario name. |
seed |
int
|
Seed of the run. |
test_loss |
float
|
Test loss of the reported model. |
test_accuracy |
float
|
Test accuracy of the reported model, in [0, 1]. |
history |
list[dict[str, Any]]
|
One entry per epoch: |
shift_epoch |
int | None
|
First epoch under the scenario's shift, or |
compute |
dict[str, Any]
|
|
environment |
dict[str, Any]
|
Device, accelerator, library versions, platform and git commit. |
config |
dict[str, Any]
|
Epochs, method and scenario arguments, and task settings. |
extra |
dict[str, Any]
|
Method-specific details (e.g. rollbacks, exploits). |
schema_version |
int
|
Version of this format. |
save ¶
Write atomically, so an interrupted run never leaves a half-written file.
Source code in src/autotunenet/bench/core/result.py
Runtimes¶
Runtime ¶
Bases: ABC
A place where cells are trained, such as this machine or Kaggle.
Each method is one stage of autotunenet run and one CLI command. Only
run is required; the other stages default to doing nothing. Register a
new runtime in autotunenet.bench.runtimes.RUNTIMES.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The value of |
setup ¶
Check what this runtime needs.
Returns:
| Type | Description |
|---|---|
list[str]
|
Problems found, each a sentence saying what to fix; empty when ready. |
data ¶
Make each task's data available to this runtime.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tasks
|
Sequence
|
|
required |
force
|
bool
|
Upload or fetch again even if already available. |
False
|
prepare ¶
prepare(exp: Experiment, exp_path: Path, cells: Sequence[Cell], results_dir: Path, plugins: Sequence[str], parallel: int) -> None
Plan the cells that have no result yet; keep a round that is still running.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exp
|
Experiment
|
The experiment. |
required |
exp_path
|
Path
|
Its YAML file (shipped to hosted runtimes). |
required |
cells
|
Sequence[Cell]
|
Cells to consider; those with results are skipped. |
required |
results_dir
|
Path
|
Root results folder. |
required |
plugins
|
Sequence[str]
|
Plugin files to ship with the work. |
required |
parallel
|
int
|
How many workers (e.g. notebooks) to use at once. |
required |
Source code in src/autotunenet/bench/runtimes/base.py
start ¶
pull ¶
Collect finished results into results_dir without overwriting existing ones.
Returns:
| Type | Description |
|---|---|
int
|
The number of new result files. |
in_progress ¶
describe ¶
run
abstractmethod
¶
run(exp: Experiment, exp_path: Path, cells: Sequence[Cell], results_dir: Path, plugins: Sequence[str], parallel: int, device: str) -> list[Cell]
Run every stage until the cells are done or the work stops.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exp
|
Experiment
|
The experiment. |
required |
exp_path
|
Path
|
Its YAML file. |
required |
cells
|
Sequence[Cell]
|
Cells to run; those with results are skipped. |
required |
results_dir
|
Path
|
Root results folder. |
required |
plugins
|
Sequence[str]
|
Plugin files or modules. |
required |
parallel
|
int
|
Workers to use at once (hosted runtimes). |
required |
device
|
str
|
|
required |
Returns:
| Type | Description |
|---|---|
list[Cell]
|
The cells that still have no result. |