search
HomeTechnology peripheralsAIStable 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!

Stable Diffusion sampling speed doubled! Diffusion model sampling algorithm in only 10 to 25 steps

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:

Stable Diffusion sampling speed doubled! Diffusion model sampling algorithm in only 10 to 25 steps

## 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:

Stable Diffusion sampling speed doubled! Diffusion model sampling algorithm in only 10 to 25 steps

##Based on The sampling process of Diffusion SDE can be regarded as discretizing the following stochastic differential equation:

Stable Diffusion sampling speed doubled! Diffusion model sampling algorithm in only 10 to 25 steps

And it is proved in [4] that DDPM[5] is the above First-order discretization of SDE.

The sampling process based on Diffusion ODE can be regarded as discretizing the following ordinary differential equation:

Stable Diffusion sampling speed doubled! Diffusion model sampling algorithm in only 10 to 25 steps

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:

Stable Diffusion sampling speed doubled! Diffusion model sampling algorithm in only 10 to 25 steps

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: A solver specially designed for diffusion models

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:

Stable Diffusion sampling speed doubled! Diffusion model sampling algorithm in only 10 to 25 steps

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):

Stable Diffusion sampling speed doubled! Diffusion model sampling algorithm in only 10 to 25 steps

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:

Stable Diffusion sampling speed doubled! Diffusion model sampling algorithm in only 10 to 25 steps

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:

Stable Diffusion sampling speed doubled! Diffusion model sampling algorithm in only 10 to 25 steps

while the remaining total derivative part is It can be approximated by the numerical method of the traditional ODE solver (without any derivative operation):

Stable Diffusion sampling speed doubled! Diffusion model sampling algorithm in only 10 to 25 steps

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:

Stable Diffusion sampling speed doubled! Diffusion model sampling algorithm in only 10 to 25 steps

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:

Stable Diffusion sampling speed doubled! Diffusion model sampling algorithm in only 10 to 25 steps

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:

Stable Diffusion sampling speed doubled! Diffusion model sampling algorithm in only 10 to 25 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:

Stable Diffusion sampling speed doubled! Diffusion model sampling algorithm in only 10 to 25 steps

Using DPM-Solver

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:

Stable Diffusion sampling speed doubled! Diffusion model sampling algorithm in only 10 to 25 steps

The official code supports four diffusion models:

Stable Diffusion sampling speed doubled! Diffusion model sampling algorithm in only 10 to 25 steps

and also supports unconditional sampling, classifier guidance and classifier-free guidance:

Stable Diffusion sampling speed doubled! Diffusion model sampling algorithm in only 10 to 25 steps

The DPM-Solver based on the Diffusers library is also very simple, you only need to define the scheduler:

Stable Diffusion sampling speed doubled! Diffusion model sampling algorithm in only 10 to 25 steps

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:

Stable Diffusion sampling speed doubled! Diffusion model sampling algorithm in only 10 to 25 steps

I believe that based on DPM-Solver, the sampling speed of the diffusion model will no longer be a bottleneck.

About the author

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.


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!

Statement
This article is reproduced at:51CTO.COM. If there is any infringement, please contact admin@php.cn delete
从VAE到扩散模型:一文解读以文生图新范式从VAE到扩散模型:一文解读以文生图新范式Apr 08, 2023 pm 08:41 PM

1 前言在发布DALL·E的15个月后,OpenAI在今年春天带了续作DALL·E 2,以其更加惊艳的效果和丰富的可玩性迅速占领了各大AI社区的头条。近年来,随着生成对抗网络(GAN)、变分自编码器(VAE)、扩散模型(Diffusion models)的出现,深度学习已向世人展现其强大的图像生成能力;加上GPT-3、BERT等NLP模型的成功,人类正逐步打破文本和图像的信息界限。在DALL·E 2中,只需输入简单的文本(prompt),它就可以生成多张1024*1024的高清图像。这些图像甚至

找不到中文语音预训练模型?中文版 Wav2vec 2.0和HuBERT来了找不到中文语音预训练模型?中文版 Wav2vec 2.0和HuBERT来了Apr 08, 2023 pm 06:21 PM

Wav2vec 2.0 [1],HuBERT [2] 和 WavLM [3] 等语音预训练模型,通过在多达上万小时的无标注语音数据(如 Libri-light )上的自监督学习,显著提升了自动语音识别(Automatic Speech Recognition, ASR),语音合成(Text-to-speech, TTS)和语音转换(Voice Conversation,VC)等语音下游任务的性能。然而这些模型都没有公开的中文版本,不便于应用在中文语音研究场景。 WenetSpeech [4] 是

