OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
[TESTS] Fix seed for SDPA layer tests and remove FP64 from precommit (#30089)
Maxim Vafinfc20e6d27fd2
diff --git a/tests/layer_tests/pytorch_tests/test_scaled_dot_product_attention.py b/tests/layer_tests/pytorch_tests/test_scaled_dot_product_attention.pyindex b48464db60c..46c88f5088c 100644--- a/tests/layer_tests/pytorch_tests/test_scaled_dot_product_attention.py+++ b/tests/layer_tests/pytorch_tests/test_scaled_dot_product_attention.py@@ -8,17 +8,19 @@ from pytorch_layer_test_class import PytorchLayerTestclass TestScaledDotProductAttention(PytorchLayerTest):-def _prepare_input(self, dtype):- return (np.random.randn(1, 2, 8, 4).astype(dtype), np.random.randn(1, 2, 16, 4).astype(dtype), np.random.randn(1, 2, 16, 6).astype(dtype))+ rng = np.random.default_rng(42)+ return (rng.standard_normal((1, 2, 8, 4), dtype=dtype),+ rng.standard_normal((1, 2, 16, 4), dtype=dtype),+ rng.standard_normal((1, 2, 16, 6), dtype=dtype))def create_model(self, mask, is_causal, dtype, mask_shape):import torch.nn.functional as Fimport torch- class aten_scaled_dot_product_atten(torch.nn.Module):-- def __init__(self, mask=False, is_causal=False, dtype=np.float32, mask_shape=None) -> None:+ class aten_sdpa(torch.nn.Module):+ def __init__(self, mask=False, is_causal=False,+ dtype=np.float32, mask_shape=None) -> None:super().__init__()self.mask = None if not mask else torch.from_numpy(np.random.randint(0, 2, mask_shape).astype(dtype))@@ -33,18 +35,54 @@ class TestScaledDotProductAttention(PytorchLayerTest):b = F.scaled_dot_product_attention(query, key, value, attn_mask=self.mask, is_causal=self.is_causal, scale=torch.tensor(5, dtype=torch.float))return a, b- return aten_scaled_dot_product_atten(mask, is_causal, dtype, mask_shape), None, 'aten::scaled_dot_product_attention'+ return (aten_sdpa(mask, is_causal, dtype, mask_shape),+ None,+ 'aten::scaled_dot_product_attention')@pytest.mark.nightly@pytest.mark.precommit@pytest.mark.precommit_fx_backend@pytest.mark.precommit_torch_export- @pytest.mark.parametrize(['mask', 'is_causal'], [(False, False), (False, True), (True, True), (True, False)])- @pytest.mark.parametrize("dtype", (np.float32, np.float64))- @pytest.mark.parametrize('mask_shape', [(8, 16), (1, 16), (8, 1), (1, 1), (1, 8, 1), (1, 1, 8, 1), (1, 2, 8, 16)])+ @pytest.mark.parametrize(['mask', 'is_causal'], [(False, False),+ (False, True),+ (True, True),+ (True, False)])+ @pytest.mark.parametrize('mask_shape', [(8, 16),+ (1, 16),+ (8, 1),+ (1, 1),+ (1, 8, 1),+ (1, 1, 8, 1),+ (1, 2, 8, 16)])+ @pytest.mark.parametrize('dyn_shapes', (True, False))+ def test_scaled_dot_product_atten(self, ie_device, precision, ir_version,+ mask, is_causal, mask_shape, dyn_shapes):+ if PytorchLayerTest.use_torch_export() and not mask and is_causal:+ pytest.xfail(reason="Unsupported case for torch.export")+ dtype = np.float32+ self._test(*self.create_model(mask, is_causal, dtype, mask_shape),+ ie_device, precision, ir_version, dynamic_shapes=dyn_shapes,+ kwargs_to_prepare_input={"dtype": dtype})++ @pytest.mark.nightly+ @pytest.mark.parametrize(['mask', 'is_causal'], [(False, False),+ (False, True),+ (True, True),+ (True, False)])+ @pytest.mark.parametrize('mask_shape', [(8, 16),+ (1, 16),+ (8, 1),+ (1, 1),+ (1, 8, 1),+ (1, 1, 8, 1),+ (1, 2, 8, 16)])@pytest.mark.parametrize('dyn_shapes', (True, False))- def test_scaled_dot_product_atten(self, ie_device, precision, ir_version, mask, is_causal, dtype, mask_shape, dyn_shapes):+ def test_scaled_dot_product_atten_fp64(self, ie_device, precision,+ ir_version, mask, is_causal,+ mask_shape, dyn_shapes):if PytorchLayerTest.use_torch_export() and not mask and is_causal:pytest.xfail(reason="Unsupported case for torch.export")+ dtype = np.float64self._test(*self.create_model(mask, is_causal, dtype, mask_shape),- ie_device, precision, ir_version, dynamic_shapes=dyn_shapes, kwargs_to_prepare_input={"dtype": dtype})+ ie_device, precision, ir_version, dynamic_shapes=dyn_shapes,+ kwargs_to_prepare_input={"dtype": dtype})