-
Notifications
You must be signed in to change notification settings - Fork 26.3k
[jit] Fix reflection on weak modules, copy attributes #20190
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
* Constructs a new type at runtime so that `isinstance` checks work for weak modules assigned to `ScriptModule`s * Register `int`, `float`, `str`, and `bool` properties of `nn.Module` classes as attributes of the corresponding weak module * Fix some issues where `bias` was added to `__constants__` even though it's a parameter
eellison
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.
Looks good, have a couple of qauestions
| >>> print(output.size()) | ||
| torch.Size([128, 30]) | ||
| """ | ||
| __constants__ = ['bias', 'in_features', 'out_features'] |
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.
Not related to this diff but: how did this work without constants previously? Should there have been a test failure somewhere that didn't happen?
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.
They're not actually used in nn.Linear except in __repr__
| return getattr(self.__dict__["_original"](), attr) | ||
| # unwrap the original | ||
| original_module = self.__dict__["_original"]() | ||
| if original_module and self.__dict__["_initialized"]: |
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 do we need the "initialized" check here?
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.
So the __getattr__ only looks at the original model after __init__ is done
isinstancechecks work forweak modules assigned to
ScriptModules__constants__in_featuresandout_featurestonn.Linear__constants__Fixes #19363
Differential Revision: D15302350