Introduction
State Space Models (SSMs), particularly the Mamba architecture, have recently emerged as a compelling alternative to Transformers for computer vision tasks. By offering linear scaling with sequence length, "Visual Mamba" models provide high efficiency for processing high-resolution images. However, deploying these models on edge hardware typically requires quantization—converting 16-bit floating-point (FP16) weights and activations into low-bit integers (e.g., INT8 or INT4).
While quantization is well-established for Transformers, Visual Mamba models prove exceptionally sensitive to bit-depth reduction. This paper introduces PTQ4VM, the first dedicated post-training quantization (PTQ) framework designed to address the unique architectural nuances of Visual Mamba, enabling significant hardware speedups with minimal accuracy degradation.
The Vulnerabilities of Visual Mamba
Standard quantization techniques often fail on Visual Mamba because they do not account for three specific "vulnerabilities" identified by the authors:
- Token-wise Variance: Unlike Transformers, Mamba processes tokens in a fixed sequential order. This leads to specific positions in the sequence developing extreme activation ranges that are independent of the actual image content.
- Channel-wise Outliers: A small subset of channels contains values several orders of magnitude larger than the rest, which "squashes" the precision of the remaining 99% of values during tensor-wide quantization.
- Long-tail Distributions: Activations often exhibit a distribution where 98% of values are clustered in a tiny range, while the remaining 2% are massive (sometimes exceeding 10,000). A single scale factor cannot accurately represent both the dense core and the extreme outliers.
As shown in the figure above, the activation spikes in Visual Mamba are remarkably consistent across entirely different images (a dog, a plant, and a car). This observation is critical: it suggests that the quantization difficulty is tied more to the index of the token in the sequence than the visual features themselves.
The PTQ4VM Framework
To overcome these hurdles, PTQ4VM introduces two primary innovations that optimize the quantization process without requiring expensive retraining.
Per-Token Static (PTS) Quantization
Standard "per-tensor" quantization uses one scale for an entire image, while "dynamic per-token" quantization calculates scales on the fly (which is computationally expensive). PTQ4VM proposes Per-Token Static (PTS) quantization. By leveraging the fact that activation patterns are position-dependent and the scan order is fixed, the authors pre-calculate unique quantization step sizes for every token position using a small calibration dataset. This manages token-wise variance with zero inference overhead.
Joint Learning of Smoothing Scale and Step Size (JLSS)
To handle channel outliers and long-tail distributions, the authors developed JLSS. This method employs a three-stage optimization process:
- Smoothing: It migrates quantization difficulty from activations to weights (inspired by SmoothQuant).
- Search and Optimization: It uses a combination of grid search and gradient descent to simultaneously fine-tune both the smoothing scales and the quantization step sizes (truncation).
- Error Minimization: The goal is to minimize the mean squared error between the quantized output and the original FP16 output, ensuring the most informative ranges are preserved.
Experimental Evaluation
The authors evaluated PTQ4VM across major architectures, including Vim, VMamba, and LocalVim, using benchmarks like ImageNet-1K and MSCOCO.
- Accuracy Recovery: In a striking example, a baseline 6-bit quantization (W6A6) of the Vim-Ti model resulted in an accuracy crash to 1.7%. PTQ4VM recovered this to 73.9%, nearing the FP16 baseline of 76.1%.
- Hardware Efficiency: By implementing custom CUDA kernels, the framework achieved a 1.83× GPU speedup for VMamba-B compared to the FP16 version.
- Downstream Robustness: The method maintained high performance in complex tasks like object detection and instance segmentation, where 4-bit models typically struggle to remain functional.
Conclusion
PTQ4VM demonstrates that the sequential nature of Visual Mamba, while a source of quantization difficulty, also provides a unique opportunity for static, position-based optimization. By combining Per-Token Static quantization with joint optimization of smoothing and step sizes, PTQ4VM paves the way for the efficient deployment of State Space Models on resource-constrained hardware. Future work may extend these techniques to specialized edge devices like mobile NPUs and FPGAs.
Summary updated