betaFeedback

WorksComputer Science

Self-Decomposing Diffusion for Code Generation

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×\times faster than the base models, and outperforming a fine-tuning baseline by up to 23.5 points with lower latency.

Introduction

Language models are proficient at function-level programming, yet generating complete programs remains difficult: the methods, helper functions, and class headers of a program must be mutually consistent in their identifiers, interfaces, and shared state, and an error in any single unit invalidates the entire program. Models therefore perform far worse on class-level than on function-level benchmarks [1, 2, 3], and the strongest model evaluated on ClassEval-Pro completes fewer than half of its classes [4].

A standard approach to such tasks, analogous to human software development, is to decompose a problem into subproblems and to plan their implementation before writing code. Planning has accordingly been widely adopted for code generation with autoregressive models, which outline solution steps or subfunctions before implementing them [5, 6, 7, 8, 9] or plan dependent edits across a repository [10]. Diffusion language models can commit multiple tokens in a single forward pass [11, 12, 13, 14], yet planning with them remains largely unexplored. Such planning by diffusion language models is especially valuable for code, whose units interact through explicit interfaces. A plan that specifies these interfaces in advance guides the reasoning about decomposition, improves consistency across units, and enables their parallel generation. Current diffusion code models decode programs without such a plan, so committing many tokens at once introduces inconsistencies across units [15, 16].

Recent work combines planning and diffusion with autoregressive decoding to accelerate generation. Building on parallel generation of semantically independent text spans with autoregressive models [17, 18], Planned Diffusion [19] autoregressively generates a plan of chunk topics and lengths, then denoises the planned chunks in parallel, whereas ReFusion [20] selects slots by diffusion and fills them autoregressively. However, these methods are not designed to coordinate interdependent program units, and both retain an autoregressive stage that limits end-to-end parallelism.

We introduce Self-Decomposing Diffusion for Code (SDDC), which aims to improve both accuracy and decoding latency in complex code generation (Figure 2). Our approach combines two complementary ideas: decomposition enables parallel implementation by dividing a program into interacting units, while a contract promotes consistency by specifying these units and the interfaces between them. SDDC first denoises the contract, then implements all units in parallel, binding each unit to its contract entry and coordinating them through cross-unit attention. Both stages are performed entirely by diffusion; to our knowledge, SDDC is the first approach that plans the generation of complex, multi-unit programs with a diffusion model.

Figure 2. Overview of SDDC on a held-out KodCode task (abridged and adapted from the model’s output). (1) Contract synthesis denoises entries that give a budget, an index, a role, and the identifiers that each unit defines (def) and requires (use). (2) Canvas instantiation fixes each entry’s header hkh_k at the start of its canvas. (3) Coupled unit decoding denoises all canvases jointly; they also coordinate a decision that the contract leaves open, nesting both helpers inside sudoku_solver, whose final return the third canvas writes (highlighted). (4) Program assembly removes headers and padding and concatenates the units.

Across five program-level and self-invoking benchmarks and two 7B diffusion backbones, SDDC improves pass@1 over Vanilla by up to 31.1 points while decoding 7.5–13.7× faster (Figure 1), and outperforms the Diffusion SFT baseline by up to 23.5 points. Our contributions are as follows:

Accuracy and latency comparison of Vanilla, Diffusion SFT, and SDDC across program-level benchmarks

Figure 1. SDDC is more accurate and faster. Dream-Coder 7B on the program-level benchmarks of Table 1: (a) pass@1 (test pass rate on ClassEval and ClassEval-Pro); (b) latency per problem and speedup over Vanilla.

  • Self-decomposing diffusion. We formulate complex code generation as diffusion over an explicit program decomposition: a contract specifying program units and their interfaces, which the model learns to generate from static-analysis supervision.

  • Contract-bound coupled decoding. We use the generated contract to guide joint denoising of interdependent program units, enabling parallel implementation while improving accuracy and cross-unit consistency.

  • Improved latency–quality trade-off. SDDC advances the latency–quality frontier of diffusion code generation, and ablations confirm the contribution of each of its components.

Related Work

Planning and decomposition with autoregressive models are well established for complex code generation [5, 7, 8, 21, 10]. This paper focuses on diffusion models for complex code generation.

Diffusion models for code. Code diffusion models have advanced through pretraining and reinforcement learning [13, 14, 22], adaptive infilling and decoding schedules [23, 24], constrained decoding [25, 26, 27, 28], and structural guidance from abstract syntax trees [29] or anchors [30]. These methods generate a program as a single sequence and are evaluated mainly on function-level benchmarks such as HumanEval [31] and MBPP [32], rather than on classes or other complex, multi-unit programs. SDDC instead synthesizes a program-level contract and generates interdependent units concurrently, modeling explicitly the identifiers that connect them.

Planning with diffusion. Recent work has applied planning to diffusion-based generation. Planned Diffusion [19] generates a plan of topics and lengths autoregressively and denoises the planned chunks in parallel, ReFusion [20] selects fixed-length slots by diffusion and fills them autoregressively, and Plan-Verify-Fill [33] decodes verified anchor tokens first; templates and learned policies further shape the generation order [34, 35, 36, 37, 38]. These methods primarily organize generation around text chunks or token positions, without explicitly planning how program components interact. Complex code, however, requires coordinating interdependent units according to program structure and dependencies. SDDC addresses this challenge through a code-specific contract that guides parallel implementation, using diffusion for both planning and generation.

Preliminaries

We study code generation from a natural-language specification cc. The model generates a program x=(x1,…,xL)∈VL\boldsymbol{x} = (x^{1}, \ldots, x^{L}) \in\mathcal{V}^{L} over a vocabulary V\mathcal{V} that contains a padding token [PAD]; a separate token [MASK] ∉V\notin\mathcal{V} marks corrupted positions.

Masked diffusion language models. Masked diffusion language models learn to reconstruct sequences corrupted by an absorbing-state masking process [39, 40, 41]: at noise level t∈[0,1]t \in[0, 1], each token of the program (but not of the specification), is replaced by [MASK] independently with probability tt. A Transformer denoiser pθ(xi∣xt,c)p_{\theta}(x^{i} \mid x_{t}, c) attends bidirectionally over the corrupted sequence xtx_{t} and is trained with the reweighted masked-token cross-entropy [40, 41]

LMDM=Et,xt[1t∑i∈Mt−log⁡pθ(xi∣xt,c)](1)\mathcal{L}_{\mathrm{MDM}} = \mathbb{E}_{t,x_{t}}\left[\frac{1}{t}\sum_{i\in\mathcal{M}_{t}}-\log p_{\theta}(x^{i}\mid x_{t},c)\right] \tag*{(1)}

where t∼U(0,1)t \sim U(0,1) and Mt\mathcal{M}_{t} is the set of masked positions. At inference, the decoder starts from a fully masked canvas, predicts all masked positions in each forward pass, and commits a subset of the predictions, so several tokens can be committed per step and in any order.

Parallel sampling. Let η\eta denote the observed context, comprising the specification and the committed tokens, and let p⋆(⋅∣η)p_{\star}(\cdot\mid\eta) be the target conditional distribution over the masked tokens. Committing a set QQ of masked positions, chosen before their values are sampled, draws the tokens XQ=(Xi)i∈QX^{Q} = (X^{i})_{i\in Q} independently from their marginals. Even with exact marginals, this incurs the error

DKL(p⋆(XQ∣η) ∥ ∏i∈Qp⋆(Xi∣η))=TC⋆(XQ∣η),(2)\begin{aligned} D_{\mathrm{KL}}\left(p_{\star}(X^{Q}\mid\eta)\,\middle\|\,\prod_{i\in Q}p_{\star}(X^{i}\mid\eta)\right) \\ &= \mathrm{TC}_{\star}(X^{Q}\mid\eta), \tag*{(2)} \end{aligned}

the total correlation [42] of the committed tokens, that is, the sum of their marginal entropies minus their joint entropy under p⋆(⋅∣η)p_{\star}(\cdot\mid\eta). It vanishes if and only if the committed tokens are conditionally independent given η\eta, so parallel decoding is accurate only when the tokens committed together are nearly independent given what has been revealed [43].

Motivation

To motivate the design of SDDC, we decompose the error of committing several tokens in parallel. (2) quantifies this error for exact marginals; to extend it to a learned denoiser and a program decomposed into disjoint units, let QQ denote the positions committed in one iteration, selected given the observed context η\eta before sampling, let QkQ_{k} be the nonempty subset of QQ belonging to unit kk, and let pθ,i(⋅∣η)p_{\theta,i}(\cdot\mid\eta) denote the denoiser’s marginal distribution at position ii.

Proposition 1 (Decomposition of parallel-sampling error). If the following divergences are finite, independent sampling from the denoiser marginals satisfies

