Manuscript Offprint

arXiv:2609.00885

Denoising Diffusion Generative Models Secretly Calculate Attentions

Farzan Haddadi, Leila Monfared, Ebrahim Rezaii, Mohammadreza Malek-Mohammadi, Pejman Zakalvand, Narges Mokhtari

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Farzan Haddadi†, Leila Monfared†, Ebrahim Rezaii†, Mohammadreza Malek-Mohammadi*, Pejman Zakalvand†, Narges Mokhtari†

Abstract—Denoising diffusion models are the dominant architecture for image generation, whereas most natural language generation and modeling are primarily handled by well-known transformer architectures employing attention mechanism. Here, we show that diffusion models also inherently use an attention mechanism very similar to that of transformers. Therefore, attention emerges as a universal machine learning principle, based on a general training objective. We also show similarities in basic functional principle of auto-encoders and attention-based models. These equivalences allows us to interchange these designs based on practical requirements. As an example, we can reformulate the diffusion framework to reduce the lengthy training process and computation-intensive image generation. Using this approach, a simplified algorithm is proposed for image generation which is based on attention mechanism. Results show that the attention-based implementation achieves comparable performance with significantly less effort and computational resources.

Index Terms—Diffusion model, attention mechanism, autoencoder, data manifold, latent space, interpolation.

I. Introduction

ARTIFICIAL intelligence (AI) encompasses a multitude of proposed architectures for different tasks. Throughout the history of AI, it was a surprise that gradually efficient unified system architectures replaced this multitude of systems for various applications. An important turning point was the advent of the dot-product-based attention mechanism [1]. Transformers were first proposed for tasks of natural language processing (NLP) such as question-answering and chatbots [2]. Soon, it was realized that transformers also have stellar performance in vision applications with the advent of the vision transformer (ViT) model [3].

In image generation, diffusion systems are arguably the best option [4]. Yet, for the best performance they are used in tandem with transformer-based components. Specifically, diffusion principle is used to determine the loss function and high-level train and test schemes, while in network level, an auto-encoder is trained which in turn uses attention mechanism and transformer architecture as its main component [5].

Here, we show that the diffusion principle is equivalent to the attention mechanism. Diffusion denoising probabilistic generative model (DDPM) [4], trains a neural network to reconstruct the original image from its noisy

copies. Then, starting from pure noise, the system can generate a realistic image based on the learned distribution of the dataset.

Detecting the presence of a signal from its noisy version is a classic statistical problem [6]. Specifically, when the noise is Gaussian, the solution is an inner-product detector. While in the context of machine learning theory, we train a neural network to solve this problem, we will show that this problem enjoys a closed-form solution which is basically the attention mechanism. This not only shows that the diffusion system is identical to the attention mechanism, but also provides a previously known statistical basis for the very attention mechanism as the closed form solution to the signal recovery problem in the Gaussian noise [7].

The closed form solution of the diffusion system was first derived in [8]. The authors calculate optimum score function of a diffusion system for a finite dataset. However, they did not notice the relation of their result to the well-known attention mechanism. Then [8] extends the result to include additional structures like CNN network which is used in the DDPM implementation and develops a creativity theory for CNN diffusion systems based on locality and positional invariance properties. Here we use a different approach based on the diffusion loss function and convex optimization to reach the same closed form solution while extending the analysis to include resemblance to transformer and autoencoders. The equivalence between diffusion and transformer principles have broad theoretical and practical consequences in machine learning theory.

It is not sufficient to understand the core diffusion principle in the forms of what we investigate as closed-form one-step solution or convergence trajectory. In practice, diffusion systems are implemented in the inner latent space of a Variational Auto-Encoder (VAE) [9]. Also, in practice the main neural network that performs denoising in the diffusion system is an AE. We argue that the same equivalence exists between attention and AE, in that both systems eventually project a random input on a learned data manifold [10], [11]. Therefore, we reach to an equivalence between three of the most important modern AI systems, namely: attention, diffusion, and AE. This enables us to interchange these systems depending on the situation.

DDPM diffusion system suffers from heavy computations in both training and generation which requires running an encoder hundreds of times on a random input.

† School of Electrical Engineering, Iran University of Science & Technology, Tehran, IRAN

  • Independent researcher

Some efforts have been made to reduce computational complexity specially in generation. A trend in the literatur is to reduce the steps for image generation using non-Markovian statistical models as in Diffusion Denoising Implicit Model (DDIM) [12].

Regarding the training, DDIM is equivalent to DDPM and very computationally complex. It requires adding noise for hundreds of times to each image in dataset to teach network to denoise images with varying degree of noise effectively. Therefore, reducing computational complexity in the training phase is highly important. Here, we calculate a closed form denoiser which reduces the need for training a network on the dataset.

As a result of the equivalence of diffusion and attention, we conclude that deliberate interpolation between neighbor real images in the latent space results is an approximately realistic image. This interpolation can be refined and projected on the real image manifold by a limited recursive application of the outer AE. Overall, the proposed system can generate a realistic image without training an inner AE network, and just by using the dataset images. The results show good quality with considerably lower computations.

The manuscript is organized as follows: The main result and discussion is presented in Sec. II, where a background review, discussion on equivalence between diffusion and attention, and convergence topics are covered. AutoEncoder equivalence with attention and projection on data manifold are addressed in Sec. III. A data structure for fast attention calculation is discussed in Sec. IV. The proposed low complexity generative network is demonstrated in Sec. V, while simulation results are exhibited in Sec. VI.

References (15)