Abstract
Diffusion models exhibit a remarkable ability to generate novel images, a phenomenon often attributed to the inductive biases of their architectures. While convolutional neural networks (CNNs) tend to produce "patch-mosaic" images—randomly stitched training patches—this work investigates how self-attention mechanisms facilitate global coherence. By deriving the optimal score function for a CNN-attention hybrid, we demonstrate that attention introduces a self-consistency term that aligns local patches into a unified, creative whole.
Introduction
Modern diffusion models, such as Stable Diffusion, are celebrated for their "creativity"—the ability to generate realistic images that do not exist in their training data. However, classical theory suggests that an optimal diffusion model should ideally return training samples. Recent research by Kamb & Ganguli (2024) addressed this paradox by highlighting the inductive biases of Convolutional Neural Networks (CNNs). Due to locality and translation equivariance, CNNs learn patch-level distributions rather than full images, resulting in "patch-mosaic" samples where valid training patches are stitched together in nonsensical ways.
This paper extends this line of inquiry to the role of self-attention, a core component of state-of-the-art UNet backbones. We ask: Does attention merely improve patch quality, or does it fundamentally alter the arrangement of these patches to ensure global consistency?
Theoretical Framework
To understand the impact of attention, we derived the optimal score function—the gradient of the log-likelihood—for a network combining a CNN with a self-attention layer. To ensure mathematical tractability, we analyzed a "winner-take-all" (Top-1) attention regime.
Our derivation reveals that the optimal score function with attention includes a novel "self-consistency" term. While the standard CNN term pulls a generated patch toward the broader training distribution, the attention term pulls the patch toward other patches within the same image. This mechanism effectively acts as a "copy-paste" or "reminder" system, ensuring that if a specific feature is generated in one region, the rest of the image adapts to maintain internal logic. This bridges the gap between local patch memorization and global image coherence.
Experimental Methodology
We evaluated our theory using a custom relational toy dataset designed to test internal consistency. The dataset consists of 4x4 RGB images divided into four 2x2 quadrants. Each image follows one of three hidden color-pairing rules (e.g., "if a block contains red, it must also contain green"). Crucially, these rules are consistent within an individual image but vary across the dataset.
A model limited to local patch learning (like a standard CNN) would observe all possible color pairings across the training set and likely mix them inconsistently during generation. We compared four architectures: a pure CNN, a CNN with Top-1 attention, a CNN with fixed "identity" attention, and a CNN with standard learnable self-attention.
Results and Analysis
The empirical results strongly validate the theoretical prediction that attention provides the "global glue" necessary for coherent image generation.
As shown in the qualitative samples, the pure CNN model produces blurry or mismatched color blocks, failing to respect the global pairing rules. In contrast, the CNN + Attention model generates sharp, internally consistent patterns that strictly follow the hidden rules of the dataset. Quantitatively, the difference is stark: the CNN + Attention model achieved a consistency score of 64.03%, compared to only 10.88% for the pure CNN.
These findings suggest that attention is the primary mechanism moving diffusion models from "local creativity" (random mosaics) to "global consistency" (coherent, novel images). It allows the model to maintain the "rules" of an image even when generating a combination of patches it has never seen before.
Discussion and Limitations
While this work provides a rigorous link between attention and global consistency, several limitations remain. The current theory focuses on a simplified architecture with a single attention layer, whereas real-world models utilize complex, multi-layered UNets with interleaved attention blocks. Additionally, the closed-form proof relies on the Top-1 attention assumption and patch independence. Future research will focus on scaling these insights to larger, natural image datasets to determine if the "global consistency" term behaves similarly in high-dimensional spaces.
Summary updated