DKL(p⋆(XQ∣η)∥∏i∈Qpθ,i(Xi∣η))=TC⁡⋆((XQk)k∣η)⏟R1: cross-unit dependence+∑kTC⁡⋆(XQk∣η)⏟R2: within-unit dependence+∑i∈QDKL(p⋆(Xi∣η)∥pθ,i(Xi∣η))⏟R3: marginal approximation error.(3)D_{\mathrm{KL}}\left(p_{\star}(X^{Q}\mid\eta)\mathbin{\Big\|}\prod_{i\in Q}p_{\theta,i}(X^{i}\mid\eta)\right) = \underbrace{\operatorname{TC}_{\star}\left((X^{Q_k})_k\mid\eta\right)}_{\text{R1: cross-unit dependence}} + \underbrace{\sum_k \operatorname{TC}_{\star}(X^{Q_k}\mid\eta)}_{\text{R2: within-unit dependence}} + \underbrace{\sum_{i\in Q}D_{\mathrm{KL}}\left(p_{\star}(X^{i}\mid\eta)\mathbin{\Big\|}p_{\theta,i}(X^{i}\mid\eta)\right)}_{\text{R3: marginal approximation error}}. \tag*{(3)}

The proof is given in Appendix B. Each term is a source of error in parallel code generation, and SDDC mitigates each with a dedicated mechanism:

R1 Cross-unit dependence. Units must coordinate their interactions, yet parallel generation can lead to incompatible decisions across units. A contract that specifies the identifiers each unit defines and requires makes the key cross-unit relationships explicit before implementation.

R2 Within-unit dependence. Confidence-gated commitment restricts additional commitments to high-confidence positions. For exact marginals, each additional position whose most probable token has probability at least γ≥12\gamma\ge\frac{1}{2} adds at most Hb(γ)+(1−γ)log⁡(∣V∣−1)H_b(\gamma) + (1-\gamma)\log(\lvert\mathcal{V}\rvert-1) to an upper bound on this term, where HbH_b is the binary entropy (Appendix B).

R3 Marginal approximation error. Accurate predictions require unit-specific context and information from other units. Contract-bound headers identify the unit being implemented, and coupled attention lets predictions condition on the evolving implementations of other units.

