TorchAO Backend Guide
The TorchAO backend leverages PyTorch’s torchao library for quantization-based model tuning. It provides various quantization schemes for weight-only and dynamic quantization.
Overview
- Weight-Only Quantization: INT8, FP8
- Dynamic Quantization: INT8, FP8, MXFP8, and NVFP4 with dynamic activations
- Easy Configuration: Predefined quantization types
- Pure PyTorch: No external dependencies beyond torchao
Quick Start
Quantization Types
Weight-Only Quantization
Dynamic Quantization
Configuration Options
TorchAOBackendConfig
Using Predefined Types
Custom Configuration
Use either quantization or quantization_config, not both.
torch.compile Options
TorchAOBackend quantizes the module and then runs it through torch.compile.
Supported mode values follow torch.compile: "default", "reduce-overhead", "max-autotune", and "max-autotune-no-cudagraphs".
Filtering Modules
Use filter_fn to restrict quantization to compatible submodules. The predicate receives (module, fqn) and should return True for modules that TorchAO should quantize.
Quantization Comparison
mxfp8dq and nvfp4dq require hardware and torchao support for the corresponding formats. AITune defers that validation until backend build time.
Best Practices
- Start with FP8: Best accuracy/performance trade-off
- Use INT8 for Memory: When memory is critical
- Dynamic Quantization: Better accuracy, slightly higher overhead
- Validate Accuracy: Always test quantized model accuracy
- Calibration Data: Use representative samples
Troubleshooting
Issue: Accuracy loss too high
Solution: Try less aggressive quantization:
Issue: Not enough speed improvement
Solution: Try dynamic quantization:
Next Steps
- Learn about TensorRT Backend for maximum performance
- Compare with Torch Inductor JIT Backend
- Review Deployment Guide