Skip to content

Commit 4df90bd

Browse files
authored
Merge pull request #273 from NYU-RTS/amanda/docs-update
Add vLLM documentation
2 parents b6bb7c3 + 482eeaa commit 4df90bd

1 file changed

Lines changed: 109 additions & 0 deletions

File tree

docs/hpc/08_ml_ai_hpc/07_vLLM.md

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# vLLM - A Command Line LLM Tool
2+
## What is vLLM?
3+
[vLLM](https://docs.vllm.ai/en/latest/) is a fast and easy-to-use library for LLM inference and serving.
4+
5+
## Why vLLM?
6+
We tested vLLM and llama-cpp on Torch, and found vLLM performs better on Torch:
7+
Model: Qwen2.5-7B-Instruct
8+
Prompt Tokens:512
9+
Output Tokens: 256
10+
|Backend|Peak Throughput|Median Latency(ms)|Recommendation
11+
|-----|-----|-----|-----|
12+
|vLLM|~4689.6|~48.0|Best for Batch/Research|
13+
|llama-cpp|~115.0|~280.0|Best for Single User|
14+
15+
## vLLM Installation Instructions
16+
Create a vLLM directory in your /scratch directory, then install the vLLM image:
17+
```
18+
apptainer pull docker://vllm/vllm-openai:latest
19+
```
20+
### Use High-Performance SCRATCH Storage
21+
LLMs require very fast storage. On Torch, the SCRATCH filesystem is an all-flash system designed for AI workloads, providing excellent performance.To avoid exceeding your $HOME quota (50GB) and inode limits (30,000 files), you should redirect vLLM's cache and Hugging Face's model downloads to your scratch space:
22+
```
23+
export HF_HOME=/scratch/$USER/hf_cache
24+
export VLLM_CACHE_ROOT=/scratch/$USER/vllm_cache
25+
```
26+
You should run this to configure vLLM to always use your SCRATCH storage for consistent use:
27+
```
28+
echo "export HF_HOME=/scratch/\$USER/hf_cache" >> ~/.bashrc
29+
echo "export VLLM_CACHE_ROOT=/scratch/\$USER/vllm_cache" >> ~/.bashrc
30+
```
31+
32+
Note: Files on $SCRATCH are not backed up and will be deleted after 60 days of inactivity. Always keep your source code and .slurm scripts in $HOME!
33+
34+
## Run vLLM
35+
### Online Serving (OpenAI-Compatible API)
36+
vLLM implements the OpenAI API protocol, allowing it to be a drop-in replacement for applications using OpenAI's services. By default, it starts the server at http://localhost:8000. You can specify the address with --host and --port arguments.
37+
**In Terminal 1:**
38+
Start vLLM server (In this example we use Qwen model):
39+
```
40+
apptainer exec --nv vllm-openai_latest.sif vllm serve "Qwen/Qwen2.5-0.5B-Instruct"
41+
```
42+
When you see:
43+
```
44+
Application startup complete.
45+
```
46+
Open another terminal and log in to the same computing node as in terminal 1.
47+
48+
**In Terminal 2**
49+
```
50+
curl http://localhost:8000/v1/chat/completions \
51+
-H "Content-Type: application/json" \
52+
-d '{
53+
"model": "Qwen/Qwen2.5-0.5B-Instruct",
54+
"messages": [
55+
{"role": "user", "content": "Your prompt..."}
56+
]
57+
}'
58+
```
59+
60+
### Offline Inference
61+
If you need to process a large dataset at once without setting up a server, you can use vLLM's LLM class.
62+
For example, the following code downloads the facebook/opt-125m model from HuggingFace and runs it in vLLM using the default configuration.
63+
```
64+
from vllm import LLM
65+
66+
# Initialize the vLLM engine.
67+
llm = LLM(model="facebook/opt-125m")
68+
```
69+
After initializing the LLM instance, use the available APIs to perform model inference.
70+
71+
### SGLang: A Simple Option for Offline Batch Inference (Supplement Material)
72+
For cases where users only want to run batch inference and do not need an HTTP endpoint, SGLang provides a much simpler offline engine API compared to running a full vLLM server. It is particularly suitable for dataset processing, evaluation pipelines, and one-off large-scale inference jobs.
73+
For more details and examples, see the official SGLang offline engine documentation:
74+
https://docs.sglang.io/basic_usage/offline_engine_api.html
75+
76+
77+
## vLLM CLI
78+
The vllm command-line tool is used to run and manage vLLM models. You can start by viewing the help message with:
79+
```
80+
vllm --help
81+
```
82+
Serve - Starts the vLLM OpenAI Compatible API server.
83+
```
84+
vllm serve meta-llama/Llama-2-7b-hf
85+
```
86+
Chat - Generate chat completions via the running API server.
87+
```
88+
# Directly connect to localhost API without arguments
89+
vllm chat
90+
91+
# Specify API url
92+
vllm chat --url http://{vllm-serve-host}:{vllm-serve-port}/v1
93+
94+
# Quick chat with a single prompt
95+
vllm chat --quick "hi"
96+
```
97+
Complete - Generate text completions based on the given prompt via the running API server.
98+
```
99+
# Directly connect to localhost API without arguments
100+
vllm complete
101+
102+
# Specify API url
103+
vllm complete --url http://{vllm-serve-host}:{vllm-serve-port}/v1
104+
105+
# Quick complete with a single prompt
106+
vllm complete --quick "The future of AI is"
107+
```
108+
109+
For more CLI command references: visit https://docs.vllm.ai/en/stable/cli/.

0 commit comments

Comments
 (0)