DiffQ is a differentiable quantization framework for PyTorch that provides tools to quantize PyTorch models, primarily focusing on large language models (LLMs) and computer vision models. It enables quantization-aware training and leverages various quantization methods like GPTQ, HQQ, and AWQ. Currently at version 0.2.4, it has seen active development, especially in late 2023, with periodic releases addressing new features and bug fixes.
pip install diffqVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to convert a standard PyTorch model into a `DiffQModel` using a `BaseQuantizationConfig`. While this example uses `quant_method="none"` for structural conversion, for actual quantization (e.g., 4-bit, 8-bit), you would specify a method like `"gptq"` and then run a specific quantizer (e.g., `GPTQQuantizer`) with a dataloader.
Verify your PyTorch, CUDA toolkit, and GPU driver versions against the `pytorch_quantization` and `diffq` requirements (usually found in their GitHub repositories' `setup.py` or documentation). Reinstalling PyTorch with the correct CUDA version is often necessary.
Install the specific optional dependencies required for your desired quantization method. For example, `pip install diffq[hqq_ext]` for HQQ, or `pip install bitsandbytes` for 8-bit quantization.
Review `diffq` documentation on supported module types and recommended practices for custom models. Start with simpler quantization schemes and gradually increase complexity. Be prepared to implement custom `QuantizedModule`s if necessary.