-
Notifications
You must be signed in to change notification settings - Fork 26.3k
Allow Freezing of Module containing interface attribute #41860
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
facebook-github-bot
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.
@bzinodev has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
💊 CI failures summary and remediationsAs of commit 47d6073 (more details on the Dr. CI page):
Extra GitHub checks: 1 failed
This comment was automatically generated by Dr. CI (expand for details).Follow this link to opt-out of these comments for your Pull Requests.Please report bugs/suggestions on the GitHub issue tracker or post in the (internal) Dr. CI Users group. This comment has been revised 43 times. |
42776a1 to
4c219bd
Compare
4c219bd to
00579bb
Compare
facebook-github-bot
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.
@bzinodev has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
facebook-github-bot
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.
@bzinodev has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
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’m not sure if we’re necessarily doing it “safe” currently - for instance, we don’t check if the top level module has any setAttrs that reassign the interface, and we don’t check that any of the interface calls contain nester setAttrs.
Having said that, interfaces aren’t a public api and I don’t know if it’s worth it to spend too much time on it.
I think as a simple thing we could just inline all of interfaces first, and then run freezing as normal
[Zino:] Changed the patch to first inline interface calls then perform freezing. I have made changes so we don't check for setattr inside interfaces. Instead fail if freezing is unable to fold away the interface
a48380a to
322f453
Compare
facebook-github-bot
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.
@bzinodev has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
747c948 to
e1f3660
Compare
facebook-github-bot
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.
@bzinodev has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
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.
class Mod(torch.nn.Module):
def __init__(self):
self.a : Interface = a
self.b : Interface = b
def forward(self, input):
self.a = b
return self.a(input)
Presently we would inline the forward of a and then invoke it with b module. I think for safety it would be good to check that there are no setAttrs of an interface type in the forward function of the top level module or interfaces we've inlined.
[Zino] I add a test to check such model. Currently freezing fails because self.a cannot be folded away. Attribute 'a' has to be preserved and we dont allow to preserve an interface attribute (for the moment).
e1f3660 to
595f743
Compare
This patch allows to freeze model that utilizes interfaces. Freezing works
under the user assumption that the interfase module dones not aliases with
any value used in the model.
To enable freezing of such modules, added an extra pramater:
torch._C._freeze_module(module, freezeInterfaces = True)
By default freezeInterfaces is to True.
595f743 to
47d6073
Compare
facebook-github-bot
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.
@bzinodev has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
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.
LGTM. This may not be completely safe re: interfaces but it provides a good amount of safety. interfaces are not a public feature so I think this is fine; doing too much work on this is not worth our time atm. If we decide to make interfaces public we should revisit this.
|
|
||
| def forward(self, x): | ||
| self.proxy_mod = self.sub | ||
| y = self.proxy_mod(x); |
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'm glad that this test fails but i'm not sure why it does lol. Do you know why ?
This patch allows to freeze model that utilizes interfaces. Freezing works
under the user assumption that the interfase module dones not aliases with
any value used in the model.
To enable freezing of such modules, added an extra pramater:
torch._C._freeze_module(module, ignoreInterfaces = True)