Efficient visual image generation method for representing dynamic fusion and memory information recovery
By introducing the representation-aware merging-unmerging module into the diffusion model, the problem of loss of representation information is solved, the quality of image generation and the speed of inference are improved, and efficient visual image generation is achieved without the need to retrain the model.
Patent Information
- Application Number
- CN202411030582.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-30
- Publication Date
- 2024-10-18
- Estimated Expiration
- 2044-07-30
AI Technical Summary
Existing diffusion model acceleration methods ignore the specific information of representations during the representation merging and unmerging process, resulting in information loss and affecting image generation performance and inference speed.
A representation-aware merging and unmerging module is designed to reduce information loss through representation-aware partitioning, two-party matching, ratio extraction and merging, and a representation-aware merging and unmerging module with a Transformer structure is introduced into the denoising network to utilize ratio information. Restore original representation and reduce computational cost.
It effectively reduces the loss of representation information, improves the quality of image generation and inference speed, and achieves efficient visual image generation without the need to retrain the model.
Smart Images

Figure CN118799222A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the fields of machine learning and computer vision, and in particular to a method for accelerating and enhancing the quality of a diffusion model for image generation tasks. Background Art
[0002] In the past few years, various generative models have been explored to generate images. Before the diffusion model, researchers mainly developed methods based on three different generative models, including generative adversarial networks (GANs) [1], variational autoencoding (VAEs) [2], and flow-based models [3]. However, GAN-based methods are usually difficult to optimize, while VAE-based and flow-based methods have difficulty in generating high-quality images.
[0003] Recently, a diffusion model has been proposed to generate images by gradually fitting the inductive bias of image data. The diffusion model has a forward diffusion process and a backward denoising process. The purpose of the forward diffusion process is to add Gaussian noise to the original image, and the purpose of the backward denoising process is to recover the original data from the noisy data. Due to the advantages of diffusion models such as stable training and strong data distribution modeling capabilities, they have been widely used in image generation and other fields. Initially, diffusion models operate in pixel space, which requires a long training and inference time. To solve this problem, a stable diffusion model (Stable Diffusion) [4] was proposed. Stable diffusion uses a VAE image encoder to generate latent features of the input image instead of the pixel space. Then, stable diffusion performs forward and backward processing on the latent feature space. Finally, the stable diffusion technique recovers the clean image from the latent space through the VAE image decoder. In addition, by introducing a cross-attention operation between text and image features, the stable diffusion technique can also perform text-to-image generation. By training on a large-scale image-text dataset, the stable diffusion technique shows a strong ability to generate high-quality images from given descriptions.
[0004] Although diffusion models have strong image generation capabilities, these models suffer from slow inference speed. Therefore, researchers have begun to explore efficient diffusion models. Some studies have improved the efficiency of diffusion models by using model distillation and quantization. For example, PTQD[5] discretizes weights and activations using quantization techniques. DeeDiff[6] introduces an early exit strategy to accelerate the generation process by sampling uncertainty estimation module (UEM). Diff-Pruning[7] designs a compression strategy to derive a lightweight diffusion model from an existing model. Although these methods are effective, they usually require resource-intensive retraining, which is impractical for large-scale pre-trained models such as stable diffusion.
[0005] In contrast, some works focus on developing efficient diffusion models that do not require training. Among these works, some methods explore more efficient multi-step denoising processes. DDIM[8] adopts a non-Markov diffusion process to reduce the number of denoising steps.
[0006] diffusion process, thereby reducing the number of denoising steps. DeepCache[9] exploits the temporal consistency of high-level features at different steps. By caching features, DeepCache can skip multiple steps of high-level feature extraction without additional training. Similarly, Faster Diffusion
[10] reuses encoder features to speed up inference. Some methods aim to improve the inference efficiency of each step of the model. Agent Attention
[11] introduces agent representations into the attention module. ToMe-SD
[12] explores merging similar representations and using the merged representations to speed up subsequent operations such as self-attention. ToFu
[13] combines representation pruning and merging into a unified algorithm by using them at different layers of the model.
[0007] References:
[0008] [1]Goodfellow, I.; Pouget-Abadie, J.; Mirza, M.; Xu, B.; Warde-Farley, D.; Ozair, S.; Courville, A.; and Bengio, Y. 2014. Generative adversarial nets. Advances in neural information processing systems, 27.
[0009] [2]Kingma, DP; and Welling, M. 2013. Auto-encoding variationalbayes.arXiv:1312.6114.
[0010] [3]Dinh, L.; Krueger, D.; and Bengio, Y. 2014. Nice: Non-linear independent components estimation. arXiv: 1410.8516.
[0011] [4]Rombach,R.;Blattmann,A.;Lorenz,D.;Esser,P.;and Ommer,B.2022.High-resolution image synthesis with latent diffusion models.In Proceedings of theIEEE / CVF conference on computer vision andpattern recognition,10684–10695.
[0012] [5]He,Y.;Liu,L.;Liu,J.;Wu,W.;Zhou,H.;and Zhuang,B.2024.Ptqd:Accuratepost-training quantization for diffusion models.Advances in neuralinformation processing systems,36.
[0013] [6]Tang,S.;Wang,Y.;Ding,C.;Liang,Y.;Li,Y.;and Xu,D.2023.Deediff:Dynamic uncertainty-aware early exiting for accelerating diffusion modelgeneration.arXiv:2309.17074.
[0014] [7]Fang,G.;Ma,X.;and Wang,X.2023.Structural pruning for diffusionmodels.Advances in neural information processing systems.
[0015] [8]Song,J.;Meng,C.;and Ermon,S.2020.Denoising diffusion implicitmodels.arXivpreprint arXiv:2010.02502.
[0016] [9] Ma, X.; Fang, G.; and Wang, X. 2024. Deepcache: Accelerating diffusion models for free. In Proceedings of the IEEE / CVF conference on computer vision and pattern recognition, 15762–15772.
[0017]
[10] Li, S.; Hu, T.; Khan, F. S.; Li, L.; Yang, S.; Wang, Y.; Cheng, M.-M.; and Yang, J. 2023. Faster diffusion: Rethinking the role of unet encoder in diffusion models. arXiv:2312.09608.
[0018]
[11] Han, D.; Ye, T.; Han, Y.; Xia, Z.; Song, S.; and Huang, G. 2023. Agent attention: On the integration of softmax and linear attention. arXiv:2312.08874.
[0019]
[12] Bolya, D.; and Hoffman, J. 2023. Token merging for fast stable diffusion. In Proceedings of the IEEE / CVF conference on computer vision and pattern recognition, 4599–4603.
[0020]
[13] Kim, M.; Gao, S.; Hsu, Y.-C.; Shen, Y.; and Jin, H. 2024. Token fusion: Bridging the gap between token pruning and token merging. In Proceedings of the IEEE / CVF Winter conference on applications of computer vision, 1383–1392. Summary of the Invention
[0021] The main technical problem solved by the present invention is how to make full use of representation information to improve merging and demerging operations to enhance the performance of image generation based on accelerating the diffusion model by means of representation reduction. At present, this type of acceleration method ignores the specific information of representation when performing representation merging and demerging, resulting in loss of representation information. To address this problem, the present invention proposes a representation-aware acceleration method for stable diffusion, which does not require training and introduces a new module, namely, the representation-aware merging-demerging module. Representation-aware merging-demerging aims to make full use of representation-specific information and reduce information loss during representation merging and demerging. Therefore, high-quality images can be generated and the reasoning speed of stable diffusion can be accelerated.
[0022] An efficient visual image generation method for representing dynamic fusion and memory information restoration comprises the following steps:
[0023] Step 1, designing a representation-aware merging-demerging module, including representation-aware merging and representation-aware demerging, wherein the representation-aware merging includes representation-aware partitioning, two-way matching, ratio extraction and merging;
[0024] Step 2: Load the pre-trained diffusion model, including the VAE encoder, CLIP text encoder, and denoising network; select text as the prompt mode;
[0025] Step 3: For text prompts, the text matching the image is fed into the CLIP text encoder to output text features;
[0026] Step 4: The denoising network is a neural network that incorporates a Transformer structure, and the denoising network is modified by adding the representation perception merging-demerging module in the neural network;
[0027] Step 5: Set relevant hyperparameters including the merging rate and the number of iterations, and send the randomly generated latent space Gaussian noise image features and text features together into the modified denoising network for iterative denoising;
[0028] Step 6: Use the VAE image decoder to restore the image.
[0029] The representation-aware merging-demerging module is as follows:
[0030] (1) Representation-aware partitioning is used to divide the representation into a source representation set and a target representation set. Dynamic source and target partitioning is performed based on the specific information of the representation. t , first calculate the variance of each input representation in the channel dimension; the resulting variance map is denoted as F var; Then, the local maximum value in each sub-region in the variance map is selected, and the representation at the position index of this local variance maximum value is used as the target representation, and the representations at the remaining position indexes are used as the source representation;
[0031] (2) Performing bidirectional matching on the source representation and the target representation, each source representation is assigned to the corresponding target representation with the highest similarity; sorting the similarities, and selecting the corresponding number of representations with the highest similarity according to the set merging rate to obtain the number of representations to be merged, and these representations are used as the source representations to be merged later;
[0032] (3) Perform ratio extraction and merging. On the one hand, the target representation of the bidirectional matching and the source representation that needs to be merged are merged by averaging to obtain the merged representation F m , in order to have information basis for subsequent characterization recovery, the norm of the matched source characterization and target characterization is calculated; the combined characterization F m The norm of the combined representation F is divided by the norm of the source representation or the target representation to generate the corresponding representation ratio; the combined representation F m and the unmerged source representation F u are fed together into a transformer-based component;
[0033] (4) Representation-aware solution merging is used to restore the merged representations to the same number of input representations, and the original representations are restored using ratio information.
[0034] 1. The efficient visual image generation method according to claim 2 is characterized in that, in (4), the method of restoring the original representation using ratio information is as follows: mapping the merged representation into the corresponding source representation and the destination representation through the representation ratio generated by the representation perception merging; and multiplying the output representation of the merged representation obtained after the merged representation is passed through the components by the representation ratio obtained in the previous module as the corresponding target representation and the output representation of the source representation for the merging operation.
[0035] In step 4, the denoising network is a U-net network that incorporates a Transformer structure.
[0036] The method for iterative denoising in step 5 is as follows:
[0037] (1) Add token pruning method, set the number of merged layers to be applied only on the layer with downsampling ratio of 1, and set the transformer module for merging to be the self-attention layer module;
[0038] (2) In the modified denoising network, token merging and token demerging are performed before and after each self-attention layer module. The initial input tokens are stored after representation perception merging, and the ratio information of the representations before and after merging is calculated;
[0039] (3) The merged representation is input into the self-attention layer, the output of the self-attention layer is merged through the representation-aware solution, and the representation is restored according to the representation ratio information calculated and saved before, and the original token size is restored, and then the subsequent residual connection operation is performed.
[0040] The present invention uses the representation perceptual merging-demerging (TMU) technology to reduce the loss of representation information and speed up the reasoning speed, thereby obtaining an efficient visual image generation method for representation dynamic fusion and memory information recovery. This method not only does not require retraining, but also can ensure the quality of image generation and improve image generation efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] Figure 1 Representation-aware merging-demerging module TMU
[0042] Figure 2 Representation Perception Partitioning
[0043] Figure 3 Ratio extraction and merging
[0044] Figure 4 Flowchart of the proposed method DETAILED DESCRIPTION
[0045] The present invention is described below in conjunction with the accompanying drawings and embodiments.
[0046] First, the proposed representation-aware merging-demerging module is introduced in detail.
[0047] The purpose of representation-aware merging-de-merging is to reduce the loss of representation information and speed up the denoising process at each step. In Stable Diffusion, the denoising process adopts a transformer-based UNet structure. In each transformer block, there are three components, including a self-attention layer, a cross-attention layer, and an MLP layer. We propose representation-aware merging to reduce the number of representations before inputting them into these transformer-based components. Therefore, the transformer-based components only need to process a small number of representations after merging, thereby reducing the computational cost. At the same time, due to the residual connection contained in the network, we need to restore the output of the component on a small number of representations to the original size before merging. Therefore, we perform representation-aware de-merging to restore the representation. Figure 1 The detailed structure of our proposed representation-aware merging-demerging is given, including representation-aware merging and representation-aware demerging.
[0048] Representation-aware merging consists of representation-aware partitioning, two-way matching, ratio extraction, and merging. The purpose of representation-aware partitioning is to divide the representations into two sets, including a source representation set and a target representation set. In ToMe-SD, it extracts a target representation from each 2×2 sub-region and regards the remaining representations as source representations. We believe that this random strategy cannot select target representations with large amounts of information. To address this issue, we introduce a representation-aware partitioning strategy to perform dynamic source and destination partitioning based on the specific information of the representations. Figure 2 As shown, according to the original input representation F t , we first calculate the variance of each input representation in the channel dimension. The resulting variance map is denoted as F var Then, we select the local maximum in each 2×2 sub-region of the variance map, and use the representation at the position index of the local variance maximum as the target representation, and the representations at the remaining position indexes as the source representations. In this way, we select the partition source and destination representations. Since the representation with a larger variance contains more information, we can use this method to select the representation with a large amount of information as the destination representation.
[0049] After the representation-aware partitioning, we will perform a two-way match between the source representation and the destination representation, which is similar to ToMe-SD. Through the two-way matching, each source representation will be assigned to the corresponding target representation with the highest similarity, and then the similarity will be sorted. According to the set merging ratio, the number of representations that need to be merged is obtained. The corresponding number of representations with the highest similarity are selected. These representations will be used as the source representations to be merged later. Then, we introduced the ratio extraction and merging module. On the one hand, the ratio extraction and merging module aims to merge these matched destination representations and the previously obtained source representations that need to be merged by averaging the representations to obtain the merged representation F. m In subsequent operations, we only need to input the merged representation and the source representations that are not merged after the previous sorting into various components based on the transformer, so the number of input component representations will be reduced accordingly, and the reduced number is consistent with the number of merges we set, that is, the number of source representations selected to be merged. Figure 3 As shown, we calculate the merged representation F by averaging m At the same time, in order to have information basis for subsequent representation recovery, we also calculated the norm of the matched source representation and target representation. Finally, we merge the representation F m The norm of is divided by the norm of the source representation or the target representation to generate the corresponding representation ratio, where the ratio of the representation can be generated according to this formula in, Represents the source or target representation of a merge.
[0050] Finally, if Figure 1 As shown, the combined representation F m and the unmerged source representation F u are fed together into a transformer-based component similar to ToMe-SD. Since representation-aware merging can remove a large number of source representations, it can reduce the computational cost of transformer-based architectures. Afterwards, residual connections are adopted in each transformer-based layer due to stable diffusion. In order to perform residual operations, we need to restore the merged representations to the same number of input representations, so we adopt a representation-aware de-merging technique to restore the original representations using the ratio information. For the operation of restoring the representations, ToMe-SD only copies the merged representations to the corresponding source and target representations. We believe that this copying operation ignores the specific information of the representations, such as the representation ratio information. Therefore, we introduce a representation-aware de-merging strategy to restore the representations. Figure 1 As shown, our representation-aware decomposition and merging maps the merged representation to the corresponding source representation and destination representation through the representation ratio generated by the representation-aware merging. We multiply the output representation of the merged representation obtained after the merged representation passes through the components by the representation ratio obtained in the previous module as the output representation of the corresponding target representation and the source representation of the merged operation, where the output representation can be calculated according to the formula Generate, where represents the output representation corresponding to the destination or source representation, Represents the output representation of the merged representation.
[0051] This method directly uses the pre-trained diffusion model to generate images. The proposed network does not have any parameter learning, so no training is required.
[0052] Next, we will embed the proposed TMU module into the Stable Diffusion network to introduce the specific implementation of the present invention. Figure 4 A brief description of the specific implementation of the method proposed in the present invention is given, and the specific steps are as follows:
[0053] Step 1: Set relevant hyperparameters including merging rate and number of iterations N; load the pre-trained diffusion model, including VAE encoder, CLIP text encoder and denoising network; select text as the prompt method.
[0054] Step 2: For text prompts, the text matching the image (e.g., “A high-quality photo of a Dandie Dinmont Terrier”) is fed into the CLIP text encoder, and the output text features are added to the network through a cross-attention layer.
[0055] Step 3: The randomly generated latent space Gaussian noise image features and text features are sent to the denoising network together, and denoised iteratively through the U-Net network with the TMU module added. In each denoising network:
[0056] a) The denoising network in the original diffusion model is a U-net network that incorporates a Transformer structure. Among them, the U-Net network has four network structures of different sizes. We design the iteration step to be 50 steps, add a token pruning method, set the merging rate to 50%, set the number of merging layers to be applied only on the layer with a downsampling ratio of 1, and then set the transformer module for merging to be a self-attention layer module. Therefore, in each denoising network, only five layers of self-attention layer modules will perform token merging and token demerging before and after. At the beginning, the token size of the input network is (2×4096×320). After the representation-aware merging, the token size becomes (2×2048×320) and the ratio information of the representation before and after the merging calculated by us is saved as (4×2048×1).
[0057] b) The merged representation is then input into the self-attention layer. Since the number of representations is significantly reduced, the amount of computation will also be reduced accordingly. The output of the self-attention layer is then restored to the original token size (2×4096×320) through representation-aware solution and merging, that is, the representation is restored according to the representation ratio information saved by the previous calculation, and then subsequent residual connections and other operations are performed. Similar operations are performed each time the five-layer self-attention module with a size of 4096 is passed.
[0058] Step 4: Finally, we use the VAE image decoder to restore the image. By inputting the final output of the denoising network into the VAE image decoder to obtain the image features in the pixel space, and then reshape the image features to restore them to the output image size, we get the generated image of the specified input text. In each step of the process, UNet uses the representation-aware merging-unmerging (TMU) technology to reduce the loss of representation information and speed up the reasoning speed. Thus, we get an efficient visual image generation method that represents dynamic fusion and memory information recovery. This method not only does not require retraining, but also ensures the quality of image generation and improves the efficiency of image generation.
[0059] This is just an example of applying the method to Stable Diffusion. This method can also be simply added to any network based on the transformer architecture to speed up the network by reducing the number of representations in the network.
Claims
1. An efficient visual image generation method for characterizing dynamic fusion and memory information recovery, comprising the following steps: Step 1, designing a representation-aware merging-demerging module, including representation-aware merging and representation-aware demerging, wherein: Representation-aware merging includes representation-aware partitioning, two-way matching, ratio extraction and merging; Step 2: Load the pre-trained diffusion model, including the VAE encoder, CLIP text encoder, and denoising network; select text as the prompt mode; Step 3: For text prompts, the text matching the image is fed into the CLIP text encoder to output text features; Step 4: The denoising network is a neural network that incorporates a Transformer structure, and the denoising network is modified by adding the representation perception merging-demerging module in the neural network; Step 5: Set relevant hyperparameters including the merging rate and the number of iterations, and send the randomly generated latent space Gaussian noise image features and text features together into the modified denoising network for iterative denoising; Step 6: Use the VAE image decoder to restore the image.
2. The efficient visual image generation method according to claim 1, characterized in that: The representation-aware merging-demerging module is as follows: (1) Representation-aware partitioning is used to divide the representation into a source representation set and a target representation set. Dynamic source and target partitioning is performed based on the specific information of the representation. t , first calculate the variance of each input representation in the channel dimension; the resulting variance map is represented as F var ; Then, the local maximum value in each sub-region in the variance map is selected, and the representation at the position index of this local variance maximum value is used as the target representation, and the representations at the remaining position indexes are used as the source representation; (2) Perform a bidirectional match between the source representation and the target representation. Each source representation is assigned to the corresponding target representation with the highest similarity. Sort the similarities, obtain the number of representations to be merged according to the set merging rate, select the corresponding number of representations with the highest similarity, and use these representations as the source representations to be merged later; (3) Perform ratio extraction and merging. On the one hand, the target representation of the bidirectional matching and the source representation that needs to be merged are merged by averaging to obtain the merged representation F m , in order to have information basis for subsequent characterization recovery, the norm of the matched source characterization and target characterization is calculated; the combined characterization F m The norm of the combined representation F is divided by the norm of the source representation or the target representation to generate the corresponding representation ratio; the combined representation F m and the unmerged source representation F u are fed together into a transformer-based component; (4) Representation-aware solution merging is used to restore the merged representations to the same number of input representations, and the original representations are restored using ratio information.
3. The efficient visual image generation method according to claim 2, characterized in that: In (4), the method of restoring the original representation using the ratio information is as follows: mapping the merged representation into the corresponding source representation and the destination representation by using the representation ratio generated by the representation perceptual merging; The output representation of the merged representation obtained after the merged representation passes through the components is multiplied by the representation ratio obtained in the previous module as the output representation of the corresponding target representation and the source representation for the merge operation.
4. The efficient visual image generation method according to claim 1, characterized in that: In step 4, the denoising network is a U-net network that incorporates a Transformer structure.
5. The efficient visual image generation method according to claim 1, characterized in that: The method for iterative denoising in step 5 is as follows: (1) Add token pruning method, set the number of merged layers to be applied only on the layer with downsampling ratio of 1, and set the transformer module for merging to be the self-attention layer module; (2) In the modified denoising network, token merging and token demerging are performed before and after each self-attention layer module. The initial input tokens are stored after representation perception merging, and the ratio information of the representations before and after merging is calculated; (3) The merged representation is input into the self-attention layer, the output of the self-attention layer is merged through the representation-aware solution, and the representation is restored according to the previously calculated and saved representation ratio information to restore it to the original token size, and then the subsequent residual connection operation is performed.
Citation Information
Patent Citations
Text-guided image processing method based on diffusion model
CN116977489A
Cross-modal image modification method based on improved diffusion model
CN117333653A
Semantic picture editing method based on diffusion model
CN117671084A
Face image restoration method based on generation diffusion prior
CN118333866A
Systems and methods for text-to-image generation using language models
US20240185035A1
