Q-S5: Towards Quantized State Space Models

Steven Abreu, Jens Egholm Pedersen, Kade M. Heckel, Alessandro PierroarXiv 2024 · DOI

TL;DR

This paper explores the impact of quantization on State Space Models (SSMs), specifically the S5 architecture, to enable their deployment on resource-constrained devices. They demonstrate that fully quantized S5 models can achieve performance very close to their full-precision counterparts on various tasks, including sequence modeling benchmarks, with significant reductions in memory footprint and computational cost.

What Problem Does This Paper Address?

Transformers have dominated sequence modeling, but their quadratic complexity with sequence length limits their scalability. State Space Models (SSMs) offer a compelling alternative, boasting linear or near-linear scaling and strong performance. However, deploying these powerful models on edge devices with limited memory and computational power is challenging. Quantization, a technique to reduce model size and speed up inference by using lower-precision numerical formats (e.g., 8-bit integers instead of 32-bit floats), is a key enabler for edge deployment. While quantization has been extensively studied for transformers, its application and impact on SSMs, particularly the advanced S5 architecture, remained largely unexplored. This paper aims to fill that gap by systematically investigating how quantization affects SSM performance and identifying which components are most sensitive to precision reduction.

Methods

The authors employ two primary quantization techniques:

  • Quantization-Aware Training (QAT): This involves simulating the effects of quantization during the training process. They use the JAX AQT library and incorporate straight-through estimators for gradient propagation through quantized operations. This method allows the model to adapt to quantization noise during training.
  • Post-Training Quantization (PTQ): Here, a pre-trained full-precision model is quantized without any further training. This is a simpler approach but can sometimes lead to larger performance drops.

They systematically evaluate the quantization sensitivity of different components of the S5 model, including the recurrent matrix (Ā), input matrix (B), output matrix (C), and skip connection matrix (D), as well as activation functions like GELU. They also investigate quantized normalization layers.

Datasets

The paper evaluates their quantized SSMs on the following:

  • Dynamical Systems Modeling: Specifically, a time-delayed 10-dimensional Mackey-Glass system.
  • Sequential MNIST (sMNIST): A benchmark for sequence modeling.
  • Long Range Arena (LRA): A suite of challenging sequence modeling tasks, excluding the Path-X task.

Key Insights and Ideas

  • SSMs are surprisingly robust to quantization: The S5 model can be quantized to very low bitwidths (e.g., 8-bit weights and activations) with minimal performance degradation on many tasks. This is crucial for their practical deployment.
  • Recurrent weights are the most sensitive: Performance degrades significantly when the recurrent weights (Ā) are quantized below 8 bits. This highlights the critical role of these parameters in capturing temporal dynamics.
  • Other components offer compression opportunities: Matrices like B, C, and D, as well as activation functions, can often be compressed to lower bitwidths with less impact on accuracy, offering further avenues for optimization.
  • QAT is generally superior to PTQ: While PTQ can work for language-based LRA tasks, QAT is necessary for achieving good performance on most other tasks, especially those involving complex temporal dynamics or requiring higher precision.
  • Quantized GELU and Layer Norm are effective: The proposed quantized GELU activation and quantized layer normalization layers can be used with QAT without significant performance loss, enabling end-to-end quantized models.

Key Results

  • Near state-of-the-art performance with quantization: Fully quantized S5 models (e.g., W8A8, W4A8SSM8) achieve test accuracies on sMNIST and most LRA tasks within 1 percentage point of the full-precision model.
  • Significant accuracy drops below 8-bit recurrent weights: For instance, on the Mackey-Glass system, quantizing the Ā matrix to 4 bits leads to a substantial performance decrease.
  • PTQ limitations: PTQ performs well on language-based LRA tasks (Text and Retrieval) but struggles on others, showing a large drop in accuracy.
  • Memory and computation savings: Quantized models use >4x less memory and rely almost exclusively on integer operations, making them ideal for edge devices.
  • Ablation studies confirm component sensitivity: Table 3 and 4 show that while qGELU and qLN have minimal impact, other components like the hard sigmoid can cause notable degradation.

Limitations and Future Work

  • ListOps challenge: The paper notes that no quantized model could match the full-precision performance on the ListOps task, though it still outperformed prior baselines. This suggests ListOps might be particularly sensitive to quantization.
  • Hyperparameter optimization: The authors hypothesize that the non-linear relationship between quantization precision and performance might be related to deep double descent and suggest that extensive hyperparameter optimization could yield better QAT recipes.
  • Exploring alternative activations: The degradation caused by the hard sigmoid replacement motivates future work to find better substitutions for sigmoid functions in quantized SSMs.
  • Extending to larger models: The authors express interest in applying their QAFT methods to larger pre-trained SSMs like Mamba, Jamba, and Griffin.
  • Theoretical analysis: They aim to theoretically demonstrate how sparse binary activations (spikes) can encode complex patterns, potentially leveraging work on linear kernels and recurrent linear maps.

Summary updated

BibTeX
@misc{abreu2024q,
  author = {Steven Abreu and Jens Egholm Pedersen and Kade M. Heckel and Alessandro Pierro},
  title = {{Q-S5: Towards Quantized State Space Models}},
  year = {2024},
  eprint = {2406.09477},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2406.09477},
}
Figure