"vllm/vscode:/vscode.git/clone" did not exist on "21b82f4ea2f12ab2c3d74f9156b50616b892ea7d"
run_on_sky.rst 9.76 KB
Newer Older
1
2
.. _on_cloud:

3
4
Deploying and scaling up with SkyPilot
================================================
5
6
7

.. raw:: html

8
9
10
  <p align="center">
    <img src="https://imgur.com/yxtzPEu.png" alt="vLLM"/>
  </p>
11

12
vLLM can be **run and scaled to multiple service replicas on clouds and Kubernetes** with `SkyPilot <https://github.com/skypilot-org/skypilot>`__, an open-source framework for running LLMs on any cloud. More examples for various open models, such as Llama-3, Mixtral, etc, can be found in `SkyPilot AI gallery <https://skypilot.readthedocs.io/en/latest/gallery/index.html>`__.
13

14
15
16
17
18
19
20

Prerequisites
-------------

- Go to the `HuggingFace model page <https://huggingface.co/meta-llama/Meta-Llama-3-8B-Instruct>`__ and request access to the model :code:`meta-llama/Meta-Llama-3-8B-Instruct`.
- Check that you have installed SkyPilot (`docs <https://skypilot.readthedocs.io/en/latest/getting-started/installation.html>`__).
- Check that :code:`sky check` shows clouds or Kubernetes are enabled.
21
22
23

.. code-block:: console

24
25
  pip install skypilot-nightly
  sky check
26
27
28
29


Run on a single instance
------------------------
30
31
32
33
34

See the vLLM SkyPilot YAML for serving, `serving.yaml <https://github.com/skypilot-org/skypilot/blob/master/llm/vllm/serve.yaml>`__.

.. code-block:: yaml

35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
  resources:
    accelerators: {L4, A10g, A10, L40, A40, A100, A100-80GB} # We can use cheaper accelerators for 8B model.
    use_spot: True
    disk_size: 512  # Ensure model checkpoints can fit.
    disk_tier: best
    ports: 8081  # Expose to internet traffic.

  envs:
    MODEL_NAME: meta-llama/Meta-Llama-3-8B-Instruct
    HF_TOKEN: <your-huggingface-token>  # Change to your own huggingface token, or use --env to pass.

  setup: |
    conda create -n vllm python=3.10 -y
    conda activate vllm

    pip install vllm==0.4.0.post1
    # Install Gradio for web UI.
    pip install gradio openai
    pip install flash-attn==2.5.7

  run: |
    conda activate vllm
    echo 'Starting vllm api server...'
    python -u -m vllm.entrypoints.openai.api_server \
      --port 8081 \
      --model $MODEL_NAME \
      --trust-remote-code \
      --tensor-parallel-size $SKYPILOT_NUM_GPUS_PER_NODE \
      2>&1 | tee api_server.log &
    
    echo 'Waiting for vllm api server to start...'
    while ! `cat api_server.log | grep -q 'Uvicorn running on'`; do sleep 1; done

    echo 'Starting gradio server...'
    git clone https://github.com/vllm-project/vllm.git || true
    python vllm/examples/gradio_openai_chatbot_webserver.py \
      -m $MODEL_NAME \
      --port 8811 \
      --model-url http://localhost:8081/v1 \
      --stop-token-ids 128009,128001
75

76
Start the serving the Llama-3 8B model on any of the candidate GPUs listed (L4, A10g, ...): 
77
78
79

.. code-block:: console

80
  HF_TOKEN="your-huggingface-token" sky launch serving.yaml --env HF_TOKEN
81

82
Check the output of the command. There will be a shareable gradio link (like the last line of the following). Open it in your browser to use the LLaMA model to do the text completion.
83
84
85

.. code-block:: console

86
  (task, pid=7431) Running on public URL: https://<gradio-hash>.gradio.live
87

88
89
90
91
**Optional**: Serve the 70B model instead of the default 8B and use more GPU:

.. code-block:: console

