accelmo.optimisers.base

Abstract optimiser interface and best-point tracking.

class accelmo.optimisers.base.BestTracker[T](value, loss=inf)[source]

Bases: Generic[T]

The lowest loss seen so far and the point it was seen at.

Parameters:
  • value (T)

  • loss (float)

value: T
loss: float = inf
record(loss, value)[source]

Make value (at loss) the best point.

Return type:

None

Parameters:
  • loss (float)

  • value (T)

class accelmo.optimisers.base.BaseOptimiser[source]

Bases: ABC

Common interface for all optimisers used by the training loop.

Subclasses are named by OPTIMISER_NAME, take their constructor arguments from an OptimiserConfig via config_kwargs(), and list in KNOB_VECTORS / KNOB_VECTOR_LISTS the state entries that hold one value per knob, which load_state_dict() remaps when the knob layout changed.

OPTIMISER_NAME: ClassVar[str]
KNOB_VECTORS: ClassVar[tuple[str, ...]] = ()

State entries that are one vector over the knobs (None allowed).

KNOB_VECTOR_LISTS: ClassVar[tuple[str, ...]] = ()

State entries that are a list of such vectors.

abstractmethod classmethod config_kwargs(config, n_params)[source]

Constructor arguments taken from config.

Return type:

dict[str, Any]

Parameters:
abstractmethod step(params, grads, lr)[source]

Apply one optimisation update step.

Return type:

ndarray

Parameters:
  • params (np.ndarray)

  • grads (np.ndarray)

  • lr (float)

abstractmethod state_dict()[source]

Serialise optimiser state to a JSON-compatible dictionary.

Return type:

dict[str, Any]

load_state_dict(state, remap=None)[source]

Restore optimiser state; remap moves each per-knob vector onto the current knob layout.

Return type:

None

Parameters:
  • state (dict[str, Any])

  • remap (Callable[[list[float]], list[float]] | None)

static with_weight_decay(grads, params, weight_decay)[source]

L2 weight decay: the gradient of 0.5 * weight_decay * |params|² added to grads.

Return type:

ndarray

Parameters:
  • grads (np.ndarray)

  • params (np.ndarray)

  • weight_decay (float)