-
Notifications
You must be signed in to change notification settings - Fork 21.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[fx][split] make sure we copy node.meta over during split (#107248)
Summary: Pull Request resolved: #107248 Previously when we create placeholder nodes for sub graph modules, we didn't copy node.meta over. Test Plan: CI Reviewed By: sayitmemory Differential Revision: D48330866 fbshipit-source-id: fa3dd3d147d153bc6af7d3c5614a20cf35b1657a
- Loading branch information
1 parent
4bfc55b
commit 6433cee
Showing
3 changed files
with
41 additions
and
8 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
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,30 @@ | ||
import torch | ||
from torch.fx.passes.split_utils import split_by_tags | ||
|
||
from torch.testing._internal.common_utils import TestCase | ||
|
||
|
||
class TestFXSplit(TestCase): | ||
def test_split_preserve_node_meta(self): | ||
class TestModule(torch.nn.Module): | ||
def forward(self, x, y): | ||
x = x + x | ||
y = y * y | ||
return x - y | ||
|
||
gm = torch.fx.symbolic_trace(TestModule()) | ||
for node in gm.graph.nodes: | ||
node.meta["name"] = node.name | ||
if node.name == "add": | ||
node.tag = "a" | ||
elif node.name == "mul": | ||
node.tag = "b" | ||
elif node.name == "sub": | ||
node.tag = "c" | ||
|
||
split_gm = split_by_tags(gm, ["a", "b", "c"]) | ||
for m in split_gm.children(): | ||
for n in m.graph.nodes: | ||
if n.op != "output": | ||
self.assertIn("name", n.meta) | ||
self.assertEqual(n.meta["name"], n.name) |
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