Skip to content

Commit

Permalink
Minor fixes in per channel support for qconv kernel (pytorch#25182)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: pytorch#25182

Removing empty line, an unused variable and adding a check for supported quantized data types.
ghstack-source-id: 8929318

Test Plan: buck test mode/dev caffe2/test:quantized -- --print-passing-details

Reviewed By: jianyuh

Differential Revision: D17052234

fbshipit-source-id: dbe470f0cd73fa4fca44bd15424adbaf7ceca469
  • Loading branch information
dskhudia authored and facebook-github-bot committed Aug 30, 2019
1 parent 0f928dc commit fcab254
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
3 changes: 3 additions & 0 deletions aten/src/ATen/native/quantized/TensorFactories.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ Tensor empty_per_channel_affine_quantized_cpu(
TORCH_CHECK(
options.has_dtype(),
"Must provide data type for Tensor creation functions.");
TORCH_CHECK(
options.dtype() == kQInt8 || options.dtype() == kQUInt8,
"Supported data type for tensor creation is int8 or uint8");
TORCH_CHECK(scales.dim() == 1, "scale tensor must have dimension 1");
TORCH_CHECK(
zero_points.dim() == 1, "zero_points tensor must have dimension 1")
Expand Down
1 change: 0 additions & 1 deletion aten/src/ATen/native/quantized/cpu/fbgemm_utils.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once

#include <c10/core/QScheme.h>

#ifdef USE_FBGEMM
#include "fbgemm/Fbgemm.h"
#include "fbgemm/QuantUtils.h"
Expand Down
3 changes: 1 addition & 2 deletions aten/src/ATen/native/quantized/cpu/qconv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ class QConv2dInt8 final : public c10::OperatorKernel {
int32_t act_zero_point = act.q_zero_point();

std::vector<float> output_multiplier_float(1, 0.0);
auto qtype = kPerTensorAffine;
TORCH_CHECK(
pack_ptr.w_scale.size() == pack_ptr.w_zp.size(),
"Weight scales and zero points vectors should have the same size.");
Expand Down Expand Up @@ -185,7 +184,7 @@ class QConv2dInt8 final : public c10::OperatorKernel {
act_ptr,
*packB,
reinterpret_cast<uint8_t*>(output.data_ptr<c10::quint8>()),
buffer.data<int32_t>(),
buffer.data_ptr<int32_t>(),
outputProcObj,
0 /* thread_id*/,
1 /* num_threads */);
Expand Down
3 changes: 1 addition & 2 deletions aten/src/ATen/native/quantized/cpu/qconv_unpack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,11 @@ class QConvUnpackWeightsInt8 final : public c10::OperatorKernel {
pack_ptr.w_zp.size(),
device(kCPU).dtype(kInt));

// The output channel axis is 0
unpacked_weights = _empty_per_channel_affine_quantized_like(
scales.toType(kDouble),
zero_points.toType(kLong),
{output_channels, kernel_h, kernel_w, C_per_G},
{0},
{0}, /* The output channel axis is 0 */
device(kCPU).dtype(kQInt8));
}
int8_t* unpacked_weights_p =
Expand Down

0 comments on commit fcab254

Please sign in to comment.