From 3f72bcfcaacadfbbfb40e1cc32fc15fdec26bca5 Mon Sep 17 00:00:00 2001 From: Jerry Zhang Date: Tue, 24 Sep 2019 10:53:02 -0700 Subject: [PATCH] Remove _dequantize_per_tensor (#26681) Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/26681 att Test Plan: ci Imported from OSS Differential Revision: D17542833 fbshipit-source-id: 653e906b0e146763609c69ef0de7f9cf38621586 --- aten/src/ATen/core/OpsAlreadyMovedToC10.cpp | 1 - aten/src/ATen/native/native_functions.yaml | 5 ----- aten/src/ATen/native/quantized/QTensor.cpp | 24 --------------------- test/test_quantized_tensor.py | 10 +-------- 4 files changed, 1 insertion(+), 39 deletions(-) diff --git a/aten/src/ATen/core/OpsAlreadyMovedToC10.cpp b/aten/src/ATen/core/OpsAlreadyMovedToC10.cpp index 1a0ea94c59f..ca63ff644d6 100644 --- a/aten/src/ATen/core/OpsAlreadyMovedToC10.cpp +++ b/aten/src/ATen/core/OpsAlreadyMovedToC10.cpp @@ -1153,7 +1153,6 @@ bool aten_op_is_not_moved_to_c10_yet(const c10::OperatorName& opName) { #endif {"aten::quantize_per_tensor", ""}, {"aten::quantize_per_channel", ""}, - {"aten::_dequantize_per_tensor", ""}, {"aten::q_per_channel_axis", ""}, {"aten::qscheme", ""}, {"aten::to", "dtype_layout"}, diff --git a/aten/src/ATen/native/native_functions.yaml b/aten/src/ATen/native/native_functions.yaml index cae146548fd..5e5d17a2a52 100644 --- a/aten/src/ATen/native/native_functions.yaml +++ b/aten/src/ATen/native/native_functions.yaml @@ -3536,11 +3536,6 @@ dispatch: QuantizedCPU: dequantize_quant -- func: _dequantize_per_tensor(Tensor self, float scale, int zero_point, ScalarType dtype) -> Tensor - variants: function - dispatch: - CPU: dequantize_per_tensor_cpu - - func: q_scale(Tensor self) -> float use_c10_dispatcher: full variants: function, method diff --git a/aten/src/ATen/native/quantized/QTensor.cpp b/aten/src/ATen/native/quantized/QTensor.cpp index db42a39a576..0a6037aa886 100644 --- a/aten/src/ATen/native/quantized/QTensor.cpp +++ b/aten/src/ATen/native/quantized/QTensor.cpp @@ -30,30 +30,6 @@ Tensor dequantize_quant(const Tensor& self) { return get_qtensorimpl(self)->quantizer()->dequantize(self); } -Tensor dequantize_per_tensor_cpu( - const Tensor& self, - double scale, - int64_t zero_point, - ScalarType dtype) { - TORCH_CHECK( - isQIntType(toQIntType(self.scalar_type())), - "Scalar type for quantized Tensor must have same underlying type as input."); - TORCH_CHECK( - dtype == toQIntType(self.scalar_type()), - "ScalarType argument must match the corresponding quantized scalar type of input integer Tensor"); - // scalar type of output Tensor is hard-coded as float - Tensor f = at::empty(self.sizes(), self.options().dtype(at::kFloat)); - AT_DISPATCH_QINT_TYPES( - toQIntType(self.scalar_type()), "dequantize_linear_cpu", [&]() { - underlying_t* qdata = self.data_ptr(); - auto* fdata = f.data_ptr(); - for (int i = 0; i < self.numel(); ++i) { - fdata[i] = (static_cast(qdata[i]) - zero_point) * scale; - } - }); - return f; -} - double q_scale_quant(const Tensor& self) { auto quantizer = get_qtensorimpl(self)->quantizer(); TORCH_CHECK(quantizer->qscheme() == kPerTensorAffine); diff --git a/test/test_quantized_tensor.py b/test/test_quantized_tensor.py index f5c00f52941..29d76af78f2 100644 --- a/test/test_quantized_tensor.py +++ b/test/test_quantized_tensor.py @@ -129,15 +129,7 @@ class TestQuantizedTensor(TestCase): rqr = qr.dequantize() self.assertTrue(np.allclose(r.numpy(), rqr.numpy(), atol=2 / scale)) - def test_qtensor_dequantize_per_tensor(self): - t = torch.arange(-10, 10, dtype=torch.int8) - scale = 3 - zero_point = 2 - qt = torch._dequantize_per_tensor(t, scale, zero_point, torch.qint8) - qt2 = torch._make_per_tensor_quantized_tensor(t, scale, zero_point) - self.assertEqual(qt, qt2.dequantize()) - - def test_qtensor_per_channel_affine(self): + def test_qtensor_quantize_per_channel(self): r = torch.rand(3, 2, dtype=torch.float) * 4 - 2 scales = torch.tensor([0.2, 0.03], dtype=torch.double) zero_points = torch.tensor([5, 10], dtype=torch.long)