Skip to content

Conversation

@bzinodev
Copy link
Contributor

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)

@bzinodev bzinodev requested a review from apaszke as a code owner July 22, 2020 19:00
@facebook-github-bot facebook-github-bot added the oncall: jit Add this issue/PR to JIT oncall triage queue label Jul 22, 2020
Copy link
Contributor

@facebook-github-bot facebook-github-bot left a 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.

@dr-ci
Copy link

dr-ci bot commented Jul 22, 2020

💊 CI failures summary and remediations

As of commit 47d6073 (more details on the Dr. CI page):


  • 1/1 failures possibly* introduced in this PR
    • 1/1 non-CircleCI failure(s)

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.

See how this bot performed.

This comment has been revised 43 times.

@bzinodev bzinodev requested review from eellison and suo August 3, 2020 22:28
Copy link
Contributor

@facebook-github-bot facebook-github-bot left a 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.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a 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.

Copy link
Contributor

@eellison eellison left a 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

@bzinodev bzinodev force-pushed the freezeInterfaces branch 2 times, most recently from a48380a to 322f453 Compare August 19, 2020 16:41
Copy link
Contributor

@facebook-github-bot facebook-github-bot left a 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.

@bzinodev bzinodev force-pushed the freezeInterfaces branch 2 times, most recently from 747c948 to e1f3660 Compare August 20, 2020 02:59
Copy link
Contributor

@facebook-github-bot facebook-github-bot left a 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.

Copy link
Contributor

@eellison eellison left a 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).

  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.
Copy link
Contributor

@facebook-github-bot facebook-github-bot left a 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.

Copy link
Contributor

@eellison eellison left a 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);
Copy link
Contributor

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 ?

@facebook-github-bot
Copy link
Contributor

@bzinodev merged this pull request in abe878c.

@facebook-github-bot facebook-github-bot deleted the freezeInterfaces branch January 27, 2021 18:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Merged oncall: jit Add this issue/PR to JIT oncall triage queue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants