Repository navigation
Tetra
🏠 Home · 🧭 Choose a method · 🚀 Quickstart · 🧰 Help
On this page
Tetra uses calibration data to compress each full block of 24 weights into a 48-bit code. It rotates the weights and the calibration Hessian, then uses the Hessian to compensate for each block's quantization error in later columns. The last partial block stays unquantized in the rotated basis. Row scales, shared gain centroids, and the tail add overhead beyond the two bits per weight in the full blocks.
import torch
from gptqmodel import BACKEND, CalibrationConfig, GPTQModel
from gptqmodel.quantization import TetraConfig
model = GPTQModel.load(
"Qwen/Qwen2.5-0.5B-Instruct",
quantize_config=TetraConfig(search_effort="balanced"),
device="cuda",
dtype=torch.bfloat16,
)
model.quantize(CalibrationConfig(dataset=calibration_texts))
model.save("qwen2.5-0.5b-tetra")
quantized = GPTQModel.load(
"qwen2.5-0.5b-tetra",
backend=BACKEND.TETRA_TORCH,
device="cuda",
dtype=torch.bfloat16,
)Supply representative text in calibration_texts. When an individual module has no usable Hessian, the quantizer falls back to an identity Hessian. See calibration data and policy.
Use TetraConfig(...) or QuantizeConfig(method="tetra", ...). Tetra fixes bits=2, group_size=-1, desc_act=False, and sym=True. Each code covers 24 weights regardless of the group_size sentinel.
Set Tetra options on the run-level config. To keep a projection dense, use a dynamic exclusion such as dynamic={"-:proj": {}}. New configs reject per-module override values. Loading an older config discards those values and preserves the matching rules.
| Field | Default | Behavior |
|---|---|---|
search_effort |
"balanced" |
"fast" searches one trial scale. "balanced" uses two. "paper" uses two scales and a wider shrink grid. |
rotation_seed |
1234 |
Integer seed for the deterministic rotation. Booleans and floating-point values raise TypeError. The checkpoint stores the rotation tensors used at reload. |
percdamp |
0.01 |
Hessian damping fraction in [0, 1). |
damp_auto_increment |
0.0 |
Nonnegative damping increment used by the Hessian solver when retrying. |
The safetensors checkpoint uses method and format tetra. Each packed linear requires codes (six bytes per full block per output row), row_scales, gain_centroids, rotation_signs, and rotation_small. The loader also requires tail for projections whose input width is not a multiple of 24 and bias for biased projections. The save-time compatibility warning directs you to GPTQModel.load. File-based dense checkpoint dequantization does not support Tetra.
For an interrupted quantization run, Tetra supports layer-boundary continuation with CheckpointConfig on eligible sources. See checkpoint requirements and usage.
BACKEND.AUTO selects TETRA_TORCH. The portable Torch kernel declares CPU, NVIDIA CUDA, AMD ROCm, XPU, NPU, and MPS support with FP16, BF16, or FP32 activations. Even under autocast, it rotates the input, decodes weights, and computes the linear reduction and bias addition in FP32 before casting the output to the input dtype. Set the activation dtype before the first forward. Generation stays eager by default. The kernel declares opt-in Inductor support on CPU.
On NVIDIA CUDA or AMD ROCm with the triton package installed, set backend=BACKEND.TETRA_TRITON (or backend="tetra_triton") in the reload example to opt into the fused kernel. It reads the same checkpoint and combines activation rotation, 48-bit code decoding, and matrix multiplication in one launch. It accepts FP16, BF16, and FP32 activations, accumulates in FP32, and returns the input dtype. This backend runs eagerly. A layer falls back to the portable Torch kernel if its padded input width exceeds 8,192 columns or its rotation requires more than 128 padded chunks.
Pass the same backend argument to model.quantize(...) to select the Triton runtime for the newly packed layers in the live model.
The encoder uses lexicographic rank order to break ties at the code table cutoff. It keeps the zero code whenever its reconstruction error is smallest.
Documentation home · Quickstart · Troubleshooting · Repository · PyPI
Public source 780f1bbfc declares package version 7.15.0. Individual pages identify their source revisions. Choose a method · Dtypes and formats. Maintained by ModelCloud.ai.
🧭 1 · Choose and understand
🚀 2 · Use it
- Installation and Quickstart
- Loading and Inference
- LeapQuant recurrent-state quantization
- Evaluation
- Serving
- Troubleshooting and FAQ
- Memory, Offload, Multi-GPU
- MLX / Apple Silicon
- Tenstorrent / Block Floats
- Hugging Face Integration
- Multimodal and MoE Models
🎛️ Methods and representations
Each guide: choose → examples → math / advanced
- GPTQ / GPTAQ / G2PTQ / ADMM-Q / RTN
- SINQ
- JointQ
- AWQ
- QQQ
- MACaQ / MXFP4
- EXL3
- CPTC
- VPTQ
- Tetra
- TWLA
- Paro
- FP8 and NVFP4
- NF12: lossless BF16 storage
- GGUF families
- BitsAndBytes: NF4 / FP4 / INT8
🧰 Refinement and execution
- GSQ refinement / allocation
- EoRA adapters
- Rotation, Smoothing, Norm Tuning
- Projection Fusion
- TurboQuant KV cache
🧠 3 · Theory and advanced reference