Tune

Perform the tuning using earlier defined Trainers.

letstune.tune(trainer: EpochTrainer[P], params_number: int, *, dataset: Any = None, rounds: Sequence[timedelta] | dict[str, Any] | None = None, results_dir: Path | str | None = None, passthrough_errors: bool = False, verbose: bool = True) TuningResults[P]
letstune.tune(trainer: SimpleTrainer[P], params_number: int, *, dataset: Any = None, results_dir: Path | str | None = None, passthrough_errors: bool = False, verbose: bool = True) TuningResults[P]

Do tuning on this computer (in this Python interpreter) with given trainer and return tuning results.

Params number

Parameter params_number declares target number of parameters and trainings.

§

If results_dir already has k parameters, then params_number - k will be generated.

True number of trainings can be less than params_number due to parameter deduplication.

Dataset

Parameter dataset is passed-through to letstune.SimpleTrainer.load_dataset() and letstune.EpochTrainer.load_dataset().

Rounds

Only for letstune.EpochTrainer.

Parameter rounds sets durations of rounds.

rounds can be set to a list of datetime.timedelta:

rounds = [
    timedelta(minutes=1),
    timedelta(minutes=2),
    timedelta(minutes=4),
]

rounds also accepts a dict:

rounds = {
    'round_durations': [
        timedelta(minutes=1),
        timedelta(minutes=2),
        timedelta(minutes=4),
    ],
}

The dict accepts trainings_reduction key:

rounds = {
    'round_durations': [
        timedelta(minutes=1),
        timedelta(minutes=2),
        timedelta(minutes=4),
    ],
    'trainings_reduction': 2.0,
}

To the next round are promoted top ceil(trainings_number / trainings_reduction) trainings.

The default value for trainings_reduction is 4.0.

Results directory

Parameter results_dir sets the directory, where tuning results will be stored.

Directory contents:

  • letstune.db is an SQLite database with training metadata,

  • checkpoints is a directory with serialized trained models.

If results_dir is not given, then directory ltruns is created, which will contain the results.

Passthrough errors

When passthrough_errors is True, then all exceptions are not caught.

Otherwise, they will be noted in tuning results and training will continue. That’s the default option.

Verbose

If verbose is True, then explanatory log messages will be printed to the standard output. That’s the default option.

Returned tuning results

The type of returned tuning results depends on the type of trainer parameter.

When given letstune.SimpleTrainer [P], then letstune.results.simple.TuningResults [P] will be returned.

When given letstune.EpochTrainer [P], then letstune.results.epoch.TuningResults [P] will be returned.

Facade

This function is a facade to the letstune system - it is usually a good choice.

If you need further customization, consider to copy this function and modify it according to your needs.