* add m1 mac pipelines as a matrix parameter * Update mac.yml disable java_api because of macos arm64 - Java is not available on macOS arm64 runners * Update mac.yml added always condition for all tests * Update mac.yml * Update mac.yml * Update mac.yml * Update setup.py temp commit * Update tools/openvino_dev/setup.py * use matrix for var * add mxnet to extras only for x86_64 * skip failing tests * use xfail for Python tests; add missing filter for transformations tests * skip CPU func tests on x86_64 mac; skip some tests from CPU func tests on arm mac * Update mac.yml * skip tests on mac arm * skip tests on darwin; apply review * add more skips for python and c++ tests * skip tf tests * skip more tf tests; skip more Python UT stages * rm alwayses, rm triggers, add nightly trigger --------- Co-authored-by: Ilya Lavrenov <ilya.lavrenov@intel.com>
115 lines
4.1 KiB
Python
115 lines
4.1 KiB
Python
# Copyright (C) 2018-2023 Intel Corporation
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
import platform
|
|
|
|
import numpy as np
|
|
import pytest
|
|
import torch
|
|
from pytorch_layer_test_class import PytorchLayerTest
|
|
|
|
|
|
class TestFakeQuantizePerTensorAffine(PytorchLayerTest):
|
|
def _prepare_input(self):
|
|
return (np.random.randn(3, 2, 2).astype(np.float32),)
|
|
|
|
def create_model(self, scale, zero_point, quant_min, quant_max):
|
|
class fake_quantize_per_tensor_affine(torch.nn.Module):
|
|
def __init__(self, scale, zero_point, quant_min, quant_max):
|
|
super(fake_quantize_per_tensor_affine, self).__init__()
|
|
self.scale = scale
|
|
self.zero_point = zero_point
|
|
self.quant_min = quant_min
|
|
self.quant_max = quant_max
|
|
|
|
def forward(self, x):
|
|
return torch.fake_quantize_per_tensor_affine(
|
|
x, self.scale, self.zero_point, self.quant_min, self.quant_max
|
|
)
|
|
|
|
ref_net = None
|
|
|
|
return (
|
|
fake_quantize_per_tensor_affine(scale, zero_point, quant_min, quant_max),
|
|
ref_net,
|
|
"aten::fake_quantize_per_tensor_affine",
|
|
)
|
|
|
|
@pytest.mark.nightly
|
|
@pytest.mark.precommit
|
|
@pytest.mark.parametrize(
|
|
"scale, zero_point, quant_min, quant_max",
|
|
[
|
|
(1.0, 1, 0, 255),
|
|
(0.01, 0, 0, 255),
|
|
(-0.01, 0, 0, 255),
|
|
(0.5, 0, -128, 127),
|
|
(0.5, -1, -128, 127),
|
|
(1.0, 0, 0, 127),
|
|
],
|
|
)
|
|
@pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64',
|
|
reason='Ticket - 122715')
|
|
def test_fake_quantize_per_tensor_affine(
|
|
self, ie_device, precision, ir_version, scale, zero_point, quant_min, quant_max
|
|
):
|
|
self._test(
|
|
*self.create_model(scale, zero_point, quant_min, quant_max),
|
|
ie_device,
|
|
precision,
|
|
ir_version,
|
|
freeze_model=False
|
|
)
|
|
|
|
|
|
class TestFakeQuantizePerChannelAffine(PytorchLayerTest):
|
|
def _prepare_input(self):
|
|
return (np.random.randn(3, 2, 2).astype(np.float32),)
|
|
|
|
def create_model(self, scale, zero_point, axis, quant_min, quant_max):
|
|
class fake_quantize_per_channel_affine(torch.nn.Module):
|
|
def __init__(self, scale, zero_point, axis, quant_min, quant_max):
|
|
super(fake_quantize_per_channel_affine, self).__init__()
|
|
self.scale = scale
|
|
self.zero_point = zero_point
|
|
self.axis = axis
|
|
self.quant_min = quant_min
|
|
self.quant_max = quant_max
|
|
|
|
def forward(self, x):
|
|
return torch.fake_quantize_per_channel_affine(
|
|
x, self.scale, self.zero_point, self.axis, self.quant_min, self.quant_max
|
|
)
|
|
|
|
ref_net = None
|
|
|
|
return (
|
|
fake_quantize_per_channel_affine(scale, zero_point, axis, quant_min, quant_max),
|
|
ref_net,
|
|
"aten::fake_quantize_per_channel_affine",
|
|
)
|
|
|
|
@pytest.mark.nightly
|
|
@pytest.mark.precommit
|
|
@pytest.mark.parametrize(
|
|
"scale, zero_point, axis, quant_min, quant_max",
|
|
[
|
|
(torch.tensor([0.005, 0.7]), torch.zeros(2), 1, 0, 255),
|
|
(torch.tensor([1.5, -0.7, -0.1]), torch.tensor([1, 0, -1], dtype=torch.int32), 0, -128, 127),
|
|
(torch.tensor([-0.005, 0.7]), torch.tensor([0, 1], dtype=torch.int32), 1, 0, 127),
|
|
(torch.tensor([-0.005, -0.7, 0.1]), torch.tensor([1, 0, 1], dtype=torch.int32), 0, 0, 255),
|
|
],
|
|
)
|
|
@pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() == 'arm64',
|
|
reason='Ticket - 122715')
|
|
def test_fake_quantize_per_channel_affine(
|
|
self, ie_device, precision, ir_version, scale, zero_point, axis, quant_min, quant_max
|
|
):
|
|
self._test(
|
|
*self.create_model(scale, zero_point, axis, quant_min, quant_max),
|
|
ie_device,
|
|
precision,
|
|
ir_version,
|
|
freeze_model=False
|
|
)
|