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

Fix the aten::mv for pytorch models #22073 #22677

Merged
merged 24 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
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
1 change: 1 addition & 0 deletions src/frontends/pytorch/src/op_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,7 @@ const std::map<std::string, CreatorFunction> get_supported_ops_ts() {
{"aten::masked_scatter_", op::inplace_op<op::translate_masked_scatter>},
{"aten::matmul", op::translate_1to1_match_2_inputs<opset10::MatMul>},
{"aten::max", op::translate_max},
{"aten::mv", op::translate_1to1_match_2_inputs<opset10::MatMul>},
{"aten::maximum", op::translate_maximum},
{"aten::max_pool1d", op::quantizable_op<op::translate_max_poolnd>},
{"aten::max_pool1d_with_indices", op::quantizable_op<op::translate_max_poolnd>},
Expand Down
42 changes: 42 additions & 0 deletions tests/layer_tests/pytorch_tests/test_matmul.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import numpy as np
import pytest
import torch
from pytorch_layer_test_class import PytorchLayerTest

class TestMatMulOperation(PytorchLayerTest):
def _prepare_input(self, matrix, vector):
matrix_input = torch.tensor(matrix, dtype=torch.float32)
vector_input = torch.tensor(vector, dtype=torch.float32)
return [matrix_input, vector_input]
eaidova marked this conversation as resolved.
Show resolved Hide resolved

def create_model(self, matrix, vector):
class CustomMatMulOperation(torch.nn.Module):
def forward(self, matrix, vector):
return torch.matmul(matrix, vector)

model_class = CustomMatMulOperation()
ref_net = None
return model_class, ref_net, "aten::mm"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test does not cover the operation you are supporting, it tests that there is aten::mm in the graph instead of aten::mv.
For having your operation in model you need to call torch.mv instead of torch.matmul


@pytest.mark.nightly
@pytest.mark.precommit
@pytest.mark.parametrize("matrix, vector, dtype, device", [
(np.array([[1, 2], [3, 4]]), np.array([5, 6]), torch.float64, 'cpu'),
(np.array([[0, 0], [0, 0]]), np.array([1, 2]), torch.float32, 'cpu'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove device, you don't use it. Also add some more shapes for tests

# Add more test cases as needed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add maybe 1 or 2 more test cases for non-square matrix and 3x3 matrix

])
def test_matmul_operation(self, matrix, vector, dtype, device, ie_device, precision, ir_version):
matrix_input = torch.tensor(matrix, dtype=torch.float32)
vector_input = torch.tensor(vector, dtype=torch.float32)

# Convert tensors to the specified dtype and device
matrix_input = matrix_input.to(dtype=dtype, device=device)
vector_input = vector_input.to(dtype=dtype, device=device)

self._test(
*self.create_model(matrix_input, vector_input),
ie_device,
precision,
ir_version,
kwargs_to_prepare_input={"matrix": matrix_input, "vector": vector_input}
)
Loading