Diffusion LLMs Require 10x More FLOPs to Match Autoregressive Loss

Stanford CME295 Transformers & LLMs | Autumn 2026 | Lecture 8 - Diffusion LLMs — Stanford Online

Stanford Online

Sparse token supervision forces diffusion language models to consume roughly ten times more training compute than autoregressive baselines to achieve comparable loss, disincentivizing adoption despite parallel inference gains.

AI-assisted summary of Stanford CME295 Transformers & LLMs | Autumn 2026 | Lecture 8 - Diffusion LLMs — original source. Check the original for full context.

Source published:

Key ideas

  • Stanford CME 295 introduced its first standalone lecture on Diffusion LLMs, exploring discrete masked diffusion as an alternative to the standard autoregressive generative paradigm. (0:06)
  • Unlike autoregressive models whose generation steps scale linearly with output token length, diffusion LLMs decode in O(T) steps decoupled from sequence length via bidirectional encoder architectures. (16:11)
  • Training discrete diffusion LLMs is derived via the Evidence Lower Bound (ELBO) using an absorbing-state Markov chain, simplifying into a weighted cross-entropy loss over masked tokens. (61:37)
  • A major barrier to diffusion LLM adoption remains training sample efficiency, requiring roughly 10 times more FLOPs than autoregressive counterparts to achieve comparable loss. (106:41)

Detailed notes

## Background This lecture was published on YouTube by Stanford Online on December 1, 2026, as part of the CME295 Transformers & LLMs course for Autumn 2026. Taught by Stanford Adjunct Professors Afshine Amidi and Shervine Amidi, the session serves as Lecture 8 and covers the core theory, mathematical foundations, and system-level trade-offs of diffusion-based large language models.

## TL;DR The lecture examines diffusion LLMs as an alternative generative paradigm to standard autoregressive next-token prediction, contrasting sequential left-to-right generation with holistic, non-autoregressive denoising. After analyzing the continuous text diffusion challenges that led to discrete absorbing-state masking formulations, the instructors derive the Evidence Lower Bound (ELBO) and its simplification into weighted cross-entropy losses. They walk through the full training and inference pipelines, highlighting architectural distinctions from masked language models like BERT and addressing failure modes like subject-verb disagreement through remasking techniques. Finally, the discussion assesses practical deployment trade-offs, demonstrating how caching, block-level generation, step distillation, and speculative decoding can mitigate latency drawbacks while confronting the paradigm's roughly tenfold compute penalty during pre-training.

## Atmosphere & style The presentation carries a rigorous, university-level instructional tone driven by a steady collaborative dynamic between Afshine and Shervine Amidi. The narrative unfolds systematically, transitioning smoothly from intuitive high-level analogies—such as comparing generation to a sculptor chiseling marble or an author refining an essay outline—into dense, step-by-step mathematical proofs on the blackboard. The atmosphere balances technical precision with candid engineering pragmatism, maintaining an encouraging and transparent mood as the instructors demystify complex derivations and openly confront the substantial efficiency bottlenecks currently facing non-autoregressive models.

## Bulletin - [00:06](https://www.youtube.com/watch?v=rkByitBwAQo&t=6s) Stanford CME 295 introduced its first standalone lecture on Diffusion LLMs, exploring discrete masked diffusion as an alternative to the standard autoregressive generative paradigm. - [16:11](https://www.youtube.com/watch?v=rkByitBwAQo&t=971s) Unlike autoregressive models whose generation steps scale linearly with output token length, diffusion LLMs decode in O(T) steps decoupled from sequence length via bidirectional encoder architectures. - [01:01:37](https://www.youtube.com/watch?v=rkByitBwAQo&t=3697s) Training discrete diffusion LLMs is derived via the Evidence Lower Bound (ELBO) using an absorbing-state Markov chain, simplifying into a weighted cross-entropy loss over masked tokens. - [01:46:41](https://www.youtube.com/watch?v=rkByitBwAQo&t=6401s) A major barrier to diffusion LLM adoption remains training sample efficiency, requiring roughly 10 times more FLOPs than autoregressive counterparts to achieve comparable loss.

## Key takeaways - [05:06](https://www.youtube.com/watch?v=rkByitBwAQo&t=306s) Autoregressive LLMs suffer from linear inference scaling, unidirectional context constraints, and irreversible generation errors where past mistakes cannot be modified. - [23:47](https://www.youtube.com/watch?v=rkByitBwAQo&t=1427s) Continuous text diffusion with Gaussian noise on embeddings suffers from the curse of dimensionality during nearest-neighbor discretization and an objective mismatch between L2 regression and discrete token identities. - [35:11](https://www.youtube.com/watch?v=rkByitBwAQo&t=2111s) Discrete diffusion circumvents continuous embedding issues by modeling token corruption directly via transition matrices and categorical distributions. - [39:47](https://www.youtube.com/watch?v=rkByitBwAQo&t=2387s) Under the absorbing state masking formulation from D3PM, tokens transition to a [MASK] token with probability beta_t and remain masked deterministically once corrupted. - [58:34](https://www.youtube.com/watch?v=rkByitBwAQo&t=3514s) Because the true marginal likelihood p_theta(x_0) over all intermediate trajectories is intractable, training optimizes a tractable surrogate derived via Jensen's inequality (ELBO). - [01:09:09](https://www.youtube.com/watch?v=rkByitBwAQo&t=4149s) Expanding the ELBO yields a sum of KL divergences between the forward posterior step and the parameterized reverse step, which simplifies to weighted cross-entropy. - [01:26:24](https://www.youtube.com/watch?v=rkByitBwAQo&t=5184s) Unlike BERT, which uses a static 15% mask ratio for representation learning, diffusion LLMs dynamically schedule noise from 100% down to 0% specifically for generative decoding. - [01:28:22](https://www.youtube.com/watch?v=rkByitBwAQo&t=5302s) Simultaneous parallel token decoding can cause contradictory agreement errors, which can be mitigated through remasking mechanisms and context-aware classifiers. - [01:33:25](https://www.youtube.com/watch?v=rkByitBwAQo&t=5605s) Inference latency can exceed autoregressive models on long-prompt short-output workloads unless mitigated by prompt hidden-state caching (DLLM-Cache) or step distillation. - [01:37:45](https://www.youtube.com/watch?v=rkByitBwAQo&t=5865s) Block-level diffusion combines local bidirectional generation within chunks with causal attention across past frozen blocks to scale to arbitrary sequence lengths. - [01:45:17](https://www.youtube.com/watch?v=rkByitBwAQo&t=6317s) Diffusion LLMs can serve as high-throughput draft models in speculative decoding pipelines, proposing multi-token candidates in parallel for causal verification. - [01:46:41](https://www.youtube.com/watch?v=rkByitBwAQo&t=6401s) Native bidirectionality makes diffusion models ideally suited for fill-in-the-middle tasks such as code infilling, despite training sample efficiency headwinds.

## Detailed walkthrough ### [00:06](https://www.youtube.com/watch?v=rkByitBwAQo&t=6s) Introduction and Technical Disclaimers

The lecture opens with a warm welcome to Lecture 8 of CME 295. The instructor emphasizes that this is a particularly special session dedicated to diffusion LLMs—a generative paradigm fundamentally different from everything covered in the course up to this point. Notably, the 2026 iteration of the class marks the very first time this subject has been awarded its own standalone lecture, reflecting its rapid surge in importance across modern machine learning research over recent years.

Before diving into the core material, the instructor offers a cautionary disclaimer: this session is noticeably more mathematical and technical than the typical lecture, sharing the demanding flavor of Lecture 4 on reinforcement learning with LLMs. To navigate the dense theoretical landscape without becoming overwhelmed, students are urged to adopt a three-step learning strategy:

1. **Intuition first:** Focus primarily on why a given mathematical formula exists and what conceptual purpose it serves before wrestling with its mechanics. 2. **Review prerequisites:** Lean heavily on core mathematical foundations, most notably probability theory, which serves as the indispensable backbone for the entire lecture. 3. **Interpret from first principles:** Work through equations step-by-step from foundational concepts rather than attempting to memorize complex expressions by heart.

An additional practical disclaimer is highlighted regarding research literature: notation and conventions tend to vary wildly across published diffusion papers. Because variable definitions and mathematical framing frequently shift from one author to another, anchoring oneself in underlying intuition is the only reliable way to follow the literature smoothly.

---

