C.W.K.
Stream
Lesson 03 of 05 · published

클라우드 서빙: vLLM & TGI

~22 min · vllm, tgi, paged-attention, openai-compatible

Level 0관찰자
0 XP0/43 lessons0/11 achievements
0/120 XP to next level120 XP to go0% complete

vLLM (실서비스 기본값)

vLLM은 high-throughput LLM 서빙 standby. 두 핵심 혁신 —

  • PagedAttention: OS가 가상 메모리 page하듯 KV-cache 메모리 관리. 단편화 제거, 동시 capacity 극적 증가.
  • Continuous batching: 여러 요청을 같은 forward pass에서 처리, slot 비면 packing. 순진한 sequential 서빙 대비 엄청난 throughput 이득.

vLLM은 OpenAI 호환 API를 기본으로 말해서 어떤 OpenAI SDK 클라이언트든 코드 변경 없이 가리킬 수 있어.

vLLM + LoRA — merge 불필요

vLLM은 베이스 모델 위에 LoRA adapter 직접 서빙하고 요청별 hot-swap 가능. 같은 베이스에 여러 파인튜닝 변형 서빙(멀티테넌트, 고객별 특화)할 때 옳은 셋업.

TGI (Text Generation Inference)

Hugging Face 자체 추론 서버. Hub 긴밀 통합에 특히 좋아. 일반적으로 vLLM이랑 비슷한 throughput, 약간 다른 사용감.

Code

vLLM serving — OpenAI-compatible API·bash
# Install
pip install vllm

# Serve your merged model with OpenAI-compatible API
python -m vllm.entrypoints.openai.api_server \
    --model ./merged-model \
    --port 8000 \
    --tensor-parallel-size 1 \
    --max-model-len 4096

# Now use with the OpenAI SDK!
# from openai import OpenAI
# client = OpenAI(base_url="http://localhost:8000/v1", api_key="none")
vLLM with multiple LoRA adapters (no merge)·python
# Server side:
# python -m vllm.entrypoints.openai.api_server \
#     --model meta-llama/Llama-3.1-8B-Instruct \
#     --enable-lora \
#     --lora-modules medical=./adapter-medical legal=./adapter-legal

# Client side: select adapter per request via the model field
from openai import OpenAI
client = OpenAI(base_url="http://localhost:8000/v1", api_key="none")

medical = client.chat.completions.create(
    model="medical",  # uses the medical LoRA
    messages=[{"role": "user", "content": "What is hypertension?"}],
)

legal = client.chat.completions.create(
    model="legal",    # uses the legal LoRA on the same base
    messages=[{"role": "user", "content": "What's force majeure?"}],
)
TGI via Docker (Hugging Face stack)·bash
docker run --gpus all -p 8080:80 \
    -v ./merged-model:/model \
    ghcr.io/huggingface/text-generation-inference:latest \
    --model-id /model \
    --quantize bitsandbytes-fp4 \
    --max-input-tokens 2048 \
    --max-total-tokens 4096

External links

Exercise

로컬에서 vLLM에 OpenAI 호환 API로 merged 7B 모델 서빙 셋업. 50요청 로드 테스트(aiohttp 또는 빠른 스크립트). P50, P95, P99 latency 측정. 단일 요청 동기 베이스라인이랑 비교 — continuous batching에서 오는 throughput 배수가 놀라울 거야.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.