AutoAWQ

Warning

Please note that AWQ support in vLLM is under-optimized at the moment. We would recommend using the unquantized version of the model for better accuracy and higher throughput. Currently, you can use AWQ as a way to reduce memory footprint. As of now, it is more suitable for low latency inference with small number of concurrent requests. vLLM’s AWQ implementation have lower throughput than unquantized version.

To create a new 4-bit quantized model, you can leverage AutoAWQ. Quantizing reduces the model’s precision from FP16 to INT4 which effectively reduces the file size by ~70%. The main benefits are lower latency and memory usage.

You can quantize your own models by installing AutoAWQ or picking one of the 400+ models on Huggingface.

  1. $ pip install autoawq

After installing AutoAWQ, you are ready to quantize a model. Here is an example of how to quantize Vicuna 7B v1.5:

  1. from awq import AutoAWQForCausalLM
  2. from transformers import AutoTokenizer
  3. model_path = 'lmsys/vicuna-7b-v1.5'
  4. quant_path = 'vicuna-7b-v1.5-awq'
  5. quant_config = { "zero_point": True, "q_group_size": 128, "w_bit": 4, "version": "GEMM" }
  6. # Load model
  7. model = AutoAWQForCausalLM.from_pretrained(model_path, **{"low_cpu_mem_usage": True})
  8. tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
  9. # Quantize
  10. model.quantize(tokenizer, quant_config=quant_config)
  11. # Save quantized model
  12. model.save_quantized(quant_path)
  13. tokenizer.save_pretrained(quant_path)

To run an AWQ model with vLLM, you can use TheBloke/Llama-2-7b-Chat-AWQ with the following command:

  1. $ python examples/llm_engine_example.py --model TheBloke/Llama-2-7b-Chat-AWQ --quantization awq

AWQ models are also supported directly through the LLM entrypoint:

  1. from vllm import LLM, SamplingParams
  2. # Sample prompts.
  3. prompts = [
  4. "Hello, my name is",
  5. "The president of the United States is",
  6. "The capital of France is",
  7. "The future of AI is",
  8. ]
  9. # Create a sampling params object.
  10. sampling_params = SamplingParams(temperature=0.8, top_p=0.95)
  11. # Create an LLM.
  12. llm = LLM(model="TheBloke/Llama-2-7b-Chat-AWQ", quantization="AWQ")
  13. # Generate texts from the prompts. The output is a list of RequestOutput objects
  14. # that contain the prompt, generated text, and other information.
  15. outputs = llm.generate(prompts, sampling_params)
  16. # Print the outputs.
  17. for output in outputs:
  18. prompt = output.prompt
  19. generated_text = output.outputs[0].text
  20. print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}")