Skip to content
Qubitium edited this page Dec 3, 2026 · 5 revisions

FITQ trellis quantization

🏠 Home · 🧭 Choose a method · 🚀 Quickstart · 🧰 Help

On this page

FITQ (Fewest-Instruction Trellis Quantization) compresses linear weights into 16 × 16 trellis-coded tiles in a Hadamard-rotated basis. It supports seven rates from 2 to 6 bits per weight, including 2.5 and 3.5. Each output row has an FP16 scale in addition to the tile bitstream.

Choose FITQ when you have representative calibration data and want to compare a low-bit trellis checkpoint with alternatives such as EXL3. Both dimensions of every quantized projection must be multiples of 16. FITQ kernels require aligned projections and have no automatic padding.

Quantize, save, and reload

Use FITQConfig or QuantizeConfig(method="fitq", ...). Pass representative calibration texts or tokenized rows as calibration in the example.

from gptqmodel import CalibrationConfig, FITQConfig, GPTQModel

model = GPTQModel.load(
    "ibm-granite/granite-3.1-1b-a400m-instruct",
    quantize_config=FITQConfig(bits=3),
)
model.quantize(CalibrationConfig(dataset=calibration, batch_size=4))
model.save("granite-fitq-t3")

reloaded = GPTQModel.load("granite-fitq-t3")

FITQ uses the calibration inputs to estimate a Hessian and feeds each 16-column block’s quantization error into the remaining columns. GPT-QModel uses a beam search to choose the trellis codes. Leave CalibrationConfig.exclude_attention_sinks unset or set it to False.

To quantize entirely on a CPU, use FITQConfig(bits=3, device="cpu") in the same workflow. The JIT-built fitq_cpu extension encodes tiles in parallel and selects AVX-512, AVX2, or scalar execution according to the host CPU. If the extension fails to build, the slower Torch reference encoder takes over. The CPU extension accelerates quantization. CPU inference uses fitq_torch.

On macOS, the CPU encoder builds with Apple Clang's -Xpreprocessor -fopenmp flags and links against libomp. The JIT build needs access to that OpenMP library to use the native path. FITQ CPU extension

Code rates and encoder settings

bits Code Default beam width when keep=None
2 t2 2048
2.5 t2p5 512
3 (default) t3 128
3.5 t3p5 1024
4 t4 1024
5 t5 1024
6 t6 1024

For mixed rates, use a dynamic rule such as dynamic={r"+:.*down_proj.*": {"bits": 3.5}}. Per-module overrides accept only bits. Use exclusion rules to skip modules.

Start with the default encoder settings. scale_grid supplies positive multipliers of the rotated row RMS and defaults to (1.0,). The solver keeps the candidate with the lowest Hessian-weighted error. refit_scales=True also tries a closed-form scale update for the chosen codes. The refit is off by default. Check held-out model quality before using it. See the config reference for all FITQ-specific fields.

FITQ skips a scale-grid candidate or optional refit if converting any of its row scales to FP16 produces a non-finite value. If every grid candidate fails, quantization raises a row-scale error. Keep the projection dense or choose a format with wider scales. The solver rescales operands by powers of two when scoring candidates to avoid overflow in the Hessian-weighted error calculation. It raises if the selected score is non-finite.

The encoder uses an FP16 scale floor of 2⁻¹⁴ and encodes an all-zero projection exactly with zero row scales. For other projections, quantization raises if the final squared reconstruction error divided by the squared weight norm is non-finite or greater than 1.0. An error mentioning the scale floor means some rows' scaled RMS values were below 2⁻¹⁴. Use another quantization method or keep the affected projection dense.

Inference backends

Automatic selection prefers fitq_cuda on Linux CUDA or ROCm. That backend requires NVIDIA SM80 (compute capability 8.0) or newer, or AMD RDNA4 gfx1200/gfx1201, and a buildable native extension. If the native path is unavailable, the layer falls back to Torch.

Backend Execution
fitq_cuda For 1–8 input rows, decodes tiles in registers for GEMV. For 9–64 rows, fuses tile decode with tensor-core GEMM. Above 64 rows, decodes into a BF16 workspace for vendor GEMM.
fitq_torch Portable Torch path for CPU, CUDA, ROCm, XPU, and MPS. Decodes FP32 tiles of output rows in the rotated basis during each forward and releases each tile after multiplication.
mlx Packed Metal inference on compatible MLX-LM architectures, with kernels tuned for Apple M5 Ultra and M6. Uses fused trellis decode and GEMV for 1–8 rows, then a temporary decoded workspace and MLX matmul from 9 rows onward.

All three paths accept FP16, BF16, and FP32 activations. Select the portable eager path explicitly with GPTQModel.load("granite-fitq-t3", backend="fitq_torch").

Torch inference keeps the weights packed between forwards, including when fitq_cuda falls back to Torch. It targets 16 MiB of decoded FP32 weights per tile, with a minimum of 16 output rows. Explicit dequantize_weight() calls still return a dense matrix to the caller.

On NVIDIA GB10 (SM 12.1), fitq_cuda tunes split-K for small token batches and sizes the 9–64-row fused GEMM to the actual row count. With a visible SM 12.1 device and a CUDA 13+ PyTorch build, the JIT build can add a native sm_121 target alongside Torch's resolved targets. The tuning applies automatically. See the GB10 layer benchmarks.

For Apple Metal inference, use GPTQModel.load(checkpoint, backend="mlx") with a model architecture supported by MLX-LM. A single checkpoint-wide rate can use any FITQ rate, including 2.5 and 3.5 bits. The MLX conversion check rejects fractional rates in nonempty dynamic rules. Use fitq_torch for those checkpoints. See MLX setup and FITQ transfer.

On M5 Ultra, MLX automatically raises the GEMV split target from 64 to 160 threadgroups. In the single-layer benchmark, a synthetic 4096 × 4096 t3 layer with BF16 activations went from 0.410 to 0.291 ms at one token and from 0.500 to 0.325 ms at eight tokens.

Checkpoint layout

model.save() writes a GPT-QModel safetensors checkpoint with the fitq format. Reload the checkpoint directory with GPTQModel.load(). Standalone .fitq export is unavailable.

Buffer Content
fitq_streams INT32 trellis words in row-major tile order
fitq_s_row One FP16 scale per output row, stored as INT16 bit patterns
fitq_sign_in, fitq_sign_out Packed INT32 sign masks for the input and output rotations
fitq_meta Four INT32 values for the code index, input and output rotation widths, and FP32 decode-unit bits

The Torch and CUDA layers validate fitq_meta when they first read it. The code index must be in range and match the configured code, the decode unit must be positive and finite, and each rotation width must be a power of two that divides the corresponding projection dimension. Before the first forward, changing the layer's execution dtype preserves the saved bias values and dtype. FITQ layer

Sources

Clone this wiki locally