# AWQ

> Activation-aware 4-bit weight quantization for compressing and accelerating LLMs

- Category: Models & Inference / Quantization & Compression
- Language: Python
- Licence: MIT
- Repository: https://github.com/mit-han-lab/llm-awq
- Canonical page: https://ai-tldr.dev/tools/awq/

## In short

AWQ (Activation-aware Weight Quantization) is the reference implementation from MIT Han Lab for shrinking large language models down to 3-bit or 4-bit weights. It sits in the Quantization & Compression category of the Models & Inference tools and is open-source, written in Python and licensed MIT. To get started: install AWQ and the CUDA kernel.

## Overview

AWQ (Activation-aware Weight Quantization) is the reference implementation from MIT Han Lab for shrinking large language models down to 3-bit or 4-bit weights. Instead of treating every weight the same, it looks at which weights matter most for the model's activations and protects them during quantization, so the smaller model keeps most of its accuracy.

It is meant for engineers who need to run LLMs and vision-language models on tighter hardware budgets, from cloud GPUs down to edge devices like the NVIDIA Jetson Orin. The repo ships an AWQ search step, a pre-computed model zoo for families such as Llama-1/2/3, OPT, CodeLlama, StarCoder, Vicuna, and VILA, plus a memory-efficient 4-bit Linear layer and CUDA kernels for fast inference.

As a quantization and compression tool, AWQ sits ahead of the serving stack: you quantize a model once, then load the result. The method is also integrated into wider tooling such as Hugging Face Transformers, vLLM, TensorRT-LLM, and LMDeploy, and the companion TinyChat project uses it for on-device LLM/VLM chat.

## What it does

- Activation-aware INT3/INT4 weight quantization that keeps accuracy close to the full-precision model
- AWQ search to find quantization scales, plus a real backend that dumps deployable quantized weights
- Pre-computed AWQ model zoo for Llama-1/2/3, OPT, CodeLlama, StarCoder, Vicuna, VILA, and LLaVA
- Memory-efficient 4-bit Linear layer in PyTorch with CUDA kernels for context and decoding stages
- Support for instruction-tuned and multi-modal models (e.g. Vicuna, VILA) including video understanding
- TinyChat companion for on-device LLM/VLM inference on edge GPUs, reporting up to ~2.7-2.9x speedups over FP16

## Getting started

AWQ runs as a Python package with a CUDA kernel you build from source. Clone the repo, set up the environment, then run the AWQ search and quantization steps.

1. Install AWQ and the CUDA kernel

   Clone the repository, create a Python 3.10 environment, install the package in editable mode, then build the W4A16 inference kernel.

```bash
git clone https://github.com/mit-han-lab/llm-awq
cd llm-awq
conda create -n awq python=3.10 -y
conda activate awq
pip install --upgrade pip
pip install -e .
cd awq/kernels
python setup.py install
```

2. Run the AWQ search

   Search for the per-channel scales on your model and dump them to a cache file. This computes the activation-aware scaling used during quantization.

```bash
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
```

3. Generate real 4-bit weights

   Load the search result and write out the quantized model with the real backend, ready to load for inference.

```bash
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
```

4. Load and evaluate the quantized model

   Load the real quantized weights and check perplexity on WikiText-2 to confirm accuracy held up.

```bash
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
```

## When to use it

- Compressing a Llama-3 or other LLM to 4-bit so it fits in less GPU memory while keeping accuracy
- Running LLM or vision-language chatbots on edge devices like Jetson Orin with TinyChat
- Producing AWQ-quantized checkpoints to serve through vLLM, TensorRT-LLM, or LMDeploy
- Cutting inference cost and latency for instruction-tuned and multi-modal models
