Revert D20984966: [quant] Generalizing _calculate_dynamic_qparams in quantized test
Test Plan: revert-hammer
Differential Revision:
D20984966
Original commit changeset: 17437297adae
fbshipit-source-id: 30b9f7a2b2a772b2bf1c4b81cf99bddf37d4b179
diff --git a/torch/testing/_internal/common_quantized.py b/torch/testing/_internal/common_quantized.py
index c8ceb7b..65f326a 100644
--- a/torch/testing/_internal/common_quantized.py
+++ b/torch/testing/_internal/common_quantized.py
@@ -43,18 +43,20 @@
according to the min and max element of the tensor"""
if isinstance(X, torch.Tensor):
X = X.numpy()
- if X.size == 0:
- return float(1.0), int(0)
- qinfo = torch.iinfo(dtype)
- qmin = qinfo.min
- qmax = qinfo.max
- n_levels = float(qmax - qmin)
- if reduce_range:
- qmin = qmin // 2
- qmax = qmax // 2
+ if dtype == torch.qint8:
+ if reduce_range:
+ qmin, qmax = -64, 63
+ else:
+ qmin, qmax = -128, 127
+ else: # dtype == torch.quint8
+ if reduce_range:
+ qmin, qmax = 0, 127
+ else:
+ qmin, qmax = 0, 255
+ n_levels = 255.0
min_val = X.min()
max_val = X.max()
- if min_val == max_val == 0:
+ if min_val == max_val:
scale = 1.0
zero_point = 0
else: