본문 바로가기
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

PagedAttention은 KV cache를 블록으로 다뤄

vLLM은 KV cache를 운영체제의 메모리 페이지처럼 고정 크기 블록에 저장하고 sequence마다 블록 표를 관리해. 빈 조각이 흩어지는 현상을 크게 줄여 같은 GPU에 더 많은 동시 요청을 담을 수 있어.

연속 배치는 가장 느린 요청을 기다리지 않아

고정 배치는 요청 N개를 함께 시작하고 가장 긴 요청이 끝날 때까지 자리를 비우지 못해. 연속 배치는 디코딩 단계마다 끝난 sequence를 빼고 대기 중인 sequence를 넣어. 길이가 다른 요청이 섞인 순간 트래픽에서 처리량이 크게 오르는 이유야.

온라인과 오프라인에 맞는 입구가 따로 있어

  • vllm serve {model_id}는 OpenAI 호환 서버를 열어 기존 클라이언트와 연결해.
  • 오프라인 배치에서는 Python의 LLMSamplingParams를 사용해.

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

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

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