Skip to content

dew.config.sweep

Search hyperparameters over the ordinary training path.

A sweep overrides a RunConfig through its own record, hands each trial to the recipe’s train entry point, and records the score that entry point returns. Trials land in a JSON ledger before they are reported, so an interrupted sweep resumes at the trial it stopped on instead of retraining the finished ones. random_search and grid_search need nothing beyond numpy; optuna_search asks Optuna’s sampler for the next point and tells it the ledger’s trials, and needs dew-ml[hpo].

NameSummary
ChoiceOne candidate value for a swept field: what JSON and Optuna both hold.
SpaceDotted paths into a run record, each with the values a trial draws from.
Point
C
SearchChooses the next point of a space, given the trials already finished.
overrideReturn config with each dotted path in point replaced, through its record.
random_searchDraw one independent value per field, reproducible from the trial’s number.
grid_searchReturn the next point of the space’s cartesian product, in order.
optuna_searchAsk Optuna’s sampler for the next point over the same space.
sweepTrain trials trials of config over space and return the ledger.

attribute source

One candidate value for a swept field: what JSON and Optuna both hold.

attribute source

Dotted paths into a run record, each with the values a trial draws from.

attribute source

attribute source

C = TypeVar('C', bound=RunConfig)

class source

class Search(Protocol)

Chooses the next point of a space, given the trials already finished.

seed is read by the samplers that draw at random, random_search and optuna_search; grid_search walks the product in order and ignores it.

function source

def override(config: C, point: Point) -> C

Return config with each dotted path in point replaced, through its record.

RunConfig.from_dict refuses a leaf the class does not declare, so a misspelled path raises instead of training the unchanged config.

function source

def random_search(space: Space, finished: Sequence[TrialFinished], seed: int) -> Point

Draw one independent value per field, reproducible from the trial’s number.

function source

def grid_search(space: Space, finished: Sequence[TrialFinished], seed: int) -> Point

Return the next point of the space’s cartesian product, in order.

seed is the Search protocol’s, and this walk draws nothing, so it goes unread here.

function source

def optuna_search(space: Space, finished: Sequence[TrialFinished], seed: int) -> Point

Ask Optuna’s sampler for the next point over the same space.

The study is built from the ledger on every call rather than kept across them, so a resumed sweep asks from the same trials a fresh one would.

function source

def sweep(
config: C,
space: Space,
*,
train: Callable[[C], float],
trials: int,
ledger: str | Path,
tracker: Tracker,
search: Search = random_search,
seed: int = 0,
) -> list[TrialFinished]

Train trials trials of config over space and return the ledger.

Each trial draws a point from space, trains under the run name <trainer.name>/trial-<index> so trials keep their own checkpoints and tracking, and records the score train returns for it. tracker receives that score as sweep/value at the trial’s number and the trial’s TrialFinished record. A trial reaches ledger before it is reported, so rerunning the same call continues an interrupted sweep.