Skip to content

Add pre_grad_pass_timing config for early vs late pre-grad passes#177429

Closed
frgossen wants to merge 12 commits intogh/frgossen/12/basefrom
gh/frgossen/12/head
Closed

Add pre_grad_pass_timing config for early vs late pre-grad passes#177429
frgossen wants to merge 12 commits intogh/frgossen/12/basefrom
gh/frgossen/12/head

Conversation

@frgossen
Copy link
Contributor

@frgossen frgossen commented Mar 13, 2026

Stack from ghstack (oldest at bottom):

Add a pre_grad_pass_timing config ("early", "late", or "default") that
controls when pre-grad passes run relative to the AOT autograd cache lookup.

  • "early": passes run before cache lookup, so they execute on every compile
    (including cache hits) and the cache key reflects the already-transformed
    graph.
  • "late": passes run after cache lookup (only on cache miss); requires
    custom passes to provide a UUID for the cache key.
  • "default": automatically resolves to "late" when possible (no custom pass,
    or a custom pass with a UUID), and falls back to "early" when the custom
    pass has no UUID.

Explicitly setting "late" with a UUID-less custom pass now raises a
RuntimeError instead of silently bypassing the cache. The existing
test_pre_grad_passes_called_on_cache_miss_only test is renamed and
pinned to "late" timing, and new tests cover early timing, both default
timing branches, and the error case.

cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @chauhang @aakhundov @coconutruben @jataylo @Lucaskabela

Allow pre-grad passes to run before the AOT autograd cache lookup
("early") instead of only after it on cache miss ("late", the default).
With "early" timing the cache key reflects the already-transformed graph
and passes always execute, even on cache hits.

[ghstack-poisoned]
@pytorch-bot
Copy link

pytorch-bot bot commented Mar 13, 2026

🔗 Helpful Links

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

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

⏳ No Failures, 1 Pending

As of commit 67ad41f with merge base 6a461fe (image):
💚 Looks good so far! There are no failures yet. 💚

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

@pytorch-bot
Copy link

pytorch-bot bot commented Mar 13, 2026

This PR needs a release notes: label

If your changes are user facing and intended to be a part of release notes, please use a label starting with release notes:.

If not, please add the topic: not user facing label.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "topic: not user facing"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

frgossen added a commit that referenced this pull request Mar 13, 2026
Allow pre-grad passes to run before the AOT autograd cache lookup
("early") instead of only after it on cache miss ("late", the default).
With "early" timing the cache key reflects the already-transformed graph
and passes always execute, even on cache hits.

ghstack-source-id: 8690d1e
Pull Request resolved: #177429
@frgossen frgossen requested review from zou3519 and removed request for bdhirsh March 13, 2026 22:04
Copy link
Contributor

@aorenste aorenste left a comment

Choose a reason for hiding this comment

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

Is it missing a test for caching "early" + UUID?

Maybe minor/not worth changing: After this change, won't an "early" pass's UUID will be part of the cache key? That means that if a pass ends up being a no-op it can't share a cache entry with a run without that pass. But not including the UUID is actually safe because the cache key is based on the pre-cache graph structure.

… passes"

Allow pre-grad passes to run before the AOT autograd cache lookup
("early") instead of only after it on cache miss ("late", the default).
With "early" timing the cache key reflects the already-transformed graph
and passes always execute, even on cache hits.

cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx ipiszy kadeng muchulee8 amjames chauhang aakhundov coconutruben jataylo Lucaskabela

[ghstack-poisoned]
frgossen added a commit that referenced this pull request Mar 17, 2026
Allow pre-grad passes to run before the AOT autograd cache lookup
("early") instead of only after it on cache miss ("late", the default).
With "early" timing the cache key reflects the already-transformed graph
and passes always execute, even on cache hits.

ghstack-source-id: 0b0e8fc
Pull Request resolved: #177429
… passes"

Allow pre-grad passes to run before the AOT autograd cache lookup
("early") instead of only after it on cache miss ("late", the default).
With "early" timing the cache key reflects the already-transformed graph
and passes always execute, even on cache hits.

cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx ipiszy kadeng muchulee8 amjames chauhang aakhundov coconutruben jataylo Lucaskabela

[ghstack-poisoned]
frgossen added a commit that referenced this pull request Mar 17, 2026
Allow pre-grad passes to run before the AOT autograd cache lookup
("early") instead of only after it on cache miss ("late", the default).
With "early" timing the cache key reflects the already-transformed graph
and passes always execute, even on cache hits.

ghstack-source-id: f257cef
Pull Request resolved: #177429
… passes"

Allow pre-grad passes to run before the AOT autograd cache lookup
("early") instead of only after it on cache miss ("late", the default).
With "early" timing the cache key reflects the already-transformed graph
and passes always execute, even on cache hits.

cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx ipiszy kadeng muchulee8 amjames chauhang aakhundov coconutruben jataylo Lucaskabela

[ghstack-poisoned]
frgossen added a commit that referenced this pull request Mar 17, 2026
Allow pre-grad passes to run before the AOT autograd cache lookup
("early") instead of only after it on cache miss ("late", the default).
With "early" timing the cache key reflects the already-transformed graph
and passes always execute, even on cache hits.

ghstack-source-id: 21013bf
Pull Request resolved: #177429
… passes"

Allow pre-grad passes to run before the AOT autograd cache lookup
("early") instead of only after it on cache miss ("late", the default).
With "early" timing the cache key reflects the already-transformed graph
and passes always execute, even on cache hits.

cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx ipiszy kadeng muchulee8 amjames chauhang aakhundov coconutruben jataylo Lucaskabela

[ghstack-poisoned]
frgossen added a commit that referenced this pull request Mar 17, 2026
Allow pre-grad passes to run before the AOT autograd cache lookup
("early") instead of only after it on cache miss ("late", the default).
With "early" timing the cache key reflects the already-transformed graph
and passes always execute, even on cache hits.

ghstack-source-id: bea0a46
Pull Request resolved: #177429
… passes"

Allow pre-grad passes to run before the AOT autograd cache lookup
("early") instead of only after it on cache miss ("late", the default).
With "early" timing the cache key reflects the already-transformed graph
and passes always execute, even on cache hits.

cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx ipiszy kadeng muchulee8 amjames chauhang aakhundov coconutruben jataylo Lucaskabela

[ghstack-poisoned]
frgossen added a commit that referenced this pull request Mar 17, 2026
Allow pre-grad passes to run before the AOT autograd cache lookup
("early") instead of only after it on cache miss ("late", the default).
With "early" timing the cache key reflects the already-transformed graph
and passes always execute, even on cache hits.

ghstack-source-id: 3705010
Pull Request resolved: #177429
@frgossen
Copy link
Contributor Author

Is it missing a test for caching "early" + UUID?

Maybe minor/not worth changing: After this change, won't an "early" pass's UUID will be part of the cache key? That means that if a pass ends up being a no-op it can't share a cache entry with a run without that pass. But not including the UUID is actually safe because the cache key is based on the pre-cache graph structure.

Good point. Put the pre-grad cache key contribution behind the timing config.

… passes"

Allow pre-grad passes to run before the AOT autograd cache lookup
("early") instead of only after it on cache miss ("late", the default).
With "early" timing the cache key reflects the already-transformed graph
and passes always execute, even on cache hits.

cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx ipiszy kadeng muchulee8 amjames chauhang aakhundov coconutruben jataylo Lucaskabela

[ghstack-poisoned]
frgossen added a commit that referenced this pull request Mar 17, 2026
Allow pre-grad passes to run before the AOT autograd cache lookup
("early") instead of only after it on cache miss ("late", the default).
With "early" timing the cache key reflects the already-transformed graph
and passes always execute, even on cache hits.

ghstack-source-id: 8519814
Pull Request resolved: #177429
… passes"

Allow pre-grad passes to run before the AOT autograd cache lookup
("early") instead of only after it on cache miss ("late", the default).
With "early" timing the cache key reflects the already-transformed graph
and passes always execute, even on cache hits.

cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx ipiszy kadeng muchulee8 amjames chauhang aakhundov coconutruben jataylo Lucaskabela

[ghstack-poisoned]
… passes"

Allow pre-grad passes to run before the AOT autograd cache lookup
("early") instead of only after it on cache miss ("late", the default).
With "early" timing the cache key reflects the already-transformed graph
and passes always execute, even on cache hits.

cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx ipiszy kadeng muchulee8 amjames chauhang aakhundov coconutruben jataylo Lucaskabela

[ghstack-poisoned]
@frgossen frgossen added the module: aotdispatch umbrella label for AOTAutograd issues label Mar 17, 2026
@frgossen
Copy link
Contributor Author

@pytorchbot merge

@pytorch-bot pytorch-bot bot added the ciflow/trunk Trigger trunk jobs on your pull request label Mar 18, 2026
@pytorchmergebot
Copy link
Collaborator

Merge failed

Reason: This PR needs a release notes: label
If your changes are user facing and intended to be a part of release notes, please use a label starting with release notes:.

If not, please add the topic: not user facing label.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "topic: not user facing"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

Details for Dev Infra team Raised by workflow job

@pytorch-bot
Copy link

pytorch-bot bot commented Mar 18, 2026

This PR needs a release notes: label

If your changes are user facing and intended to be a part of release notes, please use a label starting with release notes:.

If not, please add the topic: not user facing label.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "topic: not user facing"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

… passes"

Allow pre-grad passes to run before the AOT autograd cache lookup
("early") instead of only after it on cache miss ("late", the default).
With "early" timing the cache key reflects the already-transformed graph
and passes always execute, even on cache hits.

cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx ipiszy kadeng muchulee8 amjames chauhang aakhundov coconutruben jataylo Lucaskabela

[ghstack-poisoned]
Copy link
Contributor

@zou3519 zou3519 left a comment

Choose a reason for hiding this comment

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

lgtm but please read comments

… passes"

Allow pre-grad passes to run before the AOT autograd cache lookup
("early") instead of only after it on cache miss ("late", the default).
With "early" timing the cache key reflects the already-transformed graph
and passes always execute, even on cache hits.

cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx ipiszy kadeng muchulee8 amjames chauhang aakhundov coconutruben jataylo Lucaskabela

[ghstack-poisoned]
… passes"

Allow pre-grad passes to run before the AOT autograd cache lookup
("early") instead of only after it on cache miss ("late", the default).
With "early" timing the cache key reflects the already-transformed graph
and passes always execute, even on cache hits.

cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx ipiszy kadeng muchulee8 amjames chauhang aakhundov coconutruben jataylo Lucaskabela

[ghstack-poisoned]
@frgossen
Copy link
Contributor Author

@pytorchbot merge

@pytorchmergebot
Copy link
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

ryanzhang22 pushed a commit to ryanzhang22/pytorch that referenced this pull request Mar 19, 2026
…torch#177429)

Add a pre_grad_pass_timing config ("early", "late", or "default") that
controls when pre-grad passes run relative to the AOT autograd cache lookup.

- "early": passes run before cache lookup, so they execute on every compile
(including cache hits) and the cache key reflects the already-transformed
graph.
- "late": passes run after cache lookup (only on cache miss); requires
custom passes to provide a UUID for the cache key.
- "default": automatically resolves to "late" when possible (no custom pass,
or a custom pass with a UUID), and falls back to "early" when the custom
pass has no UUID.

Explicitly setting "late" with a UUID-less custom pass now raises a
RuntimeError instead of silently bypassing the cache. The existing
test_pre_grad_passes_called_on_cache_miss_only test is renamed and
pinned to "late" timing, and new tests cover early timing, both default
timing branches, and the error case.

Pull Request resolved: pytorch#177429
Approved by: https://github.com/aorenste, https://github.com/zou3519
ghstack dependencies: pytorch#177397, pytorch#177403, pytorch#177428
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: aotdispatch umbrella label for AOTAutograd issues module: dynamo module: inductor release notes: aotdispatcher

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants