diff --git a/paddle/fluid/inference/api/mkldnn_quantizer_config.cc b/paddle/fluid/inference/api/mkldnn_quantizer_config.cc index 9adc1150b59f9dea1beb2e6cf4bb8e76aa8b32f6..cfb5c2e7af3ca55a112bab401d396f7925c5f579 100644 --- a/paddle/fluid/inference/api/mkldnn_quantizer_config.cc +++ b/paddle/fluid/inference/api/mkldnn_quantizer_config.cc @@ -35,8 +35,8 @@ MkldnnQuantizerConfig::MkldnnQuantizerConfig() { rules_["prior_box"]["Boxes"] = ScaleAlgo::NONE; rules_["prior_box"]["Variances"] = ScaleAlgo::NONE; - rules_["transpose"]["X"] = ScaleAlgo::KL; - rules_["transpose"]["Out"] = ScaleAlgo::KL; + rules_["transpose2"]["X"] = ScaleAlgo::KL; + rules_["transpose2"]["Out"] = ScaleAlgo::KL; } ScaleAlgo MkldnnQuantizerConfig::scale_algo( diff --git a/paddle/fluid/operators/mkldnn/dequantize_mkldnn_op.cc b/paddle/fluid/operators/mkldnn/dequantize_mkldnn_op.cc index accc9a9d71ffccf2812d57a7516eaf7e0f83275c..0e203ef0010e47b25f2014fd61dd86e02b68b387 100644 --- a/paddle/fluid/operators/mkldnn/dequantize_mkldnn_op.cc +++ b/paddle/fluid/operators/mkldnn/dequantize_mkldnn_op.cc @@ -86,8 +86,9 @@ class DeQuantOpKernel : public framework::OpKernel { std::shared_ptr src_memory_p = std::shared_ptr(new primitive::at(*src_memory)); - auto dst_md = platform::MKLDNNMemDesc({dst_tz}, memory::data_type::f32, - memory::format::nchw); + auto dst_md = platform::MKLDNNMemDesc( + {dst_tz}, memory::data_type::f32, + platform::MKLDNNFormatForSize(dst_tz.size(), memory::format::nchw)); auto dst_pd = mkldnn::memory::primitive_desc(dst_md, engine); dst_memory = std::make_shared( dst_pd, to_void_cast(output_data)); diff --git a/python/paddle/fluid/tests/unittests/mkldnn/test_transpose_int8_mkldnn_op.py b/python/paddle/fluid/tests/unittests/mkldnn/test_transpose_int8_mkldnn_op.py index a8127bcc781378fa5ef4a189a0b14d079a793946..3a7f620a1003b89d2f31f0fad0a6caf7bb6fa499 100644 --- a/python/paddle/fluid/tests/unittests/mkldnn/test_transpose_int8_mkldnn_op.py +++ b/python/paddle/fluid/tests/unittests/mkldnn/test_transpose_int8_mkldnn_op.py @@ -16,6 +16,7 @@ from __future__ import print_function import unittest import numpy as np +import paddle.fluid.core as core from paddle.fluid.tests.unittests.op_test import OpTest from mkldnn_op_test import format_reorder @@ -26,10 +27,11 @@ class TestTransposeOp(OpTest): self.initTestCase() self.initInputData() self.use_mkldnn = True + self._cpu_only = True self.axis = (0, 2, 3, 1) self.inputs = { - 'X': format_reorder(self.input_data, self.shape) + 'X': format_reorder(self.input_data, self.shape).astype(np.int8) } #transform data format to 'NHWC' for INT8 transpose specially. self.attrs = { @@ -38,7 +40,7 @@ class TestTransposeOp(OpTest): } self.outputs = { - 'XShape': np.random.random(self.shape).astype('int8'), + 'XShape': np.random.random(self.shape).astype(np.int8), 'Out': self.inputs['X'].transpose(self.axis) } @@ -46,14 +48,15 @@ class TestTransposeOp(OpTest): self.op_type = "transpose2" def test_check_output(self): - self.check_output(no_check_set=['XShape']) + self.check_output_with_place( + core.CPUPlace(), 1e-5, no_check_set=['XShape']) def initTestCase(self): self.shape = (2, 3, 4, 5) def initInputData(self): self.input_data = ( - np.random.randint(0, 100, self.shape) - 50).astype('int8') + np.random.randint(0, 100, self.shape) - 50).astype(np.int8) class TestINT8Case(TestTransposeOp): @@ -62,7 +65,7 @@ class TestINT8Case(TestTransposeOp): def initInputData(self): self.input_data = ( - np.random.randint(0, 100, self.shape) - 50).astype('int8') + np.random.randint(0, 100, self.shape) - 50).astype(np.int8) class TestUINT8Case(TestTransposeOp): @@ -71,7 +74,7 @@ class TestUINT8Case(TestTransposeOp): def initDataType(self): self.input_data = (np.random.randint(0, 100, - self.shape)).astype('uint8') + self.shape)).astype(np.uint8) if __name__ == '__main__':