8000 [invoke_subgraph] Run missing graph passes recursively by anijain2305 · Pull Request #152675 · pytorch/pytorch · GitHub
[go: up one dir, main page]

Skip to content

[invoke_subgraph] Run missing graph passes recursively #152675

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 20 commits into from

Conversation

Copy link
pytorch-bot bot commented May 2, 2025

🔗 Helpful Links

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

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

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

✅ You can merge normally! (5 Unrelated Failures)

As of commit 239dd4e with merge base fdadda2 (image):

BROKEN TRUNK - The following jobs failed but were 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.

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

[ghstack-poisoned]
anijain2305 added a commit that referenced this pull request May 2, 2025
cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx ipiszy chenyang78 kadeng muchulee8 amjames chauhang aakhundov

[ghstack-poisoned]
anijain2305 added a commit that referenced this pull request May 3, 2025
ghstack-source-id: 3cd873c
Pull Request resolved: #152675

[invoke_subgraph] Force the output to have same strides as meta
@pytorch-bot pytorch-bot bot added the release notes: fx release notes category label May 3, 2025
cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx ipiszy chenyang78 kadeng muchulee8 amjames chauhang aakhundov

[ghstack-poisoned]
anijain2305 added a commit that referenced this pull request May 4, 2025
ghstack-source-id: 2e1732a
Pull Request resolved: #152675

[invoke_subgraph] Force the output to have same strides as meta
@anijain2305 anijain2305 added the topic: not user facing topic category label May 4, 2025
cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx ipiszy chenyang78 kadeng muchulee8 amjames chauhang aakhundov

[ghstack-poisoned]
anijain2305 added a commit that referenced this pull request May 4, 2025
ghstack-source-id: 129dff9
Pull Request resolved: #152675

[invoke_subgraph] Force the output to have same strides as meta
cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx ipiszy chenyang78 kadeng muchulee8 amjames chauhang aakhundov

[ghstack-poisoned]
anijain2305 added a commit that referenced this pull request May 4, 2025
ghstack-source-id: f46fc0e
Pull Request resolved: #152675

[invoke_subgraph] Force the output to have same strides as meta
cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx ipiszy chenyang78 kadeng muchulee8 amjames chauhang aakhundov

[ghstack-poisoned]
anijain2305 added a commit that referenced this pull request May 4, 2025
ghstack-source-id: b0a382c
Pull Request resolved: #152675

[invoke_subgraph] Force the output to have same strides as meta
cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx ipiszy chenyang78 kadeng muchulee8 amjames chauhang aakhundov

[ghstack-poisoned]
anijain2305 added a commit that referenced this pull request May 4, 2025
ghstack-source-id: 4be8784
Pull Request resolved: #152675

[invoke_subgraph] Force the output to have same strides as meta
cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx ipiszy chenyang78 kadeng muchulee8 amjames chauhang aakhundov

[ghstack-poisoned]
anijain2305 added a commit that referenced this pull request May 4, 2025
ghstack-source-id: 4be8784
Pull Request resolved: #152675

[invoke_subgraph] Force the output to have same strides as meta
cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx ipiszy chenyang78 kadeng muchulee8 amjames chauhang aakhundov

[ghstack-poisoned]
anijain2305 added a commit that referenced this pull request May 5, 2025
ghstack-source-id: 48ffd03
Pull Request resolved: #152675

[invoke_subgraph] Force the output to have same strides as meta
cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx ipiszy chenyang78 kadeng muchulee8 amjames chauhang aakhundov

[ghstack-poisoned]
cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx ipiszy chenyang78 kadeng muchulee8 amjames chauhang aakhundov

[ghstack-poisoned]
@@ -1207,6 +1207,15 @@ def view_to_reshape(gm):
):
nd.target = torch.ops.aten.reshape.default

subgraph_names: OrderedSet[str] = OrderedSet()
Copy link
Contributor
@bdhirsh bdhirsh May 5, 2025

Choose a reason for hiding this comment

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

more of a general question - we're probably going to have to audit the other one-off passes that inductor runs and ensure that they recurse too, right? I wonder if we can add some more invariants / refactor inductor's one-off passes so that they get this recursive behavior more automatically, for future graph-pass-writers (maybe worth filing a BE issue?)

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 - can we refactor GraphTransformObserver so it applies the passes to subgraphs automatically ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, is my main concern. And the only way I did this today is by taking 4 models and ensuring that full model invoke_subgraph has same kernels as the baseline. This is definitely not exhaustive.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@eellison This one is run outside of post_grad, so we dont use GraphTransformObserver here.

example_inputs.append(operand.meta["val"])
return FakeTensorProp(
getattr(self.module, n.args[0].target), mode=self._mode
).propagate(*example_inputs)
Copy link
Contributor

Choose a reason for hiding this comment

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

This reminds me - inductor also has a way of doing incremental faketensor updates through FakeTensorUpdater.incremental_update. The incremental updater might not know to properly perform incremental updates on subgraphs as well today, which could lead to silent correctness? https://github.com/pytorch/pytorch/blob/main/torch/_inductor/fx_utils.py#L153

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I checked that one. So anything which is run during post_grad pass, we will recurse.

view_to_reshape is outside of post_grad. Therefore, we need this PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

FakeTensorUpdater doesn't work on HOPs, we should fix that at some point

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

[ghstack-poisoned]
cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx ipiszy chenyang78 kadeng muchulee8 amjames chauhang aakhundov

[ghstack-poisoned]
cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx ipiszy chenyang78 kadeng muchulee8 amjames chauhang aakhundov

[ghstack-poisoned]
cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx ipiszy chenyang78 kadeng muchulee8 amjames chauhang aakhundov

[ghstack-poisoned]
@anijain2305
Copy link
Contributor Author

@pytorchbot merge -i

F438
@pytorch-bot pytorch-bot bot added the ciflow/trunk Trigger trunk jobs on your pull request label May 5, 2025
@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged while ignoring the following 3 checks: Lint / Link checks / Lint URLs / linux-job, inductor / cuda12.6-py3.10-gcc9-sm86 / test (inductor_torchbench, 2, 2, ephemeral.linux.g5.4xlarge.nvidia.gpu), inductor / cuda12.6-py3.10-gcc9-sm86 / test (inductor_torchbench, 1, 2, ephemeral.linux.g5.4xlarge.nvidia.gpu)

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
Collaborator

Merge failed

Reason: 1 jobs have failed, first few of them are: inductor / unit-test / cuda12.6-py3.10-gcc9-sm86 / test (inductor_cpp_wrapper, 1, 2, ephemeral.linux.g5.4xlarge.nvidia.gpu)

Details for Dev Infra team Raised by workflow job

@anijain2305
Copy link
Contributor Author

@pytorchbot merge -i

Comment on lines +1205 to +1211
subgraph_names: OrderedSet[str] = OrderedSet(
x.target for x in gm.graph.find_nodes(op="get_attr")
)

for child_name, child_mod in gm.named_children():
if child_name in subgraph_names and isinstance(child_mod, torch.fx.GraphModule):
view_to_reshape(child_mod)
Copy link
Contributor

Choose a reason for hiding this comment

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

I would prefer some automated way of doing this, like GraphTransformObserver accepts view_to_reshape and then automatically applies the pass to subgraphs.

How many more times do we need to do this manually?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
0