-
Notifications
You must be signed in to change notification settings - Fork 26.3k
Code motion CompiledFxGraph to a dedicated file #141654
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
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/141654
Note: Links to docs will display an error until the docs builds have been completed. ✅ You can merge normally! (2 Unrelated Failures)As of commit 197cc26 with merge base 4c1f50a ( UNSTABLE - The following jobs failed but were likely due to flakiness present on trunk and has been marked as unstable:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
Signed-off-by: Edward Z. Yang <[email protected]> ghstack-source-id: 3bcb4b1 Pull Request resolved: #141654
| # python test/inductor/test_codecache.py | ||
| # TestFxGraphCache.test_constant_handling_device_cpu | ||
| # TODO: Why are we monkeypatching it...... | ||
| import torch._inductor.output_code as output_code |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@masnesral you added the test in question, is there really no way to do it without monkeypatching?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can get the testing I want more directly from another test in that same file: #141898
| @@ -0,0 +1,179 @@ | |||
| """ | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This stuff is new and explains the motivation for code motion
| class OutputCode(Protocol): | ||
| def __call__(self, inputs: Sequence[Any]) -> Any: | ||
| ... | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything below is code movement only
|
|
||
|
|
||
| def _typecheck_CompiledFxGraph(h: CompiledFxGraph) -> OutputCode: | ||
| return h |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Except this, this is new
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe put this in an if TYPE_CHECKING block along w/ a comment that it's just used to verify that CompiledFxGraph implements the OutputCode protocol.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, there's an interesting idea. I'll do it in follow up (there are a few other places I did this pattern too)
Signed-off-by: Edward Z. Yang <[email protected]> ghstack-source-id: c5c09cb Pull Request resolved: #141654
Signed-off-by: Edward Z. Yang <[email protected]> ghstack-source-id: c5c09cb Pull Request resolved: #141654
Signed-off-by: Edward Z. Yang <[email protected]> ghstack-source-id: c5c09cb Pull Request resolved: #141654
Signed-off-by: Edward Z. Yang <[email protected]> ghstack-source-id: c5c09cb Pull Request resolved: #141654
Signed-off-by: Edward Z. Yang <[email protected]> ghstack-source-id: c5c09cb Pull Request resolved: #141654
Signed-off-by: Edward Z. Yang <[email protected]> ghstack-source-id: c5c09cb Pull Request resolved: #141654
| _StrideExprStr: TypeAlias = str | ||
|
|
||
|
|
||
| def has_frozen_params(gm: torch.fx.GraphModule) -> bool: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why isn't this just a method on GraphModule?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It probably shouldn't live straight on GraphModule, because it's a very Inductor specific concept. But the real reason is I was just shoving code around lol.
|
|
||
|
|
||
| def _typecheck_CompiledFxGraph(h: CompiledFxGraph) -> OutputCode: | ||
| return h |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe put this in an if TYPE_CHECKING block along w/ a comment that it's just used to verify that CompiledFxGraph implements the OutputCode protocol.
| from .triton_bundler import TritonKernelArtifacts | ||
|
|
||
|
|
||
| class OutputCode(Protocol): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's a protocol?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Structural subtyping (duck typing). You're basically saying "I take/return something that looks like this" without having to use inheritance to force the things to actually be related.
Signed-off-by: Edward Z. Yang <[email protected]> ghstack-source-id: c5c09cb Pull Request resolved: #141654
|
@pytorchbot merge -i |
Merge startedYour change will be merged while ignoring the following 2 checks: inductor / cuda12.1-py3.10-gcc9-sm86 / test (inductor_timm, 1, 2, linux.g5.4xlarge.nvidia.gpu), inductor / cuda12.4-py3.10-gcc9-sm86 / test (inductor_timm, 1, 2, linux.g5.4xlarge.nvidia.gpu, unstable) Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
Signed-off-by: Edward Z. Yang <[email protected]> Pull Request resolved: pytorch#141654 Approved by: https://github.com/aorenste, https://github.com/jansel ghstack dependencies: pytorch#141491, pytorch#141492, pytorch#141574
Signed-off-by: Edward Z. Yang <[email protected]> ghstack-source-id: c5c09cb Pull Request resolved: pytorch/pytorch#141654
Stack from ghstack (oldest at bottom):
Signed-off-by: Edward Z. Yang [email protected]
cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @yf225 @chenyang78 @kadeng @muchulee8 @ColinPeppler @amjames @desertfire @chauhang @aakhundov