Base Model¶
samudra.models.base
¶
BaseModel(in_channels, out_channels, input_steps, last_kernel_size, pad, gradient_detach_interval, residual=None)
¶
Bases: Module
Abstract base model for neural ocean emulators.
Provides shared functionality for all ocean emulator models, including residual prediction, ocean masking, and gradient detaching for multi-step autoregressive rollouts.
Source code in src/samudra/models/base.py
loss_coordinates(prognostic, prediction, label)
¶
The prediction and label in the units the network predicts.
These are the residual head's increments, or the states themselves without a head. Training and validation losses compare these.
Source code in src/samudra/models/base.py
samudra.models.residual
¶
Residual prediction: the network predicts increments on the input state.
ResidualHead(*, scale, output_steps, scale_kind='none')
¶
Bases: Module
Turns a network's output into next states, as one-step increments.
Each output step is an increment on the step before it, starting from the
newest input: z1 = x[t] + q * d1, z2 = z1 + q * d2, with gradients
flowing through z1. q has one value per variable: ones when
scale_kind is none, or each variable's typical one-step change
(from the data, like the normalization statistics) when it is
increment_rms, so the network emits unit-scale increments.
The network's outputs d are the head's coordinates, and training
compares them with the label expressed in the same coordinates
(:meth:increments), whatever the loss. With q of ones that equals a
loss on states, since the anchors cancel in the error.
The head saves its scale kind and scale with the model's state, and
loading a state saved by a different head raises, naming the
model.residual setting the checkpoint was trained with. BaseModel
handles checkpoints with no head, or from before heads were recorded.
Source code in src/samudra/models/residual.py
increments(prognostic, prediction, states)
¶
states in the head's coordinates, the units the network predicts.
Each step is an increment, in units of q, on the step before it in
prediction (the newest input for the first step), so for the
prediction itself these are the network's outputs.
Source code in src/samudra/models/residual.py
residual_config_yaml(scale_kind)
¶
The model.residual setting that builds a head, for error messages.