MoQAE: Mixed-Precision Quantization for Long-Context LLM Inference via Mixture of Quantization-Aware Experts

Wei Tao, Haocheng Lu, Xiaoyang Qu, Bin Zhang, Kai Lu, Jiguang Wan, Jianzong Wang

Abstract

One of the primary challenges in optimizing large language models (LLMs) for long-context inference lies in the high memory consumption of the Key-Value (KV) cache. Existing approaches, such as quantization, have demonstrated promising results in reducing memory usage. However, current quantization methods cannot take both effectiveness and efficiency into account. In this paper, we propose MoQAE, a novel mixed-precision quantization method via mixture of quantization-aware experts. First, we view different quantization bit-width configurations as experts and use the traditional mixture of experts (MoE) method to select the optimal configuration. To avoid the inefficiency caused by inputting tokens one by one into the router in the traditional MoE method, we input the tokens into the router chunk by chunk. Second, we design a lightweight router-only fine-tuning process to train MoQAE with a comprehensive loss to learn the trade-off between model accuracy and memory usage. Finally, we introduce a routing freezing (RF) and a routing sharing (RS) mechanism to further reduce the inference overhead. Extensive experiments on multiple benchmark datasets demonstrate that our method outperforms state-of-the-art KV cache quantization approaches in both efficiency and effectiveness.

Introduction: The Memory Wall in Long-Context LLMs

As Large Language Models (LLMs) are increasingly deployed for tasks involving massive contexts—such as document analysis and long-form code generation—they encounter a significant "memory wall." While the memory required for model weights remains constant, the Key-Value (KV) cache—which stores past token representations to speed up generation—grows linearly with the sequence length.

For instance, a Llama2-13B model processing a 128k context requires approximately 100GB of memory, which exceeds the 80GB capacity of a standard NVIDIA A100 GPU. As shown in Figure 1, the KV cache eventually dominates total memory usage, making long-context inference physically impossible on single-device setups without compression.

Memory usage vs. context length. As context grows, the KV cache dominates total memory, eventually exceeding hardware limits.

Methodology: MoQAE

To address this, we introduce MoQAE (Mixed-Precision Quantization via Mixture of Quantization-Aware Experts). MoQAE treats different quantization bit-widths (e.g., FP16, INT4, INT2) as "experts" within a Mixture-of-Experts (MoE) framework.

Quantization-Aware Experts and Chunk-based Routing

Unlike traditional MoE where experts are neural network layers, MoQAE's experts are specific quantization configurations. A lightweight MLP-based router analyzes the input data and dynamically assigns the most suitable bit-width. To maintain hardware efficiency and reduce routing overhead, MoQAE processes tokens in chunks (e.g., 32 tokens) rather than individually.

The MoQAE architecture. Input text is chunked and passed through a learned router to select the optimal quantization strategy (FP16, INT4, or INT2) for each chunk.

Lightweight Fine-Tuning

Training a full LLM for quantization is computationally prohibitive. MoQAE employs a "router-only" fine-tuning approach where the base model weights remain frozen. We optimize the routers using a custom loss function that allows users to explicitly trade off model accuracy against memory savings using a single hyperparameter ($\lambda$).

Inference Optimizations

To further minimize latency, we introduce two key mechanisms:

  1. Routing Freezing (RF): Observation of attention patterns reveals that initial tokens (attention sinks) are critical for stability. MoQAE freezes the first chunk to FP16 precision.
  2. Routing Sharing (RS): To avoid running the router for every transformer block, the quantization strategy determined in one layer can be shared across subsequent layers, significantly reducing computational overhead.

Experimental Results

We evaluated MoQAE across several benchmarks, including Wikitext2 for perplexity and LongBench for long-context tasks (QA, summarization, code completion).

  • Accuracy: MoQAE achieves near-lossless performance. On Wikitext2, the MoQAE-$\lambda$0.5 variant showed a perplexity increase of only 0.08 compared to the full FP16 baseline while drastically reducing memory footprint.
  • Memory Efficiency: MoQAE consistently outperformed state-of-the-art methods like KIVI and MiKV. It provides a more stable and efficient memory reduction across various context lengths.
  • Latency and Long-Context Performance: Thanks to chunk-based routing and Routing Sharing, MoQAE maintains competitive inference speeds. On LongBench, it often surpassed the FP16 baseline in task performance, suggesting that its learned quantization might provide a beneficial regularizing effect.

Conclusion

MoQAE provides a scalable and efficient solution for the KV cache memory bottleneck. By combining the flexibility of mixed-precision quantization with the efficiency of chunk-based MoE routing, it enables high-fidelity long-context inference on commodity hardware. Future work will focus on optimizing custom CUDA kernels for dequantization to further reduce the latency gap.

Summary updated

BibTeX
@inproceedings{tao2025moqae,
  author = {Wei Tao and Haocheng Lu and Xiaoyang Qu and Bin Zhang and Kai Lu and Jiguang Wan and Jianzong Wang},
  title = {{MoQAE: Mixed-Precision Quantization for Long-Context LLM Inference via Mixture of Quantization-Aware Experts}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2025},
  url = {https://openreview.net/forum?id=FUaPErYhoj},
}
Figure