SDDC {#sec:5}

SDDC generates a program in four stages (Figure 2 and Algorithm 1): ① contract synthesis denoises a contract that decomposes the task into program units; ② canvas instantiation allocates one canvas per unit; ③ coupled unit decoding denoises all canvases jointly; and ④ program assembly removes headers and padding and concatenates the units in contract order.

Stage 1: Contract Synthesis {#sec:5.1}

Contract synthesis plans the program before any unit is implemented. We represent a program as a concatenation of KK units, x=x(1)∘⋯∘x(K)x=x^{(1)}\circ\cdots\circ x^{(K)}, each a contiguous region of source code with a structural role, such as a class header with its constructor, a method, or a function. A contract z=(e1,…,eK)z=(e_1,\ldots,e_K) assigns each unit an entry ek=(bk,k,ρk,Dk,Rk)e_k=(b_k,k,\rho_k,D_k,R_k) that comprises a size budget bkb_k in multiples of ν\nu tokens, the unit index, a structural role, the identifiers DkD_k that the unit defines, and the identifiers RkR_k that it reads before binding them. For example, the entry 13 B2 function | def solve | use is_valid,solve in Figure 2 allocates 13 budget units to a function that defines solve and calls is_valid and, recursively, solve. We write ser⁡(z)\operatorname{ser}(z) for the serialized contract and call the serialization hkh_k of eke_k without its budget the header of unit kk.

Nominal interfaces. Identifiers form the interface between units, since a unit can call functions and access attributes defined by other units without observing their implementations. By declaring these identifiers, the contract fixes the decisions on which cross-unit dependence concentrates, which mitigates R1, and leaves all other decisions to the units.

Decoding. The contract is generated on a canvas yy of PP positions that is initialized to [MASK]P[\mathrm{MASK}]^P and appended to the specification. Contract positions attend bidirectionally to one another and to cc, so that every entry can condition on tokens committed in any other entry. At each masked position jj, the decoder selects tokens from the admissible set

Aj(y)={V∖{[PAD]}yj+1≠[PAD]Votherwise(4)\mathcal{A}_j(y)= \begin{cases} \mathcal{V}\setminus\{[\mathrm{PAD}]\} & y^{j+1}\ne[\mathrm{PAD}]\\ \mathcal{V} & \text{otherwise} \end{cases} \tag*{(4)}

with the convention yP+1=[PAD]y^{P+1}=[\mathrm{PAD}]. Padding is thus admissible only at the final position or immediately before committed padding, which keeps the padding a contiguous suffix and prevents premature truncation. In each iteration nn, the decoder proposes the most probable admissible token y^j\hat{y}^{j} at every masked position, with confidence κj\kappa_j equal to its probability, and commits all proposals with κj≥γz\kappa_j\ge\gamma_z, but at least the ⌈∣M(y)∣/(Sz−n+1)⌉\lceil\lvert\mathcal{M}(y)\rvert/(S_z-n+1)\rceil most confident ones,

Algorithm 1 Generation with SDDC. M(⋅)\mathcal{M}(\cdot) denotes the masked positions of a canvas, Top⁡r(κ;M)\operatorname{Top}_r(\kappa; M) the rr positions in MM with the largest confidences κ\kappa, and Π\Pi the token distributions returned by one evaluation of the denoiser DθconD^{\mathrm{con}}_\theta or DθunitD^{\mathrm{unit}}_\theta over the masked contract or unit positions; Az^A_{\hat{z}} removes headers and padding and concatenates the units. Other symbols are defined in Sections 5.1–5.3.

Require: θ\theta, cc; PP, SzS_z, λ∈N>0\lambda\in\mathbb{N}_{>0}; γz\gamma_z, γu∈[0,1]\gamma_u \in[0,1] Ensure: Program xx or failure outcome ⊥\bot

  1. y←[MASK]Py \leftarrow[\mathrm{MASK}]^P; n←0n \leftarrow0 ▷ contract synthesis

  2. while M(y)≠∅∧n<Sz\mathcal{M}(y) \ne\varnothing\land n < S_z do

  3. n←n+1n \leftarrow n+1; M←M(y)M \leftarrow\mathcal{M}(y); Π←Dθcon(y;c)\Pi\leftarrow D^{\mathrm{con}}_\theta(y;c)

  4. y^j←arg⁡max⁡v∈Aj(y)Πj(v)\hat{y}_j \leftarrow\mathop{\arg\max}_{v \in A_j(y)} \Pi_j(v); κj←Πj(y^j)\kappa_j \leftarrow\Pi_j(\hat{y}_j)

  5. r←max⁡(⌈∣M∣Sz−n+1⌉,∣{j∈M:κj≥γz}∣)r \leftarrow\max\left(\left\lceil\frac{|M|}{S_z-n+1}\right\rceil,\left|\{j \in M:\kappa_j \ge\gamma_z\}\right|\right)

  6. yj←y^j(j∈Top⁡r(κ;M))y_j \leftarrow\hat{y}_j\quad(j \in\operatorname{Top}_r(\kappa;M))

  7. z^=(e1,…,eK)←parse⁡(y)\hat{z}=(e_1,\ldots,e_K)\leftarrow\operatorname{parse}(y)

  8. if z^∉Z/λ\hat{z}\notin\mathcal{Z}/\lambda return ⊥\bot ▷ canvas instantiation

  9. w←Φλ(z^); H←Enc⁡θ([c;ser⁡(z^)])w\leftarrow\Phi_\lambda(\hat{z});\ \mathcal{H}\leftarrow\operatorname{Enc}_\theta([c;\operatorname{ser}(\hat{z})])

  10. while ∃k:M(w(k))≠∅\exists k:\mathcal{M}(w^{(k)})\ne\varnothing do ▷ coupled unit decoding

  11. Π←Dθunit(w;H)\Pi\leftarrow D^{\mathrm{unit}}_\theta(w;\mathcal{H})

  12. for all k:Mk=M(w(k))≠∅k:M_k=\mathcal{M}(w^{(k)})\ne\varnothing do ▷ in parallel

  13. ak,j∼Πk,j(j∈Mk)a_{k,j}\sim\Pi_{k,j}\quad(j\in M_k)

  14. jk←arg⁡max⁡j∈MkΠk,j(ak,j)j_k\leftarrow\mathop{\arg\max}_{j\in M_k}\Pi_{k,j}(a_{k,j})

  15. w,jk(k)←ak,jkw^{(k)}_{,j_k}\leftarrow a_{k,j_k}

  16. Uk←{j∈Mk∖{jk}:max⁡vΠk,j(v)≥γu}U_k\leftarrow\{j\in M_k\setminus\{j_k\}:\max_v\Pi_{k,j}(v)\ge\gamma_u\}

  17. w,j(k)←arg⁡max⁡vΠk,j(v)(j∈Uk)w^{(k)}_{,j}\leftarrow\mathop{\arg\max}_v\Pi_{k,j}(v)\quad(j\in U_k)

  18. w(k)←F(w(k))w^{(k)}\leftarrow F(w^{(k)})

  19. return Az^(w)A_{\hat{z}}(w) ▷ program assembly

where M(y)\mathcal{M}(y) denotes the masked positions of yy; this rule bounds synthesis by SzS_z iterations. A parser finally extracts the well-formed entries z^\hat{z}.

Stage 2: Canvas Instantiation

Each entry eke_k receives a canvas of ℓk=λbk\ell_k=\lambda b_k positions, initialized as w0(k)=hk∘[MASK]ℓk−∣hk∣w_0^{(k)}=h_k\circ[\mathrm{MASK}]^{\ell_k-|h_k|}; we write Φλ(z)\Phi_\lambda(z) for the initialized canvases. The header stays fixed during decoding and binds the canvas to its entry (R3), so the denoiser need not infer from position which unit a canvas implements. Budgets specify capacity rather than length: the scale λ≥ν\lambda\ge\nu provides headroom, and unused positions are filled with [PAD][\mathrm{PAD}]. Let Zλ\mathcal{Z}_\lambda be the set of nonempty contracts whose headers fit their canvases, ∣hk∣≤ℓk|h_k|\le\ell_k. For any other parsed contract, generation returns the failure outcome ⊥\bot, which we count as an incorrect program without resampling.

Stage 3: Coupled Unit Decoding

All canvases are denoised in parallel. The context is encoded once as H=Enc⁡θ([c;ser⁡(z)])\mathcal{H}=\operatorname{Enc}_\theta([c;\operatorname{ser}(z)]), and every canvas attends to H\mathcal{H} and to the current state of all canvases, so that units condition on one another’s partial implementations, including decisions that the contract leaves open (R3). In each iteration, every unfinished canvas samples a candidate ak,ja_{k,j} at each of its masked positions and commits the candidate with the highest probability; it also commits every other masked position whose maximum probability is at least γu\gamma_u to its most probable token (R2). The operator FF then fills all masked positions after the first committed [PAD][\mathrm{PAD}] of a canvas with [PAD][\mathrm{PAD}], and a canvas is complete when no masks remain. As an ablation, isolated decoding lets each canvas attend only to H\mathcal{H} and to itself.

SDDC Training

For each training pair (c,x)(c,x), we extract a reference contract z∗z^* from xx and train two views of the example: a contract view for synthesis and a unit view for implementation.

Contract extraction. Decomposition supervision comes from static analysis of reference programs. We segment xx at the definition boundaries of its abstract syntax tree into class headers with their constructors, methods, and top-level functions, attaching module-level statements to adjacent segments. Each segment forms its own unit by default, and adjacent segments are merged by annotation for a curated subset (§ 7.1). Name analysis then yields Dk\mathcal{D}_k and Rk\mathcal{R}_k, the role ρk\rho_k follows from the syntactic category, and the budget bkb_k covers the header and the unit with a small slack, with ν=10\nu= 10 (Appendix § 9.§ 1). The analyzer only constructs training targets: at inference, the model generates the contract from the specification alone.

Contract view. The target is the padded serialization y⋆=ser⁡(z⋆)∘[PAD]P−∣ser⁡(z⋆)∣y^\star= \operatorname{ser}(z^\star) \circ[\mathrm{PAD}]^{P-\lvert\operatorname{ser}(z^\star)\rvert}, which is corrupted as in § 3 while cc remains intact. With bidirectional attention over the contract canvas, the loss is

LCON=E[1t∑j∈Mt−log⁡pθ(yj⋆∣yt,c)],(5)\mathcal{L}_{\mathrm{CON}} = \mathbb{E}\left[\frac{1}{t}\sum_{j\in\mathcal{M}_t} -\log p_\theta(y^\star_j \mid y_t,c)\right], \tag*{(5)}

where the expectation is over t∼U(0,1)t\sim U(0,1) and the corrupted canvas yty_t, and Mt\mathcal{M}_t denotes its masked positions. Supervising the padding teaches the model how many units to create; contracts longer than PP positions are excluded from this view.

Unit view. Each unit forms a canvas target hk∘x(k)∘[PAD]rkh_k\circ x^{(k)}\circ[\mathrm{PAD}]^{r_k} with a padding surplus rkr_k. Because SDDC allocates canvases in proportion to predicted budgets, unused capacity grows with the unit, so we draw each surplus independently from

rk∼12U{0,…,10}r_k \sim\frac{1}{2}U\{0,\ldots,10\}
rk∼ +12U{0,…,max⁡(10,∣x(k)∣)}.(6)\phantom{r_k \sim}\ + \frac{1}{2}U\{0,\ldots,\max(10,\lvert x^{(k)}\rvert)\}. \tag*{(6)}

and concatenate the canvases into ww. Scaling the surplus with the unit length teaches the model to pad unused capacity instead of extending the unit into the next one (R3), which keeps oversized canvases safe at inference. Headers are never masked or supervised, and all other canvas positions are masked independently with probability tt, which yields

LUNIT=E[1t∑j∈Mt−log⁡pθ(wj∣wt,z⋆,c)],(7)\mathcal{L}_{\mathrm{UNIT}} = \mathbb{E}\left[\frac{1}{t}\sum_{j\in\mathcal{M}_t} -\log p_\theta(w^j\mid w_t,z^\star,c)\right], \tag*{(7)}

where the expectation also covers the surpluses rkr_k, and Mt\mathcal{M}_t denotes the masked canvas positions. The context [c;ser⁡(z⋆)][c;\operatorname{ser}(z^\star)] is encoded with causal attention, and canvas positions attend to the context and to one another, or only to themselves in the isolated variant. The causal context also admits an auxiliary next-token loss LCTX\mathcal{L}_{\mathrm{CTX}} on its contract tokens; SDDC does not use it for generation, but it allows the same weights to write contracts left to right (§ 7.3).

Objective. Both views train the same parameters with L=E(c,x)[LCON+LUNIT+LCTX]\mathcal{L}=\mathbb{E}_{(c,x)}[\mathcal{L}_{\mathrm{CON}}+\mathcal{L}_{\mathrm{UNIT}}+\mathcal{L}_{\mathrm{CTX}}]. The unit view conditions on the reference contract during training and on the generated contract at inference.

Experiments

We evaluate the latency–quality trade-off of SDDC (§ 7.2) and analyze how its mechanisms mitigate the error sources identified in § 4 (§ 7.3).

Experimental Setup

Models and training. We fine-tune two open 7B masked diffusion code models, Dream-Coder-v0-Instruct-7B [13] and DiffuCoder-7B-Instruct [14]. The training corpus contains 15,973 problems from KodCode-V1 [44] whose verified solutions define at least three functions or four methods. For 2,770 of these programs, an LLM annotator merged adjacent units following a written guideline; the corpus yields 25.5K unit-view and 25.1K contract-view examples. Each backbone is trained for six epochs, about 13 hours on four GPUs (Appendix A).

Decoding. SDDC uses P=224P = 224, γz=0.95\gamma_z = 0.95, Sz=112S_z = 112, λ=14\lambda= 14, and γu=0.99\gamma_u = 0.99, sampling with temperature 0.2 and top-pp 0.95 (Appendix § 9.§ 3). All decoding hyperparameters are tuned on KodCode; for ClassEval-Pro, whose specifications list up to 27 methods, we enlarge the contract canvas to P=320P = 320.

Benchmarks. We evaluate on five benchmarks in two groups. Program-level composition requires complete programs whose units interact through shared state and calls. KodCode (held-out) contains 240 problems withheld from training and stratified by structure and difficulty, scored by their pytest suites. ClassEval [1] contains 100 hand-written classes whose skeletons specify interdependent methods. ClassEval-Pro [4] contains 300 cross-domain classes specified only in prose, most of which exceed our 2,048-token training length. On both class benchmarks, we report the class pass rate, which requires all tests of a class to pass, and the test pass rate, which credits partially correct classes (Appendix § 9.§ 4). Self-invoking problem solving isolates a single cross-unit dependency: HumanEval Pro and MBPP Pro [45] extend HumanEval [31] and MBPP [32] with 164 and 378 problems in which the solution to a base problem must be invoked to solve a harder one.

Baselines. Vanilla decodes each released backbone over a full canvas with 512 iterations, its most accurate setting on every benchmark. Diffusion SFT fine-tunes the same backbone on exactly the same programs with the same recipe and the standard masked diffusion objective, which isolates the effect of the generation scheme from that of the training data; we report the more accurate of confidence-threshold decoding [43] and 256 iterations on each benchmark. Appendix § 9.§ 3 lists all evaluated configurations.

Metrics. We report pass@1 at temperature 0.2 and pass@5 from five samples at temperature 0.4. Latency is the mean wall-clock time per problem on one NVIDIA RTX PRO 6000 GPU with batch size one, including contract synthesis; for pass@5, it covers all five samples.

Main Results

Program-level composition. Table 1 shows that SDDC is the fastest method on all three program-level benchmarks with both backbones and the most accurate on all but one metric. On KodCode, it attains 24.2 and 23.3 pass@1, compared with 15.0 and 10.8 for Diffusion SFT and 12.5 and 7.9 for the base models, while answering in 7.6 and 5.3 seconds, 8.2× and 11.7× faster than the base models. On ClassEval, it raises the class pass rate to 14.0 and 13.0, from at most 9.0 and 6.0, and passes 48.5% and 47.2% of unit tests, compared with at most 42.3% and 25.6%. The advantage widens on ClassEval-Pro, the most compositional benchmark, where SDDC passes 31.9% and 28.3% of test classes, compared with at most 19.6% and 6.0%. The only exception, the DiffuCoder base model on complete ClassEval-Pro classes (4.0 vs. 3.0), amounts to three of 300 classes at 9.2× the latency. Diffusion SFT on the same programs, in contrast, lowers the class pass rate on both class benchmarks with both backbones, so the gains of SDDC stem from generating programs through contracts rather than from the training data.

Table 1: Program-level composition: pass@1 and pass@5 (%) on KodCode (held-out), ClassEval, and ClassEval-Pro. Class: classes that pass all of their tests; Test: unit tests (ClassEval) or test classes (ClassEval-Pro) passed. Blue rows give the mean latency per problem in seconds and the speedup over Vanilla; pass@5 latency covers five samples. Values next to the scores give the change from Vanilla (green ≥10 points, yellow <10 points, red a decrease). pass@5 samples at temperature 0.4 and pass@1 at 0.2 (Appendix A.4). Vanilla uses 512 iterations and Diffusion SFT threshold decoding (256 iterations for DiffuCoder on KodCode). The best score per backbone is bolded.

ModelMethodKodCode (held-out) pass@1KodCode (held-out) pass@5ClassEval pass@1 ClassClassEval pass@1 TestClassEval pass@5 ClassClassEval pass@5 TestClassEval-Pro pass@1 ClassClassEval-Pro pass@1 TestClassEval-Pro pass@5 ClassClassEval-Pro pass@5 Test
Dream-Coder 7BVanilla12.5<br>61.96.7<br>308.09.0<br>61.322.6<br>61.36.0<br>306.923.2<br>306.93.3<br>123.64.7<br>123.64.0<br>619.76.8<br>619.7
Dream-Coder 7BDiffusion SFT15.0 (+2.5)<br>9.7 (6.4×)18.3 (+11.6)<br>51.3 (6.0×)7.0 (−2.0)<br>10.4 (5.9×)42.3 (+19.7)<br>10.4 (5.9×)8.0 (+2.0)<br>55.5 (5.5×)48.3 (+25.1)<br>55.5 (5.5×)1.3 (−2.0)<br>42.8 (2.9×)19.6 (+14.9)<br>42.8 (2.9×)3.0 (−1.0)<br>220.8 (2.8×)32.0 (+25.2)<br>220.8 (2.8×)
Dream-Coder 7BSDDC (Ours)24.2 (+11.7)<br>7.6 (8.2×)31.2 (+24.5)<br>36.9 (8.3×)14.0 (+5.0)<br>7.9 (7.8×)48.5 (+25.9)<br>7.9 (7.8×)18.0 (+12.0)<br>39.5 (7.8×)63.2 (+40.0)<br>39.5 (7.8×)3.7 (+0.4)<br>16.5 (7.5×)31.9 (+27.2)<br>16.5 (7.5×)4.3 (+0.3)<br>81.0 (7.7×)46.1 (+39.3)<br>81.0 (7.7×)
DiffuCoder 7BVanilla7.9<br>61.88.8<br>308.16.0<br>61.516.1<br>61.53.0<br>307.017.0<br>307.04.0<br>124.16.0<br>124.14.0<br>620.29.2<br>620.2
DiffuCoder 7BDiffusion SFT10.8 (+2.9)<br>30.7 (2.0×)13.3 (+4.5)<br>153.5 (2.0×)4.0 (−2.0)<br>13.4 (4.6×)25.6 (+9.5)<br>13.4 (4.6×)4.0 (+1.0)<br>69.9 (4.4×)27.1 (+10.1)<br>69.9 (4.4×)0.0 (−4.0)<br>32.1 (3.9×)4.8 (−1.2)<br>32.1 (3.9×)0.0 (−4.0)<br>165.9 (3.7×)5.1 (−4.1)<br>165.9 (3.7×)
DiffuCoder 7BSDDC (Ours)23.3 (+15.4)<br>5.3 (11.7×)24.2 (+15.4)<br>23.6 (13.1×)13.0 (+7.0)<br>4.5 (13.7×)47.2 (+31.1)<br>4.5 (13.7×)20.0 (+17.0)<br>22.1 (13.9×)64.0 (+47.0)<br>22.1 (13.9×)3.0 (−1.0)<br>13.5 (9.2×)28.3 (+22.3)<br>13.5 (9.2×)4.7 (+0.7)<br>62.4 (9.9×)42.7 (+33.5)<br>62.4 (9.9×)

Table 1.

Self-invoking problem solving. SDDC also attains the highest pass@1 on HumanEval Pro and MBPP Pro with both backbones (Table 2). The base models approach this accuracy only with 512 iterations, at 35–40 seconds per problem; SDDC exceeds them by up to 9.8 points while running 7.7–12.4× faster. Diffusion SFT trails the base models by 11.0–16.6 points; even with 512 iterations, it surpasses SDDC only on MBPP Pro with Dream-Coder (54.2 vs. 52.6), at about eight times the latency (Table 5). Since each problem couples a base function with a function that must invoke it, these results indicate that the dependency declared in the contract is honored even though the two units are generated in parallel.

Table 2: Self-invoking problem solving (pass@1 and pass@5, %), formatted as in Table 1. Blue rows give the mean latency per problem in seconds and the speedup over Vanilla. Values next to the scores give the change from Vanilla (green ≥10 points, yellow <10 points, red a decrease). Diffusion SFT uses threshold decoding (256 iterations for DiffuCoder on HumanEval Pro); Table 5 adds further configurations.

ModelMethodHumanEval Pro pass@1HumanEval Pro pass@5MBPP Pro pass@1MBPP Pro pass@5
Dream-Coder 7BVanilla40.2<br>39.419.5<br>197.351.9<br>34.733.9<br>173.4
Dream-Coder 7BDiffusion SFT26.8 (−13.4)<br>4.2 (9.4×)31.7 (+12.2)<br>21.7 (9.1×)36.0 (−15.9)<br>2.3 (14.9×)38.9 (+5.0)<br>12.2 (14.2×)
Dream-Coder 7BSDDC (Ours)44.5 (+4.3)<br>5.1 (7.7×)42.1 (+22.6)<br>25.6 (7.7×)52.6 (+0.7)<br>4.4 (8.0×)56.1 (+22.2)<br>21.6 (8.0×)
DiffuCoder 7BVanilla31.1<br>39.528.0<br>197.548.1<br>34.742.1<br>173.5
DiffuCoder 7BDiffusion SFT20.1 (−11.0)<br>19.7 (2.0×)17.7 (−10.3)<br>98.8 (2.0×)31.5 (−16.6)<br>2.8 (12.6×)36.2 (−5.9)<br>14.1 (12.3×)
DiffuCoder 7BSDDC (Ours)40.9 (+9.8)<br>3.2 (12.4×)51.2 (+23.2)<br>15.0 (13.1×)49.7 (+1.6)<br>3.2 (10.8×)54.0 (+11.9)<br>15.6 (11.1×)

Table 2.

DecodingHumanEval Pro Dream-CoderHumanEval Pro DiffuCoderMBPP Pro Dream-CoderMBPP Pro DiffuCoder
Threshold 0.826.814.036.031.5
4.24.25.55.52.32.32.82.8
Threshold 0.931.115.240.233.3
6.66.69.29.23.73.74.64.6
Threshold 0.9530.514.640.533.9
9.09.012.712.75.45.46.56.5
256 iterations15.220.124.628.0
19.819.819.719.717.317.317.317.3
512 iterations33.537.254.249.5
39.539.539.539.534.734.734.734.7
Vanilla40.231.151.948.1
39.439.439.539.534.734.734.734.7
SDDC44.540.952.649.7
5.15.13.23.24.44.43.23.2

Table 5. Diffusion SFT under different decoding configurations on HumanEval Pro and MBPP Pro: pass@1 (%), with the mean latency per problem in seconds in the blue row below. Vanilla (512 iterations) and SDDC are shown for reference; the most accurate entry of each column is bolded.

Sampling multiple programs. With five samples, SDDC is the most accurate method in every pass@5 column of Table 1 and Table 2; on ClassEval, it passes 63.2% and 64.0% of unit tests, compared with at most 48.3% and 27.1%.

Latency–quality frontier. On KodCode (Figure 3), the default configuration of SDDC dominates every evaluated baseline configuration on both backbones: none is both faster and more accurate. The advantage originates in parallel unit decoding: because each iteration advances all units at once, SDDC completes the units of a KodCode program in 54 (Dream-Coder) and 61 (DiffuCoder) iterations on average, whereas the text-generation baselines decode a canvas of about 1.5K positions for up to 512 iterations.

Latency–quality trade-off on KodCode

Figure 3. Latency–quality trade-off on KodCode (held-out). Each point is one decoding configuration, labeled with its number of iterations; the upper left is better. On both backbones, the default configuration of SDDC (star) dominates every baseline configuration, and its variants with other contract schedules and single commitment (circles) lie above all of them. Threshold decoding of the Dream-Coder base model (0.8 pass@1, not timed) is omitted.

Analysis

Diffused versus left-to-right contracts. To isolate the benefit of diffusion-based planning, we let the same weights write the contract left to right, as in Planned Diffusion [19] (Table 6). Diffused contracts raise KodCode pass@1 from 22.1 to 25.8 on Dream-Coder and from 19.6 to 21.7 on DiffuCoder; they are also finer grained, with 6.7 instead of 5.3 entries on average, and all 240 of them parse. Diffusion thus yields better decompositions, which supports using it for both planning and implementation.

ContractDream-Coder pass@1Dream-Coder Lat.DiffuCoder pass@1DiffuCoder Lat.
Default25.812.4622.112.37
End-after-entry22.99.8121.79.55
Pad-scan21.78.5622.58.90
Left-to-right22.19.0719.68.92

Table 6. Contract schedules on KodCode (held-out) with single commitment per canvas: pass@1 (%) and latency (s).

Binding and coupled attention. Table 3 varies the two mechanisms that inform each canvas’s predictions (R3). Without binding, a canvas is tied to its entry only by position, as in Planned Diffusion, and under isolated attention 32.3% of canvases begin with a sibling’s definition. Binding nearly eliminates misbinding and overruns and triples pass@1 under isolated attention (4.2 to 13.3) at unchanged latency. Coupled attention partly compensates for missing binding and adds 0.9 points on top of it.

Table 3: Binding (headers and length-scaled padding) and coupled attention on KodCode (curated subset, left-to-right contracts, λ = 10; held-out). Misbound: canvases whose first definition belongs to another entry; Overrun: canvases that continue into the next unit (%).

AttentionBindingpass@1MisboundOverrun
isolated4.232.310.1
coupled11.211.04.9
isolated✓13.30.11.0
coupled✓14.20.00.9

Table 3.

Commitment threshold. Relative to single commitment, γu=0.99\gamma_{u} = 0.99 reduces unit-decoding iterations by 2.2–2.4× and end-to-end latency on held-out KodCode by 1.65× and 1.82×, with accuracy changes within noise (25.8 to 24.2 and 21.7 to 23.3; sign test p≥0.52p \ge0.52). Lower thresholds collapse, as R2 predicts: at γu=0.7\gamma_{u} = 0.7, pass@1 falls below 5%, and the share of syntactically valid programs on Dream-Coder drops from 96.7% to 40.0% (Table 7). Appendix C reports further ablations.

γu\gamma_uDream-Coder 7B pass@1Dream-Coder 7B Iter.DiffuCoder 7B pass@1DiffuCoder 7B Iter.
single22.413720.0143
0.9924.85620.564
0.9519.53318.639
0.9017.12515.228
0.8010.5179.520
0.704.8143.816

Table 7. Commitment threshold γu\gamma_u on the KodCode validation split: pass@1 (%) and mean unit-decoding iterations (Iter.); “single” commits one token per canvas per iteration.

Conclusion

We presented Self-Decomposing Diffusion for Code (SDDC), a fully diffusion-based framework that integrates program decomposition and parallel implementation into a unified generative process. By explicitly modeling program structure and inter-unit dependencies through a generated contract, SDDC enables coordinated parallel decoding while improving program correctness and substantially reducing latency. Our results across diverse benchmarks and diffusion backbones demonstrate that planning and parallelism can be complementary rather than competing objectives. More broadly, this work suggests that realizing the potential of diffusion models for complex code generation requires not only faster token generation, but also explicit mechanisms for organizing and coordinating interdependent decisions. Future work could extend contract-guided diffusion to repository-scale generation and explore adaptive decomposition guided by execution feedback.

Limitations

Our experiments use two open 7B diffusion code models. Diffusion models still trail frontier autoregressive models, more capable diffusion systems such as Gemini Diffusion [46], Mercury 2.5 [47], and Seed Diffusion Preview [48] do not release their weights, and larger open diffusion models for code remain scarce; we expect stronger backbones to benefit SDDC, but we have not verified this. Contracts capture nominal interfaces, namely the identifiers that units define and require, but not types or behavioral specifications, and our supervision relies on static analysis of Python programs, so other languages and richer interfaces require corresponding analyzers. Finally, contract synthesis adds a sequential stage before unit decoding. This overhead is more than offset by parallel unit decoding, but it accounts for 4.5 of the 7.6 seconds per KodCode problem with Dream-Coder, so faster contract decoding would reduce latency further.

Ethical Considerations

SDDC improves both accuracy and the efficiency of diffusion-based code generation, but it inherits the potential risks of automated code generation, including producing insecure or incorrect code and facilitating the development of harmful software. Generated programs should therefore be reviewed and tested before deployment, particularly in security-sensitive settings. Although faster decoding may reduce inference costs, training and deploying these models still consume computational resources and energy.

Implementation Details

Training Data

KodCode programs. We start from the 487K problems of KodCode-V1 [44], each a triple of question, reference solution, and unit tests. We keep solutions that define at least three top-level functions or a class with at least four methods and span at least 30 non-empty lines (29,047 problems), discard the competitive-programming subsets (22,418), discard problems whose benchmark-similarity score provided by KodCode is at least 0.75 (21,729), and re-execute every solution’s tests in an isolated sandbox, keeping solutions that pass (17,795). After decomposition checks, the pool contains 17,499 programs. Problems in our held-out and validation splits are excluded from training.

Unit annotation. Segmentation follows Section 6: class headers with their constructors, methods, and top-level functions form segments, short function-level programs may also be divided into statement segments, and the segments concatenate exactly to the source. For a curated subset, an LLM annotator read each program and its segments and, following a written guideline, either rejected the program as unsuitable (for example, interactive programs, programs dominated by placeholder code, or programs that communicate through mutable global state) or partitioned its segments into contiguous units. The guideline keeps every helper that a sibling calls in its own unit, since its name must appear in the contract, keeps public entry points separate, merges trivial unreferenced helpers and symmetric families of near-identical methods, and isolates trailing demonstration code. Every label is validated automatically, requiring that the partition covers every segment exactly once, that groups are contiguous, and that no group crosses a class boundary. On 252 programs labeled independently twice, the keep-or-reject decision agrees in 94.8% of cases and the exact partition in 77.1%, and the decisions on all 11 hidden reference items match their reference labels. The annotation yields 2,770 programs. The remaining 13,203 pool programs use one unit per segment, a rule that reproduces the annotated partition exactly for 64.4% of 1,200 annotated programs.

Optimizerpaged 8-bit AdamW
Learning rate10−510^{-5}
Schedulecosine, 3% warm-up
Effective batch size32
Epochs (steps)6 (8,520)
Sequence length2,048 tokens
Precisionbf16
GPUs4×4 \times RTX PRO 6000 (96 GB)
Training timeabout 13 hours

Table 4. Training hyperparameters. The optimizer is paged 8-bit AdamW [49, 50].

Example construction. The budget of unit kk is bk=⌈(∣hk∣+∣x(k)∣+sk)/ν⌉b_k = \left\lceil(|h_k| + |x^{(k)}| + s_k)/\nu\right\rceil, where ∣⋅∣|\cdot| counts tokens and sks_k is a small slack. For every example, trailing demonstration or test code (assertions, __main__ guards, print-only statements, and test functions) is removed, the units must reconstruct the program exactly, the budgets must parse back exactly, and the example must fit into 2,048 tokens. The annotated programs are upsampled threefold, giving 25,513 unit-view examples; the 25,118 examples whose contracts fit into P=224P = 224 positions also form contract-view examples. We hold out 10% of the examples for monitoring and train on the remaining 45,438.

Training

Table 4 lists the hyperparameters, which are shared by both backbones; Diffusion SFT uses the same settings and, without contract-view examples, takes fewer steps. In the contract view, the specification and the contract canvas attend bidirectionally. In the unit view, the context [c;ser⁡(z∗)][c; \operatorname{ser}(z^*)] is causal, and canvas positions attend to the context and to all canvases (coupled) or to their own canvas (isolated). Both backbones follow the shifted prediction convention of Dream [12], in which the token at position jj is predicted from the output at position j−1j - 1; we therefore select the supervised outputs by the masking state of their targets rather than of their inputs, which would leave a third of the targets visible to the model. The next-token loss LCTX\mathcal{L}_{\mathrm{CTX}} on contract tokens shares the 1/t1/t weight of its example. Diffusion SFT trains on the same 25,513 programs with contract and canvas delimiters removed, applying the masked diffusion objective to the full response with the same supervision indexing.

Decoding

SDDC. On DiffuCoder, the admissible set Aj(y)\mathcal{A}_j(y) also contains [PAD] directly after a complete entry, and a [PAD] committed there ends the contract. Unit decoding samples candidates with temperature 0.2 and top-pp 0.95. The keys and values of the context are computed once, and those of completed canvases are reused; under coupled attention this reuse is an approximation, because they were computed while other canvases were still changing.

Baselines. Vanilla and Diffusion SFT denoise a canvas that fills the length budget of each benchmark, including the prompt: 2,048 tokens for KodCode and ClassEval, 4,096 for ClassEval-Pro, 1,280 for HumanEval Pro, and 1,024 for MBPP Pro. Fixed-iteration decoding uses the entropy-ordered sampler of Dream [12] with temperature 0.2 and top-pp 0.95. Threshold decoding commits every position whose confidence is at least 0.8, and at least one per iteration, for up to 512 iterations. We evaluate Vanilla with 128, 256, and 512 iterations and Diffusion SFT with 64, 128, and 256 iterations on KodCode, both with 256 iterations on the other benchmarks and Vanilla additionally with 512, and both with threshold decoding everywhere. The most accurate of these configurations is 512 iterations for Vanilla on every benchmark and threshold decoding for Diffusion SFT, except on KodCode and HumanEval Pro with DiffuCoder, where 256 iterations are best; Table 1 and Table 2 report these configurations. On the self-invoking benchmarks, we further evaluate Diffusion SFT with thresholds 0.9 and 0.95 and with 512 iterations (Table 5). For baselines, the program is the fenced code block of the answer, or all blocks that define code and parse if there are several, or the whole answer if there is none.

Hyperparameter selection. The commitment threshold γu\gamma_u and the DiffuCoder contract variant were selected on the 210-problem validation split. For Dream-Coder, the canvas scale λ\lambda and the contract schedule were chosen on KodCode during development; the configuration that is best on the validation split alone (λ=16\lambda= 16) attains the same held-out pass@1 within one problem.

Evaluation

Benchmarks. Every method receives the benchmark prompt as the user turn of its chat template. The KodCode held-out split contains 240 problems with 120 multi-function modules and 120 class-based programs, 48 of which define several classes, and 80 problems at each difficulty level; the 210 validation problems are drawn in the same way. KodCode programs are run against their pytest suites with a timeout of 300 seconds. On ClassEval, the class pass rate requires all unit tests of a class to pass, and the test pass rate is the fraction of all unit tests passed. On ClassEval-Pro, whose reference solutions have a median length of 1,001 tokens, we use the official holistic prompt and evaluator: its class success requires all test classes of a class to pass, and its function-level success, our test pass rate, is the fraction of test classes whose tests all pass. Because some official tests patch built-in functions, we run the evaluator separately for each problem and sample, so that a failing program cannot affect later ones. On HumanEval Pro and MBPP Pro, we use the official sanitizer and harness and report the official score, the better of raw and sanitized outputs; every method receives the official instruction as a chat turn rather than a pre-filled function signature, because SDDC begins its response with a contract.

pass@5. We draw five samples per problem at temperature 0.4 and top-p 0.95. All stochastic stages sample, including contract synthesis and threshold decoding, whose commitment decisions use the untempered probability of the sampled token so that the thresholds stay calibrated. A problem counts as solved if any sample passes; on ClassEval, a unit test counts as passed if any sample passes it, and on ClassEval-Pro we use the official pass@k estimator. Sampling at temperature 0.4 lowers the per-sample accuracy of several models, most strongly of the base models, which then often answer in prose without code; pass@5 can therefore fall below pass@1 at temperature 0.2.

Latency. Latency is the wall-clock time per problem with batch size one, including contract synthesis and context encoding, measured on a single NVIDIA RTX PRO 6000 GPU of the same machine for all methods. The cost of fixed-iteration decoding varies by less than 5% across problems, so we time it on subsets of 20–60 problems. For pass@5, latency is the time to draw all five samples.

Proofs

Proposition 1. Write p⋆p_\star for p⋆(⋅∣η)p_\star(\cdot\mid\eta), H⋆H_\star for entropy under p⋆p_\star, and pθ,ip_{\theta,i} for pθ,i(⋅∣η)p_{\theta,i}(\cdot\mid\eta). Adding and subtracting ∑i∈Qlog⁡p⋆(Xi)\sum_{i\in Q}\log p_\star(X^i) inside the expectation gives

DKL(p⋆(XQ)∥∏i∈Qpθ,i(Xi))D_{\mathrm{KL}}\left(p_\star(X^Q)\mathbin\Vert\prod_{i\in Q}p_{\theta,i}(X^i)\right)
=E[log⁡p⋆(XQ)∏ip⋆(Xi)]+∑i∈QE[log⁡p⋆(Xi)pθ,i(Xi)]= \mathbb{E}\left[\log\frac{p_\star(X^Q)}{\prod_i p_\star(X^i)}\right]+\sum_{i\in Q}\mathbb{E}\left[\log\frac{p_\star(X^i)}{p_{\theta,i}(X^i)}\right]
=TC⋆(XQ)+∑i∈QDKL(p⋆(Xi)∥pθ,i(Xi)),= \mathrm{TC}_\star(X^Q)+\sum_{i\in Q}D_{\mathrm{KL}}\left(p_\star(X^i)\mathbin\Vert p_{\theta,i}(X^i)\right),

with expectations under p⋆(XQ)p_\star(X^Q). Adding and subtracting ∑kH⋆(XQk)\sum_k H_\star(X^{Q_k}) in the definition of total correlation yields

TC⋆(XQ)=∑kTC⋆(XQk)+TC⋆((XQk)k),\mathrm{TC}_\star(X^Q)=\sum_k\mathrm{TC}_\star(X^{Q_k})+\mathrm{TC}_\star\left((X^{Q_k})_k\right),

because ∑i∈QH⋆(Xi)−∑kH⋆(XQk)\sum_{i\in Q}H_\star(X^i)-\sum_k H_\star(X^{Q_k}) is the sum of the within-unit total correlations and ∑kH⋆(XQk)−H⋆(XQ)\sum_k H_\star(X^{Q_k})-H_\star(X^Q) is the total correlation among the units. Substituting this identity proves Eq. (3).

Confidence bound. Fix a unit kk and any position j∈Qkj\in Q_k. Because H⋆(XQk)≥H⋆(Xj)H_\star(X^{Q_k})\ge H_\star(X^j), the within-unit term satisfies

TC⋆(XQk)=∑i∈QkH⋆(Xi)−H⋆(XQk)≤∑i∈Qk∖{j}H⋆(Xi).\begin{aligned} \mathrm{TC}_\star(X^{Q_k})=\sum_{i\in Q_k}H_\star(X^i)-H_\star(X^{Q_k}) \\ &\le\sum_{i\in Q_k\setminus\{j\}}H_\star(X^i). \end{aligned}

If the most probable token at position ii has probability pi≥γ≥12p_i \ge\gamma\ge\frac{1}{2}, grouping the remaining tokens gives H⋆(Xi)≤Hb(pi)+(1−pi)log⁡(∣V∣−1)H_{\star}(X^i) \le H_b(p_i) + (1-p_i)\log(|\mathcal{V}|-1), and the right-hand side decreases in pip_i on [12,1]\left[\frac{1}{2},1\right]. Hence each position of QkQ_k other than jj adds at most Hb(γ)+(1−γ)log⁡(∣V∣−1)H_b(\gamma) + (1-\gamma)\log(|\mathcal{V}|-1) to the within-unit term, a bound that vanishes as γ→1\gamma\to1. No condition is required at jj, which corresponds to the single sampled commitment of each canvas in Algorithm 1. □\square

Additional Results

Decoding configurations of Diffusion SFT. Table 5 evaluates Diffusion SFT on the self-invoking benchmarks with five decoding configurations. Below 20 seconds per problem, its best configuration remains 12.1–20.8 points below SDDC; 512 iterations, its most accurate configuration, costs 35–40 seconds per problem and surpasses SDDC only on MBPP Pro with Dream-Coder, by 1.6 points at about eight times the latency.

Contract schedules. Table 6 compares contract schedules on KodCode with a single commitment per canvas. Besides the default schedule (Sz=112S_z = 112, padding only as a suffix), end-after-entry also admits [PAD] directly after a complete entry, and pad-scan (Sz=56S_z = 56) extends the padding suffix in each iteration over all masked positions whose padding probability exceeds γz\gamma_z. Faster schedules shorten contracts and trade accuracy for latency; the default schedule is the most accurate on Dream-Coder, and all three diffused schedules outperform left-to-right synthesis on DiffuCoder. With γu=0.99\gamma_u = 0.99, the configurations of Table 1 reach 24.2 and 23.3 pass@1 at 7.55 and 5.26 seconds, of which contract synthesis takes 4.55 and 2.19 seconds and unit decoding, which needs 54 and 61 iterations on average, 3.00 and 3.07 seconds.

Commitment threshold. Table 7 reports validation pass@1 and the mean number of unit-decoding iterations for each commitment threshold γu\gamma_u.

Binding components. In the controlled setting of Table 3 with isolated attention, validation pass@1 is 5.2 without binding, 5.7 with length-scaled padding alone, 9.5 with headers alone, and 12.9 with both; configurations without length-scaled padding draw every surplus from U{0,…,10}\mathcal{U}\{0,\ldots,10\}, and coupled attention with both components reaches 14.8. Length-scaled padding halves the overruns into the next unit, from 9.2% to 4.7% without headers and from 4.4% to 1.4% with them, so the two components are complementary.

Canvas scale and pad-fill. In the same controlled setting, λ=10\lambda= 10, 14, and 18 yield 14.2, 21.7, and 19.2 held-out pass@1 at 6.54, 10.86, and 16.06 seconds: small canvases truncate units, whereas large ones slow decoding without improving accuracy. Pad-fill exploits the contiguous padding suffix induced by length-scaled padding; for a model trained on the full corpus with left-to-right contracts and λ=14\lambda= 14, it reduces latency from 10.42 to 8.55 seconds while pass@1 changes from 21.2 to 22.1.

References

  1. [1]Xueying Du, Mingwei Liu, Kaixin Wang, Hanlin Wang, Junwei Liu, Yixuan Chen, Jiayi Feng, Chaofeng Sha, Xin Peng, and Yiling Lou. Evaluating large language models in class-level code generation. In Proceedings of the IEEE/ACM 46th International Conference on Software Engineering, 2024.DOI
  2. [2]Musfiqur Rahman, SayedHassan Khatoonabadi, and Emad Shihab. Beyond synthetic benchmarks: Evaluating llm performance on real-world class-level code generation. arXiv preprint arXiv:2510.26130, 2025.arxiv.org/abs/2510.26130
  3. [3]Yunhao Liang, Ruixuan Ying, Shiwen Ni, and Zhe Cui. Scaling test-driven code generation from functions to classes: An empirical study. arXiv preprint arXiv:2602.03557, 2026.arxiv.org/abs/2602.03557
  4. [4]Yeheng Chen, Chaoxiang Xie, Yuling Shi, Wenhao Zeng, Yongpan Wang, Hongyu Zhang, and Xiaodong Gu. ClassEval-Pro: A cross-domain benchmark for class-level code generation. In International Conference on AI-Powered Software (AIware), 2026. arXiv:2604.26923.arxiv.org/abs/2604.26923
  5. [5]Xue Jiang, Yihong Dong, Lecheng Wang, Zheng Fang, Qiwei Shang, Ge Li, Zhi Jin, and Wenpin Jiao. Self-planning code generation with large language models. ACM Transactions on Software Engineering and Methodology, 33(7):1–30, 2024.arxiv.org/abs/2303.06689
  6. [6]Eric Zelikman, Qian Huang, Gabriel Poesia, Noah D. Goodman, and Nick Haber. Parsel: Algorithmic reasoning with language models by composing decompositions. In Advances in Neural Information Processing Systems, 2023.arxiv.org/abs/2212.10561
  7. [7]Hung Le, Hailin Chen, Amrita Saha, Akash Gokul, Doyen Sahoo, and Shafiq Joty. CodeChain: Towards modular code generation through chain of self-revisions with representative sub-modules. In International Conference on Learning Representations, 2024.arxiv.org/abs/2310.08992
  8. [8]Jingchang Chen, Hongxuan Tang, Zheng Chu, Qianglong Chen, Zekun Wang, Ming Liu, and Bing Qin. Divide-and-conquer meets consensus: Unleashing the power of functions in code generation. Advances in Neural Information Processing Systems, 37:67061–67105, 2024.arxiv.org/abs/2405.20092
  9. [9]Evan Wang, Federico Cassano, Catherine Wu, Yunfeng Bai, Will Song, Vaskar Nath, Ziwen Han, Sean Hendryx, Summer Yue, and Hugh Zhang. Planning in natural language improves LLM search for code generation. In International Conference on Learning Representations, 2025.arxiv.org/abs/2409.03733
  10. [10]Ramakrishna Bairi, Atharv Sonwane, Aditya Kanade, Vageesh D. C, Arun Iyer, Suresh Parthasarathy, Sriram Rajamani, B. Ashok, and Shashank Shet. CodePlan: Repository-level coding using LLMs and planning. Proceedings of the ACM on Software Engineering, 1(FSE):675–698, 2024.arxiv.org/abs/2309.12499
  11. [11]Shen Nie, Fengqi Zhu, Zebin You, Xiaolu Zhang, Jingyang Ou, Jun Hu, Jun Zhou, Yankai Lin, Ji-Rong Wen, and Chongxuan Li. Large language diffusion models. Advances in Neural Information Processing Systems, 38:50608–50646, 2026.arxiv.org/abs/2502.09992
  12. [12]Jiacheng Ye, Zhihui Xie, Lin Zheng, Jiahui Gao, Zirui Wu, Xin Jiang, Zhenguo Li, and Lingpeng Kong. Dream 7B: Diffusion large language models. arXiv preprint arXiv:2508.15487, 2025.arxiv.org/abs/2508.15487
  13. [13]Zhihui Xie, Jiacheng Ye, Lin Zheng, Jiahui Gao, Jingwei Dong, Zirui Wu, Xueliang Zhao, Shansan Gong, Xin Jiang, Zhenguo Li, et al. Dream-coder 7b: An open diffusion language model for code. arXiv preprint arXiv:2509.01142, 2025.arxiv.org/abs/2509.01142
  14. [14]Shansan Gong, Ruixiang Zhang, Huangjie Zheng, Jiatao Gu, Navdeep Jaitly, Lingpeng Kong, and Yizhe Zhang. DiffuCoder: Understanding and improving masked diffusion models for code generation. In International Conference on Learning Representations, volume 2026, pages 15723–15750, 2026.arxiv.org/abs/2506.20639
  15. [15]Wonjun Kang, Kevin Galim, Seunghyuk Oh, Minjae Lee, Yuchen Zeng, Shuibai Zhang, Coleman Hooper, Yuzhou Hu, Hyung Koo, Nam Ik Cho, et al. Parallelbench: Understanding the trade-offs of parallel decoding in diffusion llms. In International Conference on Learning Representations, volume 2026, pages 89900–89938, 2026.arxiv.org/abs/2510.04767
  16. [16]Bumjun Kim, Dongjae Jeon, Moongyu Jeon, and Albert No. Dapd: Dependency-aware parallel decoding via attention for diffusion llms. arXiv preprint arXiv:2603.12996, 2026.arxiv.org/abs/2603.12996
  17. [17]Xuefei Ning, Zinan Lin, Zixuan Zhou, Zifu Wang, Huazhong Yang, and Yu Wang. Skeleton-of-thought: Prompting LLMs for efficient parallel generation. In International Conference on Learning Representations, 2024.arxiv.org/abs/2307.15337
  18. [18]Tian Jin, Ellie Y. Cheng, Zack Ankner, Nikunj Saunshi, Blake M. Elias, Amir Yazdanbakhsh, Jonathan Ragan-Kelley, Suvinay Subramanian, and Michael Carbin. Learning to keep a promise: Scaling language model decoding parallelism with learned asynchronous decoding. In Proceedings of the 42nd International Conference on Machine Learning, pages 27941–27956, 2025.arxiv.org/abs/2502.11517
  19. [19]Daniel Israel, Tian Jin, Ellie Cheng, Guy Van den Broeck, Aditya Grover, Suvinay Subramanian, and Michael Carbin. Planned diffusion. In International Conference on Learning Representations, volume 2026, pages 98298–98318, 2026.arxiv.org/abs/2510.18087
  20. [20]Jia-Nan Li, Jian Guan, Wei Wu, and Chongxuan Li. Refusion: A diffusion large language model with parallel autoregressive decoding. In International Conference on Learning Representations, volume 2026, pages 53846–53869, 2026.arxiv.org/abs/2512.13586
  21. [21]Md. Ashraful Islam, Mohammed Eunus Ali, and Md Rizwan Parvez. MapCoder: Multi-agent code generation for competitive problem solving. In Proceedings of the 62nd Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers), 2024.arxiv.org/abs/2405.11403
  22. [22]Chenghao Fan, Wen Heng, Bo Li, Sichen Liu, Yuxuan Song, Jing Su, Xiaoye Qu, Kai Shen, and Wei Wei. Stable-diffcoder: Pushing the frontier of code diffusion large language model. arXiv preprint arXiv:2601.15892, 2026.arxiv.org/abs/2601.15892
  23. [23]Zirui Wu, Lin Zheng, Zhihui Xie, Jiacheng Ye, Jiahui Gao, Shansan Gong, Yansong Feng, Zhenguo Li, Wei Bi, Guorui Zhou, et al. Dreamon: Diffusion language models for code infilling beyond fixed-size canvas. In International Conference on Learning Representations, volume 2026, pages 76626–76643, 2026.arxiv.org/abs/2602.01326
  24. [24]Yihong Dong, Zhaoyu Ma, Xue Jiang, Zhiyuan Fan, Jiaru Qian, Yongmin Li, Jianha Xiao, Zhi Jin, Rongyu Cao, Binhua Li, et al. Saber: An efficient sampling with adaptive acceleration and backtracking enhanced remasking for diffusion language model. arXiv preprint arXiv:2510.18165, 2025.arxiv.org/abs/2510.18165
  25. [25]Tarun Suresh, Debangshu Banerjee, Shubham Ugare, Sasa Misailovic, and Gagandeep Singh. Dingo: Constrained inference for diffusion llms. Advances in Neural Information Processing Systems, 38:160518–160551, 2026.arxiv.org/abs/2505.23061
  26. [26]Niels Mündler, Jasper Dekoninck, and Martin Vechev. Constrained decoding of diffusion llms with context-free grammars. In International Conference on Learning Representations, volume 2026, pages 99362–99408, 2026.arxiv.org/abs/2508.10111
  27. [27]Yitong Zhang, Yongmin Li, Yuetong Liu, Jia Li, Xiaoran Jia, Zherui Li, and Ge Li. Lookahead-then-verify: Reliable constrained decoding for diffusion llms under context-free grammars. Proceedings of the ACM on Software Engineering, 3(ISSTA):1264–1286, 2026.arxiv.org/abs/2602.00612
  28. [28]Lize Shao, Michael Cardei, Zichen Xie, Ferdinando Fioretto, and Wenxi Wang. Constrained code generation with discrete diffusion. arXiv preprint arXiv:2605.16829, 2026.arxiv.org/abs/2605.16829
  29. [29]Yiming Zeng, Jinghan Cao, Zexin Li, Yiming Chen, Tao Ren, Zhuochun Li, Dawei Xiang, Xidong Wu, Shangqian Gao, and Tingting Yu. Treeddiff: Ast-guided code generation with diffusion llms. In Proceedings of the First Workshop on Structured Understanding, Retrieval, and Generation in the LLM Era (SURGeLLM 2026), pages 93–106, 2026.arxiv.org/abs/2508.01473
  30. [30]Anton Xue, Litu Rout, Constantine Caramanis, and Sanjay Shakkottai. Ancoder: Anchored code generation via discrete diffusion models. arXiv preprint arXiv:2602.17688, 2026.arxiv.org/abs/2602.17688
  31. [31]Mark Chen, Jerry Tworek, Heewoo Jun, Qiming Yuan, Henrique Ponde de Oliveira Pinto, Jared Kaplan, Harri Edwards, Yuri Burda, Nicholas Joseph, Greg Brockman, et al. Evaluating large language models trained on code. arXiv preprint arXiv:2107.03374, 2021.arxiv.org/abs/2107.03374
  32. [32]Jacob Austin, Augustus Odena, Maxwell Nye, Maarten Bosma, Henryk Michalewski, David Dohan, Ellen Jiang, Carrie Cai, Michael Terry, Quoc Le, and Charles Sutton. Program synthesis with large language models. arXiv preprint arXiv:2108.07732, 2021.arxiv.org/abs/2108.07732
  33. [33]Miao Li, Hanyang Jiang, Sikai Cheng, Hengyu Fu, Yuhang Cai, Baihe Huang, Tinghan Ye, Xuanzhou Chen, and Pascal Van Hentenryck. Plan, verify and fill: A structured parallel decoding approach for diffusion language models. arXiv preprint arXiv:2601.12247, 2026.arxiv.org/abs/2601.12247
  34. [34]Zhen Xiong, Yujun Cai, Zhecheng Li, and Yiwei Wang. Unveiling the potential of diffusion large language model in controllable generation. In International Conference on Learning Representations, volume 2026, pages 66670–66686, 2026.arxiv.org/abs/2507.04504
  35. [35]Junhoo Lee, Seungyeon Kim, and Nojun Kwak. Unlocking the potential of diffusion language models through template infilling. In Proceedings of the 64th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers), pages 6273–6287, 2026.
  36. [36]Zemin Huang, Zhiyang Chen, Zijun Wang, Tiancheng Li, and Guo-Jun Qi. Reinforcing the diffusion chain of lateral thought with diffusion language models. Advances in Neural Information Processing Systems, 38:152677–152710, 2026.arxiv.org/abs/2505.10446
  37. [37]Gyunyeop Kim and Sangwoo Kang. Ta-grpo-d: Trajectory-aware grpo for optimizing denoising trajectories in diffusion llms. In Proceedings of the 64th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers), pages 37159–37174, 2026.
  38. [38]Jiawei Xu, Minghui Liu, Aakriti Agrawal, Yifan Chen, and Furong Huang. Scheduling thoughts: Learning the order of thought in diffusion language models. In Forty-third International Conference on Machine Learning, 2026.arxiv.org/abs/2606.23567
  39. [39]Jacob Austin, Daniel D Johnson, Jonathan Ho, Daniel Tarlow, and Rianne Van Den Berg. Structured denoising diffusion models in discrete state-spaces. Advances in neural information processing systems, 34:17981–17993, 2021.arxiv.org/abs/2107.03006
  40. [40]Subham S Sahoo, Marianne Arriola, Yair Schiff, Aaron Gokaslan, Edgar Marroquin, Justin T Chiu, Alexander Rush, and Volodymyr Kuleshov. Simple and effective masked diffusion language models. Advances in Neural Information Processing Systems, 37:130136–130184, 2024.arxiv.org/abs/2406.07524
  41. [41]Jiaxin Shi, Kehang Han, Zhe Wang, Arnaud Doucet, and Michalis K. Titsias. Simplified and generalized masked diffusion for discrete data. In Advances in Neural Information Processing Systems, volume 37, 2024.arxiv.org/abs/2406.04329
  42. [42]Satoshi Watanabe. Information theoretical analysis of multivariate correlation. IBM Journal of Research and Development, 4(1):66–82, 1960. doi: 10.1147/rd.41.0066.DOI
  43. [43]Chengyue Wu, Hao Zhang, Shuchen Xue, Zhijian Liu, Shizhe Diao, Ligeng Zhu, Ping Luo, Song Han, and Enze Xie. Fast-dllm: Training-free acceleration of diffusion llm by enabling kv cache and parallel decoding. In International Conference on Learning Representations, volume 2026, pages 57027–57051, 2026.arxiv.org/abs/2505.22618
  44. [44]Zhangchen Xu, Yang Liu, Yueqin Yin, Mingyuan Zhou, and Radha Poovendran. KodCode: A diverse, challenging, and verifiable synthetic dataset for coding. In Findings of the Association for Computational Linguistics: ACL 2025. Association for Computational Linguistics, 2025.arxiv.org/abs/2503.02951
  45. [45]Zhaojian Yu, Yilun Zhao, Arman Cohan, and Xiao-Ping Zhang. HumanEval Pro and MBPP Pro: Evaluating large language models on self-invoking code generation task. In Findings of the Association for Computational Linguistics: ACL 2025, pages 13253–13279. Association for Computational Linguistics, 2025.
  46. [46]Google DeepMind. Gemini diffusion is our new experimental research model. Google Blog, May 2025. URL https://blog.google/innovation-and-ai/models-and-research/google-deepmind/gemini-diffusion/.
  47. [47]Stefano Ermon. Introducing mercury 2.5. Inception Blog, September 2026. URL https://www.inceptionlabs.ai/blog/introducing-mercury-2-5.
  48. [48]Yuxuan Song, Zheng Zhang, Cheng Luo, Pengyang Gao, Fan Xia, Hao Luo, Zheng Li, Yuehang Yang, Hongli Yu, Xingwei Qu, Yufei Wu, Jing Su, Ge Zhang, Wenhao Huang, Mingxuan Wang, Lin Yan, Xiaoying Jia, Jingjing Liu, Wei-Ying Ma, Ya-Qin Zhang, Yonghui Wu, and Hao Zhou. Seed diffusion: A large-scale diffusion language model with high-speed inference, 2025. URL https://arxiv.org/abs/2508.02193.
  49. [49]Ilya Loshchilov and Frank Hutter. Decoupled weight decay regularization. In International Conference on Learning Representations, 2019.
  50. [50]Tim Dettmers, Mike Lewis, Sam Shleifer, and Luke Zettlemoyer. 8-bit optimizers via block-wise quantization. In International Conference on Learning Representations, 2022.arxiv.org/abs/2110.02861

Paper details

vlnc:W_jngqf4vz
Version
v1 · latest
Published
Fresh — added to the Hub within the last 30 days
Added
License
CC BY 4.0
Usage

views · 12

downloads · 3

A view counts once per browser per day, a download each time the PDF is requested.

  • Computer Science

Not recorded for this paper

View statement
Looking for related papers…
Contents