Skip to content

Commit d9fca9d

Browse files
authored
Update 3-run-inference-and-serve.md
1 parent 059f10f commit d9fca9d

1 file changed

Lines changed: 34 additions & 10 deletions

File tree

content/learning-paths/servers-and-cloud-computing/vllm-acceleration/3-run-inference-and-serve.md

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,20 @@ weight: 4
66
layout: learningpathall
77
---
88

9-
## About batch sizing in vLLM
9+
## Batch Sizing in vLLM
1010

11-
vLLM enforces two limits to balance memory use and throughput: a per‑sequence length (`max_model_len`) and a per‑batch token limit (`max_num_batched_tokens`). No single request can exceed the sequence limit, and the sum of tokens in a batch must stay within the batch limit.
11+
vLLM uses dynamic continuous batching to maximize hardware utilization. Two key parameters govern this process:
12+
* `max_model_len` — The maximum sequence length (number of tokens per request).
13+
No single prompt or generated sequence can exceed this limit.
14+
* `max_num_batched_tokens` — The total number of tokens processed in one batch across all requests.
15+
The sum of input and output tokens from all concurrent requests must stay within this limit.
16+
17+
Together, these parameters determine how much memory the model can use and how effectively CPU threads are saturated.
18+
On Arm-based servers, tuning them helps achieve stable throughput while avoiding excessive paging or cache thrashing.
1219

1320
## Serve an OpenAI‑compatible API
1421

15-
Start the server with sensible CPU default parameters and a quantized model:
22+
Start vLLM’s OpenAI-compatible API server using the quantized INT4 model and environment variables optimized for performance.
1623

1724
```bash
1825
export VLLM_TARGET_DEVICE=cpu
@@ -27,9 +34,19 @@ vllm serve DeepSeek-V2-Lite-w4a8dyn-mse-channelwise \
2734
--dtype float32 --max-model-len 4096 --max-num-batched-tokens 4096
2835
```
2936

37+
The server now exposes the standard OpenAI-compatible /v1/chat/completions endpoint.
38+
39+
You can test it using any OpenAI-style client library to measure tokens-per-second throughput and response latency on your Arm-based server.
40+
3041
## Run multi‑request batch
42+
After verifying a single request in the previous section, simulate concurrent load against the OpenAI-compatible server to exercise vLLM’s continuous batching scheduler.
43+
44+
About the client:
45+
Uses AsyncOpenAI with base_url="http://localhost:8000/v1" to target the vLLM server.
46+
A semaphore caps concurrency to 8 simultaneous requests (adjust CONCURRENCY to scale load).
47+
max_tokens limits generated tokens per request—this directly affects batch size and KV cache use.
3148

32-
After confirming a single request works explained in previous example, simulate concurrent load with a small OpenAI API compatible client. Save this as `batch_test.py`:
49+
Save the code below in a file named `batch_test.py`:
3350

3451
```python
3552
import asyncio
@@ -88,7 +105,7 @@ if __name__ == "__main__":
88105
asyncio.run(main())
89106
```
90107

91-
Run 8 concurrent requests against your server:
108+
Run 8 concurrent requests:
92109

93110
```bash
94111
python3 batch_test.py
@@ -108,19 +125,26 @@ This validates multi‑request behavior and shows aggregate throughput in the se
108125
(APIServer pid=4474) INFO: 127.0.0.1:44120 - "POST /v1/chat/completions HTTP/1.1" 200 OK
109126
(APIServer pid=4474) INFO 11-10 01:01:06 [loggers.py:221] Engine 000: Avg prompt throughput: 0.0 tokens/s, Avg generation throughput: 57.5 tokens/s, Running: 0 reqs, Waiting: 0 reqs, GPU KV cache usage: 0.0%, Prefix cache hit rate: 0.0%
110127
```
111-
## Optional: Serving BF16 non-quantized model
128+
## Optional: Serve a BF16 (Non-Quantized) Model
112129

113-
For a BF16 path on Arm, vLLM is acclerated by direct oneDNN integration in vLLM which allows aarch64 model to be hyperoptimized.
130+
For a non-quantized path, vLLM on Arm can run BF16 end-to-end using its oneDNN integration (which routes to Arm-optimized kernels via ACL under aarch64).
114131

115132
```bash
116133
vllm serve deepseek-ai/DeepSeek-V2-Lite \
117134
--dtype bfloat16 --max-model-len 4096 \
118135
--max-num-batched-tokens 4096
119136
```
137+
Use this BF16 setup to establish a quality reference baseline, then compare throughput and latency against your INT4 deployment to quantify the performance/accuracy trade-offs on your Arm system.
120138

121139
## Go Beyond: Power Up Your vLLM Workflow
122-
Now that you’ve successfully quantized and served a model using vLLM on Arm, here are some further ways to explore:
140+
Now that you’ve successfully quantized, served, and benchmarked a model using vLLM on Arm, you can build on what you’ve learned to push performance, scalability, and usability even further.
123141

124-
* **Try different models:** Apply the same steps to other [Hugging Face models](https://huggingface.co/models) like Llama, Qwen or Gemma.
142+
**Try Different Models**
143+
Extend your workflow to other models on Hugging Face that are compatible with vLLM and can benefit from Arm acceleration:
144+
* Meta Llama 2 / Llama 3 – Strong general-purpose baselines; excellent for comparing BF16 vs INT4 performance.
145+
* Qwen / Qwen-Chat – High-quality multilingual and instruction-tuned models.
146+
* Gemma (Google) – Compact and efficient architecture; ideal for edge or cost-optimized serving.
147+
148+
You can quantize and serve them using the same `quantize_vllm_models.py` recipe, just update the model name.
125149

126-
* **Connect a chat client:** Link your server with OpenAI-compatible UIs like [Open WebUI](https://github.com/open-webui/open-webui)
150+
* **Connect a chat client:** Link your server with OpenAI-compatible UIs like [Open WebUI](https://github.com/open-webui/open-webui)

0 commit comments

Comments
 (0)