-
Notifications
You must be signed in to change notification settings - Fork 26.3k
[jit] fix handling of function attributes. #28569
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
Previously, the inclusion of function attributes would "poison" a ConcreteModuleType, because we did not have a way of checking whether they are actually the same function. This PR uses the Python function object to perform that check. This improves our ability to reuse JIT types between modules. Also this PR fixes a bug where we weren't properly adding modules as attributes when converting from ConcreteType -> JIT type (we were adding them after the fact--another reason to switch from using `register_x` to `set_x` during module construction, which is on my to-do list after this). Fixes #28559
Previously, the inclusion of function attributes would "poison" a ConcreteModuleType, because we did not have a way of checking whether they are actually the same function. This PR uses the Python function object to perform that check. This improves our ability to reuse JIT types between modules. Also this PR fixes a bug where we weren't properly adding modules as attributes when converting from ConcreteType -> JIT type (we were adding them after the fact--another reason to switch from using `register_x` to `set_x` during module construction, which is on my to-do list after this). Fixes #28559 ghstack-source-id: 50dedca Pull Request resolved: #28569
Previously, the inclusion of function attributes would "poison" a ConcreteModuleType, because we did not have a way of checking whether they are actually the same function. This PR uses the Python function object to perform that check. This improves our ability to reuse JIT types between modules. Also this PR fixes a bug where we weren't properly adding modules as attributes when converting from ConcreteType -> JIT type (we were adding them after the fact--another reason to switch from using `register_x` to `set_x` during module construction, which is on my to-do list after this). Fixes #28559 Differential Revision: [D18111331](https://our.internmc.facebook.com/intern/diff/D18111331)
Previously, the inclusion of function attributes would "poison" a ConcreteModuleType, because we did not have a way of checking whether they are actually the same function. This PR uses the Python function object to perform that check. This improves our ability to reuse JIT types between modules. Also this PR fixes a bug where we weren't properly adding modules as attributes when converting from ConcreteType -> JIT type (we were adding them after the fact--another reason to switch from using `register_x` to `set_x` during module construction, which is on my to-do list after this). Fixes #28559 ghstack-source-id: 44bca50 Pull Request resolved: #28569
| def __init__(self): | ||
| super().__init__() | ||
| encoder_norm = nn.ReLU() | ||
| self.encoder = N(encoder_norm) |
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.
encoder_norm here is a module instead of a function, modules seemed to already work fine
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 my attempt to minify this test case went wrong. I'll add back the function attr
| fn1_mod = M(fn) | ||
| fn2_mod = M(fn) | ||
|
|
||
| self.assertSameType(fn1_mod, fn2_mod) |
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.
Can you add a test that they’re not the same if fn is changed to something else?
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.
that's test_python_function_attribute_different
test/jit/test_type_sharing.py
Outdated
|
|
||
| def test_python_function_attribute_same(self): | ||
| """ | ||
| Different functions passed in should lead to different types |
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.
Different -> same?
| cls->addAttribute(name, type, isParameter); | ||
| } | ||
|
|
||
| for (const auto& moduleInfo : modules_) { |
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 is this adding to cls? Is modules_ all callables attached to this type or is it just sub-ScriptModules?
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's all the submodules
Previously, the inclusion of function attributes would "poison" a ConcreteModuleType, because we did not have a way of checking whether they are actually the same function. This PR uses the Python function object to perform that check. This improves our ability to reuse JIT types between modules. Also this PR fixes a bug where we weren't properly adding modules as attributes when converting from ConcreteType -> JIT type (we were adding them after the fact--another reason to switch from using `register_x` to `set_x` during module construction, which is on my to-do list after this). Fixes #28559 Differential Revision: [D18111331](https://our.internmc.facebook.com/intern/diff/D18111331)
Summary: Pull Request resolved: pytorch#28569 Previously, the inclusion of function attributes would "poison" a ConcreteModuleType, because we did not have a way of checking whether they are actually the same function. This PR uses the Python function object to perform that check. This improves our ability to reuse JIT types between modules. Also this PR fixes a bug where we weren't properly adding modules as attributes when converting from ConcreteType -> JIT type (we were adding them after the fact--another reason to switch from using `register_x` to `set_x` during module construction, which is on my to-do list after this). Fixes pytorch#28559 Test Plan: Imported from OSS Differential Revision: D18111331 Pulled By: suo fbshipit-source-id: ec2cccf832d3ddd4cd4d28fe19cb265f1275325a
Stack from ghstack:
Previously, the inclusion of function attributes would "poison" a
ConcreteModuleType, because we did not have a way of checking whether
they are actually the same function. This PR uses the Python function
object to perform that check. This improves our ability to reuse JIT
types between modules.
Also this PR fixes a bug where we weren't properly adding modules as
attributes when converting from ConcreteType -> JIT type (we were adding
them after the fact--another reason to switch from using
register_xtoset_xduring module construction, which is on my to-do list afterthis).
Fixes #28559
Pull Request resolved: #28569
Differential Revision: D18111331