Loss#
- class liesel.optim.Loss(*args, **kwargs)[source]#
Bases:
ProtocolProtocol for optimizer losses.
OptimEngineis intentionally agnostic about the concrete loss type. Any object satisfying this protocol can be optimized: it must expose the split used for training and validation, provide initial parameter positions, compute training and validation losses, and provide gradients for optimizer updates.Notes
The standard built-in optimizer calls
value_and_grad()so the objective value used for monitoring and its gradient share one stochastic evaluation. Custom losses can inherit fromLossMixinto getvalue_and_grad()andgrad()automatically.Methods
grad(params, carry)Returns the gradient of
loss_train_batched()with respect to params.loss_monitor(params, carry)Computes the complete validation monitoring loss at
params.loss_train(params, carry)Computes the full-data training loss at
params.loss_train_batched(params, carry)Computes the training loss for the current mini-batch.
position(position_keys)Extracts an initial optimizer position.
value_and_grad(params, carry)Returns
(loss_train_batched(params, carry), grad).Attributes
Train/validation/test split used by this loss.