SkyPilot — vLLM 배포
SkyPilot — vLLM 배포
SkyPilot은 어떤 클라우드에서든 LLM을 실행할 수 있게 해 주는 오픈소스 프레임워크입니다. vLLM을 클라우드와 Kubernetes에서 실행하고 여러 서비스 레플리카로 확장할 수 있습니다. Llama-3, Mixtral 등 다양한 오픈 모델에 대한 더 많은 예제는 SkyPilot AI gallery에서 확인할 수 있습니다.
출처: 문서
본문
사전 준비 (Prerequisites)
- HuggingFace 모델 페이지로 가서
meta-llama/Meta-Llama-3-8B-Instruct모델에 대한 접근을 요청합니다. - SkyPilot이 설치돼 있는지 확인합니다 (문서).
sky check로 클라우드나 Kubernetes가 활성화돼 있는지 확인합니다.
pip install skypilot-nightly
sky check
단일 인스턴스에서 실행 (Run on a single instance)
서빙용 vLLM SkyPilot YAML, serving.yaml을 참고하세요.
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:
PYTHONUNBUFFERED: 1
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...'
vllm serve $MODEL_NAME \
--port 8081 \
--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/applications/chatbot/gradio_openai_chatbot_webserver.py \
-m $MODEL_NAME \
--port 8811 \
--model-url http://localhost:8081/v1 \
--stop-token-ids 128009,128001
나열된 후보 GPU(L4, A10g, ...) 중 아무 곳에서나 Llama-3 8B 모델 서빙을 시작합니다:
HF_TOKEN="your-huggingface-token" sky launch serving.yaml --env HF_TOKEN
명령 출력을 확인하세요. 공유 가능한 gradio 링크(아래 마지막 줄처럼)가 나옵니다. 브라우저에서 열어 LLaMA 모델로 텍스트 완성을 해 볼 수 있습니다.
(task, pid=7431) Running on public URL: https://<gradio-hash>.gradio.live
선택사항: 기본 8B 대신 70B 모델을 더 많은 GPU로 서빙하려면:
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
여러 레플리카로 확장 (Scale up to multiple replicas)
SkyPilot은 내장 오토스케일링, 로드밸런싱, 장애 허용(fault-tolerance)으로 서비스를 여러 서비스 레플리카로 확장할 수 있습니다. YAML 파일에 services 섹션을 추가하면 됩니다.
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_completion_tokens: 1
완전한 YAML은 읽기 준비 프로브(readiness probe)를 포함해 resources, envs, setup, run 섹션을 함께 담습니다:
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_completion_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:
PYTHONUNBUFFERED: 1
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...'
vllm serve $MODEL_NAME \
--port 8081 \
--trust-remote-code \
--tensor-parallel-size $SKYPILOT_NUM_GPUS_PER_NODE \
2>&1 | tee api_server.log
Llama-3 8B 모델을 여러 레플리카로 서빙합니다:
HF_TOKEN="your-huggingface-token" \
sky serve up -n vllm serving.yaml \
--env HF_TOKEN
서비스가 준비될 때까지 기다립니다:
watch -n10 sky serve status vllm
출력 예시:
Services
NAME VERSION UPTIME STATUS REPLICAS ENDPOINT
vllm 1 35s READY 2/2 xx.yy.zz.100:30001
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
서비스가 READY가 되면 서비스용 단일 엔드포인트를 찾아 그 엔드포인트로 서비스에 접근할 수 있습니다:
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]
}'
오토스케일링을 활성화하려면 service 안의 replicas를 다음 설정으로 바꿀 수 있습니다:
service:
replica_policy:
min_replicas: 2
max_replicas: 4
target_qps_per_replica: 2
이렇게 하면 레플리카당 QPS가 2를 넘을 때 서비스가 확장됩니다. 완전한 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_completion_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:
PYTHONUNBUFFERED: 1
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...'
vllm serve $MODEL_NAME \
--port 8081 \
--trust-remote-code \
--tensor-parallel-size $SKYPILOT_NUM_GPUS_PER_NODE \
2>&1 | tee api_server.log
새 설정으로 서비스를 갱신하려면:
HF_TOKEN="your-huggingface-token" sky serve update vllm serving.yaml --env HF_TOKEN
서비스를 중지하려면:
sky serve down vllm
선택사항: 엔드포인트에 GUI 연결 (Connect a GUI to the endpoint)
별도의 GUI 프론트엔드로 Llama-3 서비스에 접근할 수도 있습니다. GUI로 보내는 사용자 요청은 레플리카 간에 로드밸런싱됩니다.
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/applications/api_client/gradio_openai_chatbot_webserver.py \
-m $MODEL_NAME \
--port 8811 \
--model-url http://$ENDPOINT/v1 \
--stop-token-ids 128009,128001 | tee ~/gradio.log
- 채팅 웹 UI를 시작합니다:
sky launch \
-c gui ./gui.yaml \
--env ENDPOINT=$(sky serve status --endpoint vllm)
- 그런 다음 반환된 gradio 링크에서 GUI에 접근할 수 있습니다:
| INFO | stdout | Running on public URL: https://6141e84201ce0bb4ed.gradio.live
더 알아보기 (Learn more)
- 모든 배포 프레임워크 — vLLM과 연동되는 프레임워크 목록
- SkyPilot 문서 — 설치·사용법
- SkyPilot AI gallery — 다양한 오픈 모델 예제
- SkyPilot vLLM serving.yaml — 공식 서빙 YAML