Skip to content

Commit 2fc3bcb

Browse files
committed
Reordered pages and switched quant recipe to w8a8. Updated inference page to use custom scripts and added whisper inference back in. Accuracy results in benchmarking page are now full runs.
Signed-off-by: Anna Mayne <anna.mayne@arm.com>
1 parent 5202295 commit 2fc3bcb

7 files changed

Lines changed: 311 additions & 198 deletions

File tree

content/learning-paths/servers-and-cloud-computing/vllm-benchmark-quantisation/1-overview-and-setup.md

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,20 @@ layout: learningpathall
1010

1111
[vLLM](https://docs.vllm.ai/en/latest/) is an open-source, high-throughput inference and serving engine for large language models (LLMs). It’s designed to maximise hardware efficiency, making LLM inference faster, more memory-efficient, and scalable.
1212

13-
## Understanding the Llama models
13+
## Understanding the models
1414

1515
Llama 3.1 8B is an open-weight, text-only LLM with 8 billion parameters that can understand and generate text. You can view the model card at https://huggingface.co/meta-llama/Llama-3.1-8B.
1616

17-
Quantised models have their weights converted to a lower precision data type, which reduces the memory requirements of the model and can improve performance significantly. In the [Run vLLM inference with INT4 quantization on Arm servers](/learning-paths/servers-and-cloud-computing/vllm-acceleration/) Learning Path we have covered how to quantise a model yourself. There are also many publicly available quantised versions of popular models, such as https://huggingface.co/RedHatAI/Meta-Llama-3.1-8B-quantized.w8a8.
18-
19-
The notation w8a8 means that the weights have been quantised to 8-bit integers and the activations (the input data) are dynamically quantised to the same. This allows our kernels to utilise Arm's 8-bit integer matrix multiply feature I8MM. You can learn more about this in the [KleidiAI and matrix multiplication](/learning-paths/cross-platform/kleidiai-explainer/) Learning Path.
20-
21-
The RedHatAI/Meta-Llama-3.1-8B-quantized.w8a8 model we are using in this Learning Path only applies quantisation to the weights and activations in the linear layers of the transformer blocks. The activation quantisations are applied per-token and the weights are quantised per-channel. That is, each output channel dimension has a scaling factor applied between INT8 and BF16 representations.
17+
Whisper large V3 is an automatic speech recognition (ASR) and speech translation model. It has 1.55 billion parameters and can both transcribe many languages and translate them to English. You can find the model card at https://huggingface.co/openai/whisper-large-v3.
2218

2319
## Set up your environment
2420

2521
Before you begin, make sure your environment meets these requirements:
2622

2723
- Python 3.12 on Ubuntu 22.04 LTS or newer
2824
- At least 32 vCPUs, 96 GB RAM, and 64 GB of free disk space
29-
This Learning Path was tested on an AWS Graviton4 c8g.12xlarge instance with 200 GB of attached storage.
25+
26+
This Learning Path was tested on a 96 core machine with 128-bit SVE, 192 GB of RAM and 500 GB of attached storage.
3027

3128
## Install build dependencies
3229

@@ -54,10 +51,21 @@ python -m pip install --upgrade pip
5451

5552
Install a recent CPU specific build of vLLM:
5653
```bash
57-
export VLLM_VERSION=0.19.1
58-
pip install https://github.com/vllm-project/vllm/releases/download/v${VLLM_VERSION}/vllm-${VLLM_VERSION}+cpu-cp38-abi3-manylinux_2_35_aarch64.whl
54+
export VLLM_VERSION=0.20.0
55+
pip install https://github.com/vllm-project/vllm/releases/download/v${VLLM_VERSION}/vllm-${VLLM_VERSION}+cpu-cp38-abi3-manylinux_2_35_aarch64.whl --extra-index-url https://download.pytorch.org/whl/cpu
5956
```
6057

6158
If you wish to build vLLM from source you can follow the instructions in the [Build and Run vLLM on Arm Servers Learning Path](/learning-paths/servers-and-cloud-computing/vllm/vllm-setup/).
6259

63-
Your environment is now setup to run inference with vLLM. Next, you'll use vLLM to run inference on both quantised and non-quantised Llama models.
60+
61+
## Set up access to LLama3.1-8B models
62+
63+
To access the Llama models hosted by Hugging Face, you will need to install the Hugging Face CLI so that you can authenticate yourself and the harness can download what it needs. You should create an account on https://huggingface.co/ and follow the instructions [in the Hugging Face CLI guide](https://huggingface.co/docs/huggingface_hub/en/guides/cli) to set up your access token. You can then install the CLI and login:
64+
```bash
65+
curl -LsSf https://hf.co/cli/install.sh | bash
66+
hf auth login
67+
```
68+
69+
Paste your access token into the terminal when prompted. To access Llama3.1-8B you need to request access on the Hugging Face website. Visit https://huggingface.co/meta-llama/Llama-3.1-8B and select "Expand to review and access". Complete the form and you should be granted access in a matter of minutes.
70+
71+
Your environment is now setup to run inference with vLLM. Next, we'll review model quantisation and then you'll use vLLM to run inference on both quantised and non-quantised Llama and Whisper models.
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
---
2+
title: Quantisation Recipe
3+
weight: 3
4+
5+
### FIXED, DO NOT MODIFY
6+
layout: learningpathall
7+
---
8+
9+
## Understanding quantisation
10+
11+
Quantised models have their weights converted to a lower precision data type, which reduces the memory requirements of the model and can improve performance significantly. In the [Run vLLM inference with INT4 quantization on Arm servers](/learning-paths/servers-and-cloud-computing/vllm-acceleration/) Learning Path we have covered how to quantise a model yourself. There are also many publicly available quantised versions of popular models, such as https://huggingface.co/RedHatAI/Meta-Llama-3.1-8B-quantized.w8a8 and https://huggingface.co/RedHatAI/whisper-large-v3-quantized.w8a8, which we will be using in this Learning Path.
12+
13+
The notation w8a8 means that the weights have been quantised to 8-bit integers and the activations (the input data) are dynamically quantised to the same. This allows our kernels to utilise Arm's 8-bit integer matrix multiply feature I8MM. You can learn more about this in the [KleidiAI and matrix multiplication](/learning-paths/cross-platform/kleidiai-explainer/) Learning Path.
14+
15+
The w8a8 models we are using in this Learning Path only apply quantisation to the weights and activations in the linear layers of the transformer blocks. The activation quantisations are applied per-token and the weights are quantised per-channel. That is, each output channel dimension has a scaling factor applied between INT8 and BF16 representations.
16+
17+
## Quantising your own models
18+
19+
If you would prefer to generate your own w8a8 quantised models, the recipe below is provided as an example. This is an optional activity and not a core part of this Learning Path, as it can take several hours to run.
20+
21+
You will need to install the required packages before running the quantisation script.
22+
```bash
23+
pip install compressed-tensors==0.14.0.1
24+
pip install llmcompressor==0.10.0.1
25+
pip install datasets==4.6.0
26+
27+
python w8a8_quant.py
28+
```
29+
30+
Where w8a8_quant.py contains:
31+
```python
32+
from transformers import AutoTokenizer
33+
from datasets import Dataset, load_dataset
34+
from transformers import AutoModelForCausalLM
35+
from llmcompressor import oneshot
36+
from llmcompressor.modifiers.quantization import GPTQModifier
37+
from compressed_tensors.quantization import QuantizationType, QuantizationStrategy
38+
import random
39+
40+
model_id = "meta-llama/Meta-Llama-3.1-8B"
41+
42+
num_samples = 256
43+
max_seq_len = 4096
44+
45+
tokenizer = AutoTokenizer.from_pretrained(model_id)
46+
47+
def preprocess_fn(example):
48+
return {"text": example["text"]}
49+
50+
ds = load_dataset("neuralmagic/LLM_compression_calibration", split="train")
51+
ds = ds.shuffle().select(range(num_samples))
52+
ds = ds.map(preprocess_fn)
53+
54+
scheme = {
55+
"targets": ["Linear"],
56+
"weights": {
57+
"num_bits": 8,
58+
"type": QuantizationType.INT,
59+
"strategy": QuantizationStrategy.CHANNEL,
60+
"symmetric": True,
61+
"dynamic": False,
62+
"group_size": None
63+
},
64+
"input_activations":
65+
{
66+
"num_bits": 8,
67+
"type": QuantizationType.INT,
68+
"strategy": QuantizationStrategy.TOKEN,
69+
"dynamic": True,
70+
"symmetric": False,
71+
"observer": None,
72+
},
73+
"output_activations": None,
74+
}
75+
76+
recipe = GPTQModifier(
77+
targets="Linear",
78+
config_groups={"group_0": scheme},
79+
ignore=["lm_head"],
80+
dampening_frac=0.01,
81+
block_size=512,
82+
)
83+
84+
model = AutoModelForCausalLM.from_pretrained(
85+
model_id,
86+
device_map="auto",
87+
trust_remote_code=True,
88+
)
89+
90+
oneshot(
91+
model=model,
92+
dataset=ds,
93+
recipe=recipe,
94+
max_seq_length=max_seq_len,
95+
num_calibration_samples=num_samples,
96+
)
97+
model.save_pretrained("Meta-Llama-3.1-8B-quantized.w8a8")
98+
```
99+
100+
When this has completed you will need to copy over the tokeniser specific files from the original model before you can run inference on your quantised model.
101+
102+
```bash
103+
cp ~/.cache/huggingface/hub/models--meta-llama--Llama-3.1-8B/snapshots/*/*token* Meta-Llama-3.1-8B-quantized.w8a8/
104+
```

content/learning-paths/servers-and-cloud-computing/vllm-benchmark-quantisation/2-run-inference.md

Lines changed: 0 additions & 43 deletions
This file was deleted.
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
---
2+
title: Run inference with vLLM
3+
weight: 4
4+
5+
### FIXED, DO NOT MODIFY
6+
layout: learningpathall
7+
---
8+
9+
## Run inference on LLama3.1-8B
10+
11+
We will use vLLM to serve an openAI-compatible API that we can use to run inference on Llama3.1-8B. This will demonstrate that the local environment is setup correctly.
12+
13+
Start vLLM’s OpenAI-compatible API server using Llama3.1-8B:
14+
```bash
15+
vllm serve meta-llama/Llama-3.1-8B
16+
```
17+
18+
Then we can create a test script that sends a request to the server using the OpenAI library. Copy the below to a file named llama_test.py.
19+
20+
```python
21+
import time
22+
from openai import OpenAI
23+
from transformers import AutoTokenizer
24+
25+
# vLLM's OpenAI-compatible server
26+
client = OpenAI(base_url="http://localhost:8000/v1", api_key="EMPTY")
27+
28+
model = "meta-llama/Llama-3.1-8B" # vllm server model
29+
30+
# Define a chat template for the model
31+
llama3_template = "{% set loop_messages = messages %}{% for message in loop_messages %}{% set content = '<|start_header_id|>' + message['role'] + '<|end_header_id|>\n\n'+ message['content'] | trim + '<|eot_id|>' %}{% if loop.first and message['role'] != 'system' %}{{ '<|start_header_id|>system<|end_header_id|>\n\n'+ 'You are a helpful assistant.' + '<|eot_id|>' }}{% endif %}{{ content }}{% endfor %}{{ '<|start_header_id|>assistant<|end_header_id|>\n\n' }}"
32+
33+
# Define your prompt
34+
message = [{"role": "user", "content": "Explain Big O notation with two examples."}]
35+
36+
def run(prompt):
37+
resp = client.completions.create(
38+
model=model,
39+
prompt=prompt,
40+
max_tokens=128, # The maximum number of tokens that can be generated in the completion
41+
)
42+
return resp.choices[0].text
43+
44+
def main():
45+
t0 = time.time()
46+
47+
tokenizer = AutoTokenizer.from_pretrained(model)
48+
tokenizer.chat_template = llama3_template
49+
prompt = tokenizer.apply_chat_template(message, tokenize=False)
50+
result = run(prompt)
51+
52+
print(f"\n=== Output ===\n{result}\n")
53+
print(f"Batch completed in : {time.time() - t0:.2f}s")
54+
55+
if __name__ == "__main__":
56+
main()
57+
```
58+
59+
Now run the script with:
60+
```bash
61+
python llama_test.py
62+
```
63+
64+
This will return the text generated by the model from your prompt. In the server logs you can see the throughput measured in tokens per second.
65+
66+
You can do the same for the quantised model. Start the server:
67+
```bash
68+
vllm serve RedHatAI/Meta-Llama-3.1-8B-quantized.w8a8
69+
```
70+
71+
Update your test script to use the quantised model:
72+
```python
73+
model = "RedHatAI/Meta-Llama-3.1-8B-quantized.w8a8"
74+
```
75+
76+
Run inference on the quantised model:
77+
```bash
78+
python llama_test.py
79+
```
80+
81+
You have now run inference using both the non-quantised and quantised Llama3.1-8B models.
82+
83+
## Run inference on Whisper
84+
85+
We will use a similar approach to test our ability to run inference on Whisper models. Install the required vLLM audio library then start vLLM’s OpenAI-compatible API server using Whisper-large-v3:
86+
```bash
87+
pip install vllm[audio]
88+
89+
vllm serve openai/whisper-large-v3
90+
```
91+
92+
Then we can create a test script that sends a request with an audio file to the server using the OpenAI library. Copy the below to a file named whisper_test.py.
93+
94+
```python
95+
import time
96+
from openai import OpenAI
97+
from vllm.assets.audio import AudioAsset
98+
99+
# vLLM's OpenAI-compatible server
100+
client = OpenAI(base_url="http://localhost:8000/v1", api_key="EMPTY")
101+
102+
model = "openai/whisper-large-v3" # vllm server model
103+
104+
# You can update the below with an audio file of your choosing
105+
audio_filepath=str(AudioAsset("winning_call").get_local_path())
106+
107+
def transcribe_audio():
108+
with open(audio_filepath, "rb") as audio:
109+
transcription = client.audio.transcriptions.create(
110+
model=model,
111+
file=audio,
112+
language="en",
113+
response_format="json",
114+
temperature=0.0,
115+
)
116+
return transcription.text
117+
118+
def main():
119+
t0 = time.time()
120+
out = transcribe_audio()
121+
print(f"\n=== Output ===\n{out}\n")
122+
print(f"Batch completed in : {time.time() - t0:.2f}s")
123+
124+
if __name__ == "__main__":
125+
main()
126+
```
127+
128+
Now run the script with:
129+
```bash
130+
python whisper_test.py
131+
```
132+
133+
You can do the same for the quantised model. Start the server:
134+
```bash
135+
vllm serve RedHatAI/whisper-large-v3-quantized.w8a8
136+
```
137+
138+
Update your test script to use the quantised model:
139+
```python
140+
model = "RedHatAI/whisper-large-v3-quantized.w8a8"
141+
```
142+
143+
Run inference on the quantised model:
144+
```bash
145+
python whisper_test.py
146+
```
147+
148+
You now have the quantised and non-quantised Llama and Whisper models on your local machine. You have installed vLLM and demonstrated you can run inference on your models. Now you can move on to benchmarking the Llama models and compare their performance.

0 commit comments

Comments
 (0)