You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2020/10/28 21:26:49 UTC
[GitHub] [incubator-tvm] masahi commented on a change in pull request #6782: [Torch, QNN] Support dynamic quantization flow to enable importing quantized transformer models
masahi commented on a change in pull request #6782:
URL: https://github.com/apache/incubator-tvm/pull/6782#discussion_r513771153
##########
File path: python/tvm/relay/frontend/qnn_torch.py
##########
@@ -826,6 +826,74 @@ def _impl(inputs, _):
return _impl
+def _linear_dynamic():
+ def _calculate_qparam(inp):
+ # reference ATen/native/quantized/cpu/qlinear_dynamic.cpp
+ # ChooseQuantizationParams function
+ mn = _op.min(inp)
+ mx = _op.max(inp)
+
+ # Ensure that the interval contains 0
+ mn = _op.minimum(mn, _op.const(0.0, dtype="float32"))
+ mx = _op.maximum(mx, _op.const(0.0, dtype="float32"))
+
+ qmax = 255
+
+ # reduce_range became True in v1.6
+ if is_version_greater_than("1.5.1"):
+ qmax = 127
Review comment:
This comes from https://github.com/pytorch/pytorch/blob/d642992877139671466d2a96663abede9e39ad55/aten/src/ATen/native/quantized/cpu/quant_utils.h#L64-L66
Here, they intentionally reduce the possible range of quantized values by half, i.e. [qmin, qmax] to [qmin/2, qmax/2]. Since PyTorch only uses uint8, this is fine.
It's not clear to me why they do this, but the following PR has some explanation: "reduce_range option restricts the activation tensor to 7 bits instead of 8.This is necessary to enable per channel quant for RNNs and LSTMs" https://github.com/pytorch/pytorch/pull/39041
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org