Skip to content

Commit

Permalink
Remove set_quantizer_ from native_functions.yaml (#49463)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #49463

set_quantizer_ takes a ConstQuantizerPtr argument, which is neither supported by JIT nor by c10.
Also, it doesn't get dispatched (CPU and CUDA have the same implementation) and it is excluded from python bindings generation.
So there is no real reason why this needs to be in native_functions.yaml

Removing it unblocks the migration to c10-fullness since this is an op that would have been hard to migrate. See https://fb.quip.com/QRtJAin66lPN
ghstack-source-id: 118710663

Test Plan: waitforsandcastle

Reviewed By: ezyang

Differential Revision: D25587763

fbshipit-source-id: 8fab921f4c256c128d48d82dac731f04ec9bad92
  • Loading branch information
smessmer authored and facebook-github-bot committed Dec 17, 2020
1 parent f5b68e7 commit 26974e6
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 24 deletions.
2 changes: 1 addition & 1 deletion aten/src/ATen/native/Copy.cpp
Expand Up @@ -171,7 +171,7 @@ static Tensor & copy_impl(Tensor & self, const Tensor & src, bool non_blocking)
TORCH_CHECK(self.qscheme() == src.qscheme(),
"Quantized Copy only works with same qscheme");
TORCH_CHECK(self.scalar_type() == src.scalar_type());
self.set_quantizer_(src.quantizer());
set_quantizer_(self, src.quantizer());
}

