xuan-luo/DMTD-Qwen3-4B
Direct Multi-Token Decoding (DMTD) — Qwen3-4B
Notice that this model requires transformers==5.6.2
This repository contains the model for [Direct Multi-Token Decoding](https://arxiv.org/abs/2510.11958).
Direct Multi-Token Decoding (DMTD) reuses the late ("decoding") layers of a decoder-only LLM to directly emit multiple tokens per cycle. DMTD adds no extra parameters, no auxiliary draft model, and no post-generation verification — it just fine-tunes the original network to decode in fixed multi-token cycles, giving up to ~2× inference speedup with minor quality loss.
Importantly, DMTD is complementary to speculative decoding: because a DMTD model can act as its own fast drafter, you can layer speculative decoding on top of DMTD. This repo ships several such self-speculative variants (see Decoding methods).
This checkpoint reuses the last 8 of 36 layers as decoding layers (E0D8) with a decoding cycle length of mtp_horizon = 4.
🏋️ Training code lives on GitHub: [luoxuan-cs/Direct-Multitoken-Decoding](https://github.com/luoxuan-cs/Direct-Multitoken-Decoding) (how to download the dataset, process it, and run SFT).
Decoding methods
We implement several decoding methods on top of the same DMTD checkpoint. Each has a self-contained benchmark script that runs a think-mode math prompt and reports decoding-stage throughput. Because DMTD is compatible with speculative decoding, most variants are self-speculative (the DMTD model drafts and verifies itself, so the greedy output is lossless w.r.t. the full DMTD model). We don't cover the algorithmic details here — see the scripts and the paper.
- Vanilla (
generation_vanilla.py) — standard one-token-at-a-time Qwen3 baseline. - DMTD (
generation.py) — core direct multi-token decoding with cyclical refilling. - DMTD + speculative decoding (
generation_sd.py) — linear self-speculative drafting + one-shot verification. - DMTD + tree speculative decoding (
generation_tree_sd.py) — builds a tree of candidates verified in a single forward. - DMTD + Medusa-style tree speculative decoding (
generation_medusa_style.py) — per-step top-k act as Medusa "heads" assembled into a sparse tree.
Example invocations:
python generation_vanilla.py --max-new-tokens 256
python generation.py --max-new-tokens 256
python generation_sd.py --num-speculations 3 --max-new-tokens 256
python generation_tree_sd.py --branches 2,2,2 --max-new-tokens 256
python generation_medusa_style.py --topk 10 --max-new-tokens 256Common flags: --max-new-tokens, --seed, --attn {sdpa,eager}, --dtype {bfloat16,float16,float32}, --prompt "...". Method-specific knobs: --num-speculations k (linear SD), --branches b0,b1,b2 (tree SD), --topk (Medusa-style). Speculative scripts also accept --check-lossless.
The DMTD inference models build explicit 4D attention masks — run them with--attn sdpaor--attn eager(notflash_attention_2).
Citation
@article{luo2025dmtd,
title = {Direct Multi-Token Decoding},
author = {Luo, Xuan and Wang, Weizhi and Yan, Xifeng},
journal = {arXiv preprint arXiv:2510.11958},
year = {2025},
url = {https://arxiv.org/abs/2510.11958}
}Trained on a-m-team/AM-Thinking-v1-Distilled (arXiv:2505.14464). Please also cite the dataset if you use it. The dataset is released for research purposes only.
Training code: luoxuan-cs/Direct-Multitoken-Decoding
