DeepSpec is a full-stack codebase for training and evaluating speculative decoding algorithms (DSpark-style and others). It provides dataset utilities, modeling components, training scripts, and evaluation tooling used to develop and benchmark speculative decoding and related heads/algorithms.
Table of Contents
- Key features
- Stack
- Repository layout
- Quickstart — run training and evaluation
- Configuration and examples
- How it fits together
- Datasets and formats
- Extending / Adding models and evaluators
- Maintainers
- PR checklist & contributing notes
- Cite us
- Contributing
- License
- Modular dataset loading and caching (JSONL support, prefetchers).
- Modeling building blocks for speculative decoding heads (confidence, Markov, loss functions).
- Training script and evaluation pipeline for end-to-end experiments.
- Config-driven experiments (per-model/per-dataset config files under
config/).
- Language(s): Python (primary)
- Runtime: CPython (GPU support via PyTorch expected)
- Notable libraries: PyTorch (modeling/training), Hugging Face tokenizers / transformers (likely used in configs), numpy / tqdm for data and utilities.
README.md # (this file)
LICENSE
NOTICE
DSpark_paper.pdf # paper describing DSpark/approach
requirements.txt # Python deps
train.py # training entrypoint
eval.py # evaluation entrypoint
config/ # experiment configs by model / dataset
dspark/
dflash/
eagle3/
deepspec/ # core python package
__init__.py
data/ # dataset loaders, parser, prefetchers
jsonl_dataset.py
parser.py
target_cache_dataset.py
cuda_prefetcher.py
eval/ # evaluators and evaluation utilities
base_evaluator.py
dspark/
evaluator.py
draft_ops.py
confidence_head.py
modeling/ # modeling components, heads, and loss
dspark/
common.py
loss.py
markov_head.py
... (gemma4, qwen3 subpackages)
trainer/ # training orchestration (hooks, loops)
utils/ # misc helpers
scripts/ # utility scripts
eval_datasets/ # dataset-specific evaluation assets
Prerequisites
- Python 3.8+ (virtualenv recommended)
- pip
- (Optional) CUDA-enabled GPU and matching PyTorch
Install dependencies:
git clone https://github.com/chang5-ctrl/DeepSpec.git
cd DeepSpec
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txtRun training (example):
# Example: run a training job using a config under config/dspark
python train.py --config config/dspark/dspark_qwen3_14b.py \
--data_dir /path/to/data \
--output_dir /path/to/output \
--num_epochs 1Run evaluation (example):
python eval.py --config config/dspark/dspark_qwen3_14b.py \
--checkpoint /path/to/output/checkpoint.pt \
--data_dir /path/to/eval_data \
--output /path/to/eval_results.jsonNotes:
- The repository provides
config/files for concrete model/dataset combinations (seeconfig/dspark/*). - Environment variables you may want to set:
- DATA_DIR or --data_dir for dataset root
- OUTPUT_DIR or --output_dir for checkpoints & logs
- HF_HOME if you use Hugging Face cache/custom paths
- Config files under
config/encode dataset, optimizer, model head, and training/eval hyperparameters. - Example configs:
config/dspark/dspark_qwen3_14b.pyconfig/dspark/dspark_gemma4_12b.py- Use these as templates for new experiments and replace dataset and output paths.
- Data flow:
deepspec/data/*parses JSONL-style datasets into PyTorch datasets (seejsonl_dataset.py,target_cache_dataset.py) and provides prefetchers for GPU feeding. - Modeling:
deepspec/modeling/dspark/*contains implementations of loss functions and speculative decoding heads (confidence estimators, Markov heads). - Training:
train.pyorchestrates the training loop and usesdeepspec/trainerutilities (hooks, checkpointing). - Evaluation:
eval.pyusesdeepspec/eval/base_evaluator.pyand thedeepspec/eval/dsparkevaluators to run end-to-end metrics described in the accompanying DSpark paper.
- The codebase expects dataset JSONL files (one example per line) and includes parsing utilities in
deepspec/data/parser.py. jsonl_dataset.pyshows the required fields / expected tokenization step — examine it to prepare custom datasets.
- Add a new model head:
- Create a new module in
deepspec/modeling/<family>/your_head.py - Implement forward(), any loss computation, and register to the config.
- Create a new module in
- Add a new evaluator:
- Extend
deepspec/eval/base_evaluator.BaseEvaluator - Add dataset-specific evaluation code under
deepspec/eval/<family>/
- Extend
- Primary: chang5-ctrl (GitHub user chang5-ctrl)
- For urgent issues, open an issue and tag the maintainers.
Before opening a PR, please:
- Run unit tests (if present) and confirm linting.
- Add or update docs if you change public behavior.
- Keep changes isolated and add a short description in the PR body.
- For experimental changes, open a draft PR for early feedback.
If you use DeepSpec or the DSpark algorithms in your research or product, please cite:
- See
DSpark_paper.pdfin the repository for the formal citation.
BibTeX example:
@inproceedings{DeepSpec2024,
title = {DSpark: Speculative Decoding ...},
author = {Authors},
year = {2024}
}- Issues & PRs welcome — please open issues for bugs or feature requests.
- Follow the existing code style; tests and clear commit messages simplify reviews.
- For substantial changes, open a draft PR and mention maintainers for early feedback.
- Out of memory during training: reduce batch size or sequence length, use gradient accumulation.
- Slow data loading: check
cuda_prefetcher.py, and ensure dataset caching usingtarget_cache_dataset.pyis enabled. - Reproducibility: commit config file and record
requirements.txt/ environment info.
DeepSpec is provided under the terms in the LICENSE file in this repository.