Skip to content

Convert fake tensors to detected fake mode in pattern matcher replace_by_example#176938

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

Convert fake tensors to detected fake mode in pattern matcher replace_by_example#176938
frgossen wants to merge 4 commits intogh/frgossen/4/basefrom
gh/frgossen/4/head

Conversation

@frgossen
Copy link
Contributor

@frgossen frgossen commented Mar 9, 2026

Stack from ghstack (oldest at bottom):

When running pre-grad passes outside the fake_mode wrapper in
compile_fx, the fake tensors attached to graph nodes can belong to a
different fake mode than the one active during pattern replacement
tracing. This mismatch triggers the "Mixing fake modes NYI" assertion.

Fix this by detecting the fake mode from the example values in
Match.replace_by_example and converting any fake tensors into that
mode before calling trace_fn. This removes the need for the
wrapped_run_pre_grad_passes shim in compile_fx that previously
papered over the problem by restoring the original fake mode.

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

…_by_example

When running pre-grad passes outside the `fake_mode` wrapper in
`compile_fx`, the fake tensors attached to graph nodes can belong to a
different fake mode than the one active during pattern replacement
tracing. This mismatch triggers the "Mixing fake modes NYI" assertion.

Fix this by detecting the fake mode from the example values in
`Match.replace_by_example` and converting any fake tensors into that
mode before calling `trace_fn`. This removes the need for the
`wrapped_run_pre_grad_passes` shim in `compile_fx` that previously
papered over the problem by restoring the original fake mode.

[ghstack-poisoned]
@frgossen frgossen requested a review from aorenste as a code owner March 9, 2026 21:58
@pytorch-bot
Copy link

pytorch-bot bot commented Mar 9, 2026

🔗 Helpful Links

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

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

✅ You can merge normally! (3 Unrelated Failures)

As of commit e616cfd with merge base e45dfba (image):

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

BROKEN TRUNK - The following job failed but was present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

UNSTABLE - The following job is marked as unstable, possibly due to flakiness on trunk:

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

frgossen added a commit that referenced this pull request Mar 9, 2026
…_by_example

When running pre-grad passes outside the `fake_mode` wrapper in
`compile_fx`, the fake tensors attached to graph nodes can belong to a
different fake mode than the one active during pattern replacement
tracing. This mismatch triggers the "Mixing fake modes NYI" assertion.

Fix this by detecting the fake mode from the example values in
`Match.replace_by_example` and converting any fake tensors into that
mode before calling `trace_fn`. This removes the need for the
`wrapped_run_pre_grad_passes` shim in `compile_fx` that previously
papered over the problem by restoring the original fake mode.

ghstack-source-id: c5c06e4
Pull Request resolved: #176938
@pytorch-bot
Copy link

pytorch-bot bot commented Mar 9, 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 frgossen requested a review from zou3519 March 9, 2026 22:00
@frgossen frgossen added topic: not user facing topic category module: aotdispatch umbrella label for AOTAutograd issues labels Mar 10, 2026
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.

seems reasonable modulo the fx.map_arg comment

…her replace_by_example"

When running pre-grad passes outside the `fake_mode` wrapper in
`compile_fx`, the fake tensors attached to graph nodes can belong to a
different fake mode than the one active during pattern replacement
tracing. This mismatch triggers the "Mixing fake modes NYI" assertion.

Fix this by detecting the fake mode from the example values in
`Match.replace_by_example` and converting any fake tensors into that
mode before calling `trace_fn`. This removes the need for the
`wrapped_run_pre_grad_passes` shim in `compile_fx` that previously
papered over the problem by restoring the original fake mode.

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

[ghstack-poisoned]
frgossen added a commit that referenced this pull request Mar 10, 2026
…_by_example

When running pre-grad passes outside the `fake_mode` wrapper in
`compile_fx`, the fake tensors attached to graph nodes can belong to a
different fake mode than the one active during pattern replacement
tracing. This mismatch triggers the "Mixing fake modes NYI" assertion.

Fix this by detecting the fake mode from the example values in
`Match.replace_by_example` and converting any fake tensors into that
mode before calling `trace_fn`. This removes the need for the
`wrapped_run_pre_grad_passes` shim in `compile_fx` that previously
papered over the problem by restoring the original fake mode.

ghstack-source-id: 33be38c
Pull Request resolved: #176938
@pytorch-bot pytorch-bot bot added the ciflow/torchtitan Run TorchTitan integration tests label Mar 10, 2026
…her replace_by_example"

When running pre-grad passes outside the `fake_mode` wrapper in
`compile_fx`, the fake tensors attached to graph nodes can belong to a
different fake mode than the one active during pattern replacement
tracing. This mismatch triggers the "Mixing fake modes NYI" assertion.

Fix this by detecting the fake mode from the example values in
`Match.replace_by_example` and converting any fake tensors into that
mode before calling `trace_fn`. This removes the need for the
`wrapped_run_pre_grad_passes` shim in `compile_fx` that previously
papered over the problem by restoring the original fake mode.

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

[ghstack-poisoned]
frgossen added a commit that referenced this pull request Mar 10, 2026
…_by_example

When running pre-grad passes outside the `fake_mode` wrapper in
`compile_fx`, the fake tensors attached to graph nodes can belong to a
different fake mode than the one active during pattern replacement
tracing. This mismatch triggers the "Mixing fake modes NYI" assertion.

Fix this by detecting the fake mode from the example values in
`Match.replace_by_example` and converting any fake tensors into that
mode before calling `trace_fn`. This removes the need for the
`wrapped_run_pre_grad_passes` shim in `compile_fx` that previously
papered over the problem by restoring the original fake mode.

ghstack-source-id: 6654245
Pull Request resolved: #176938
…her replace_by_example"

When running pre-grad passes outside the `fake_mode` wrapper in
`compile_fx`, the fake tensors attached to graph nodes can belong to a
different fake mode than the one active during pattern replacement
tracing. This mismatch triggers the "Mixing fake modes NYI" assertion.

Fix this by detecting the fake mode from the example values in
`Match.replace_by_example` and converting any fake tensors into that
mode before calling `trace_fn`. This removes the need for the
`wrapped_run_pre_grad_passes` shim in `compile_fx` that previously
papered over the problem by restoring the original fake mode.

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

[ghstack-poisoned]
frgossen added a commit that referenced this pull request Mar 10, 2026
…_by_example

When running pre-grad passes outside the `fake_mode` wrapper in
`compile_fx`, the fake tensors attached to graph nodes can belong to a
different fake mode than the one active during pattern replacement
tracing. This mismatch triggers the "Mixing fake modes NYI" assertion.

Fix this by detecting the fake mode from the example values in
`Match.replace_by_example` and converting any fake tensors into that
mode before calling `trace_fn`. This removes the need for the
`wrapped_run_pre_grad_passes` shim in `compile_fx` that previously
papered over the problem by restoring the original fake mode.

ghstack-source-id: e36bc0a
Pull Request resolved: #176938
@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 10, 2026
@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

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: inductor topic: not user facing topic category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants