adamw-sr

Fused AdamW with stochastic rounding, loadable through kernels: the decoupled-weight-decay Adam step fused into one kernel per parameter, with unbiased bf16 write-back and deterministic, shard-invariant randomness. The reference baseline is torch.optim.AdamW, tracked to < 1e-4 over 100 fp32 steps.

Training in bf16 without an fp32 master copy fails under ordinary rounding: any update smaller than a bf16 ULP rounds away, so small updates, which is most of them late in training, simply vanish and the weights stall. This kernel rounds stochastically, up or down with probability set by the truncated bits, so the write-back is unbiased and sub-ULP updates accumulate statistically. bf16 weights then train with no master copy, removing 4 bytes per parameter from the optimizer footprint.

Sub-ULP updates rain into two tanks: the round-to-nearest tank stays empty while the stochastic-rounding tank fills to the target

6,000 optimizer steps of 1e-4, forty times below one bf16 ULP at this weight scale. Round-to-nearest drops every update and the mean weight never leaves 1.0000; stochastic rounding accumulates them and converges toward the 1.5 target, with repeated runs bitwise identical.

Usage

import torch
from kernels import get_kernel

asr = get_kernel("phanerozoic/adamw-sr", version=1, trust_remote_code=True)

model = MyModel().cuda().to(torch.bfloat16)      # bf16 weights, no fp32 master
opt = asr.AdamWSR(model.parameters(), lr=1e-3, weight_decay=0.01, seed=0)

for batch in loader:
    opt.zero_grad()
    loss(model(batch)).backward()
    opt.step()                                    # stochastic rounding auto-on for bf16

version selects the release branch; trust_remote_code is required by kernels for publishers without the trusted-publisher mark. Drop-in for torch.optim.AdamW. Optimizer states are float32; parameters may be f32 or bf16; gradients f32 or bf16.

API

Symbol Purpose
AdamWSR(params, lr, betas, eps, weight_decay, seed) optimizer, drop-in for torch.optim.AdamW
adamw_sr_step(param, grad, exp_avg, exp_avg_sq, ..., base_index, stochastic_rounding) functional in-place step; base_index sets the global RNG offset for sharded updates

Method

The rounding randomness is counter-based Philox keyed by (seed, step) and indexed by each element's global parameter position, so the step is bitwise reproducible run to run and identical whether a parameter is updated whole or split across shards and ranks. This composes with det-train and det-attn: matmul, attention, and the optimizer step are each reproducible under any parallel decomposition.

Correctness

  • fp32 parameters track torch.optim.AdamW over 100 steps to < 1e-4.
  • Stochastic rounding is unbiased: repeated bf16 write-back of a sub-ULP value averages to the value; round-to-nearest drops it.
  • A bf16-only layer with no fp32 master converges with SR and out-trains round-to-nearest.
  • Same (seed, step) gives a bitwise-identical step; a parameter updated in shards with per-shard base_index equals the whole update bitwise.

Requirements and limits

  • NVIDIA GPU with compute capability 8.0+.
  • Optimizer states are float32 regardless of parameter dtype; the saving is the removed fp32 master copy, not the states.

References

Gupta et al., "Deep Learning with Limited Numerical Precision" (stochastic rounding, 2015); decoupled weight decay (Loshchilov and Hutter, 2019); counter-based Philox RNG.

License

Apache-2.0.

