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",
    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

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

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for speculative_decoding_metrics-0.1.5.tar.gz
Algorithm Hash digest
SHA256 453f94728d944176580f065c7a8491f99c6af933ffaf1bbc4c5d89b18670d169
MD5 66f8668b3c0a9d7628a6274b3d77b97f
BLAKE2b-256 8613b27652bada27239640de8cc247fe5185b1586eabed9266d2544fb82a1ee1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for speculative_decoding_metrics-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 86705d91eb7658bfc61e2864214fa65fefc38f6c0c3685cc57db48098e3eeb1d
MD5 e4e8bf151872a0d6d2259466d2926e2d
BLAKE2b-256 f9998815e12a0c8d151975c1457ce3a9b156fc23aa7adf427f9192918d523ef5

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