Skip to content
← Learn JAX

Optax

JAX

Gradient transforms, optimizer chains, schedules, weight decay, EMA, masking. The production optimizer library for JAX.

This track uses JAX. You can make it your practice mode to browse related content across the site.

25 exercises

Explore freely. Sign in to keep your progress.

Your learning sequence

  1. 1 Not solved yet. Optax SGD Step Practice · Easy
  2. 2 Not solved yet. Optax SGD with Momentum Practice · Easy
  3. 3 Not solved yet. Optax Adam Step Practice · Medium
  4. 4 Not solved yet. AdamW with Decoupled Weight Decay Practice · Medium
  5. 5 Not solved yet. Optax RMSprop Step Practice · Medium
  6. 6 Not solved yet. Constant Schedule Practice · Easy
  7. 7 Not solved yet. Linear Schedule Practice · Easy
  8. 8 Not solved yet. Warmup + Cosine Decay Practice · Medium
  9. 9 Not solved yet. Piecewise Constant Schedule Practice · Medium
  10. 10 Not solved yet. Exponential Decay Schedule Practice · Easy
  11. 11 Not solved yet. Chain: Clip + SGD Practice · Medium
  12. 12 Not solved yet. Adam + Weight Decay (Chain) Practice · Medium
  13. 13 Not solved yet. Global-Norm Gradient Clipping Practice · Medium
  14. 14 Not solved yet. Lookahead Optimizer Wrapper Practice · Hard
  15. 15 Not solved yet. multi_transform per-Param Group Practice · Hard
  16. 16 Not solved yet. Optax EMA on Params Practice · Medium
  17. 17 Not solved yet. Gradient Accumulation via MultiSteps Practice · Hard
  18. 18 Not solved yet. masked: Apply WD Only To Certain Params Practice · Hard
  19. 19 Not solved yet. inject_hyperparams for Runtime LR Practice · Medium
  20. 20 Not solved yet. Simulated NaN Cleanup Before SGD Practice · Medium
  21. 21 Not solved yet. Full Training Step (Loss + Grad + Update) Practice · Hard
  22. 22 Not solved yet. Train Step with Frozen Params (Mask) Practice · Hard
  23. 23 Not solved yet. Train Step with Global-Norm Clipping Practice · Hard
  24. 24 Not solved yet. Train Step with Warmup Schedule Practice · Hard
  25. 25 Not solved yet. 4-Step Training Loop with Scan + Loss Curve Practice · Hard

Check yourself

4 questions · not saved while you're signed out

Use these questions to check your understanding and compare explanations. Your score does not affect track completion.

0 / 4 correct

For a single scalar gradient of 100, what update does clip_first return? Would reversing the transformations change it?

Choose one answer to reveal the explanations. Answers are kept only while this page is open.

import jax.numpy as jnp
import optax

params = jnp.array(0.0)
grad = jnp.array(100.0)
clip_first = optax.chain(optax.clip_by_global_norm(1.0), optax.sgd(0.1))
scale_first = optax.chain(optax.sgd(0.1), optax.clip_by_global_norm(1.0))
for opt in (clip_first, scale_first):
    updates, _ = opt.update(grad, opt.init(params), params)
    print(f"{float(updates):.1f}")
Question 1 of 4