[02:06](https://www.youtube.com/watch?v=rkByitBwAQo&t=126s) The Autoregressive Paradigm and Next-Token Prediction

To contextualize why diffusion is needed, the lecture revisits the foundational building blocks of modern large language models covered in earlier sessions. Modern architectures rely on the transformer backbone, which has demonstrated extraordinary empirical scaling behavior both as a function of training token volume and total parameter count. Under the standard regime, virtually all tasks are cast into a unified text-to-text formulation where text inputs produce text outputs generated strictly one token at a time.

```mermaid flowchart LR accTitle: Autoregressive Next-Token Generation accDescr: Sequential generation loop where generated tokens are fed back as inputs until a stop token is reached.

subgraph InputStage["Input Context"] BOS["BOS Token"] Past["Past Tokens"] end

subgraph ModelStage["Transformer"] LLM["Causal Transformer Engine"] end

subgraph OutputStage["Sequential Output"] Next["Next Token"] EOS{"EOS Token?"} end

BOS --> LLM Past -.-> LLM LLM --> Next Next --> EOS EOS -- No --> Past ```

This classic framework is known as the autoregressive paradigm. At training time, the model optimizes a standard cross-entropy objective designed to maximize the conditional probability of predicting the correct ground-truth target token given all preceding historical tokens. At inference time, sequence generation proceeds sequentially:

- The process initializes with a dedicated marker, such as a Beginning of Sequence (`BOS`) token, passed into the model. - Internal attention and feed-forward layers compute hidden states to yield the first predicted output token. - This newly emitted token is appended to the input prompt, and the combined sequence is fed back into the model to predict the subsequent token. - This sequential loop repeats iteratively until the model emits an End of Sequence (`EOS`) token signaling that generation should terminate.

---

[05:06](https://www.youtube.com/watch?v=rkByitBwAQo&t=306s) Three Fundamental Limitations of Autoregressive LLMs

While next-token prediction has powered modern generative AI, the lecturer points out a glaring structural bottleneck: the total number of inference forward passes scales directly with the length of the generated response. In the instructor's words: “So, you're doing as many iterations as you have output tokens in your response.” In an era where advanced reasoning models rely heavily on lengthy chains of thought before arriving at a final answer, generating massive intermediate token traces token-by-token introduces severe latency penalties.

```mermaid flowchart TD accTitle: Limitations of Autoregressive Generation accDescr: Three core weaknesses of the autoregressive token-by-token generation setup.

subgraph Bottlenecks["Autoregressive Bottlenecks"] A["1. Inference Speed: Forward passes equal output length"] B["2. Unidirectional Context: Causal masking ignores future context"] C["3. Irreversibility: Cannot backtrack or edit past errors"] end

A --> Impact["High latency on long chain-of-thought outputs"] B --> Code["Suboptimal for code infilling and bidirectional editing"] C --> Hallucination["Cascading errors require awkward forward self-correction"] ```

Beyond raw generation latency, the lecturer isolates two additional intrinsic weaknesses:

- **Unidirectional causal masking:** Because standard decoder-only models rely strictly on causal self-attention, each token representation can attend only to itself and preceding positions. In bidirectional tasks—such as code synthesis or infilling, where a developer needs to generate an implementation bounded between existing code blocks above and below—the inability to attend to downstream context is fundamentally limiting. - **Inability to revise or backtrack:** Generation is strictly irreversible. Once an incorrect token is sampled, the model cannot erase or modify it. As the instructor explains: “When you predict a token and you want to go to the next one, the token that you just predicted is there. Like there is nothing you can do in case you make a mistake.” The model's only recourse is to emit subsequent tokens that attempt to steer the generation back on track, often worsening hallucinations or incoherence.

---

[08:57](https://www.youtube.com/watch?v=rkByitBwAQo&t=537s) Motivation from Computer Vision: Diffusion and the Sculptor's Block

When machine learning practitioners encounter fundamental roadblocks in one subdiscipline, they routinely look to adjacent domains for inspiration. In this case, natural language processing looks directly toward computer vision. Image generation models do not produce scenes pixel-by-pixel in an autoregressive raster scan; instead, they sample an entire block of pure random noise and apply holistic operations across the entire canvas simultaneously, refining all pixels concurrently over a series of denoising steps.

To make this concept intuitive, the lecturer draws an analogy to classical stone sculpture. If an artist sets out to carve a sculpture—such as a teddy bear—they begin with a raw, unformed block of rock fresh from a quarry. The surface is jagged, uneven, and chaotic, serving as the physical analogue of noise. The sculptor's task is not to construct the statue piece by piece, but rather to identify what material is superfluous and systematically chip it away until the final form is revealed.

> “The sculpture is already complete within the marble block before I start my work. It is already there. I just have to chisel away the superfluous material.” — Michelangelo

This artistic philosophy maps directly onto the mechanics of diffusion models:

- The model initializes from an unformed state of pure noise representing latent possibilities. - Through a trained neural network, the model repeatedly predicts and strips away the noise contaminating the latent representation. - Through continuous holistic refinement rather than left-to-right sequential assembly, the clean end product gradually emerges from the initial random state.

[12:56](https://www.youtube.com/watch?v=rkByitBwAQo&t=776s) The Speechwriting Analogy and Coarse-to-Fine Generation

Afshine Amidi begins by bridging from continuous image generation—such as DDPM (Denoising Diffusion Probabilistic Models), score matching, and flow matching—to text generation. When asking the class how many students have heard of score matching or flow matching, only three people raise their hands. Amidi asks the class to consider how humans actually generate text. Rather than treating writing as an autoregressive autocompletion exercise where tokens are generated strictly left-to-right, he invites them to imagine preparing a speech for their former school.

Instead of writing sentences in a strictly linear sequence, an author typically outlines the major sections, sketches the overarching ideas, and gradually fills in the details between those anchors until reaching the final text. In diffusion, pure noise functions analogously to a blank page. The model iteratively fleshes out structure and content, operating under a principle of coarse-to-fine generation. Amidi highlights that the math can get involved, but promises to strike a careful balance between intuitive visual explanations and rigorous derivations.

```mermaid flowchart TD accTitle: Coarse-to-Fine Speechwriting Metaphor accDescr: Progression from a blank page or noise through section outlines down to fully refined text.

A["Blank Page / Pure Noise"] --> B["Section Outlines & Key Ideas"] B --> C["Drafting Content Between Sections"] C --> D["Final Polished Speech"] ```

[16:11](https://www.youtube.com/watch?v=rkByitBwAQo&t=971s) Architecture Choice: Encoder-Only Models for Text Denoising

Amidi asks the class what type of transformer architecture would best fit this non-autoregressive, iterative denoising paradigm. While standard autoregressive language models rely on causal attention masks in a decoder-only setup (predicting the next token conditioned strictly on past tokens), a diffusion model requires an unmasked, bidirectional view of the entire noisy sequence. A student correctly answers that an encoder-only architecture is appropriate.

Amidi confirms this, noting that an encoder-only backbone—much like BERT from Lecture 2—gives the model a holistic view of the input it is trying to denoise. However, unlike traditional BERT, which was trained solely for representation learning and masked-token classification rather than open-ended text generation, this setup is repurposed for iterative generation.

> “In this process, you would want your model to actually have a holistic view of the noisy input that is trying to denoise.” — Afshine Amidi

- **Autoregressive paradigm:** Decoder-only architecture with causal self-attention, constrained to left-to-right generation. - **Diffusion paradigm:** Encoder-only transformer backbone with bidirectional attention across all positions simultaneously. - **Core distinction from BERT:** While sharing the bidirectional encoder-only architecture, diffusion models use this structure directly as a generative engine across multiple refinement steps.

[17:41](https://www.youtube.com/watch?v=rkByitBwAQo&t=1061s) Iterative Denoising and Complexity Benefits

The diffusion generation process begins with a sequence of random noise. That noisy input is fed into the encoder-only transformer, which outputs a representation with slightly less noise. This intermediate representation is fed back into the model in a loop, stripping away corruption step-by-step until the clean, final sequence is produced.

```mermaid flowchart LR accTitle: Iterative Denoising Loop accDescr: Repeated forward passes through an encoder-only model gradually remove noise.

subgraph Loop["Denoising Loop"] direction LR N0["Noisy Input"] --> M1["Encoder-Only Model"] M1 --> N1["Less Noisy Text"] N1 --> M2["Encoder-Only Model"] M2 --> NF["Clean Output Text"] end ```

Amidi stresses the profound computational difference between this approach and autoregressive decoding: - **Autoregressive decoding iteration count:** $\mathcal{O}(\text{number of output tokens})$. Generating longer answers scales linearly in required sequential iterations. - **Diffusion decoding iteration count:** $\mathcal{O}(\text{number of diffusion steps})$. The number of passes through the model is determined by the chosen diffusion schedule, completely decoupled from the output sequence length.

A student asks whether diffusion models are naturally better suited for long responses, while autoregressive models remain preferable for short responses. Amidi acknowledges the intuition and notes that co-instructor Shervine Amidi will analyze those exact speed trade-offs later in the lecture.

[21:02](https://www.youtube.com/watch?v=rkByitBwAQo&t=1262s) Continuous Diffusion Formulations

Because the literature has not converged on a single standard formulation for diffusion LLMs, Amidi categorizes current work into continuous and discrete approaches, starting with the continuous framework inherited from computer vision. In vision, continuous diffusion operates directly on pixel spaces or latent spaces characterized by real continuous numbers. By contrast, text is natively composed of discrete categorical tokens from a finite vocabulary.

Before tackling the discrete hurdle, Amidi provides a brief taxonomy of how continuous generative modeling is formulated across contemporary literature: 1. **Denoising Diffusion Probabilistic Models (DDPM):** The standard formulation that focuses on directly predicting and subtracting injected noise across discrete time steps. 2. **Score Matching:** Formulates generation around estimating the score function—defined as the gradient of the log probability density with respect to data, $\nabla_x \log p(x)$—to guide samples toward regions of higher probability density. 3. **Flow Matching:** Formulates the problem as optimal transport, learning continuous vector fields to smoothly push probability mass from a tractable source distribution to the target data distribution.

[23:47](https://www.youtube.com/watch?v=rkByitBwAQo&t=1427s) Forward and Reverse Processes in Continuous Diffusion

Focusing on the standard DDPM framework, Amidi defines the two fundamental directions of continuous diffusion: - **Forward process ($q$):** Takes a clean input and progressively corrupts it across steps by injecting Gaussian noise according to a predefined variance schedule. Given the state at the previous step, Gaussian perturbations are iteratively applied until the input is indistinguishable from standard normal noise. - **Reverse process ($p_\theta$):** A parameterized neural network trained to invert the corruption trajectory, stepping backward from noisy states to less noisy states.

In practice, the model is trained with an $L_2$ regression loss, learning to predict the specific noise vector that was added to a corrupted sample. Once trained, this enables the network to systematically subtract estimated noise and reconstruct clean samples. Having established how continuous diffusion operates in image domains, Amidi sets up the guiding question for the next segment: how can these mathematical tools, built entirely around continuous Gaussian perturbations, be transferred to discrete text tokens?

[26:07](https://www.youtube.com/watch?v=rkByitBwAQo&t=1567s) Continuous Diffusion for Text and Embedding-Space Noise

To bridge the gap between image generation and language, the instructor poses the fundamental question: what is the text equivalent of a noisy image in a continuous space? Since raw text is composed of discrete tokens, one natural idea is to represent tokens via their continuous embedding representations—vectors of floating-point numbers in a $D$-dimensional space. By concatenating the token embeddings across a sequence of length $L$, the entire text sequence can be represented as a continuous matrix of dimension $D \times L$.

```mermaid flowchart LR accTitle: Continuous Diffusion Workflow for Text accDescr: Diagram illustrating continuous forward noising and reverse denoising with nearest neighbor lookup. subgraph Forward ["Forward Process"] A["Clean Text Embeddings (x0)"] -->|"Add Gaussian Noise"| B["Partially Noisy Matrix (xt)"] B -->|"Iterative Noise"| C["Pure Noise Matrix (xT)"] end subgraph Reverse ["Reverse Process"] C -->|"Learned Denoising"| D["Denoised Matrix (x0 hat)"] D -->|"Nearest Neighbor Lookup"| E["Discrete Tokens"] end ```

Using this continuous matrix representation, one can mimic the standard forward diffusion process used in computer vision. Starting from clean text embeddings ($x_0$), Gaussian noise (drawn iteratively from a normal distribution) is added at each discrete step $t$ through $x_{t-1}, x_t$, all the way to $x_T$, until the matrix degrades into complete noise. A model is then trained to learn the reverse process: removing the noise step by step to recover the clean embedding matrix.

However, continuous diffusion faces a major round-trip conversion challenge. While mapping from a discrete token to an embedding is straightforward (a simple table lookup), mapping a continuous vector back to a discrete token is unnatural: - Nothing guarantees that an intermediate or denoised continuous vector corresponds to any valid token embedding; it may land in an empty or meaningless region of the high-dimensional space. - The standard mapping back to vocabulary space requires performing a nearest-neighbor search to find the closest token embedding to each vector in the denoised matrix.

---

[31:05](https://www.youtube.com/watch?v=rkByitBwAQo&t=1865s) Limitations of Continuous Diffusion in Text

The instructor highlights three major theoretical and practical limitations that make continuous text diffusion challenging: 1. **Curse of Dimensionality and Empty Space:** Token embedding spaces typically have thousands of dimensions. In such vast spaces, the vast majority of coordinates do not map to any valid semantic token. 2. **Mismatch in the Objective Function:** Vision diffusion models optimize an $L_2$ regression loss in pixel space. For text, an $L_2$ loss optimizes distance over continuous embedding regions rather than discrete token identities. As the instructor emphasizes: “At the end of the day you don't care about regions of embeddings, you actually care about tokens. So you're not actually optimizing for exactly what you want.” 3. **Semantic Meaning of Gaussian Noise:** Adding Gaussian noise to an image produces a visual corruption that intuitively looks like static or grain. Applying Gaussian perturbations to float vectors in text embeddings does not have a clean semantic corruption analogue.

To mitigate these issues, researchers have proposed techniques such as **clamping**—forcing vectors back to the nearest token embeddings at every denoising step—and encoding entire sequences into a single holistic embedding rather than diffusing independent per-token vectors. Despite these efforts, continuous diffusion remains challenging and inconsistent across the literature, motivating the search for a native, discrete alternative:

> “Can we define a corruption process that actually happens directly in the discrete token space?”

---

[35:11](https://www.youtube.com/watch?v=rkByitBwAQo&t=2111s) Discrete Diffusion and the Categorical Distribution

Rather than projecting tokens into continuous vector spaces and adding Gaussian float perturbations, discrete diffusion operates directly on the discrete token space. The forward process $q$ corrupts the clean token sequence directly by swapping or replacing tokens according to a categorical distribution.

```mermaid flowchart LR accTitle: Discrete Token Corruption Process accDescr: Showing how tokens transition between states via a transition matrix. A["Discrete Token i"] -->|"Transition Matrix Qt"| B{"Categorical Choice"} B -->|"Probability 1 - p"| C["Keep Token i"] B -->|"Probability p"| D["Replace with [MASK]"] ```

The instructor clarifies the notation of the categorical distribution (`Cat`), explaining it as a probability distribution over a finite set of $N$ discrete outcomes: - If there are three mutually exclusive choices with probabilities $0.4$, $0.4$, and $0.2$, each choice is sampled according to its assigned probability weight. - In the context of discrete text diffusion, the categorical distribution governs the transition probabilities of whether an individual token stays the same or transforms into another token at time step $t$. - This process is formalized through a transition matrix, denoted $Q_t$, which defines the conditional probability $q(x_t = j \mid x_{t-1} = i)$ of token $i$ transitioning to token $j$ at time step $t$.

---

[38:01](https://www.youtube.com/watch?v=rkByitBwAQo&t=2281s) Corrupting Tokens via Masking

When defining what constitutes "noise" directly within vocabulary space, researchers have explored two primary strategies: 1. Swapping a token with a uniformly random token drawn from the entire vocabulary. 2. Replacing the token with an explicit `[MASK]` token, drawing inspiration from masked language modeling architectures like BERT.

The lecture focuses on the masking paradigm. Under this formulation, corrupting an input sequence does not require adding continuous values or random words that disrupt syntax haphazardly; rather, each token has a specific probability—governed by the transition matrix $Q_t$—of being replaced by the `[MASK]` token at each discrete step $t$. The reverse generative model then learns to reconstruct the original tokens behind the masks across the sequence.

[39:47](https://www.youtube.com/watch?v=rkByitBwAQo&t=2387s) Discrete Diffusion and the Masking Transition Matrix

At time step $t = 0$, the process begins with a completely clean token sequence. Noise is applied progressively across discrete steps until reaching time step $T$, where the sequence is entirely corrupted. The forward transition between time steps is modeled through a transition matrix of dimensionality $|\mathcal{V}| \times |\mathcal{V}|$, where $|\mathcal{V}|$ denotes the size of the vocabulary. For any time step $t \in [0, T]$, the transition matrix dictates the probability of a token $i$ corrupting into a token $j$. Because every entry in this matrix represents a transition probability, all values strictly fall within the interval $[0, 1]$.

```mermaid flowchart LR accTitle: Forward Discrete Transition Matrix Process accDescr: Clean tokens transition to a masked absorbing state via discrete corruption steps.

subgraph StepT0["t = 0"] A["Clean Token x₀"] end

subgraph StepT["t - 1 to t"] B["Keep token: 1 - βₜ"] C["Corrupt to [MASK]: βₜ"] end

subgraph StepBigT["t = T"] D["Absorbing State [MASK] (Prob = 1.0)"] end

A --> B A --> C C --> D D -->|"Remains masked"| D ```

This theoretical framework draws directly from foundational literature on discrete denoising diffusion probabilistic models, specifically the D3PM paper (*Discrete Denoising Diffusion Probabilistic Models*). In this setup, noise is concretely instantiated as the special token `[MASK]`. The vocabulary includes standard semantic words—such as "a", "bear", or "cute"—alongside this designated mask token:

- **Clean Token Transition**: For any regular (clean) token, there is a probability $\beta_t$ of being corrupted into the `[MASK]` token at step $t$, and a complementary probability $1 - \beta_t$ of remaining unchanged from step $t-1$ to $t$. - **Absorbing State Property**: If a token is corrupted into `[MASK]` at any step, it remains `[MASK]` for all subsequent steps with probability $1.0$.

The lecturer underlines this property: “So by the way, that's the reason why we are saying that this formulation is an absorbing state formulation because when a token is corrupted to the mask token, it stays there. So it is absorbing.”

---

[43:29](https://www.youtube.com/watch?v=rkByitBwAQo&t=2609s) Mathematical Formalization of Forward Masking ($\alpha_t$)

In practice, working directly with individual single-step transition probabilities $\beta_t$ becomes unwieldy when calculating multi-step marginals. Instead, it is far more convenient to work with a composite quantity, $\alpha_t$, defined as the probability that an original token remains unmasked all the way from time step $0$ through time step $t$. Under the assumption of independent random masking applied at each intermediate transition, $\alpha_t$ accumulates as the running product of the non-corruption probabilities:

$$\alpha_t = \prod_{k=1}^t (1 - \beta_k)$$

Using the notation $x_0^i$, where the subscript $0$ denotes a clean original state and the superscript $i$ indicates the $i$-th token index of the sequence: 1. The conditional probability that token $i$ at time $t$ matches the original token $x_0^i$ is given by $\alpha_t$. 2. The conditional probability that token $i$ has transitioned to `[MASK]` at time $t$ is $1 - \alpha_t$. 3. For any intermediate step $s < t$, if token $i$ is already masked at step $s$ ($x_s^i = \text{[MASK]}$), the probability that it remains masked at the later step $t$ ($x_t^i = \text{[MASK]}$) is exactly $1$.

The progressive corruption is illustrated using the running sentence example `"a teddy bear is reading"`. At the initial step $t = 0$, the sequence is fully intact. Moving forward through time, individual tokens independently succumb to corruption: `"a"` might be replaced by `[MASK]`, while other tokens remain intact. In the next step, `"a"` stays masked due to the absorbing constraint, while another token in the sequence gets masked. Repeating this step by step causes the mask tokens to accumulate relentlessly until the entire sequence is masked out at $t = T$.

Responding to a question from the audience regarding whether the total horizon $T$ is fixed, the lecturer confirms that it is predetermined at the start of the process. While this formulation utilizes discrete time steps $t \in [0, T]$, other conventions in the literature scale time continuously between $0$ and $1$. Both approaches simply represent lower and upper bounds of the corruption trajectory.

---

[48:58](https://www.youtube.com/watch?v=rkByitBwAQo&t=2938s) The Reverse Process Objective and the Limits of Autoregression

The fundamental objective of masked diffusion models is to invert the corruption pipeline. While the forward process $q$ methodically destroys structure by adding noise according to known probabilities, the neural network parameterized by $\theta$ must learn a reverse process, denoted $p_\theta$, capable of taking a completely masked sequence and iteratively denoising it back into coherent text.

```mermaid flowchart LR accTitle: Forward Corruption Versus Reverse Generation accDescr: Comparison of the forward corruption process q and the learned reverse denoising process p_theta.

subgraph Forward["Forward Process q (Known)"] F0["Clean text x₀"] -->|"Progressive masking"| FT["Complete noise x_T"] end

subgraph Reverse["Reverse Process p_θ (Learned)"] RT["Complete noise x_T"] -->|"Iterative denoising"| R0["Clean text x₀"] end ```

To learn the parameter weights $\theta$, standard modeling defaults to first principles via Maximum Likelihood Estimation (MLE) on the clean training sequences $x_0$, seeking parameters that maximize the log-likelihood:

$$\arg\max_\theta \log p_\theta(x_0)$$

In classic autoregressive language modeling, this likelihood factorizes cleanly using the probability chain rule across token positions:

$$p_\theta(x_0) = \prod_{i=1}^L p_\theta(x_0^i \mid x_0^{<i})$$

Because autoregressive models are explicitly parameterized to predict the immediate next token given all preceding left-to-right context ($x_0^{<i}$), the derivation of the standard cross-entropy loss function follows directly from this decomposition.

In masked diffusion models, however, this standard autoregressive decomposition breaks down completely. The generation is non-autoregressive and multi-directional, meaning the exact marginal likelihood $p_\theta(x_0)$ cannot be computed via the standard left-to-right chain rule. The speaker emphasizes this divergence from standard causal models: “You cannot derive the loss in the same way because we said that we did not want to do autoregressive generation.” Consequently, training a diffusion model demands an alternative, tractable surrogate objective to optimize the reverse trajectory.

- **Forward Process ($q$)**: Fixed, parameter-free corruption schedule moving from clean data $x_0$ to noise $x_T$. - **Reverse Process ($p_\theta$)**: Learned parametric denoising model reconstructing $x_0$ from $x_T$. - **Autoregressive Limitation**: The causal factorization $p_\theta(x_0^i \mid x_0^{<i})$ cannot be applied when generating all sequence tokens through iterative unmasking steps.

[54:01](https://www.youtube.com/watch?v=rkByitBwAQo&t=3241s) Formulating the Objective Across Noise Levels

Because diffusion models do not predict sequences token by token in an autoregressive fashion, the training loss cannot be formulated as a standard autoregressive conditional factorization over token positions. Instead, the process works by iteratively denoising an input to step from total noise back to a clean state. The goal is to parameterize a model $p_\theta$ that takes a more heavily noised sequence $x_t$ and learns to recover a less noised sequence $x_{t-1}$. To formulate a learning objective around this denoising mechanism, the instructor demonstrates that the probabilistic chain rule can still be applied—not across spatial token indices, but across temporal noise levels.

```mermaid flowchart LR accTitle: Denoising Trajectory and Markov Assumption accDescr: Reverse diffusion trajectory from pure noise to clean data under the Markov assumption. subgraph Reverse["Reverse Denoising Process"] direction LR XT["x_T (Pure Noise)"] -->|"p_theta(x_{T-1} | x_T)"| XT1["x_{T-1}"] XT1 -.->|"p_theta(x_{t-1} | x_t)"| Xt["x_t"] Xt -.->|"p_theta(x_0 | x_1)"| X0["x_0 (Clean Data)"] end ```

To express the likelihood of the clean data sequence $p_\theta(x_0)$ in terms of its corrupted intermediate versions, one can begin with the joint probability distribution over the entire trajectory $p_\theta(x_0, x_1, \dots, x_T)$, where $x_1, \dots, x_T$ represent progressively noised states up to maximum noise step $T$. By marginalizing (summing or integrating) across all intermediate trajectories $x_1$ through $x_T$, one recovers $p_\theta(x_0)$. Applying the chain rule of probability decomposes this joint distribution into the prior probability of pure noise $p_\theta(x_T)$ multiplied by a product of conditional transitions:

$$p_\theta(x_0, x_1, \dots, x_T) = p_\theta(x_T) \prod_{t=1}^{T} p_\theta(x_{t-1} \mid x_t, \dots, x_T)$$

To make this reverse process tractable, the instructor invokes the Markov assumption: the distribution of the less noisy state $x_{t-1}$ is assumed to depend strictly on the immediately preceding, more noisy state $x_t$, allowing the model to discard all subsequent noise states from $x_{t+1}$ to $x_T$. As the instructor explains: “So this is by the way called the Markov assumption where you only assume that current state is just a function of another state but not the ones that happened before that.”

[58:34](https://www.youtube.com/watch?v=rkByitBwAQo&t=3514s) The Intractability Dilemma and the Four-Step Strategy

While decomposing $p_\theta(x_0)$ by marginalizing across all possible trajectories $x_1$ through $x_T$ is mathematically exact, it presents an insurmountable computational bottleneck. In practice, summing over every intermediate sequence configuration across $T$ timesteps involves an astronomically large, virtually infinite number of trajectory combinations. Consequently, the true marginal likelihood $p_\theta(x_0)$ is completely intractable to evaluate or differentiate directly.

```mermaid flowchart TD accTitle: Four-Step Roadmap to a Tractable Loss accDescr: High-level overview of the four-step strategy to derive a tractable diffusion loss. S1["Step 1: Construct Lower Bound (ELBO) via Jensen's Inequality"] S2["Step 2: Factor Trajectories using Known Forward Distribution q"] S3["Step 3: Expand and Simplify Loss into Per-Step Divergences"] S4["Step 4: Sample Trajectories to Train Network Parameters"] S1 --> S2 --> S3 --> S4 ```

To train a neural network, one requires a computable loss function that measures performance and produces informative gradients for updating the weights $\theta$. The instructor outlines a four-step derivation roadmap to bridge the gap between the intractable ideal objective and a practical training signal: “All that to say that this four step plan is for us to get a loss that is tractable for us to compute and that is telling us that we're optimizing things in a way that makes sense with respect to the objective that we care about, which is to find parameters $\theta$ that maximize the probability of us seeing the training data.” Rather than getting lost in exhaustive mathematical minutiae immediately, the focus remains first on the overarching conceptual intuition before diving into the formal mechanics.

- The fundamental goal of the loss derivation is to find model weights $\theta$ that maximize the likelihood of the empirical training data $x_0$. - Directly computing $\sum_{x_{1:T}} p_\theta(x_0, x_1, \dots, x_T)$ fails because the state space across all sequence lengths and masking configurations is far too vast. - The four-step strategy systematically massages the intractable objective into an expectation that can be estimated through Monte Carlo sampling.

[01:01:37](https://www.youtube.com/watch?v=rkByitBwAQo&t=3697s) Derivation of the ELBO via Jensen's Inequality

When directly optimizing an intractable likelihood is impossible, the standard variational technique used across the diffusion literature is to maximize a tractable lower bound instead. If a surrogate function is proven to lie strictly below the true target quantity, pushing that lower bound upward will naturally pull the actual target along in the same direction. To construct this bound, the instructor introduces the predefined forward corruption process $q(x_1, \dots, x_T \mid x_0)$. Because $q$ is fully specified by user-defined masking probabilities—where each token has probability $1 - \alpha_t$ of being masked at step $t$ and probability $\alpha_t$ of remaining unmasked—it is completely known and efficient to sample from.

The instructor rewrites the marginal distribution $p_\theta(x_0)$ by multiplying and dividing the integrand by $q(x_{1:T} \mid x_0)$, converting the intractable sum over trajectories into an expectation under the known forward process:

$$p_\theta(x_0) = \int p_\theta(x_{0:T}) \, dx_{1:T} = \int q(x_{1:T} \mid x_0) \frac{p_\theta(x_{0:T})}{q(x_{1:T} \mid x_0)} \, dx_{1:T} = \mathbb{E}_{q(x_{1:T} \mid x_0)} \left[ \frac{p_\theta(x_{0:T})}{q(x_{1:T} \mid x_0)} \right]$$

Since the training objective is to maximize log-likelihood $\log p_\theta(x_0)$, applying Jensen's inequality across the concave logarithm function allows the log operator to slip inside the expectation:

$$\log p_\theta(x_0) = \log \mathbb{E}_{q(x_{1:T} \mid x_0)} \left[ \frac{p_\theta(x_{0:T})}{q(x_{1:T} \mid x_0)} \right] \ge \mathbb{E}_{q(x_{1:T} \mid x_0)} \left[ \log \frac{p_\theta(x_{0:T})}{q(x_{1:T} \mid x_0)} \right]$$

This resulting lower bound constitutes the Evidence Lower Bound (ELBO). While the expression may still look formidable on the board, replacing an intractable deterministic summation with an expectation over a known sampling distribution $q$ is what unlocks tractability. As the instructor emphasizes: “And that is our lower bound, which still is scary, but it is a lower bound that we have shown here that is actually tractable.” By sampling corruption trajectories from $q$, the model can optimize the bound during training.

- The forward distribution $q(x_t \mid x_{t-1})$ is fully known and governed by the retention schedule $\alpha_t$. - Multiplying and dividing by $q(x_{1:T} \mid x_0)$ acts as an importance sampling reformulation over the intermediate latent trajectory $x_{1:T}$. - Jensen’s inequality guarantees that $\log \mathbb{E}[Z] \ge \mathbb{E}[\log Z]$ because the logarithm is strictly concave, yielding the variational lower bound on data log-likelihood.

[01:09:09](https://www.youtube.com/watch?v=rkByitBwAQo&t=4149s) Tractability of the ELBO and KL Divergence

To make the Evidence Lower Bound (ELBO) usable for training diffusion models, it must be mathematically tractable to compute. As a foundational reminder, measuring the distance between two probability distributions $P$ and $Q$ is achieved using Kullback-Leibler (KL) divergence, defined in the discrete case as:

$$D_{\mathrm{KL}}(P \parallel Q) = \sum_i P_i \log\left(\frac{P_i}{Q_i}\right)$$

This quantity is non-negative ($D_{\mathrm{KL}} \ge 0$) and equals zero if and only if the two distributions are identical, with an analogous definition holding for continuous distributions. Sparing the class the tedious algebra, expanding the ELBO reveals an objective expressed as a sum of KL divergences between the true forward trajectory posterior $q$ and the parameterized reverse process $p_\theta$:

$$D_{\mathrm{KL}}\!\left(q(x_{t-1}^i \mid x_t^i, x_0^i) \;\parallel\; p_\theta(x_{t-1}^i \mid x_t)\right)$$

Here, $q$ represents the probability distribution of token index $i$ at step $t-1$ conditioned on both its noisier counterpart $x_t^i$ and its clean starting state $x_0^i$, while $p_\theta$ is the neural model's parameterized reverse step attempting to estimate $x_{t-1}^i$ conditioned only on the noisier sequence $x_t$. The speaker promises: “And we're going to show that the ELBO, which is the quantity that is on the right side, is something that is tractable for you to compute.”

```mermaid flowchart LR accTitle: Masked Diffusion Forward and Reverse Process accDescr: Comparison of true forward posterior conditioned on clean data against the parameterized reverse estimate. subgraph Forward Posterior ["Forward Posterior (Tractable Ground Truth)"] Clean["Clean Token: x₀ⁱ"] Noisy["Noisy Token: xₜⁱ"] Target["Posterior: q(x_{t-1}ⁱ | xₜⁱ, x₀ⁱ)"] Clean --> Target Noisy --> Target end

subgraph Reverse Estimation ["Model Reverse Process"] InputSeq["Noisy Sequence: xₜ"] ModelEst["Model: p_θ(x_{t-1}ⁱ | xₜ)"] InputSeq --> ModelEst end

Target -.->|"Minimize KL Divergence"| ModelEst ```

---

[01:11:52](https://www.youtube.com/watch?v=rkByitBwAQo&t=4312s) Computing the Forward Step Posterior $q(x_{t-1} \mid x_t, x_0)$

Evaluating the KL divergence requires deriving the exact distribution of $q(x_{t-1}^i \mid x_t^i, x_0^i)$. If the token $x_t^i$ at noise level $t$ is unmasked, its state at time $t-1$ is deterministic: it must also be unmasked, because tokens once masked can never become unmasked in the forward process. However, if $x_t^i$ is masked at time $t$, it could have either been newly masked at step $t$ or already masked at step $t-1$.

By standard conditional probability:

$$q(x_{t-1}^i, x_t^i \mid x_0^i) = q(x_{t-1}^i \mid x_t^i, x_0^i) \cdot q(x_t^i \mid x_0^i)$$

By definition, the marginal probability of a token being masked at time step $t$ given $x_0^i$ is $1 - \alpha_t$. When evaluating the joint event where $x_{t-1}^i = [\mathrm{MASK}]$ and $x_t^i = [\mathrm{MASK}]$, observing that a token masked at $t-1$ remains masked at $t$ with probability 1 allows simplifying the joint probability to simply $q(x_{t-1}^i = [\mathrm{MASK}] \mid x_0^i) = 1 - \alpha_{t-1}$. Rearranging yields:

$$q(x_{t-1}^i = [\mathrm{MASK}] \mid x_t^i = [\mathrm{MASK}], x_0^i) = \frac{1 - \alpha_{t-1}}{1 - \alpha_t}$$

The complement—the probability that the token was still its clean value at $t-1$ and transitioned to masked exactly at $t$—is $1 - \frac{1 - \alpha_{t-1}}{1 - \alpha_t}$. Denoting this transition term as $r_t$, the token can only take one of two states at step $t-1$ (either masked with probability $1 - r_t$, or clean with probability $r_t$). As the speaker notes: “Because we had said that if you mask a token, then all the following time steps it's also masked.”

---

[01:19:04](https://www.youtube.com/watch?v=rkByitBwAQo&t=4744s) Parameterizing $p_\theta$ and Deriving the Training Objective

Because the true posterior $q$ is fully determined by the noise schedule coefficients $\alpha_t$ and $\alpha_{t-1}$, parameterizing the reverse process $p_\theta(x_{t-1}^i \mid x_t)$ becomes straightforward. If $x_t^i$ is not masked, $x_{t-1}^i$ remains unmasked. If $x_t^i$ is masked, the model uses a neural network $\pi_\theta(x_0^i \mid x_t, t)$ to predict the distribution over the original clean token $x_0^i$, and plugs this estimate directly into the reverse distribution.

Substituting these forms into the KL divergence simplifies the ELBO into a weighted cross-entropy loss that forces the model to predict the original clean token given the corrupted sequence:

$$\mathcal{L} \propto - \log \pi_\theta(x_0^i \mid x_t, t)$$

In practice, the discrete time index $t \in \{0, \dots, T\}$ is often rescaled to a continuous interval $t \in [0, 1]$. Under a linear noise schedule where the unmasked probability is $\alpha_t = 1 - t$ (meaning the probability of any token being masked is exactly $t$), the loss weights simplify considerably into clean analytical coefficients such as $-\frac{1}{t}$. Summarizing the outcome of these derivations, the speaker emphasizes: “if you take some assumptions, then you can derive a loss function that is going to allow you to train a model that is going to generate tokens in a diffusion way.”

- **Rescaled noise index**: Time $t$ is mapped from discrete steps to a normalized interval $[0, 1]$. - **Linear noise schedule**: $\alpha_t = 1 - t$, making the masking probability exactly equal to $t$. - **Model objective**: The network $\pi_\theta$ takes corrupted sequence $x_t$ and scalar time $t$ as inputs to predict the categorical logits of the clean target token $x_0$.

---

[01:23:02](https://www.youtube.com/watch?v=rkByitBwAQo&t=4982s) Practical Training Pipeline

Moving from theoretical derivations to real-world implementation, training a masked diffusion language model follows a direct procedural recipe. The model is trained to reverse corruption across arbitrary noise levels rather than sequentially autoregressively unrolling one token at a time.

The practical training procedure begins by drawing a random noise level $t \sim \mathcal{U}(0, 1)$ for a given clean training sequence $x_0$. Based on $t$, a corresponding fraction of tokens within the sequence is randomly replaced with the $[\mathrm{MASK}]$ token according to the noise schedule $\alpha_t$, producing the corrupted input $x_t$. The speaker opens the implementation discussion: “The first step is to actually sample the noise level and so here is between zero and one.”

[01:23:23](https://www.youtube.com/watch?v=rkByitBwAQo&t=5003s) Training and Inference in Masked Diffusion Models

Afshine Amidi wraps up the derivation of the training workflow before walking through the step-by-step mechanics of running inference on a diffusion language model. During training, the process is streamlined into three recurring steps: first, every token in a clean sequence is corrupted by being replaced with a mask token according to a noise probability schedule $t$. Second, the corrupted sequence is passed through an encoder-based neural network tasked with predicting what original tokens were obscured under the masks. Third, those predictions are evaluated using the simplified loss derived from the evidence lower bound (ELBO), gradients are backpropagated, and the model weights are updated repeatedly across iterations:

> “That is your training process.”

```mermaid flowchart LR accTitle: Diffusion LLM Inference Loop accDescr: Iterative denoising loop from pure mask noise to final revealed sequence via partial commitment and remasking.

subgraph Input ["Initial State"] A["Pure Noise:<br/>All Mask Tokens"] end

subgraph Step ["Denoising Step t"] B["Diffusion LLM<br/>Predicts Tokens"] C{"Probabilistic<br/>Filter"} D["Committed<br/>Tokens (r_t)"] E["Remasked<br/>Tokens (1 - r_t)"] end

subgraph Output ["Final State"] F["Fully Revealed<br/>Text Output"] end

A --> B B --> C C -->|"High confidence / rate"| D C -->|"Remask rate"| E E --> B D -->|"Iterate until t = 0"| F ```

Inference reverses this corruption trajectory to generate entirely new text from scratch. The model begins with an input sequence consisting exclusively of noise—meaning every single position is filled with a mask token. When this completely masked sequence is passed into the diffusion LLM, the model outputs predicted clean token distributions for all positions simultaneously. However, because the learned reverse transition probabilities dictate that a token stays masked with probability $1 - r_t$ and transitions to an unmasked candidate with probability $r_t$, the model cannot simply commit to all its initial predictions at once. Instead, a subset of the predicted positions is purposefully remasked, while the model commits to only a fraction of the most reliable tokens. This yields an intermediate sequence that is noticeably less noisy than the pure mask input. The partially resolved sequence is then fed right back into the model to predict the remaining masked positions, repeating the cycle of predicting, selectively remasking, and committing until the final timestep is reached and the complete, coherent sequence is unmasked.

- **Training Step 1:** Corrupt the sequence by masking each token independently with probability $t$. - **Training Step 2:** Pass the masked sequence through the model to predict the original corrupted tokens. - **Training Step 3:** Compute the loss, backpropagate error gradients, and update model parameters. - **Inference Initiation:** Start with an input sequence composed entirely of mask tokens (`[MASK]... [MASK]`). - **Iterative Denoising:** Unmask candidate tokens using probability $r_t$, remask the remaining fraction with probability $1 - r_t$, and feed the refined sequence back into the model across successive diffusion steps until generation is complete.

---

[01:26:24](https://www.youtube.com/watch?v=rkByitBwAQo&t=5184s) Architectural Parallels and Distinctions: Diffusion vs. BERT

Taking over the lecture, Shervine Amidi steps in to explore the intuition, failure modes, and practical properties of masked diffusion. He addresses an immediate observation students often raise: the structural resemblance between masked diffusion models and the bidirectional encoder architecture of BERT introduced earlier in the course. In both cases, an encoder receives text peppered with mask tokens and leverages a projection head to predict the underlying vocabulary elements. Yet, as Shervine emphasizes, their foundational purposes and mechanics diverge completely:

> “BERT was just a pretext to learn about language. We didn’t actually care about the unmasked response that we’re going to get. We just wanted to use the excuse of this loss function to make the weights of the encoder learn something useful for other tasks. But here, generation is our primary goal.”

Beyond the difference in end goals, the operational frameworks differ in step depth and masking schedules. While BERT is strictly a single-step model designed purely for feature extraction and downstream fine-tuning, masked diffusion relies on an iterative trajectory across $T$ discrete timesteps to progressively sculpt coherent text. Furthermore, BERT relies on a static masking recipe—famously holding the corruption rate fixed at 15% of the input tokens—whereas masked diffusion systematically varies the noise level across a continuous continuum, moving dynamically from 100% masked noise down to zero.

| Dimension | BERT (Masked Language Modeling) | Diffusion Language Models | |:--- |:--- |:--- | | **Primary Objective** | Representation learning / Pretext task | Autoregressive-free text generation | | **Decoding Steps** | Single-step forward pass ($T = 1$) | Multi-step iterative refinement ($T$ steps) | | **Masking Strategy** | Fixed empirical ratio (15% masked) | Dynamic schedule ($100\%$ noise down to $0\%$) | | **Output Utilization** | Internal representations fine-tuned on tasks | Clean decoded token text emitted to user |

---

[01:28:22](https://www.youtube.com/watch?v=rkByitBwAQo&t=5302s) Parallel Decoding Failure Modes and the Need for Remasking

Shervine illustrates what happens when the number of diffusion steps $T$ is kept small and the model is forced to decode multiple interdependent tokens concurrently. Using the recurring class example of a reading teddy bear, he presents a sentence skeleton where both the noun number and verb agreement are masked simultaneously: *"The teddy [mask] [mask] reading."* In standard English, there are two valid ways to resolve this: singular (*"The teddy bear is reading"*) or plural (*"The teddy bears are reading"*).

Because the encoder samples representations across positions in parallel without conditioning each choice on the other position's simultaneous draw, the model can easily pick the plural noun alongside the singular verb:

> “So you could well come into a case where you have the teddy bears is reading, which is bad.”

To remedy these parallel generation collisions, diffusion models introduce remasking mechanisms that renegotiate previously committed tokens. By deliberately re-introducing masks onto already selected tokens in subsequent timesteps, the model allows a position to observe the newly committed words in its surrounding context and auto-correct grammatical clashes. However, doing this purely at random introduces fresh instability: the model might remask an unproblematic word like *"teddy"* instead of resolving the clash between *"bears"* and *"is"*, potentially steering the entire sentence into incoherence.

```mermaid flowchart TD accTitle: Parallel Decoding Clash and Remasking accDescr: Parallel sampling leads to agreement conflict, resolved through contextual remasking.

subgraph Independent Sampling ["Independent Parallel Prediction"] A["Context: The teddy [?] [?] reading"] --> B["Token 1 sampled: 'bears'"] A --> C["Token 2 sampled: 'is'"] end

subgraph Failure ["Inconsistent Joint State"] B & C --> D["'The teddy bears is reading' (Subject-Verb Mismatch)"] end

subgraph Resolution ["Contextual Remasking"] D --> E["Remask position: 'bears' or 'is'"] E --> F["Re-evaluate conditioned on updated context"] F --> G["Consistent Output: 'bears are' OR 'bear is'"] end ```

- **Root Cause of Clashes:** Tokens decoded simultaneously in parallel lack awareness of one another's stochastic sampling outcomes. - **Agreement Errors:** Models generate locally valid but globally incompatible pairs (e.g., singular verb with plural subject). - **Remasking as Auto-Correction:** Overwriting committed tokens gives the network another pass to condition on finalized neighbors. - **Hazard of Random Remasking:** Tossing masks at random risks erasing well-chosen tokens and injecting further errors.

---

[01:31:38](https://www.youtube.com/watch?v=rkByitBwAQo&t=5498s) Confidence-Based Resampling vs. Context-Aware Classifiers

To avoid the pitfalls of blind random remasking, one intuitive strategy is to inspect model confidence: use the predicted token's probability score under the model distribution and remask tokens where confidence is lowest. Shervine walks through this thought experiment, showing why naive confidence scoring falls apart under parallel sampling conditions:

> “The thing is if you have the problem of generating tokens together, then maybe that each token separately with stale context will have still a high probability.”

In the *"teddy bears is"* scenario, when both slots are masked, the token *"bears"* evaluates to a high conditional probability given solely the surrounding stale context (*"BOS"*, *"the"*, *"teddy"*, and *"reading"*). Simultaneously and under that exact same partial context, the token *"is"* also scores a very high probability. Because both tokens independently register high confidence against the stale backdrop, a simple confidence threshold fails to flag either token as erroneous.

To overcome this structural limitation, contemporary research trains auxiliary classifiers or energy functions specifically tasked with judging the probability of a token occurring given the freshly updated, fully instantiated context. This external verification allows the system to identify subtle contextual contradictions and selectively remask the offending tokens.

- **Stale Context Illusion:** Masked tokens scored concurrently assign high individual probabilities to mutually contradictory words because neither sees the other's sampled outcome. - **Confidence Trap:** Naive probability thresholds fail to identify joint inconsistencies because each marginal probability appears high. - **Classifier Solutions:** Modern masked diffusion architectures train dedicated contextual classifiers to evaluate the holistic plausibility of completed sequences and guide targeted remasking.

---

[01:33:25](https://www.youtube.com/watch?v=rkByitBwAQo&t=5605s) Inference Speed Trade-offs: Prompt Masking and Autoregressive Comparison

Shervine transitions to analyzing inference latency—frequently cited as the headline selling point for diffusion models over autoregression due to their ability to emit multiple tokens per forward pass. To test this advantage, he posits a challenging "worst-case scenario" for diffusion: an inference prompt consisting of a very long user query paired with a very short expected completion.

Before posing the comparison to the class, a student asks for clarification on whether the user prompt itself undergoes masking during diffusion generation. Shervine clarifies that the prompt functions strictly as an uncorrupted prefix, mirroring standard autoregressive setups:

> “When you are a user and you use a diffusion LLM, you will ask for something and you want that response to anchor on it, which is why it doesn’t get masked. The response will have bidirectional attention on this input.”

With the setup clarified, Shervine asks the room to determine which architecture will generate the short completion faster under these conditions: standard autoregressive generation or the diffusion model. The lecture concludes this segment with an audience member correctly identifying that the autoregressive model wins in this specific regime, setting up the deeper computational breakdown of KV caching and bidirectional attention costs.

- **Prompt Conditioning:** The input prompt remains unmasked and static, providing an uncorrupted anchor. - **Attention Pattern:** Generated response tokens attend bidirectionally across the user prompt while denoising. - **Worst-Case Scenario Setup:** A large context prefix paired with a very brief target output tests whether multi-step bidirectional processing can outpace standard autoregression.

[01:35:10](https://www.youtube.com/watch?v=rkByitBwAQo&t=5710s) First-Principles Latency: Autoregression vs. Diffusion LLMs

To understand which model is truly faster, one must break down the generation time from first principles. In standard autoregressive generation, inference consists of two phases: a parallel prefill phase (teacher forcing) where the prompt's key and value representations are computed and cached, followed by a sequential generation phase that computes one token at a time across a number of forward passes equal to the output response length. In contrast, diffusion LLMs do not separate prefill and generation; they take the prompt combined with noise and refine it into an answer over a fixed schedule of $T$ diffusion steps.

When comparing computational orders of magnitude, a single teacher forcing pass with causal attention matches the general order of magnitude of a diffusion forward pass with bidirectional attention, even with slight architectural differences. However, the per-pass cost diverges sharply during decoding: autoregressive decoding relies on cached keys and values, so each subsequent step only requires causal attention over a single new token, making each pass extremely cheap. Consequently, when the target output sequence is short, autoregressive generation often runs faster than diffusion LLMs. As Afshine Amidi puts it:

> “So at the end of the day, as your intuition guided you, the first choice could be faster in this setting. And we're going to see how we can remedy that in order to make our intuition of making diffusion LLMs be the fastest come true.”

- **Autoregressive latency**: Prefill time (parallel key/value calculation) plus $N$ per-token generation steps, where each generation step has minimal latency due to KV caching. - **Diffusion LLM latency**: Fixed $T$ forward passes (typically tens to hundreds) across the full sequence of prompt plus masked tokens.

```mermaid flowchart TD accTitle: Autoregressive vs Diffusion LLM Inference accDescr: Comparison of latency pipelines between autoregressive decoding and diffusion models. subgraph AR["Autoregressive Model"] A1["Prefill Phase (Prompt KV Cache)"] --> A2["Per-Token Sequential Decoding"] A2 --> A3["Low latency per step via KV cache"] end subgraph DLLM["Diffusion LLM"] B1["Prompt + Noise Input"] --> B2["Iterative Denoising (Fixed T passes)"] B2 --> B3["Full bidirectional pass per step"] end ```

---

[01:37:45](https://www.youtube.com/watch?v=rkByitBwAQo&t=5865s) Reducing DLLM Latency: Prompt Caching and Semi-Autoregressive Blocks

To accelerate diffusion LLMs, researchers target two distinct factors: the execution time per forward pass and the total number of passes. Looking first at the time per pass, standard diffusion architectures maintain fixed prompt tokens, but bidirectional attention causes the prompt's hidden representations to fluctuate whenever unmasked answer tokens update. Studies such as DLLM-Cache show that these representations do not change drastically over time. Therefore, one can compute the prompt representations once (or refresh them on an infrequent cadence $K_p$) rather than recomputing them at every step. Anecdotally, freezing the prompt cache without refreshing can even improve downstream accuracy, likely because partially unmasked, noisy tokens are prevented from corrupting the clean hidden representation of the prompt.

Another optimization bridges the gap between pure bidirectional attention and autoregressive generation: block-level diffusion. Instead of performing global bidirectional diffusion over the entire sequence at once, the target output is split into consecutive blocks. Within any active block, full bidirectional attention operates to diffuse tokens simultaneously. Once a block is fully resolved, its representations are frozen into an exact KV cache, and subsequent blocks attend back to past blocks in a standard causal manner.

- **Prompt Cache Cadence ($K_p$)**: Dictates how frequently prompt token hidden states are refreshed during iterative unmasking; setting $K_p = \infty$ (no refreshing) retains high quality while saving compute. - **Block-by-Block Diffusion**: Generates chunks of tokens with internal bidirectional diffusion while enforcing strictly causal attention across previously resolved blocks.

---

[01:40:42](https://www.youtube.com/watch?v=rkByitBwAQo&t=6042s) Step Distillation: Compressing Denoising Passes

The second lever for reducing diffusion inference latency is compressing the total number of denoising passes $T$. Rather than taking dozens or hundreds of steps, knowledge distillation allows a fast student model to emulate the output of a multi-step teacher in far fewer evaluations.

In step distillation, a teacher model takes two steps to refine tokens, while a student model is trained to match that two-step distribution in a single step. For example, if the teacher resolves a token like `"teddy"` in step one and uses that intermediate context to resolve `"bear"` in step two, the student is trained directly against the resulting distribution. The student benefits because the teacher's target distribution for `"bear"` is already informed by `"teddy"`. By repeating this distillation process iteratively—halving the step budget at each stage—models can produce high-fidelity text in as few as roughly 10 sampling steps.

---

[01:42:39](https://www.youtube.com/watch?v=rkByitBwAQo&t=6159s) Sample Efficiency and Flops: The Training Signal Gap

Examining the training efficiency reveals a major disadvantage for diffusion models compared to autoregressive architectures. In standard autoregressive training, every token in the sequence serves as a supervised target under teacher forcing against real ground-truth inputs, providing a dense, highly informative training signal across the entire sequence in a single forward pass.

In diffusion LLMs, however, an arbitrary forward pass only unmasks a fraction of the sequence, and those unmasked positions must attend to partially noisy or unresolved representations elsewhere. Furthermore, the diffusion loss optimizes an upper bound on negative log-likelihood (via the ELBO) rather than the direct joint likelihood. Consequently, diffusion models extract much less signal per step:

> “And then you see that the typical order of magnitude of compute efficiency is like 10 times less. So you you need 10 times the number of flops to reach a similar loss.”

| Dimension | Autoregressive LLM | Diffusion LLM | |:--- |:--- |:--- | | **Input Context** | Full ground-truth history | Ground truth mixed with masked/noisy tokens | | **Supervision Density** | Dense (loss computed on every token) | Sparse (loss computed only on masked subset) | | **Objective** | Exact joint probability (negative log-likelihood) | Variational bound (ELBO estimate) | | **Compute Efficiency** | High (baseline sample efficiency) | Low (~10× more FLOPs required for similar loss) |

---

[01:45:17](https://www.youtube.com/watch?v=rkByitBwAQo&t=6317s) Hybrid Generation: Speculative Decoding with Diffusion Drafters

To combine the high sample efficiency and verification power of autoregression with the parallel generation capability of diffusion, architectures can leverage speculative decoding. In standard speculative decoding, an efficient draft model proposes several candidate tokens in parallel, which a larger verifier model checks and accepts or rejects in a single step.

Traditionally, the drafting component was itself a small autoregressive model, which preserved the inherent sequential bottleneck during drafting. By replacing the autoregressive draft model with a non-autoregressive diffusion LLM, the system can draft multiple candidate tokens simultaneously in parallel, leaving the primary autoregressive model to verify the proposed candidates in a single causal pass.

[01:46:41](https://www.youtube.com/watch?v=rkByitBwAQo&t=6401s) Conclusion: Strengths, Trade-Offs, and Open Challenges of Diffusion LLMs

The lecture wraps up with a high-level assessment of how discrete diffusion language models compare against the established autoregressive paradigm. As demonstrated throughout the discussion, the outputs produced by these models can match high quality standards, be formally verified, and yield tangible speedups in real-world generation. Graphs benchmarking inference speeds indicate that diffusion models offer a substantially higher per-user throughput or lower single-user latency. However, this advantage comes with an engineering trade-off: it occurs at the expense of batch-level parallelization across multiple requests. Even with that operational drawback, the individual end-user experience can feel significantly faster.

Beyond pure latency, diffusion architecture provides a profound structural advantage: native bidirectionality. Because the model attends to both left and right context simultaneously rather than generating strictly left-to-right, it is purpose-built for fill-in-the-middle tasks. Coding is the prime application where this capability shines, as developers frequently edit, insert, or complete code blocks that are sandwiched between existing functions and classes. In programming workflows where rapid feedback loops are essential, being able to reliably infer missing blocks from bidirectional cues is a major practical win.

```mermaid flowchart TD accTitle: Trade-offs of Diffusion LLMs accDescr: Diagram illustrating the advantages and challenges of diffusion LLMs compared to autoregressive models.

subgraph Advantages ["Advantages"] A["Native Bidirectionality"] --> C["Fill-in-the-Middle (Coding)"] B["Fast Per-User Latency"] --> D["Rapid Feedback Loops"] end

subgraph Challenges ["Challenges & Future Work"] E["Higher Training Cost"] --> G["Reduced Incentive under Fixed Budgets"] F["Batch Parallelization Penalty"] --> H["Research: Porting Autoregressive Wins to DLLMs"] end ```

On the flip side, critical hurdles remain before diffusion language models can fully dethrone autoregressive architectures. The most pressing bottleneck is training efficiency: training diffusion models is noticeably more computationally expensive, which heavily disincentivizes teams operating within fixed compute budgets. The speaker explicitly summarizes the economic friction facing practitioners: “So if you have a given compute budget, you do not have the incentive to go the DLLM way.” Consequently, an active frontier of ongoing research focuses on bridging this gap and porting the well-known optimizations and training efficiencies of autoregressive models over to diffusion language models. With those closing thoughts, the instructor wishes the class a wonderful Thanksgiving break.

- **Inference Latency vs. Throughput**: Diffusion models excel at per-user generation speed, though at the cost of diminished parallelization efficiency across request batches. - **Native Bidirectional Context**: Eliminates artificial prompt engineering for "fill-in-the-middle" generation, making diffusion exceptionally suited for code generation and software development tasks. - **Compute Cost Barrier**: The heightened expense of training diffusion models remains the primary reason large-scale model pre-training still heavily favors autoregressive approaches.

## Notable quotes > [01:26:24](https://www.youtube.com/watch?v=rkByitBwAQo&t=5184s) BERT was just a pretext to learn about language. We didn’t actually care about the unmasked response that we’re going to get. — Shervine Amidi

> [31:05](https://www.youtube.com/watch?v=rkByitBwAQo&t=1865s) At the end of the day you don't care about regions of embeddings, you actually care about tokens. So you're not actually optimizing for exactly what you want.

> [01:33:25](https://www.youtube.com/watch?v=rkByitBwAQo&t=5605s) When you are a user and you use a diffusion LLM, you will ask for something and you want that response to anchor on it, which is why it doesn’t get masked. — Shervine Amidi

## Mentioned Stanford CME295, Afshine Amidi, Shervine Amidi, BERT, DDPM, D3PM, Michelangelo, DLLM-Cache, DLLM

## Video description For more information about Stanford’s graduate programs, visit: https://stanford.io/grad-ed-cme295-A2026

To follow along with the course schedule and syllabus, visit: https://cme295.stanford.edu/syllabus/

Chapters: 00:00:00 Introduction 00:04:01 Limitations of autoregressive paradigm 00:08:57 Motivation behind diffusion 00:20:20 Continuous diffusion 00:34:14 Discrete diffusion 00:38:23 Masking 00:48:55 Objective of masked diffusion 01:01:37 Derivation of ELBO 01:09:24 Loss derivation 01:22:39 Training 01:24:07 Inference 01:26:24 Discussion 01:29:38 Remasking 01:33:24 Inference speed 01:42:38 Training signal 01:46:50 Conclusion

Afshine Amidi is an Adjunct Professor at Stanford University.

Shervine Amidi is an Adjunct Professor at Stanford University.

Follow the playlist: https://youtube.com/playlist?list=PLakGfbKCei80&si=HF2tNywj7nXIQq8X

[Source](https://www.youtube.com/watch?v=rkByitBwAQo)

Reading summary

In Stanford CME295 (Autumn 2026), instructors Afshine and Shervine Amidi argue that diffusion large language models offer a viable alternative to autoregressive architectures by replacing sequential next-token prediction with iterative, bidirectional denoising. While diffusion models decouple inference latency from output sequence length and excel at infilling tasks, they face steep trade-offs in training compute efficiency and parallel decoding stability. Autoregressive Bottlenecks and the Diffusion Alternative (5:06) Standard large language models rely on causal decoder architectures trained on next-token prediction. Because generation proceeds strictly left to right, the number of sequential forward passes scales linearly with the total response length (an O(N) iteration complexity), introducing high latency during extended chain-of-thought reasoning. Causal masking also prevents models from attending to future context, creating structural hurdles for bidirectional editing and infilling tasks, while cascading errors cannot be revised without forward self-correction. Diffusion LLMs bypass these limits by treating generation as an iterative denoising process over an encoder-only transformer backbone. Initializing from complete noise, the model refines an entire sequence simultaneously across a fixed schedule of T diffusion steps. This design decouples generation forward passes from output sequence length, operating with bidirectional attention across all positions at every refinement pass. Discrete Masking Formulations and Objective Derivation (31:05) Adapting continuous image diffusion (such as DDPM, score matching, or flow matching) to text encounters severe hurdles: embedding spaces suffer from the curse of dimensionality, unassigned empty regions, and a misalignment between continuous L2 loss and categorical token identities. Consequently, practical text diffusion shifts directly into discrete token space using transition matrices. Rather than corrupting sequences with continuous Gaussian noise or uniform vocabulary replacements, tokens are progressively replaced by an absorbing [MASK] token governed by a probability schedule alpha_t. Because exact marginal data likelihood across all intermediate corruption trajectories is computationally intractable, training relies on optimizing the Evidence Lower Bound (ELBO) via Jensen's inequality. Expanding the ELBO reduces the objective to a sum of Kullback-Leibler divergences comparing the true forward posterior against the model's parameterized reverse step. Under a rescaled time interval and linear masking schedule, this mathematically simplifies into a tractable weighted cross-entropy loss that trains an encoder network to predict the original tokens under masked slots. Parallel Decoding Collisions and Contextual Remasking (86:24) Unlike BERT, which utilizes a static 15% mask rate strictly as a pretext task for representation learning, diffusion models actively generate text by varying noise levels dynamically from 100% masking to zero. However, forcing an encoder to resolve multiple masked slots simultaneously introduces severe parallel decoding failure modes. For instance, in the prompt 'The teddy [mask] [mask] reading', the model may independently evaluate high probabilities for both the plural noun 'bears' and the singular verb 'is' under stale surrounding context, producing the ungrammatical collision 'The teddy bears is reading'. To resolve these collisions, diffusion architectures introduce remasking mechanisms to renegotiate tentative token selections in subsequent timesteps. Because naive probability thresholds fall into a 'confidence trap'—where mutually contradictory tokens independently register high confidence against unupdated context—contemporary implementations deploy auxiliary context-aware classifiers or energy functions to identify contradictory joint outputs and selectively remask offending positions. Inference Latency, Caching, and Compute Efficiency Diffusion LLMs do not unconditionally surpass autoregressive models in inference speed. In scenarios featuring a long input prompt and a short target completion, autoregressive decoding is faster because prompt key-value representations are prefilled once, leaving individual token generation steps computationally cheap. In contrast, standard diffusion LLMs must reprocess the prompt alongside the output across all bidirectional denoising passes. To mitigate this penalty, implementations use prompt caching (freezing prompt representations across steps) and block-by-block semi-autoregressive diffusion. Additionally, step distillation can halve intermediate sampling passes iteratively to compress generation down to approximately 10 steps. Nevertheless, diffusion models suffer from a significant training signal gap. Under autoregressive teacher forcing, dense supervision is extracted across every token against ground-truth history in a single forward pass. Diffusion models calculate loss only over masked subsets attending to noisy states, requiring an estimated 10 times more FLOPs to achieve a comparable loss level. To combine their respective strengths, hybrid pipelines leverage diffusion models as parallel drafters within speculative decoding, allowing a primary autoregressive model to verify multiple proposed tokens in a single causal pass. Diffusion LLMs provide structural benefits for fill-in-the-middle tasks such as code synthesis and deliver lower single-user latency for long generations. However, their broader adoption remains constrained by high pre-training compute requirements, reduced batch-level parallelization throughput compared to causal decoders, and the algorithmic complexity of managing parallel decoding errors.

Source quotes

[86:24] Shervine Amidi: BERT was just a pretext to learn about language. We didn’t actually care about the unmasked response that we’re going to get. [31:05] At the end of the day you don't care about regions of embeddings, you actually care about tokens. So you're not actually optimizing for exactly what you want. [93:25] Shervine Amidi: When you are a user and you use a diffusion LLM, you will ask for something and you want that response to anchor on it, which is why it doesn’t get masked.

Original transcript

[0:06] Hello everyone and welcome to lecture [0:09] eight of CMU 295. [0:12] So today is a special day because we'll [0:14] be talking about diffusion LLMs [0:17] which is actually a generation paradigm [0:20] that we have not been seeing before. [0:23] And in particular [0:25] these class in 2026 is the first one to [0:30] actually have this topic as a standalone [0:33] lecture [0:34] because it has been gaining an [0:35] importance is in recent years. [0:38] But before we start I just want to give [0:41] a disclaimer that this lecture is going [0:45] to be a little bit more technical than [0:48] what we're used to. [0:50] So I think you recognize this slide [0:52] which is in the same flavor as lecture [0:54] four which was reinforcement learning [0:57] with LLMs. [0:58] So this one is also technical. [1:01] So I highly recommend that if you [1:04] see formulas that you do not get [1:07] intimidated by them [1:09] and that you follow this three-step [1:10] process. So first one [1:13] intuition first, you know, why is a [1:15] certain formula there? [1:17] Second one [1:19] make sure to review the prerequisites [1:21] that are there [1:23] to have you understand [1:25] what is on the slides and in particular [1:27] in this lecture I would say that just [1:30] knowing about probability theory is [1:32] going to be very useful. [1:34] And then the third one is just to [1:36] interpret the formulas from first [1:38] principles, no need to know them by [1:41] heart for most of them. [1:44] So that is the disclaimer. Second [1:46] disclaimer that is not on the slides [1:48] diffusion related papers tend to have [1:52] conventions that vary from paper to [1:54] paper. [1:56] And so that's why [1:58] intuition really [2:00] and [2:02] um yeah, that's the main piece of advice [2:04] that I would have. [2:06] Okay, so with that being said, [2:09] let's start [2:11] by just talking about the kinds of LLMs [2:14] that we've been seeing so far, and in [2:16] particular, what we've been learning in [2:19] terms of their building blocks. [2:22] So if you recall, we spent the first [2:25] lecture talking about the transformer [2:27] architecture [2:29] that we saw [2:31] scaled very well [2:33] as a function of tokens that it is [2:35] trained on [2:37] or as a function of parameter size. [2:40] And this is in particular the backbone [2:44] of modern-day LLMs. [2:46] So that's one, architecture is [2:48] transformer-based. [2:50] And the second thing that we've been [2:52] seeing was that in order to generate the [2:56] output, [2:57] we framed [2:59] all problems as text-to-text problems. [3:03] And in particular, [3:05] once we have [3:06] the text as input, we generate the [3:09] output one token at a time. [3:13] And here we saw that there was this nice [3:16] loss function [3:17] that came from it, that is the [3:19] cross-entropy loss function. [3:22] And here what we're trying to do is to [3:25] maximize the probability of seeing a [3:28] given target token [3:30] given the tokens that happened in the [3:33] past. [3:35] And this lecture is all about revisiting [3:39] the paradigm that we've been seeing. And [3:41] so here there's a special name for that [3:43] paradigm. It is the autoregressive [3:46] paradigm [3:47] that is saying that you generate the [3:49] output one token at a time. [3:52] And every time you generate a token, [3:56] you consider the tokens that have been [3:58] predicted before. [4:01] So [4:03] here, just as a refresher, the way we [4:05] generates responses using the [4:08] autoregressive paradigm is we take [4:12] tokens as inputs. So, let's suppose here [4:14] we want to just generate texts. So, the [4:17] usual convention is to start with a [4:19] special token, which signals that you [4:22] should start to generate the outputs. [4:23] So, here beginning of sequence token [4:27] going to your LLM. And so here you have [4:29] a bunch of operations, attention [4:31] operations, and then you get uh token as [4:33] outputs. [4:35] And then at inference time, what you do [4:37] is you consider the BOS token and the [4:39] newly generated token as input. [4:43] And again, [4:44] you generate the next token. [4:47] And you repeat that [4:49] over and over again until hitting a [4:52] special token that tells you that uh [4:55] you should just stop uh generating your [4:57] sequence. [4:59] So, this is how next token prediction [5:02] works, and this is what we've been [5:03] seeing so far. [5:06] So, [5:07] here you may notice that the number of [5:10] iterations that you need to do [5:13] when you're generating your outputs at [5:15] inference time [5:17] is a function of the number of output [5:20] tokens that you're predicting. [5:23] So, you're doing as many iterations [5:26] as you have output tokens in your [5:29] response. [5:31] And you can think that if you were to [5:34] output, let's say a very very long [5:36] response, [5:37] this can take [5:39] a lot of time. [5:41] And we've been seeing for instance that [5:43] when it comes to reasoning models, [5:46] we have typically a reasoning chain, a [5:48] chain of thought that we need to output [5:51] before outputting a response. [5:53] So, the response length can be [5:55] actually pretty large. [5:58] So, this is the bottleneck [6:01] that we want to address. [6:03] And we want to [6:05] wonder [6:06] if there is not a better way to generate [6:09] the output. Is there a better way other [6:11] than next token prediction? [6:15] So in order to answer that question, [6:18] let's first think about the limitations [6:21] of this approach. So here we saw [6:23] the first one is it is slow [6:26] if your output response is long. [6:29] The second one [6:31] is that next token prediction [6:35] intrinsically [6:36] is actually only looking [6:39] at the tokens that you've been [6:41] predicting so far in order to predict [6:44] the next one. [6:46] And so here when it comes to the [6:47] architecture, [6:48] we've seen that it is transformer-based, [6:50] but not only transformer-based, but [6:52] typically decoder only [6:55] that is leveraging [6:56] the causal attention operation [7:00] that allows your model to take a look at [7:02] the token [7:04] that is currently processing along with [7:06] the past tokens. [7:08] And when it comes to some problems, like [7:11] for instance coding, [7:13] where you need to generate a piece of [7:14] code that may be between [7:18] certain pieces of code, maybe before and [7:20] after it, [7:22] you may find this a bit limiting. [7:25] You may want to actually have access [7:28] to the context that may be before or [7:30] after what you're generating. [7:33] So the fact of only looking [7:36] what's been before that [7:38] can be a limiting factor. [7:41] And then the third one is [7:43] when you're generating your outputs, [7:46] for instance in the previous slide, when [7:47] you're generating your tokens one at a [7:49] time, [7:51] when you predict a token and you want to [7:53] go to the next one, [7:55] the token that you just predicted [7:57] is there. Like there is nothing you can [7:59] do in case you make a mistake. [8:01] So when it comes to [8:04] correcting what you did in the past that [8:07] may have been wrong, there is no way for [8:09] you to correct what you have previously [8:11] generated. [8:12] The only way for you to correct yourself [8:14] is [8:15] by outputting tokens that maybe realign [8:18] yourself in a way that makes more sense. [8:22] So I just want to highlight these three [8:23] limitations. One, it's slow because [8:26] the number of iterations is a function [8:28] of the [8:29] response length. Second one, it only [8:33] looks at what it has generated so far [8:36] and the context before that. [8:38] And the third one is [8:40] if the generation is actually involving [8:44] something that is a mistake, there is no [8:47] way for you to fix what you have [8:49] previously generated. [8:52] So far does that make sense on the [8:54] limitations? Okay. [8:55] So with that being said, [8:57] what we want to do [8:59] is [9:01] to try another way of generating our [9:03] outputs. And in the ML community, most [9:07] of the time when people want to try [9:09] different things, [9:11] what they do is they look at what people [9:13] do in some other adjacent field. [9:17] And so here in this case, let's look at [9:19] how people in the computer vision worlds [9:23] do it. [9:25] So when it comes to [9:27] not generating text but generating [9:29] images, [9:30] you will see, and maybe you may know if [9:32] you have a background in computer [9:34] vision, [9:35] that you actually start [9:38] from [9:40] noise [9:41] in order to generate an image. [9:45] And the way you generate that image [9:47] is by taking into consideration that [9:50] noise [9:51] and by doing some operation that applies [9:54] to the whole input as a whole, holistic [9:58] operations [10:00] in order to get to your output. [10:03] So it is not done in an autoregressive [10:05] way. You are not predicting the pixels [10:07] one at a time. You're doing something [10:09] that takes into consideration the whole [10:11] input [10:13] and you're doing something in between. [10:17] And so by the way, why noise? Because it [10:18] has elegant properties that we're not [10:21] going to go super in depth here, [10:24] but when it comes to training your model [10:28] on [10:29] such a setup, you you have nice [10:31] properties that that come up. [10:35] So [10:36] if that sounds a little bit unnatural to [10:39] you to generate images from noise, [10:43] I want to further motivate [10:45] that way of thinking by just thinking [10:48] about people who make sculptures. [10:51] So let's assume you want to make a [10:53] sculpture, let's say of a teddy bear, [10:56] you would start with some piece of rock [11:00] that maybe you [11:01] ordered. [11:03] And it is typically a rock [11:06] that is uneven on its surface. It it has [11:08] rough edges. It's not something that is [11:12] well made. [11:14] And you can interpret this as noise. [11:17] And [11:19] what you're trying to do when you make [11:20] your sculpture is to think [11:23] of what are the forms that you want to [11:26] sculpt [11:27] and then [11:28] remove the extra pieces of rock [11:32] accordingly [11:33] and obtain [11:35] your end sculpture. [11:37] And so here, if you think about it, [11:40] there is a nice parallel between what I [11:42] just said before on the image generation [11:44] side, which is if you want to generate [11:46] an image, [11:47] you can start from noise and try to [11:50] predict [11:51] what are the noise to remove in order to [11:53] get your final image. [11:57] So you can think of it as making a [11:59] sculpture from [12:00] a rock. [12:04] And I will leave you with that quote [12:06] from Michelangelo which says the [12:08] sculpture is already complete within the [12:10] marble block before I start my work. It [12:12] is already there. I just have to chisel [12:14] away the superfluous material. In other [12:17] words, [12:18] even [12:19] from the perspective of people who make [12:21] sculptures, [12:22] this approach may make sense. [12:26] Okay. So now, how does that relate to [12:29] what we want to achieve? So [12:31] on the image generation sides, as I [12:34] mentioned, a very popular way of [12:36] generating images is to start from noise [12:39] and then have a model that you train to [12:42] predict [12:43] what is the noise from that noisy image [12:45] to remove in order to get your final [12:47] image. [12:48] So you have this process of predicting [12:51] the noise to remove [12:53] which slowly denoises [12:56] that noisy input [12:59] until [13:00] getting a clean image [13:03] without any noise. So you may have heard [13:05] of [13:06] diffusion models. So diffusion is the [13:08] topic of today, but in the context of [13:10] image generation, [13:13] you have diffusion with DDPM or also [13:17] other paradigms that approach things in [13:20] a similar way such as score matching [13:23] and flow matching. [13:25] By the way, who has heard of these terms [13:28] before? [13:31] One. Oh, okay. Three. Three people. [13:36] Okay. Makes sense. [13:38] So [13:39] with that being said, let's think for a [13:41] little bit how we want to transpose this [13:43] way of thinking for our use case, which [13:46] is text generation. [13:50] So [13:53] so far, [13:54] we've been thinking about generating [13:56] text as a way to autocomplete [14:00] a given sentence. [14:02] But if you think about it, [14:04] maybe one way to [14:06] draw a parallel with that approach is to [14:09] think about how you would write [14:12] a speech. Let's suppose you need to give [14:14] a speech to, let's say, your former [14:15] school, and you need to figure out what [14:17] you want to say. [14:20] Are you going to write your speech in a [14:22] linear way? [14:23] Or are you rather going to try to think [14:26] about what to put in your speech, what [14:28] are the sections you would put in your [14:29] speech, and then [14:31] slowly think about [14:33] what to write to be in between the [14:34] sections until [14:37] getting your final speech? [14:39] Wouldn't that be a more natural [14:41] approach? [14:43] Okay, so this is [14:44] exactly the idea behind what we want to [14:47] do. So here, noise, you can think of it [14:49] as, you know, a blank page or something, [14:51] you know, to do, need to write your [14:53] speech. [14:55] And then slowly you're thinking about [14:57] what your speech is going to look like. [14:59] So you think about like sections, and [15:01] then you think more about what these [15:02] sections could contain. So you add the [15:04] text, and then at the end [15:07] you get your speech. [15:08] So [15:09] can think of it as a course to fine [15:13] generation. So course at the very [15:14] beginning, think about the big things, [15:16] and then you iterate and you refine. [15:22] And [15:24] what we want to do in this lecture is to [15:27] learn [15:28] how we want to do that, [15:30] how we want to train our model to do [15:32] that, how do we want to generate text [15:35] using this paradigm. [15:37] So these are the questions that [15:38] hopefully this lecture will answer. [15:42] So one thing that I will say is [15:45] these [15:46] looks very intuitive, [15:48] but the math behind it is a little bit [15:51] involved. [15:52] So what I'm going to try to do is to [15:55] strike a balance between intuition and [15:58] mathematical rigor. [16:00] So depending on the time that we have, [16:01] we may or may not go into some of these [16:04] derivations, [16:05] but I hope that this up until now makes [16:07] sense. Does does that make sense so far? [16:09] Okay, great. [16:11] So [16:13] the next question that I want to ask you [16:15] is given this new way of [16:19] so I told you that in the auto [16:21] regression case, [16:22] we had [16:24] a causal attention [16:26] and a mechanism where we relied on the [16:29] past tokens to predict the next token, [16:31] which is why we use typically a decoder [16:34] only architecture. [16:36] So here, given this new paradigm, [16:39] what do you think is a good model [16:42] architecture that you could use on this [16:44] one? [16:46] Yep. So the answer is encoder only. Yes, [16:48] exactly. [16:50] And the reason for that [16:52] is that [16:54] in this process, [16:57] you would want your model to actually [16:59] have a holistic view of the noisy input [17:02] that is trying to denoise. [17:04] So great answer encoder only, which as [17:07] you remember from lecture two, [17:10] we had seen [17:12] one prime example of such a model, which [17:14] was BERT, if you remember. [17:16] But one big difference with BERT, and [17:19] you're going to see it more with [17:20] Chervin, is that BERT was not generating [17:23] text. [17:24] So this is really not new what we're [17:26] seeing. [17:28] So yeah, so you would typically use an [17:29] encoder only model, but typically still [17:31] based on the transformer. [17:34] So everything we saw about transformers [17:35] are still applicable. [17:39] Cool. Okay. So [17:41] now that we have that done, [17:44] let's think a bit more about how we want [17:46] to build [17:48] our model and how we want to proceed to [17:51] generating text using a diffusion based [17:54] paradigm. [17:56] So here, [17:57] we'd need to think about a way to [18:01] have noisy text. So we'll see how we can [18:04] have [18:05] a way to say, okay, this text is noisy, [18:07] but let's assume [18:09] you start with text with random noise. [18:12] The idea is to pass in that input [18:16] into your model, [18:18] which is going to get you a text with [18:21] slightly less noise. [18:25] And what you're going to do is you're [18:26] going to again [18:27] passing [18:29] that [18:31] less noisy input into your model, which [18:33] will again [18:35] remove the noise up until [18:37] getting you the final answer. [18:41] So that is the rough idea of what we [18:43] want to achieve. [18:45] And so if you draw a parallel with [18:48] image generation, it's exactly similar [18:51] in that image generation you take [18:53] a noisy input and you predict the noise [18:56] to remove and then slowly [18:59] you are getting a less and less noisy [19:01] image until getting your clean image. [19:03] Here it would be exactly the same thing [19:06] but applied for text. [19:09] And one nice thing is [19:13] that the number of steps that you would [19:14] need in order to achieve that [19:17] would not be a function of [19:20] the number of output tokens. [19:22] It would actually be a function of the [19:24] number of times you are repeating this [19:27] process. [19:29] That is pretty nice, right? [19:34] So long story short, the whole reason [19:37] why [19:39] we are interested in another paradigm [19:41] or at least to explore another paradigm [19:43] is [19:44] to address the limitations that we had [19:47] mentioned and in particular the facts [19:50] that [19:50] autoregressive models [19:53] perform their response generation [19:56] by having O of the number of output [19:59] tokens [20:01] operations or iterations, I would say, [20:04] whereas here we're actually having O of [20:07] the number of diffusion steps [20:09] as the number of iterations. So [20:13] do you all see why this would be [20:15] attractive? [20:17] Yeah? Okay. [20:20] Cool. Okay, so I I from this part I hope [20:23] we all [20:24] know why we're doing this lecture, why [20:27] is it something that we're interested [20:28] in. [20:29] So here what I want us to do is to [20:32] explore Oh yeah, you have a question. [20:37] So the question is you would probably [20:38] use the diffusion based paradigm for [20:41] longer responses and autoregressive for [20:44] shorter responses. We'll actually have a [20:46] section on this with Shervin. So hold [20:49] your thoughts and we'll we'll cover [20:50] that. [20:53] Cool. Any other questions on this? [20:58] Great. So now we're going to explore [21:02] different formulations that can get us [21:05] there. [21:06] So the field has so far not converged on [21:09] a single formulation. So we're going to [21:12] take a look at the two main ones and [21:15] we're going to start with the first one [21:16] which is the continuous formulation of [21:20] this problem. [21:21] And here what we're going to do is [21:24] take a look at how [21:26] diffusion works in the image case. [21:30] So why do we say continuous diffusion? [21:32] We say continuous diffusion because it [21:34] operates on continuous inputs [21:37] which is the case of [21:39] images because the input here can be [21:42] represented with [21:44] continuous values. [21:47] So here the problem is with text. [21:49] We don't have continuous values by [21:51] default. We have tokens [21:53] which are discrete. [21:55] It's part of a vocabulary, so it's a [21:57] little bit weird [21:59] but let's try [22:00] by taking the approach that [22:02] images do [22:04] and [22:05] let's have [22:06] an overview of how image generation is [22:10] performed with diffusion. [22:12] So the first thing that you need to do [22:14] is to represent your inputs and so here [22:17] let's assume that each image can be [22:19] represented with some vector of some [22:22] dimension. [22:25] So the idea of diffusion is to predict [22:28] the noise to remove, as I mentioned, in [22:30] order to denoise your image. [22:32] So that is one. [22:33] Uh I want to call out that there are [22:35] other formulations that I will just [22:37] mention here [22:39] for reference. [22:41] A second formulation that you may see [22:43] out there is the score matching [22:45] formulation [22:47] which is trying to estimate [22:50] the [22:52] direction of where [22:55] probabilities are of highest density. So [22:57] in particular, it's actually not that, [22:59] but more the score that you're [23:01] interested in, which is the gradient [23:03] of the log of the probability [23:05] distribution. So [23:08] it has its own math. And then the third [23:10] one is flow matching that you may have [23:13] heard out there or you may hear out [23:14] there [23:15] which thinks of it as a transport [23:19] problem. [23:20] Trying to transform [23:23] your initial distribution into a target [23:25] distribution. [23:26] So I just want to say that out there [23:29] there are several perspectives on how to [23:32] do this math. [23:34] And in this part, we will focus on the [23:36] traditional diffusion one. [23:39] But just know that you may see papers [23:41] that do differently and these are the [23:44] two others that you may see out there. [23:47] So if you take the diffusion [23:51] case, [23:53] what you would want to do So again, [23:54] objective is to learn how to generate [23:57] images from noise. [23:59] So the idea here is [24:02] to take your clean images [24:06] and to corrupt them with a process that [24:08] you are defining. [24:11] So that step is called the forward [24:12] process. [24:14] And you perform your corruption [24:17] with some [24:19] quantity Q [24:21] which allows you to noise your inputs in [24:24] a iterative way. [24:27] And [24:28] you some [24:30] identity here. So, you take in your [24:33] previous image and you noise it with [24:36] Gaussian distribution [24:37] and you add the noise [24:40] with the variance term. [24:43] And the whole idea behind diffusion [24:47] is [24:48] to [24:49] try to reconstruct the image that you [24:52] have corrupted. [24:53] So, the idea behind diffusion is to [24:55] learn a reverse process [24:58] which we note p theta [25:01] which is a probability distribution [25:03] that allows you to go from [25:06] noisy inputs to less noisy inputs. [25:10] So, I will spare the math for you, but [25:13] long story short, there is some some [25:16] things going on there. [25:18] And what you end up with is a formula [25:22] that allows you to denoise [25:26] your inputs [25:28] by predicting the noise to remove. [25:32] And you have a way to teach your model [25:36] to learn what noise to remove [25:39] with a rather simple loss formulation. [25:43] So, it's like L2 loss where you're [25:45] trying to [25:46] estimate [25:48] the noise that was added to a noisy [25:51] image. [25:52] That's what your model is trying to do. [25:55] And [25:57] the question that I have here is, can we [25:59] use the results that have been [26:02] established in the image generation [26:04] case? So, here what what I'm showing you [26:07] for our case. [26:08] So, that is the question. [26:13] So, [26:14] the first question that we need to [26:15] answer is, what is the equivalent of a [26:19] noisy image in the text world? [26:24] What is it in the continuous space? [26:28] So, let's assume [26:30] we take [26:32] our text inputs. [26:36] We know that in the text case, these are [26:38] discrete inputs, so these are tokens. [26:42] So one idea is to take their [26:44] representation, their embedding [26:46] representation [26:47] as a way to see them as continuous [26:51] inputs. [26:52] Because if you think about it, each [26:54] token is associated with a [26:56] representation [26:57] that is a bunch of floats in [27:01] D dimensional space. [27:04] So you could very well [27:06] consider these embeddings [27:09] as your continuous inputs [27:12] and come up with a way to represent your [27:15] whole sequence [27:17] with one matrix. [27:20] So your matrix here would be of [27:21] dimension [27:24] the dimension of your vector and the [27:26] length of your sequence. [27:31] So [27:32] one idea is to say, okay, let's try to [27:35] mimic what image generation folks have [27:37] done, [27:39] but by taking the representation of your [27:41] sequence [27:43] by concatenating the embeddings of the [27:45] representations of the tokens that are [27:47] in that sequence. So if we do that, [27:51] one thing we can do is to start from our [27:54] clean text, which is just the embeddings [27:57] of the tokens that are concatenated to [28:00] form a matrix, [28:02] and then to come up with a forward [28:04] process [28:06] that noises your inputs iteratively, [28:09] exactly like the image generation case, [28:13] until ending up with pure noise. [28:16] And by the way, here by noise, I mean [28:19] adding something that corrupts [28:22] your input. [28:23] And so in image generation, [28:26] the noise that we're typically adding is [28:29] a Gaussian noise. So by drawing from a [28:31] Gaussian distribution, so does everyone [28:33] know what a Gaussian distribution is? [28:35] Yeah? Normal distribution? Okay. So here [28:37] you would do something similar [28:41] up until let's say time step T. So here [28:44] I noted subscript X 0 X T - 1 X T up [28:48] until X capital T. So if you noise your [28:51] input [28:53] enough times, you may just end up with a [28:56] completely noisy [28:58] matrix. [29:00] And the whole idea is to learn [29:04] a way for you to reverse [29:07] that noise, to to remove that noise in [29:09] order to go back [29:11] to your clean text. [29:15] So [29:17] all of that sounds great, but let's [29:19] remember that [29:21] tokens are discrete. We're taking their [29:24] embedding representation, but nothing [29:25] tells us that the representation that we [29:28] obtain in any of these steps actually [29:30] correspond to a token. [29:32] May actually be very far from a token. [29:36] So one key step here is to make sure [29:40] we're never [29:41] losing that mapping between [29:44] embeddings and tokens. [29:46] And so one big question is how do you [29:49] map [29:50] these embeddings [29:52] to the tokens? [29:54] Well, [29:55] in one way it's quite natural. So if you [29:57] go from discrete token to embedding, you [30:01] just take its embedding. [30:03] But then the other way it is less [30:06] natural. [30:07] But one way you can do that is [30:11] take the nearest embedding around a [30:14] given embedding [30:15] and associate the corresponding token. [30:19] So in other words, so if I go back here, [30:22] let's assume you start from noise, which [30:24] is on the right side of the slides, and [30:26] let's assume you learn a process, [30:30] a reverse process to remove remove that [30:32] noise. [30:33] Let's assume you end up with a matrix on [30:36] the far left of the slides. [30:38] The way you would [30:40] map that to tokens is [30:43] by taking [30:44] the individual vectors [30:47] and trying to find the nearest neighbor [30:50] of an embedding that corresponds [30:53] to a token. [30:55] Could very well do that. [30:57] All of what I'm saying is, you know, [30:59] great, but I would just want to [31:01] highlight a few limitations of this [31:03] approach. [31:05] So the first one that I want to say is [31:07] that the vectors that we're used to to [31:09] represent tokens, [31:11] they're quite high dimensional. [31:14] They're on the order of let say [31:15] thousands of dimensions [31:18] and there's actually a lot of [31:21] locations in that high dimensional space [31:23] that are actually not meaningful. [31:24] They're not corresponding to any [31:26] token. [31:28] So that is one limitation. The second [31:30] limitation is I mentioned that the loss [31:33] function for image generation diffusion [31:36] is an L2 regression loss. [31:40] And here one can wonder whether that [31:43] would actually be a good loss for you [31:44] because at the end of the day you don't [31:46] care about [31:48] regions of embeddings, you actually care [31:49] about tokens. So you're not actually [31:51] optimizing for exactly [31:54] what you want. [31:56] And the third one is I told you about [31:59] the noise that we're adding. So in the [32:01] image case we're adding Gaussian noise, [32:04] but here one could wonder whether that [32:07] is actually something that is meaningful [32:08] because for images when you [32:09] [clears throat] add Gaussian noise [32:11] it visually corrupts the image in a way [32:14] that looks like noise, [32:16] but for text maybe it is not [32:19] performing a similar behavior. [32:22] And so people they've been trying to [32:25] address this issue. So I'll I'll just [32:27] name a few methods. So one method is [32:31] to ensure that tokens throughout the [32:35] denoising process are always [32:38] being mapped to the embeddings. [32:40] So there is a method called clamping [32:42] that does that. [32:44] And the second one is [32:46] to actually consider embeddings of the [32:48] whole [32:49] sequence as opposed to individual [32:53] token embeddings because you can think [32:54] that [32:56] maybe if you consider [32:59] embeddings of individual tokens and you [33:02] try to map each of these individual [33:04] embeddings to corresponding tokens and [33:07] you take the [33:08] corresponding sequence [33:10] that this may not make as much sense [33:13] as if you were to [33:15] consider the embedding of the whole [33:17] sequence [33:19] and consider the whole sequence as one [33:21] thing that you actually want [33:23] to predict. [33:25] Because maybe I don't know, some noise [33:28] words can actually not make sense in the [33:30] context of the other words, let's say. [33:34] So this is the reason why [33:37] the continuous diffusion space [33:40] is an active area of research. [33:43] It's been sometimes [33:46] an area where you know researchers have [33:48] had a lot of hope for and sometimes [33:49] less, but it is [33:53] a place where you have these challenges. [33:56] And [33:58] given these challenges, [34:00] I hope it was a good enough motivation [34:02] for us to actually look [34:04] at another approach [34:06] that actually takes a look [34:08] at the problem [34:10] from [34:11] a text perspective, directly from a text [34:13] perspective. [34:15] And this is a reason why [34:17] I want to ask the following question. [34:22] Can we define a corruption process that [34:26] actually happens directly in the [34:28] discrete token space? [34:30] Can we do that? [34:32] Because if we were to do that, then it [34:34] would be much more [34:36] relevant to our use case because here [34:38] we're just trying to [34:40] we're just trying to adapt what image [34:42] generation people are doing and trying [34:44] to match it to our discrete case. [34:48] So can we not just do that directly [34:50] on discrete tokens? [34:53] And that is exactly what we're going to [34:55] cover now, [34:57] which is [34:59] discrete diffusion. So here we saw [35:01] continuous diffusion. Now we're going to [35:02] see how we can perform diffusion [35:04] directly [35:06] in the space of tokens, which is [35:07] discrete. [35:11] And [35:12] I want us to just go back to the process [35:15] that we have seen, [35:17] which takes a clean text [35:20] and then noises that text [35:23] iteratively until getting a completely [35:25] noised text. So here, instead of [35:29] operating on [35:30] the embeddings that are associated with [35:32] the clean text that we're trying to [35:34] noise, [35:36] now what we're proposing is [35:39] to just swap [35:41] or change the tokens of your clean text [35:44] and corrupt them directly, [35:46] directly in the token space. [35:49] And so here we can think of a [35:53] forward process defined by Q [35:56] that is directly [35:59] trying to [36:01] change those tokens [36:03] using some categorical distribution. So [36:06] has anyone heard of [36:07] this categorical distribution? [36:09] Do you know what [36:11] this means? [36:16] Okay, cat of this. [36:19] Or is the first time that you're seeing [36:21] this notation? [36:23] Assuming it's the first time. [36:25] So this is a probability distribution [36:28] that is operating on a discrete set of [36:30] choices. [36:32] Let's suppose you have [36:35] n number of choices. [36:37] Each of these choices will be [36:39] associated with some probability. [36:41] So for instance, if you have three [36:42] choices, let's say 0.4, 0.4 and 0.2, [36:46] what that means is you have 0.4 [36:48] probability to go into the first choice, [36:51] 0.4 probability to go to the second [36:52] choice, and 0.2 probability to go to the [36:54] third choice. [36:57] And so the reason why [36:59] this notation is on the slides [37:02] is because we are defining our forward [37:05] process [37:07] in the token space [37:09] by saying that tokens [37:11] have some probability of being corrupted [37:14] to another token. [37:17] Is that part clear? [37:21] Yeah? Okay. [37:23] And so [37:24] the idea for us [37:27] is [37:28] to leverage some transition matrix that [37:31] we can define [37:33] in order to noise our clean text by [37:37] directly noising it in the token space. [37:41] And as a result of that, learn a reverse [37:44] process [37:46] that would allow us to go from noisy [37:49] text to clean text. [37:51] That's what we want to do. [37:54] And so here, I think there's a natural [37:56] question that's [37:58] is presenting itself, which is [38:01] what is [38:03] the equivalent of a noisy text in terms [38:05] of what we have in our [38:08] in our vocabulary? Like what is the [38:09] token that we should use in order to [38:11] represent noise? [38:15] So out there, [38:16] there are a few ways you can do that. [38:18] You can either take a random token [38:21] or [38:23] you can take [38:24] the mask token that we have seen, I [38:26] think in the context of BERT. [38:29] And here you can say that [38:32] you can corrupt tokens by just replacing [38:35] them with a mask token. [38:38] And that [38:40] is one way of doing this among others. [38:43] But this is the way we're going to focus [38:46] on for the rest of this part. [38:49] So in other words, what we're saying is [38:52] if we want to noise [38:54] a given token, [38:57] we corrupt that token by [39:01] replacing it with a mask token with some [39:03] probability that is given by [39:06] our categorical distribution. [39:08] So we're going to see that in more [39:10] details, but that's the rough idea. [39:14] So [39:16] here, let's assume we define a [39:19] transition matrix that we note Q [39:24] that tells us [39:26] what is the probability [39:28] for a given token I [39:31] to be corrupted to some other [39:34] token J at time T. [39:37] So by the way, time T, why am I saying [39:39] time T? Because here [39:42] when we are corrupting [39:45] our input, [39:47] we assume that at the very beginning it [39:49] is clean. We're at time zero [39:52] and then we're corrupting it [39:55] progressively until ending up with a [39:58] completely noise [40:00] sequence, which is at time step big T. [40:06] So this is the T that I'm talking about. [40:07] So here [40:09] what the transition matrix is saying is [40:12] at a given time T between this zero and [40:14] big T, [40:16] what are the probabilities [40:19] for a token I to be corrupted to a token [40:21] J at that time step? [40:24] And so here that transition matrix is [40:27] telling us [40:29] what are the tokens that can be [40:30] corrupted to other tokens. So it's a [40:32] matrix of size [40:35] size of vocabulary times size of [40:37] vocabulary. [40:40] Okay, so I told you that we could very [40:42] well define noise as being the mask [40:46] token. [40:48] So let's see what the transition matrix [40:51] could look like in this case. [40:54] So before we do that, just want to say [40:56] that [40:57] the entries in the transition matrix [41:01] are probabilities. So they're [41:04] in the range 0 1. [41:09] So by the way, [41:11] there's a lot of math behind everything [41:13] I'm saying. So we're going to cover the [41:16] main important ones, but if you are [41:18] curious, there are some papers that we [41:20] always put at the bottom of the slides. [41:23] And in particular, [41:25] this formulation is known in the [41:29] community as D 3 PM, which stands for [41:31] discrete denoising diffusion [41:33] probabilistic model. So [41:36] feel free to take a look at the paper if [41:37] you're interested to learn more. [41:40] But in our case, [41:43] we have the whole vocabulary. So for [41:45] instance, we have the token A, we have [41:47] the token bear, we have the token cute, [41:49] and so on. And we also have the token [41:51] mask. [41:54] So what we're saying is if your token [41:58] is a regular token, [42:01] and here we're going to say a clean [42:02] token as in not a masked token, [42:05] then [42:07] you have some probability beta t [42:12] of [42:13] corrupting that token into noise, which [42:17] is the mask token. [42:19] And you have some probability 1 minus [42:22] beta t of actually not changing your [42:25] token. [42:28] So the first thing that I want to want [42:29] to tell you, we can corrupt tokens from [42:33] let's say time steps t minus 1 to t [42:36] by [42:38] just randomly saying, okay, with a [42:41] probability beta t, let's corrupt it. [42:43] With a probability 1 minus beta t, we [42:45] actually keep it. [42:47] And the second thing that I want to tell [42:49] you, and this is actually quite [42:50] important, [42:52] is [42:53] that we're assuming [42:55] that once [42:56] we corrupted a token, [43:00] that that token will always stay [43:02] corrupted. [43:03] So here the mask token [43:06] is always going to be the mask token for [43:08] remaining time steps. [43:12] So by the way, that's the reason why [43:15] we are saying that this formulation is [43:18] an absorbing state formulation because [43:20] when a token is corrupted to the mask [43:22] token, it stays there. So it is [43:25] absorbing. [43:29] And one thing that I want to say is that [43:32] in practice it is much more convenient [43:35] to handle [43:37] alpha t that is defined as the [43:40] probability [43:42] that a token stays unmasked [43:46] from zero to time step t. And so if you [43:49] think about it, so if one minus [43:52] beta t is the probability from time step [43:54] t minus one to t of a token staying [43:57] unmasked. [43:58] So if you assume that in between each [44:00] time step [44:02] you are doing that randomly, [44:03] independently, [44:06] then the probability for you to have a [44:09] token that stays unmasked after t steps [44:14] is the product of the one minus beta k [44:19] when k is between one and t. [44:23] So I'm just saying that because we're [44:25] going to use it. [44:30] So what I want to say is a few things. [44:34] The first one is with that newly defined [44:37] quantity which is alpha t and I'm going [44:39] to just repeat what that means, which is [44:41] the probability that an original token [44:44] remains unmasked [44:46] at time step t. [44:48] What we're saying is [44:50] if we start with a clean token [44:55] which is noted x 0 i. So I'm just going [44:58] to say what that means. [45:00] So x 0 i. [45:04] So here zero means [45:06] clean [45:08] and i means token i. [45:15] Just to make sure we're agreeing on the [45:16] notations. [45:18] So what we're saying is [45:20] that the probability knowing that clean [45:23] token i [45:25] at time step t [45:27] is [45:29] alpha t to stay unmasked. So [45:32] you have alpha t probability that [45:36] the token i at time t is the same token [45:40] and you have a probability of one minus [45:43] alpha t [45:45] for that token i [45:46] to actually become masked at time step [45:49] t. [45:50] So the second thing that we said is [45:52] whenever [45:53] token [45:54] is masked [45:56] at a given time step [45:58] then it stays masked [46:00] for the following time steps. [46:03] So here what we're saying is [46:05] if we assume that for a given time step [46:09] s [46:11] the token i [46:13] at time step s is masked [46:17] then [46:18] that token i at time step t, which is [46:22] later than time step s [46:24] is also masked with a probability of [46:27] one. [46:29] So I'm just putting in mathematical form [46:33] what we just mentioned. [46:35] So we're going to go through an example [46:37] which hopefully will make more sense and [46:40] I think you recognize the example we're [46:42] always using which is [46:44] a teddy bear is reading. So let's assume [46:46] this is our clean sequence [46:49] and let's imagine we're progressively [46:52] corrupting that sequence [46:57] along [46:58] time [46:59] which here let's assume is between zero [47:02] and big T. [47:04] So you progressively are masking your [47:07] inputs. So for each token, you have a [47:09] certain probability of masking it, a [47:11] certain probability of not masking it. [47:14] And let's assume you do that. The first [47:16] token gets masked. [47:18] And then you do that another time. So [47:19] the first token still stays masked. [47:22] And there's another token in the [47:23] sequence that is getting masked. [47:26] And you do that again and again and then [47:28] the ones that are masked, they just stay [47:31] masked. And the ones that are not [47:33] masked, they have some probability of [47:34] being masked. [47:36] And so you do that until the end until [47:39] your whole sequence is masked. [47:43] So the sequence at the very top is the [47:45] clean sequence. The sequence at the very [47:47] bottom is the noised sequence, [47:49] completely noised. [47:51] You maybe wondering why we're doing all [47:52] this. So [47:55] we're doing all of this in order for us [47:57] to learn a way [47:59] for us to go from noise to clean. [48:01] And here we're just defining some [48:04] mathematical foundations. So just a way [48:06] for us to get the notations right. [48:09] So up until now, it's just a matter of [48:12] aligning on what all this means in [48:14] mathematical medical terms. [48:17] So is the mathematical formulation [48:19] clear? [48:23] Yeah, yeah. [48:24] So the question is is big T fixed? So [48:27] you fix it at the beginning. [48:29] So yes, it is fixed. But one thing that [48:32] I want to say is there are multiple [48:35] conventions on [48:37] you know, should it be between zero and [48:38] big T? Should it be between zero and [48:40] one? [48:41] And so here we're just taking the [48:43] convention of big T. [48:46] But I want you to know that sometimes [48:48] it's between zero and one. [48:50] So you can think of it as just a lower [48:52] and upper bound if you want. [48:55] Great. So [48:58] what do we want to do? [49:00] So what we want to do is [49:03] to learn the reverse process. [49:06] So maybe I'm going to just tell you a [49:08] little bit about what we just said. So [49:11] I'm going to remove this. [49:15] So if you remember, [49:17] the diffusion process is such that [49:20] you take your clean sequence [49:23] and what you're trying to do is to [49:26] iteratively corrupt it with some process [49:29] that is known to us because we define [49:32] it. [49:32] So here we said it is defined by some [49:35] process Q, which is the forward process. [49:38] And you end up with a complete [49:42] completely noisy sequence. [49:45] And our goal is to say, okay, [49:48] let's do the same thing as for the image [49:50] generation case where we start from [49:52] complete noise and try to remove that [49:55] noise in order to get a clean [49:59] text in this case. And so here our goal [50:03] is to learn a reverse process that we [50:06] can note [50:08] P of theta. So theta is [snorts] the [50:10] parameters of our model. [50:14] Our goal is to learn [50:17] such a reverse process that will get us [50:20] where we want to be. [50:22] And so how do people typically learn [50:25] parameters of a model? [50:27] They usually go back to first [50:28] principles. [50:29] So if you remember, [50:33] you have some training data. Let's [50:35] assume you noted X0. So by the way, X0 [50:38] because it's clean. [50:40] What you want to do is to find [50:43] parameters of a model theta [50:46] that maximize the probability [50:49] of you seeing [50:51] that data. [50:54] So this is just maximum likelihood [50:57] estimation that we all know. [50:59] So now what I want to do is [51:04] to tell you a little bit more about how [51:05] we want to proceed in this case. [51:08] So, [51:09] we want to [51:10] find a tractable way [51:13] to find parameters theta that maximize [51:16] this quantity. [51:19] But before we do that, I just want to [51:20] tell you about what we used to do in the [51:23] autoregressive case. [51:25] So, in the autoregressive case, [51:29] we had [51:31] so everything was [51:33] clean. So, everything is an x 0. [51:36] But [51:37] what we said was [51:39] p theta of x 0, which is your sequence, [51:45] is actually something that you can [51:46] express as the probability for you of [51:51] predicting your first token [51:54] and then [51:55] probability for you [51:57] of predicting [51:59] the next token given the initial token [52:01] and so on [52:03] using the chain rule. [52:06] So, uh by the way, my notations are [52:09] this. So, let's see. [52:11] 0 So, here we're just trying to abide by [52:16] the conventions here. So, this is all [52:19] clean [52:20] data. But here what we're saying is we [52:21] take the token at index 0 and we say [52:24] what is the probability of this [52:26] times the probability of the token at [52:28] index i given [52:31] token at index 0 and so on using the [52:33] chain rule. So, here [52:35] it's uh [52:37] p of theta x 0 [52:42] with the product of uh i from 1 [52:47] to let's say l, which is your sequence [52:50] length [52:52] of p theta [52:53] x 0 i given x [52:59] 0 all the past tokens. [53:04] Does that one make sense? [53:06] So if you remember, I think we derived [53:08] the cross entropy loss from first [53:10] principles using this. [53:13] We were able to do that [53:16] because in the autoregressive case, [53:19] we're formulating our problem [53:22] by saying we want to learn a model [53:26] that tells us about the probability of a [53:28] token given all the past tokens. [53:32] So we are actually [53:35] we mean to actually train [53:38] such a model, [53:40] which is nice because we can pop it up [53:41] here and we can [53:44] maximize this [53:46] in the usual way. [53:49] And so the problem here is that you [53:50] cannot do that. [53:52] You cannot [53:54] derive the loss in the same way because [53:57] we said that we did not want to do [53:58] autoregressive generation. [54:01] We actually do not want to predict [54:03] tokens one at a time. [54:07] So we cannot express our loss like this. [54:11] So what did we say? [54:13] We said that we were trying [54:16] to denoise [54:19] some [snorts] [54:20] noisy input in an iterative fashion [54:23] in order for us to go from complete [54:26] noise [54:27] to clean. [54:30] So in other words, for diffusion, [54:37] so our goal [54:39] so the goal [54:41] is [54:43] to parameterize [54:45] our [54:46] model [54:47] such that we learn [54:52] a version of the sequence that is less [54:54] noised than some input that we're [54:57] getting that is [54:59] more noised. So XT [55:03] is like more noise. [55:05] So more noise [55:08] and this is less noise. [55:13] So we want to find a way to express our [55:15] loss [55:17] as a function of how we want to learn [55:19] our model. [55:25] What we have is [55:27] this quantity and we're wondering how to [55:29] express that. Well, you can very well [55:31] use the chain rule again. So why don't [55:33] we use the chain rule again, but this [55:35] time not across the tokens, but across [55:40] the noise levels. So let's see how we [55:42] can do that. [55:48] So [55:54] if we think about [55:56] P theta of X zero that we're trying to [56:00] maximize and if we want to express that [56:03] as a function of the noise version of [56:07] that sequence, [56:09] we could very well [56:11] consider [56:14] the joint probability distribution of X [56:18] zero, X one [56:20] until X big T [56:23] which are [56:24] the noise version of X zero [56:30] and sum that across the X one through X [56:33] T. [56:34] So if you do that, you obtain P theta of [56:36] X zero. So why did I write that? We want [56:39] to find a way [56:40] to express this quantity as a function [56:43] of the ones that we care about, which [56:45] are which are the noise version of the [56:46] sequence. [56:49] So [56:51] how can you express that? [56:55] You can also use the chain rule in the [56:57] same fashion. You can have [56:59] P theta of X [57:01] big T which is this one and then have [57:06] the chain rule apply again [57:08] which is [57:10] P theta of x t let's say minus one [57:16] given [57:18] let's say x [57:22] t up until x p t [57:30] from one to [57:32] big t. Do you all agree with this? So [57:34] this is just a chain rule. [57:38] And so here we can choose [57:42] to have our p theta [57:46] for a given less noisy version of the [57:49] sequence. [57:51] We can choose to say this is actually [57:55] only [57:57] a function of the more noisy version and [57:59] just discard the the ones that are [58:01] above. We can do that. We can make this [58:02] assumption. So this is by the way called [58:04] the Markov assumption [58:06] where you only assume [58:08] that current state is just a function of [58:11] another state but not the ones that [58:13] happened before that. [58:16] So [58:17] if you were to do that you can express [58:21] p theta of x zero as a function of [58:25] what you care about. [58:28] And so [58:30] given this [58:34] your next question is going to be [58:37] how can you compute this quantity [58:39] because I told you very casually that [58:42] you can very well compute this quantity [58:44] by marginalizing across [58:47] the noised versions of x. So you can [58:50] think of this as being a trajectory. [58:53] But the problem is [58:55] there is an [58:56] almost infinite amount of different [58:58] combinations [59:00] that could fit in here. [59:04] So in other words so here this [59:06] decomposition is valid [59:08] but you cannot compute [59:10] this quantity. You cannot it is not [59:12] tractable. [59:15] So, it is not tractable. [59:18] And this is the reason why [59:20] in order to find the parameters theta [59:24] that maximize the expression that is on [59:26] the slides, [59:28] you need to do some work. [59:30] We need to massage the expression in a [59:33] way that makes it tractable. [59:37] And so, this is the reason why we have a [59:40] recipe of four steps. [59:43] I'm going to see how ambitious we want [59:45] to be because [59:47] I mean, we could spend two hours on [59:49] this, but the idea is for us to focus on [59:51] the intuition first [59:53] and then, if time permits, go into the [59:55] math. [59:58] All that to say that this four step plan [60:01] is for us to get a loss [60:04] that is tractable for us to compute [60:07] and that is [60:09] telling us [60:10] that [60:12] we're optimizing things in a way that [60:14] makes sense [60:15] with respect to the objective that we [60:17] care about, which is to find parameters [60:19] theta that [60:21] maximize the probability of us seeing [60:25] the training data. [60:28] So, I'm going to pause here. [60:30] Is there any questions so far? [60:33] So, do you know why we're here? Why do [60:35] we do this? [60:37] So, the goal here is to derive [60:41] a loss [60:43] that is going to be [60:45] that is going to allow us to train a [60:47] model. [60:48] Because if you want to train a model, [60:49] you need to know how well you're doing. [60:51] How do you know that? Well, you have a [60:53] loss function and then, depending on how [60:56] well you're doing, you know how to [60:58] update your parameters. [61:00] And so, here the goal now is to derive a [61:03] loss function that is [61:05] going to be allowing us to do that. [61:09] And we just saw here [61:11] that the expression that we want to [61:13] maximize is not tractable for us to [61:17] compute. [61:18] It is not tractable. [61:19] And that is the reason why we have this [61:22] strategy plan [61:24] to derive a loss that is tractable. [61:29] Okay, so [61:31] hopefully if we go through these steps [61:33] you are going to be a bit more convinced [61:34] about what we're doing. [61:35] So the first step [61:38] is around [61:41] finding [61:42] a quantity [61:44] that is allowing us to actually [61:47] compute something that is tractable. [61:50] And so there is a very common trick in [61:53] the diffusion field [61:55] which is [61:56] if you want to maximize a quantity that [61:59] you cannot compute, that is hard for you [62:01] to compute, [62:03] then the next best thing for you is to [62:05] compute [62:07] a lower bound [62:09] that is tractable for you to compute, [62:11] that you can maximize. [62:14] So if you compute [62:16] something that you know for sure is [62:20] smaller that what you care about, if you [62:21] maximize that lower bound then your hope [62:23] is that what you care about will be [62:26] maximized or or not made but [62:29] is going to be be in the same direction. [62:32] That's that's the hope. [62:34] And so the first step for us is to [62:36] determine what that lower bound is. [62:40] So there is a very common trick that [62:42] we're going to go through together [62:44] that [62:46] is going to [62:48] bring up [62:49] the forward process that we have [62:51] defined. [62:53] Because remember [62:55] the text that we're corrupting [62:57] is performed [62:59] with the forward process Q that we have [63:02] defined. We know what Q is. [63:05] So here uh Q what is Q? Q is [63:09] this probability distribution that we [63:10] have defined [63:12] such that [63:13] we know what is the probability of [63:15] masking a token at time step T [63:18] uh and it is alpha T uh sorry one minus [63:20] alpha T of masking it and alpha T in [63:23] terms of [63:26] letting it be unmasked. [63:29] So here what I said was [63:33] back [63:35] back here that [63:37] what we're going to do is to try to sum [63:41] this quantity in a way that makes it [63:43] tractable. [63:44] So I mentioned here [63:46] that it is hard for you to sum across [63:48] trajectories that are a large number. [63:52] And our goal here [63:54] is to use the forward process as a way [63:58] for us to sample [64:00] these trajectories. [64:01] So we're going to try to [64:04] pop up Q in that expression such that [64:08] we can estimate that by sampling from Q. [64:12] So I'm going to just derive this. [64:15] So what I'm going to do is [64:25] just take this. [64:39] So [64:41] I mentioned that our objective is to [64:44] maximize [64:45] P theta [64:48] of X zero and we had said that we could [64:51] let the trajectories [64:54] pop up in our expression by just [64:56] marginalizing [64:59] over the joint distribution of our clean [65:03] sequence along with all the other [65:06] sequences that are noise. [65:08] So here what we want to do is to sum [65:11] across all these possible trajectories. [65:14] So here the problem is it is hard for us [65:18] to sum across all these trajectories so [65:20] we want to find a way for us to leverage [65:23] Q in order to sample from these [65:24] trajectories. [65:26] So we're going to find [65:29] a clever way to let Q appear. [65:33] And in particular, what we're going to [65:36] see here is [65:39] if you consider the joint distribution, [65:41] so this is equal of the integral of P [65:45] theta of the joint distribution X 0 [65:48] through T. [65:50] We can assume that [65:57] we can actually pop up [65:59] the forward process [66:01] of the joint distribution of X 1 through [66:03] T given X 0. [66:07] This is something that you can do. [66:12] Because this over this is one, so I just [66:14] let it pop up. [66:18] And [66:22] by definition of the expectation, this [66:24] is just [66:26] expectation [66:28] of [66:29] P theta of the joint distribution of X 0 [66:32] through T [66:34] over [66:35] Q of [66:36] X 1 through T given X 0. [66:40] And then this [66:43] is the expectation over the X 1 through [66:46] T [66:47] that are [66:48] sampled from [66:51] the forward process Q that we have [66:53] defined that we know how to sample [66:58] of X 1 through T given X 0. [67:04] So far so good? [67:09] And so here, what we care about is to [67:12] maximize [67:14] P theta of X 0 which is the same as [67:16] maximizing [67:18] log [67:20] of P theta of X zero. [67:30] And [67:32] we're just going to have [67:35] something nice that's going to pop up. [67:39] So, [67:41] have you heard of Jensen's inequality? [67:44] So, we're going to use this trick here. [67:46] So, let's assume that what we have above [67:50] is [67:52] expectation of let's say star. [67:56] So, Jensen's inequality tells us that if [67:59] you have a function that is concave, [68:01] which log is one of them, [68:04] then [68:05] you can [68:08] have this inequality, which is [68:09] expectation of log [68:13] of this quantity. [68:16] And that [68:19] is our lower bound, [68:22] which still is [68:24] scary, [68:27] but it is a lower bound [68:30] that we have shown here [68:32] that is actually tractable. [68:36] This is the whole point of this [68:37] derivation. So, we're trying to derive a [68:39] quantity that that is tractable. And at [68:42] this point, you don't know that it is [68:44] tractable. We're We're going to show [68:45] that it is indeed tractable. [68:49] So, I think it's enough math for this [68:51] part. [68:52] I'm going to focus more on intuition in [68:54] the next part. [68:57] So, we have a lower bound of what we [69:00] care about, which is [69:02] maximizing log of P theta of X zero. So, [69:06] here we have a quantity that we know is [69:09] lower than that quantity. [69:11] And we're going to show that the elbow, [69:13] which is the quantity that is on the [69:15] right side, [69:16] is something that is tractable for you [69:18] to compute. [69:20] We're going to show that now. [69:23] So, let's go [69:24] through the next step. But before we do [69:26] that, just a reminder of [69:29] a way for you to measure the distance [69:31] between two distributions. So we I think [69:33] we have seen KL divergence [69:35] earlier in this class, but just a [69:37] reminder that [69:39] the KL divergence between two [69:40] distributions is defined as the sum [69:43] of [69:44] So if it's between P and Q, it's the sum [69:46] over PI log of PI over QI. [69:50] So that quantity that quantity is always [69:51] positive or equal to zero and it is [69:53] equal to zero when [69:55] the probability distributions are the [69:57] same. [69:59] And we have the same for uh the [70:02] continuous case. So why am I telling you [70:03] this? [70:05] Because the second step [70:07] is for us to [70:09] actually demonstrate [70:12] that the elbow is structible. [70:14] And I'm going to spare you the math. [70:16] If you do the math, [70:18] then you actually end up with an [70:21] expression [70:22] that is a function of the KL divergence [70:25] of [70:26] Q which is the forward process that you [70:28] have defined [70:31] and P theta [70:34] which is the reverse process that we're [70:36] trying to learn. [70:39] So here we're not going to do the math, [70:40] but please trust me. [70:43] And so here just going through the [70:45] notations that are on the slide. So it [70:47] is the KL divergence [70:49] of [70:51] the distribution of [70:53] the [70:55] token at index I that is at [70:58] step time step T minus one given that [71:01] you know [71:02] the more noisy version of this token and [71:05] its clean version. [71:08] And you do the KL divergence of this [71:10] quantity with [71:12] the learned reverse process that you're [71:14] trying to learn [71:16] which is [71:18] trying to estimate [71:21] X [71:24] T minus one. So at time step T minus one [71:26] for the [71:28] token index i [71:30] given [71:33] the more noisy sequence. Next. [71:36] So trust me that we have this formula. [71:40] Now the question is can we actually [71:42] compute what is in between the KL [71:45] divergence? [71:47] So let's see what each of these terms [71:50] mean. [71:52] And this is the third step here. [71:54] So what is Q of x t-1 at index i given x [72:01] t at index i and x 0 at index i? [72:04] So let's assume you have a given token. [72:06] You know what is [72:08] that token at noise level t. You know [72:10] what is the token when it's completely [72:13] clean. Can you know [72:15] the probability distribution of what [72:17] that token would be at [72:19] time step t-1? So that's the question. [72:23] So if [72:26] your token at index i [72:29] and at noise level t, if it's not [72:32] masked, if your token is not masked at [72:35] time step t, [72:37] what can you say about that token at [72:41] time step t-1? [72:44] Yeah, the answer is it's also not [72:46] masked. Yes, you're completely right. [72:48] Does everyone see [72:49] that that part? Because we had said that [72:52] if you mask a token, then all the [72:56] following [72:57] time steps it's also masked. So if x t-1 [73:01] was masked then x t would have been [73:02] masked. But it's not the case. [73:05] So that part is easy. [73:07] But now let's think about the case where [73:10] x t is actually masked. [73:14] So if your token at index i [73:17] in the sequence of time step t, if that [73:19] one is masked, [73:21] then actually when you think about it, [73:22] it can either be masked at t-1 or it can [73:25] also not be masked. [73:27] So let's try to derive that part [73:32] because it is actually not [73:34] trivial or actually not something that [73:36] you can trivially deduce by just looking [73:38] at the at the slide. [73:41] So we're at the in the case where [73:43] your token at index I in the sequence of [73:47] uh time step T is masked. [73:51] And what you're trying to do [73:53] is to figure out what is the probability [73:56] distribution [73:58] of that same token I but [74:01] at time step T minus one given [74:04] X T I [74:07] which is masked [74:11] and [74:13] that same token but clean. [74:17] Okay, so now how we're going to do that? [74:22] The first thing that I want to say is [74:26] just probability theory. [74:29] If you multiply this [74:32] by [74:35] X [74:37] T [74:38] I [74:40] given X 0 I [74:43] you obtain [74:47] Q of [74:49] X T minus one [74:52] I [74:53] and [74:57] X T I [75:04] given X 0 I. [75:07] Do you agree with me? [75:10] So if you multiply this quantity by Q of [75:12] X T I given X 0 I you obtain [75:16] Q of X T minus one I equal to some value [75:20] and X T I equal to being masked given X [75:23] 0 I. [75:25] Do you Do you agree with me? [75:29] So if you consider this [75:33] then [75:34] what you realize [75:36] is [75:37] if you want to know that value if let's [75:40] assume [75:41] x t - 1 [75:45] let's say is masked [75:50] then [75:54] Q of x t i = masked given x 0 is we said [76:00] by definition this is 1 - alpha t. [76:04] Do you remember when we defined what [76:06] alpha t was? [76:08] This is the probability of masking a [76:10] token at index i [76:13] from 0 to t. [76:16] And here if we say what is the [76:18] probability given by our forward process [76:20] of x t - 1 i being masked and x t i [76:25] being masked given x 0 [76:27] this [76:29] is the same as saying [76:31] that it's the probability of x t - [76:34] 1 of i being masked just that given x 0 [76:38] because if this one is masked [76:41] then of course this one is going to be [76:42] masked with a probability 1. [76:45] So [76:46] if [76:47] you consider this one as being masked [76:52] then this one can disappear. [76:55] So let's be a bit more clean. [76:59] Then this one can disappear. [77:01] And that one we said [77:03] was [77:06] 1 - alpha t - 1. [77:12] So far so good? [77:14] So [77:16] I think we have everything [77:19] in there to [77:20] conclude. [77:23] And what we're going to say is [77:26] that the quantity that we care about [77:36] so Q of [77:39] x t minus one [77:42] i [77:44] equal mask [77:49] given x t i [77:52] being masked [77:57] and x zero i [78:00] is equal to one minus [78:03] alpha t minus one over one minus alpha [78:06] t. [78:09] So, if x t minus one i is masked, this [78:12] is this. If x t minus one i [78:15] is not masked, [78:18] then it is one minus this quantity. [78:23] So, so I hope I convinced you that we [78:25] can compute this [78:28] these pieces and there is a way for us [78:31] to express this quantity as a function [78:33] of alpha t and alpha t minus one. [78:36] So, if you do some math, [78:37] can figure out that this is one minus r [78:39] t with r t defined on the slide for x t [78:44] minus one i being masked [78:46] and r t if x t minus one i is the clean [78:50] token. [78:52] So, by the way, here [78:53] x x t minus one i can only either be [78:57] masked or cleaned. Can only be [79:00] one of the two. That's why we only have [79:02] these two values. [79:04] So, we just said that this we could [79:07] compute. [79:09] Now, let's see if we can compute t [79:12] theta of x t minus one i. [79:16] So, if [79:18] x t is not masked, [79:22] then x t minus one is also not masked. [79:25] That's good. [79:26] But what if x t is masked? [79:30] Then what we can do [79:31] is to try [79:34] to estimate [79:37] x zero [79:39] with a model. [79:41] And then plug in [79:44] that estimates [79:46] into this exact [79:48] formulation [79:50] to get us [79:52] the learned reverse process. [79:55] And so here pi theta is the probability [79:59] of a token given by our model. So it's [80:01] the probability of [80:03] the token at index I [80:05] noise level T minus one given [80:08] the more noise version of the sequence [80:11] at [80:12] time step T and the noise level. [80:16] So I skipped a bunch of derivations I'm [80:18] not going to do just in the interest of [80:20] time. [80:21] But this is how what we obtain. [80:24] And so why are we happy? We're happy [80:26] because we said that the lower bound of [80:30] the loss function we care about [80:32] is actually something that is expressed [80:34] with a KL divergence of [80:37] two quantities that we also know how to [80:39] compute. [80:41] So this is great [80:42] because that means that we can finally [80:45] compute that lower bound. We can finally [80:48] compute it because we need to just [80:50] compute each term, put them in the KL [80:52] divergence [80:53] and we just compute the results. [80:57] And so if we do that, if we had more [80:59] time, [81:00] then we could have shown that the loss [81:04] function [81:06] is actually [81:07] something that is a function of the log [81:11] of pi theta of [81:15] predicting the clean [81:17] token given the noise [81:19] sequence [81:21] and the noise level. [81:23] And I think you had a question on the T [81:27] being between zero and big T. So I just [81:29] want to say that [81:31] here we can choose to actually rescale T [81:35] to be between zero and one instead, [81:38] which people typically do. [81:40] And if we were to do that, then the last [81:43] function gets much easier. [81:46] And you see that this log of pi theta [81:50] is actually weighted by a term minus one [81:52] over two [81:55] if you assume that alpha t, the [81:57] probability of a token being unmasked [82:00] is equal to one minus t. [82:02] So in other words, the probability of a [82:05] token being masked is exactly equal to [82:08] t. [82:10] So it's a linear noise schedule. [82:13] So all that to say that [82:15] I think the takeaway from all these [82:17] derivations is [82:18] if you take some assumptions, [82:21] then you can derive a last function [82:24] that is going to allow you [82:27] to train [82:28] a model [82:30] that is going to generate tokens in a [82:31] diffusion diffusion way. So [82:34] we're now going to spend the next few [82:36] minutes actually talking about [82:39] exactly how we want to use that. So all [82:42] that is the math part and again, we did [82:45] not have the time to go through the [82:46] details, but if you're interested, we [82:49] also have some links. [82:52] So [82:53] the question here that I have is, well, [82:55] all of that is great, but how can we [82:57] train and use our model in practice? [83:02] So let's start with training. So we said [83:04] we can actually learn a model that takes [83:07] in [83:08] a noised sequence and a noise level and [83:11] tell you the clean tokens. So how do we [83:13] do that? [83:15] The first step is to actually sample the [83:17] noise level and so here is between zero [83:19] and one. [83:21] And what we're going to do is to mask [83:23] our sequence [83:25] with a probability of t. So every token [83:29] will be masked with the probability of [83:30] t. [83:32] The second thing [83:34] is [83:35] you're going to learn [83:37] what these masked tokens [83:40] actually were. [83:42] So So going to use a model that takes [83:44] your corrupted sequence as input, [83:47] and it's going to try to estimate what [83:49] is the token that was corrupted. [83:54] And then the third step is to just plug [83:56] that into the loss that we just arrived [83:59] and to backpropagate and just do that [84:02] over and over again. [84:04] That is your training process. [84:07] So now let's go to inference. So here [84:10] you assume that you have trained your [84:12] diffusion model [84:14] and you what you're interested in is to [84:16] generate a new response. [84:20] So you start with complete noise. So [84:23] here it's only masked tokens [84:26] and [84:27] you're going to just input that into [84:29] your diffusion based LLM. [84:32] What you're going to obtain is [84:35] you know predictions of clean tokens. [84:39] But if you remember, so a few slides ago [84:42] we said [84:43] our learned [84:46] our learned reverse process [84:48] actually predicts [84:50] the masked token with some probability 1 [84:52] minus RT, but then an unmasked token [84:55] with some probability RT [84:57] associated with the probability that is [85:00] given by our model. [85:02] So actually among the tokens [85:05] that we have predicted [85:07] part of them will actually be masked. [85:10] So the second step is to remask [85:13] these tokens [85:15] and then commit to the remaining tokens. [85:19] So we end up with a sequence [85:22] that is less noisy [85:24] than the start because the start there [85:25] was only noise. [85:28] The idea is now you take that less noisy [85:32] input [85:34] and you pass it into your diffusion [85:35] model [85:36] and you repeat the process. You try to [85:38] predict [85:39] the masked tokens [85:42] and [85:43] as we said part of those predictions [85:46] will be remasked [85:48] with some probability [85:51] and the other ones will be committed. [85:55] And then you start that over and over [85:56] again until hitting your last step where [86:00] you can [86:02] just have your whole sequence be [86:04] revealed. [86:06] And this [86:08] is how you do inference. [86:12] And in the second part, Shervin will [86:15] tell us what we can do with it because [86:17] all that was great. It's a bit of math, [86:19] but hopefully some intuition as well. [86:22] And so with that, [86:23] I'll give it to Shervin. [86:26] >> Thank you, Afshin. [86:28] So we're going to continue this last [86:30] part on the intuition. So we saw a bunch [86:32] of formulas and derivations and now [86:36] we're going to continue and see what [86:38] links we can put to this diffusion [86:40] process and what are its failure modes [86:43] and interesting properties. [86:44] So first, as Afshin had mentioned it, [86:47] some of you might think, okay, hey, we [86:50] talked about something that looks like [86:51] this in lecture two. We have an encoder [86:54] and we have some masked tokens and we [86:57] try to predict things out of it. And [86:59] then I would say, well, you're right. [87:02] You had a projection layer that would [87:04] try to predict what the masked token [87:07] was. [87:09] But as Afshin mentioned, one key [87:11] difference that we have between [87:13] diffusion and BERT [87:15] is that BERT was just a pretext to learn [87:18] about language. We didn't actually care [87:21] about the unmasked response that we're [87:23] going to get. We just wanted to use the [87:26] excuse of this loss function to make the [87:29] weights of the encoder learn something [87:31] useful for other tasks. [87:34] But here, generation is our primary [87:36] goal. [87:37] So that is the first difference. [87:39] The second main one is that BERT didn't [87:41] have this process of T steps because we [87:44] didn't care about perfect generation. We [87:46] just wanted to learn features. It was [87:48] just one step. [87:50] And then a last interesting difference [87:53] is that the BERT authors [87:56] they had [87:58] looked for the perfect recipe to learn [88:00] about language and they had fixed that [88:03] amount of masked tokens. So you had 15% [88:07] of tokens that were going to be masked [88:09] and then we were trying to predict them. [88:12] So it's different from the case that we [88:13] have here where we progressively go from [88:16] fully masked to fully revealed. [88:21] Okay, great. [88:22] So now let's talk a bit about failure [88:25] modes. Let's suppose T is low and you [88:28] want to decode multiple tokens at once. [88:31] So let's let's see what could happen. [88:34] So here we have our favorite sentence [88:36] about a teddy bear that is reading. So [88:39] sorry, a teddy that is reading. I'm not [88:41] telling you what the other words are. [88:44] So you have two choices to make the [88:47] sentence make sense in English. Actually [88:50] more, but I for simplicity just two. [88:52] So maybe the teddy bears are reading or [88:55] maybe the teddy bear is reading. Could [88:58] be two options. [89:00] But then you might say wait, [89:02] we do not know [89:05] at the time we sample from the output [89:07] distribution which token has been [89:09] sampled for the other [89:11] position, right? Because you have a [89:13] bunch of representations that come at [89:15] the output of the encoder [89:19] and then you sampled some token. But [89:21] these tokens, they're sampled in [89:23] parallel. [89:24] So you could well [89:26] come into a case where [89:28] you have [89:29] the teddy bears [89:31] is reading, which is bad. [89:35] So we need some flexibility there. [89:38] So [89:41] who can tell me [89:43] what could be an option to [89:46] remedy that? So we said we unmask tokens [89:49] and then we commit to them. [89:53] Is there possibility to [89:56] renegotiate some committed tokens? So [89:59] this is what we're going to see here. [90:01] And [90:03] we can imagine a process where once we [90:05] commit to these tokens, we randomly [90:09] mask them again, so like some of them [90:12] again, and then try to predict them [90:13] again. [90:15] And by doing so, the masked token will [90:18] have in its context the other ones that [90:21] have been predicted, so you can remedy [90:24] these cases where inconsistencies have [90:26] been generated in parallel and have [90:30] these auto correct. [90:33] But the thing is [90:35] you do not know [90:37] what has been inconsistent, right? [90:39] Because you're at inference time, you're [90:41] trying to do your best to get the best [90:43] quality, but you do not know what is the [90:46] case that you have here. We are in a [90:48] optimal setting. This makes sense. I'm [90:50] telling you there are two combinations, [90:53] but this is not always the case. You [90:55] could well be in a case where you remask [90:58] a token that was great. So let's say the [91:00] teddy bear [91:02] the teddy bear is reading, maybe you are [91:04] not [91:05] remedying bears and ease, but maybe you [91:08] remask teddy. [91:10] And then you're up for more trouble, [91:11] let's say if you were to sample another [91:13] token that doesn't make sense. [91:16] So who can [91:18] tell me some intuition of what could [91:20] help us more here? [91:24] So here I resampled [91:27] the mask token to unmask randomly. [91:31] Is there a way to not do that randomly? [91:38] Maybe you could use probability [91:40] distributions. You have the probability [91:43] distribution of the token to be [91:45] predicted and you could use maybe these [91:47] as confidence scores. [91:49] Well, let's try to do that. [91:53] So now let's suppose we have generated [91:55] all these tokens at several steps. Maybe [92:00] the has been the first one that was [92:02] generated and [92:04] you know oftentimes when a sentence [92:06] starts maybe you have a or a the so it [92:08] had a fairly high probability. [92:11] Then maybe we had the reading that had [92:14] for some reason high probability and [92:15] then teddy [92:17] which came afterwards with a very small [92:19] probability because [92:22] what are the odds for a teddy bear to be [92:23] reading but in this class the teddy bear [92:26] reads a lot [92:27] and so on and so forth. [92:29] But [92:30] the thing is [92:32] if you have the problem of generating [92:36] tokens together [92:37] then maybe that each token separately [92:40] with stale context will have still a [92:43] high probability. [92:44] So here in this case where we generate [92:46] both tokens bears and is if we do not [92:50] know what the other token is [92:53] then given the other context that was [92:55] here [92:56] BOS the [92:58] teddy and reading [92:59] then it was fairly a high probability. [93:02] So it's not working here [93:05] which is why we can come up with the [93:07] process [93:09] that can look at the probability of that [93:12] token occurring given the current [93:15] context and this is what some papers [93:17] explore by training some [93:20] classifier that's [93:22] aim at doing that. [93:25] Okay great. So now let's go back to your [93:27] point at the beginning of the lecture. [93:29] So let's take a look at inference speeds [93:32] which is one key advantage of such [93:35] models. We're saying they can generate a [93:37] bunch of things in parallel which is [93:39] much better than auto regression. [93:42] And let's put ourselves in the so-called [93:46] worst case scenario. So you have a large [93:48] prompt as input [93:50] and a small response as output for as a [93:53] setup. So this is how it would look like [93:55] in the kinds of LLMs that we have seen [93:58] in the past lectures. And in the kind of [94:00] LLM that we have seen today, you would [94:02] have a large prompt and then a bunch of [94:04] mask tokens and then you try to generate [94:07] the response. [94:11] So I have a question for you. In this [94:13] setup, [94:14] which of the two completions do you [94:16] think could be fastest given the [94:19] assumptions that we have seen so far? [94:22] So the question is do you mask the [94:23] prompt in the diffusion LLM? So exactly [94:25] as in autoregression, the prompt is a [94:28] sub is a prefix that is given to you. So [94:30] so far we have had this BOS token [94:34] that was given to you as input. So it [94:36] was the unguided case. But when you are [94:39] a user and you you use a diffusion LLM, [94:42] you will ask for something and you want [94:44] that response to anchor on it, which is [94:46] why it doesn't get masked. [94:49] The response will have bidirectional [94:51] attention on this input. [94:55] Yeah. [94:56] Only the response. [94:58] Yeah, great point. [95:00] So going back to this question, does [95:02] anyone have [95:04] a guess [95:05] of which is fastest here? [95:08] Okay, so the answer is first one, yes. [95:10] So let's try to see why together. So [95:13] let's go back to first principles and [95:15] try to compute the time it takes for an [95:18] answer to be generated. [95:19] So in the autoregressive case, we had [95:22] seen a few lectures ago at the inference [95:26] systems lecture [95:28] that we had a face that we called [95:31] prefill. So let's say you have a huge [95:33] prompt. You need to have the [95:34] representations of keys and values [95:38] computed in order for your generation [95:41] case to anchor on these [95:44] vectors. So this is why you have a [95:46] teacher forcing stage where you do all [95:50] of that in parallel. So you have a [95:52] prefill [95:53] and then the autoregression case [95:55] computes one token at a time, [95:58] which is why you have a number of passes [96:01] that correspond to your response length. [96:04] And then [96:05] in these diffusion LLM world, you do not [96:08] have [96:09] these two steps. You have just one step. [96:11] You want to turn your prompt plus a [96:13] bunch of noise [96:15] up to the answer that you're looking for [96:18] with a fixed number of steps T. [96:21] Now let's compare orders of magnitude. [96:24] So this teacher forcing phase and the [96:27] one [96:28] where you compute a forward pass. [96:31] So in one case you have causal attention [96:33] in the autoregression case and in the [96:35] encoder case you have bidirectional [96:37] attention. So you might have [96:40] these as a factor and then architectural [96:42] considerations that [96:44] might make them different in terms of [96:46] speed, [96:47] but overall same order of magnitude. [96:49] Now let's look at [96:51] other parameters. So number of passes is [96:54] fixed. We saw it's maybe tens or [96:56] hundreds. [96:57] And the autoregression case has, in this [97:01] case, an output size that is low. So [97:04] let's suppose [97:05] the number of passes doesn't need to be [97:07] high. But surprise, [97:09] the time [97:11] that you need to compute per pass, since [97:13] you have cached all these keys and [97:15] values, [97:16] is small because all you have to do is [97:18] to do this causal attention of [97:22] one new token. [97:25] So at the end of the day, as your [97:27] intuition guided you, [97:29] the first choice could be faster in this [97:33] setting. And we're going to see how we [97:34] can [97:36] remedy that in order to make our [97:38] intuition of making diffusion LLMs be [97:41] the fastest come true. [97:45] So let's focus on this DLLM case and on [97:48] each factor and then see what we can [97:50] improve. So let's first [97:52] focus on [97:54] the time you take per pass. [97:57] So we said [97:59] we have a bunch of representations that [98:01] we need to compute. We didn't talk about [98:05] anything regarding prompt caching here. [98:08] And [98:10] what we want to do here is to see if we [98:12] have a way to cache some of the [98:14] representations in order to reuse them. [98:17] So there was a question here that said, [98:19] okay, by the way, what do you put as [98:21] input? What is your mask? What is your [98:24] non-mask? So you have your prompt [98:26] that stays fixed. [98:28] But as you might guess, [98:30] bidirectional attention, [98:32] when you compute these new tokens, the [98:36] representations that correspond to the [98:38] prompt, they will change. [98:40] But the thing is, will they change a [98:42] lot? [98:44] Some papers have studied it and maybe [98:46] not that much. [98:48] So this is why [98:50] one way to deal with it is to compute [98:53] these representations once or maybe [98:55] several times, [98:57] but then space the number of times [99:00] that you need to refresh such [99:01] representations. [99:03] And then here in one of the papers, so [99:05] DLLM cache here, you can see [99:08] so KP is the cadence at which you [99:12] refresh [99:13] your prompt cache. [99:15] You see that [99:17] anecdotally [99:18] if you do not refresh it, [99:20] then the end accuracy sometimes [99:22] increases. That might be due to the fact [99:25] that as you unmask [99:27] the tokens, maybe they introduce noise [99:29] into the representation of [99:33] the prompts [99:34] um hidden representation. [99:36] So but you see overall that it doesn't [99:38] change much, [99:40] which is great. [99:42] Now you might tell me something else. [99:45] So we have here an encoder [99:48] with a concept of bidirectional [99:50] attention that we haven't really talked [99:52] about so far as to how much [99:54] it is [99:56] a great assumption for us. It is, but [99:58] maybe we can reduce this assumption in [100:01] order to leverage some of the benefits [100:03] of speed [100:04] that autoregression had. [100:06] So how about we divide these prompts in [100:10] two blocks and then we do the diffusion [100:14] by blocks, which means [100:16] that [100:18] within each block we allow this [100:20] bidirectional attention to happen, but [100:23] then as you complete one block at a [100:25] time, you can leverage the [100:26] representations that you have fixed [100:29] in the past and then consider them as [100:31] exact caching and then attend on them in [100:34] a causal fashion. [100:37] So this is one other approach that is [100:39] commonly used. [100:42] Okay, so this was for a time per pass. [100:44] Now let's focus on the other [100:47] factor, so the number of passes [100:49] themselves. [100:51] So since we do not have time, I'm going [100:53] to give you the clues directly. So one [100:57] option in order to distil knowledge into [101:02] lesser amounts of steps could be done by [101:04] distillation [101:06] and we could use a teacher that has more [101:09] knowledge than a student [101:12] to [101:13] distinguish the steps and then ask a [101:15] student to directly fit on a lesser [101:17] amount of steps. [101:19] So [101:21] here in this case, [101:22] we ask the teacher to do two steps [101:27] and then the students to directly fit [101:30] in a single step. [101:32] And then the key here is to distil the [101:34] knowledge that intermediate [101:37] token resolution has given the teacher [101:40] into feeding [101:41] the knowledge of the student. [101:44] So you do some loss that compares the [101:47] probability distribution of the teddy [101:49] token with the one that was generated [101:51] with the teacher one. And then regarding [101:53] bear, we leverage the richness of the [101:56] representation that bear was predicted [101:59] in because we knew that teddy was [102:01] predicted in the teacher case. [102:03] So you have a better informed [102:05] probability distribution to fit against. [102:09] Okay, this is great, and you can do that [102:12] with some principled mechanisms. So [102:16] maybe every two steps of the teacher, [102:18] you try to fit the students. [102:20] And once it's done, you can even divide [102:23] the number of steps it takes by two [102:25] further on [102:28] until you're happy with the quality. And [102:30] I think the paper that was attached here [102:33] arrived to a number of steps that was at [102:34] about 10 if you want some order of [102:37] magnitude. [102:39] Okay, great. So now we talked about [102:41] inference. Let's talk about training. [102:44] How [102:45] meaningful is the training signal when [102:48] you use these diffusion LLMs? [102:50] So let's just recap what we had in the [102:53] autoregression case. [102:54] So there it was honestly a great world. [102:58] You had [102:59] all of the tokens given as input, and [103:01] then in a teacher forcing way, you had [103:04] all the predictions for which you had [103:07] true labels on that you could fit [103:09] against the predictions that your model [103:11] would do. [103:12] So you have a teacher forcing with [103:14] ground truth targets, [103:16] and then as input, you also have ground [103:19] truth that is fed as input. So every [103:21] output [103:22] is deeply anchored in your labels. [103:26] And this single teacher forcing step [103:30] is exactly the process that leads you to [103:33] learn about the generation of a given [103:35] sequence. So it's greatly contained. [103:38] But on the other hand, for diffusion, [103:40] let's say you do a pass, you just unmask [103:43] a subset of your tokens, [103:46] which is not great. You you spend a lot [103:48] of compute just to get a little bit of [103:50] information. [103:52] And also these [103:55] tokens, they attend on representations [103:58] that are not [103:59] resolved yet. So you do not have a [104:02] strong learning signal in the same way [104:05] as you had for autoregression. [104:07] And for these two reasons, in order to [104:09] reach a similar loss, you need a lot [104:12] more compute on the diffusion side in [104:14] order to reach it compared to [104:16] auto-regression. [104:17] And maybe I'm going to gloss over it, [104:20] but offline you can see [104:23] that there is [104:26] a way to compute that [104:28] in a in an exact way because we saw that [104:31] the loss that we have in the diffusion [104:33] case is not the true loss that we're [104:35] looking for, but it's a lower bound that [104:38] we're trying to estimate. So when you [104:40] compute the loss, you're not computing [104:42] this joint probability immediately. You [104:44] have some upper bound that you try to [104:46] minimize. [104:48] And there is a way to compute that with [104:50] some mechanism. [104:52] So if you inject the ground truth at the [104:55] right steps and compare the [104:57] distributions, then you can recover a [104:59] single trajectory and then [105:01] fit against it. And then you see that [105:05] the typical order of magnitude of [105:07] compute efficiency is like 10 times [105:10] less. So you you need 10 times the [105:12] number of flops to reach a similar loss. [105:17] Okay, now you might [105:18] wonder how do I get the best of both? [105:22] So [105:23] John Joyce is going to give you some [105:25] clues and a last guess. [105:27] So [105:28] what have we [105:30] seen in the past [105:32] where we want fast generation but then [105:35] principled verification? [105:40] So we had written some formulas on the [105:42] blackboard to try to see whether a [105:44] two-stage process would fit the target [105:47] distribution. [105:48] Do you remember the concept [105:51] that benefits from a fast generator? [106:01] Speculative decoding. [106:03] So you had, if you remember, so lecture [106:06] five, you had a draft model that was [106:09] fast and quick that would propose some [106:12] draft tokens and then you have a [106:14] verifier that comes and says whether [106:16] these tokens are indeed the ones it [106:18] would have sampled. [106:20] And if it's the case, then you are a few [106:22] tokens ahead. [106:24] But the thing is that draft LLM was [106:26] still an autoregressive one in that [106:28] case, and we see that autoregression is [106:31] sequential and takes time, and we want [106:32] to parallelize this. [106:35] And you can come up with a mix of the [106:37] two. So you can have a diffusion LLM do [106:39] the drafting and then still have the [106:41] autoregressive one that we have seen can [106:44] be made of high quality, [106:46] verified, which is great, and you do see [106:49] speed ups in practice. [106:51] Now [106:52] when you look at these speeds, [106:55] so there are some graphs that show that [106:58] diffusion can bring [107:00] a speed per user that is much greater, [107:03] but it's at the detriment of [107:06] the ability to parallelize across [107:09] patches. [107:10] But at the user level, you might see [107:13] much faster speeds, [107:15] and then this ability to look [107:17] bidirectionally can be natively [107:20] leveraged in the case of coding where, [107:22] for example, you want to fill something [107:24] and you have context in both ends, which [107:26] is called fill in the middle task. [107:29] And [107:30] you and I know that in coding you want [107:32] fast [107:34] feedback loops, which is important. [107:37] And in the terms of challenges, so you [107:39] have training that we saw is more [107:41] expensive. So if you have a given [107:42] compute budget, you do not have the [107:44] incentive to go the DLLM way. [107:47] So you have [107:48] an area of research to adapt existing [107:52] benefits of autoregression towards [107:54] diffusion. [107:56] And with that, I hope you have a great [107:59] Thanksgiving.