LLM 추론 효율 극대화: Speculative Decoding 종합 서베이
Unlocking Efficiency in Large Language Model Inference: A Comprehensive Survey of Speculative Decoding
TL;DR Highlight
작은 모델로 토큰 미리 예측하고 큰 모델로 병렬 검증해서 LLM 추론 속도를 2~3배 높이는 Speculative Decoding 기법들을 총정리한 서베이.
Who Should Read
LLM API 호출 비용이나 응답 지연(latency)을 줄이고 싶은 백엔드/ML 엔지니어. vLLM, TGI 같은 추론 서버를 운영하거나 온디바이스 LLM을 최적화하는 개발자.
Core Mechanics
- Speculative Decoding의 핵심 아이디어: 작은 draft 모델이 토큰 K개를 미리 예측하고, 큰 target LLM이 이걸 한 번에 병렬로 검증 → 토큰당 메모리 I/O 횟수를 줄여서 속도 향상
- 드래프터 종류는 크게 2가지 - (1) 외부 소형 모델 사용(T5-small로 T5-XXL 가속 등), (2) target LLM 자체를 활용하는 self-drafting(Medusa, EAGLE처럼 추가 헤드 붙이기)
- EAGLE이 Spec-Bench 기준 전체 1등: RTX 3090에서 Vicuna-7B 대비 평균 2.08×, A100에서 최대 2.5× 속도 향상 달성. KV 캐시를 재활용해 드래프팅 오버헤드를 줄인 게 핵심
- Token Tree Verification(토큰 트리 검증): 여러 후보 시퀀스를 트리 구조로 묶어 LLM이 한 번에 검증 → 단일 시퀀스 검증보다 acceptance rate 향상 (SpecInfer, Medusa, EAGLE이 사용)
- 샘플링 온도가 올라갈수록 가속 효과 감소: T=0에서 EAGLE 2.08×이던 게 T=1에서 1.74×로 줄어듦. 높은 온도에서는 speculative sampling 기준의 계산 복잡도가 증가하기 때문
- FP16 vs FP32 주의: FP16에서 Speculative Decoding 결과가 일반 autoregressive decoding과 미묘하게 달라질 수 있음. 긴 시퀀스에서 부동소수점 오차 누적 때문
Evidence
- EAGLE: RTX 3090 + Vicuna-7B 기준 평균 2.08× 속도 향상 (수학 추론 2.44×, 멀티턴 대화 2.35×), A100에서는 최대 2.53× (Vicuna-13B)
- Medusa vs EAGLE GPU별 차이: 3090에서 Medusa 1.48× → A100에서 2.42× (64% 향상), Lookahead 1.11× → 1.77× (59% 향상). 고성능 GPU일수록 Speculative Decoding 효과 커짐
- PLD(Prompt Lookup Decoding): 요약 태스크에서 2.41× 달성했지만 번역에서는 1.11×로 뚝 떨어짐. 입출력 텍스트 유사도가 높은 태스크에 특화
- 초기 SpecDec 논문 기준 5× 속도 향상 보고 (Transformer-base 65M 모델 사용 시). 현실적으로 범용 태스크에서는 2~3× 수준이 일반적
How to Apply
- 기존 LLM 서빙 파이프라인에 EAGLE이나 Medusa를 붙이려면: target 모델에 추가 autoregression head를 fine-tuning해서 장착. 별도 소형 모델 관리 없이 단일 모델로 2×+ 속도 향상 가능. GitHub SafeAILab/EAGLE 참고
- 별도 모델 학습 없이 빠르게 적용하고 싶으면: HuggingFace의 assisted generation(SpS) 기능 사용. 같은 시리즈 소형 모델(예: vicuna-68m)을 drafter로 설정하면 추가 학습 없이 1.5~2× 가속 가능
- RAG 파이프라인처럼 입력과 출력이 비슷한 태스크면: PLD(Prompt Lookup Decoding)가 간단하고 효과적. 입력 프롬프트에서 텍스트 스팬을 draft로 재활용하는 방식이라 구현이 매우 단순함
Code Example
# HuggingFace Assisted Generation (SpS) - 추가 학습 없이 바로 사용 가능
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
# Target LLM (큰 모델)
target_model = AutoModelForCausalLM.from_pretrained("lmsys/vicuna-7b-v1.3")
# Draft 모델 (작은 모델 - 같은 시리즈)
draft_model = AutoModelForCausalLM.from_pretrained("double7/vicuna-68m")
tokenizer = AutoTokenizer.from_pretrained("lmsys/vicuna-7b-v1.3")
inputs = tokenizer("Tell me about speculative decoding", return_tensors="pt")
# Speculative Decoding으로 생성 (assistant_model 파라미터가 핵심)
outputs = target_model.generate(
**inputs,
assistant_model=draft_model, # 이게 전부!
max_new_tokens=200,
do_sample=False # greedy decoding (T=0)
)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
# PLD (Prompt Lookup Decoding) - RAG/요약 태스크에 효과적
# pip install transformers>=4.35
outputs = target_model.generate(
**inputs,
prompt_lookup_num_tokens=10, # 입력에서 10토큰씩 draft로 재활용
max_new_tokens=200,
)Terminology
Related Resources
Original Abstract (Expand)
To mitigate the high inference latency stemming from autoregressive decoding in Large Language Models (LLMs), Speculative Decoding has emerged as a novel decoding paradigm for LLM inference. In each decoding step, this method first drafts several future tokens efficiently and then verifies them in parallel. Unlike autoregressive decoding, Speculative Decoding facilitates the simultaneous decoding of multiple tokens per step, thereby accelerating inference. This paper presents a comprehensive overview and analysis of this promising decoding paradigm. We begin by providing a formal definition and formulation of Speculative Decoding. Then, we organize in-depth discussions on its key facets, such as drafter selection and verification strategies. Furthermore, we present a comparative analysis of leading methods under third-party testing environments. We aim for this work to serve as a catalyst for further research on Speculative Decoding, ultimately contributing to more efficient LLM inference.