-
-
Save imaginary-person/111e9ece31a4c754bde3c41936cae496 to your computer and use it in GitHub Desktop.
Quantization benchmark
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch | |
import time | |
x = torch.rand(1, 256, 256, 256) | |
y = torch.rand(1, 256, 256, 256) | |
print('dtype', 'ms/iter (float)', 'ms/iter (quant)', 'quant / float', sep='\t') | |
for dtype in [torch.quint8, torch.qint8, torch.qint32]: | |
qX = torch.quantize_per_tensor(x, 0.1, 5, dtype) | |
qY = torch.quantize_per_tensor(y, 0.1, 5, dtype) | |
NITER = 1000 | |
# Test float | |
s = time.time() | |
for i in range(NITER): | |
x + y | |
elapsed_float = time.time() - s | |
ms_per_iter_float = elapsed_float / NITER * 1000 | |
# Test quantized | |
s = time.time() | |
for i in range(NITER): | |
torch.ops.quantized.add(qX, qY, 0.1, 5) | |
elapsed = time.time() - s | |
ms_per_iter = elapsed / NITER * 1000 | |
print(str(dtype), ms_per_iter_float, ms_per_iter, ms_per_iter / ms_per_iter_float, sep='\t') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Single-thread results
AVX512
AVX2
Multiple threads results (32 threads, Two NUMA nodes with 32 physical cores, Hyperthreading ON)
AVX512
AVX2