GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||
GeezerVison is showing github.com — Fix hook count performance regression from v0.18.5 by tohtana · Pull Request #7886 · deepspeedai/DeepSpeed Conversation
Collaborator
Fixes performance regressions reported in #7882 and #7885. PR #7780 added dynamic hook count computation for reentrant checkpointing correctness, but placed the call inside every gradient hook closure. For a model with n parameter tensors, this creates significant overhead per backward pass. Summary:
With 24-layer transformer, ~267M params (147 parameter tensors), ZeRO-2, 8×H100 80GB, bf16, batch size 8, 20 warmup + 20 measured iterations:
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Add phase-refresh predicate to BackwardHookStateManager to avoid calling count_used_parameters_in_backward() on every gradient hook. Harden enter_backward() to reset counters on first real backward entry, preventing pre-user-backward hook pollution. Signed-off-by: Masahiro Tanaka <[email protected]> Use should_refresh_expected_hook_count() to only recompute the expected hook count at phase boundaries instead of every hook invocation, reducing O(n^2) overhead to O(p*n). Signed-off-by: Masahiro Tanaka <[email protected]> Apply the same refresh/cache pattern in both reduce_partition_and_remove_grads and reduce_leaf_module_grads to avoid per-hook O(n) overhead. Signed-off-by: Masahiro Tanaka <[email protected]>
Collaborator
Author
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
delock
reviewed
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @tohtana the
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for checking, @delock! Yes, there's actually a dependency. I added a comment to clarify it.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
delock
approved these changes
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
|
There was an error while loading. Please reload this page.
|
This fix resolves the ~20% performance regression introduced in DeepSpeed v0.18.5 (311674f) for the DeepSpeed-Megatron GPT-3 13B workload. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Co-authored-by: Ramya Ramineni <[email protected]> Signed-off-by: Masahiro Tanaka <[email protected]>
Signed-off-by: Masahiro Tanaka <[email protected]>
fd933f3 to
c43e423
Compare
There was an error while loading. Please reload this page.
Fixes performance regressions reported in deepspeedai#7882 and deepspeedai#7885. PR deepspeedai#7780 added dynamic hook count computation for reentrant checkpointing correctness, but placed the call inside every gradient hook closure. For a model with n parameter tensors, this creates significant overhead per backward pass. Summary: 1. Added `should_refresh_expected_hook_count()` predicate that returns true only at backward phase boundaries (first hook, or new reentrant phase), so `count_used_parameters_in_backward()` is called once per phase instead of once per hook. 2. Applied this predicate in ZeRO-1/2 (stage_1_and_2.py) and both ZeRO-3 hook sites (stage3.py), reusing the `cached_max_expected_hooks_seen` value when refresh isn't needed. 3. Changed enter_backward() to reset hook counters on first real backward entry, preventing pollution from pre-user-backward autograd calls (e.g., TiledFusedLogitsLoss). With 24-layer transformer, ~267M params (147 parameter tensors), ZeRO-2, 8×H100 80GB, bf16, batch size 8, 20 warmup + 20 measured iterations: - Before fix: 0.1265s/iter - After fix: 0.0505s/iter --------- Signed-off-by: Masahiro Tanaka <[email protected]> Co-authored-by: Ramya Ramineni <[email protected]> Signed-off-by: nathon-lee <[email protected]>
Fixes performance regressions reported in deepspeedai#7882 and deepspeedai#7885. PR deepspeedai#7780 added dynamic hook count computation for reentrant checkpointing correctness, but placed the call inside every gradient hook closure. For a model with n parameter tensors, this creates significant overhead per backward pass. Summary: 1. Added `should_refresh_expected_hook_count()` predicate that returns true only at backward phase boundaries (first hook, or new reentrant phase), so `count_used_parameters_in_backward()` is called once per phase instead of once per hook. 2. Applied this predicate in ZeRO-1/2 (stage_1_and_2.py) and both ZeRO-3 hook sites (stage3.py), reusing the `cached_max_expected_hooks_seen` value when refresh isn't needed. 3. Changed enter_backward() to reset hook counters on first real backward entry, preventing pollution from pre-user-backward autograd calls (e.g., TiledFusedLogitsLoss). With 24-layer transformer, ~267M params (147 parameter tensors), ZeRO-2, 8×H100 80GB, bf16, batch size 8, 20 warmup + 20 measured iterations: - Before fix: 0.1265s/iter - After fix: 0.0505s/iter --------- Signed-off-by: Masahiro Tanaka <[email protected]> Co-authored-by: Ramya Ramineni <[email protected]> Signed-off-by: nathon-lee <[email protected]>
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.