mlgenerate.comVisual Generative ML
All Models/text/Masked Diffusion LM

Masked Diffusion Language Model (MDLM / LLaDA)

Diffusion2024 · Cornell / Stanford / Renmin Univ.

Continuous-time discrete token masking + iterative bidirectional unmasking

Execution Paradigm:Iterative Parallel Confidence Unmasking
Parallel Multi-Token Unmasking per Step

Intuition & Key Idea

ELI5 Guide

Why this model was invented and how it transforms generation

The 30-Second Core Idea

"Starts with a sentence made entirely of [MASK] tokens and unmasks the easiest, most confident words first, refining the whole paragraph in parallel."

Real-World Metaphor

Solving a crossword puzzle or game of Hangman: you fill in the obvious clues first across the entire board, and those answers reveal the harder missing words.

Key Superpowers & Values
Inference StepsFast Parallel
16 – 32 Steps Total

Generates hundreds of words in a few parallel refinement passes.

Attention DirectionGlobal Context
Full Bidirectional

Tokens attend to both earlier and later words simultaneously.

Infilling & EditingSelf-Correction
Native Capability

Can fix, rewrite, or complete the middle of existing paragraphs.

GPU ParallelismCompute Bound
High Batch Utilization

Decodes all positions together with full FlashAttention.

1. Initialize Full [MASK] Canvas

Concatenate the user prompt with T_gen absorbing [MASK] tokens representing the entire unknown response canvas at t = 1.0.

Key Insight:

Response length T_gen is allocated upfront as a parallel canvas.

Interactive Stage (INFERENCE)All target generation slots start as [MASK] tokens.
MDLM Inference: Parallel Confidence UnmaskingStep 1 of 3

The canvas begins fully masked. At each step, all remaining [MASK] positions are predicted in parallel. The highest-confidence tokens are locked into the sequence, progressively anchoring the generation.

Active Generation Canvas (Length T = 8)Unmasked: 0 / 8
Slot 0
[MASK]
Pending
Slot 1
[MASK]
Pending
Slot 2
[MASK]
Pending
Slot 3
[MASK]
Pending
Slot 4
[MASK]
Pending
Slot 5
[MASK]
Pending
Slot 6
[MASK]
Pending
Slot 7
[MASK]
Pending
Hardware & Weights InspectorStep 1: Initialize Full [MASK] Canvas
Execution Bottleneck
Communication-Bound
Calculated via Arithmetic Intensity
Arithmetic Intensity
Dynamic per batch
Ratio of math operations (FLOPs) to memory traffic (Bytes)
Dominant GPU Kernel
FlashAttention-2 / CuBLAS GEMM
Optimized CUDA / Triton kernel launched

GPU Memory Hierarchy & HBM Traffic for this Step

HBM ↔ SRAM on-chip

Weights are loaded from High-Bandwidth Memory (HBM) into Streaming Multiprocessor (SM) registers and SRAM cache for computation.

Active Tensor Dimensions & Memory Shapes

x_t[B, P + T_gen]
Prompt + all-masked canvas
sample_mdlm_iterative.py
1
def generate_mdlm(prompt, model, gen_len=64, steps=8):
2
xt = torch.cat([prompt, full((B, gen_len), MASK_ID)], dim=1)
3
for k in reversed(range(1, steps + 1)):
4
probs = model.bidirectional_forward(xt, k / steps).softmax(-1)
5
conf, pred_tokens = probs.max(dim=-1) # Confidence per slot
6
unmask_idx = select_top_k_confident(conf, is_masked=(xt == MASK_ID), k=gen_len // steps)
7
xt = torch.where(unmask_idx, pred_tokens, xt)
8
return xt
Click code line to jump to corresponding stepPyTorch Reference
Why This Architecture Matters

Enables arbitrary-order generation, bidirectional infilling, and controllable step-vs-quality trade-offs in language modeling without causal left-to-right constraints.

Runtime Complexity & Bottlenecks

Training Objective:Time-Weighted Masked Cross-Entropy ELBO: ∫ (α′_t / (1 - α_t)) CE(x_0, p_θ(x_t)) dt

Inference Bottleneck:O(K) full-sequence bidirectional passes