From 2ce6473f144da298aba4a43d46918f27d463cf7c Mon Sep 17 00:00:00 2001 From: wozna Date: Sat, 31 Aug 2019 22:50:13 +0000 Subject: [PATCH] Fix test_transpose_int8_mkldnn test=develop --- .../inference/api/mkldnn_quantizer_config.cc | 4 ++-- .../operators/mkldnn/dequantize_mkldnn_op.cc | 5 +++-- .../mkldnn/test_transpose_int8_mkldnn_op.py | 15 +++++++++------ 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/paddle/fluid/inference/api/mkldnn_quantizer_config.cc b/paddle/fluid/inference/api/mkldnn_quantizer_config.cc index 9adc1150b59..cfb5c2e7af3 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 accc9a9d71f..0e203ef0010 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 a8127bcc781..3a7f620a100 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__': -- GitLab