普林斯顿陈丹琦:如何让「大模型」变小普林斯顿陈丹琦:如何让「大模型」变小Apr 08, 2023 pm 04:01 PM

“Making large models smaller”这是很多语言模型研究人员的学术追求,针对大模型昂贵的环境和训练成本,陈丹琦在智源大会青源学术年会上做了题为“Making large models smaller”的特邀报告。报告中重点提及了基于记忆增强的TRIME算法和基于粗细粒度联合剪枝和逐层蒸馏的CofiPruning算法。前者能够在不改变模型结构的基础上兼顾语言模型困惑度和检索速度方面的优势;而后者可以在保证下游任务准确度的同时实现更快的处理速度,具有更小的模型结构。陈丹琦 普

解锁CNN和Transformer正确结合方法,字节跳动提出有效的下一代视觉Transformer解锁CNN和Transformer正确结合方法,字节跳动提出有效的下一代视觉TransformerApr 09, 2023 pm 02:01 PM

由于复杂的注意力机制和模型设计,大多数现有的视觉 Transformer(ViT)在现实的工业部署场景中不能像卷积神经网络(CNN)那样高效地执行。这就带来了一个问题:视觉神经网络能否像 CNN 一样快速推断并像 ViT 一样强大?近期一些工作试图设计 CNN-Transformer 混合架构来解决这个问题,但这些工作的整体性能远不能令人满意。基于此,来自字节跳动的研究者提出了一种能在现实工业场景中有效部署的下一代视觉 Transformer——Next-ViT。从延迟 / 准确性权衡的角度看,

Stable Diffusion XL 现已推出—有什么新功能,你知道吗?Stable Diffusion XL 现已推出—有什么新功能,你知道吗?Apr 07, 2023 pm 11:21 PM

3月27号,Stability AI的创始人兼首席执行官Emad Mostaque在一条推文中宣布,Stable Diffusion XL 现已可用于公开测试。以下是一些事项:“XL”不是这个新的AI模型的官方名称。一旦发布稳定性AI公司的官方公告,名称将会更改。与先前版本相比,图像质量有所提高与先前版本相比,图像生成速度大大加快。示例图像让我们看看新旧AI模型在结果上的差异。Prompt: Luxury sports car with aerodynamic curves, shot in a

五年后AI所需算力超100万倍!十二家机构联合发表88页长文:「智能计算」是解药五年后AI所需算力超100万倍!十二家机构联合发表88页长文:「智能计算」是解药Apr 09, 2023 pm 07:01 PM

人工智能就是一个「拼财力」的行业,如果没有高性能计算设备,别说开发基础模型,就连微调模型都做不到。但如果只靠拼硬件,单靠当前计算性能的发展速度,迟早有一天无法满足日益膨胀的需求,所以还需要配套的软件来协调统筹计算能力,这时候就需要用到「智能计算」技术。最近,来自之江实验室、中国工程院、国防科技大学、浙江大学等多达十二个国内外研究机构共同发表了一篇论文,首次对智能计算领域进行了全面的调研,涵盖了理论基础、智能与计算的技术融合、重要应用、挑战和未来前景。论文链接:​https://spj.scien

​什么是Transformer机器学习模型?​什么是Transformer机器学习模型?Apr 08, 2023 pm 06:31 PM

译者 | 李睿审校 | 孙淑娟​近年来, Transformer 机器学习模型已经成为深度学习和深度神经网络技术进步的主要亮点之一。它主要用于自然语言处理中的高级应用。谷歌正在使用它来增强其搜索引擎结果。OpenAI 使用 Transformer 创建了著名的 GPT-2和 GPT-3模型。自从2017年首次亮相以来,Transformer 架构不断发展并扩展到多种不同的变体,从语言任务扩展到其他领域。它们已被用于时间序列预测。它们是 DeepMind 的蛋白质结构预测模型 AlphaFold

AI模型告诉你,为啥巴西最可能在今年夺冠!曾精准预测前两届冠军AI模型告诉你,为啥巴西最可能在今年夺冠!曾精准预测前两届冠军Apr 09, 2023 pm 01:51 PM

说起2010年南非世界杯的最大网红,一定非「章鱼保罗」莫属!这只位于德国海洋生物中心的神奇章鱼,不仅成功预测了德国队全部七场比赛的结果,还顺利地选出了最终的总冠军西班牙队。不幸的是,保罗已经永远地离开了我们,但它的「遗产」却在人们预测足球比赛结果的尝试中持续存在。在艾伦图灵研究所(The Alan Turing Institute),随着2022年卡塔尔世界杯的持续进行,三位研究员Nick Barlow、Jack Roberts和Ryan Chan决定用一种AI算法预测今年的冠军归属。预测模型图

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools