Optimizers and Schedules
Reference for jacobi::optim. Every optimizer implements Module, stores learning rate as a scalar device Tensor (so .set_lr(lr) never triggers XLA recompilation), and updates your model in place via .step(&mut model, &grads).
Standard Optimizers
| Optimizer |
Constructor |
Builders & Methods |
Sgd<M> |
Sgd::new(&model, lr), Sgd::with_momentum(&model, lr, momentum) |
.weight_decay(wd), .set_lr(lr), .step(&mut model, &grads) |
Adam<M> |
Adam::new(&model, lr), Adam::spec_for(&model_spec) |
.betas(b1, b2), .eps(eps), .weight_decay(wd), .weight_decay_filter(&model, \|name, t\| ...), .no_decay_1d(&model), .set_lr(lr), .step(&mut model, &grads) |
AdamW<M> |
AdamW::new(&model, lr), AdamW::spec_for(&model_spec) |
.betas(b1, b2), .eps(eps), .weight_decay(wd), .weight_decay_filter(&model, \|name, t\| ...), .no_decay_1d(&model), .set_lr(lr), .step(&mut model, &grads) |
RMSprop<M> |
RMSprop::new(&model, lr), RMSprop::with_momentum(&model, lr, momentum) |
.alpha(a), .eps(eps), .weight_decay(wd), .set_lr(lr), .step(&mut model, &grads) |
Muon<M> |
Muon::new(&model, lr) |
.momentum(0.95), .nesterov(true), .ns_steps(5), .weight_decay(wd), .set_lr(lr), .step(&mut model, &grads) (quintic Newton-Schulz orthogonalization for 2D+ matrices) |
Ema<M> |
Ema::new(&model, decay) |
.step(&model), .params() -> &M, .copy_to(&mut model) |
Low-Rank Subspace Optimizer (EfficientAdamW<M>)
EfficientAdamW keeps first and second optimizer moments inside a tracked rank-r orthonormal subspace for 2D/3D/4D weight matrices (saving 96% to 98.7% of optimizer state HBM), streams large stacked layer projections and updates layer-by-layer to eliminate dense temporary spikes, and synchronizes gradients in compressed low-rank space across DP or hybrid DP/EP meshes.
let mut opt = EfficientAdamW::new(&model, 1e-3, 32)
.weight_decay(1e-2)
.update_proj_gap(10);
let (loss, eff_grads) = opt.value_and_grad(|p| p.loss(&x, &y), &model);
opt.step(&mut model, &eff_grads);
| Method |
Signature |
Description |
| Constructors |
EfficientAdamW::new(&model, lr, rank), EfficientAdamW::spec_for(&model_spec, rank) |
Allocate low-rank state (or zero-HBM AOT spec for compile_for) |
| Builders |
.betas(b1, b2), .eps(eps), .weight_decay(wd), .scale(f64), .min_dim(usize), .update_proj_gap(usize), .factorized_v(bool) |
Configure AdamW hyperparameters, periodic subspace refresh interval, and optional rank-1 factorized variance |
| Single-device grad |
.value_and_grad(f, &model) -> (Tensor, EfficientGrad<M>) |
Warm-started or periodic-refresh low-rank gradient computation |
| Data-parallel grad |
.value_and_grad_dp(f, &model, dp_axis: &str) |
Averages loss and syncs compressed low-rank gradients across dp_axis |
| Hybrid DP/EP grad |
.value_and_grad_hybrid(f, &model, loss_axes: &[&str], leaf_axes_fn) |
Per-leaf multi-axis low-rank gradient sync (e.g. ["ep", "dp"] for attention/norms, ["dp"] for sharded experts) |
| Update & stats |
.step(&mut model, &eff_grads), .set_lr(lr), .bases(), .state_bytes(), .compression_ratio(&model), EfficientAdamW::dense_adamw_bytes(&model) |
Apply low-rank AdamW step and inspect memory compression |
Gradient Clipping and Learning-Rate Schedules
| Function |
Signature |
Description |
global_norm |
optim::global_norm<M: Module>(&grads) -> Tensor |
Global L2 norm across all gradient leaves |
clip_grad_norm |
optim::clip_grad_norm<M: Module>(&mut grads, max_norm: f64) -> Tensor |
Clip global gradient norm in place and return pre-clip norm |
clip_grad_value |
optim::clip_grad_value<M: Module>(&mut grads, lo: f64, hi: f64) |
Elementwise clamp across all gradient leaves |
linear_warmup |
optim::linear_warmup(lr, step, warmup_steps) -> f64 |
Linear ramp from 0 to lr |
step_decay |
optim::step_decay(lr, step, step_size, gamma) -> f64 |
Multiplicative step decay |
cosine_decay |
optim::cosine_decay(lr, step, total_steps) -> f64 |
Cosine annealing from lr to 0 |
warmup_cosine |
optim::warmup_cosine(lr, step, warmup_steps, total_steps) -> f64 |
Linear warmup followed by cosine decay |
one_cycle |
optim::one_cycle(max_lr, step, total_steps, pct_start) -> f64 |
1cycle schedule |
wsd_schedule |
optim::wsd_schedule(lr, step, warmup_steps, total_steps, decay_steps, min_lr) -> f64 |
Warmup-Stable-Decay schedule |