From 55b664a1310c3148809688a7fbdd94073aa26a7d Mon Sep 17 00:00:00 2001 From: Liufang Sang Date: Mon, 25 May 2020 13:52:12 +0800 Subject: [PATCH] remove pow to speed up in dequantize_log op (#24607) * remove pow in speed up in dequantize_log test=develop * remove pow in speed up in dequantize_log test=develop * fix unittest test=develop --- paddle/fluid/operators/dequantize_log_op.cc | 4 ++-- paddle/fluid/operators/dequantize_log_op.cu | 4 ++-- python/paddle/fluid/tests/unittests/test_dequantize_log_op.py | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/paddle/fluid/operators/dequantize_log_op.cc b/paddle/fluid/operators/dequantize_log_op.cc index bfd26061e32..2ecd54f7edd 100644 --- a/paddle/fluid/operators/dequantize_log_op.cc +++ b/paddle/fluid/operators/dequantize_log_op.cc @@ -31,9 +31,9 @@ struct DequantizeFunctor { int ind = in->numel(); for (size_t i = 0; i < (unsigned)ind; i++) { if (input_data[i] < 0) { - output_data[i] = -std::pow(2.0, dict_data[input_data[i] + 128]); + output_data[i] = -dict_data[input_data[i] + 128]; } else { - output_data[i] = std::pow(2.0, dict_data[input_data[i]]); + output_data[i] = dict_data[input_data[i]]; } } } diff --git a/paddle/fluid/operators/dequantize_log_op.cu b/paddle/fluid/operators/dequantize_log_op.cu index 57bad318ab6..9f63f8ed6f5 100644 --- a/paddle/fluid/operators/dequantize_log_op.cu +++ b/paddle/fluid/operators/dequantize_log_op.cu @@ -26,9 +26,9 @@ __global__ void KeDequantize(const T* in, const float* dict, int num, const int idx = threadIdx.x + blockIdx.x * blockDim.x; if (idx < num) { if (in[idx] < 0) { - out[idx] = -std::pow(static_cast(2.0), dict[in[idx] + 128]); + out[idx] = -dict[in[idx] + 128]; } else { - out[idx] = std::pow(static_cast(2.0), dict[in[idx]]); + out[idx] = dict[in[idx]]; } } } diff --git a/python/paddle/fluid/tests/unittests/test_dequantize_log_op.py b/python/paddle/fluid/tests/unittests/test_dequantize_log_op.py index 6c6f0811bbb..3ad1f05f92d 100644 --- a/python/paddle/fluid/tests/unittests/test_dequantize_log_op.py +++ b/python/paddle/fluid/tests/unittests/test_dequantize_log_op.py @@ -26,9 +26,9 @@ def dequantize_log(x, dict_data): output_data_f = output_data.flatten() for i in range(x_f.size): if x_f[i] < 0: - output_data_f[i] = -np.power(2, dict_data[x_f[i] + 128]) + output_data_f[i] = -dict_data[x_f[i] + 128] else: - output_data_f[i] = np.power(2, dict_data[x_f[i]]) + output_data_f[i] = dict_data[x_f[i]] return output_data_f.reshape(x.shape) -- GitLab