-
Notifications
You must be signed in to change notification settings - Fork 743
Changes to allow the export of functions with no user input. #8031
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -316,6 +316,8 @@ def lift_constant_tensor_pass(ep): | |
| new_input_specs.extend(lifted_constants) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And if we just insert all the constants at the beginning, we can just directly prepend to input_specs.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done, and removed all the logic I had previously, now: No user inputs -> inserting before |
||
| lifted_constants.clear() | ||
| new_input_specs.append(s) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a test case?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added a test case, shifted to the simpler implementation of just prepending the signature since the order of the non-user inputs does not matter.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have also validated that it works with my export process as well. |
||
| if len(lifted_constants) > 0: | ||
| new_input_specs = lifted_constants + new_input_specs | ||
| ep.graph_signature.input_specs = new_input_specs | ||
| ep.graph_module.recompile() | ||
| return ep | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -1057,6 +1057,35 @@ def forward(self, x: torch.Tensor) -> torch.Tensor: | |||||
| new_ep.graph_module.code | ||||||
| ) | ||||||
|
|
||||||
| def test_pass_no_user_inputs(self) -> None: | ||||||
| class NoUserInputs(torch.nn.Module): | ||||||
| def __init__(self): | ||||||
| super().__init__() | ||||||
| self.register_buffer("a", torch.ones(1)) | ||||||
|
|
||||||
| def forward(self) -> torch.Tensor: | ||||||
| return 3 + self.a | ||||||
|
|
||||||
| mod = NoUserInputs() | ||||||
| exported_program = export(mod, (), strict=True) | ||||||
| edge = to_edge( | ||||||
| exported_program, | ||||||
| compile_config=EdgeCompileConfig(_skip_dim_order=False), | ||||||
| ) | ||||||
| ep = edge.exported_program() | ||||||
| # because there is no user input, the lifted constant should be the first input. | ||||||
| FileCheck().check("_lifted_tensor_constant1").check( | ||||||
| "b_a" # followed by the buffer input. | ||||||
| ).run(ep.graph_module.code) | ||||||
| # the graph signature should also be the same: | ||||||
| assert ep.graph_signature.input_specs[0].arg.name == "_lifted_tensor_constant1" | ||||||
|
||||||
| assert ep.graph_signature.input_specs[0].arg.name == "_lifted_tensor_constant1" | |
| self.assertEquals(ep.graph_signature.input_specs[0].arg.name, "_lifted_tensor_constant1") |
Outdated
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 are these commented out?
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 accidentally left those in, when I was initially writing the test/debugging and validating changes I just copy/pasted those lines so I had something to drop a debugger breakpoint on.
I removed those, and left in the to_executorch call, this is there to ensure that the validation steps that were previously failing are correctly bypassed. (Does not throw an exception.)
Uh oh!
There was an error while loading. Please reload this page.
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.
this change looks fine. On our side we should probably take a pass over all the memory planning infra. A lot of it was written before export graphs were functionalized so the concept of non user inputs didnt make exist.
Like realistically we should /only/ be verifying the memory planning of user inputs here