Skip to main content

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:

  1. Tokens per second – Measures generation speed.
  2. Cosine Similarity – Semantic similarity vs baseline (no draft).
  3. ROUGE-L – Overlap-based quality score vs baseline.

alt text

⚙️ 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.py by changing the self.prompt_text variable.
  • 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

speculative_decoding_metrics-0.1.3.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

speculative_decoding_metrics-0.1.3-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file speculative_decoding_metrics-0.1.3.tar.gz.

File metadata

File hashes

Hashes for speculative_decoding_metrics-0.1.3.tar.gz
Algorithm Hash digest
SHA256 b63cf5c1715c223955685a81dd4ae1d0cfacde3af31bab1be508b7bcde7f7b19
MD5 c782ba4d13cae9e56f51534a9f8bca4f
BLAKE2b-256 9a29edb66185faaf238d55ef95795e8934f5589f5c67c69833db5b793df8cd4b

See more details on using hashes here.

File details

Details for the file speculative_decoding_metrics-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for speculative_decoding_metrics-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 b41d3204cc20d45105161da47493d77a2a8b16c7bb96fcbf9d636a73f1b8e2b0
MD5 359855c078dc41a0bfb882158fc57d04
BLAKE2b-256 44f2a868610b87dd41050cedc7a5124565ac6da78a7af0a49d4510d926fff034

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page