Skip to content

Commit

Permalink
TorchFX unit tests: index_select, unary_ops, isinf, isnan
Browse files Browse the repository at this point in the history
  • Loading branch information
cavusmustafa committed Mar 5, 2024
1 parent 33da1ba commit a3f919a
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/layer_tests/pytorch_tests/test_index_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def forward_out(self, x, indices, out):
@pytest.mark.parametrize("out", [False, True])
@pytest.mark.nightly
@pytest.mark.precommit
@pytest.mark.precommit_fx_backend
def test_index_select(self, dim, out, indices, ie_device, precision, ir_version):
self._test(*self.create_model(dim, out), ie_device, precision, ir_version,
kwargs_to_prepare_input={"index": indices, "out": out, "dim": dim})
33 changes: 33 additions & 0 deletions tests/layer_tests/pytorch_tests/test_isinf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

import numpy as np
import pytest
import torch

from pytorch_layer_test_class import PytorchLayerTest


@pytest.mark.parametrize('input_tensor', (torch.tensor([1, float('inf'), 2, float('-inf'), float('nan')])))
class TestIsInf(PytorchLayerTest):

def _prepare_input(self):
input_tensor = self.input_tensor
return (input_tensor,)

def create_model(self):
class aten_isinf(torch.nn.Module):

def forward(self, input_tensor):
return torch.isinf(input_tensor)

ref_net = None

return aten_isinf(), ref_net, "aten::isinf"

@pytest.mark.nightly
@pytest.mark.precommit
@pytest.mark.precommit_fx_backend
def test_isinf(self, ie_device, precision, ir_version, input_tensor):
self.input_tensor = input_tensor
self._test(*self.create_model(), ie_device, precision, ir_version)
33 changes: 33 additions & 0 deletions tests/layer_tests/pytorch_tests/test_isnan.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright (C) 2018-2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

import numpy as np
import pytest
import torch

from pytorch_layer_test_class import PytorchLayerTest


@pytest.mark.parametrize('input_tensor', (torch.tensor([1, float('nan'), 2])))
class TestIsNan(PytorchLayerTest):

def _prepare_input(self):
input_tensor = self.input_tensor
return (input_tensor,)

def create_model(self):
class aten_isnan(torch.nn.Module):

def forward(self, input_tensor):
return torch.isnan(input_tensor)

ref_net = None

return aten_isnan(), ref_net, "aten::isnan"

@pytest.mark.nightly
@pytest.mark.precommit
@pytest.mark.precommit_fx_backend
def test_isnan(self, ie_device, precision, ir_version, input_tensor):
self.input_tensor = input_tensor
self._test(*self.create_model(), ie_device, precision, ir_version)
1 change: 1 addition & 0 deletions tests/layer_tests/pytorch_tests/test_unary_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def _prepare_input(self):
@pytest.mark.nightly
@pytest.mark.precommit
@pytest.mark.precommit_torch_export
@pytest.mark.precommit_fx_backend
@pytest.mark.parametrize("dtype", [torch.float32, torch.float64, torch.int8, torch.uint8, torch.int32, torch.int64])
@pytest.mark.parametrize("op_type",
[
Expand Down

0 comments on commit a3f919a

Please sign in to comment.