Repository navigation
Skip ZeRO DeepCompile backward hooks for AutoSP - #8667
Merged
tohtana merged 1 commit intoSep 27, 2026
Merged
Conversation
jinyouzhi
requested review from
loadams,
tjruwase and
tohtana
as code owners
September 25, 2026 15:57
The engine's backward prologue and epilogue only exempted the AutoTP compile pass from the ZeRO DeepCompile hooks. With the AutoSP pass, backward therefore called deepcompile_backward_prologue(), which loads (and JIT-builds on first use) the DeepCompile native extension and calls start_backward() on it, although AutoSP never initializes that runtime. On accelerators that cannot build the extension, backward fails. Use uses_parallelization_pass_only() for both checks, as allreduce_gradients() already does, so neither parallelization pass enters the ZeRO DeepCompile hooks. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: Jin, Youzhi <youzhi.jin@intel.com>
tohtana
approved these changes
Sep 27, 2026
tohtana
left a comment
Collaborator
There was a problem hiding this comment.
Hi @jinyouzhi, this looks good to me. Thank you for the improvement!
tohtana
enabled auto-merge
September 27, 2026 21:23
Collaborator
Merged
via the queue into
deepspeedai:master
with commit Sep 27, 2026
016fb76
13 of 15 checks passed
Contributor
Author
Thank you very much! I split #8457 into separate individual PRs to make review easier! I will remove the duplicate parts in #8457. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What breaks
DeepSpeedEngine._backward_prologue()/_backward_epilogue()enter the ZeRO DeepCompile backward hooks whenever DeepCompile is active, exempting only the AutoTP compile pass:With
compile.passes: ["autosp"],engine.compile()installs the AutoSP backend and marks DeepCompile active, so every backward callsdeepcompile_backward_prologue(). That callsget_deepcompile_handle(), which loads (and JIT-builds on first use) the DeepCompile native extension, then callsstart_backward()on it. AutoSP never initializes that runtime (dc.init()is only called on the ZeRO DeepCompile path), so on CUDA this silently loads an unused extension, and on accelerators that cannot build it, backward fails.allreduce_gradients()already usesuses_parallelization_pass_only()(AutoSP or AutoTP) for the same decision; the backward hooks were missed when that helper was introduced.Fix
Use
uses_parallelization_pass_only()in both the backward prologue and epilogue checks. The AutoTP behavior is unchanged.Tests
Added
TestAutoSPEngineBackward::test_backward_skips_zero_deepcompile_hooksintests/unit/v1/compile/test_compile_autosp.py. It builds a ZeRO-0 engine withcompile.passes: ["autosp"], marks DeepCompile active asengine.compile()would, makesget_deepcompile_handle()and the post-backward hooks raise, and runs forward/backward/step.RuntimeError: AutoSP backward must not load the ZeRO DeepCompile runtime)Also ran locally:
tests/unit/compile/test_zero3_grad_dtype.py,tests/unit/compile/test_backend.py, and the rest oftests/unit/v1/compile/test_compile_autosp.py(all IR-level tests pass). The end-to-endTestAutoSPCompilecases fail identically on master and this branch in my environment (torch 2.13, transformers 5.17) during Dynamo tracing of the forward pass, before backward is reached, so they are unrelated to this change.