* Support GetAttr with packed params * Apply suggestions from code review * [PT FE] Add quantized types as normal types to decoder * [PT FE] Add decoder dequantize, add dtypes to quantize * [PT FE] Add dequantize example * [PT FE] Implement replacer for quantized nodes * [PT FE] Register replacer for quantize/dequantize * [PT FE] Remove unwanted junk from previous version * [PT FE] Fix building mistakes for frontend * [PT FE] Clang fix * [PT FE] Ease of use upgrade to quantize funcs * [PT FE] Clang format * [PT FE] Introduce new version of quantize/dequantize * [PT FE] Remove unwanted files from new version * [PT FE] Fix style * [PT FE] Add QuantizedPtNode replacer, fix accuracy error * [PT FE] Quantized add * [PT FE] Add improved version of quantize/dequantize with shared_ptrs * [PT FE] Quantized Add Relu * [PT FE] Fix utils shared ptr reference error * [PT FE] Quantized Hardswish & tests * [PT FE] Add quantized_add_relu test * [PT FE] Quantize now takes correct input for operations * [PT FE] Add dtype to tests * [PT FE] Increase matrix size in the tests to cover more edge cases * [PT FE] Upgrade quantize method * [PT FE] Add BFS for dequantize, add quantize_per_channel * [PT FE] Add missing replacer to frontend, improve tests * [PT FE] Rename replacer -> remover, remove unwanted header files * [PT FE] Change function declarations to return ov::Output instead of shared ptr * [PT FE] Add missing context mark node * [PT FE] Remove unknown modifications to ie_c_api * [PT FE] Remove fp16 support, turn off int32 tests * [PT FE] Clang format * [PT FE] Fix quantize_per_tensor * [PT FE] Minor fixes from review * [PT FE] Remove dequantize, remove helpers, replacer now removes nodes instead * [PT FE] Rename Replacer to Remover for dequantize nodes * [PT FE] Clang format * [PT FE] Move comments to header files, minor import fixes * [PT FE] Enable add, add_relu, mul, hardswish with newest quantize ops * [PT FE] Fix clang format * [PT FE] Fix dtype issue * [PT FE] Reenable hardswish tests * [PT FE] Fix building error for quantized ops * [PT FE] Tests now use rand instead of randn * [PT FE] Remove int32 support from tests * [PT FE] Fix quantize_per_channel tests * Apply suggestions from code review Removing sporadic tests from precommit * Apply suggestions from code review * [PT FE] Mark qint32 with skip, remove precommit flag due to sporadic errors * [PT FE] Introduce quantized test for PytorchTestClass * [PT FE] Add missing tensor size in the errors count computation * Update pytorch_layer_test_class.py * [PT FE] Apply suggestions from review - remove contexts, log100 for errors, add precommit flags * Apply suggestions from code review * [PT FE] Fix quantize per channel test after merge * Update tests/layer_tests/pytorch_tests/pytorch_layer_test_class.py * Update pytorch_layer_test_class.py * Update test_quantize.py * Apply suggestions from code review * [PT FE] Fix quantized mul by changing default quantization dtype * Update pytorch_layer_test_class.py * Update tests/layer_tests/pytorch_tests/pytorch_layer_test_class.py * Update src/frontends/pytorch/src/utils_quantize.cpp * Update src/frontends/pytorch/src/utils_quantize.cpp * Update tests/layer_tests/pytorch_tests/test_quantized_mul.py --------- Co-authored-by: Maxim Vafin <maxim.vafin@intel.com>
45 lines
1.7 KiB
Python
45 lines
1.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
|
|
|
|
class quantized_add(torch.nn.Module):
|
|
def __init__(self, scale, zero_point, dtype) -> None:
|
|
torch.nn.Module.__init__(self)
|
|
self.scale = scale
|
|
self.zero_point = zero_point
|
|
self.dtype = dtype
|
|
|
|
def forward(self, input_tensor1, input_tensor2):
|
|
quantized_tensor1 = torch.quantize_per_tensor(input_tensor1, self.scale, self.zero_point, self.dtype)
|
|
quantized_tensor2 = torch.quantize_per_tensor(input_tensor2, self.scale, self.zero_point, self.dtype)
|
|
quantized_add = torch.ops.quantized.add(quantized_tensor1, quantized_tensor2, self.scale, self.zero_point)
|
|
dequantized_tensor = torch.dequantize(quantized_add)
|
|
return dequantized_tensor
|
|
|
|
class TestQuantizedAdd(PytorchLayerTest):
|
|
def _prepare_input(self):
|
|
return (np.array(5.00 * np.random.rand(100, 100) + 5.00, dtype=np.float32),
|
|
np.array(5.00 * np.random.rand(100, 100) + 5.00, dtype=np.float32))
|
|
|
|
@pytest.mark.parametrize("scale", [
|
|
1.0, 0.21, 0.62
|
|
])
|
|
@pytest.mark.parametrize("zero_point", [
|
|
0, 4, -7
|
|
])
|
|
@pytest.mark.parametrize("dtype", [
|
|
torch.quint8,
|
|
torch.qint8
|
|
])
|
|
@pytest.mark.nightly
|
|
@pytest.mark.precommit
|
|
def test_quantized_add(self, scale, zero_point, dtype, ie_device, precision, ir_version):
|
|
if dtype == torch.quint8: zero_point = abs(zero_point)
|
|
self._test(quantized_add(scale, zero_point, dtype), None, ["quantized::add"],
|
|
ie_device, precision, ir_version, quantized_ops=True, quant_size=scale)
|