Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

JohnScheuer/speculative-decoding-real-v2

Open more actions menu

Repository files navigation

speculative-decoding-real-v2

Python PyTorch GPU License: MIT Best

Measures real speculative decoding speedup using the official HuggingFace assistant_model API across 4 model pairs and multiple output lengths.

Validates speculative-decoding-sim (project 6) and resolves the KV cache bug from speculative-decoding-validation (project 10).

For design details see DESIGN.md.


Best Result: 1.747x speedup

distilgpt2 (82M) -> gpt2-medium (355M)
K=1, n=512 output tokens
Baseline: 8.19s  Speculative: 4.69s  Speedup: 1.747x

Key Findings

1. Draft/verifier cost ratio is the dominant parameter

ratio=0.23 (distilgpt2->gpt2-medium): 1.747x at n=512
ratio=0.35 (gpt2->gpt2-medium):       1.490x at n=512
ratio=0.46 (gpt2-medium->gpt2-large): 1.170x at n=256
ratio=1.00 (gpt2->gpt2, self):        0.821x (never wins)

Validates speculative-decoding-sim cost_ratio breakeven prediction.

2. Speedup grows with output length

distilgpt2->gpt2-medium (K=1):
n=16:  0.914x
n=64:  1.125x
n=128: 1.439x
n=256: 1.590x
n=512: 1.747x  <- speedup keeps growing

gpt2->gpt2-medium (K=5):
n=64:  1.101x  n=256: 1.467x  n=512: 1.490x

3. Optimal K depends on draft quality

ratio=0.23: K=1 optimal  (low alignment)
ratio=0.35: K=5 optimal  (moderate alignment)
ratio=0.46: K=7 optimal  (better alignment)

At K=1 with ratio=0.23, speculation acts like assisted decoding:
one cheap candidate per verifier step. Trying K>1 adds overhead
that outweighs the benefit at this alignment level.

4. 19/36 configs exceed 1.0x speedup


Quick Start

python3 -m venv venv
source venv/bin/activate
pip install torch transformers

python3 profile_speculative.py      # basic pairs
python3 profile_speculative_v2.py   # all 4 pairs + long outputs

vs Project 10

Aspect Project 10 This project
API Manual KV cache HF assistant_model
KV issue DynamicCache bug Handled by HF
Best speedup 1.14x 1.747x
Output lengths up to 64 tok up to 512 tok

Results

results/sweep_k.csv          K sweep for original pairs
results/output_length.csv    Output length for original pairs
results/all_results_v2.csv   All v2 results (37 rows)

Portfolio Context

Project 20 in a series on LLM inference infrastructure. Full series: https://github.com/JohnScheuer

About

Measures real speculative decoding speedup using the official HuggingFace assistant_model API across 4 model pairs and output lengths up to 512 tokens. Best result: distilgpt2->gpt2-medium achieves 1.747x speedup at 512 output tokens. Validates that cost_ratio and output_length are the key parameters.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.