drytorch.lib.runners

Module containing classes that run a model.

Classes

ModelCaller(model[, name])

Base class that calls a model.

ModelRunner(model[, name])

Run a model on a dataset.

ModelRunnerWithLogs(model[, name])

Run a model on a dataset and log the value of an objective function.

ModelRunnerWithObjective(model[, name])

Run a model on a dataset, calculating the value of an objective function.

SupportsSync(*args, **kwargs)

Protocol for objects that support syncing.

class ModelCaller(model: ModelProtocol[Input, Output], name: str = '')[source]

Bases: CreatedAtMixin, Generic[Input, Output]

Base class that calls a model.

model

the wrapped model.

Type:

drytorch.core.protocols.ModelProtocol[drytorch.lib.runners.Input, drytorch.lib.runners.Output]

Initialize.

Parameters:
  • model (ModelProtocol[Input, Output]) – the wrapped model.

  • name (str) – the name for the object for logging purposes. Defaults to class name plus eventual counter.

property name: str

The name of the model.

abstractmethod __call__() None[source]

Document itself when the model is first called.

Return type:

None

class ModelRunner(model: ModelProtocol[Input, Output], name: str = '', *, loader: LoaderProtocol[tuple[Input, Target]])[source]

Bases: ModelCaller[Input, Output], Generic[Input, Target, Output]

Run a model on a dataset.

model

the model to run.

Type:

drytorch.core.protocols.ModelProtocol[drytorch.lib.runners.Input, drytorch.lib.runners.Output]

loader

the loader providing inputs and targets in batches.

Type:

drytorch.core.protocols.LoaderProtocol[tuple[drytorch.lib.runners.Input, drytorch.lib.runners.Target]]

outputs_list

list of optionally stored outputs.

Type:

list[drytorch.lib.runners.Output]

Initialize.

Parameters:
  • model (ModelProtocol[Input, Output]) – the model to run.

  • name (str) – the name for the object for logging purposes. Defaults to class name plus eventual counter.

  • loader (LoaderProtocol[tuple[Input, Target]]) – provides inputs and targets in batches.

__call__(store_outputs: bool = False) None[source]

Single pass on the dataset.

Parameters:

store_outputs (bool) – whether to store model outputs. Defaults to False.

Return type:

None

property computed_metrics: Mapping[str, float]

Retrieve cached metrics.

class ModelRunnerWithLogs(model: ModelProtocol[Input, Output], name: str = '', *, loader: LoaderProtocol[tuple[Input, Target]], objective: _Objective_co)[source]

Bases: ModelRunnerWithObjective[Input, Target, Output, _Objective_co]

Run a model on a dataset and log the value of an objective function.

model

the model containing the weights to evaluate.

Type:

drytorch.core.protocols.ModelProtocol[drytorch.lib.runners.Input, drytorch.lib.runners.Output]

loader

provides inputs and targets in batches.

Type:

drytorch.core.protocols.LoaderProtocol[tuple[drytorch.lib.runners.Input, drytorch.lib.runners.Target]]

objective

processes the model outputs and targets.

Type:

drytorch.lib.runners._Objective_co

outputs_list

list of optionally stored outputs.

Type:

list[drytorch.lib.runners.Output]

Initialize.

Parameters:
  • model (ModelProtocol[Input, Output]) – the model containing the weights to evaluate.

  • name (str) – the name for the object for logging purposes. Defaults to class name plus eventual counter.

  • loader (LoaderProtocol[tuple[Input, Target]]) – provides inputs and targets in batches.

  • objective (_Objective_co) – processes the model outputs and targets.

class ModelRunnerWithObjective(model: ModelProtocol[Input, Output], name: str = '', *, loader: LoaderProtocol[tuple[Input, Target]], objective: _Objective_co)[source]

Bases: ModelRunner[Input, Target, Output], MonitorProtocol, Generic[Input, Target, Output, _Objective_co]

Run a model on a dataset, calculating the value of an objective function.

model

the model containing the weights to evaluate.

Type:

drytorch.core.protocols.ModelProtocol[drytorch.lib.runners.Input, drytorch.lib.runners.Output]

loader

provides inputs and targets in batches.

Type:

drytorch.core.protocols.LoaderProtocol[tuple[drytorch.lib.runners.Input, drytorch.lib.runners.Target]]

objective

processes the model outputs and targets.

Type:

drytorch.lib.runners._Objective_co

outputs_list

list of optionally stored outputs.

Type:

list[drytorch.lib.runners.Output]

Initialize.

Parameters:
  • model (ModelProtocol[Input, Output]) – the model containing the weights to evaluate.

  • name (str) – the name for the object for logging purposes. Defaults to class name plus eventual counter.

  • loader (LoaderProtocol[tuple[Input, Target]]) – provides inputs and targets in batches.

  • objective (_Objective_co) – processes the model outputs and targets.