Files
openvino/tests/layer_tests/pytorch_tests/test_remainder.py
T
d42b53c070 Torchfx backend (#18244)
* Added Torchscript Backend

* First commit for backend with Torch FX Decoder

* Merging changes from Torch FX branch

* Torch FX initial fixes (Temporary)

* Fixed type/shape issues in Torch FX decoder

* Added translation for built-in getitem

* MaxPool update & Output shape fix (Torch FX)

* Torch FX graph outputs fix

* Torch FX support for sigmoid and slu_

* Torch FX graph module caching

* Torch Fx partitioner cache removed

* Torch FX initial getitem replacer added

* Index check for torch fx getitem replacer

* Debug print removed from partitioner

* Added environment variables for pytorch tracing mode and openvino device

* FX translation fix for getitem & getitem replacer removed

* Added checks for PyTorch tracing mode environment variable

* Adding compile mode for fallback

* Added more ops for resnet18

* Added a check for environment variable

* Generalized addmm to work with torchscript and torchfx

* Added the missing batch_norm.default translation

* fx_backend: include get_attr ops to the partitions

* AddeTODO note t to improvget_attr algorithm

* created function for adding get_attr nodes

* fx_backend: added aten.mul.Tensor, re-enabled aten.empty.memory_format

* fx_backend: Additional op support/improvement for Inception V3

* Added comment for fix 64-bit to 32-bit max int conversion

* fx_backend: Update for avg_poolnd to support 3 inputs

* Fixed erorr in decoder.py

* TorchFX caching fix

* Torch backend, op support for Stable Diff. & BERT

* Arranged ops in order and added torch tensor mapping

* Added support for more ops for super glue

* TorchFX: Initial permanent fallback

* TorchFX: New ops for improved TorchVision support

* TorchFX backend optimizations for partitioning and tmp fallback

* working operator updates for superglue

* Updates to operators for superglue

* Removed max.dim and stack

* Cleanup

* Cleanup

* Fixed a couple of syntax issues

* Fixed a couple of syntax issues

* Added missing method to TorchFX Decoder

* Added missing method to TorchFX Decoder

* Removed redundant code for transpose

* TorchFX: Initial StableDiffusion support

* PyTorch decoder ovtype to ctype fix for int64

* Added ops for distilbert

* Fixed few unnecessary include statements

* Seperated TorchFX and TorchScript decoders

* Modified import statements to reflect two decoders

* f64 fix for TorchFX

* Import fix for PyTorch backend modules

* TorchFX serialize graph for debugging (Temporary)

* Serialize and load back feature enabled for TorchFX

* Temporary optimization to remove Broadcast

* Temporary SoftmaxRehapeElimination pass is added

* TorchFX custom model cache directory

* PyTorch bitwise translation, conversion checks enabled

* Naming fix in make_list_construct

* TorchFX: Added comments to Softmax and Slice translations

* translate_chunk temporarily removed for TS backend

* Fixed linter issues

* Addressed clang formatting issues

* Fixed few more clang and linter issues

* Fixed tests to use ts_decoder

* Fixed naming convention issues

* Added missing import

* Added inlined_inputs to TorchScriptDecoder

* Added tests for torch fx backend

* Removed magic numbers in PyTorch decoder utils

* TorchFX decoder data type fix

* Added cast from size_t to int

* TorchFX output handling code cleanup

* TorchFX: Use detached input tensor

* Added missing cast from size_t to int

* Added static cast in group_norm

* Fixed casting issue in split

---------

Co-authored-by: ynimmaga <yamini.nimmagadda@intel.com>
Co-authored-by: Cavus Mustafa <mustafa.cavus@intel.com>
2023-07-26 16:23:42 +02:00

112 lines
3.7 KiB
Python

# 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_rhs",
(
np.random.randn(2, 5, 3, 4).astype(np.float32),
np.random.randn(1, 5, 3, 4).astype(np.float32),
np.random.randn(1).astype(np.float32),
),
)
class TestRemainder(PytorchLayerTest):
def _prepare_input(self):
return (np.random.randn(2, 5, 3, 4).astype(np.float32), self.input_rhs)
def create_model(self):
class aten_remainder(torch.nn.Module):
def forward(self, lhs, rhs):
return torch.remainder(lhs, rhs)
ref_net = None
return aten_remainder(), ref_net, "aten::remainder"
@pytest.mark.nightly
@pytest.mark.precommit
def test_remainder(self, ie_device, precision, ir_version, input_rhs):
self.input_rhs = input_rhs
self._test(*self.create_model(), ie_device, precision, ir_version)
class TestRemainderTypes(PytorchLayerTest):
def _prepare_input(self):
if len(self.lhs_shape) == 0:
return (torch.randint(2, 5, self.rhs_shape).to(self.rhs_type).numpy(),)
elif len(self.rhs_shape) == 0:
return (10 * torch.randn(self.lhs_shape).to(self.lhs_type).numpy(),)
return (
10 * torch.randn(self.lhs_shape).to(self.lhs_type).numpy(),
torch.randint(2, 5, self.rhs_shape).to(self.rhs_type).numpy(),
)
def create_model(self, lhs_type, lhs_shape, rhs_type, rhs_shape):
class aten_remainder(torch.nn.Module):
def __init__(self, lhs_type, lhs_shape, rhs_type, rhs_shape):
super().__init__()
self.lhs_type = lhs_type
self.rhs_type = rhs_type
if len(lhs_shape) == 0:
self.forward = self.forward1
elif len(rhs_shape) == 0:
self.forward = self.forward2
else:
self.forward = self.forward3
def forward1(self, rhs):
return torch.remainder(torch.tensor(3).to(self.lhs_type), rhs.to(self.rhs_type))
def forward2(self, lhs):
return torch.remainder(lhs.to(self.lhs_type), torch.tensor(3).to(self.rhs_type))
def forward3(self, lhs, rhs):
return torch.remainder(lhs.to(self.lhs_type), rhs.to(self.rhs_type))
ref_net = None
return aten_remainder(lhs_type, lhs_shape, rhs_type, rhs_shape), ref_net, "aten::remainder"
@pytest.mark.parametrize(
("lhs_type", "rhs_type"),
[
[torch.int32, torch.int64],
[torch.int32, torch.float32],
[torch.int32, torch.float64],
[torch.int64, torch.int32],
[torch.int64, torch.float32],
[torch.int64, torch.float64],
[torch.float32, torch.int32],
[torch.float32, torch.int64],
[torch.float32, torch.float64],
],
)
@pytest.mark.parametrize(
("lhs_shape", "rhs_shape"),
[
([2, 3], [2, 3]),
([2, 3], []),
([], [2, 3]),
],
)
@pytest.mark.nightly
@pytest.mark.precommit
@pytest.mark.precommit_ts_backend
@pytest.mark.precommit_fx_backend
def test_remainder_types(self, ie_device, precision, ir_version, lhs_type, lhs_shape, rhs_type, rhs_shape):
self.lhs_type = lhs_type
self.lhs_shape = lhs_shape
self.rhs_type = rhs_type
self.rhs_shape = rhs_shape
self._test(
*self.create_model(lhs_type, lhs_shape, rhs_type, rhs_shape),
ie_device,
precision,
ir_version,
)