Research & Papers

[P] Micro Diffusion — Discrete text diffusion in ~150 lines of pure Python

Minimal implementation demystifies diffusion with pure NumPy, trains in minutes without GPU.

Deep Dive

Inspired by Andrej Karpathy's minimalist approach with MicroGPT, developer Siwoo4985 has released Micro Diffusion, a bare-bones implementation of discrete text diffusion designed to reveal the core algorithm stripped of production-level complexity. The project demonstrates how diffusion models generate all tokens simultaneously through iterative unmasking—transforming from random noise (_____) to partial (_or_a) to complete words (noria)—contrasting with the sequential left-to-right generation of autoregressive models like GPT. This educational tool makes the often-opaque diffusion process accessible by providing the irreducible essence of the technique in a digestible format.

The implementation comes in three versions: a 143-line pure NumPy version showing the algorithm's essence, a 292-line commented version with visualization, and a 413-line PyTorch version using a bidirectional Transformer as the denoiser. All share the same diffusion loop while treating the denoiser as a pluggable component, highlighting the architecture's modularity. Trained on just 32K Social Security Administration names, the model runs entirely on CPU in minutes, eliminating GPU dependency and lowering the barrier to experimentation. By providing working code that fits in a single file, Micro Diffusion serves as both a learning resource and a foundation for developers to build upon without wrestling with massive codebases.

Key Points
  • Three implementations: 143-line pure NumPy (minimal), 292-line (commented), 413-line PyTorch with Transformer denoiser
  • Trains on 32K SSA names on CPU in minutes with no GPU required
  • Demonstrates discrete diffusion where all tokens generate simultaneously via iterative unmasking from noise

Why It Matters

Democratizes understanding of diffusion AI by providing minimal, runnable code that professionals can study and extend.