Repository navigation
LeapQuant
🏠 Home · 🧭 Choose a method · 🚀 Quickstart · 🧰 Help
On this page
LeapQuant compresses the fixed-size recurrent state of delta-rule linear attention during native GPT-QModel inference. It works with dense or weight-quantized checkpoints on supported ports without changing the weights, checkpoint format, or quant_method.
LeapQuant was introduced by Yi Pan et al. in LeapQuant: Efficient Linear Attention with Accurate Recurrent State Quantization. See the official implementation and BibTeX citation.
Source revision ccc7868a1.
Pass state_quant=LeapQuantConfig(...) to GPTQModel.load() with a local path or Hub ID for a supported checkpoint. LeapQuant is off by default.
from gptqmodel import GPTQModel, LeapQuantConfig
model = GPTQModel.load(
"/path/to/supported-checkpoint",
state_quant=LeapQuantConfig(bits=8),
)
output_ids = model.generate("Explain linear attention.", use_cache=True, max_new_tokens=64)For an already loaded model, call model.enable_state_quant(LeapQuantConfig()) or model.enable_state_quant(None) before the first forward to select packed or dense state. Start generation with a fresh cache to apply the policy. A caller-provided past_key_values keeps the policy it was created with. With no supplied cache, use_cache=False skips cache creation. Passing a config to a model with no supported port raises ValueError. Loader source · Toggle source.
LeapQuantConfig field |
Default | Effect |
|---|---|---|
bits |
8 |
Symmetric code width. The 4 and 6 modes bit-pack their codes for lower storage. Start with 8 for accuracy. |
window |
16 |
Positive number of decode-token updates between requantizations. 1 requantizes after every decode token. |
rank |
4 |
Number of low-rank Compensator Tokens. 0 disables them. The rank must fit both head dimensions. |
smooth |
True |
Rescales key rows of the residual before quantization. |
buffer_dtype |
torch.bfloat16 |
Dtype for buffered keys and updates. Accepts torch.float16, torch.bfloat16, or torch.float32. |
lowrank_iters |
2 |
Nonnegative number of power iterations for the Compensator fit. |
lowrank_oversample |
4 |
Nonnegative number of extra sketch columns for the fit. |
seed |
0 |
Integer seed for the randomized Compensator fit. |
See the configuration and state implementation.
| Native model port | Recurrent layers |
|---|---|
| Kimi K3 | Kimi Delta Attention (KDA) |
| Dense Qwen3.5 (multimodal wrapper or text wrapper) | Gated DeltaNet (GDN) |
| GLM-5.3 | KDA |
LeapQuant applies to the listed ports' recurrent layers. Other attention layers keep their usual cache format. Use native GPT-QModel generation and leave cache_implementation at the port's default.
- Use unpadded prompts with either no attention mask or a 2D all-ones mask. Packed sequence boundaries such as
cu_seqlensare rejected. - Ordinary generation and cached continuation are supported. Live sequences can be reordered at the same batch size. A forward with a changed batch size or recurrent-state geometry raises
ValueError. Start with a fresh cache for a different shape. Live batch expansion and cache cropping are unsupported. - Use the packed state for inference. Training and autograd are unsupported.
Prefill runs the port's existing recurrence and quantizes its final state. During decode, LeapQuant keeps a quantized state between window boundaries and buffers the per-token decay, key, and update records. At a boundary it fits a low-rank Compensator, smooths the remaining residual when enabled, and quantizes it again.
Persistent storage includes the codes, FP32 scales, FP16 Compensator factors, and the window buffer. Each code row represents V values along the recurrent state's value dimension.
| Code width | Stored code row | Bytes per row |
|---|---|---|
4 |
uint8, two signed codes per byte |
ceil(V / 2) |
6 |
uint8, four signed codes per three bytes |
3 * ceil(V / 4) |
8 |
int8, one signed code per byte |
V |
Packing reduces the code tensor. Scales, Compensator factors, and window buffers also contribute to total storage. LeapQuantState.checkpoint_bytes() counts the codes, scales, and factors, and storage_bytes() includes the window buffers. During decode, the portable Torch path unpacks 4- and 6-bit codes for the current dequantization and materializes a temporary FP32 recurrent state. Prefill uses a dense transient state.
LeapQuantState.packed_state() returns a version 2 snapshot with code_container set to "packed4", "packed6", or "int8". load_packed_state() checks the format version, container, and state configuration. Version 1 snapshots are rejected. Use a fresh cache when upgrading.
The randomized Compensator fit uses a Cholesky factor and a small Gram-matrix eigendecomposition. Decode checks the output and both buffer casts for finite values together before updating the state. State implementation.
With 8 heads, key and value dimensions of 128, and the default bits=8, window=16, and rank=4, the repository's benchmark measured 724 µs per LeapQuant decode token and 64–70 µs for a dense FP32 step on one accelerator. The Compensator fit took 1175 µs per window and is included in the average LeapQuant decode time. Benchmark results.
Run the benchmark from the source checkout with GPT-QModel installed. Set --bits to 4, 6, or 8 (the default) to compare checkpoint storage and decode timings. Benchmark script.
python scripts/benchmark_leapquant_state.py --device cuda --bits 4Documentation home · Quickstart · Troubleshooting · Repository · PyPI
Public source 8d42d0c29 declares package version 7.12.4. 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
- JointQ
- AWQ
- QQQ
- MACaQ / MXFP4
- EXL3
- CPTC
- VPTQ
- Paro
- FP8 and NVFP4
- NF12: lossless BF16 storage
- GGUF families
- BitsAndBytes: NF4 / FP4 / INT8
🧰 Refinement and execution
🧠 3 · Theory and advanced reference