Downloads last month
-
apache-2.0
Supported hardwares new
CUDA
8.08.68.99.010.012.0
GPU
B300
288GB
NVIDIA SXM
B200
192GB
NVIDIA SXM
H200
141GB
NVIDIA SXM
H100
80GB
GPU
H800
80GB
GPU
H20
96GB
GPU
L40s
48GB
GPU
L40
48GB
GPU
L20
48GB
GPU
L4
24GB
DGX Spark
GB10
128GB
GPU
RTX PRO 6000 WS
96GB
GPU
RTX PRO 6000 Max-Q
96GB
GPU
RTX PRO 5000
48GB
GPU
RTX PRO 4500 WS
32GB
GPU
RTX PRO 4000
24GB
GPU
RTX PRO 4000 SFF
24GB
GPU
RTX PRO 2000
16GB
GPU
RTX 6000 Ada
48GB
GPU
RTX 5880 Ada
48GB
RTX
RTX 5000 Ada
32GB
GPU
RTX 4500 Ada
24GB
RTX
RTX 4000 Ada
20GB
RTX
RTX 4000 SFF Ada
20GB
GPU
RTX 3500 Ada Mobile
12GB
GPU
RTX 2000 Ada
16GB
GPU
RTX A6000
48GB
GPU
RTX A5000
8GB
GPU
RTX A5000 Max-Q
16GB
GPU
RTX A5000 Mobile
16GB
GPU
RTX A4000
16GB
GPU
RTX A4000 Max-Q
8GB
GPU
RTX A4000 Mobile
8GB
GPU
RTX A3000 Mobile
6GB
GPU
RTX A2000
6GB
GPU
RTX A2000 Embedded
4GB
GPU
RTX A2000 Max-Q
4GB
GPU
RTX A2000 Mobile
4GB
GPU
A800
40GB
GPU
A100
80GB
GPU
A40
48GB
GPU
A30
24GB
GPU
A10
24GB
GPU
A2
16GB
RTX
RTX 5090
32GB
RTX
RTX 5090 D
32GB
RTX
RTX 5090 Mobile
24GB
RTX
RTX 5080
16GB
RTX
RTX 5080 Mobile
16GB
RTX
RTX 5070
12GB
RTX
RTX 5070 Mobile
8GB
RTX
RTX 5070 Ti
16GB
RTX
RTX 5070 Ti Mobile
12GB
RTX
RTX 5060 Ti
16GB
RTX
RTX 5060
8GB
RTX
RTX 5060 Mobile
8GB
RTX
RTX 5050
8GB
RTX
RTX 5050 Mobile
8GB
RTX
RTX 4090
24GB
RTX
RTX 4090D
24GB
RTX
RTX 4090 Mobile
16GB
RTX
RTX 4080 SUPER
16GB
RTX
RTX 4080
16GB
RTX
RTX 4080 Mobile
12GB
RTX
RTX 4070
12GB
RTX
RTX 4070 Mobile
8GB
RTX
RTX 4070 Ti
12GB
RTX
RTX 4070 Super
12GB
RTX
RTX 4070 Ti Super
16GB
RTX
RTX 4060
8GB
RTX
RTX 4060 Ti
8GB
RTX
RTX 4090 Laptop
16GB
RTX
RTX 4080 Laptop
12GB
RTX
RTX 4070 Laptop
8GB
RTX
RTX 4060 Laptop
8GB
RTX
RTX 4050 Laptop
6GB
RTX
RTX 3090
24GB
RTX
RTX 3090 Ti
24GB
RTX
RTX 3080
12GB
RTX
RTX 3080 Ti
12GB
RTX
RTX 3080 Mobile
16GB
RTX
RTX 3070
8GB
RTX
RTX 3070 Ti
8GB
RTX
RTX 3070 Ti Mobile
8GB
RTX
RTX 3060 Ti
8GB
RTX
RTX 3060
12GB
RTX
RTX 3060 Mobile
6GB
RTX
RTX 3050 Mobile
4GB
GPU
RTX 2050 Mobile
4GB
Jetson
Jetson AGX Orin 64GB
64GB
Jetson
Jetson AGX Orin 32GB
32GB
Jetson
Jetson Orin NX 16GB
16GB
Jetson
Jetson Orin NX 8GB
8GB
Jetson
Jetson Orin Nano 8GB
8GB
Jetson
Jetson Orin Nano 4GB
4GB
OS
linux
Arch
x86_64
Kernel Builder
2c516fc