Skip to content

Scope DeepCompile compiler state to graph and engine lifecycles#8159

Open
tohtana wants to merge 2 commits into
deepspeedai:masterfrom
tohtana:tohtana/deepcompile-compiler-lifecycle-standalone
Open

Scope DeepCompile compiler state to graph and engine lifecycles#8159
tohtana wants to merge 2 commits into
deepspeedai:masterfrom
tohtana:tohtana/deepcompile-compiler-lifecycle-standalone

Conversation

@tohtana

@tohtana tohtana commented Jul 19, 2026

Copy link
Copy Markdown
Collaborator

DeepCompile uses several process-global PyTorch compiler mechanisms while building graph-specific state. Scheduled recompilation also replaces previously compiled graphs.

These lifetimes did not have explicit ownership boundaries.

  • Forward inputs could be consumed by a different graph
  • Dynamo frame IDs could collide across engines
  • Cleanup could either leave graph-specific patches installed or release shared compiler state that another engine still needed

This PR gives those existing mechanisms explicit graph and engine lifecycle ownership.

Fixes:

  • Keep forward inputs in a graph-local one-shot queue and InputStorage.
  • Qualify compiled-backward frames with an owner token and track them per engine.
  • Keep the torch.autograd.Function patch active until the last owned backward frame is released, then clear captured backward inputs.
  • Reference-count the ZeRO-3 Dynamo configuration overrides across engines and restore the original values after the last owner exits.
  • Limit the graph-specific AotAutograd.__init__ patch to the Inductor compilation call and restore it in finally.
  • Release engine-owned compiler state during scheduled recompilation, deactivation, and destruction.

Signed-off-by: Masahiro Tanaka <mtanaka@anyscale.com>
@tohtana
tohtana force-pushed the tohtana/deepcompile-compiler-lifecycle-standalone branch from 0b27f37 to 8f8f693 Compare July 23, 2026 01:01
@tohtana tohtana changed the title Improve DeepCompile compiler lifecycle cleanup Scope DeepCompile compiler state to engine lifecycles Jul 23, 2026
@tohtana tohtana changed the title Scope DeepCompile compiler state to engine lifecycles Scope DeepCompile compiler state to graph and engine lifecycles Jul 23, 2026
@tohtana
tohtana marked this pull request as ready for review July 23, 2026 20:48
@tohtana
tohtana requested review from loadams and tjruwase as code owners July 23, 2026 20:48

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8f8f69327a

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread deepspeed/compile/backend.py
Signed-off-by: Masahiro Tanaka <mtanaka@anyscale.com>
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