File size: 7,471 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
<div align="center">
      <h2><b> dMoE: dLLMs with Learnable Block Experts </b></h2>
</div>

<div align="center">

![](https://img.shields.io/github/stars/fscdc/dmoe?color=yellow)
![](https://img.shields.io/github/forks/fscdc/dmoe?color=lightblue)
![](https://img.shields.io/github/last-commit/fscdc/dmoe?color=green)
![](https://img.shields.io/badge/PRs-Welcome-blue)
<a href="https://arxiv.org/abs/2605.30876" target="_blank"><img src="https://img.shields.io/badge/arXiv-2605.30876-009688.svg" alt="arXiv"></a>
<a href="https://huggingface.co/FSCCS/dMoE-16B" target="_blank"><img src="https://img.shields.io/badge/πŸ€—%20HuggingFace-dMoE--16B-yellow.svg" alt="HuggingFace"></a>

</div>

https://github.com/user-attachments/assets/fb2fb91d-5d25-4cb1-8d46-2f2fe4248f05

> **[dMoE: dLLMs with Learnable Block Experts](https://arxiv.org/abs/2605.30876)** \
> [Sicheng Feng](https://fscdc.github.io/)<sup>1</sup>, [Zigeng Chen](https://czg1225.github.io/chenzigeng99/)<sup>1</sup>, [Gongfan Fang](https://fangggf.github.io/)<sup>1</sup>, [Xinyin Ma](https://horseee.github.io/)<sup>1</sup>, [Xinchao Wang](https://sites.google.com/site/sitexinchaowang/)<sup>1,*</sup> \
> <sup>1</sup>National University of Singapore, Singapore \
> <sup>βˆ—</sup>Corresponding author: xinchao@nus.edu.sg

---

## ⭐ Updates

- **[4.26.2026]**: Paper, code and model are released. 

---

## πŸ’ͺ Highlights

- **Learnable Block Experts**: Introduces block-level MoE routing into dLLMs, drastically compressing the number of activated unique experts across diffusion steps β€” directly targeting memory footprint reduction.
- **Reduced MoE Bandwidth**: By constraining expert activation at the block level, dMoE significantly reduces memory bandwidth consumed by expert weight loading during the block diffusion process.
- **Improved Efficiency-Accuracy Trade-off**: dMoE achieves competitive performance on reasoning and general benchmarks while reducing unnecessary computation through adaptive expert activation.
- **Plug-and-play on LLaDA-2.0**: Built directly on top of LLaDA-2.0-mini without architectural changes, enabling straightforward extension to other masked dLLMs.

---

## πŸ“š Table of Contents

- [πŸ’‘ Introduction](#-introduction)
- [πŸ’» Model and Datasets](#-model-and-datasets)
- [πŸš€ Quick Start](#-quick-start)
- [πŸ”§ Installation](#-installation)
- [πŸ”₯ Training](#-training)
- [⚑ Evaluation](#-evaluation)
- [β˜€οΈ Acknowledgement](#-acknowledgement)
- [πŸ“– Citation](#-citation)

---

## πŸ’‘ Introduction

We present **dMoE**, a framework that introduces Learnable Block Experts into diffusion large language models (dLLMs).

![Overview](assets/overview.png)

---

## πŸ’» Model and Datasets

| Model | Description | Source Model | Link |
|-------|-------------|--------------|------|
| πŸ€– dMoE-16B | General-purpose dLLM with learnable block experts | LLaDA-2.0-mini | [Hugging Face](https://huggingface.co/FSCCS/dMoE-16B) |

---

## πŸš€ Quick Start

```bash
git clone https://github.com/fscdc/dMoE.git
cd dMoE

# not include all but main libraries
conda create -n dmoe python==3.12
conda activate dmoe
pip install -r ./evaluations/requirements.txt
```

```python
import torch
from transformers import AutoTokenizer
from evaluations.models.modeling_llada2_moe_be_adaptive import LLaDA2MoeModelLM

MODEL_NAME = "FSCCS/dMoE-16B"

device = "cuda:0"

model = LLaDA2MoeModelLM.from_pretrained(
    MODEL_NAME, trust_remote_code=True, torch_dtype=torch.bfloat16
).to(device).eval()

tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME, 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"

messages = [[{"role": "user", "content": prompt}]]
input_text = tokenizer.apply_chat_template(messages, add_generation_prompt=True, tokenize=False)

inputs = tokenizer(input_text, return_tensors="pt", padding_side="left")
input_ids = inputs["input_ids"].to(device)

with torch.no_grad():
    out, unique_experts_count = model.generate(
        input_ids,
        steps=32,
        gen_length=2048,
        block_length=32,
        temperature=0.0,
        eos_early_stop=True,
    )

generated = out[:, input_ids.shape[1]:]
result = tokenizer.batch_decode(generated, skip_special_tokens=True)

print("Output:", result[0])
print("Unique experts count:", unique_experts_count)
```

---

## πŸ”§ Installation

Clone the dMoE repository:

```bash
git clone https://github.com/fscdc/dmoe.git --recursive
cd dmoe
```

Install the **training** environment (based on dFactory):

```bash
cd training
conda create -n dmoe-training python==3.12
conda activate dmoe-training
pip install -e VeOmni/
```

Install the **evaluation** environment:

```bash
cd evaluations
conda create -n dmoe python==3.12
conda activate dmoe
pip install -r requirements.txt
```

---

## πŸ”₯ Training

Our training pipeline is based on [dFactory](https://github.com/inclusionAI/dFactory).

```bash
cd training
```

### 1. Download and Merge Model Weights

Download the base model and convert it to the merged-expert format required for training:

```bash
# Download the original LLaDA-2.0-mini weights
python scripts/download_hf_model.py \
  --repo_id inclusionAI/LLaDA2.0-mini \
  --local_dir /path/to/separate_expert_model

# Convert to merged format for training
python scripts/moe_convertor.py \
  --input-path /path/to/separate_expert_model \
  --output-path /path/to/merged4moe/LLaDA2.0-mini \
  --mode merge
```

### 2. Prepare Training Data

```bash
# gsm8k as an example
python scripts/build_gsm8k_dataset.py
```

### 3. Modify Training Config

Edit `configs/moe/llada2_mini_adaptive.yaml`:

```yaml
model:
  model_path: "/path/to/merged4moe/LLaDA2.0-mini"
  tokenizer_path: "/path/to/merged4moe/LLaDA2.0-mini"
data:
  train_path: "/your/data/path"
train:
  output_dir: "/your/output/path"
```

### 4. Run Training

```bash
PYTHONPATH=$(pwd)/VeOmni:$PYTHONPATH sh train.sh tasks/train_llada2_bd.py configs/moe/llada2_mini_adaptive.yaml
# Or
bash scripts_moe/train_adaptive.sh
```

### 5. Convert the Checkpoint

After training, convert the checkpoint back to the standard MoE format:

```bash
python scripts/moe_convertor.py \
  --input-path ./logs/llada2_mini_dmoe/checkpoints/global_step_XXX/hf_ckpt/ \
  --output-path /path/to/output/llada2_mini_dmoe \
  --mode split
```

---

## ⚑ Evaluation

```bash
cd evaluations
```

### Evaluate dMoE (Adaptive Block Experts)

Set `--model-name` to your local model path in `scripts_moe/run_be_adaptive.sh`, then run:

```bash
bash scripts_moe/run_be_adaptive.sh
```

This evaluates on four benchmarks:
- βœ… GSM8K
- βœ… MATH500
- βœ… MMLU
- βœ… ARC-C

### Evaluate Baseline (Original LLaDA-2.0-mini)

```bash
bash scripts_moe/run_origin.sh
```

---

## β˜€οΈ Acknowledgement

We sincerely thank Huawei for their support and contribution to the research and development of this model and algorithm. Furthermore, our code builds on [dFactory](https://github.com/inclusionAI/dFactory). We acknowledge these great works for laying the groundwork that made our approach possible.

---

## πŸ“– Citation

If our research assists your work, please give us a star ⭐ or cite us using:

```bibtex
@article{feng2026dmoe,
  title={dMoE: dLLMs with Learnable Block Experts},
  author={Feng, Sicheng and Chen, Zigeng and Fang, Gongfan and Ma, Xinyin and Wang, Xinchao},
  journal={arXiv preprint arXiv:2605.30876},
  year={2026}
}
```