pytorch/test/quantization
Vasiliy Kuznetsov 95c00cf029 speed up quantized relu6 inplace kernel (#68404)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/68404

The qclamp kernel is equal to (non inplace) or faster (inplace) than the
qrelu6 kernel.  Removing the qrelu6 kernel and routing qrelu6 to the
qclamp kernel instead.

Test Plan:
```
// correctness
python test/test_quantization.py TestQuantizedOps.test_qrelu6

// benchmarking
import torch
import torch.nn.functional as F
toq = torch.ops.quantized
import time

N_WARMUP = 5
N_ITER = 1000

data = torch.randn(32, 32, 64, 64)
data = torch.quantize_per_tensor(data, 0.05, 0, torch.quint8)

for _ in range(N_WARMUP):
    F.hardtanh(data, 0., 6., inplace=True)
t1 = time.time()
for _ in range(N_ITER):
    F.hardtanh(data, 0., 6., inplace=True)
t2 = time.time()

for _ in range(N_WARMUP):
    toq.relu6(data, inplace=True)
t3 = time.time()
for _ in range(N_ITER):
    toq.relu6(data, inplace=True)
t4 = time.time()

t_hardtanh = t2 - t1
t_qrelu6 = t4 - t3
print(t_hardtanh, t_qrelu6)

// before
0.7156341075897217 1.4007949829101562

// after
0.6825599670410156 0.6571671962738037
```

Reviewed By: jerryzh168

Differential Revision: D32463754

Pulled By: vkuzo

fbshipit-source-id: a87fe5907d7b71d87eb1d5f6588cd509a88f2969
2021-11-21 07:08:23 -08:00
..
ao_migration Set test owners for quantization tests (#66832) 2021-10-21 16:04:41 -07:00
bc Set test owners for quantization tests (#66832) 2021-10-21 16:04:41 -07:00
core speed up quantized relu6 inplace kernel (#68404) 2021-11-21 07:08:23 -08:00
dbr dbr quant: refactor get_func_output_obs_type to only use seen_op_info (#68341) 2021-11-20 15:16:56 -08:00
eager [quant][embedding qat] eager mode QAT for Embeddings (#66429) 2021-11-18 05:57:11 -08:00
fx [quant] Fix comparison against reference for test_qat_functional_linear (#68061) 2021-11-09 13:33:13 -08:00
jit Set test owners for quantization tests (#66832) 2021-10-21 16:04:41 -07:00
serialized fx quant: add a BC test for loading old torch.package models (#65538) 2021-10-11 08:23:38 -07:00
__init__.py