Skip to content

SaveWeights

minnt.callbacks.SaveWeights

Bases: Callback

A callback that saves model weights to a file after each epoch.

Source code in minnt/callbacks/save_weights.py
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
class SaveWeights(Callback):
    """A callback that saves model weights to a file after each epoch."""

    def __init__(self, path: str, optimizer_path: str | None = None) -> None:
        """Create the SaveWeights callback.

        Parameters:
          path: A path where weights will be saved using the [minnt.TrainableModule.save_weights][]
            method after each epoch. Note that you can use templates like `{logdir}` and `{epoch[:formatting]}`.
          optimizer_path: An optional path passed to [minnt.TrainableModule.save_weights][] to
            save also the optimizer state; it is relative to `path`.
        """
        self._path = path
        self._optimizer_path = optimizer_path

    def __call__(self, module: "TrainableModule", epoch: int, logs: Logs) -> None:
        module.save_weights(self._path, optimizer_path=self._optimizer_path)

__init__

__init__(path: str, optimizer_path: str | None = None) -> None

Create the SaveWeights callback.

Parameters:

Source code in minnt/callbacks/save_weights.py
17
18
19
20
21
22
23
24
25
26
27
def __init__(self, path: str, optimizer_path: str | None = None) -> None:
    """Create the SaveWeights callback.

    Parameters:
      path: A path where weights will be saved using the [minnt.TrainableModule.save_weights][]
        method after each epoch. Note that you can use templates like `{logdir}` and `{epoch[:formatting]}`.
      optimizer_path: An optional path passed to [minnt.TrainableModule.save_weights][] to
        save also the optimizer state; it is relative to `path`.
    """
    self._path = path
    self._optimizer_path = optimizer_path