Skip to content

Commit df4ba50

Browse files
committed
Document Sync by Tina
1 parent 0314244 commit df4ba50

File tree

1 file changed

+211
-0
lines changed

1 file changed

+211
-0
lines changed

docs/stable/serve/live_migration.md

Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
---
2+
sidebar_position: 1
3+
---
4+
5+
# Live Migration of Inference Instances
6+
7+
This example illustrates the live migration of inference instances in a ServerlessLLM cluster by constructing a scenario where two models are deployed to the cluster. Model `Qwen2.5-3B` is stored on both nodes, while model `Qwen2.5-1.5B` is only stored on node 0 (e.g., due to being less popular). This example will show a locality-contention scenario where `Qwen2.5-3B` is being served on node 0 but `Qwen2.5-1.5B` is requested to be served on the same node for optimal locality. We will find that:
8+
9+
- **Without migration**, `Qwen2.5-1.5B` would have to wait for the completion of the ongoing inference instance of `Qwen2.5-3B` on node 0.
10+
- **With live migration**, the ongoing inference instance of `Qwen2.5-3B` is migrated to node 1, and `Qwen2.5-1.5B` is allocated to node 0, thus can be served immediately.
11+
12+
## Prerequisites
13+
14+
To run this example, we will use Docker Compose to set up a ServerlessLLM cluster. Before proceeding, please ensure you have read the [Docker Quickstart Guide](../getting_started/docker_quickstart.md).
15+
16+
**Requirements:**
17+
18+
- **Two GPUs** are required to illustrate the live migration of inference instances.
19+
- **At least 20 GB of host memory** (this can be adjusted by using smaller models).
20+
- **ServerlessLLM version 0.6**: Ensure you have `sllm==0.6` and `sllm-store==0.6` installed.
21+
22+
##
23+
24+
Start a local Docker-based ray cluster using Docker Compose.
25+
26+
### Clone the ServerlessLLM Repository
27+
28+
If you haven't already, clone the ServerlessLLM repository:
29+
30+
```bash
31+
git clone https://github.com/ServerlessLLM/ServerlessLLM.git
32+
cd ServerlessLLM/examples/live_migration
33+
```
34+
35+
### Configure the Model Directory
36+
37+
Create a directory on your host machine where models will be stored, and set the MODEL_FOLDER environment variable to point to this directory:
38+
39+
```bash
40+
export MODEL_FOLDER=/path/to/your/models
41+
```
42+
43+
Replace `/path/to/your/models` with the actual path where you want to store the models.
44+
45+
The Docker Compose configuration is already located in the `examples/live_migration` directory.
46+
47+
## Test ServerlessLLM Without Live Migration
48+
49+
1. **Start the ServerlessLLM Services Using Docker Compose**
50+
51+
```bash
52+
docker compose up -d --build
53+
```
54+
55+
This command will start the Ray head node and two worker nodes defined in the `docker-compose.yml` file.
56+
57+
:::tip
58+
Use the following command to monitor the logs of the head node:
59+
60+
```bash
61+
docker logs -f sllm_head
62+
```
63+
:::
64+
65+
2. **Deploy Models with the Placement Spec Files**
66+
67+
Activate the ServerlessLLM environment and set the server URL:
68+
```bash
69+
conda activate sllm
70+
export LLM_SERVER_URL=http://127.0.0.1:8343/
71+
```
72+
73+
Deploy the models:
74+
```bash
75+
sllm-cli deploy --config config-qwen-1.5b.json
76+
sllm-cli deploy --config config-qwen-3b.json
77+
```
78+
79+
3. **Verify the Deployment**
80+
81+
Start two inference requests in parallel. The first request is for `Qwen2.5-3B`, and the second request, sent shortly after, is for `Qwen2.5-1.5B`. The `sleep` command is used to introduce a short interval between the two requests:
82+
83+
```bash
84+
curl http://127.0.0.1:8343/v1/chat/completions \
85+
-H "Content-Type: application/json" \
86+
-d '{
87+
"model": "Qwen/Qwen2.5-3B-Instruct",
88+
"messages": [
89+
{"role": "system", "content": "You are a helpful assistant."},
90+
{"role": "user", "content": "Could you share a story of the history of Computer Science?"}
91+
],
92+
"max_tokens": 1024
93+
}' &
94+
95+
sleep 3
96+
97+
curl http://127.0.0.1:8343/v1/chat/completions \
98+
-H "Content-Type: application/json" \
99+
-d '{
100+
"model": "Qwen/Qwen2.5-1.5B-Instruct",
101+
"messages": [
102+
{"role": "system", "content": "You are a helpful assistant."},
103+
{"role": "user", "content": "What is your name?"}
104+
],
105+
"max_tokens": 64
106+
}'
107+
```
108+
109+
Since `Qwen2.5-3B` is requested first, `Qwen2.5-1.5B` must wait for the ongoing inference instance of `Qwen2.5-3B` to complete on node 0 before it can start processing.
110+
111+
112+
4. Clean up.
113+
114+
```bash
115+
docker compose down
116+
```
117+
118+
## Test ServerlessLLM With Live Migration
119+
120+
1. **Start the ServerlessLLM Services with Live Migration Enabled**
121+
122+
Use the following command to start the ServerlessLLM services with live migration enabled. This configuration includes the `enable-migration.yml` file:
123+
124+
```bash
125+
docker compose -f docker-compose.yml -f enable-migration.yml up -d --build
126+
```
127+
128+
This command will start the Ray head node and two worker nodes, enabling the live migration feature.
129+
130+
2. **Deploy Models with the Placement Spec Files**
131+
132+
Activate the ServerlessLLM environment and set the server URL:
133+
134+
```bash
135+
conda activate sllm
136+
export LLM_SERVER_URL=http://127.0.0.1:8343/
137+
```
138+
139+
Deploy the models:
140+
141+
```bash
142+
sllm-cli deploy --config config-qwen-1.5b.json
143+
sllm-cli deploy --config config-qwen-3b.json
144+
```
145+
146+
3. **Verify the Deployment**
147+
148+
Start two inference requests in parallel. The first request is for `Qwen2.5-3B`, and the second request, sent shortly after, is for `Qwen2.5-1.5B`. The `sleep` command is used to introduce a short interval between the two requests:
149+
150+
```bash
151+
curl http://127.0.0.1:8343/v1/chat/completions \
152+
-H "Content-Type: application/json" \
153+
-d '{
154+
"model": "Qwen/Qwen2.5-3B-Instruct",
155+
"messages": [
156+
{"role": "system", "content": "You are a helpful assistant."},
157+
{"role": "user", "content": "Could you share a story of the history of Computer Science?"}
158+
],
159+
"max_tokens": 1024
160+
}' &
161+
162+
sleep 3
163+
164+
curl http://127.0.0.1:8343/v1/chat/completions \
165+
-H "Content-Type: application/json" \
166+
-d '{
167+
"model": "Qwen/Qwen2.5-1.5B-Instruct",
168+
"messages": [
169+
{"role": "system", "content": "You are a helpful assistant."},
170+
{"role": "user", "content": "What is your name?"}
171+
],
172+
"max_tokens": 64
173+
}'
174+
```
175+
176+
According to the response, you should observe that `Qwen2.5-1.5B` completes ahead of `Qwen2.5-3B`. This is because the ongoing inference instance of `Qwen2.5-3B` is live-migrated from node 0 to node 1, allowing `Qwen2.5-1.5B` to be served immediately on node 0.
177+
178+
As shown in the log message, the ongoing inference instance of the model `Qwen/Qwen2.5-3B-Instruct` is live-migrated from node 0 to node 1. And model `Qwen/Qwen2.5-1.5B-Instruct` is allocated to node 0.
179+
180+
```bash
181+
(MigrationRouter pid=1724) INFO 12-10 22:05:02 migration_router.py:106] Executing migration plan: MigrationPlan(target_node_id='1', source_instance=InstanceStatus(instance_id='Qwen/Qwen2.5-3B-Instruct_dedb945f-74e5-403f-8677-35965453abab', node_id='0', num_gpu=1, concurrency=0, model_name='Qwen/Qwen2.5-3B-Instruct', num_current_tokens=0))
182+
(MigrationRouter pid=1724) INFO 12-10 22:05:13 migration_router.py:164] Initialized backend for instance Qwen/Qwen2.5-3B-Instruct_2c9ef57f-c432-45d6-a4a9-1bae9c792853 for model Qwen/Qwen2.5-3B-Instruct
183+
# Start multi-round live migration
184+
(MigrationRouter pid=1724) INFO 12-10 22:05:13 migration_router.py:178] Migration iteration 0
185+
(MigrationRouter pid=1724) INFO 12-10 22:05:13 migration_router.py:183] Number of tokens: 353, delta: 353
186+
(MigrationRouter pid=1724) INFO 12-10 22:05:13 migration_router.py:198] Migration iteration 0 completed
187+
(MigrationRouter pid=1724) INFO 12-10 22:05:13 migration_router.py:178] Migration iteration 1
188+
(MigrationRouter pid=1724) INFO 12-10 22:05:13 migration_router.py:183] Number of tokens: 14, delta: 14
189+
(MigrationRouter pid=1724) INFO 12-10 22:05:13 migration_router.py:188] Migration completed: remained 14 tokens
190+
(MigrationRouter pid=1724) INFO 12-10 22:05:13 migration_router.py:201] Migrated instance Qwen/Qwen2.5-3B-Instruct_dedb945f-74e5-403f-8677-35965453abab to Qwen/Qwen2.5-3B-Instruct_2c9ef57f-c432-45d6-a4a9-1bae9c792853
191+
# Finish multi-round live migration
192+
(MigrationRouter pid=1724) INFO 12-10 22:05:13 migration_router.py:215] Instance Qwen/Qwen2.5-3B-Instruct_dedb945f-74e5-403f-8677-35965453abab removed
193+
(MigrationRouter pid=1724) DEBUG 12-10 22:05:13 migration_router.py:77] Preempted request: ...
194+
# Resume the instance on target node
195+
(MigrationRouter pid=1724) INFO 12-10 22:05:13 migration_router.py:83] Resuming request on target instance: Qwen/Qwen2.5-3B-Instruct_2c9ef57f-c432-45d6-a4a9-1bae9c792853
196+
# Qwen/Qwen2.5-1.5B is allocated to node 0
197+
(StoreManager pid=1459) INFO 12-10 22:05:14 store_manager.py:344] Loading Qwen/Qwen2.5-1.5B-Instruct to node 0
198+
(StorageAwareScheduler pid=1574) INFO 12-10 22:05:14 fcfs_scheduler.py:92] Deallocating model Qwen/Qwen2.5-3B-Instruct instance Qwen/Qwen2.5-3B-Instruct_dedb945f-74e5-403f-8677-35965453abab
199+
(StorageAwareScheduler pid=1574) INFO 12-10 22:05:14 fcfs_scheduler.py:103] Node 0 deallocated 1 GPUs
200+
(StorageAwareScheduler pid=1574) INFO 12-10 22:05:14 fcfs_scheduler.py:108] Model Qwen/Qwen2.5-3B-Instruct instance Qwen/Qwen2.5-3B-Instruct_dedb945f-74e5-403f-8677-35965453abab deallocated
201+
(StorageAwareScheduler pid=1574) INFO 12-10 22:05:14 storage_aware_scheduler.py:188] Migrated instance Qwen/Qwen2.5-3B-Instruct to node 1 instance Qwen/Qwen2.5-3B-Instruct_2c9ef57f-c432-45d6-a4a9-1bae9c792853
202+
(StorageAwareScheduler pid=1574) INFO 12-10 22:05:14 storage_aware_scheduler.py:195] Allocated node 0 for model Qwen/Qwen2.5-1.5B-Instruct
203+
```
204+
205+
4. Clean up.
206+
207+
```bash
208+
docker compose down
209+
```
210+
211+

0 commit comments

Comments
 (0)