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

#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 8bitmlx-community/<model>-8bit
  • Draft model: Quantized to 4bitmlx-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

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.6.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.6-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for speculative_decoding_metrics-0.1.6.tar.gz
Algorithm Hash digest
SHA256 504ff0c6c240ca18d98da66bc1376fa1b2bdb830387e5e2aec8f5786c77316bc
MD5 9360212f3f878c98dc38f1915eeca76c
BLAKE2b-256 5a94230a4192993823b4796dff206ba1808bad21515a4b037a0178b2c4eb93bd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for speculative_decoding_metrics-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 6c041bf82219492adbd302508c965ebce3cdf3cd4daf4a22a9f3d0e8c971b463
MD5 fb1bcbfe69261d37b51db21212f9eedf
BLAKE2b-256 b2bdb70e1e38d2ad1e90a3299cf5daff83bc5c4b8deb5e86784da9966617a74a

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