Skip to content
Closed
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
39 changes: 25 additions & 14 deletions kernels/quantized/cpu/op_dequantize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ Tensor& dequantize_per_tensor_tensor_args_out(
Tensor& dequantize_per_channel_out(
const Tensor& input,
const Tensor& scale,
const Tensor& zero_point,
const optional<Tensor>& opt_zero_points,
int64_t axis,
int64_t quant_min,
int64_t quant_max,
Expand Down Expand Up @@ -201,16 +201,19 @@ Tensor& dequantize_per_channel_out(
ssize_t(scale.numel()),
ssize_t(input.size(axis)));

ET_CHECK_MSG(
zero_point.scalar_type() == ScalarType::Long,
"zero_point.scalar_type() %" PRId8 " is not integer type",
static_cast<int8_t>(zero_point.scalar_type()));
if (opt_zero_points.has_value()) {
auto zero_point = opt_zero_points.value();
ET_CHECK_MSG(
zero_point.scalar_type() == ScalarType::Long,
"zero_point.scalar_type() %" PRId8 " is not integer type",
static_cast<int8_t>(zero_point.scalar_type()));

ET_CHECK_MSG(
zero_point.numel() == input.size(axis),
"zero_point.numel() %zd != input.size(axis) %zd",
ssize_t(zero_point.numel()),
ssize_t(input.size(axis)));
ET_CHECK_MSG(
zero_point.numel() == input.size(axis),
"zero_point.numel() %zd != input.size(axis) %zd",
ssize_t(zero_point.numel()),
ssize_t(input.size(axis)));
}

check_dequantize_per_tensor_args(
input, quant_min, quant_max, dtype, out_dtype, out);
Expand All @@ -225,7 +228,12 @@ Tensor& dequantize_per_channel_out(
}
}
const double* scale_data = scale.const_data_ptr<double>();
const int64_t* zero_point_data = zero_point.const_data_ptr<int64_t>();
const int64_t* zero_point_data;
if (opt_zero_points.has_value()) {
zero_point_data = opt_zero_points.value().const_data_ptr<int64_t>();
} else {
zero_point_data = nullptr;
}

exec_aten::optional<exec_aten::ArrayRef<int64_t>> optional_dim_list{
exec_aten::ArrayRef<int64_t>{dims, size_t(input.dim() - 1)}};
Expand All @@ -242,7 +250,10 @@ Tensor& dequantize_per_channel_out(
case ScalarType::out_dtype: \
for (size_t channel_ix = 0; channel_ix < input.size(axis); ++channel_ix) { \
double _scale = scale_data[channel_ix]; \
int64_t _zero_point = zero_point_data[channel_ix]; \
int64_t _zero_point = 0; \
if (zero_point_data != nullptr) { \
_zero_point = zero_point_data[channel_ix]; \
} \
apply_over_dim_list( \
[input, out, _scale, _zero_point](size_t in_ix) { \
out.mutable_data_ptr<CTYPE_OUT>()[in_ix] = static_cast<CTYPE_OUT>( \
Expand Down Expand Up @@ -284,7 +295,7 @@ Tensor& dequantize_per_channel_out(
RuntimeContext& context,
const Tensor& input,
const Tensor& scale,
const Tensor& zero_point,
const optional<Tensor>& opt_zero_points,
int64_t axis,
int64_t quant_min,
int64_t quant_max,
Expand All @@ -295,7 +306,7 @@ Tensor& dequantize_per_channel_out(
return dequantize_per_channel_out(
input,
scale,
zero_point,
opt_zero_points,
axis,
quant_min,
quant_max,
Expand Down
2 changes: 1 addition & 1 deletion kernels/quantized/quantized.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
- arg_meta: null
kernel_name: torch::executor::quantize_per_channel_out

- func: quantized_decomposed::dequantize_per_channel.out(Tensor input, Tensor scales, Tensor zero_points, int axis, int quant_min, int quant_max, ScalarType dtype, *, ScalarType? out_dtype=None, Tensor(a!) out) -> Tensor(a!)
- func: quantized_decomposed::dequantize_per_channel.out(Tensor input, Tensor scales, Tensor? zero_points, int axis, int quant_min, int quant_max, ScalarType dtype, *, ScalarType? out_dtype=None, Tensor(a!) out) -> Tensor(a!)
variants: function
kernels:
- arg_meta: null
Expand Down