


Stable Diffusion sampling speed doubled! Diffusion model sampling algorithm in only 10 to 25 steps
To talk about the most influential developments in the AI field this year, the explosive AI mapping is definitely one of them. Designers only need to enter a text description of the image, and AI will generate a high-resolution image of extremely high quality. Currently, the most widely used model is StabilityAI’s open source model Stable Diffusion. Once the model was open sourced, it caused widespread discussion in the community.
However, the biggest problem in using the diffusion model is its extremely slow sampling speed. Model sampling needs to start from pure noise pictures and continuously denoise step by step to finally obtain clear pictures. In this process, the model must calculate at least 50 to 100 steps serially to obtain a higher quality image. This results in the time required to generate an image 50 to 100 times that of other deep generation models, which greatly limits the model. deployment and implementation.
In order to speed up the sampling of diffusion models, many researchers start from the perspective of hardware optimization. For example, Google uses JAX language to compile and run the model on TPU, and the OneFlow team [1] uses self-developed The compiler achieves "image output in one second" with Stable Diffusion. These methods are based on the 50-step sampling algorithm PNDM [2], which has a sharp decline in sampling effect when the number of steps is reduced.
Just a few days ago, this record was refreshed! The official Demo[3] update of Stable Diffusion shows that the time to sample 8 pictures has been directly shortened from the original 8 seconds to 4 seconds! It's twice as fast!
The OneFlow team, which is based on self-developed deep learning compiler technology, has successfully transformed the previous "OneFlow" without reducing the sampling effect. "Pictures will appear in seconds" has been shortened to "Pictures will appear in half a second"! Get a high-definition image in less than 0.5 seconds on the GPU! Related work has been published in [1].
In fact, the core driving force of these works comes from the DPM-Solver proposed by the TSAIL team led by Professor Zhu Jun of Tsinghua University, an efficient solver specially designed for diffusion models Filter: This algorithm does not require any additional training, is suitable for both discrete-time and continuous-time diffusion models, can almost converge within 20 to 25 steps, and can obtain very high-quality sampling in only 10 to 15 steps. On Stable Diffusion, a 25-step DPM-Solver can achieve better sampling quality than a 50-step PNDM, so the sampling speed is directly doubled!
Project link:
- DPM-Solver: A Fast ODE Solver for Diffusion Probabilistic Model Sampling in Around 10 Steps: https: //arxiv.org/abs/2206.00927 (NeurIPS 2022 Oral)
- DPM-Solver : Fast Solver for Guided Sampling of Diffusion Probabilistic Models: https://arxiv.org/abs/ 2211.01095
- Project open source code: https://github.com/LuChengTHU/dpm-solver
- Project online Demo: https:// huggingface.co/spaces/LuChengTHU/dpmsolver_sdm
The definition and sampling method of the diffusion model
The diffusion model defines a forward process that continuously adds noise. The picture is gradually turned into Gaussian noise, and then a reverse process is defined to gradually denoise the Gaussian noise into a clear picture to obtain samples:
## During the sampling process, diffusion models can be divided into two categories according to whether additional noise is added: one is the diffusion stochastic differential equation model (Diffusion SDE), and the other is the diffusion ordinary differential equation (Diffusion ODE). The training objective functions of both models are the same. A "noise prediction network" is trained by minimizing the mean square error with noise:
The sampling process based on Diffusion ODE can be regarded as discretizing the following ordinary differential equation:
And it is proved in [6] that DDIM[7] is a first-order discretization of the above ODE. However, these first-order discretization methods converge extremely slowly, and the sampling of the diffusion model usually requires 100 to 1000 serial calculations to obtain a high-quality picture. Usually, in order to speed up the sampling of diffusion models, researchers often use high-order solvers for Diffusion ODE to speed up the process, such as the classic Runge-Kutta method (RK45). This is because ODE does not bring additional randomness. , the discretization step size can be relatively larger. After given the solution at time s, the Runge-Kutta method is based on the discretization of the following integral: Such discretization treats the Diffusion ODE as a whole A black box loses the known information of the ODE and is difficult to converge in less than 50 steps. DPM-Solver is based on the semi-linear structure of Diffusion ODE, through accurate and analytical Calculating the linear terms in the ODE, we can get: The remaining integral term is a complex integral with respect to time. However, the proposer of DPM-Solver discovered that this integral can be obtained in a very simple form by substituting log-SNR (log signal-to-noise ratio): The remaining integral is an exponentially weighted integral about the noise prediction model. By performing Taylor expansion on the noise prediction model, we can get an estimate of the integral: There are two items in this estimate: one is the full The derivative part (vector) and the other term is the coefficient part (scalar). Another core contribution of DPM-Solver is that the coefficient can be calculated analytically by integrating by parts: while the remaining total derivative part is It can be approximated by the numerical method of the traditional ODE solver (without any derivative operation): Based on the above 4 points, DPM-Solver does To calculate all known terms as accurately as possible, only the neural network part is approximated, thus minimizing the discretization error: In addition, based on this derivation, we can get that DDIM is essentially the first-order form of DPM-Solver, which can also explain why DDIM can still achieve good acceleration effects when the number of steps is small: In the experiment, DPM-Solver achieved an acceleration effect far exceeding that of other sampling algorithms, and it almost converged in only 15-20 steps: And the quantitative results in the paper show that the additional calculation amount introduced by DPM-Solver is completely negligible, that is, the acceleration effect on the number of steps is directly proportional to the acceleration effect on time - therefore, based on 25 steps The sampling speed of DPM-Solver and Stable-Diffusion models is directly doubled! For example, the figure below shows the effect of different sampling algorithms on Stable-Diffusion as the number of steps changes. It can be seen that DPM-Solver can obtain very high-quality sampling in 10 to 15 steps: The use of DPM-Solver is very simple. It can be based on the official code provided by the author or the mainstream Diffusers library. For example, based on the official code provided by the author (https://github.com/LuChengTHU/dpm-solver), only 3 lines are needed: The official code supports four diffusion models: and also supports unconditional sampling, classifier guidance and classifier-free guidance: The DPM-Solver based on the Diffusers library is also very simple, you only need to define the scheduler: In addition, the author team also provides an online Demo: https://huggingface.co/spaces/LuChengTHU/dpmsolver_sdm The picture below is 15 steps For example, you can see that the image quality is very high: I believe that based on DPM-Solver, the sampling speed of the diffusion model will no longer be a bottleneck. The first author of the DPM-Solver paper is Dr. Lu Cheng from the TSAIL team of Tsinghua University. He also wrote in the discussion about the diffusion model on Zhihu An introductory introduction to the principle of diffusion model, currently has 2000 likes: https://www.zhihu.com/question/536012286/answer/2533146567 Tsinghua University TSAIL team long-term Committed to the theory and algorithm research of Bayesian machine learning, it is one of the earliest teams in the world to study deep probabilistic generation models. It has achieved systematic and in-depth research results in Bayesian models, efficient algorithms and probabilistic programming libraries. Bao Fan, another doctoral student in the team, proposed Analytic-DPM [8][9], which provided a simple and surprising analytical form for the optimal mean and variance of the diffusion model, and won the ICLR 2022 Outstanding Paper Award. In terms of probabilistic programming, Machine Heart reported on the "ZhuSuan" deep probabilistic programming library released by the team as early as 2017 (https://zhusuan.readthedocs.io/en/latest/) [10], which is the earliest in the world. One of the programming libraries for deep probabilistic models. In addition, it is worth mentioning that the two core authors of the diffusion probability model, Song Yang and Song Jiaming, both received scientific research training under the guidance of Professor Zhu Jun as undergraduates, and later went to Stanford University to study for doctoral degrees. The co-authors of the paper, Zhou Yuhao, Chen Jianfei, and Li Chongxuan, are also outstanding doctoral students trained by the TSAIL group. Zhou Yuhao is a student, and Chen Jianfei and Li Chongxuan teach in the Computer Department of Tsinghua University and the Hillhouse School of Artificial Intelligence of Renmin University respectively. DPM-Solver: A solver specially designed for diffusion models
Using DPM-Solver
About the author
The above is the detailed content of Stable Diffusion sampling speed doubled! Diffusion model sampling algorithm in only 10 to 25 steps. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

The 2024CSRankings National Computer Science Major Rankings have just been released! This year, in the ranking of the best CS universities in the United States, Carnegie Mellon University (CMU) ranks among the best in the country and in the field of CS, while the University of Illinois at Urbana-Champaign (UIUC) has been ranked second for six consecutive years. Georgia Tech ranked third. Then, Stanford University, University of California at San Diego, University of Michigan, and University of Washington tied for fourth place in the world. It is worth noting that MIT's ranking fell and fell out of the top five. CSRankings is a global university ranking project in the field of computer science initiated by Professor Emery Berger of the School of Computer and Information Sciences at the University of Massachusetts Amherst. The ranking is based on objective

Imagine an artificial intelligence model that not only has the ability to surpass traditional computing, but also achieves more efficient performance at a lower cost. This is not science fiction, DeepSeek-V2[1], the world’s most powerful open source MoE model is here. DeepSeek-V2 is a powerful mixture of experts (MoE) language model with the characteristics of economical training and efficient inference. It consists of 236B parameters, 21B of which are used to activate each marker. Compared with DeepSeek67B, DeepSeek-V2 has stronger performance, while saving 42.5% of training costs, reducing KV cache by 93.3%, and increasing the maximum generation throughput to 5.76 times. DeepSeek is a company exploring general artificial intelligence

Earlier this month, researchers from MIT and other institutions proposed a very promising alternative to MLP - KAN. KAN outperforms MLP in terms of accuracy and interpretability. And it can outperform MLP running with a larger number of parameters with a very small number of parameters. For example, the authors stated that they used KAN to reproduce DeepMind's results with a smaller network and a higher degree of automation. Specifically, DeepMind's MLP has about 300,000 parameters, while KAN only has about 200 parameters. KAN has a strong mathematical foundation like MLP. MLP is based on the universal approximation theorem, while KAN is based on the Kolmogorov-Arnold representation theorem. As shown in the figure below, KAN has

Boston Dynamics Atlas officially enters the era of electric robots! Yesterday, the hydraulic Atlas just "tearfully" withdrew from the stage of history. Today, Boston Dynamics announced that the electric Atlas is on the job. It seems that in the field of commercial humanoid robots, Boston Dynamics is determined to compete with Tesla. After the new video was released, it had already been viewed by more than one million people in just ten hours. The old people leave and new roles appear. This is a historical necessity. There is no doubt that this year is the explosive year of humanoid robots. Netizens commented: The advancement of robots has made this year's opening ceremony look like a human, and the degree of freedom is far greater than that of humans. But is this really not a horror movie? At the beginning of the video, Atlas is lying calmly on the ground, seemingly on his back. What follows is jaw-dropping

The performance of JAX, promoted by Google, has surpassed that of Pytorch and TensorFlow in recent benchmark tests, ranking first in 7 indicators. And the test was not done on the TPU with the best JAX performance. Although among developers, Pytorch is still more popular than Tensorflow. But in the future, perhaps more large models will be trained and run based on the JAX platform. Models Recently, the Keras team benchmarked three backends (TensorFlow, JAX, PyTorch) with the native PyTorch implementation and Keras2 with TensorFlow. First, they select a set of mainstream

AI is indeed changing mathematics. Recently, Tao Zhexuan, who has been paying close attention to this issue, forwarded the latest issue of "Bulletin of the American Mathematical Society" (Bulletin of the American Mathematical Society). Focusing on the topic "Will machines change mathematics?", many mathematicians expressed their opinions. The whole process was full of sparks, hardcore and exciting. The author has a strong lineup, including Fields Medal winner Akshay Venkatesh, Chinese mathematician Zheng Lejun, NYU computer scientist Ernest Davis and many other well-known scholars in the industry. The world of AI has changed dramatically. You know, many of these articles were submitted a year ago.

Target detection is a relatively mature problem in autonomous driving systems, among which pedestrian detection is one of the earliest algorithms to be deployed. Very comprehensive research has been carried out in most papers. However, distance perception using fisheye cameras for surround view is relatively less studied. Due to large radial distortion, standard bounding box representation is difficult to implement in fisheye cameras. To alleviate the above description, we explore extended bounding box, ellipse, and general polygon designs into polar/angular representations and define an instance segmentation mIOU metric to analyze these representations. The proposed model fisheyeDetNet with polygonal shape outperforms other models and simultaneously achieves 49.5% mAP on the Valeo fisheye camera dataset for autonomous driving

The latest video of Tesla's robot Optimus is released, and it can already work in the factory. At normal speed, it sorts batteries (Tesla's 4680 batteries) like this: The official also released what it looks like at 20x speed - on a small "workstation", picking and picking and picking: This time it is released One of the highlights of the video is that Optimus completes this work in the factory, completely autonomously, without human intervention throughout the process. And from the perspective of Optimus, it can also pick up and place the crooked battery, focusing on automatic error correction: Regarding Optimus's hand, NVIDIA scientist Jim Fan gave a high evaluation: Optimus's hand is the world's five-fingered robot. One of the most dexterous. Its hands are not only tactile