if (!self.is_quantized() && src.is_quantized()) {
Expand Down
5 changes: 0 additions & 5 deletions aten/src/ATen/native/native_functions.yaml
Expand Up @@ -5455,11 +5455,6 @@
CPU: set_cpu_
CUDA: set_cuda_

- func: set_quantizer_(Tensor(a!) self, ConstQuantizerPtr quantizer) -> Tensor(a!)
variants: method
dispatch:
QuantizedCPU, QuantizedCUDA: set_quantizer_

- func: is_set_to(Tensor self, Tensor tensor) -> bool
use_c10_dispatcher: full
variants: method
Expand Down
5 changes: 0 additions & 5 deletions aten/src/ATen/native/quantized/QTensor.cpp
Expand Up @@ -128,11 +128,6 @@ QScheme qscheme_quant(const Tensor& self) {
return quantizer->qscheme();
}

Tensor& set_quantizer_(Tensor& self, ConstQuantizerPtr quantizer) {
get_qtensorimpl(self)->set_quantizer_(quantizer);
return self;
}

Tensor quantized_clone(
const Tensor& self,
c10::optional<c10::MemoryFormat> optional_memory_format) {
Expand Down
12 changes: 6 additions & 6 deletions aten/src/ATen/native/quantized/cpu/fbgemm_utils.cpp
Expand Up @@ -237,8 +237,8 @@ template <>
Tensor TransposeConvTensorUnpackConversion<2>(const Tensor& src, int groups) {
// OC IC/G HW -> IC OC/G HW logically
auto oc_g_ic_g_hw_tensors = src.chunk(groups);
auto fused_tensor =
at::cat(oc_g_ic_g_hw_tensors, 1).set_quantizer_(src.quantizer());
auto fused_tensor = at::cat(oc_g_ic_g_hw_tensors, 1);
set_quantizer_(fused_tensor, src.quantizer());
return fused_tensor.permute({1, 0, 2, 3});
}

Expand Down Expand Up @@ -284,8 +284,8 @@ template <>
Tensor TransposeConvTensorUnpackConversion<3>(const Tensor& src, int groups) {
// OC IC/G DHW -> IC OC/G DHW logically
auto oc_g_ic_g_hw_tensors = src.chunk(groups);
auto fused_tensor =
at::cat(oc_g_ic_g_hw_tensors, 1).set_quantizer_(src.quantizer());
auto fused_tensor = at::cat(oc_g_ic_g_hw_tensors, 1);
set_quantizer_(fused_tensor, src.quantizer());
return fused_tensor.permute({1, 0, 2, 3, 4});
}

Expand All @@ -302,8 +302,8 @@ Tensor ConvertConvWeightsToChannelLastTensor<2>(
for (auto& tensor : ic_g_oc_g_hw_tensors) {
tensor = tensor.unsqueeze(0);
}
auto fused_tensor =
at::cat(ic_g_oc_g_hw_tensors).set_quantizer_(src.quantizer());
auto fused_tensor = at::cat(ic_g_oc_g_hw_tensors);
set_quantizer_(fused_tensor, src.quantizer());
return fused_tensor.permute({0, 2, 3, 4, 1})
.contiguous(c10::MemoryFormat::Contiguous);
}()
Expand Down
6 changes: 3 additions & 3 deletions aten/src/ATen/native/quantized/cpu/qadd.cpp
Expand Up @@ -88,7 +88,7 @@ Tensor _add_scalar_out(Tensor& out, const Tensor& self, Scalar other) {
if (q_min > z - c_q) {
s_prime = (((double)q_max - (z - c_q))) / ((double)q_max - q_min) * s;
z_prime = q_min;
out.set_quantizer_(make_per_tensor_affine_quantizer(
set_quantizer_(out, make_per_tensor_affine_quantizer(
s_prime, z_prime, self.scalar_type()));
if (ReLUFused) {
qadd_scalar_relu_stub(self.device().type(), out, self, c_q);
Expand All @@ -98,7 +98,7 @@ Tensor _add_scalar_out(Tensor& out, const Tensor& self, Scalar other) {
} else if (q_max < z - c_q) {
s_prime = ((double)(z - c_q) - q_min) / ((double)q_max - q_min) * s;
z_prime = q_max;
out.set_quantizer_(make_per_tensor_affine_quantizer(
set_quantizer_(out, make_per_tensor_affine_quantizer(
s_prime, z_prime, self.scalar_type()));
if (ReLUFused) {
qadd_scalar_relu_stub(self.device().type(), out, self, c_q);
Expand All @@ -109,7 +109,7 @@ Tensor _add_scalar_out(Tensor& out, const Tensor& self, Scalar other) {
s_prime = s;
z_prime = z - c_q;
out.copy_(self);
out.set_quantizer_(make_per_tensor_affine_quantizer(
set_quantizer_(out, make_per_tensor_affine_quantizer(
s_prime, z_prime, self.scalar_type()));
if (ReLUFused) {
at::native::relu_quantized_cpu_(out);
Expand Down
6 changes: 3 additions & 3 deletions aten/src/ATen/native/quantized/cpu/qmul.cpp
Expand Up @@ -59,7 +59,7 @@ Tensor _mul_scalar_out(Tensor& out, const Tensor& self, Scalar other) {
} else {
out.copy_(self);
}
out.set_quantizer_(make_per_tensor_affine_quantizer(
set_quantizer_(out, make_per_tensor_affine_quantizer(
scale_prime, zero_point_prime, self.scalar_type()));
} else if (other_val == 0.0) {
scale_prime = 1.0;
Expand All @@ -74,7 +74,7 @@ Tensor _mul_scalar_out(Tensor& out, const Tensor& self, Scalar other) {
[&](Vec256<scalar_t> vec) -> Vec256<scalar_t> {
return Vec256<scalar_t>(scalar_t(0));
});
out.set_quantizer_(make_per_tensor_affine_quantizer(
set_quantizer_(out, make_per_tensor_affine_quantizer(
scale_prime, zero_point_prime, self.scalar_type()));
} else /* other_val < 0.0 */ {
scale_prime = std::abs(other_val) * self_scale;
Expand All @@ -91,7 +91,7 @@ Tensor _mul_scalar_out(Tensor& out, const Tensor& self, Scalar other) {
}
return a;
});
out.set_quantizer_(make_per_tensor_affine_quantizer(
set_quantizer_(out, make_per_tensor_affine_quantizer(
scale_prime, zero_point_prime, self.scalar_type()));
}
});
Expand Down
4 changes: 4 additions & 0 deletions aten/src/ATen/quantized/Quantizer.cpp
Expand Up @@ -207,4 +207,8 @@ Tensor PerChannelAffineFloatQParamsQuantizer::dequantize(Tensor qtensor) {

Quantizer::~Quantizer() {}

C10_EXPORT void set_quantizer_(const Tensor& self, ConstQuantizerPtr quantizer) {
get_qtensorimpl(self)->set_quantizer_(quantizer);
}

} // namespace at
2 changes: 2 additions & 0 deletions aten/src/ATen/quantized/Quantizer.h
Expand Up @@ -225,4 +225,6 @@ CAFFE2_API Tensor new_qtensor(
const TensorOptions& options,
QuantizerPtr quantizer);

CAFFE2_API void set_quantizer_(const Tensor& self, ConstQuantizerPtr quantizer);

} // namespace at
1 change: 0 additions & 1 deletion tools/autograd/gen_python_functions.py
Expand Up @@ -78,7 +78,6 @@
'copy_sparse_to_sparse_', 'copy_',
'numpy_T', # this needs to be an attribute in Python, not a function
'nonzero(_(out|numpy))?',
'set_quantizer_', # return types not supported yet
'set_data',
'.*_overrideable', # overrideable functions for backend extension
'data', 'is_leaf', 'output_nr', '_version', 'requires_grad_', 'retain_grad', 'set_'
Expand Down

0 comments on commit 26974e6

Please sign in to comment.