diff --git a/tests/constraints.txt b/tests/constraints.txt index fca15ab7cbe..b877cd951f5 100644 --- a/tests/constraints.txt +++ b/tests/constraints.txt @@ -23,4 +23,4 @@ pytest-html==3.2.0 pytest-timeout==2.1.0 jax<=0.4.14 jaxlib<=0.4.14 -torch<2.1.0,>=1.13 \ No newline at end of file +torch>=1.13 diff --git a/tests/layer_tests/pytorch_tests/test_masked_fill.py b/tests/layer_tests/pytorch_tests/test_masked_fill.py index f86b6c4bbda..0f934843b07 100644 --- a/tests/layer_tests/pytorch_tests/test_masked_fill.py +++ b/tests/layer_tests/pytorch_tests/test_masked_fill.py @@ -2,6 +2,8 @@ # SPDX-License-Identifier: Apache-2.0 import numpy as np +import torch +from packaging.version import parse as parse_version import pytest from pytorch_layer_test_class import PytorchLayerTest @@ -48,7 +50,7 @@ class TestMaskedFill(PytorchLayerTest): @pytest.mark.parametrize( "mask_fill", ['zeros', 'ones', 'random']) @pytest.mark.parametrize("input_dtype", [np.float32, np.float64, int, np.int32]) - @pytest.mark.parametrize("mask_dtype", [np.uint8, np.int32, bool]) # np.float32 incorrectly casted to bool + @pytest.mark.parametrize("mask_dtype", [bool]) # np.float32 incorrectly casted to bool @pytest.mark.parametrize("inplace", [True, False]) @pytest.mark.nightly @pytest.mark.precommit @@ -56,3 +58,17 @@ class TestMaskedFill(PytorchLayerTest): self._test(*self.create_model(value, inplace), ie_device, precision, ir_version, kwargs_to_prepare_input={'mask_fill': mask_fill, 'mask_dtype': mask_dtype, "input_dtype": input_dtype}) + + @pytest.mark.skipif(parse_version(torch.__version__) >= parse_version("2.1.0"), reason="pytorch 2.1 and above does not support nonboolean mask") + @pytest.mark.parametrize("value", [0.0, 1.0, -1.0, 2]) + @pytest.mark.parametrize( + "mask_fill", ['zeros', 'ones', 'random']) + @pytest.mark.parametrize("input_dtype", [np.float32, np.float64, int, np.int32]) + @pytest.mark.parametrize("mask_dtype", [np.uint8, np.int32]) # np.float32 incorrectly casted to bool + @pytest.mark.parametrize("inplace", [True, False]) + @pytest.mark.nightly + @pytest.mark.precommit + def test_masked_fill_non_bool_mask(self, value, mask_fill, mask_dtype, input_dtype, inplace, ie_device, precision, ir_version): + self._test(*self.create_model(value, inplace), + ie_device, precision, ir_version, + kwargs_to_prepare_input={'mask_fill': mask_fill, 'mask_dtype': mask_dtype, "input_dtype": input_dtype}) diff --git a/tests/layer_tests/pytorch_tests/test_masked_scatter.py b/tests/layer_tests/pytorch_tests/test_masked_scatter.py index 81aab9774d7..30c41b5e7f9 100644 --- a/tests/layer_tests/pytorch_tests/test_masked_scatter.py +++ b/tests/layer_tests/pytorch_tests/test_masked_scatter.py @@ -2,6 +2,8 @@ # SPDX-License-Identifier: Apache-2.0 import pytest +import torch +from packaging.version import parse as parse_version from pytorch_layer_test_class import PytorchLayerTest @@ -45,7 +47,7 @@ class TestMaskedScatter(PytorchLayerTest): @pytest.mark.precommit @pytest.mark.parametrize("shape", [[2, 5], [10, 10], [2, 3, 4], [10, 5, 10, 3], [2, 6, 4, 1]]) @pytest.mark.parametrize("input_dtype", ["float32", "int32", "float", "int", "uint8"]) - @pytest.mark.parametrize("mask_dtype", ["bool", "uint8"]) + @pytest.mark.parametrize("mask_dtype", ["bool"]) @pytest.mark.parametrize("out", [True, False]) def test_masked_scatter(self, shape, input_dtype, mask_dtype, out, ie_device, precision, ir_version): self._test(*self.create_model(out), ie_device, precision, ir_version, @@ -55,7 +57,28 @@ class TestMaskedScatter(PytorchLayerTest): @pytest.mark.precommit @pytest.mark.parametrize("shape", [[2, 5], [10, 10], [2, 3, 4], [10, 5, 10, 3], [2, 6, 4, 1]]) @pytest.mark.parametrize("input_dtype", ["float32", "int32", "float", "int", "uint8"]) - @pytest.mark.parametrize("mask_dtype", ["bool", "uint8"]) + @pytest.mark.parametrize("mask_dtype", ["bool"]) def test_masked_scatter_inplace(self, shape, input_dtype, mask_dtype, ie_device, precision, ir_version): + self._test(*self.create_model(inplace=True), ie_device, precision, ir_version, + kwargs_to_prepare_input={"shape": shape, "x_dtype": input_dtype, "mask_dtype": mask_dtype}) + + @pytest.mark.skipif(parse_version(torch.__version__) >= parse_version("2.1.0"), reason="pytorch 2.1 and above does not support nonboolean mask") + @pytest.mark.nightly + @pytest.mark.precommit + @pytest.mark.parametrize("shape", [[2, 5], [10, 10], [2, 3, 4], [10, 5, 10, 3], [2, 6, 4, 1]]) + @pytest.mark.parametrize("input_dtype", ["float32", "int32", "float", "int", "uint8"]) + @pytest.mark.parametrize("mask_dtype", ["uint8"]) + @pytest.mark.parametrize("out", [True, False]) + def test_masked_scatter_u8(self, shape, input_dtype, mask_dtype, out, ie_device, precision, ir_version): + self._test(*self.create_model(out), ie_device, precision, ir_version, + kwargs_to_prepare_input={"shape": shape, "x_dtype": input_dtype, "mask_dtype": mask_dtype, "out": out}) + + @pytest.mark.skipif(parse_version(torch.__version__) >= parse_version("2.1.0"), reason="pytorch 2.1 and above does not support nonboolean mask") + @pytest.mark.nightly + @pytest.mark.precommit + @pytest.mark.parametrize("shape", [[2, 5], [10, 10], [2, 3, 4], [10, 5, 10, 3], [2, 6, 4, 1]]) + @pytest.mark.parametrize("input_dtype", ["float32", "int32", "float", "int", "uint8"]) + @pytest.mark.parametrize("mask_dtype", ["uint8"]) + def test_masked_scatter_inplace_u8(self, shape, input_dtype, mask_dtype, ie_device, precision, ir_version): self._test(*self.create_model(inplace=True), ie_device, precision, ir_version, kwargs_to_prepare_input={"shape": shape, "x_dtype": input_dtype, "mask_dtype": mask_dtype}) \ No newline at end of file diff --git a/tests/model_hub_tests/torch_tests/requirements.txt b/tests/model_hub_tests/torch_tests/requirements.txt index 406607b69d2..707fa63716a 100644 --- a/tests/model_hub_tests/torch_tests/requirements.txt +++ b/tests/model_hub_tests/torch_tests/requirements.txt @@ -2,7 +2,7 @@ numpy pytest pytest-html -torch +torch<2.1 torchvision av transformers