Feature/zero multi loss separate backward#8135
Conversation
Signed-off-by: nathon-lee <leejianwoo@gmail.com>
…te-backward-test Fix ZeRO-3 so two separate backward passes on the same forward graph work correctly when `retain_graph=True` is used on the first backward.
There was a problem hiding this comment.
💡 Codex Review
DeepSpeed/deepspeed/runtime/engine.py
Lines 4348 to 4350 in f873f69
After removing the all-rank save_dir validation, a misconfigured save_checkpoint(save_dir=None) or empty string now fails only on rank 0 inside makedirs, while the other ranks proceed to dist.barrier() and can hang indefinitely. The previous check failed synchronously on every rank before this rank-gated filesystem call, so distributed checkpoint misconfiguration no longer fails cleanly.
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| for i in range(len(ev_values)): | ||
| self.summary_events.append(( | ||
| f"Train/Eigenvalues/ModelBlockParam_{i}", | ||
| self.ev_values[i][0], |
There was a problem hiding this comment.
Use block eigenvalues when logging events
When monitoring and eigenvalue logging are enabled at a gradient-accumulation boundary, this block now reads self.ev_values[i][0], but self.ev_values is never initialized anywhere on DeepSpeedEngine (the local value is ev_values = self.block_eigenvalue.values()). That makes engine.step() raise AttributeError instead of writing the eigenvalue summaries in that configuration.
Useful? React with 👍 / 👎.
…changes Signed-off-by: nathon-lee <leejianwoo@gmail.com>
…te-backward-test fix(engine,zero3): restore pre-8135 behavior for non-deepspeedai#8045 changes
Summary
Fix ZeRO-3 so two separate backward passes on the same forward graph work correctly when
retain_graph=Trueis used on the first backward.What changed
retain_graphthrough the ZeRO backward path.finallyto avoid state leakage.Why
This fixes the ZeRO-3 failure where the second backward on the same forward graph hit a tensor size mismatch after
zero_grad(). The regression is tracked by issue #7352.Validation
Test command
CUDA_VISIBLE_DEVICES=0,1 DS_DISABLE_REUSE_DIST_ENV=1 NCCL_IB_DISABLE=1 NCCL_P2P_DISABLE=1 TORCH_NCCL_ASYNC_ERROR_HANDLING=1 TORCH_DISTRIBUTED_DEBUG=DETAIL DS_UNITTEST_TIMEOUT=120 pytest test_zero_user_backward.py -k "test_two_losses_separate_backward_gas1" -vv -s -rsResult
3 passed
0 skipped
55 deselected
Notes
The test previously reproduced a ZeRO-3 RuntimeError on the second backward.
The current run confirms the stage 1/2/3 regression coverage is passing.
cc @tohtana @sfc-gh-truwase