Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【Hackathon 6th No.52】move dequantize_abs_max op to phi -part #63826

Merged
merged 3 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 0 additions & 117 deletions paddle/fluid/operators/dequantize_abs_max_op.cc

This file was deleted.

62 changes: 0 additions & 62 deletions paddle/fluid/operators/dequantize_abs_max_op.cu

This file was deleted.

58 changes: 0 additions & 58 deletions paddle/fluid/operators/dequantize_abs_max_op.h

This file was deleted.

4 changes: 1 addition & 3 deletions paddle/fluid/operators/unity_build_rule.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ register_unity_group(
deformable_conv_v1_op.cc
deformable_psroi_pooling_op.cc
delete_var_op.cc
dequantize_abs_max_op.cc
dequantize_op.cc
onednn/dequantize_onednn_op.cc)
register_unity_group(
Expand Down Expand Up @@ -362,8 +361,7 @@ register_unity_group(
unzip_op.cu
data_norm_op.cu
deformable_conv_op.cu
deformable_conv_v1_op.cu
dequantize_abs_max_op.cu)
deformable_conv_v1_op.cu)
register_unity_group(
cu
dgc_clip_by_norm_op.cu
Expand Down
6 changes: 6 additions & 0 deletions paddle/phi/api/yaml/op_compat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,12 @@
attrs :
{scale : Scale, shift : Shift}

- op : dequantize_abs_max
inputs :
{x : X, scale : Scale}
outputs :
out : Out

- op : dequantize_linear
inputs :
{x : X, scale : Scale, zero_point : ZeroPoint, in_accum : InAccum, in_state : InState}
Expand Down
9 changes: 9 additions & 0 deletions paddle/phi/api/yaml/ops.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,15 @@
data_type : input
backward : depthwise_conv2d_grad

- op : dequantize_abs_max
args : (Tensor x, Tensor scale, float max_range)
output : Tensor(out)
infer_meta :
func : DequantizeAbsMaxInferMeta
kernel :
func : dequantize_abs_max
data_type : x

- op : det
args : (Tensor x)
output : Tensor
Expand Down
9 changes: 9 additions & 0 deletions paddle/phi/infermeta/binary.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1085,6 +1085,15 @@ void DepthwiseConvInferMeta(const MetaTensor& input,
config);
}

void DequantizeAbsMaxInferMeta(const MetaTensor& x,
const MetaTensor& scale,
float max_range,
MetaTensor* out) {
out->set_dtype(x.dtype());
out->share_dims(x);
out->share_lod(x);
}

void DequantizeLogInferMeta(const MetaTensor& x,
const MetaTensor& dict,
MetaTensor* out) {
Expand Down
5 changes: 5 additions & 0 deletions paddle/phi/infermeta/binary.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ void DepthwiseConvInferMeta(const MetaTensor& input,
MetaTensor* out,
MetaConfig config = MetaConfig());

void DequantizeAbsMaxInferMeta(const MetaTensor& x,
const MetaTensor& scale,
float max_range,
MetaTensor* out);

void DequantizeLogInferMeta(const MetaTensor& x,
const MetaTensor& dict,
MetaTensor* out);
Expand Down
43 changes: 43 additions & 0 deletions paddle/phi/kernels/cpu/dequantize_abs_max_kernel.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright (c) 2024 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "paddle/phi/kernels/dequantize_abs_max_kernel.h"

#include "paddle/phi/backends/cpu/cpu_context.h"
#include "paddle/phi/core/kernel_registry.h"

namespace phi {

template <typename T, typename Context>
void DequantizeAbsMaxKernel(const Context& dev_ctx,
const DenseTensor& x,
const DenseTensor& scale,
float max_range,
DenseTensor* out) {
const float* scale_factor = scale.data<float>();
const T* input_data = x.data<T>();
float* output_data = dev_ctx.template Alloc<float>(out);
int ind = static_cast<int>(x.numel());
for (size_t i = 0; i < (unsigned)ind; i++) {
output_data[i] = scale_factor[0] * input_data[i] / max_range;
}
}
} // namespace phi

PD_REGISTER_KERNEL(dequantize_abs_max,
CPU,
ALL_LAYOUT,
phi::DequantizeAbsMaxKernel,
int8_t,
int16_t) {}
29 changes: 29 additions & 0 deletions paddle/phi/kernels/dequantize_abs_max_kernel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) 2024 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#pragma once

#include "paddle/phi/backends/all_context.h"
#include "paddle/phi/core/dense_tensor.h"

namespace phi {

template <typename T, typename Context>
void DequantizeAbsMaxKernel(const Context& dev_ctx,
const DenseTensor& x,
const DenseTensor& scale,
float max_range,
DenseTensor* out);

} // namespace phi
Loading