Self-Decomposing Diffusion for Code Generation
Organizations: University of Virginia
Abstract
Diffusion language models (DLMs) are emerging as a promising paradigm for code generation, offering the potential for fast, parallel decoding. However, generating complex programs remains challenging, as their interdependent components must maintain consistent interfaces, data flows, and shared assumptions. Aggressive parallel decoding can compromise these dependencies and undermine program correctness, while conservative decoding sacrifices efficiency. To address this trade-off, we propose planning program decomposition before implementation to coordinate interdependent units during parallel generation. We introduce Self-Decomposing Diffusion for Code (SDDC), a novel framework that decomposes complex programs and implements their units in parallel, entirely through diffusion. SDDC first generates a contract specifying the program's decomposition and inter-unit dependencies, then uses it to guide coordinated parallel implementation. Across five benchmarks and two 7B diffusion backbones, SDDC substantially improves the accuracy--latency trade-off, raising pass@1 by up to 31.1 percentage points while decoding 7.5--13.7 faster than the base models, and outperforming a fine-tuning baseline by up to 23.5 points with lower latency.
Figures & tables
| KodCode (held-out) | ClassEval | ClassEval-Pro | |||||||||
| pass@1 | pass@5 | pass@1 | pass@5 | ||||||||
| Model | Method | pass@1 | pass@5 | Class | Test | Class | Test | Class | Test | Class | Test |
| Dream-Coder 7B | Vanilla | 12.5 | 6.7 | 9.0 | 22.6 | 6.0 | 23.2 | 3.3 | 4.7 | 4.0 | 6.8 |
| 61.9 | 308.0 | 61.3 | 61.3 | 306.9 | 306.9 | 123.6 | 123.6 | 619.7 | 619.7 | ||
| Diffusion SFT | 15.0 (+2.5) | 18.3 (+11.6) | 7.0 ( 2.0) | 42.3 (+19.7) | 8.0 (+2.0) | 48.3 (+25.1) | 1.3 ( 2.0) | 19.6 (+14.9) | 3.0 ( 1.0) | 32.0 (+25.2) | |
| 9.7 (6.4 ) | 51.3 (6.0 ) | 10.4 (5.9 ) | 10.4 (5.9 ) | 55.5 (5.5 ) | 55.5 (5.5 ) | 42.8 (2.9 ) | 42.8 (2.9 ) | 220.8 (2.8 ) | 220.8 (2.8 ) | ||
| HumanEval Pro | MBPP Pro | ||||
|---|---|---|---|---|---|
| Model | Method | pass@1 | pass@5 | pass@1 | pass@5 |
| Dream- Coder 7B | Vanilla | 40.2 | 19.5 | 51.9 | 33.9 |
| 39.4 | 197.3 | 34.7 | 173.4 | ||
| Diffusion SFT | 26.8 ( 13.4) | 31.7 (+12.2) | 36.0 ( 15.9) | 38.9 (+5.0) | |
| 4.2 (9.4 ) | 21.7 (9.1 ) | 2.3 (14.9 ) | 12.2 (14.2 ) | ||
| SDDC (Ours) | 44.5 (+4.3) | 42.1 (+22.6) | 52.6 (+0.7) | 56.1 (+22.2) | |
| Attention | Binding | pass@1 | Misbound | Overrun |
|---|---|---|---|---|
| isolated | 4.2 | 32.3 | 10.1 | |
| coupled | 11.2 | 11.0 | 4.9 | |
| isolated | ✓ | 13.3 | 0.1 | 1.0 |
| coupled | ✓ | 14.2 | 0.0 | 0.9 |
Appendix figures & tables4 assets
Supplementary material from the paper’s appendix.
Appendix
| Optimizer | paged 8-bit AdamW |
|---|---|
| Learning rate | |
| Schedule | cosine, 3% warm-up |
| Effective batch size | 32 |
| Epochs (steps) | 6 (8,520) |
| Sequence length | 2,048 tokens |
| Precision | bf16 |
| HumanEval Pro | MBPP Pro | |||
| Decoding | Dream-Coder | DiffuCoder | Dream-Coder | DiffuCoder |
| Threshold 0.8 | 26.8 | 14.0 | 36.0 | 31.5 |
| 4.2 | 5.5 | 2.3 | 2.8 | |
| Threshold 0.9 | 31.1 | 15.2 | 40.2 | 33.3 |
| 6.6 | 9.2 | 3.7 | 4.6 | |
| Threshold 0.95 | 30.5 | 14.6 | 40.5 | 33.9 |
| Dream-Coder | DiffuCoder | |||
|---|---|---|---|---|
| Contract | pass@1 | Lat. | pass@1 | Lat. |
| Default | 25.8 | 12.46 | 22.1 | 12.37 |
| End-after-entry | 22.9 | 9.81 | 21.7 | 9.55 |
| Pad-scan | 21.7 | 8.56 | 22.5 | 8.90 |
| Left-to-right | 22.1 | 9.07 | 19.6 | 8.92 |
| Dream-Coder 7B | DiffuCoder 7B | |||
|---|---|---|---|---|
| pass@1 | Iter. | pass@1 | Iter. | |
| single | 22.4 | 137 | 20.0 | 143 |
| 0.99 | 24.8 | 56 | 20.5 | 64 |
| 0.95 | 19.5 | 33 | 18.6 | 39 |
| 0.90 | 17.1 | 25 | 15.2 | 28 |
| 0.80 | 10.5 | 17 | 9.5 | 20 |
Code Generation
Code generation studies methods for turning natural-language, visual, or formal specifications into executable programs and code edits.
See all 313 papers