Skip to content

Skip SuperOffload's eager CPU step on non-finite gradients - #8771

Draft
vineethsaivs wants to merge 1 commit into
deepspeedai:masterfrom
vineethsaivs:fix/superoffload-skip-nonfinite-async-step
Draft

vineethsaivs wants to merge 1 commit into
deepspeedai:masterfrom
vineethsaivs:fix/superoffload-skip-nonfinite-async-step

Conversation

@vineethsaivs

Copy link
Copy Markdown
Contributor

With SuperOffload and fp16, one overflow step permanently breaks the affected weights: they are reset to 0 and their Adam moments become nan, so every later update for them is nan.

Without gradient clipping, partition_grads runs the CPU Adam step during backward, and step() rolls it back when it finds the overflow. The rollback inverts the update ((exp_avg - (1 - beta1) * grad) / beta1), which is inf - inf for an inf gradient, and the kernel sets the non-finite param to 0.

Fix: skip the eager step for a sub-group whose fp32 gradient is not finite. step() still detects the overflow and, since #8638, only rolls back the sub-groups that were submitted.

Test: new unit test in test_invalid_grad_norm.py fails on master (both sub-groups stepped) and passes here; the file gives 18 passed, 1 skipped. On CPU, DeepSpeedCPUAdam step + rollback with grad [inf, 0.2, 0.3] gives param [0.0, ...] and exp_avg [nan, ...]. Not run on a Grace Hopper machine.

On an fp16 overflow step() rolls back the CPU Adam step that already ran
during backward. The rollback inverts the update algebraically, so an inf
or nan gradient leaves nan exp_avg and exp_avg_sq and resets the weight
to 0, and every later step for those elements is nan. Do not take the
eager step on a sub-group whose gradient is not finite; step() sees the
overflow and only rolls back the sub-groups that were stepped.

Signed-off-by: Vineeth Sai <vineethsai4444@gmail.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant