File size: 12,974 Bytes
13c5606 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 | <div align="center">
# π DMax: Aggressive Parallel Decoding for dLLMs
<p>
<a href="https://github.com/czg1225/DMax/blob/main/LICENSE">
<img alt="Apache" src="https://img.shields.io/badge/License-Apache-4E94CE.svg">
</a>
<a href="https://arxiv.org/abs/2604.08302">
<img src="https://img.shields.io/badge/Paper-Arxiv-darkred.svg" alt="Paper">
</a>
<a href="https://huggingface.co/collections/Zigeng/dmax-models">
<img src="https://img.shields.io/badge/HuggingFace-Models-FFB000.svg" alt="Project">
</a>
<a href="https://huggingface.co/collections/Zigeng/dmax-training-data">
<img src="https://img.shields.io/badge/HuggingFace-Dataset-FFB000.svg" alt="Project">
</a>
</p>
<p><strong>DMax is a new dLLM paradigm achieving aggressive parallel decoding while preserving generation quality.</strong></p>
</div>
https://github.com/user-attachments/assets/4856fa9e-9dae-41b7-9716-568f36a0f638
> **DMax: Aggressive Parallel Decoding for dLLMs**
> [Zigeng Chen](https://czg1225.github.io/chenzigeng99/), [Gongfan Fang](https://fangggf.github.io/), [Xinyin Ma](https://horseee.github.io/), [Ruonan Yu](https://scholar.google.com/citations?user=UHP95egAAAAJ&hl=en), [Xinchao Wang](https://sites.google.com/site/sitexinchaowang/)
> [xML Lab](https://sites.google.com/view/xml-nus), National University of Singapore \
> Paper [Arxiv](https://arxiv.org/abs/2604.08302)
---
<a id="updates"></a>
## β Updates
- **[May 25, 2026]**: Our latest model, **DMax-16B**, is now available. It is a highly parallel, general-purpose dLLM that delivers superior efficiency across math, code, and general-purpose tasks. To run inference or evaluation, simply set the model path to `Zigeng/DMax-16B`.
- **[April 10, 2026]**: Our Arxiv paper is available now.
- **[April 10, 2026]**: Code, model and dataset are released.
---
<a id="highliths"></a>
## πͺ Highlights
- **Aggressive Decoding Parallelism**: Achieves 6.0 TPF on math and reasoning tasks and 6.6 TPF on code tasks while preserving accuracy.
- **Self-Revising dLLM**: Extends a pretrained MDLM into a UDLM with an intrinsic ability to revise its own erroneous predictions during decoding.
- **Soft Parallel Decoding**: Uses interpolation between mask and token embeddings to propagate confidence priors from previous steps.
<div align="center">
<img src="assets/tradeoff.png" width="93%" />
<br>
<em>Superior Parallelism-Accuracy Trade-off, Increased TPF with Maintained Accuracy.</em>
</div>
---
## π Table of Contents
- [π‘ Introduction](#introduction)
- [π» Model and Datasets](#model-and-datasets)
- [π Quick Start](#quick-start)
- [π§ Installation](#installation)
- [π₯ Training](#training)
- [β‘ Evaluation](#evaluation)
- [π Decoding Process Visualization](#decoding-process-visualization)
- [βοΈ Acknowledgement](#acknowledgement)
- [π Citation](#citations)
---
<a id="introduction"></a>
## π‘ Introduction
We present DMax, a new paradigm for efficient dLLMs. It mitigates error accumulation in parallel decoding, enabling aggressive decoding parallelism while preserving generation quality. Unlike conventional masked dLLMs that decode through a binary mask-to-token transition, DMax reformulates decoding as a progressive self-refinement from mask embeddings to token embeddings. At the core of our approach is On-Policy Uniform Training, a novel training strategy that efficiently unifies masked and uniform dLLMs, equipping the model to recover clean tokens from both masked inputs and its own erroneous predictions. Building on this foundation, we further intoduce Soft Parallel Decoding. Extensive experiments across a variety of benchmarks demonstrate the effectiveness of DMax.
<!--  -->
<div align="center">
<img src="assets/train.png" width="90%" />
<br>
<em>Overview of the On-Policy Uniform Training.</em>
</div>
---
<a id="model-and-datasets"></a>
## π» Model and Datasets
| Model | Description | Source Model | Link |
| --- | --- | --- | --- |
| π€ DMax-16B | Highly parallel general-purpose dLLM. | LLaDA-2.0-mini | [Hugging Face](https://huggingface.co/Zigeng/DMax-16B) |
| π€ DMax-Math-16B | Highly parallel dLLM for math and reasoning. | LLaDA-2.0-mini | [Hugging Face](https://huggingface.co/Zigeng/DMax-Math-16B) |
| π€ DMax-Coder-16B | Highly parallel dLLM for code generation. | LLaDA-2.0-mini | [Hugging Face](https://huggingface.co/Zigeng/DMax-Coder-16B) |
| Dataset | Description | Link |
| --- | --- | --- |
| π DMax-Math-Training-Data | Trajectories on math problems generated by LLaDA-2.0-mini | [Hugging Face](https://huggingface.co/datasets/Zigeng/DMax-LLaDA-2.0-Mini-Math-Trajectories) |
| π DMax-Code-Training-Data | Trajectories on code problems generated by LLaDA-2.0-mini | [Hugging Face](https://huggingface.co/datasets/Zigeng/DMax-LLaDA-2.0-Mini-Code-Trajectories) |
---
<a id="quick-start"></a>
## π Quick Start
```python
import torch
from transformers import AutoModelForCausalLM
from transformers import AutoTokenizer
model = AutoModelForCausalLM.from_pretrained(
"Zigeng/DMax-16B", trust_remote_code=True, device_map="cuda:0"
)
model = model.to(torch.bfloat16)
model.eval()
tokenizer = AutoTokenizer.from_pretrained("Zigeng/DMax-16B", trust_remote_code=True)
prompt = "A robe takes 2 bolts of blue fiber and half that much white fiber. How many bolts in total does it take?" + "\nLet's think step by step\n"
input_ids = tokenizer.apply_chat_template(
[{"role": "user", "content": prompt}],
add_generation_prompt=True,
tokenize=True,
return_tensors="pt",
)
nfe, generated_tokens = model.generate_spd(
inputs=input_ids,
gen_length=2048,
block_length=32,
threshold=0.0,
)
generated_answer = tokenizer.decode(
generated_tokens[0],
skip_special_tokens=True,
)
print(generated_answer)
print("nfe:",nfe,"token length",len(generated_tokens[0]))
```
---
<a id="installation"></a>
## π§ Installation
1. Clone the **DMax** reposity
```bash
git clone https://github.com/czg1225/DMax.git --recursive
cd DMax
```
2. Install **dFactory** environment for training:
```bash
cd dFactory
conda create -n dFactory python==3.11
conda activate dFactory
pip install -e VeOmni/
```
3. Install **dInfer** environment for efficient evaluation:
```bash
cd dInfer
conda create -n dInfer python==3.11
conda activate dInfer
pip install .
pip install sglang==0.5.3.post1
pip install vllm==0.10.2
```
---
<a id="training"></a>
## π₯ Training
Our training scripts is based on the dFactory reposity.
```bash
cd dFactory
```
### 1. Download and Merge Model Weights
The training scripts require model weights in a "merged-expert" format for optimal performance. Before starting, you must download the standard weights and convert them.
**Download the original model:** Follow the helper script to download the weights from the Hugging Face Hub.
```bash
# Choose a destination for the original model files
python scripts/download_hf_model.py \
--repo_id inclusionAI/LLaDA2.0-mini \
--local_dir /path/to/separate_expert_model
```
**Convert to the merged format:** Run the following script to create the merged checkpoint required for training.
```bash
# Use the path from the previous step as the source
python scripts/moe_convertor.py \
--input-path /path/to/separate_expert_model \
--output-path /path/to/save/merged_model \
--mode merge
```
### 2. Prepare Training Data
Before training, the dataset must be converted into the conversational format expected by our training pipeline. The script below transforms the original `"question"` and `"answer"` fields into a `"messages"` field. Run the following command to perform the conversion.
```bash
#prepare the math and reasoning training data
python scripts/build_dataset_oput.py --dataset_path Zigeng/DMax-LLaDA-2.0-Mini-Math-Trajectories
# or prepare the code training data
python scripts/build_dataset_oput.py --dataset_path Zigeng/DMax-LLaDA-2.0-Mini-Code-Trajectories
```
### 3. Modify Training Configs
Edit `configs/sft/llada2_mini_bd_oput.yaml`:
```yaml
model:
model_path: "/path/to/save/merged_model"
data:
train_path: "/your/data/path"
train:
output_dir: "/your/output/path"
```
### 4. Run Training
Once all preparation steps are finished, you can launch the fine-tuning process with the following command.
The default configuration uses distributed training across 8 GPUs.
```bash
PYTHONPATH=$(pwd)/VeOmni:$PYTHONPATH sh train.sh tasks/train_llada2_bd_oput.py configs/sft/llada2_mini_bd_oput.yaml
```
### 5. Interact with the Trained Model
To interact with a trained model, complete the following two steps:
#### Step 1: Convert the Checkpoint
First, convert the checkpoint from the merged format used during training back to the standard Mixture-of-Experts (MoE) format.
> **Note:** the `--input-path` should point to the saved Hugging Face checkpoint, **not** the root output directory specified during training. The checkpoint is typically located in a subdirectory such as:
`TRAIN_OUTPUT_DIR/checkpoints/global_step_XXX/hf_ckpt/`
Run the following command to perform the conversion:
```bash
python scripts/moe_convertor.py \
--input-path /path/to/merged_model \
--output-path /path/to/save/separate_expert_model \
--mode split
```
**Step 2: Copy the Modeling File**
After the conversion, a final manual step is required. You must copy the DMax model's architecture file (`modeling_llada2_moe.py` and `configuration_llada2_moe`) into the newly created separate_expert_model directory. This file must come from the directory of your local saved DMax model. The training and conversion processes only update the model weights, not the architecture file, which is why the DMax version is needed.
```bash
cp /path/to/local_saved_DMax_model/modeling_llada2_moe.py /path/to/save/separate_expert_model/
cp /path/to/local_saved_DMax_model/configuration_llada2_moe.py /path/to/save/separate_expert_model/
```
With the model converted and the modeling file in place, you are now ready to chat!
---
<a id="evaluation"></a>
## β‘ Evaluation
Our training scripts is based on the dInfer reposity.
```bash
cd dInfer/evaluations
```
Download the DMax model: Follow the helper script to download the weights from the Hugging Face Hub.
```bash
# Choose a destination for the original model files
python download_hf_model.py \
--repo_id Zigeng/DMax-16B \
--local_dir /path/to/local_saved_model
```
### 1. Evaluation on Math & Reasoning Benchmarks
We provide evaluation scripts for several math and reasoning benchmarks. Run the following command to launch the evaluation. You may modify the inference settings in `eval_llada_dmax_math.sh` as needed. Before running the script, please set `model_path` to the path of your locally saved model.
The current evaluation suite supports four benchmarks:
- β
`GSM8K`
- β
`MATH500`
- β
`Minerva_Algebra`
- β
`ASDIV`
```bash
bash eval_llada_dmax_math.sh
```
After generation, run the following scripts to extract answers from the generated responses and evaluate accuracy against the ground-truth labels.
```bash
python val_gsm8k.py # postprocess and calculate accuracy on GSM8K
python val_math.py # postprocess and calculate accuracy on MATH500
python val_algebra.py # postprocess and calculate accuracy on Minerva_Algebra
python val_asdiv.py # postprocess and calculate accuracy on ASDIV
```
### 2. Evaluation on Code Benchmarks
We also provide evaluation scripts for code generation benchmarks. Run the following command to start the evaluation. You may modify the inference settings in `eval_llada_dmax_code.sh` as needed. Before running the script, please set `model_path` to the path of your locally saved model.
The current evaluation suite supports the following four benchmarks:
- β
`HumanEval_Instruct`
- β
`MBPP_Instruct`
- β
`HumanEval_Instruct_Plus`
- β
`MBPP_Instruct_Plus`
```bash
bash eval_llada_dmax_code.sh
```
---
<a id="decoding-process-visualization"></a>
## π Decoding Process Visualization
We provide a script for visualizing the full decoding process. Run `demo.py` to generate an HTML file named `dllm_demo.html`.Then open this file in Chrome to view the decoding visualization.
```bash
python demo.py
```

---
<a id="acknowledgement"></a>
## βοΈ Acknowledgement
Our code builds on [dFactory](https://github.com/inclusionAI/dFactory), [dInfer](https://github.com/inclusionAI/dInfer), and we acknowledge these great works for laying the groundwork that made our approach possible.
---
<a id="citations"></a>
## π Citation
If our research assists your work, please give us a star β or cite us using:
```
@article{chen2026dmax,
title={DMax: Aggressive Parallel Decoding for dLLMs},
author={Chen, Zigeng and Fang, Gongfan and Ma, Xinyin and Yu, Ruonan and Wang, Xinchao},
journal={arXiv preprint arXiv:2604.08302},
year={2026}
}
``` |