-
Notifications
You must be signed in to change notification settings - Fork 26.3k
Added super init to Module #91819
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
Added super init to Module #91819
Conversation
Added super init to Module for user modules derived from multiple python classes
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/91819
Note: Links to docs will display an error until the docs builds have been completed. ❌ 6 FailuresAs of commit 77cdda8: NEW FAILURES - The following jobs have failed:
BROKEN TRUNK - The following jobs failed but were present on the merge base 438f12d:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
|
albanD
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.
We tried this before and it was reverted: #74036
I can check what is the status now.
|
@albanD has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
|
I see (#74036). I did first try to check what happens when I put the I also understand your opinion on providing args and kwargs to the super class. We can probably still add |
albanD
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.
In general, this is BC-breaking for anyone that is currently doing mixin of nn.Module and working around the lack of super() init() manually...
I guess that is ok to break as it is an explicit error
|
if approved, then it can be in the docs of OR to help everyone with huge library's and any error due to this change. Something maybe like this: class Module:
_call_super: bool = True #deprecated in future
def __init__(self, *args, **kwargs) -> None:
......
......
if Module._call_super:
super().__init__(*args, **kwargs)in this way anyone can disable the import torch
torch.nn.Module._call_super = FalseLet me know if you want me to implement this. 🙂 |
|
I like this idea of having a class attribute to control this behavior as a way to make the transition smoother. Could you add this new class attribute and make it False by default. We can do a follow up, BC-breaking, PR that switch the default behavior to True. |
default value for call_super_init is False
|
Added |
Signed-off-by: Vivswan Shah <58091053+Vivswan@users.noreply.github.com>
albanD
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.
The change looks good to me. Could you just add a test in test/test_nn.py to make sure it does the right thing when a subclass sets this flag to True please and then we can merge this!
|
@albanD has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
|
Can you give me a link to documentation, how to create tests for pytorch? |
|
Ho I'm not sure we have doc for that :/ Line 165 in cf5a40c
Call it |
|
The test failures are relevant. Not sure why at a glance... |
|
All the failed test are coming from the following code, since now we do accept pytorch/test/test_module_init.py Lines 416 to 419 in 6f1727b
Either we can change this test |
|
Ho that is interesting haha |
|
@albanD has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
|
Looks good! |
|
@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 |
Merge failedReason: 1 jobs have failed, first few of them are: trunk / win-vs2019-cuda11.6-py3 / test (default, 3, 5, windows.g5.4xlarge.nvidia.gpu) Details for Dev Infra teamRaised by workflow job |
|
@pytorchbot merge -f "Flaky test" |
Merge startedYour change will be merged immediately since you used the force (-f) flag, bypassing any CI checks (ETA: 1-5 minutes). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
Added super init to Module for complex user modules derived from multiple python classes.
And by adding the super init call at the end so it doesn't change any functionality of Module class.
I am working on building a module for simulating analog neural network on PyTorch.
and this small change is really useful for that and we can definitely think of many other useful cases especially for more module or mro hierarchy.
Issues: #28746, #48626, #61662, #74036