mipcandy.training

Contents

mipcandy.training#

Module Contents#

Classes#

Functions#

API#

mipcandy.training.try_append(new: float, to: dict[str, list[float]], key: str) None[source]#
mipcandy.training.try_append_all(new: dict[str, float], to: dict[str, list[float]]) None[source]#
class mipcandy.training.TrainerToolbox[source]#

Bases: object

model: torch.nn.Module = None#
optimizer: torch.optim.Optimizer = None#
scheduler: torch.optim.lr_scheduler.LRScheduler = None#
criterion: torch.nn.Module = None#
ema: torch.nn.Module | None = None#
class mipcandy.training.TrainerTracker[source]#

Bases: object

epoch: int = 0#
best_score: float = 'float(...)'#
worst_case: int | None = None#
class mipcandy.training.Trainer(trainer_folder: str | os.PathLike[str], dataloader: torch.utils.data.DataLoader[tuple[torch.Tensor, torch.Tensor]], validation_dataloader: torch.utils.data.DataLoader[tuple[torch.Tensor, torch.Tensor]], *, recoverable: bool = True, profiler: bool = False, device: torch.device | str = 'cpu', console: rich.console.Console = Console())[source]#

Bases: mipcandy.layer.WithPaddingModule, mipcandy.layer.WithNetwork

Initialization

save_everything_for_recovery(toolbox: mipcandy.training.TrainerToolbox, tracker: mipcandy.training.TrainerTracker, **training_arguments) None[source]#
load_state_orb() dict[str, dict[str, mipcandy.types.Setting]][source]#
load_tracker() mipcandy.training.TrainerTracker[source]#
load_training_arguments() dict[str, mipcandy.types.Setting][source]#
load_metrics() dict[str, list[float]][source]#
load_toolbox(num_epochs: int, example_shape: mipcandy.types.AmbiguousShape, compile_model: bool, ema: bool) mipcandy.training.TrainerToolbox[source]#
recover_from(experiment_id: str) Self[source]#
continue_training(num_epochs: int) None[source]#
trainer_folder() str[source]#
trainer_variant() str[source]#
experiment_id() str[source]#
dataloader() torch.utils.data.DataLoader[tuple[torch.Tensor, torch.Tensor]][source]#
validation_dataloader() torch.utils.data.DataLoader[tuple[torch.Tensor, torch.Tensor]][source]#
console() rich.console.Console[source]#
metrics() dict[str, list[float]][source]#
frontend() mipcandy.frontend.Frontend[source]#
tracker() mipcandy.training.TrainerTracker[source]#
initialized() bool[source]#
recovery() bool[source]#
experiment_folder() str[source]#
get_example_input() torch.Tensor[source]#
predict_maximum_validation_score(num_epochs: int, *, degree: int = 5) tuple[int, float][source]#
etc(epoch: int, num_epochs: int, *, target_epoch: int | None = None, val_score_prediction_degree: int = 5) float[source]#
set_frontend(frontend: type[mipcandy.frontend.Frontend], *, path_to_secrets: str | os.PathLike[str] | None = None) None[source]#
set_seed(seed: int) None[source]#
_allocate_experiment_folder() str[source]#
allocate_experiment_folder() str[source]#
init_experiment() None[source]#
log(msg: str, *, on_screen: bool = True) None[source]#
record(metric: str, value: float) None[source]#
record_all(metrics: dict[str, list[float]]) None[source]#
record_profiler() None[source]#
record_profiler_linebreak(message: str) None[source]#
record_profiler_allocated_tensors() None[source]#
save_metrics() None[source]#
save_metric_curve(name: str, values: Sequence[float]) None[source]#
save_metric_curve_combo(metrics: dict[str, Sequence[float]], *, title: str = 'All Metrics') None[source]#
save_metric_curves(*, names: Sequence[str] | None = None) None[source]#
save_progress(*, names: Sequence[str] = ('combined loss', 'val score')) None[source]#
save_preview(image: torch.Tensor, label: torch.Tensor, output: torch.Tensor, *, quality: float = 0.75) None[source]#
show_metrics(epoch: int, metrics: dict[str, list[float]], prefix: str, *, epochwise: bool = True, lookup_prefix: str = '', global_previous_index: int = -2) None[source]#
Parameters:
  • epoch – the current epoch number

  • metrics – the metrics to show

  • prefix – the prefix to use for the table title

  • epochwise – whether the metrics are for one epoch (so that previous values are in self._metrics) or for all epochs (so that previous values are contained in :param: metrics itself)

  • lookup_prefix – the prefix to use for the lookup in self._metrics

  • global_previous_index – the index of the previous epoch in self._metrics

show_metrics_per_case(epoch: int, metrics: dict[str, list[float]]) None[source]#
abstractmethod build_optimizer(params: mipcandy.types.Params) torch.optim.Optimizer[source]#
abstractmethod build_scheduler(optimizer: torch.optim.Optimizer, num_epochs: int) torch.optim.lr_scheduler.LRScheduler[source]#
abstractmethod build_criterion() torch.nn.Module[source]#
abstractmethod build_ema(model: torch.nn.Module) torch.nn.Module[source]#
_build_toolbox(num_epochs: int, example_shape: mipcandy.types.AmbiguousShape, compile_model: bool, ema: bool, *, model: torch.nn.Module | None = None) mipcandy.training.TrainerToolbox[source]#
build_toolbox(num_epochs: int, example_shape: mipcandy.types.AmbiguousShape, compile_model: bool, ema: bool) mipcandy.training.TrainerToolbox[source]#
empty_cache() None[source]#
sanity_check(template_model: torch.nn.Module, example_shape: mipcandy.types.AmbiguousShape) mipcandy.sanity_check.SanityCheckResult[source]#
abstractmethod backward(images: torch.Tensor, labels: torch.Tensor, toolbox: mipcandy.training.TrainerToolbox) tuple[float, dict[str, float]][source]#
train_batch(images: torch.Tensor, labels: torch.Tensor, toolbox: mipcandy.training.TrainerToolbox) tuple[float, dict[str, float]][source]#
train_epoch(toolbox: mipcandy.training.TrainerToolbox) dict[str, list[float]][source]#
train(num_epochs: int, *, note: str = '', num_checkpoints: int = 5, compile_model: bool = True, ema: bool = True, seed: int | None = None, early_stop_tolerance: int = 5, val_score_prediction: bool = True, val_score_prediction_degree: int = 5, save_preview: bool = True, preview_quality: float = 0.75) None[source]#
static filter_train_params(**kwargs) dict[str, mipcandy.types.Setting][source]#
train_with_settings(num_epochs: int, **kwargs) None[source]#
abstractmethod validate_case(idx: int, image: torch.Tensor, label: torch.Tensor, toolbox: mipcandy.training.TrainerToolbox) tuple[float, dict[str, float], torch.Tensor][source]#
validate(toolbox: mipcandy.training.TrainerToolbox) tuple[float, dict[str, list[float]]][source]#
__call__(*args, **kwargs) None[source]#
__str__() str[source]#