SuperOffload: checkpoint the CPU Adam state, fix unused parameters and rollbacks, speculate with clipping (#8972)
## Summary
SuperOffload has several bugs that change the training result without an
error, mostly in the path that runs the CPU
Adam step during backward and undoes it in `step()`. This PR fixes them.
## Fixes
Before → after, against ZeRO-3 CPU offload on GH200 (base `c6291b7e1`):
1. Checkpoints had no Adam state (it lives in the CPU worker process).
It is now saved in the ZeRO-3 layout.
2. A sub-group with an unused param never stepped, and a param without a
gradient reused an old one.
3. Gradient accumulation lost the gradients of earlier micro-steps.
4. Undoing a step with an inf/nan gradient set the weights to 0, and
undoing a finite step could make `exp_avg_sq`
negative (nan in the next step).
5. The worker ignored `adam_w_mode`, `bias_correction` and
`fp32_optimizer_states`, and failed with bf16 master
weights. Up to 1.4e-1 off, or `RuntimeError`
6. Under fp16, the step during backward used the loss-scaled gradient.
7. The worker kept the initial `betas`, `eps` and `weight_decay` (only
`lr` was sent).
8. With `gradient_clipping` > 0 (the default is 1.0), no CPU step
overlapped backward. Now it does; `step()` undoes and
redoes those steps when clipping triggers or the fp16 loss scale
changes.
9. With the decoupled checkpoint engine, the next backward could change
the state while it was being written.
`save_checkpoint` now commits the save first.
---------
Signed-off-by: Xinyu Lian <lian7@illinois.edu>
Signed-off-by: Zhipeng Wang <zhipeng.rainbowserie@gmail.com>
Co-authored-by: Zhipeng Wang <zhipeng.rainbowserie@gmail.com>