Size and latency of seven precision configurations, three of them fasterai Quantizer calls, on a CPU and on a GPU
Overview
This notebook times seven precision configurations on a CPU model and six on a GPU model, and reports their size and latency. Three come from fasterai’s Quantizer (x86/static, torchao/int8_weight_only, torchao/int8_dynamic); the rest use .half() and torchao’s quantize_ directly. Quantizer backends and methods not run here (pt2e, qnnpack, fbgemm, onednn, method='dynamic', method='qat') are out of scope. No accuracy is measured for the quantized models; the training table below reports the baseline’s validation accuracy only.
CPU section: ResNet-18 fine-tuned for 3 epochs on Oxford Pets at 64x64, timed on one training batch (dls.one_batch(), at ImageDataLoaders.from_name_func’s default bs=64; the page does not print the batch shape).
GPU section: torchvision ResNet-50 with random weights (weights=None) on a random batch of 32 images at 224x224, on the GPU that the page names below.
Protocol for both sections: each configuration is timed in one block of 50 iterations after 10 warm-up iterations (3 for the torch.compile row), wall-clock time.time(), with torch.cuda.synchronize() around the GPU blocks; the blocks run once each, in the order shown, baseline first. No dispersion, no interleaved comparison and no output-parity check against the FP32 model is reported. Sizes are the state_dict files on disk, in MB of 10^6 bytes; the compiled model’s size is not measured.
Weights and activations in INT8, with a calibration pass over dls.valid. At 16.8 ms against 25.9 ms it is the largest CPU latency difference on this page, and the only one above 10%, at a quarter of the size. With one timing block per configuration and no dispersion reported, the page cannot say how much of any difference is run-to-run variation.
Only the weights are INT8; activations stay FP32; no calibration. The torchao backend rewrites Linear layers only, not convolutions (see the Quantizer reference), which is why the file barely moves on a ResNet, 45.3 MB against 46.9 MB. The latency comes out 7% below FP32, 24.0 ms against 25.9 ms; with a single timing block per configuration this page cannot separate that from run-to-run variation.
W8A32 weight-only (torchao) size= 45.3 MB latency= 24.01 ms
5. W8A8 dynamic (torchao)
INT8 weights, activations quantized on the fly at run time; no calibration. Linear layers only, so the same 45.3 MB as W8A32; here 25.5 ms against 25.9 ms for FP32, a difference one timing block cannot resolve.
W8A8 dynamic (torchao) size= 45.3 MB latency= 25.48 ms
6. W4A32 (INT4 weight-only)
Weights in 4 bits through torchao’s IntxWeightOnlyConfig, applied to Conv2d and Linear layers. The file is about four times smaller; on this CPU the latency is higher than FP32, 30.2 ms against 25.9 ms.
W4A32 (INT4 weight-only) size= 12.0 MB latency= 30.18 ms
7. W4A16 (INT4 weights, FP16 activations)
The INT4 model above with activations in half precision. Nearly the same size as W4A32, 11.9 MB against 12.0 MB; on CPU its latency is in the same range as the half-precision row of section 2, 658 ms against 633 ms.
W4A16 (INT4 + half) size= 11.9 MB latency=658.23 ms
GPU benchmarks
The same methods on ResNet-50 with random weights (weights=None) and a random batch of 32 images at 224x224, plus torch.compile on the FP16 model. Latency only: with random weights there is no accuracy to compare and no parity check against a trained reference. The size printed for the compiled model is typed into the cell, not measured.
The figures are the ones printed above, rounded to the precision shown; this table restates them.
Configuration
CPU: ResNet-18, one training batch at 64x64
GPU: ResNet-50, batch of 32 at 224x224
FP32
46.9 MB, 25.9 ms
102.5 MB, 7.66 ms
FP16 (.half())
23.5 MB, 633 ms
51.3 MB, 4.24 ms
W8A8 static (x86)
11.9 MB, 16.8 ms
not run
W8A32 weight-only (torchao)
45.3 MB, 24.0 ms
96.4 MB, 7.66 ms
W8A8 dynamic (torchao)
45.3 MB, 25.5 ms
not run
W4A32 (INT4 weight-only)
12.0 MB, 30.2 ms
26.4 MB, 8.38 ms
W4A16 (INT4 + half)
11.9 MB, 658 ms
26.0 MB, 5.09 ms
FP16 + torch.compile
not run
size not measured, 2.25 ms
Measured on: CPU section, an x86 CPU that the page does not identify; ResNet-18 fine-tuned 3 epochs on Oxford Pets, one training batch at 64x64 (default bs=64, shape not printed). GPU section, NVIDIA GeForce RTX 5090; ResNet-50 with random weights, random 32x3x224x224 input. Each configuration: one block of 50 iterations after 10 warm-ups (3 for the compiled row), wall-clock time, run once, no dispersion, no interleaving, no parity check. Nothing here was measured on other hardware, batch sizes or models.