Skip to content

[dynamo] Don't call the backend for a graph that computes nothing - #193157

Closed
anijain2305 wants to merge 7 commits into
gh/anijain2305/1302/basefrom
gh/anijain2305/1302/head
Closed

anijain2305 wants to merge 7 commits into
gh/anijain2305/1302/basefrom
gh/anijain2305/1302/head

Conversation

@anijain2305

@anijain2305 anijain2305 commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

A frame can reach the backend with the graph

class GraphModule(torch.nn.Module):
    def forward(self):
        return ()

and pay a full AOTAutograd pass for it: a metadata collection, a joint trace,
an AOTAutograd cache miss and the artifact dumping that goes with them. In one
model, a frame does exactly this, costing 0.2s of AOTAutograd and about 0.9s of
surrounding compile work.

compile_and_call_fx_graph already bails out for an empty graph, but it checks
before pruning: the frame is compiled because it has outputs, and
remove_unused_graphargs plus DCE then establish that every output is an input or
a constant that codegen emits directly, leaving nothing behind. Check again once
the graph is final, just before handing it to the user compiler, and substitute
a stub that returns an empty tuple.

The predicate deliberately requires both no call nodes and no output leaves, so
a graph with a single op, or one that only passes an input through, still goes
to the backend. It is weaker than OutputGraph.is_empty_graph, which wants a
graph with no nodes at all and so does not recognize this shape.

Test plan:

python test/dynamo/test_misc.py
python test/dynamo/test_repros.py

Both match a run with the change stashed. Verified that the frame's AOTAutograd
artifacts (aotautograd_cache_miss, before/after_joint_graph,
aot_inference_graph, runtime_wrapper_orchestration) are gone from the tlparse
output while the rest of the compile is unchanged.

This PR was authored with the assistance of an AI coding agent.

cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @kadeng @chauhang @amjames @jataylo @azahed98

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Aug 12, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/193157

Note: Links to docs will display an error until the docs builds have been completed.

✅ You can merge normally! (1 Unrelated Failure)

As of commit c9f253f with merge base bc18429 (image):

FLAKY - The following job failed but was likely due to flakiness present on trunk:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@pytorch-bot pytorch-bot Bot added ciflow/inductor ciflow/torchtitan Run TorchTitan integration tests module: dynamo labels Aug 12, 2026
anijain2305 added a commit that referenced this pull request Aug 12, 2026
A frame can reach the backend with the graph

    class GraphModule(torch.nn.Module):
        def forward(self):
            return ()

and pay a full AOTAutograd pass for it: a metadata collection, a joint trace,
an AOTAutograd cache miss and the artifact dumping that goes with them. In
FairChem UMA one frame does exactly this, costing 0.2s of AOTAutograd and about
0.9s of surrounding compile work.

compile_and_call_fx_graph already bails out for an empty graph, but it checks
before pruning: the frame is compiled because it has outputs, and
remove_unused_graphargs plus DCE then establish that every output is an input or
a constant that codegen emits directly, leaving nothing behind. Check again once
the graph is final, just before handing it to the user compiler, and substitute
a stub that returns an empty tuple.

The predicate deliberately requires both no call nodes and no output leaves, so
a graph with a single op, or one that only passes an input through, still goes
to the backend. It is weaker than OutputGraph.is_empty_graph, which wants a
graph with no nodes at all and so does not recognize this shape.

Test plan:

```
python test/dynamo/test_misc.py
python test/dynamo/test_repros.py
```

Both match a run with the change stashed. Verified on UMA that the frame's
AOTAutograd artifacts (aotautograd_cache_miss, before/after_joint_graph,
aot_inference_graph, runtime_wrapper_orchestration) are gone from the tlparse
output while the rest of the compile is unchanged.

This PR was authored with the assistance of an AI coding agent.


ghstack-source-id: c2d90a1
Pull-Request: #193157
@anijain2305
anijain2305 requested review from guilhermeleobas, mlazos and williamwen42 and removed request for guilhermeleobas August 12, 2026 13:47
@anijain2305 anijain2305 added ciflow/trunk Trigger trunk jobs on your pull request topic: not user facing topic category labels Aug 12, 2026
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
@anijain2305

Copy link
Copy Markdown
Contributor Author

@pytorchbot merge

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: 1 jobs have failed, first few of them are: Check mergeability of ghstack PR / ghstack-mergeability-check

Details for Dev Infra team Raised by workflow job

[ghstack-poisoned]
@anijain2305

Copy link
Copy Markdown
Contributor Author

@pytorchbot merge

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

orrangetabby17 pushed a commit to orrangetabby17/pytorch that referenced this pull request Sep 2, 2026
…torch#193157)

A frame can reach the backend with the graph

    class GraphModule(torch.nn.Module):
        def forward(self):
            return ()

and pay a full AOTAutograd pass for it: a metadata collection, a joint trace,
an AOTAutograd cache miss and the artifact dumping that goes with them. In one
model, a frame does exactly this, costing 0.2s of AOTAutograd and about 0.9s of
surrounding compile work.

compile_and_call_fx_graph already bails out for an empty graph, but it checks
before pruning: the frame is compiled because it has outputs, and
remove_unused_graphargs plus DCE then establish that every output is an input or
a constant that codegen emits directly, leaving nothing behind. Check again once
the graph is final, just before handing it to the user compiler, and substitute
a stub that returns an empty tuple.

The predicate deliberately requires both no call nodes and no output leaves, so
a graph with a single op, or one that only passes an input through, still goes
to the backend. It is weaker than OutputGraph.is_empty_graph, which wants a
graph with no nodes at all and so does not recognize this shape.

Test plan:

```
python test/dynamo/test_misc.py
python test/dynamo/test_repros.py
```

Both match a run with the change stashed. Verified that the frame's AOTAutograd
artifacts (aotautograd_cache_miss, before/after_joint_graph,
aot_inference_graph, runtime_wrapper_orchestration) are gone from the tlparse
output while the rest of the compile is unchanged.

This PR was authored with the assistance of an AI coding agent.

Pull Request resolved: pytorch#193157
Approved by: https://github.com/mlazos
@github-actions
github-actions Bot deleted the gh/anijain2305/1302/head branch November 5, 2026 01:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/inductor ciflow/torchtitan Run TorchTitan integration tests ciflow/trunk Trigger trunk jobs on your pull request Merged module: dynamo topic: not user facing topic category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants