Skip to main content

Speculative Decoder

Project description

SpecDec: A Speculative Decoding Benchmarking Tool

Overview

SpecDec is a Python-based command-line tool designed for benchmarking the performance of speculative decoding against conventional autoregressive generation. Speculative decoding is an optimization technique that utilizes a smaller, faster model to generate draft tokens, which are then verified by a larger, more powerful model. This can result in significant latency improvements for text generation tasks.

This tool provides a standardized interface for evaluating the speedup achieved with different model configurations and hyperparameters.

Installation

To install the latest stable version from the Python Package Index (PyPI):

pip install specdec

Usage

The specdec command-line tool is the primary entry point for running benchmarks.

Command Structure

specdec --num_sample_tok <value> [OPTIONS]

Example

Here is an example of how to run a benchmark using gpt2 as the small model and gpt2-xl as the large model:

specdec \
    --small_model "gpt2" \
    --big_model "gpt2-xl" \
    --prompt "Quantum computing is a field that" \
    --max_new_tok 100 \
    --num_sample_tok 5 \
    --device "cuda" \
    --seed 42

The tool will output the time taken for both autoregressive and speculative generation, the generated text from both methods, and the calculated speedup.

Command-Line Arguments

The following arguments are available to configure the benchmark:

Argument Type Required Default Description
--small_model string No "gpt2" The identifier for the smaller draft model from Hugging Face.
--big_model string No "gpt2-xl" The identifier for the larger verification model.
--prompt string No "Artificial intelligence is" The input prompt for text generation.
--max_new_tok integer No 50 The maximum number of new tokens to generate.
--num_sample_tok integer Yes - The number of tokens to sample from the small model at each step.
--device string No "cuda" The device to run the models on ("cuda" or "cpu").
--[no-]sample flag No True Toggles sampling for the autoregressive generation baseline.
--seed integer No None A random seed for ensuring reproducibility.

To view all available options, run:

specdec --help

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

specdec-0.2.0.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

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

specdec-0.2.0-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file specdec-0.2.0.tar.gz.

File metadata

  • Download URL: specdec-0.2.0.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for specdec-0.2.0.tar.gz
Algorithm Hash digest
SHA256 b7e80cd36a548dbe87fdc52cae5f9ca0d37ca5e96ccb997857d9bf13e3a25338
MD5 2def9b8338ef39f96d8cf6b8b12690f8
BLAKE2b-256 aebe0934589a058ac1ebdb231f534b100ec81ebfb006af8ed54892a8def1d73a

See more details on using hashes here.

File details

Details for the file specdec-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: specdec-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for specdec-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cfe701a49ee730d3debb9440fa5c20d81b4d3b177a079d069dfe7c9fd6861110
MD5 5a2a4315e1183960f9caf126cb4feb21
BLAKE2b-256 05ccc498ada2d9b094853f17b04c1f4d533bcbdc3c5b79979a1124692f03de11

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