█

AI/TLDR

Buy me a coffee
Buy me a coffee

HQQ

Calibration-free quantization for LLMs and vision models down to 1 bit

Quantization & CompressionOpen source
Language
Python
IN SHORT

What is HQQ?

HQQ (Half-Quadratic Quantization) is a method for shrinking the weights of large models so they take up less memory. It sits in the Quantization & Compression category of the Models & Inference tools and is open-source, written in Python. To get started: install HQQ.

Overview

HQQ (Half-Quadratic Quantization) is a method for shrinking the weights of large models so they take up less memory. It compresses weights to lower bit widths (8, 4, 3, 2, or even 1 bit) and, unlike many other quantization methods, it does not need any calibration dataset to do so.

Because it skips calibration, HQQ can quantize even very large models in a few minutes. It works on any model type, including LLMs and vision models, and integrates with HuggingFace Transformers as well as its own library for saving and loading quantized checkpoints.

It fits in the quantization and compression part of an inference stack: you quantize a model once, then run it with less VRAM. The dequantization step is a plain linear operation, so it stays compatible with torch.compile and optimized CUDA/Triton inference kernels.

What it does

  • Quantizes to 8, 4, 3, 2, or 1 bits with no calibration data required
  • Works on any model, including LLMs and vision models
  • Integrated into HuggingFace Transformers via HqqConfig, with save_pretrained / from_pretrained support
  • Linear dequantization step compatible with optimized CUDA/Triton kernels
  • Aims for full torch.compile compatibility to speed up training and inference
  • Compatible with PEFT training; HQQ+ adds trainable low-rank adapters for better quality at low bits

Getting started

Make sure you have a PyTorch 2 build that matches your CUDA version, then install HQQ and quantize a model. The README recommends starting with nbits=4, group_size=64, axis=1 for a good balance of quality, VRAM, and speed.

Install HQQ

Install the latest stable release from PyPI, or the latest updates straight from GitHub (recommended in the README).

bashbash
# latest stable version
pip install hqq

# latest updates - recommended
pip install git+https://github.com/dropbox/hqq.git

Quantize a linear layer

Replace a torch.nn.Linear layer with an HQQLinear configured by a BaseQuantizeConfig.

pythonpython
from hqq.core.quantize import *

quant_config = BaseQuantizeConfig(nbits=4, group_size=64)

hqq_layer = HQQLinear(your_linear_layer,
                      quant_config=quant_config,
                      compute_dtype=torch.float16,
                      device='cuda',
                      initialize=True,
                      del_orig=True)

y = hqq_layer(x)  # forward-pass

Quantize a Transformers model

Pass an HqqConfig as quantization_config when loading a model from HuggingFace; all linear layers use the same config.

pythonpython
from transformers import AutoModelForCausalLM, HqqConfig

quant_config = HqqConfig(nbits=4, group_size=64)

model = AutoModelForCausalLM.from_pretrained(
    model_id,
    torch_dtype=torch.float16,
    device_map="cuda",
    quantization_config=quant_config,
)

Commands and code are distilled from the project's own documentation — always check the official repo for the latest.

When to use it

  • Fit a large LLM into limited GPU VRAM by quantizing its weights to 4 bits or lower
  • Quickly quantize very large models without preparing a calibration dataset
  • Compress vision or language models for cheaper inference while staying torch.compile compatible
  • Run low-bit quantized models through HuggingFace Transformers with standard save/load workflows

How HQQ compares

HQQ alongside other open-source quantization & compression tools AI/TLDR tracks, ranked by GitHub stars.

ToolStarsWhat it does
BitNet★ 42.6kMicrosoft's inference framework for running extremely low-bit (1.58-bit) quantized LLMs efficiently on CPUs.
bitsandbytes★ 8.6kA library that adds 8-bit and 4-bit quantization to PyTorch models, widely used for loading and fine-tuning LLMs in low memory.
LLM Compressor★ 4kA library for applying quantization and sparsity methods to LLMs to produce compressed models that run faster in vLLM.
AWQ★ 3.7kThe reference implementation of Activation-aware Weight Quantization for compressing LLMs to 4-bit with little accuracy loss.
torchao★ 3kPyTorch's native library for quantizing and applying low-bit data types to models for faster training and inference.
Intel Neural Compressor★ 2.7kAn Intel toolkit for compressing models through quantization, pruning, and distillation across multiple deep-learning frameworks.
GPTQModel★ 1.3kA model quantization toolkit, successor to AutoGPTQ, that compresses LLMs with GPTQ, AWQ, and other methods across many chips.
HQQ★ 964Calibration-free quantization for LLMs and vision models down to 1 bit