Patch Diffusion: Faster and More Data-Efficient Training of Diffusion Models
Zhendong Wang, Yifan Jiang, Huangjie Zheng, Peihao Wang, Pengcheng He, Zhangyang Wang, Weizhu Chen, Mingyuan Zhou
Introduction
Diffusion models have become the new de facto generative AI (GenAI) models. Song et al. unite the diffusion models into the framework of score-based generative models . Diffusion models have found great success in a wide range of applications, including unconditional image synthesis , text-to-image generation , audio generation , uncertainty quantification , and reinforcement learning .
Although diffusion models are stable to train and powerful in capturing distributions, they are notoriously slow in generation due to the need to traverse the reverse diffusion chain, which involves going through the same U-Net-based generator network hundreds or even thousands of times . As such, there is great interest in improving the inference speed of diffusion models, leading to many improved samplers such as DDIM , TDPM , DPM-Solver , and EDM-Sampling .
However, diffusion models are also notoriously expensive and data-hungry to train. They require large datasets and many iterations to capture the high-dimensional and complex data distributions. For instance, training DDPM on eight V100 GPUs for the LSUN-Bedroom dataset at resolutions of and takes approximately four days and over two weeks, respectively. A state-of-the-art diffusion model in Dhariwal & Nichol consumes 150-1000 V100 GPU days to produce high-quality samples. The training costs grow exponentially as the resolution and diversity of the target data increase. Moreover, the best-performing models rely on billion-level image datasets such as OpenImages and LAION , which are not easily accessible or scalable.
While some most exciting GenAI results are arguably accomplished by training diffusion models with enormous computational power and data (often owned or led by large corporations), the prohibitive time and data scale required to train competitive diffusion models have presented a critical bottleneck for democratizing this GenAI workhorse technology to the broader research community who generally lack access to such high-end privileged resources. This problem of democratizing diffusion model training is becoming pressing, yet largely overlooked so far.
To democratize diffusion model training, we propose patch-wise diffusion training (Patch Diffusion), a plug-and-play training technique that is agnostic to any choice of UNet architecture, sampler, noise schedule, and so on. Instead of learning the score function on the full-size image for each pixel, we propose to learn a conditional score function on image patches, where both patch location in the original image and patch size are the conditions. Training on patches instead of full images significantly reduces the computational burden per iteration. To incorporate the conditions of patch locations, we construct a pixel-level coordinate system and encode the patch location information as additional coordinate channels, which are concatenated with the original image channels as the input for diffusion models. We further propose diversifying the patch sizes in a progressive or stochastic schedule throughout training, to capture the cross-region dependency at multiple scales.
Patch Diffusion aims to significantly reduce the training time costs while improving the data efficiency of diffusion models. Sampling with our method is as easy as it in the original diffusion model: we compute and parameterize the full coordinates with respect to the original image, concatenate them with the sampled noise, and then reverse the diffusion chain to collect samples, as illustrated in Figure 1. Through Patch Diffusion, we could achieve faster training, while maintaining comparable or better generation quality. We also observe that Patch Diffusion improves the performance of diffusion models trained on relatively small datasets, , clearly superior generation results when training with as few as 5,000 images from scratch. We summarize our main contributions as follows:
The first patch-level training framework, generally applicable to diffusion models, that targets saving training time and data costs.
Novel strategies of patch coordinate conditioning and patch size conditioning/scheduling, to balance training efficiency and effective global structure encoding.
Competitive results while generally halving the training time, and notable performance gains at small training data regimes.
Related Work
Diffusion probabilistic models first construct a forward process that injects noise into data distribution, then reverse the forward process to reconstruct it. The forward process iteratively applies noise to the given images, whereas the reverse process iteratively denoises a noisy observation. After the origin of the diffusion model, many efforts have been made to apply it to various downstream tasks. Ho et al. and Vahdat et al. propose a hierarchical architecture to stabilize the training process of diffusion models and further mitigate memory cost issues. DallE-2 first introduces the diffusion model to the text-to-image generative task and achieves remarkable success. Later, Saharia et al. found that increasing the parameter of the language model improves both sample fidelity and image-text alignment much more than increasing the size of the image model.
Data-efficient training in generative models. Prior to the study of diffusion models, many explorations have been conducted on limited data or even the few-shot setting of generative model’s training schemes, , Generative Adversarial Networks (GANs). To avoid expensive data collection, Zhao et al. propose differentiable augmentation on both the generator and discriminator of GANs and achieve acceptable performance with only 10% data. Karras et al. apply adaptive augmentation strategy for the setting of limited data to prevent information leakage. Wang et al. propose to train GANs with an adaptive forward diffusion process that injects different levels of noise during training, significantly improving GANs’ performance in small datasets. Chen et al. discover the lottery ticket mask of a specific GAN architecture that allows further reducing the training data. Tseng et al. propose to add regularization on top of the existing data augmentation strategy and stabilize the brittle training process of adversarial learning. Others explore the domain adaptation of GAN frameworks when only a few data from target domains are available, . by using elastic weight consolidation or cross-domain correspondence .
Meanwhile, recent works also start exploring the few-shot adaptation of diffusion models . DreamBooth uses four frontal images of a specific subject to finetune a pre-trained diffusion model and additionally set a special indicator in the prompt, where the obtained model is able to generate various examples with the same identity. Later, Zhang et al. reduce the number of required images to only a single example when finetuning the diffusion model, but still generate visually impressive photos given various prompt inputs. However, the above works do not fully explore the setting of training a diffusion model from scratch. Although a few single-image diffusion algorithms only need a single training image, they can only produce variations of the same image and hence focus drastically differently compared to our proposed method.
Resource-efficient training in generative models. To address the issue of mode collapse given limited training data, Lin et al. propose Anycost-GAN that is able to generate examples with different levels of cost during inference. However, their proposed techniques do not help save the training cost, and may even take a longer time to optimize the SuperNet . Coco-GAN firstly introduces the patch-wise training scheme on GAN frameworks. However, since their discriminator still needs to combine several generated patches together, its effectiveness on memory saving is not distinguishable. Lee et al. further apply the patch-wise training scheme to the INR-GAN framework. Although their approach is able to save GPU memory cost, it will hurt the quality of generated examples (, increasing FID on the FFHQ dataset from 8.51 to 24.38). In the meantime, since the low-resolution images are generally more accessible compared to high-resolution ones, Chai et al. adopt any-resolution framework which is able to blend data with different resolutions together to feed the training of GANs, and therefore reduce the partition of the high-resolution part. Despite its superiority of data efficiency, it does not particularly discuss the training costs and the effectiveness of its methodology remains unknown and unexplored for diffusion models.
A handful of works try to tackle the issue of huge training and inference costs in diffusion models. Rombach et al. perform diffusion in a latent space instead of the pixel space, which largely reduces the training and inference cost. Other works study the fast sampling strategy at the inference stage, which does not directly help speed up the training process. Our proposed approach is orthogonal to the aforementioned works and can serve as a plug-and-play module.
Simultaneously with our research efforts, Ding et. al. concurrently developed another model of patch-based denoising diffusion. Their model excels in memory-efficient high-resolution image synthesis while avoiding the introduction of boundary artifacts. Central to their methodology is the introduction of a novel feature collage technique, achieved through a systematic window-sliding process, which effectively enforces spatial consistency.
Patch Diffusion Training
Further generalizing to an infinite number of noise scales , , the forward diffusion process could be characterized by a stochastic differential equation (SDE) and further converted to an ordinary differential equation (ODE). The closed form of the reverse SDE is given by
As shown in Equations (1) and (2), solving the reverse SDE or ODE requires us to know both the terminal distribution and score function . By design, the former is close to a white Gaussian noise distribution. The analytical form of is generally intractable, and hence we learn a function parameterized by a neural network to estimate its values. Denoising score matching is currently the most popular way of estimating score functions applied in diffusion models. After learning the estimated score function , we can obtain an estimated reverse SDE or ODE to collect data samples from the estimated data distribution.
Next, we introduce our patch diffusion training in three subsections. First, we propose to conduct conditional score matching on randomly cropped image patches, with the patch location and patch size as conditions, to improve the efficiency of learning scores. Second, we introduce pixel coordinate systems to provide better guidance on patch-level score matching. Then, we show by using our method, for each reverse step, we could do sampling globally as easily as the original diffusion models, without the need to explicitly sample separate local patches and merge them afterwards.
Following denoising score-matching in Karras et al. , we build a denoiser, , that minimizes the expected denoising error for samples drawn from data distribution independently for any :
Instead of conducting the score matching on the full images, we propose to learn the score function on random-size patches. As shown in Figure 1, for any , we first randomly crop small patches , where we use , the left-upper corner pixel coordinates, to locate each image patch, and to denote the patch size, , . We conduct denoising score matching on image patches with the corresponding patch locations and sizes as the conditions, expressed as
With Equation 4, the training speed is significantly boosted due to the use of small local patches. However, the challenge now lies in that the score function has only seen local patches and may have not captured the global cross-region dependency between local patches, in other words, the learned scores from nearby patches should form a coherent score map to induce coherent image sampling. To resolve this issue, we propose two strategies: 1) random patch sizes and 2) involving a small ratio of full-size images. Our training patch size is sampled from a mixture of small and large patch sizes, and then the cropped large patch could be seen as a sequence of small patches. In this way, the score function learns how to unite the scores from small patches to form a coherent score map when training on the large patches. To ensure the reverse diffusion converges towards the original data distribution, in some iterations during training, full-size images are required to be seen.
We further provide a theoretical interpretation in Appendix A to help understand our method, and conduct a detailed empirical study in Section 4.1 to show the impact of the ratio of full images.
2 Progressive and Stochastic Patch Size Scheduling
To strengthen the awareness of score function in cross-region dependency, we are motivated to propose patch-size scheduling. Denote the ratio of iterations that takes as input the full-size images as , and the original image resolution as . We propose to use the patch options, as follows
Two patch-size schedulings could be considered. 1) Stochastic: During training, we randomly sample for each mini-batch with the probability mass function defined in Equation 5. 2) Progressive: We train our conditional score function from small patches to large patches. In the first training iterations, we fix the patch size as , while in the second training iterations, is applied. Finally, we train the models on full-size images for ratio of the total iterations.
Empirically, we find that with stochastic scheduling reaches a sweet point in the trade-off between training efficiency and generation quality, as shown in Figure 3.
One natural question is why the denoiser could handle image patches of varying sizes. We note the UNet architecture is fully designed with convolutional layers, and the convolutional filters are capable of handling any resolution images by moving themselves around the inputs. Hence, our patch diffusion training could be regarded as a plug-and-play training technique for any UNet-based diffusion models. The flexibility of UNet on resolutions also makes our sampling easy and fast.
3 Conditional Coordinates for Patch Location
Motivated by COCO-GAN , to further incorporate and simplify the conditions of patch locations in the score function, we build up a pixel-level coordinate system. We normalize the pixel coordinate values to $(-1,-1)(1,1)$.
As shown in Figure 1, for any image patch , we extract its and pixel coordinates as two additional channels. For each training batch, we independently randomly crop each data sample with a sampled patch size for the batch and extract its corresponding coordinate channels. We concatenate the two coordinate channels with the original image channels to form the input of our denoiser . When computing the loss defined in Equation 4, we ignore the reconstructed coordinate channels and only minimize the loss on the image channels.
The pixel-level coordinate system together with random patch size could be seen as a kind of data augmentation method. For example, for an image with resolution , with patch size , we could have possible patches with different locations specified. Hence, we believe training diffusion models on patch-wise would help the data efficiency of diffusion models, in other words, with our method, diffusion models could perform better on small datasets. We validate this hypothesis through experiments in Section 4.4.
4 Sampling
By utilizing our coordinate system and the UNet, we are able to easily accomplish the reverse sampling defined in either Equation 1 or Equation 2. As we have shown in Figure 1, we compute and parameterize the coordinates for the full image, and concatenate them together with the image sample from last step as coordinate conditions at each reverse iteration. We abandon the reconstruction output of coordinate channels at each reverse iteration.
We provide a theoretical interpretation of Patch Diffusion Training in Appendix A.
Experiments
We conduct five sets of experiments to validate our patch diffusion training method. In the first subsection, we conduct an ablation study on what impacts the performance of our method. In the second subsection, we compare our method with its backbone model and other state-of-the-art diffusion model baselines on commonly-used benchmark datasets. Thirdly, we show that our method could also help improve the efficiency of finetuning large-scale pretrained models. Then, we show that patch diffusion models could achieve better generation quality on typical small datasets. Finally, we evaluate the out-painting capability of patch diffusion models.
Following previous works , we select CelebA (200k images) , FFHQ (70k images) , LSUN (200k images) , and ImageNet (1.2 million images) as our large datasets, and AFHQv2-Cat/Dog/Wild (5k images in each of them) as our small datasets.
Evaluation protocol.
We measure image generation quality using Fréchet Inception Distance (FID) . Following Karras et al. , we measure FID using 50k generated samples, with the full training set used as reference. We use the number of real images shown to the diffusion models to measure our training duration . Unless specified otherwise, all models are trained with a duration of 200 million images to ensure convergence (these trained with longer or shorter durations are specified in table captions). For the sampling time, we use the number of function evaluations (NFE) as a measure.
Implementations.
We implement our Patch Diffusion on top of the current state-of-the-art Unet-based diffusion model EDM-DDPM++ and EDM-ADM . EDM-DDPM++ is our default backbone model for training low-resolution (6464) datasets, while EDM-ADM coupling with Stable Diffusion latent en/decoders is our backbone model for training high-resolution (256256) datasets. We inherit the hyperparameter settings and the UNet architecture from Karras et al. . We implement random cropping independently on each data point in the same batch, and the corresponding pixel coordinates are concatenated with the image channels to form the input for the UNet denoiser. When computing the diffusion loss at any level, we ignore the reconstructed pixel coordinates. We adopt the EDM-Sampling strategy with 50 deterministic reverse steps in the inference stage, for both the baseline model and ours.
1 Ablation study
We provide ablation studies to investigate what may impact the performance of Patch Diffusion.
We first study the main effect of , the ratio of full-size images during training, regarding the quality of generated examples and the training cost. We conduct experiments on a gird, . Note here when , only patch images and their pixel coordinates are available during the training process, and when , patch training becomes the same as the standard training procedure of diffusion models. We train all models on 16 Nvidia V100 GPUs with a batch size of 512 for a duration of 200 million images.
We show the results in Figures 3 and 3. In the extreme case , the conditional score function is only trained on local patches, , and image patches, without the knowledge of how the full-size images look like. The FID is reasonably unsatisfactory while we still observe some coherently sampled images, such as the third and fourth faces shown in the 1st row of Figure 3. This observation validates our idea that using a mixture of large and small patch sizes could help the conditional score function to capture cross-region dependency. The learned small patch scores are guided by large patch score matching to form a coherent score mapping. Then, when is greater than , even if is as small as 0.1, the generation quality is dramatically improved in terms of FID. We reason this as that the involvement of full-size images provides the global score for patch-wise score matching, even though only a small ratio of the global score could guide the score function to learn towards it. As the increases, we could see the FID also becomes better, and we hypothesize this is because the conditional score function converges better towards the local minimum due to more global score guidance. However, the improvement of FID gained from increasing is not unlimited. We also observe that when is large enough, such as , the FID values converge to the minimum level, which indicates that sparsely using full-size images during training could be sufficient to guide the conditional score-matching to converge.
On the other hand, larger means more training cost and longer training time. Hence, we pick the sweet point shown on the line plot, , which provides a good trade-off between generation quality and training efficiency, for our following experiments.
Patch size scheduling.
Further, we investigate the impact of patch size scheduling, a stochastic or progressive way. Note usually the training of diffusion models applies learning rate decay. This may hurt the performance of progressive scheduling, since the training in the front stage is totally based on local patches while it has a large learning rate. We report FID comparison 1.66 (stochastic) v.s. 2.05 (progressive) on CelebA-6464 and 3.11 (stochastic) v.s. 3.85 (progressive) on FFHQ-6464. Therefore, unless otherwise specified, we employ stochastic patch size scheduling, as discussed in Section 3.2, for the following experiments.
2 Experiments on Large-scale Dataset
In this section, we aim to compare our Patch Diffusion Model (PDM) with other state-of-the-art diffusion model baselines in terms of both generation quality and training efficiency. As shown in Table 3, Patch Diffusion generally works well in terms of FID while having significantly reduced training time. Note, the FID results of our model and backbone are based on 50 deterministic reverse steps while the other baselines need a much larger number of reverse steps and are much slower in sampling.
We also combine our method with the Latent Diffusion framework to achieve dramatic reduction in training time cost for high-resolution image synthesis, such as LSUN-Bedroom/Church-256256 and ImageNet-256256 , and we denote it as Latent Patch Diffusion Model (LPDM). We borrow the pretrained image encoder and decoder from Stable Diffusion , encode the original images to a smaller latent space and then apply our patch diffusion training. Note the pretrained auto-encoder is not specifically trained for LSUN/ImageNet, which may limit the performance. We use the same latent diffusion model but without patch diffusion training under our codebase as a baseline, and we denote the implementation as LDM-ADM.
For LSUN-Bedroom/Church datasets, we train unconditional sampling, while for ImageNet dataset, we train conditional sampling. Following the classifier-free diffusion guidance (CFG) , during training, we randomly drop 10% of the given class labels, and during sampling, we use strength 1.3 for applying CFG, cfg=1.3.
We present the FID and training cost in Table 3 and Table 3 for LSUN and ImageNet datasets, repsectively. Patch Diffusion notably surpasses both the baseline and previous state-of-the-art Unet-based diffusion models in both generation quality and training efficiency. We show a number of uncurated image samples generated by Patch Diffusion in Figure 6 and Appendix B. Qualitatively, the images generated by Patch Diffusion exhibit photo-realism and are rich in variety.
3 Experiments on Finetuning
We evaluate Patch Diffusion in finetuning large-scale pretrained diffusion models. We plug it into ControlNet as one example. We use the data proposed by Brooks et al. as our base datasets and extract the HED maps by the HED boundary detector as the input controls. We then finetune the ControlNet on the HED map to image generation task from the Stable Diffusion ‘v1-5’ checkpoint with 20k steps. We show the qualitative generation from HED maps to images in Figure 6. We observe that patch diffusion can be effectively applied to fine-tuning without compromising performance, while also enhancing training efficiency by approximately two times.
4 Experiments on Limited-size Dataset
We further investigate whether coordinate-guided score matching could improve the data efficiency of diffusion models. Note by doing random cropping with different patch sizes, even one single image could be extended to thousands of patch samples, which helps overcome the overfitting issue.
Specifically, we conduct experiments on three popular small datasets, AFHQv2-Cat, -Dog, and -Wild, each with as few as around 5k images . We train our Patch Diffusion and the baseline approach EDM-DDPM++ from scratch for a duration of 75 million images. We compare the training cost and generation quality between different methods. As shown in Table 4, we observe that by using patch score matching, our model consistently outperforms the baseline model across all three datasets in terms of FID, while achieving faster training at the same time. We show a number of uncurated image samples generated by Patch Diffusion in Figure 6. This experiment demonstrates that patch diffusion training could help improve the data efficiency of diffusion models.
5 Experiments on Image Extrapolation
In this section, we evaluate the out-painting performance of Patch Diffusion on the LSUN-Bedroom dataset. We initially enlarge the coordinate system to a higher resolution, maintaining the range . The reference image is positioned at the center of the expanded coordinate system and remains static throughout the Patch Diffusion reversal process. In Figure 7, we extend the pixel manifold to dimensions of , even though our Patch Diffusion model is trained on image samples. The model effectively generates new content beyond the original boundary. Additionally, we present the extrapolation to a resolution in Appendix D.
Conclusion and Future Work
We present Patch Diffusion, a novel patch-level training framework that trains diffusion models via coordinate conditioned score matching. We also propose to diversify the patch sizes for score matching in a progressive or stochastic schedule during training, to capture the cross-region dependency at multiple scales. Sampling with our method is as easy as in the original diffusion model. Patch Diffusion could significantly reduce the training time costs, , faster training, while improving the data efficiency of diffusion models, , improving the performance of diffusion models trained on relatively small datasets. Going forward, the current coordinate system could be further improved by advanced positional embeddings, such as periodic one , to better incorporate the position information. We also leave the theoretical proof of the convergence of patch-wise score matching in general cases as our future work.
Acknowledgments
Z. Wang, H. Zheng, and M. Zhou acknowledge the support of NSF-IIS 2212418, NIH-R37 CA271186, and the NSF AI Institute for Foundations of Machine Learning (IFML).
References
Appendix A Theoretical Interpretations
In this section, we provide mathematical intuitions for our patch diffusion from two perspectives.
Markov Random Field (MRF) has been widely used to represent image distributions due to its compactness and expressiveness in modeling dependence. Usually, images are modeled as an undirected regular graph (pixel grids) in MRF, where each pixel is considered as a graph vertex, and each vertex will connect to its neighboring pixels on the image. Therefore, we can adopt the clique factorization form to represent the PDF defined over images:
Next, we point out that the score function of the MRF parameterization can be even neat:
where is eliminated as it is irrelevant to . As suggested by Equation 7, the score function can be eventually decomposed into independent pieces. That being said, we can separately learn each score function and first, and then average them up to approximate the entire score function during the inference. Our training procedure can be viewed as: each time we sample patches which contains subsets of and , and we conduct score matching on the corresponding and . Note that and is not necessarily spatial-invariant. We condition the network on the coordinates to model the location dependence for and .
Linear Regression.
We also provide an alternative interpretation for patch-wise score matching through the lens of least square. We consider a multivariate Gaussian distribution as the demonstration example. Suppose we parameterize our target distribution as where is the optimizee. Then its score function is written as: . The original score matching with full-size image is equivalent to the following least square problem:
On the other hand, the patch distribution can be considered as the marginal distribution on a subset of randam variables. The transformation between patch distribution and full-size image distribution is a marginalization integral, which is as simple as a linear operator (more precisely an orthogonal projection). In our Gaussian example, the patch distribution has a closed form: , where indices a set of pixels within an image patch identified by the location and size, and is a selection matrix associated with . Then patch-wise score matching can be written as:
From the linear regression perspective, the only difference between patch-based and full-size score matching is the measurement matrix. At first glance, patch diffusion trades the computation cost off the well-posedness. However, we argue that due to well-known redundancy and symmetry in image distributions, recovering the whole image distribution under limited observation can be factually feasible. This guarantees our patch diffusion can also converge to the true distribution. We consider a general argument beyond Gaussian examples as a promising future exploration.
Appendix B More Generated Images.
More generated images from Patch Diffusion are listed below.
Appendix C Potential Social Implications
Our work might lead to common negative social impacts of generation models for computer vision. One concern is the proliferation of fake or manipulated images, leading to a crisis of trust and credibility. As these models become more sophisticated, it turns increasingly difficult to discern between real and generated images, undermining the integrity of visual evidence. This can have significant implications in journalism, forensics, and other fields that heavily rely on accurate visual representation. Image generation models can also be misused for harmful purposes such as creating realistic but false identities, deepfake pornography, or even propaganda and disinformation campaigns. These applications can lead to privacy violations, cyberbullying, defamation, and manipulation of public opinion. Therefore, it is crucial to address the potential negative social impacts of image generation models and implement ethical guidelines and safeguards to mitigate harmful effects.