未验证 提交 627d5567 编写于 作者: L Liufang Sang 提交者: GitHub

cherry pick remove pow to speed up in dequantize_log op (#24607) (#24723)

* remove pow in speed up in dequantize_log test=develop

* remove pow in speed up in dequantize_log test=develop

* fix unittest test=develop
上级 b84fedfc
...@@ -31,9 +31,9 @@ struct DequantizeFunctor<platform::CPUDeviceContext, T> { ...@@ -31,9 +31,9 @@ struct DequantizeFunctor<platform::CPUDeviceContext, T> {
int ind = in->numel(); int ind = in->numel();
for (size_t i = 0; i < (unsigned)ind; i++) { for (size_t i = 0; i < (unsigned)ind; i++) {
if (input_data[i] < 0) { 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 { } else {
output_data[i] = std::pow(2.0, dict_data[input_data[i]]); output_data[i] = dict_data[input_data[i]];
} }
} }
} }
......
...@@ -26,9 +26,9 @@ __global__ void KeDequantize(const T* in, const float* dict, int num, ...@@ -26,9 +26,9 @@ __global__ void KeDequantize(const T* in, const float* dict, int num,
const int idx = threadIdx.x + blockIdx.x * blockDim.x; const int idx = threadIdx.x + blockIdx.x * blockDim.x;
if (idx < num) { if (idx < num) {
if (in[idx] < 0) { if (in[idx] < 0) {
out[idx] = -std::pow(static_cast<float>(2.0), dict[in[idx] + 128]); out[idx] = -dict[in[idx] + 128];
} else { } else {
out[idx] = std::pow(static_cast<float>(2.0), dict[in[idx]]); out[idx] = dict[in[idx]];
} }
} }
} }
......
...@@ -26,9 +26,9 @@ def dequantize_log(x, dict_data): ...@@ -26,9 +26,9 @@ def dequantize_log(x, dict_data):
output_data_f = output_data.flatten() output_data_f = output_data.flatten()
for i in range(x_f.size): for i in range(x_f.size):
if x_f[i] < 0: 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: 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) return output_data_f.reshape(x.shape)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册