92
  HF_TOKEN="your-huggingface-token" sky launch serving.yaml --gpus A100:8 --env HF_TOKEN --env MODEL_NAME=meta-llama/Meta-Llama-3-70B-Instruct
93
94
95
96
97
98
99
100
101


Scale up to multiple replicas
-----------------------------

SkyPilot can scale up the service to multiple service replicas with built-in autoscaling, load-balancing and fault-tolerance. You can do it by adding a services section to the YAML file.

.. code-block:: yaml

102
103
104
105
106
107
108
109
110
111
112
113
  service:
    replicas: 2
    # An actual request for readiness probe.
    readiness_probe:
      path: /v1/chat/completions
      post_data:
      model: $MODEL_NAME
      messages:
        - role: user
          content: Hello! What is your name?
    max_tokens: 1
    
114
115
.. raw:: html

116
117
  <details>
  <summary>Click to see the full recipe YAML</summary>
118
119
120
121


.. code-block:: yaml

122
123
124
125
126
127
128
129
130
131
  service:
    replicas: 2
    # An actual request for readiness probe.
    readiness_probe:
      path: /v1/chat/completions
      post_data:
        model: $MODEL_NAME
        messages:
          - role: user
            content: Hello! What is your name?
132
133
        max_tokens: 1

134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
  resources:
    accelerators: {L4, A10g, A10, L40, A40, A100, A100-80GB} # We can use cheaper accelerators for 8B model.
    use_spot: True
    disk_size: 512  # Ensure model checkpoints can fit.
    disk_tier: best
    ports: 8081  # Expose to internet traffic.

  envs:
    MODEL_NAME: meta-llama/Meta-Llama-3-8B-Instruct
    HF_TOKEN: <your-huggingface-token>  # Change to your own huggingface token, or use --env to pass.

  setup: |
    conda create -n vllm python=3.10 -y
    conda activate vllm

    pip install vllm==0.4.0.post1
    # Install Gradio for web UI.
    pip install gradio openai
    pip install flash-attn==2.5.7

  run: |
    conda activate vllm
    echo 'Starting vllm api server...'
    python -u -m vllm.entrypoints.openai.api_server \
      --port 8081 \
      --model $MODEL_NAME \
      --trust-remote-code \
      --tensor-parallel-size $SKYPILOT_NUM_GPUS_PER_NODE \
      2>&1 | tee api_server.log
163
164
165

.. raw:: html

166
  </details>
167
168
169
170
171

Start the serving the Llama-3 8B model on multiple replicas:

.. code-block:: console

172
  HF_TOKEN="your-huggingface-token" sky serve up -n vllm serving.yaml --env HF_TOKEN
173
174
175


Wait until the service is ready:
176
177
178

.. code-block:: console

179
  watch -n10 sky serve status vllm
180
181
182
183


.. raw:: html

184
185
  <details>
  <summary>Example outputs:</summary>
186
187
188

.. code-block:: console

189
190
191
  Services
  NAME  VERSION  UPTIME  STATUS  REPLICAS  ENDPOINT
  vllm  1        35s     READY   2/2       xx.yy.zz.100:30001
192

193
194
195
196
  Service Replicas
  SERVICE_NAME  ID  VERSION  IP            LAUNCHED     RESOURCES                STATUS  REGION
  vllm          1   1        xx.yy.zz.121  18 mins ago  1x GCP([Spot]{'L4': 1})  READY   us-east4
  vllm          2   1        xx.yy.zz.245  18 mins ago  1x GCP([Spot]{'L4': 1})  READY   us-east4
197
198

.. raw:: html
199
200
  
  </details>
201
202
203
204
205

After the service is READY, you can find a single endpoint for the service and access the service with the endpoint:

.. code-block:: console

206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
  ENDPOINT=$(sky serve status --endpoint 8081 vllm)
  curl -L http://$ENDPOINT/v1/chat/completions \
    -H "Content-Type: application/json" \
    -d '{
      "model": "meta-llama/Meta-Llama-3-8B-Instruct",
      "messages": [
      {
        "role": "system",
        "content": "You are a helpful assistant."
      },
      {
        "role": "user",
        "content": "Who are you?"
      }
      ],
      "stop_token_ids": [128009,  128001]
    }'

To enable autoscaling, you could replace the `replicas` with the following configs in `service`:
225
226
227

.. code-block:: yaml

228
229
230
231
232
  service:
    replica_policy:
      min_replicas: 2
      max_replicas: 4
      target_qps_per_replica: 2
233
234
235

This will scale the service up to when the QPS exceeds 2 for each replica.

236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
    
.. raw:: html

  <details>
  <summary>Click to see the full recipe YAML</summary>


.. code-block:: yaml

  service:
    replica_policy:
      min_replicas: 2
      max_replicas: 4
      target_qps_per_replica: 2
    # An actual request for readiness probe.
    readiness_probe:
      path: /v1/chat/completions
      post_data:
        model: $MODEL_NAME
        messages:
          - role: user
            content: Hello! What is your name?
        max_tokens: 1

  resources:
    accelerators: {L4, A10g, A10, L40, A40, A100, A100-80GB} # We can use cheaper accelerators for 8B model.
    use_spot: True
    disk_size: 512  # Ensure model checkpoints can fit.
    disk_tier: best
    ports: 8081  # Expose to internet traffic.

  envs:
    MODEL_NAME: meta-llama/Meta-Llama-3-8B-Instruct
    HF_TOKEN: <your-huggingface-token>  # Change to your own huggingface token, or use --env to pass.

  setup: |
    conda create -n vllm python=3.10 -y
    conda activate vllm

    pip install vllm==0.4.0.post1
    # Install Gradio for web UI.
    pip install gradio openai
    pip install flash-attn==2.5.7

  run: |
    conda activate vllm
    echo 'Starting vllm api server...'
    python -u -m vllm.entrypoints.openai.api_server \
      --port 8081 \
      --model $MODEL_NAME \
      --trust-remote-code \
      --tensor-parallel-size $SKYPILOT_NUM_GPUS_PER_NODE \
      2>&1 | tee api_server.log


.. raw:: html
  
  </details>

To update the service with the new config:

.. code-block:: console

  HF_TOKEN="your-huggingface-token" sky serve update vllm serving.yaml --env HF_TOKEN


To stop the service:

.. code-block:: console

  sky serve down vllm

308
309
310
311
312
313
314
315
316

**Optional**: Connect a GUI to the endpoint
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


It is also possible to access the Llama-3 service with a separate GUI frontend, so the user requests send to the GUI will be load-balanced across replicas.

.. raw:: html

317
318
  <details>
  <summary>Click to see the full GUI YAML</summary>
319
320
321

.. code-block:: yaml

322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
  envs:
    MODEL_NAME: meta-llama/Meta-Llama-3-8B-Instruct
    ENDPOINT: x.x.x.x:3031 # Address of the API server running vllm. 

  resources:
    cpus: 2

  setup: |
    conda create -n vllm python=3.10 -y
    conda activate vllm

    # Install Gradio for web UI.
    pip install gradio openai

  run: |
    conda activate vllm
    export PATH=$PATH:/sbin

    echo 'Starting gradio server...'
    git clone https://github.com/vllm-project/vllm.git || true
    python vllm/examples/gradio_openai_chatbot_webserver.py \
      -m $MODEL_NAME \
      --port 8811 \
      --model-url http://$ENDPOINT/v1 \
      --stop-token-ids 128009,128001 | tee ~/gradio.log

348
349

.. raw:: html
350
351
  
  </details>
352
353
354
355
356

1. Start the chat web UI:

.. code-block:: console

357
  sky launch -c gui ./gui.yaml --env ENDPOINT=$(sky serve status --endpoint vllm)
358
359
360
361
362
363


2. Then, we can access the GUI at the returned gradio link:

.. code-block:: console

364
  | INFO | stdout | Running on public URL: https://6141e84201ce0bb4ed.gradio.live
365

366