Transformers as In-Context Samplers: From Closed-Form Diffusion to Estimation-Free Sampling
AuthorsArman Adibi, Alireza Jafari, Mohammad Ghavamzadeh, Hadi Daneshmand
Resources
This work argues that transformers can generate data in context by internally simulating diffusion-like sampling processes.
Key results
GPT-2-style transformer layers used in the two-moons and smile experiments
Embedding width of the controlled GPT-2-style model
What the paper found
This paper expands in-context learning from prediction to generation by asking whether a frozen transformer can act as a sampler: given independent samples from an unknown distribution, can it produce a new sample without parameter updates or an estimated score network? The theory answers yes. Standard softmax attention computes Gaussian-mixture responsibility weights and their weighted empirical mean, while feedforward layers perform Euler updates, allowing a transformer to implement closed-form diffusion exactly, including a smoothed variant that reduces memorization. A second theorem shows approximation of a finite Estimation-Free Sampling procedure, combining particle gradient descent with reverse-time transport, so transformers can execute both score-based and estimation-free samplers in context. Experiments with a GPT-2-style model show compositional out-of-distribution generation: training excludes a smile-shaped component, yet smile points in the prompt lead to new samples along that unseen curve. In a 16-layer, 32-dimensional model trained on two-moons and related point clouds, hidden states first spread toward a more uniform geometry and later recover the prompt’s structured distribution. The same U-shaped layerwise pattern appears in normalized embeddings from OpenAI’s GPT-2, Meta’s Llama-3.3-70B-Instruct, Cerebras-GPT, and Qwen2.5, measured with RBF MMD2 and an interacting-particle energy. However, the authors emphasize an expressivity-versus-mechanism gap: these theorems prove that transformers can implement the algorithms, not that pretrained models literally do so, and smaller Qwen2.5 variants show a weaker intermediate transport phase.
Original abstract
A growing body of work establishes that large language models are not mere statistical memorizers, but are capable of in-context learning: performing inference at test time using only examples provided in the prompt, without any parameter updates. Prior theoretical work has shown that this capability extends to supervised learning tasks such as linear regression. We prove that in-context learning extends further to \emph{data generation}: frozen transformers can simulate iterative generative samplers from in-context samples. We first show that transformers can realize closed-form and smoothed closed-form diffusion samplers. The construction identifies a concrete generative role for softmax attention: it computes responsibility weights and weighted empirical averages, while feedforward layers implement Euler updates. To empirically relate these constructions to pretrained language models, we study \emph{semantic-topic sampling}: prompts consisting of words drawn from a common semantic category, such as animals, foods, or cities. Across transformer layers, the normalized hidden states exhibit a two-stage geometry: they move toward a uniform spherical reference in intermediate layers and then return to structured, topic-dependent representations near the output. We further measure an interacting-particle energy on these hidden-state clouds and observe the same U-shape pattern. We then prove that transformers can approximate an energy-based sampler, constructing the same U-shape energy across the layers.
Read the original paperMore in Diffusion Models
Browse all 82 papers →FewStepRL: Fine-tuning Few-step Diffusion Models with Reinforcement Learning
Haitao Lin, Minsi Ren, Yang Li, Xingtong Ge, Zheyuan Hu, Peiyan Hu, Tailin Wu
FewStepRL adapts multiple reinforcement-learning fine-tuning methods to make reward-driven improvements to fast, few-step diffusion models.
JVT: Just Video Transformer makes pixel-space video diffusion simple
Jianjun Zhou, Hua Geng, Haoyu Guo
JVT shows that a straightforward Transformer can generate video directly in pixels—and even produce matching depth-like geometry alongside it.
Restoring Diversity in Distilled Image and Video Generators by Probing Activations
Furkan Horoz, Ozgur Kara, Kaan Oktay, Adil Kaan Akan, Atakan Kara, Anand Bhattad, James Matthew Rehg
The paper restores variety in fast distilled image and video generators by finding and correcting a collapse in their internal activation directions.