Home

Awesome

AWQ: Activation-aware Weight Quantization for LLM Compression and Acceleration

[Paper][Slides][Video]

Efficient and accurate low-bit weight quantization (INT3/4) for LLMs, supporting instruction-tuned models and multi-modal LMs.

overview

The current release supports:

Thanks to AWQ, TinyChat can deliver more efficient responses with LLM/VLM chatbots through 4-bit inference.

TinyChat on RTX 4090: W4A16 is 3.4x faster than FP16

TinyChat on Orin: W4A16 is 3.2x faster than FP16

TinyChat also supports inference with vision language models (e.g., VILA, LLaVA). In the following examples, W4A16 quantized models from VILA family are launched with TinyChat.

TinyChat with VILA on 4090

TinyChat with VILA on Orin

<!-- Check out [TinyChat](tinychat), which delievers **30 tokens/second** inference performance (**3.2x faster** than FP16) for the **Llama2** chatbot on the resource-constrained NVIDIA Jetson Orin! -->

Check out TinyChat, which offers a turn-key solution for on-device inference of LLMs and VLMs on resource-constrained edge platforms. With TinyChat, it is now possible to efficiently run large models on small and low-power devices even without Internet connection!

News

Contents

Helpful Links

Install

  1. Clone this repository and navigate to AWQ folder
git clone https://github.com/mit-han-lab/llm-awq
cd llm-awq
  1. Install Package
conda create -n awq python=3.10 -y
conda activate awq
pip install --upgrade pip  # enable PEP 660 support
pip install -e .
  1. Install efficient W4A16 (4-bit weight, 16-bit activation) CUDA kernel and optimized FP16 kernels (e.g. layernorm, positional encodings).
cd awq/kernels
python setup.py install
  1. In order to run AWQ and TinyChat with VILA-1.5 model family, please install VILA:
git clone git@github.com:Efficient-Large-Model/VILA.git
cd VILA
pip install -e .

AWQ Model Zoo

We provide pre-computed AWQ search results for multiple model families, including LLaMA, OPT, Vicuna, and LLaVA. To get the pre-computed AWQ search results, run:

# git lfs install  # install git lfs if not already
git clone https://huggingface.co/datasets/mit-han-lab/awq-model-zoo awq_cache

The detailed support list:

ModelsSizesINT4-g128INT3-g128
VILA-1.53B/8B/13B/40B
Llama38B/70B
VILA7B/13B
Llama27B/13B/70B
LLaMA7B/13B/30B/65B
OPT125m/1.3B/2.7B/6.7B/13B/30B
CodeLlama7B/13B/34B
StarCoder15.5B
Vicuna-v1.17B/13B
LLaVA-v013B

Note: We only list models that we have prepare the AWQ searching results in the table above. AWQ also supports models such as LLaVA-v1.5 7B, and you may need to run the AWQ search on your own to quantize these models.

Examples

AWQ can be easily applied to various LMs thanks to its good generalization, including instruction-tuned models and multi-modal LMs. It provides an easy-to-use tool to reduce the serving cost of LLMs.

Here we provide two examples of AWQ application: Vicuna-7B (chatbot) and LLaVA-13B (visual reasoning) under ./examples directory. AWQ can easily reduce the GPU memory of model serving and speed up token generation. It provides accurate quantization, providing reasoning outputs. You should be able to observe memory savings when running the models with 4-bit weights.

Note that we perform AWQ using only textual calibration data, depsite we are running on multi-modal input. Please refer to ./examples for details.

overview

Usage

We provide several sample script to run AWQ (please refer to ./scripts). We use Llama3-8B as an example.

  1. Perform AWQ search and save search results (we already did it for you):
python -m awq.entry --model_path /PATH/TO/LLAMA3/llama3-8b \
    --w_bit 4 --q_group_size 128 \
    --run_awq --dump_awq awq_cache/llama3-8b-w4-g128.pt
  1. Evaluate the AWQ quantized model on WikiText-2 (simulated pseudo quantization)
