Skip to content

Commit

Permalink
fix vec*mat in PyTorch converter (#11347)
Browse files Browse the repository at this point in the history
* fix vec*mat in PyTorch converter

* Trigger CI
  • Loading branch information
ganler authored May 20, 2022
1 parent e02bf82 commit a6a3404
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions python/tvm/relay/frontend/pytorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -1698,6 +1698,8 @@ def matmul(self, inputs, input_types):
return output
elif len(a_shape) > 2:
inputs_0 = _op.reshape(inputs_0, [-1, a_shape[-1]])
elif len(a_shape) == 1:
return _op.squeeze(_op.nn.matmul(_op.expand_dims(inputs_0, axis=0), inputs_1), axis=[0])

if len(b_shape) > 2:
trans_axes = list(range(len(b_shape)))
Expand Down
5 changes: 5 additions & 0 deletions tests/python/frontend/pytorch/test_forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -3511,6 +3511,11 @@ def forward(self, *args):
tensor2 = torch.randn(4)
verify_model(MatMul1().float().eval(), input_data=[tensor1, tensor2])

# vector x matrix
tensor1 = torch.randn(4)
tensor2 = torch.randn(4, 3)
verify_model(MatMul1().float().eval(), input_data=[tensor1, tensor2])

# matrix x matrix
tensor1 = torch.randn(10, 4)
tensor2 = torch.randn(4, 10)
Expand Down

0 comments on commit a6a3404

Please sign in to comment.