A package that evaluates and plots results to test Throughput based on number of draft tokens
Project description
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",
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:
- Tokens/sec – Speed boost with draft tokens
- Cosine Similarity – Semantic match with baseline (no draft)
- ROUGE-L – Text overlap quality score
🛠 Customization Tips
- 🔧 Change the prompt – Modify the
promptindemo/run_example.py - 🧠 Try other models – Swap the
base_modelstring (e.g., Mistral, TinyLlama) - 🎛️ Adjust draft token range – Modify
num_draft_tokens_listfor finer control
Acknowledgments
- Apple MLX – Lightweight ML framework
- HuggingFace – Transformers + SentenceTransformers
- Google Research – ROUGE scoring tools
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file speculative_decoding_metrics-0.1.5.tar.gz.
File metadata
- Download URL: speculative_decoding_metrics-0.1.5.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
453f94728d944176580f065c7a8491f99c6af933ffaf1bbc4c5d89b18670d169
|
|
| MD5 |
66f8668b3c0a9d7628a6274b3d77b97f
|
|
| BLAKE2b-256 |
8613b27652bada27239640de8cc247fe5185b1586eabed9266d2544fb82a1ee1
|
File details
Details for the file speculative_decoding_metrics-0.1.5-py3-none-any.whl.
File metadata
- Download URL: speculative_decoding_metrics-0.1.5-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
86705d91eb7658bfc61e2864214fa65fefc38f6c0c3685cc57db48098e3eeb1d
|
|
| MD5 |
e4e8bf151872a0d6d2259466d2926e2d
|
|
| BLAKE2b-256 |
f9998815e12a0c8d151975c1457ce3a9b156fc23aa7adf427f9192918d523ef5
|