OSTQuant

April 8, 2025 · View on GitHub

Official code for ICLR2025 paper OSTQuant: Refining Large Language Model Quantization with Orthogonal and Scaling Transformations for Better Distribution Fitting

Motivation

Our motivation Fig1 : Transformation of a batch of data XN(μ,Σ)X \sim \mathcal{N}({\mu}, {\Sigma}) using different methods. Eigenvalues λ1\lambda_1 and λ2\lambda_2 represent the spread of the distribution along principal axes after eigenvalue decomposition of Σ\Sigma . (a) shows the original distribution, while (b), (c), and (d) illustrate the effects of the Smooth-based, Rotate-base, and ours OST-based methods, respectively, on QSUR.

OSTQuant Diagram

Fig2 : The overall flow diagram of OSTQuant. The top section of the figure illustrates how the global orthogonal transformation, RresR_{res}, along with the two scaling transformations, SattnS_{attn} and SffnS_{ffn}, collaborate within each block to adjust the distributions across the entire network while maintaining computational invariance. The bottom section highlights four equivalent transformation pairs applied to the FFN and Self-Attention layers. Each fully-connected (FC) layer’s activation and weight are influenced by one or more of these transformation pairs. During runtime, these transformation pairs are fused with the weights, ensuring minimal runtime overhead.

Evaluate from ours optimized transformation matrix weights

We have provided the optimized transformation matrix weights in google drive.

You can choose to load the checkpoints we provide to evaluate directly.

python main.py --output_dir output/llama2_w4a16kv16 --model weights/Llama-2-7b-hf  \
 --loss_type=kl_top --post_attn=True \
 --rotate_ov=True --rotate_post_rope=False --online_qk_hadamard=False --smooth_qk=True --smooth_ov=True --smooth_up_down=True --smooth_norm_linear=True --bf16=True --lm_eval=True --per_device_train_batch_size=4 \
 --max_steps=100 --a_bits=16 --v_bits=16 --k_bits=16 --down_bits=16 --w_clip=True\
 --train_enable_wquant=True --sub_mean False --train_rotate=False --resume_path=checkpoints/llama2_7b_w4a16kv16.bin

Reproduce from scratch

You can repdoduce our results with the following command:

export CUDA_VISIBLE_DEVICES="0,1,2,3"
sh scripts/w4a16kv16.sh

Main Results

Table:Comparison of perplexity on WikiText2 and averaged accuracy on nine Zero-Shot tasks. Results for SmoothQuant, GPTQ, OmniQuant, AWQ, and QuaRot are based on official code and SpinQuant's results for LLaMA-2/3 using official weights, with LLaMA-1 from the official code.

#Bits W-A-KVMethodLLaMA-3 8BLLaMA-2 7BLLaMA-2 13BLLaMA 7BLLaMA 13BLLaMA 30B
0-shot9Wiki0-shot9Wiki0-shot9Wiki0-shot9Wiki0-shot9Wiki0-shot9Wiki
Avg.(↑)(↓)Avg.(↑)(↓)Avg.(↑)(↓)Avg.(↑)(↓)Avg.(↑)(↓)Avg.(↑)(↓)
16-16-16FloatingPoint68.096.1465.215.4767.614.8864.485.6866.675.0970.004.10
4-16-16RTN63.708.1361.277.0260.246.3962.677.9463.458.6065.696.13
SmoothQuant62.798.1258.888.0362.035.8662.247.4662.6918.7565.695.80
GPTQ61.037.4360.869.8464.715.7960.157.9364.366.5866.955.26
OmniQuant65.667.1963.195.7466.385.0263.425.8666.225.2169.074.25
AWQ67.037.3663.895.8366.255.0763.305.9765.585.2869.444.28
QuaRot67.276.5364.305.6266.955.0063.405.8365.915.2069.734.27
SpinQuant66.546.4963.595.5867.145.0063.945.7666.325.1669.624.21
OSTQuant67.806.5364.375.6467.314.9464.135.8166.625.2169.844.19
4-4-16RTN33.426e232.44nan30.868e332.517e331.633e431.572e3
SmoothQuant33.041e332.13nan34.261e334.423e233.296e234.641e3
GPTQ32.985e232.72nan30.114e332.121e331.513e330.882e3
QuaRot61.698.0261.876.0565.135.3561.766.2264.465.5068.144.57
SpinQuant64.117.2857.376.7863.235.2461.826.0864.595.3668.084.53
OSTQuant65.147.2463.905.6066.245.1462.726.0465.805.4068.524.43
4-4-4RTN33.187e232.67nan30.937e332.871e431.333e431.642e3
SmoothQuant32.961e332.12nan33.361e333.323e233.285e234.651e3
GPTQ33.716e233.52nan27.855e331.802e330.633e331.072e3
OmniQuant32.334e248.4014.2650.3512.3048.4611.2645.6310.8745.0412.35
QuaRot61.388.1861.486.1165.165.3961.226.2664.595.5368.084.60
SpinQuant64.107.3562.015.9664.135.7461.326.1264.955.3968.144.55
OSTQuant65.377.2963.185.9165.415.2562.556.0765.435.4068.204.42

Contributing

We welcome contributions from the research and development community! Whether you're interested in improving the existing features, adding new functionalities, or reporting issues, your input is invaluable.

Future Work

We plan to extend OSTQuant to FullyQuant, aiming to quantize all activations within a Transformer block. The Fig3 below demonstrates our design to improve the QSUR of activations across all layers.

OSTQuant for FullyQuant.

FullyQuant

Citation

If you find OSTQuant useful in your research, please consider citing our paper:

@inproceedings{hu2025ostquant,
title={{OSTQ}uant: Refining Large Language Model Quantization with Orthogonal and Scaling Transformations for Better Distribution Fitting},
author={Xing Hu, Yuan Cheng, Dawei Yang, Zhixuan Chen, Zukang Xu, Jiangyong Yu, Chen Xu, Zhihang Yuan, Zhe jiang and Sifan Zhou},
booktitle={The Thirteenth International Conference on Learning Representations},
year={2025},
url={https://openreview.net/forum?id=rAcgDBdKnP}
}

Star History

Star History Chart