Skip to main content

Speculative-Decoding-DraftToken-Analysis

#MLX #AppleSilicon #SpeculativeDecoding This project analyzes the performance and quality trade-offs in speculative decoding using draft tokens and different quantized model configurations. It evaluates:

  • ⚡ Generation speed (tokens/sec)
  • 🔍 Semantic similarity (Accuracy metric) (cosine similarity via sentence embeddings)
  • 📝 Text quality (Accuracy metric) (ROUGE-L score)

▶️ Install the pip package

pip install speculative-decoding-metrics

Customize the Speculative decoding analysis

After installing the package, create a demo script with a default prompt and model:

demo/run_example.py

from speculative_decoding_metrics.main import run_evaluation

run_evaluation(
    base_model="phi-3-mini-4k-instruct",  #Use a model that'll run on your local
    main_quant="8bit",          #use q8 instead of "8bit" based on HuggingFace Repo name 
    draft_quant="4bit",         #use q4 instead of "4bit" based on HuggingFace Repo name
    prompt="Tell me a bedtime story",
    max_tokens=64,              #Tweak max tokens per output
    num_draft_tokens_list=[0, 1, 2, 3, 4]
)


▶️ Run the Demo

python demo/run_example.py

📌 What Is Speculative Decoding?

Speculative decoding speeds up language generation by using a smaller "draft" model to propose tokens, which are then verified by a larger "main" model.

This repo benchmarks speculative decoding using:

  • Main model: Quantized to 8bit → mlx-community/<model>-8bit
  • Draft model: Quantized to 4bit → mlx-community/<model>-4bit

📊 Visualized Metrics

Based on these results, the user can decide which speculative decoding they want to run for the best results! This package generates plots comparing output quality and speed across draft token counts:

  1. Tokens/sec – Speed boost with draft tokens
  2. Cosine Similarity – Semantic match with baseline (no draft)
  3. ROUGE-L – Text overlap quality score

Results Graph


🛠 Customization Tips

  • 🔧 Change the prompt – Modify the prompt in demo/run_example.py
  • 🧠 Try other models – Swap the base_model string (e.g., Mistral, TinyLlama)
  • 🎛️ Adjust draft token range – Modify num_draft_tokens_list for finer control
  • 📏 Set max output length – Use max_tokens to limit generation length

Acknowledgments

  • Apple MLX – Lightweight ML framework
  • HuggingFace – Transformers + SentenceTransformers
  • Google Research – ROUGE scoring tools

Metadata

Release files for speculative-decoding-metrics 0.1.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for speculative-decoding-metrics 0.1.6
File Size Uploaded
speculative_decoding_metrics-0.1.6.tar.gz 4.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for speculative-decoding-metrics 0.1.6
File Interpreter ABI Platform
speculative_decoding_metrics-0.1.6-py3-none-any.whl Python 3 none any Details

Total release size: 11.1 kB

Release files / speculative_decoding_metrics-0.1.6.tar.gz

Download URL speculative_decoding_metrics-0.1.6.tar.gz
Size 4.9 kB
Tags Source
SHA-256 checksum
How to use checksums
504ff0c6c240ca18d98da66bc1376fa1b2bdb830387e5e2aec8f5786c77316bc
BLAKE2b-256 checksum
How to use checksums
5a94230a4192993823b4796dff206ba1808bad21515a4b037a0178b2c4eb93bd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.11

Release files / speculative_decoding_metrics-0.1.6-py3-none-any.whl

Download URL speculative_decoding_metrics-0.1.6-py3-none-any.whl
Size 6.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6c041bf82219492adbd302508c965ebce3cdf3cd4daf4a22a9f3d0e8c971b463
BLAKE2b-256 checksum
How to use checksums
b2bdb70e1e38d2ad1e90a3299cf5daff83bc5c4b8deb5e86784da9966617a74a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.11

Release history Release notifications | RSS feed

This release

0.1.6 This release

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page