python -m awq.entry --model_path /PATH/TO/LLAMA3/llama3-8b \
    --tasks wikitext \
    --w_bit 4 --q_group_size 128 \
    --load_awq awq_cache/llama3-8b-w4-g128.pt \
    --q_backend fake
  1. Generate real quantized weights (INT4)
mkdir quant_cache
python -m awq.entry --model_path /PATH/TO/LLAMA3/llama3-8b \
    --w_bit 4 --q_group_size 128 \
    --load_awq awq_cache/llama3-8b-w4-g128.pt \
    --q_backend real --dump_quant quant_cache/llama3-8b-w4-g128-awq.pt
  1. Load and evaluate the real quantized model (now you can see smaller gpu memory usage)
python -m awq.entry --model_path /PATH/TO/LLAMA3/llama3-8b \
    --tasks wikitext \
    --w_bit 4 --q_group_size 128 \
    --load_quant quant_cache/llama3-8b-w4-g128-awq.pt

Results on Vision-Language Models (VILA-1.5)

AWQ also seamlessly supports large multi-modal models (LMMs). We demonstrate the results on the recent VILA-1.5 model family.

VILA-1.5-3BVQA-v2GQAVizWizScienceQATextVQAPOPEMMEMMBenchMMBench-CNSEED
FP1680.461.553.569.060.485.91442.463.452.760.9
AWQ-INT480.061.153.867.860.485.91437.363.351.459.8
VILA-1.5-8BVQA-v2GQAVizWizScienceQATextVQAPOPEMMEMMBenchMMBench-CNSEED
FP1680.961.958.779.966.384.41577.0172.366.264.2
AWQ-INT480.361.759.379.065.482.91593.6571.064.964.0
VILA-1.5-13BVQA-v2GQAVizWizScienceQATextVQAPOPEMMEMMBenchMMBench-CNSEED
FP1682.864.362.680.165.086.31569.5574.966.365.1
AWQ-INT482.764.563.379.764.786.71531.3574.766.765.1
VILA-1.5-40BVQA-v2GQAVizWizScienceQATextVQAPOPEMMEMMBenchMMBench-CNSEED
FP1684.364.662.287.273.687.31726.8282.480.269.1
AWQ-INT484.164.461.386.773.288.21714.7983.279.668.9

Inference speed ( Token/sec )

$~~~~~~$PrecisionA1004090Orin
VILA1.5-3Bfp16104.6137.625.4
VILA1.5-3B-AWQint4182.8215.542.5
VILA1.5-3B-S2fp16104.3137.224.6
VILA1.5-3B-S2-AWQint4180.2219.340.1
Llama-3-VILA1.5-8Bfp1674.957.410.2
Llama-3-VILA1.5-8B-AWQint4168.9150.228.7
VILA1.5-13Bfp1650.9OOM6.1
VILA1.5-13B-AWQint4115.9105.720.6
VILA1.5-40Bfp16OOMOOM--
VILA1.5-40B-AWQint457.0OOM--

Reference

If you find AWQ useful or relevant to your research, please kindly cite our paper:

@inproceedings{lin2023awq,
  title={AWQ: Activation-aware Weight Quantization for LLM Compression and Acceleration},
  author={Lin, Ji and Tang, Jiaming and Tang, Haotian and Yang, Shang and Chen, Wei-Ming and Wang, Wei-Chen and Xiao, Guangxuan and Dang, Xingyu and Gan, Chuang and Han, Song},
  booktitle={MLSys},
  year={2024}
}

Related Projects

SmoothQuant: Accurate and Efficient Post-Training Quantization for Large Language Models

GPTQ: Accurate Post-training Compression for Generative Pretrained Transformers

Vicuna and FastChat

LLaVA: Large Language and Vision Assistant

VILA: On Pre-training for Visual Language Models