forked from pytorch/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add weak script modules (pytorch#12682)
Summary: Adds support for weak script modules created that get compiled to `ScriptModule`s once added as a submodule of a `ScriptModule`: ```python weak_module class Test(torch.nn.Module): ... weak_script_method def forward(self, x): ... ``` Pull Request resolved: pytorch#12682 Differential Revision: D10458626 Pulled By: driazati fbshipit-source-id: 10ae23cb83cdafc4646cee58f399e14b2e60acd4
- Loading branch information
1 parent
3fb3a07
commit af78d4c
Showing
9 changed files
with
523 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
graph(%x : Dynamic) { | ||
%1 : int = prim::Constant[value=55]() | ||
%2 : int = prim::Constant[value=199]() | ||
%3 : int = prim::Constant[value=1]() | ||
%4 : int = aten::add(%1, %2) | ||
%5 : Dynamic = ^python_op_in_weak_module()(%x) | ||
%6 : Dynamic = aten::add(%5, %4, %3) | ||
return (%6); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
graph(%x : Dynamic) { | ||
%1 : int = prim::Constant[value=357]() | ||
%2 : int = prim::Constant[value=55]() | ||
%3 : int = prim::Constant[value=199]() | ||
%4 : int = prim::Constant[value=2]() | ||
%5 : int = prim::Constant[value=1]() | ||
%y : Dynamic = aten::mul(%x, %4) | ||
%7 : Dynamic = aten::add(%y, %5, %5) | ||
%8 : int = aten::add(%2, %3) | ||
%9 : Dynamic = ^python_op_in_weak_module()(%y) | ||
%10 : Dynamic = aten::add(%9, %8, %5) | ||
%11 : Dynamic = aten::add(%7, %10, %5) | ||
%12 : Dynamic = aten::add(%y, %1, %5) | ||
%13 : Dynamic = ^python_op_in_strong_module()(%y) | ||
%14 : Dynamic = aten::add(%12, %13, %5) | ||
%15 : Dynamic = aten::add(%11, %14, %5) | ||
return (%15); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
graph(%x : Dynamic | ||
%1 : Dynamic | ||
%2 : Dynamic | ||
%3 : Dynamic | ||
%4 : Dynamic) { | ||
%5 : int = prim::Constant[value=1]() | ||
%6 : int = prim::Constant[value=3]() | ||
%7 : int = prim::Constant[value=27]() | ||
%8 : Dynamic = aten::mul(%x, %x) | ||
%9 : Dynamic = aten::add(%8, %6, %5) | ||
%10 : Dynamic = aten::linear(%x, %1, %2) | ||
%11 : Dynamic = aten::add(%9, %10, %5) | ||
%12 : Dynamic = aten::add(%x, %11, %5) | ||
%13 : Dynamic = aten::add(%x, %7, %5) | ||
%14 : Dynamic = aten::add(%12, %13, %5) | ||
%15 : Dynamic = aten::linear(%x, %3, %4) | ||
%16 : Dynamic = aten::add(%14, %15, %5) | ||
%17 : Dynamic = aten::add(%x, %16, %5) | ||
return (%17); | ||
} |
19 changes: 19 additions & 0 deletions
19
test/expect/TestScript.test_weak_module_parameters_and_buffers.expect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
graph(%x : Dynamic | ||
%1 : Dynamic | ||
%2 : Dynamic | ||
%3 : Dynamic | ||
%4 : Dynamic | ||
%5 : Dynamic | ||
%6 : Dynamic) { | ||
%7 : int = prim::Constant[value=1]() | ||
%8 : Dynamic = aten::linear(%x, %1, %2) | ||
%9 : Dynamic = aten::add(%8, %3, %7) | ||
%10 : Dynamic = aten::add(%x, %9, %7) | ||
%11 : Dynamic = aten::linear(%x, %1, %2) | ||
%12 : Dynamic = aten::add(%11, %3, %7) | ||
%13 : Dynamic = aten::add(%10, %12, %7) | ||
%14 : Dynamic = aten::linear(%x, %4, %5) | ||
%15 : Dynamic = aten::add(%14, %6, %7) | ||
%16 : Dynamic = aten::add(%13, %15, %7) | ||
return (%16); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.