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

vLLM: PagedAttention 과 Continuous Batching

~28 min · serving, vllm

Level 0스카우트
0 XP0/50 lessons0/10 achievements
0/120 XP to next level120 XP to go0% complete

vLLM 의 명성

vLLM 의 명성은 PagedAttention: KV cache 가 OS 메모리 페이지처럼 fixed-size 블록 저장, sequence 별 block table. 결과 거의 zero KV-cache fragmentation — 같은 GPU 에 naive 엔진보다 훨씬 많은 동시 요청 fit.

한 단락의 continuous batching

Naive batching: 요청 N 개 모아 같이 돌려 응답 N 개. 가장 느린 요청이 모두 stall. Continuous batching: 매 디코딩 step 엔진이 끝난 sequence swap out, queued sequence pull in. token 50 의 sequence A 가 token 1 의 sequence B 와 step 공유 가능. 버스트 트래픽 throughput 5-10x.

vLLM 실행 방법 둘

  • OpenAI 호환 서버: vllm serve {model_id} — OpenAI 클라이언트 drop-in.
  • Python 라이브러리: 오프라인 batch 작업엔 LLM + SamplingParams.

Code

OpenAI 호환 서버로 vLLM 실행·bash
pip install vllm

# 서버 시작
vllm serve meta-llama/Llama-3.1-8B-Instruct \
  --quantization awq \
  --max-model-len 8192 \
  --gpu-memory-utilization 0.85

# 다른 터미널:
curl http://localhost:8000/v1/chat/completions \
  -H 'Content-Type: application/json' \
  -d '{"model":"meta-llama/Llama-3.1-8B-Instruct","messages":[{"role":"user","content":"Hi"}]}'
Python 라이브러리로 vLLM (오프라인 batch)·python
from vllm import LLM, SamplingParams

llm = LLM(
    model="meta-llama/Llama-3.1-8B-Instruct",
    quantization="awq",
    max_model_len=4096,
)

prompts = [
    "Hello",
    "Translate 'open source' to Korean",
    "Write a haiku about Hugging Face",
] * 100  # 300 prompts, batched

params = SamplingParams(temperature=0.7, max_tokens=80)
outputs = llm.generate(prompts, params)
print(len(outputs), outputs[0].outputs[0].text[:100])

External links

Exercise

같은 모델을 비슷한 양자화 (둘 다 AWQ, 또는 가용하면 둘 다 bnb-nf4) 로 TGI 와 vLLM 통과. 동시 요청 100 개 각각에. 비교: 토큰/초 총 throughput, p50 latency, p95 latency, peak GPU 메모리. 차이 + likely cause 메모.

Progress

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

댓글 0

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

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