드래프트 모델
드래프트 모델 (Draft Models)
스펙큘레이티브 디코딩의 가장 직관적인 방법은, 작고 빠른 드래프트 모델(draft model) 이 여러 개의 토큰을 미리 제안하고 큰 타겟 모델이 이를 한 번에 검증하는 거예요. 이 페이지에서 vLLM에서 드래프트 모델 방식의 스펙큘레이티브 디코딩을 설정하는 방법을 살펴볼게요.
오프라인 방식 (Offline mode)
아래 코드는 오프라인 모드로 드래프트 모델을 쓰는 스펙큘레이티브 디코딩을 설정해요. 한 번에 5개 토큰을 추측(speculate)하죠.
from vllm import LLM, SamplingParams
prompts = ["The future of AI is"]
sampling_params = SamplingParams(temperature=0.8, top_p=0.95)
llm = LLM(
model="Qwen/Qwen3-8B",
tensor_parallel_size=1,
speculative_config={
"model": "Qwen/Qwen3-0.6B",
"num_speculative_tokens": 5,
"method": "draft_model",
},
)
outputs = llm.generate(prompts, sampling_params)
for output in outputs:
prompt = output.prompt
generated_text = output.outputs[0].text
print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}")
온라인 방식 (Online mode)
온라인 모드에서 같은 설정을 하려면 서버 쪽 코드로 이렇게 해요.
vllm serve Qwen/Qwen3-4B-Thinking-2507 \
--host 0.0.0.0 \
--port 8000 \
--seed 42 \
-tp 1 \
--max_model_len 2048 \
--gpu_memory_utilization 0.8 \
--speculative_config '{"model": "Qwen/Qwen3-0.6B", "num_speculative_tokens": 5, "method": "draft_model"}'
클라이언트가 completions을 요청하는 코드는 전과 동일하게 유지돼요.
from openai import OpenAI
# OpenAI API key와 base를 vLLM API 서버로 변경
openai_api_key = "EMPTY"
openai_api_base = "http://localhost:8000/v1"
client = OpenAI(
api_key=openai_api_key,
base_url=openai_api_base,
)
models = client.models.list()
model = models.data[0].id
# Completion API
stream = False
completion = client.completions.create(
model=model,
prompt="The future of AI is",
echo=False,
n=1,
stream=stream,
)
print("Completion results:")
if stream:
for c in completion:
print(c)
else:
print(completion)
⚠️ 스펙큘레이티브 디코딩 관련 모든 설정은
--speculative_config로 전달하세요. 예전 방식인--speculative_model으로 모델을 지정하고--num_speculative_tokens같은 파라미터를 따로 붙이는 방법은 deprecated 됐어요.