Introduction
State Space Models (SSMs) like Mamba have emerged as powerful alternatives to Transformers, offering linear scaling with sequence length. However, as these models scale, they encounter a significant memory bottleneck: the state cache. Q-Mamba is a post-training quantization (PTQ) framework designed to address this by quantizing Mamba state caches down to 4 bits, effectively halving memory consumption while maintaining high accuracy. It is the first framework to successfully tackle the unique outlier problems inherent in SSM states without sacrificing the architecture's signature parallel processing speed.
The State Cache Bottleneck
In architectures like Mamba-2, states are expanded significantly—often up to 128 times larger than standard activations. During token generation, these massive caches can dominate GPU memory usage, particularly at larger batch sizes.
As shown in the figure above, at a batch size of 128, the state cache can account for nearly 80% of the total memory footprint. This bottleneck limits the maximum batch size and increases inference latency. Standard quantization methods fail to address this because Mamba states exhibit extreme outliers in two distinct dimensions simultaneously: the state dimension and the channel dimension. This "two-dimensional" outlier problem causes standard quantization slots to be wasted on empty space, leading to catastrophic accuracy drops.
The Q-Mamba Framework
Q-Mamba introduces a two-stage quantization process to optimize both states and weights, as illustrated in the framework overview below.
Decoupled Scale Quantization (DSQ)
The primary challenge in quantizing Mamba states lies in their unique distribution. Unlike standard activations, Mamba states are formed by the outer product of two vectors, leading to extreme outliers along both the state and channel dimensions. Standard quantization methods, which typically use a single scaling factor, fail to capture this variance.
DSQ addresses this by decoupling the scaling factors. By applying independent scales to the state and channel dimensions, Q-Mamba can effectively "wrap" the quantization grid around the outliers in both directions. This mathematical grounding allows the model to maintain high precision even at 4-bit depths, significantly reducing rounding errors.
Efficient Selectivity Reconstruction (ESR)
Post-training quantization often requires a small amount of fine-tuning to recover accuracy. However, Mamba's speed comes from its "parallel scan" algorithm, which requires mathematical linearity. Standard step-by-step quantization breaks this linearity, making traditional fine-tuning prohibitively slow.
ESR overcomes this through two clever strategies:
- Error Simulation: It employs a "simulated error" approach, quantizing only the final timestep during the reconstruction phase. This allows the model to learn to compensate for quantization noise while still utilizing high-speed parallel kernels.
- Selectivity Guided Adaptation (SGA): It focuses updates exclusively on the parameters that control the model's "selective" behavior (i.e., what to remember or forget). Since these parameters account for only ~2% of the total model, the reconstruction process is both fast and memory-efficient.
Experimental Results and Discussion
The researchers evaluated Q-Mamba across various benchmarks, including WikiText2, C4, and several zero-shot tasks such as PIQA and HellaSwag.
- Memory Efficiency: Achieved a 50% reduction in memory consumption for Mamba2-2.7B.
- Accuracy Preservation: In the W8A8H4 configuration (8-bit weights/activations, 4-bit states), Q-Mamba showed only a 2.13% average accuracy degradation across zero-shot tasks.
- Superior Perplexity: On WikiText2, Q-Mamba maintained a perplexity of 12.99 with 4-bit states, whereas baseline quantization methods collapsed, jumping to a perplexity of 21.18 even with 6-bit states.
- Inference Speed: Custom Triton kernels provided a 1.18x speedup on NVIDIA RTX 3090 GPUs.
Quantization as a Stabilizer
One of the most surprising findings was Q-Mamba's performance on long-context tasks (up to 8,000 tokens). In some cases, the 4-bit quantized model outperformed the full-precision baseline. This is attributed to a "stabilizer" effect: Mamba models can suffer from "state explosion," where values in certain channels grow uncontrollably over long sequences. Quantization naturally clips these extreme values, acting as a form of regularization that prevents state divergence.
Conclusion
Q-Mamba represents the first successful attempt to quantize Mamba state caches to 4 bits. By addressing the unique outlier characteristics of SSMs and maintaining compatibility with parallel processing, it paves the way for deploying large-scale Mamba models on memory-constrained hardware with minimal performance trade-offs.
Summary updated