Skip to content
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

[ONNX] Fix graph position to insert clone node for inplace op removal #50123

Merged
merged 3 commits into from
Jan 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions test/onnx/test_pytorch_onnx_onnxruntime.py
Original file line number Diff line number Diff line change
Expand Up @@ -2741,6 +2741,7 @@ def forward(self, input, indices):
indices = torch.tensor([[1, 0], [0, 1], [0, 1]], dtype=torch.int64)
self.run_test(GatherModel(), input=(input, indices))

@disableScriptTest() # RuntimeError: Python type cannot be used as a value
@skipIfUnsupportedMinOpsetVersion(11)
def test_gather_constant_fold(self):
class GatherModule(torch.nn.Module):
Expand Down Expand Up @@ -3517,6 +3518,20 @@ def forward(self, input, other):
y = torch.randn(6, 4)
self.run_test(ViewModel(), (x, y))

def test_linear(self):
class LinearModel(torch.nn.Module):
def __init__(self):
super(LinearModel, self).__init__()
self.fc = torch.nn.Linear(16, 16)

def forward(self, x):
out = self.fc(x)
out = self.fc(out)
return out

x = torch.randn(3, 16)
self.run_test(LinearModel(), (x,))

@disableScriptTest()
def test_weight_norm(self):
# addmm for 3-d inputs converts to onnx::MatMul
Expand Down
1 change: 1 addition & 0 deletions torch/csrc/jit/passes/onnx/remove_inplace_ops_for_onnx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,7 @@ static void PrepareForRemoveMutations(MutationRemover& mr, Block* b) {
b->prependNode(newNode);
BowenBao marked this conversation as resolved.
Show resolved Hide resolved
noneNode->insertBefore(newNode);
}
TORCH_INTERNAL_ASSERT(nullptr != newNode);
node->replaceInput(index, newNode->output());
input->replaceAllUsesAfterNodeWith(node, newNode->output());
}
Expand Down