TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/itsubaki/autograd/llms.txt
Use this file to discover all available pages before exploring further.
hook package provides gradient-processing functions that run just before an optimizer updates model parameters. Hooks let you apply regularization and gradient clipping without modifying optimizer or model code.
Both functions return a value of type optimizer.Hook — func(params []layer.Parameter) — and can be attached to any optimizer’s Hook slice.
WeightDecay
The regularization coefficient. Typical values range from
1e-4 to 1e-2. A larger value applies stronger regularization.WeightDecay modifies gradients in place (gradient-based L2 regularization). For decoupled weight decay — where the penalty is applied directly to the parameters rather than the gradients — use optimizer.AdamW instead.ClipGrad
max:
max, gradients are left unchanged.
The maximum allowed global gradient norm. Typical values:
1.0 or 5.0.Attaching hooks to optimizers
Hooks are added to theHook field present on each optimizer struct. They are applied in order by the optimizer.Params helper before the parameter update step.
SGD with weight decay
Adam with gradient clipping
Combining multiple hooks
Hooks run in the order they appear in the slice.Complete example
See also
- optimizer package — SGD, Momentum, Adam, and AdamW
- model package — MLP and LSTM model types
- Guides: deep learning — training loop patterns