nemos.callbacks.TrainingContext#
- class nemos.callbacks.TrainingContext(model=None, solver=None, params=None, state=None, aux=None, pass_idx=None, batch_idx=None, n_passes=0, frozen=None)[source]#
Bases:
objectMutable context object passed to callbacks during training.
One instance is created per training run. Fields are updated in-place by the training loop before each callback invocation.
- Parameters:
model (
Any) – The model being trained (e.g. GLM instance). Set bystochastic_fit.solver (
Any) – The solver instance running the optimization.params (
Any) – Current model parameters. Exposed as a read/write property: the training loop assigns the actively optimized subtree (ctx.params = ...), and readingctx.paramsrecombines the frozen subtree (seefrozen) so callbacks always see the complete parameters.state (
Any) – Current solver state.aux (
Any) – Auxiliary output from the last batch.batch_idx (
int|None) – Current batch index within the pass.n_passes (
int) – Total number of passes requested.frozen (
Any) – Parameter subtree held fixed during optimization (e.g. a zero intercept whenfit_intercept=False). The solver optimizes only the active subtree; this is recombined with it so callbacks always see the complete parameters.Nonewhen nothing is frozen.
Attributes
Current parameters, with the frozen subtree recombined into the active one.
Whether a callback has requested early stopping.
Reason for the stop request, if any.
- __init__(model=None, solver=None, params=None, state=None, aux=None, pass_idx=None, batch_idx=None, n_passes=0, frozen=None)[source]#
Methods
__init__([model, solver, params, state, ...])request_stop([reason])Request early stopping of the training loop.
Create a post-fit summary from the current training context.
- __repr__(N_CHAR_MAX=700)[source]#
Represent this context as a string.
Simple string representation, similar to that of a dataclass.