IVON¶
Improved Variational Online Newton (Shen et al., 2024): a practical diagonal
BLR variant designed for deep learning, with separate EMA rates for the mean
and precision, explicit weight decay acting as the prior, and gradient
clipping in natural-parameter space. Accepts standard loss gradients
(same convention as optax.adam).
For proper Bayesian MC training, draw a posterior sample with
sample_ivon before computing gradients at each
step; for optimizer-only use, feed gradients at the current params directly.
Optimizer¶
ivon(learning_rate: float = 0.001, beta1: float = 0.9, beta2: float = 0.99999, weight_decay: float = 0.0001, hess_init: float = 1.0, clip_radius: float = float('inf'), ess: float = 1.0) -> optax.GradientTransformation
¶
IVON optimizer (Shen et al., 2024).
A diagonal BLR variant designed for deep learning. Accepts
standard loss gradients (same convention as optax.adam).
The optimizer maintains a diagonal precision estimate and a
momentum buffer. Use sample_ivon to draw reparameterised
posterior samples before computing gradients for proper Bayesian
inference.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
learning_rate
|
float
|
Step size alpha. |
0.001
|
beta1
|
float
|
EMA rate for gradient momentum. |
0.9
|
beta2
|
float
|
EMA rate for Hessian (precision) estimate. |
0.99999
|
weight_decay
|
float
|
Prior precision / L2 regularisation strength. Acts as both the Bayesian prior and explicit weight decay. |
0.0001
|
hess_init
|
float
|
Initial diagonal Hessian value. |
1.0
|
clip_radius
|
float
|
Maximum magnitude of the natural-gradient update per parameter. |
float('inf')
|
ess
|
float
|
Effective sample size scaling for the Hessian. Set to the training set size N for calibrated uncertainty; set to 1.0 (default) for optimizer-only mode. |
1.0
|
Returns:
| Type | Description |
|---|---|
GradientTransformation
|
An |
Source code in src/optax_bayes/_src/ivon.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | |
Posterior sampling & extraction¶
sample_ivon(state: IVONState, params: optax.Params, key: jax.Array, weight_decay: float = 0.0001) -> optax.Params
¶
Draw a reparameterised posterior sample from IVON state.
Samples \(\theta \sim \mathcal{N}(\text{params},\ \operatorname{diag}(1 / (h + \lambda)))\) via
where \(h\) is the Hessian estimate and \(\lambda\) the weight decay. Call this before computing gradients for proper Bayesian MC estimation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
IVONState
|
An |
required |
params
|
Params
|
Current parameters (the posterior mean). |
required |
key
|
Array
|
PRNG key. |
required |
weight_decay
|
float
|
Must match the |
0.0001
|
Returns:
| Type | Description |
|---|---|
Params
|
Sampled parameter pytree. |
Source code in src/optax_bayes/_src/ivon.py
get_posterior_ivon(state: IVONState, params: optax.Params, weight_decay: float = 0.0001) -> tuple[optax.Params, optax.Params]
¶
Extract the approximate posterior from IVON state.
Returns (mean, variance) where the mean is the current iterate
(params) and
with \(h\) the Hessian estimate and \(\lambda\) the weight decay.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
IVONState
|
An |
required |
params
|
Params
|
Current parameters. |
required |
weight_decay
|
float
|
Must match the |
0.0001
|
Returns:
| Type | Description |
|---|---|
tuple[Params, Params]
|
Tuple |
Source code in src/optax_bayes/_src/ivon.py
State¶
IVONState
¶
Bases: NamedTuple
State for the IVON optimizer.
Attributes:
| Name | Type | Description |
|---|---|---|
momentum |
Params
|
EMA of gradients (first moment), pytree. |
hess |
Params
|
Diagonal Hessian estimate (precision - weight_decay), pytree. |
count |
Array
|
Scalar step counter. |