CodeQuant: Unified Clustering and Quantization for Enhanced Outlier Smoothing in Low-Precision Mixture-of-Experts

Xiangyang Yin, Xingyu Liu, Tianhua Xia, Bo Bao, Vithursan Thangarasa, Valavan Manohararajah, Eric Sather, Sai Qian Zhang

Mixture-of-Experts (MoE) architectures have become the backbone of modern Large Language Models (LLMs), enabling massive scaling alongside efficient computation. However, deploying these massive models in resource-constrained environments requires Post-Training Quantization (PTQ)—reducing the precision of weights and activations (e.g., from 16-bit to 4-bit) to save memory and accelerate inference.

The primary bottleneck in this process is the "outlier problem." Extreme numerical values in activations and weights expand the dynamic range, causing standard quantization methods to lose precision on the majority of normal values. In MoE models, this degradation is particularly severe because outliers can disrupt the routing mechanism that selects which experts to activate. If the routing logic breaks, the model's performance collapses.

To address this, researchers have introduced CodeQuant, a unified quantization and clustering framework designed to smooth outliers and optimize hardware performance for MoE models.

The CodeQuant Framework

CodeQuant introduces a comprehensive four-stage pipeline to manage outliers and maintain high accuracy during low-precision deployment.

The CodeQuant Framework
  1. Activation-oriented Outlier Smoothing (AOS): Instead of relying on random rotations to redistribute outlier magnitudes, CodeQuant employs learnable rotation matrices optimized via the Cayley transform. This approach specifically minimizes activation quantization error by shifting the representational difficulty from the activations into the weight space.
  2. Permutation-Invariant Outlier Grouping (POG): Because some weight groups exhibit high variance and are harder to cluster, POG reorders weight columns to pair high-variance subgroups with low-variance ones. This creates a more uniform distribution, simplifying the subsequent clustering stage.
  3. Adaptive Weight Clustering with Centroid Finetuning (ACCF): Moving away from standard linear quantization, CodeQuant maps weights to a "codebook" of representative centroids. During finetuning, a KL-divergence loss is incorporated to ensure the quantized model’s router behavior remains faithful to the original FP16 model.
  4. LUT-based Kernel Design: To maximize computational efficiency, the framework includes a specialized kernel for GPUs and CPUs. By replacing expensive multiplications with Lookup Tables (LUTs), the system can precompute the results of "activation × centroid" and simply look them up during inference.

Key Insights

  • Clustering as an Outlier Sponge: Unlike uniform quantization, which forces all data into a rigid, low-resolution grid, clustering naturally absorbs outliers. An extreme value simply becomes its own centroid without degrading the precision of the remaining data.
  • Preserving the Router: In MoE architectures, routing integrity is just as critical as the data itself. Using KL-divergence to stabilize the router during quantization allows CodeQuant to maintain accuracy where other methods fail.
  • Hardware-Software Co-design: Transitioning from a multiplication-heavy workload to a lookup-heavy workload via LUTs cleverly bypasses traditional arithmetic bottlenecks, leveraging optimized memory access patterns.

Performance and Results

CodeQuant was rigorously evaluated across prominent MoE models, including Phi-mini-MoE-Instruct, Qwen3-30B-A3B, DeepSeek-V2-Lite, and Mixtral 8x7B, using benchmarks like WikiText2, MMLU, and GSM8K.

  • Accuracy: On the Qwen3-30B-A3B model at 4-bit precision, CodeQuant reduced perplexity by 5.73 compared to the previous state-of-the-art method, QuaRot.
  • Reasoning: In mathematical reasoning tasks (GSM8K), CodeQuant outperformed QuaRot by a massive 35.9% on the Qwen3 model, performing remarkably close to the unquantized BF16 baseline.
  • Speed and Efficiency: The framework achieved up to a 4.15× speedup on CPU benchmarks compared to BF16 baselines. It consistently outperformed other quantized kernels in GPU simulations while significantly lowering the memory footprint, enabling large MoE models to run on hardware with limited VRAM.

Limitations and Future Directions

While highly effective, CodeQuant's AOS and ACCF stages require an offline calibration phase that can take between 30 minutes to 4 hours, depending on model size. Additionally, while CPU results were validated on real hardware, GPU performance gains were demonstrated via simulation; a native CUDA/Triton implementation remains a future target. Finally, exploring whether this clustering approach maintains its efficacy at ultra-low precisions (e.g., 2-bit) remains an open and exciting question for future research.

Summary updated

BibTeX
@inproceedings{yin2026codequant,
  author = {Xiangyang Yin and Xingyu Liu and Tianhua Xia and BO BAO and Vithursan Thangarasa and Valavan Manohararajah and Eric Sather and Sai Qian Zhang},
  title = {{CodeQuant: Unified Clustering and Quantization for Enhanced Outlier Smoothing in Low-Precision Mixture-of-Experts}},
  booktitle = {International Conference on Learning Representations},
  year = {2026},
  url = {https://openreview.net/forum?id=ATpchFiBQi},
}
Figure