nvalchemi.training.LinearWeight#

pydantic model nvalchemi.training.LinearWeight[source]#

Loss weight that ramps linearly from start to end.

LinearWeight interpolates a component’s weight along a straight line: it returns start at schedule index 0 and end at index num_steps, moving proportionally in between. Use it to phase a loss term in or out gradually – for example warming a force or stress term up from 0 over the first few thousand updates, or annealing an auxiliary term down toward the end of training. The schedule index is the global step when per_epoch=False (default) and the epoch when per_epoch=True, and the value is clamped to start for index <= 0 and to end for index >= num_steps.

Examples

>>> from nvalchemi.training.losses import LinearWeight
>>> w = LinearWeight(start=0.0, end=1.0, num_steps=10)
>>> w(step=0, epoch=0), w(step=5, epoch=0), w(step=100, epoch=0)
(0.0, 0.5, 1.0)

Advance the ramp once per epoch instead of per step:

>>> w = LinearWeight(start=0.2, end=1.0, num_steps=10, per_epoch=True)

Notes

num_steps must be strictly positive. Instances are frozen (immutable) per the shared _BaseWeightSchedule config.