Quantization, batching, and the memory tricks that got inference running on cheap edge hardware.
Fix the memory and latency budget first, then choose the model. Not the other way around.
Post-training dynamic quantization is usually the cheapest win:
import torch
# dynamic INT8 quantization for CPU / edge inference
quantized = torch.quantization.quantize_dynamic(
model, {torch.nn.Linear}, dtype=torch.qint8
)
torch.save(quantized.state_dict(), "model.int8.pt")Code language: Python (python)
FANAP Advanced Technologies Laboratory