-
Notifications
You must be signed in to change notification settings - Fork 26.3k
[inductor] Refactor MutableBox to make IRNode typing easier #140895
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/140895
Note: Links to docs will display an error until the docs builds have been completed. ❗ 1 Active SEVsThere are 1 currently active SEVs. If your PR is affected, please view them below: ✅ No FailuresAs of commit 85dbca2 with merge base 260d1dc ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
| def __getattr__(self, name): # type: ignore[no-untyped-def] | ||
| fn = getattr(self.data, name) | ||
| if callable(fn): | ||
| return fn | ||
| raise AttributeError(f"{type(self.data).__name__}.{name} not callable") |
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.
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.
Yay!
ezyang
left a comment
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.
Thankssss
| size = input_node.get_size() | ||
| reduction_size = input_node.get_reduction_size() | ||
| size = [*input_node.get_size()] | ||
| reduction_size = [*input_node.get_reduction_size()] |
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.
Curious, is this equivalent to list(...)?
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.
Yeah curious what the motivation here is for this. It should actually be marginally less efficient than the ctor list method, shouldn't it?
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 is faster (for small lists) and looks cleaner IMO:
>>> timeit.timeit("list(range(10))")
0.12816928839311004
>>> timeit.timeit("[*range(10)]")
0.11478627705946565
>>>
list gets mapped to a LOAD_GLOBAL bytecode (since you could do list = tuple in global scope), while [*x] gets mapped to list-specific bytecodes without touching global scope.
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.
@ezyang @Skylion007 maybe we should add a rule to automate this change?
| continue | ||
| op = buffer.get_defining_op() | ||
| if op is None: | ||
| if op is None or isinstance(op, ExternKernel): |
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.
:0
| ): | ||
| def inner(*inputs: List[TensorBox], alpha=None): | ||
| if triton_fallback is not None and any(map(is_triton, inputs)): | ||
| def inner(*inputs: TensorBox, alpha=None): |
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.
lol whoops
| if triton_fallback is not None and any(map(is_triton, inputs)): | ||
| def inner(*inputs: TensorBox, alpha=None): | ||
| if triton_fallback is not None and any( | ||
| isinstance(inp, IRNode) and is_triton(inp) for inp in inputs |
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.
Huh, when is inp not an IRNode?
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.
Usually it is an int/float/None/etc.
| def codegen(self) -> None: | ||
| assert isinstance(self.node, ir.ComputedBuffer), f"{type(self.node)=}" | ||
| self.node.get_store_function()(self.node.make_loader()()) | ||
| raise NotImplementedError |
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.
:0
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.
Was unused code (with incorrect num args to make_loader())
torch/_inductor/ir.py
Outdated
| elif isinstance(x, IRNode): | ||
| try: | ||
| return x.get_device().type | ||
| except NoDevice: |
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.
:0
| raise NoDevice(f"{self.__class__.__name__} does not implement get_device()") | ||
|
|
||
| def has_exceeded_max_reads(self) -> bool: | ||
| raise NotImplementedError(type(self).__name__) |
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 don't think commit should change this, but would it be better for these to return NotImplemented instead, so that a catch isn't required from call sites? Not sure...
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.
Yeah, I think we could also move some more stuff to the base class (and other stuff down to only on subclasses) -- but that would be for another PR.
| def __getattr__(self, name): # type: ignore[no-untyped-def] | ||
| fn = getattr(self.data, name) | ||
| if callable(fn): | ||
| return fn | ||
| raise AttributeError(f"{type(self.data).__name__}.{name} not callable") |
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.
Yay!
|
@pytorchbot merge |
Merge startedYour 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 |
|
@pytorchbot merge |
Merge startedYour 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 |
This separate the concepts of a Layout (size/stride/etc) and an OutputSpec (which includes multiple outputs). Which should make typing easier. Pull Request resolved: #140910 Approved by: https://github.com/ezyang ghstack dependencies: #140895
Pull Request resolved: #140912 Approved by: https://github.com/aorenste ghstack dependencies: #140895, #140910
…ytorch#140895)" This reverts commit c79e78b. Reverted pytorch#140895 on behalf of https://github.com/huydhn due to Sorry for reverting your change but I think test_torchbind_inductor is failing in trunk after this lands ([comment](pytorch#140895 (comment)))
This separate the concepts of a Layout (size/stride/etc) and an OutputSpec (which includes multiple outputs). Which should make typing easier. Pull Request resolved: pytorch#140910 Approved by: https://github.com/ezyang ghstack dependencies: pytorch#140895
Pull Request resolved: pytorch#140912 Approved by: https://github.com/aorenste ghstack dependencies: pytorch#140895, pytorch#140910
Stack from ghstack (oldest at bottom):
cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @yf225 @chenyang78 @kadeng @muchulee8 @ColinPeppler @amjames @desertfire @chauhang @aakhundov