A package that evaluates and plots results to test Throughput based on number of draft tokens
Project description
Speculative-Decoding-DraftToken-Analysis
This project analyzes the performance and quality trade-offs in speculative decoding using draft tokens with different model configurations. It compares output speed, semantic similarity, and ROUGE-L scores across varying numbers of draft tokens.
If you've installed using pip,, Run main analysis script (Runs default phi-3-mini-4k-instruct model)
python -m speculative_decoding_metrics.main
If you've installed using pip, You can also specify your preferred model using --model and --prompt
python -m speculative_decoding_metrics.main --model phi-3-mini-4k-instruct --prompt "What are the benefits of AI in education?"
📌 Overview
Speculative decoding is a technique to accelerate language generation by proposing draft tokens before validating them with a larger model. This repo evaluates:
- Throughput (tokens/sec)
- Semantic similarity (cosine similarity via sentence embeddings)
- Text quality (ROUGE-L score)
All experiments are run using:
- Main model: 8-bit quantized (
mlx-community/<model>-8bit) - Draft model: 4-bit quantized (
mlx-community/<model>-4bit)
📊 Visualized Metrics
Three metrics are plotted against the number of draft tokens:
- Tokens per second – Measures generation speed.
- Cosine Similarity – Semantic similarity vs baseline (no draft).
- ROUGE-L – Overlap-based quality score vs baseline.
⚙️ Requirements
- Python 3.8+
- MLX +
mlx_lm - SentenceTransformers
- rouge_score
- Matplotlib
- NumPy
Install dependencies using pip
pip install mlx_lm sentence-transformers rouge-score matplotlib numpy
⚙️ Customization
Tailor the analysis to your specific needs:
- Prompt Modification: Adjust the input prompt within
evaluator.pyby changing theself.prompt_textvariable. - Model Selection: Experiment with different MLX-compatible models by modifying the model names in the scripts.
- Draft Token Range: Alter the range of draft tokens explored in
main.py.
🖼️ Example Output
The script will generate plots showcasing the trade-offs between generation speed and output quality as a function of the number of draft tokens used. These visualizations provide insights into the optimal number of draft tokens for different use cases.
🙏 Acknowledgments
This work leverages the following open-source projects:
- MLX: Developed by Apple.
- HuggingFace Transformers & SentenceTransformers: Provided by Hugging Face.
- ROUGE Scoring: Developed by Google Research.
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.2.tar.gz.
File metadata
- Download URL: speculative_decoding_metrics-0.1.2.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
619ec227ecc2a3b5b03221d9dd5406aa87a1ac89910935fd4bc1e1d59998ddf0
|
|
| MD5 |
aaa100fd254b0da72f73553ae61a8440
|
|
| BLAKE2b-256 |
4323aacfbd3f354d16d535e5889ecb4ce408a6805f9d6123f69298c2780a74cd
|
File details
Details for the file speculative_decoding_metrics-0.1.2-py3-none-any.whl.
File metadata
- Download URL: speculative_decoding_metrics-0.1.2-py3-none-any.whl
- Upload date:
- Size: 6.0 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 |
299de79b317a043d098d50e253c4486b9460ca90a92f8ec452a28d89528ef50b
|
|
| MD5 |
78e13d9e657ec00a76fd04ded8642c2b
|
|
| BLAKE2b-256 |
1b5bf85be05876a1af82a19002d9732e88b97bf449c31bf3d193debf980f8ab3
|