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

[PyTorch] Fix rsub type #10090

Merged
merged 2 commits into from
Jan 28, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions python/tvm/relay/frontend/pytorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -1972,10 +1972,7 @@ def stack(self, inputs, input_types):
return self.tensor_array_stack(inputs, input_types)

def rsub(self, inputs, input_types):
data0, data1 = self.pytorch_promote_types(inputs[:2], input_types[:2])

# TODO (t-vi): should this also be part of the type promotion?
alpha = _expr.const(float(inputs[2]))
data0, data1, alpha = self.pytorch_promote_types(inputs, input_types)

# note: rsub means data0 and data1 swap places
return get_relay_op("subtract")(data1, alpha * data0)
Expand Down
7 changes: 7 additions & 0 deletions tests/python/frontend/pytorch/test_forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -2691,6 +2691,13 @@ def forward(self, *args):
verify_model(Rsub2().float().eval(), input_data=[d1, d2])
verify_model(Rsub2().float().eval(), input_data=[d1, d3])

d1 = torch.rand([1, 3]).half()
d2 = torch.rand([1, 3]).half()
verify_model(Rsub1().half().eval(), input_data=[d1, d2])
verify_model(Rsub1().half().eval(), input_data=[d1, d3])
verify_model(Rsub2().half().eval(), input_data=[d1, d2])
verify_model(Rsub2().half().eval(), input_data=[d1, d3])


@tvm.testing.uses_gpu
def test_forward_embedding():
Expand Down