Optimisation¤
The zodiax.optimisation module contains functions to provide a simple interface to apply Optax optimisers to individual leaves!
zodiax.optimisation
¤
adam(lr, start, *schedule)
¤
Wrapper for the optax Adam optimiser with a piecewise constant learning rate schedule.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lr
|
float
|
The initial learning rate. |
required |
start
|
int
|
The starting step (learning rate will be ~0 before this). |
required |
args
|
tuple
|
A variable number of tuples, each containing a step and a multiplier. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
optimiser |
adam
|
The optimiser with the piecewise constant learning rate schedule. |
Source code in zodiax/optimisation.py
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 | |
debug_nan_check(grads)
¤
Checks for NaN values in the gradients and triggers a breakpoint if any are found.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
grads
|
PyTree
|
The gradients to be checked for NaN values. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
grads |
PyTree
|
The gradients. |
Source code in zodiax/optimisation.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | |
decompose(matrix, hermitian=True, normalise=False)
¤
Returns: eigvals: (D,) array sorted descending eigvecs: (D, D) array where each ROW is an eigenvector
Source code in zodiax/optimisation.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | |
delay(lr, start, length=1)
¤
Delays the learning rate by starting at 0 and linearly increasing to the specified learning rate over a specified number of steps.
Source code in zodiax/optimisation.py
101 102 103 104 105 106 | |
eigen_projection(fmat=None, cov=None)
¤
Projects the parameter space into the an orthonormal basis
TODO: develop docs more
Source code in zodiax/optimisation.py
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 | |
get_optimiser(pytree, parameters, optimisers)
¤
Returns an Optax.GradientTransformion object, with the optimisers specified by optimisers applied to the leaves specified by parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pytree
|
PyTree
|
A zodiax.base.PyTree object. |
required |
parameters
|
Params
|
A path or list of parameters or list of nested parameters. |
required |
optimisers
|
Optimisers
|
A optax.GradientTransformation or list of optax.GradientTransformation objects to be applied to the leaves specified by parameters. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
optimiser |
GradientTransformion
|
TODO Update A tuple of (Optax.GradientTransformion, optax.MultiTransformState) objects, with the optimisers applied to the leaves specified by parameters, and the initialised optimisation state. |
state |
MultiTransformState
|
|
Source code in zodiax/optimisation.py
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 | |
map_optimisers(params, optimisers, strict=False)
¤
Maps optimiser from a dictionary of optax optimisers to a dictionary of parameters.
TODO: Develop docs more
Source code in zodiax/optimisation.py
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 | |
scheduler(lr, start, *args)
¤
Function to easily interface with the optax library to create a piecewise constant learning rate schedule. The function takes a learning rate, a starting step and optionally, a variable number of tuples. Each tuple should contain a step and a multiplier; the learning rate will be multiplied by the corresponding multiplier at the specified step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lr
|
float
|
The initial learning rate. |
required |
start
|
int
|
The starting step (learning rate will be ~0 before this). |
required |
args
|
tuple
|
A variable number of tuples, each containing a step and a multiplier. |
()
|
Returns:
| Name | Type | Description |
|---|---|---|
schedule |
schedule
|
The piecewise constant learning rate schedule. |
Source code in zodiax/optimisation.py
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 | |
sgd(lr, start, *schedule)
¤
Wrapper for the optax SGD optimiser with a piecewise constant learning rate schedule.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lr
|
float
|
The initial learning rate. |
required |
start
|
int
|
The starting step (learning rate will be ~0 before this). |
required |
args
|
tuple
|
A variable number of tuples, each containing a step and a multiplier. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
optimiser |
sgd
|
The optimiser with the piecewise constant learning rate schedule. |
Source code in zodiax/optimisation.py
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 | |
zero_nan_check(grads)
¤
Replaces any NaN values in the gradients and with zeros.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
grads
|
PyTree
|
The gradients to be checked for NaN values. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
grads |
PyTree
|
The gradients with NaN values replaced by zeros. |
Source code in zodiax/optimisation.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | |