In this article
An auxiliary metric is returned for observation; it does not contribute to the differentiated objective unless that objective explicitly includes it.
Decide which value actually trains the model
A training step returns a loss, an accuracy statistic and a regularization diagnostic. Treating this collection as an undifferentiated result obscures the mathematical target. The grad reference requires a scalar objective and provides has_aux for an output paired with auxiliary data. Decide whether regularization belongs in the objective or is merely being reported. Returning a diagnostic beside a loss does not automatically add its contribution to the parameter update.
Distinguish scalar shape from a short vector
A scalar array and a vector containing a single loss entry are different interfaces. Reducing per-example losses requires a deliberate mathematical rule before calling a scalar-gradient transformation. Specify weighting, masking and normalization according to the task. Simply reshaping a vector to satisfy an interface can conceal an unresolved reduction decision. A report should be able to explain which examples contribute and what changes when the batch contains different amounts of usable information.
Read the nested result intentionally
The value_and_grad reference documents its combined return and the additional nesting used with has_aux. Unpack value, diagnostics and gradients explicitly in the training wrapper. Avoid passing a diagnostic dictionary into code that expects the objective or accidentally recording an entire result tuple as the loss. Named local variables make this boundary inspectable and prevent interface changes in logging from silently changing which value reaches the optimizer.
Choose parameter arguments independently of diagnostics
The autodiff cookbook explains derivatives and their composition. Review the differentiated argument selection alongside the scalar objective: a batch input and model parameters have different roles even when both are arrays. Keep auxiliary values within the intended transformation-compatible output contract. Their presence is useful for inspection, but it is not a declaration that every value they contain is an optimization target or a separate parameter gradient.
Validate the update with a controlled example
Construct a small case where changing a diagnostic alone leaves the intended objective unchanged, and a case where changing an included penalty changes it. Compare resulting parameter gradients. The guides on variable-length loss reduction and autograd chain rules provide related context. This separates monitoring decisions from mathematical training decisions. A successful backward call is meaningful when the scalar target and selected parameter arguments match the update the experiment was designed to study.
Earn rental income from GPUs
Have idle GPUs or looking to fund AI infrastructure? Retrivium finds a rental platform, sets up the server and helps you assess income and costs with a pilot.