Fast parallel code generation using discrete-state diffusion models with curriculum learning and trajectory optimization, achieving 2,146 tokens/second inference speed.
Scanned 9/9/2026
Install to Claude Code
npx -y skills add ADu2021/skillXiv --skill seed-diffusion-parallel-code-generation --agent claude-codeInstalls into .claude/skills of the current project.
Are you the author of Seed Diffusion Parallel Code Generation?
Add the live security badge to your README — it updates automatically with every re-scan.
[](https://www.skillsdirectory.com/skills/adu2021-seed-diffusion-parallel-code-generation)More formats (shields.io, HTML) on the badges page.
---
name: seed-diffusion-parallel-code-generation
title: Seed Diffusion - Parallel Code Generation with Discrete Diffusion
version: 0.0.2
engine: skillxiv-v0.0.2-claude-opus-4.6
license: MIT
url: https://arxiv.org/abs/2508.02193
keywords: [diffusion, code-generation, parallel-decoding, discrete-diffusion]
description: "Fast parallel code generation using discrete-state diffusion models with curriculum learning and trajectory optimization, achieving 2,146 tokens/second inference speed."
---
## Seed Diffusion: Parallel Code Generation with Discrete Diffusion
Seed Diffusion replaces sequential token-by-token autoregressive generation with parallel, non-sequential generation using discrete diffusion. The core innovation is recognizing that code can be generated by progressively refining corrupted sequences rather than building left-to-right, enabling massive speedups while maintaining competitive accuracy.
### Core Concept
Traditional autoregressive models generate tokens sequentially: each token depends on all previous tokens. This serialization creates an inference bottleneck—a 4096-token output requires 4096 sequential steps. Seed Diffusion inverts this by treating code generation as a denoising problem: start with corrupted code (masked tokens), then iteratively refine it toward valid output, sampling multiple positions in parallel.
The key insight: code has structure and redundancy that allows parallel recovery. Unlike natural language where word order strictly matters, code patterns (imports, function definitions, control flow) can be inferred from partial context and refined together.
### Architecture Overview
- **Discrete Diffusion Framework**: Corruption schedule replaces tokens with [MASK] symbols; refinement network predicts which masked positions and generates replacements in parallel
- **Two-Stage Curriculum Training**: Early training (80%) uses mask-based corruption; final training (20%) uses edit-based augmentation (insertions, deletions, substitutions) forcing genuine code re-evaluation
- **Trajectory Space Tailoring**: Filters synthetic training trajectories using ELBO maximization to avoid learning from detrimental or redundant orderings
- **Block-Level Semi-Autoregressive Inference**: Balances parallelism and quality by processing tokens in causal blocks—full parallelism within blocks, sequential ordering between blocks
- **On-Policy Diffusion Learning**: Minimizes trajectory length during inference with verifier-guided convergence
### Implementation Steps
**Step 1: Prepare the Diffusion Corruption Schedule**
Define how tokens are progressively corrupted during training. The schedule maps step t to a masking ratio:
```python
import numpy as np
def create_corruption_schedule(max_steps=1000, schedule_type="linear"):
"""
Create corruption schedule for diffusion training.
Linear schedule: more aggressive early corruption, gentle refinement later.
"""
if schedule_type == "linear":
# At step 0, fully masked; at max_steps, fully unmasked
corruption_ratios = np.linspace(1.0, 0.0, max_steps)
elif schedule_type == "cosine":
# Smoother cosine schedule
t = np.arange(max_steps)
corruption_ratios = 0.5 * (1 + np.cos(np.pi * t / max_steps))
return corruption_ratios
# For 80% mask-based phase, sample from this schedule
mask_schedule = create_corruption_schedule(800)
```
During Phase 1 (mask training), tokens are replaced with [MASK] according to the schedule.
**Step 2: Implement Edit-Based Augmentation for Phase 2**
After mask training converges, introduce edit operations (deletions, insertions, substitutions) using Levenshtein distance:
```python
from difflib import SequenceMatcher
def apply_edits_via_levenshtein(clean_code, edit_probability=0.3):
"""
Apply edit operations (insert, delete, substitute) to code based on Levenshtein distance.
Forces model to genuinely re-evaluate entire sequences, not just predict unmasked tokens.
"""
tokens = clean_code.split()
corrupted = tokens.copy()
for i in range(len(corrupted)):
if np.random.random() < edit_probability:
operation = np.random.choice(['delete', 'insert', 'substitute'])
if operation == 'delete' and len(corrupted) > 1:
corrupted.pop(i)
elif operation == 'insert':
corrupted.insert(i, '[EDIT]')
elif operation == 'substitute':
corrupted[i] = '[CORRUPT]'
return ' '.join(corrupted)
# Phase 2: Train on edit-corrupted sequences
corrupted_code = apply_edits_via_levenshtein(clean_code, edit_probability=0.4)
```
This prevents the model from exploiting the simplification that unmasked tokens are always correct.
**Step 3: Trajectory Filtering with ELBO**
Not all generation orderings are equally useful. Filter training trajectories to include only high-quality ones:
```python
def compute_elbo_score(trajectory, clean_target, model):
"""
Compute Evidence Lower Bound (ELBO) as proxy for trajectory quality.
Trajectories with high ELBO are more likely to lead to valid outputs.
"""
log_likelihood = 0.0
for step, (corrupted_state, predicted_tokens) in enumerate(trajectory):
# Log probability of predicting correct tokens from corrupted state
logits = model(corrupted_state)
step_log_prob = np.sum(np.log(softmax(logits)[predicted_tokens]))
log_likelihood += step_log_prob
# ELBO accounts for trajectory length (encourages efficiency)
elbo = log_likelihood - len(trajectory) * 0.01
return elbo
# Filter trajectories: keep only top percentile by ELBO
all_trajectories = sample_synthetic_trajectories(code_dataset)
filtered_trajectories = sorted(all_trajectories, key=lambda t: compute_elbo_score(t, model))[-top_10_percent:]
```
**Step 4: Block-Level Semi-Autoregressive Inference**
During inference, balance parallelism with causality by processing in blocks:
```python
def block_level_inference(initial_code, block_size=64, num_iterations=8):
"""
Semi-autoregressive decoding: full parallelism within blocks,
sequential causal ordering between blocks.
"""
state = initial_code
for iteration in range(num_iterations):
# Identify blocks (sequences of block_size tokens)
tokens = state.split()
blocks = [tokens[i:i+block_size] for i in range(0, len(tokens), block_size)]
refined_blocks = []
for block_idx, block in enumerate(blocks):
# Condition on all previous blocks for causality
context = ' '.join(refined_blocks)
block_input = context + ' ' + ' '.join(block)
# Refine all positions in block in parallel
refined_block = model.refine_block(block_input, mask_positions=all_positions_in_block)
refined_blocks.append(refined_block)
state = ' '.join(refined_blocks)
return state
```
**Step 5: Verifier-Guided Convergence**
Use a lightweight verifier to stop refinement early:
```python
def verifier_guided_refinement(code, max_iterations=20, confidence_threshold=0.95):
"""
Iteratively refine code until verifier indicates high confidence in validity.
This prevents unnecessary iterations once convergence is reached.
"""
state = code
for iteration in range(max_iterations):
# Check if current state is valid
validity_score = verifier(state)
if validity_score > confidence_threshold:
return state, iteration
# Refine further
state = refine_step(state)
return state, max_iterations
# Usage
final_code, steps_taken = verifier_guided_refinement(corrupted_code)
```
### Practical Guidance
**When to Use:**
- Code generation tasks where inference latency is critical (embedded systems, real-time code completion)
- Tasks with moderate-length outputs (up to few thousand tokens) where block processing is efficient
- Domains with structured output (code, templates, JSON) that support parallel refinement
- Scenarios tolerating slightly longer training time for faster inference
**When NOT to Use:**
- Long-form generation (>10K tokens) where block overhead dominates
- Tasks requiring strict left-to-right dependencies (e.g., narrative text)
- Applications where training data for diffusion is sparse
- Scenarios where generation latency is not a bottleneck
**Hyperparameters:**
| Parameter | Default | Impact |
|-----------|---------|--------|
| `mask_phase_ratio` | 0.8 | Higher = more mask training before edits; too high leads to overfitting to masking |
| `edit_probability` | 0.3-0.4 | Higher = more aggressive edits; balance prevents catastrophic forgetting |
| `block_size` | 64 | Larger = more parallelism, higher latency per block; 64-128 optimal for most hardware |
| `num_iterations` | 8-16 | More iterations refine quality; diminishing returns after 8 for most tasks |
| `confidence_threshold` | 0.95 | Early stopping; lower allows faster (less refined) generation |
**Training Tips:**
- Phase 1 (mask) typically converges quickly; monitor validation loss
- Phase 2 (edits) requires more careful tuning; start with lower edit probability and increase gradually
- Use curriculum learning: start with shorter code sequences, gradually increase length
- Monitor validation loss across both phases separately to detect phase-transition issues
### Reference
**Paper**: Seed Diffusion: Scaling Discrete Diffusion Models for Generative Modeling (2508.02193)
- Achieves 2,146 tokens/second on H20 GPUs (competitive with or exceeding autoregressive baselines)
- Maintains code quality while enabling massive parallelization
- Demonstrates scalability to production code generation at scale
Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.
No comments yet. Be the first to comment!