Training state and results
This page documents the functional state and fit-result contracts. Most applications can use
Trainer.fit() and do not need to construct these objects directly. See the
training guide for the common workflow and the Trainer reference for runtime
options.
State
TrainState contains model parameters, Optax state, balancer state, independent PRNG streams, the optimizer step,
mixed-precision loss-scaling state, and the model's input normalization statistics. A complete checkpoint restores every
field. The statistics are never differentiated; see
input normalization statistics.
TrainState
[source]
Carry all mutable arrays through compiled training computations.
Attributes:
| Name | Type | Description |
|---|---|---|
model_state |
Any
|
Explicit differentiable NNX model state. |
optimizer_state |
OptState
|
Optax transformation state aligned with |
balancer_state |
Any
|
Arbitrary JAX-compatible loss-balancer state. |
rng_key |
Array
|
Explicit PRNG stream for stochastic model execution. |
sampling_key |
Array
|
Persistent PRNG stream for DataModule-owned training batches. |
balancer_key |
Array
|
Persistent PRNG stream for adaptive-balancer diagnostics. |
step |
Array
|
Scalar integer training iteration stored on device. |
loss_scale |
Array
|
Current loss scale used by FP16 mixed precision. |
finite_steps |
Array
|
Consecutive finite-gradient update count used to grow |
input_statistics |
InputStatistics | None
|
Model-input normalization statistics the model was built with, or |
input_periods |
ResolvedInputPeriods | None
|
Physical input periods the model applies, as sorted |
Fit results
FitResult returns the bound module and final functional state. Pass it to Trainer.predict() to predict in memory.
FitResult
[source]
dataclass
FitResult(
module: BasePhiModule,
state: TrainState,
metrics: dict[str, float],
stopped_early: bool,
iterations: int,
interrupted: bool = False,
)
Summarize the terminal state of one Trainer fit call.
Attributes:
| Name | Type | Description |
|---|---|---|
module |
BasePhiModule
|
Bound module used for training and subsequent prediction. |
state |
TrainState
|
Final functional training state. |
metrics |
dict[str, float]
|
Final host scalar metrics. |
stopped_early |
bool
|
Whether a callback requested termination. |
iterations |
int
|
Number of batches processed by this fit call. |
interrupted |
bool
|
Whether an operating-system signal or :class: |
Training output
TrainingOutput carries named scalar losses and optional fixed-structure diagnostics from the compiled step. Scalar
diagnostics are logged by default. Array diagnostics remain available to callbacks and are never reduced implicitly.
TrainingOutput
[source]
dataclass
Return named objective losses and optional compiled diagnostics.
Attributes:
| Name | Type | Description |
|---|---|---|
losses |
Mapping[str, Array]
|
Stable scalar losses consumed by the configured loss balancer. |
diagnostics |
Mapping[str, Array]
|
Stable auxiliary arrays returned to the host without affecting gradients. |