不用关网站备案,温州市网站建设公司,php网站开发实例教程下载,wordpress 上一篇文章相关阅读#xff1a;扩散模型#xff08;一#xff09;
Parameterization of L t L_t Lt for Training Loss
回想一下#xff0c;我们需要训练一个神经网络来近似反向扩散过程中的条件概率分布#xff0c;即, p θ ( x t − 1 ∣ x t ) N ( x t − 1 ; μ θ ( x t…相关阅读扩散模型一
Parameterization of L t L_t Lt for Training Loss
回想一下我们需要训练一个神经网络来近似反向扩散过程中的条件概率分布即, p θ ( x t − 1 ∣ x t ) N ( x t − 1 ; μ θ ( x t , t ) , Σ θ ( x t , t ) ) p_\theta(\mathbf{x}_{t-1} \vert \mathbf{x}_t) \mathcal{N}(\mathbf{x}_{t-1}; \boldsymbol{\mu}_\theta(\mathbf{x}_t, t), \boldsymbol{\Sigma}_\theta(\mathbf{x}_t, t)) pθ(xt−1∣xt)N(xt−1;μθ(xt,t),Σθ(xt,t)). 我们希望训练 μ θ \boldsymbol{\mu}_\theta μθ 以预测 μ ~ t 1 α t ( x t − 1 − α t 1 − α ˉ t ϵ t ) \tilde{\boldsymbol{\mu}}_t \frac{1}{\sqrt{\alpha_t}} \Big( \mathbf{x}_t - \frac{1 - \alpha_t}{\sqrt{1 - \bar{\alpha}_t}} \boldsymbol{\epsilon}_t \Big) μ~tαt 1(xt−1−αˉt 1−αtϵt). 由于训练时 x t \mathbf{x}_t xt 可以获取, 我们可以对高斯噪声项进行重参数化 使其在时间步 t t t 从输入 x t \mathbf{x}_t xt 预测出 ϵ t \boldsymbol{\epsilon}_t ϵt。 μ θ ( x t , t ) 1 α t ( x t − 1 − α t 1 − α ˉ t ϵ θ ( x t , t ) ) Thus x t − 1 N ( x t − 1 ; 1 α t ( x t − 1 − α t 1 − α ˉ t ϵ θ ( x t , t ) ) , Σ θ ( x t , t ) ) \begin{aligned} \boldsymbol{\mu}_\theta(\mathbf{x}_t, t) \color{blue}{\frac{1}{\sqrt{\alpha_t}} \Big( \mathbf{x}_t - \frac{1 - \alpha_t}{\sqrt{1 - \bar{\alpha}_t}} \boldsymbol{\epsilon}_\theta(\mathbf{x}_t, t) \Big)} \\ \text{Thus } \mathbf{x}_{t-1} \mathcal{N}(\mathbf{x}_{t-1}; \frac{1}{\sqrt{\alpha_t}} \Big( \mathbf{x}_t - \frac{1 - \alpha_t}{\sqrt{1 - \bar{\alpha}_t}} \boldsymbol{\epsilon}_\theta(\mathbf{x}_t, t) \Big), \boldsymbol{\Sigma}_\theta(\mathbf{x}_t, t)) \end{aligned} μθ(xt,t)Thus xt−1αt 1(xt−1−αˉt 1−αtϵθ(xt,t))N(xt−1;αt 1(xt−1−αˉt 1−αtϵθ(xt,t)),Σθ(xt,t))
损失项 L t L_t Lt 通过参数化来最小化与 μ ~ \tilde{\boldsymbol{\mu}} μ~ 的差异 L t E x 0 , ϵ [ 1 2 ∥ Σ θ ( x t , t ) ∥ 2 2 ∥ μ ~ t ( x t , x 0 ) − μ θ ( x t , t ) ∥ 2 ] E x 0 , ϵ [ 1 2 ∥ Σ θ ∥ 2 2 ∥ 1 α t ( x t − 1 − α t 1 − α ˉ t ϵ t ) − 1 α t ( x t − 1 − α t 1 − α ˉ t ϵ θ ( x t , t ) ) ∥ 2 ] E x 0 , ϵ [ ( 1 − α t ) 2 2 α t ( 1 − α ˉ t ) ∥ Σ θ ∥ 2 2 ∥ ϵ t − ϵ θ ( x t , t ) ∥ 2 ] E x 0 , ϵ [ ( 1 − α t ) 2 2 α t ( 1 − α ˉ t ) ∥ Σ θ ∥ 2 2 ∥ ϵ t − ϵ θ ( α ˉ t x 0 1 − α ˉ t ϵ t , t ) ∥ 2 ] \begin{aligned} L_t \mathbb{E}_{\mathbf{x}_0, \boldsymbol{\epsilon}} \Big[\frac{1}{2 \| \boldsymbol{\Sigma}_\theta(\mathbf{x}_t, t) \|^2_2} \| \color{blue}{\tilde{\boldsymbol{\mu}}_t(\mathbf{x}_t, \mathbf{x}_0)} - \color{green}{\boldsymbol{\mu}_\theta(\mathbf{x}_t, t)} \|^2 \Big] \\ \mathbb{E}_{\mathbf{x}_0, \boldsymbol{\epsilon}} \Big[\frac{1}{2 \|\boldsymbol{\Sigma}_\theta \|^2_2} \| \color{blue}{\frac{1}{\sqrt{\alpha_t}} \Big( \mathbf{x}_t - \frac{1 - \alpha_t}{\sqrt{1 - \bar{\alpha}_t}} \boldsymbol{\epsilon}_t \Big)} - \color{green}{\frac{1}{\sqrt{\alpha_t}} \Big( \mathbf{x}_t - \frac{1 - \alpha_t}{\sqrt{1 - \bar{\alpha}_t}} \boldsymbol{\boldsymbol{\epsilon}}_\theta(\mathbf{x}_t, t) \Big)} \|^2 \Big] \\ \mathbb{E}_{\mathbf{x}_0, \boldsymbol{\epsilon}} \Big[\frac{ (1 - \alpha_t)^2 }{2 \alpha_t (1 - \bar{\alpha}_t) \| \boldsymbol{\Sigma}_\theta \|^2_2} \|\boldsymbol{\epsilon}_t - \boldsymbol{\epsilon}_\theta(\mathbf{x}_t, t)\|^2 \Big] \\ \mathbb{E}_{\mathbf{x}_0, \boldsymbol{\epsilon}} \Big[\frac{ (1 - \alpha_t)^2 }{2 \alpha_t (1 - \bar{\alpha}_t) \| \boldsymbol{\Sigma}_\theta \|^2_2} \|\boldsymbol{\epsilon}_t - \boldsymbol{\epsilon}_\theta(\sqrt{\bar{\alpha}_t}\mathbf{x}_0 \sqrt{1 - \bar{\alpha}_t}\boldsymbol{\epsilon}_t, t)\|^2 \Big] \end{aligned} LtEx0,ϵ[2∥Σθ(xt,t)∥221∥μ~t(xt,x0)−μθ(xt,t)∥2]Ex0,ϵ[2∥Σθ∥221∥αt 1(xt−1−αˉt 1−αtϵt)−αt 1(xt−1−αˉt 1−αtϵθ(xt,t))∥2]Ex0,ϵ[2αt(1−αˉt)∥Σθ∥22(1−αt)2∥ϵt−ϵθ(xt,t)∥2]Ex0,ϵ[2αt(1−αˉt)∥Σθ∥22(1−αt)2∥ϵt−ϵθ(αˉt x01−αˉt ϵt,t)∥2]
Simplification
根据实证研究霍等人2020 年发现使用一个简化的目标函数来训练扩散模型效果更好该目标函数忽略了加权项。 L t simple E t ∼ [ 1 , T ] , x 0 , ϵ t [ ∥ ϵ t − ϵ θ ( x t , t ) ∥ 2 ] E t ∼ [ 1 , T ] , x 0 , ϵ t [ ∥ ϵ t − ϵ θ ( α ˉ t x 0 1 − α ˉ t ϵ t , t ) ∥ 2 ] \begin{aligned} L_t^\text{simple} \mathbb{E}_{t \sim [1, T], \mathbf{x}_0, \boldsymbol{\epsilon}_t} \Big[\|\boldsymbol{\epsilon}_t - \boldsymbol{\epsilon}_\theta(\mathbf{x}_t, t)\|^2 \Big] \\ \mathbb{E}_{t \sim [1, T], \mathbf{x}_0, \boldsymbol{\epsilon}_t} \Big[\|\boldsymbol{\epsilon}_t - \boldsymbol{\epsilon}_\theta(\sqrt{\bar{\alpha}_t}\mathbf{x}_0 \sqrt{1 - \bar{\alpha}_t}\boldsymbol{\epsilon}_t, t)\|^2 \Big] \end{aligned} LtsimpleEt∼[1,T],x0,ϵt[∥ϵt−ϵθ(xt,t)∥2]Et∼[1,T],x0,ϵt[∥ϵt−ϵθ(αˉt x01−αˉt ϵt,t)∥2]
最终简化的目标为 L simple L t simple C L_\text{simple} L_t^\text{simple} C LsimpleLtsimpleC
其中 C C C 是常数不依赖于 θ \theta θ。 图 4
Connection with noise-conditioned score networks (NCSN)
宋和埃尔蒙2019提出了一种基于分数的生成建模方法通过利用分数匹配估计的数据分布梯度经由朗之万动力学见 “与随机梯度朗之万动力学的联系”生成样本。每个样本 x \mathbf{x} x 的密度概率的分数定义为其梯度 ∇ x log q ( x ) \nabla_{\mathbf{x}} \log q(\mathbf{x}) ∇xlogq(x) 。训练一个分数网络 s θ : R D → R D \mathbf{s}_\theta: \mathbb{R}^D \to \mathbb{R}^D sθ:RD→RD 来进行估计即 s θ ( x ) ≈ ∇ x log q ( x ) \mathbf{s}_\theta(\mathbf{x}) \approx \nabla_{\mathbf{x}} \log q(\mathbf{x}) sθ(x)≈∇xlogq(x) 。 为了使其在深度学习环境中适用于高维数据他们提出使用 “去噪分数匹配” 或 “切片分数匹配”。去噪分数匹配向数据 q ( x ~ ∣ x ) q(\tilde{\mathbf{x}} \vert \mathbf{x}) q(x~∣x) 添加预先指定的少量噪声并通过分数匹配估计 q ( x ~ ) q(\tilde{\mathbf{x}}) q(x~)。回想一下朗之万动力学可以在迭代过程中仅使用分数 ∇ x log q ( x ) \nabla_{\mathbf{x}} \log q(\mathbf{x}) ∇xlogq(x) 从概率密度分布中采样数据点。 然而根据流形假设尽管观测到的数据可能看起来维度极高但大多数数据预计集中在一个低维流形中。这对分数估计产生了负面影响因为数据点无法覆盖整个空间。在数据密度低的区域分数估计的可靠性较差。在添加少量高斯噪声以使扰动后的数据分布覆盖整个 R D \mathbb{R}^D RD 空间后分数估计器网络的训练变得更加稳定。宋和埃尔蒙2019通过用不同程度的噪声扰动数据并训练一个噪声条件分数网络来联合估计不同噪声水平下所有扰动数据的分数从而对该方法进行了改进。 噪声水平增加的过程类似于正向扩散过程。如果我们使用扩散过程的标注分数近似为 s θ ( x t , t ) ≈ ∇ x t log q ( x t ) \mathbf{s}_\theta(\mathbf{x}_t, t) \approx \nabla_{\mathbf{x}_t} \log q(\mathbf{x}_t) sθ(xt,t)≈∇xtlogq(xt) 。对于高斯分布 x ∼ N ( μ , σ 2 I ) \mathbf{x} \sim \mathcal{N}(\mathbf{\mu}, \sigma^2 \mathbf{I}) x∼N(μ,σ2I) 我们可以将其密度函数对数的导数写为 ∇ x log p ( x ) ∇ x ( − 1 2 σ 2 ( x − μ ) 2 ) − x − μ σ 2 − ϵ σ \nabla_{\mathbf{x}}\log p(\mathbf{x}) \nabla_{\mathbf{x}} \Big(-\frac{1}{2\sigma^2}(\mathbf{x} - \boldsymbol{\mu})^2 \Big) - \frac{\mathbf{x} - \boldsymbol{\mu}}{\sigma^2} - \frac{\boldsymbol{\epsilon}}{\sigma} ∇xlogp(x)∇x(−2σ21(x−μ)2)−σ2x−μ−σϵ 其中 ϵ ∼ N ( 0 , I ) \boldsymbol{\epsilon} \sim \mathcal{N}(\boldsymbol{0}, \mathbf{I}) ϵ∼N(0,I) 。考虑到前文介绍的 q ( x t ∣ x 0 ) ∼ N ( α ˉ t x 0 , ( 1 − α ˉ t ) I ) q(\mathbf{x}_t \vert \mathbf{x}_0) \sim \mathcal{N}(\sqrt{\bar{\alpha}_t} \mathbf{x}_0, (1 - \bar{\alpha}_t)\mathbf{I}) q(xt∣x0)∼N(αˉt x0,(1−αˉt)I)因此 s θ ( x t , t ) ≈ ∇ x t log q ( x t ) E q ( x 0 ) [ ∇ x t log q ( x t ∣ x 0 ) ] E q ( x 0 ) [ − ϵ θ ( x t , t ) 1 − α ˉ t ] − ϵ θ ( x t , t ) 1 − α ˉ t \mathbf{s}_\theta(\mathbf{x}_t, t) \approx \nabla_{\mathbf{x}_t} \log q(\mathbf{x}_t) \mathbb{E}_{q(\mathbf{x}_0)} [\nabla_{\mathbf{x}_t} \log q(\mathbf{x}_t \vert \mathbf{x}_0)] \mathbb{E}_{q(\mathbf{x}_0)} \Big[ - \frac{\boldsymbol{\epsilon}_\theta(\mathbf{x}_t, t)}{\sqrt{1 - \bar{\alpha}_t}} \Big] - \frac{\boldsymbol{\epsilon}_\theta(\mathbf{x}_t, t)}{\sqrt{1 - \bar{\alpha}_t}} sθ(xt,t)≈∇xtlogq(xt)Eq(x0)[∇xtlogq(xt∣x0)]Eq(x0)[−1−αˉt ϵθ(xt,t)]−1−αˉt ϵθ(xt,t)
Parameterization of β t \beta_t βt
在霍等人2020的研究中正向方差被设定为一系列线性递增的常数从 β 1 1 0 − 4 \beta_110^{-4} β110−4 到 β T 0.02 \beta_T0.02 βT0.02。与归一化后在 [ − 1 , 1 ] [-1, 1] [−1,1] 之间的图像像素值相比这些方差相对较小。他们实验中的扩散模型生成了高质量的样本但与其他生成模型相比仍无法实现具有竞争力的模型对数似然。 尼科尔和达里瓦尔2021提出了几种改进技术以帮助扩散模型获得更低的负对数似然NLL。其中一项改进是使用基于余弦的方差调度。调度函数的选择可以是任意的只要它在训练过程中间提供近乎线性的下降并且在 t 0 t0 t0 和 t T tT tT 附近变化细微。 β t clip ( 1 − α ˉ t α ˉ t − 1 , 0.999 ) α ˉ t f ( t ) f ( 0 ) where f ( t ) cos ( t / T s 1 s ⋅ π 2 ) 2 \beta_t \text{clip}(1-\frac{\bar{\alpha}_t}{\bar{\alpha}_{t-1}}, 0.999) \quad\bar{\alpha}_t \frac{f(t)}{f(0)}\quad\text{where }f(t)\cos\Big(\frac{t/Ts}{1s}\cdot\frac{\pi}{2}\Big)^2 βtclip(1−αˉt−1αˉt,0.999)αˉtf(0)f(t)where f(t)cos(1st/Ts⋅2π)2
其中小的偏移量 s s s 是为了防止在接近 t 0 t0 t0 时 β t \beta_t βt 过小。 图 5
Parameterization of reverse process variance Σ θ \boldsymbol{\Sigma}_\theta Σθ
Ho et al. (2020) 选择将 β t \beta_t βt 固定为常数而非使其可学习并设定 Σ θ ( x t , t ) σ t 2 I \boldsymbol{\Sigma}_\theta(\mathbf{x}_t, t) \sigma^2_t \mathbf{I} Σθ(xt,t)σt2I , 其中 σ t \sigma_t σt 并非通过学习得到而是设为 β t \beta_t βt 或者 β ~ t 1 − α ˉ t − 1 1 − α ˉ t ⋅ β t \tilde{\beta}_t \frac{1 - \bar{\alpha}_{t-1}}{1 - \bar{\alpha}_t} \cdot \beta_t β~t1−αˉt1−αˉt−1⋅βt. 因为他们发现学习对角方差 Σ θ \boldsymbol{\Sigma}_\theta Σθ 会导致训练不稳定且样本质量较差。 Nichol Dhariwal (2021) 提出通过模型预测一个混合向量 v \mathbf{v} v将 Σ θ ( x t , t ) \boldsymbol{\Sigma}_\theta(\mathbf{x}_t, t) Σθ(xt,t) 作为 β t \beta_t βt 与 β ~ t \tilde{\beta}_t β~t 之间的插值来进行学习。 Σ θ ( x t , t ) exp ( v log β t ( 1 − v ) log β ~ t ) \boldsymbol{\Sigma}_\theta(\mathbf{x}_t, t) \exp(\mathbf{v} \log \beta_t (1-\mathbf{v}) \log \tilde{\beta}_t) Σθ(xt,t)exp(vlogβt(1−v)logβ~t)
然而简单目标函数 L simple L_\text{simple} Lsimple 并不依赖于 Σ θ \boldsymbol{\Sigma}_\theta Σθ。为了引入这种依赖关系他们构建了一个混合目标函数 L hybrid L simple λ L VLB L_\text{hybrid} L_\text{simple} \lambda L_\text{VLB} LhybridLsimpleλLVLB其中 λ 0.001 \lambda0.001 λ0.001 取值较小并且在 L VLB L_\text{VLB} LVLB 项中对 μ θ \boldsymbol{\mu}_\theta μθ 停止梯度计算这样 L VLB L_\text{VLB} LVLB 就仅用于指导 Σ θ \boldsymbol{\Sigma}_\theta Σθ 的学习。从经验上看他们发现 L VLB L_\text{VLB} LVLB 极难优化这很可能是由于梯度噪声所致因此他们提议使用一种带有重要性采样的 L VLB L_\text{VLB} LVLB 时间平均平滑版本。
Conditioned Generation
在使用诸如 ImageNet 数据集这类带有条件信息的图像来训练生成模型时基于类别标签或一段描述性文本等条件生成样本是很常见的做法。
Classifier Guided Diffusion
为了将类别信息明确纳入扩散过程达里瓦尔和尼科尔2021在含噪图像 x t \mathbf{x}_t xt 上训练了一个分类器 f ϕ ( y ∣ x t , t ) f_\phi(y \vert \mathbf{x}_t, t) fϕ(y∣xt,t)并通过改变噪声预测使用梯度 ∇ x log f ϕ ( y ∣ x t ) \nabla_\mathbf{x} \log f_\phi(y \vert \mathbf{x}_t) ∇xlogfϕ(y∣xt) 将扩散采样过程导向到条件信息 y y y。
考虑之前的 ∇ x t log q ( x t ) − 1 1 − α ˉ t ϵ θ ( x t , t ) \nabla_{\mathbf{x}_t} \log q(\mathbf{x}_t) - \frac{1}{\sqrt{1 - \bar{\alpha}_t}} \boldsymbol{\epsilon}_\theta(\mathbf{x}_t, t) ∇xtlogq(xt)−1−αˉt 1ϵθ(xt,t)我们可以将联合分布 q ( x t , y ) q(\mathbf{x}_t, y) q(xt,y) 的分数函数写成如下形式 ∇ x t log q ( x t , y ) ∇ x t log q ( x t ) ∇ x t log q ( y ∣ x t ) ≈ − 1 1 − α ˉ t ϵ θ ( x t , t ) ∇ x t log f ϕ ( y ∣ x t ) − 1 1 − α ˉ t ( ϵ θ ( x t , t ) − 1 − α ˉ t ∇ x t log f ϕ ( y ∣ x t ) ) \begin{aligned} \nabla_{\mathbf{x}_t} \log q(\mathbf{x}_t, y) \nabla_{\mathbf{x}_t} \log q(\mathbf{x}_t) \nabla_{\mathbf{x}_t} \log q(y \vert \mathbf{x}_t) \\ \approx - \frac{1}{\sqrt{1 - \bar{\alpha}_t}} \boldsymbol{\epsilon}_\theta(\mathbf{x}_t, t) \nabla_{\mathbf{x}_t} \log f_\phi(y \vert \mathbf{x}_t) \\ - \frac{1}{\sqrt{1 - \bar{\alpha}_t}} (\boldsymbol{\epsilon}_\theta(\mathbf{x}_t, t) - \sqrt{1 - \bar{\alpha}_t} \nabla_{\mathbf{x}_t} \log f_\phi(y \vert \mathbf{x}_t)) \end{aligned} ∇xtlogq(xt,y)∇xtlogq(xt)∇xtlogq(y∣xt)≈−1−αˉt 1ϵθ(xt,t)∇xtlogfϕ(y∣xt)−1−αˉt 1(ϵθ(xt,t)−1−αˉt ∇xtlogfϕ(y∣xt))
因此一种新的由分类器引导的预测器 ϵ ˉ θ \bar{\boldsymbol{\epsilon}}_\theta ϵˉθ 将采用如下形式。 ϵ ˉ θ ( x t , t ) ϵ θ ( x t , t ) − 1 − α ˉ t ∇ x t log f ϕ ( y ∣ x t ) \bar{\boldsymbol{\epsilon}}_\theta(\mathbf{x}_t, t) \boldsymbol{\epsilon}_\theta(x_t, t) - \sqrt{1 - \bar{\alpha}_t} \nabla_{\mathbf{x}_t} \log f_\phi(y \vert \mathbf{x}_t) ϵˉθ(xt,t)ϵθ(xt,t)−1−αˉt ∇xtlogfϕ(y∣xt)
为了控制分类器引导的强度我们可以在增量部分添加一个权重 w w w ϵ ˉ θ ( x t , t ) ϵ θ ( x t , t ) − 1 − α ˉ t w ∇ x t log f ϕ ( y ∣ x t ) \bar{\boldsymbol{\epsilon}}_\theta(\mathbf{x}_t, t) \boldsymbol{\epsilon}_\theta(x_t, t) - \sqrt{1 - \bar{\alpha}_t} \; w \nabla_{\mathbf{x}_t} \log f_\phi(y \vert \mathbf{x}_t) ϵˉθ(xt,t)ϵθ(xt,t)−1−αˉt w∇xtlogfϕ(y∣xt)
由此得到的简化扩散模型ADM以及添加了分类器引导的模型ADM - G能够取得比当时最先进的生成模型如 BigGAN更好的效果。 图 7
此外通过对 U-Net 架构进行一些修改达里瓦尔和尼科尔2021展示了扩散模型优于生成对抗网络GAN的性能。架构修改包括增加模型深度 / 宽度、增多注意力头、采用多分辨率注意力机制、在上下采样中使用 BigGAN 残差块、通过 对残差连接进行重新缩放 1 / 2 1/\sqrt{2} 1/2 以及使用自适应组归一化AdaGN。
Classifier-Free Guidance
即便没有独立的分类器 f ϕ f_{\phi} fϕ通过整合来自条件扩散模型和无条件扩散模型的分数依然可以执行条件扩散步骤霍和萨利曼斯2021。设通过分数估计器 ϵ θ ( x t , t ) \boldsymbol{\epsilon}_\theta(\mathbf{x}_t, t) ϵθ(xt,t) 参数化的无条件去噪扩散模型为 p θ ( x ) p_\theta(\mathbf{x}) pθ(x)通过 ϵ θ ( x t , t , y ) \boldsymbol{\epsilon}_\theta(\mathbf{x}_t, t, y) ϵθ(xt,t,y) 参数化的条件模型为 p θ ( x ∣ y ) p_\theta(\mathbf{x} \vert y) pθ(x∣y)。这两个模型可以由单个神经网络进行学习。确切地说条件扩散模型 p θ ( x ∣ y ) p_\theta(\mathbf{x} \vert y) pθ(x∣y) 在成对数据上 ( x , y ) (\mathbf{x}, y) (x,y) 进行训练其中条件信息 y y y 会被随机且周期性地丢弃这样模型也能知晓如何进行无条件图像生成即 ϵ θ ( x t , t ) ϵ θ ( x t , t , y ∅ ) \boldsymbol{\epsilon}_\theta(\mathbf{x}_t, t) \boldsymbol{\epsilon}_\theta(\mathbf{x}_t, t, y\varnothing) ϵθ(xt,t)ϵθ(xt,t,y∅)。
隐式分类器的梯度可以用条件和无条件分数估计器来表示。一旦将其代入分类器引导的修正分数中该分数就不再依赖于单独的分类器。 ∇ x t log p ( y ∣ x t ) ∇ x t log p ( x t ∣ y ) − ∇ x t log p ( x t ) − 1 1 − α ˉ t ( ϵ θ ( x t , t , y ) − ϵ θ ( x t , t ) ) ϵ ˉ θ ( x t , t , y ) ϵ θ ( x t , t , y ) − 1 − α ˉ t w ∇ x t log p ( y ∣ x t ) ϵ θ ( x t , t , y ) w ( ϵ θ ( x t , t , y ) − ϵ θ ( x t , t ) ) ( w 1 ) ϵ θ ( x t , t , y ) − w ϵ θ ( x t , t ) \begin{aligned} \nabla_{\mathbf{x}_t} \log p(y \vert \mathbf{x}_t) \nabla_{\mathbf{x}_t} \log p(\mathbf{x}_t \vert y) - \nabla_{\mathbf{x}_t} \log p(\mathbf{x}_t) \\ - \frac{1}{\sqrt{1 - \bar{\alpha}_t}}\Big( \boldsymbol{\epsilon}_\theta(\mathbf{x}_t, t, y) - \boldsymbol{\epsilon}_\theta(\mathbf{x}_t, t) \Big) \\ \bar{\boldsymbol{\epsilon}}_\theta(\mathbf{x}_t, t, y) \boldsymbol{\epsilon}_\theta(\mathbf{x}_t, t, y) - \sqrt{1 - \bar{\alpha}_t} \; w \nabla_{\mathbf{x}_t} \log p(y \vert \mathbf{x}_t) \\ \boldsymbol{\epsilon}_\theta(\mathbf{x}_t, t, y) w \big(\boldsymbol{\epsilon}_\theta(\mathbf{x}_t, t, y) - \boldsymbol{\epsilon}_\theta(\mathbf{x}_t, t) \big) \\ (w1) \boldsymbol{\epsilon}_\theta(\mathbf{x}_t, t, y) - w \boldsymbol{\epsilon}_\theta(\mathbf{x}_t, t) \end{aligned} ∇xtlogp(y∣xt)ϵˉθ(xt,t,y)∇xtlogp(xt∣y)−∇xtlogp(xt)−1−αˉt 1(ϵθ(xt,t,y)−ϵθ(xt,t))ϵθ(xt,t,y)−1−αˉt w∇xtlogp(y∣xt)ϵθ(xt,t,y)w(ϵθ(xt,t,y)−ϵθ(xt,t))(w1)ϵθ(xt,t,y)−wϵθ(xt,t)
他们的实验表明无分类器引导能够在 FID区分合成图像与生成图像的指标和 IS衡量图像质量与多样性的指标之间取得良好平衡。
引导扩散模型 GLIDE尼科尔、达里瓦尔、拉梅什等人2022对 CLIP 引导和无分类器引导这两种策略都进行了探索结果发现更倾向于后者。他们推测这是因为 CLIP 引导是利用对抗样本对 CLIP 模型进行开发利用而非优化生成匹配度更高的图像。
Speed up Diffusion Models
通过遵循反向扩散过程的马尔可夫链从 DDPM去噪扩散概率模型生成样本的速度非常慢因为步数可能多达一千步甚至几千步。宋等人2020的一项数据表明“例如从 DDPM 中采样 50,000 张 32×32 尺寸的图像大约需要 20 个小时而在英伟达 2080 Ti GPU 上使用生成对抗网络GAN采样同样数量的图像则不到一分钟。”
Fewer Sampling Steps Distillation
一种简单的方法是采用跨步采样方案尼科尔和达里瓦尔2021每 ⌈ T / S ⌉ \lceil T/S \rceil ⌈T/S⌉ 步进行一次采样更新从而将采样过程从 T T T 步缩减至 S S S 步。新的生成采样方案为 { τ 1 , … , τ S } \{\tau_1, \dots, \tau_S\} {τ1,…,τS}其中 τ 1 τ 2 ⋯ τ S ∈ [ 1 , T ] \tau_1 \tau_2 \cdots \tau_S \in [1, T] τ1τ2⋯τS∈[1,T] 且 S T S T ST。至于另一种方法我们可以将 q σ ( x t − 1 ∣ x t , x 0 ) q_\sigma(\mathbf{x}_{t-1} \vert \mathbf{x}_t, \mathbf{x}_0) qσ(xt−1∣xt,x0) 改写为通过期望标准差 σ t \sigma_t σt 进行参数化的形式。 x t − 1 α ˉ t − 1 x 0 1 − α ˉ t − 1 ϵ t − 1 α ˉ t − 1 x 0 1 − α ˉ t − 1 − σ t 2 ϵ t σ t ϵ α ˉ t − 1 ( x t − 1 − α ˉ t ϵ θ ( t ) ( x t ) α ˉ t ) 1 − α ˉ t − 1 − σ t 2 ϵ θ ( t ) ( x t ) σ t ϵ q σ ( x t − 1 ∣ x t , x 0 ) N ( x t − 1 ; α ˉ t − 1 ( x t − 1 − α ˉ t ϵ θ ( t ) ( x t ) α ˉ t ) 1 − α ˉ t − 1 − σ t 2 ϵ θ ( t ) ( x t ) , σ t 2 I ) \begin{aligned} \mathbf{x}_{t-1} \sqrt{\bar{\alpha}_{t-1}}\mathbf{x}_0 \sqrt{1 - \bar{\alpha}_{t-1}}\boldsymbol{\epsilon}_{t-1} \\ \sqrt{\bar{\alpha}_{t-1}}\mathbf{x}_0 \sqrt{1 - \bar{\alpha}_{t-1} - \sigma_t^2} \boldsymbol{\epsilon}_t \sigma_t\boldsymbol{\epsilon} \\ \sqrt{\bar{\alpha}_{t-1}} \Big( \frac{\mathbf{x}_t - \sqrt{1 - \bar{\alpha}_t} \epsilon^{(t)}_\theta(\mathbf{x}_t)}{\sqrt{\bar{\alpha}_t}} \Big) \sqrt{1 - \bar{\alpha}_{t-1} - \sigma_t^2} \epsilon^{(t)}_\theta(\mathbf{x}_t) \sigma_t\boldsymbol{\epsilon} \\ q_\sigma(\mathbf{x}_{t-1} \vert \mathbf{x}_t, \mathbf{x}_0) \mathcal{N}(\mathbf{x}_{t-1}; \sqrt{\bar{\alpha}_{t-1}} \Big( \frac{\mathbf{x}_t - \sqrt{1 - \bar{\alpha}_t} \epsilon^{(t)}_\theta(\mathbf{x}_t)}{\sqrt{\bar{\alpha}_t}} \Big) \sqrt{1 - \bar{\alpha}_{t-1} - \sigma_t^2} \epsilon^{(t)}_\theta(\mathbf{x}_t), \sigma_t^2 \mathbf{I}) \end{aligned} xt−1qσ(xt−1∣xt,x0)αˉt−1 x01−αˉt−1 ϵt−1αˉt−1 x01−αˉt−1−σt2 ϵtσtϵαˉt−1 (αˉt xt−1−αˉt ϵθ(t)(xt))1−αˉt−1−σt2 ϵθ(t)(xt)σtϵN(xt−1;αˉt−1 (αˉt xt−1−αˉt ϵθ(t)(xt))1−αˉt−1−σt2 ϵθ(t)(xt),σt2I)
其中模型 ϵ θ ( t ) ( . ) \epsilon^{(t)}_\theta(.) ϵθ(t)(.) 从 x t \mathbf{x}_t xt 预测 ϵ t \epsilon_t ϵt。 根据前面的定义在 q ( x t − 1 ∣ x t , x 0 ) N ( x t − 1 ; μ ~ ( x t , x 0 ) , β ~ t I ) q(\mathbf{x}_{t-1} \vert \mathbf{x}_t, \mathbf{x}_0) \mathcal{N}(\mathbf{x}_{t-1}; \tilde{\boldsymbol{\mu}}(\mathbf{x}_t, \mathbf{x}_0), \tilde{\beta}_t \mathbf{I}) q(xt−1∣xt,x0)N(xt−1;μ~(xt,x0),β~tI) 中, 因此我们有: β ~ t σ t 2 1 − α ˉ t − 1 1 − α ˉ t ⋅ β t \tilde{\beta}_t \sigma_t^2 \frac{1 - \bar{\alpha}_{t-1}}{1 - \bar{\alpha}_t} \cdot \beta_t β~tσt21−αˉt1−αˉt−1⋅βt
令 σ t 2 η ⋅ β ~ t \sigma_t^2 \eta \cdot \tilde{\beta}_t σt2η⋅β~t这样我们就可以将 η ∈ R \eta \in \mathbb{R}^ η∈R 作为超参数进行调整以控制采样的随机性。当 η 0 \eta 0 η0 这个特殊情况时采样过程就变为确定性的。这样的模型被称为去噪扩散隐式模型DDIM宋等人2020。DDIM 具有相同的边际噪声分布但能确定性地将噪声映射回原始数据样本。 在生成过程中我们无需遵循从 t 1 , 2 , . . . T t1,2,...T t1,2,...T 的完整链条而是只需其中的一个步骤子集。设 s t s t st 为这个加速轨迹中的两个步骤。DDIM 的更新步骤为 q σ , s t ( x s ∣ x t , x 0 ) N ( x s ; α ˉ s ( x t − 1 − α ˉ t ϵ θ ( t ) ( x t ) α ˉ t ) 1 − α ˉ s − σ t 2 ϵ θ ( t ) ( x t ) , σ t 2 I ) q_{\sigma, s t}(\mathbf{x}_s \vert \mathbf{x}_t, \mathbf{x}_0) \mathcal{N}(\mathbf{x}_s; \sqrt{\bar{\alpha}_s} \Big( \frac{\mathbf{x}_t - \sqrt{1 - \bar{\alpha}_t} \epsilon^{(t)}_\theta(\mathbf{x}_t)}{\sqrt{\bar{\alpha}_t}} \Big) \sqrt{1 - \bar{\alpha}_s - \sigma_t^2} \epsilon^{(t)}_\theta(\mathbf{x}_t), \sigma_t^2 \mathbf{I}) qσ,st(xs∣xt,x0)N(xs;αˉs (αˉt xt−1−αˉt ϵθ(t)(xt))1−αˉs−σt2 ϵθ(t)(xt),σt2I)
在实验中所有模型均采用 T 1000 T1000 T1000 扩散步骤进行训练。他们观察到当 S S S 较小时DDIM[ η 0 \eta0 η0]能够生成质量最佳的样本而 DDPM[ η 1 \eta1 η1]在较小的 [ S S S] 下表现则差得多。当我们能够承担完整的反向马尔可夫扩散步骤[ S T 1000 ST1000 ST1000]时DDPM 的表现确实更好。借助 DDIM可以将扩散模型训练到任意数量的前向步骤但在生成过程中仅从步骤子集中进行采样。
与去噪扩散概率模型DDPM相比去噪扩散隐式模型DDIM具备以下优势
以更少的步数生成更高质量的样本DDIM 能够在使用显著更少步数的情况下生成质量更高的样本。这意味着在实际应用中它可以更高效地完成样本生成任务减少计算资源的消耗和时间成本。具有 “一致性” 特性由于 DDIM 的生成过程是确定性的它具有 “一致性”。这表明基于相同潜在变量生成的多个样本应具有相似的高级特征。这种一致性在许多应用场景中非常重要例如需要生成具有相似风格或主题的多个样本时DDIM 可以确保这些样本在整体特征上保持一致。可在潜在变量中进行语义上有意义的插值得益于其一致性特性DDIM 能够在潜在变量空间中进行语义上有意义的插值操作。这使得在潜在变量空间中进行平滑过渡成为可能从而生成在语义上连贯且有意义的样本序列。例如在图像生成任务中可以通过对潜在变量进行插值实现从一个图像到另一个图像的平滑过渡生成一系列具有渐进变化的图像。 图9Progressive distillation can reduce the diffusion sampling steps by half in each iteration.
渐进蒸馏萨利曼斯和霍2022 年是一种将训练好的确定性采样器提炼成采样步数减半的新模型的方法。学生模型由教师模型初始化并且在去噪时其目标设定为让一个学生 DDIM 步骤匹配两个教师步骤而不是像原来那样使用样本 x 0 \mathbf{x}_0 x0 作为去噪目标。在每一次渐进蒸馏迭代中我们都可以将采样步数减半。 图 10Comparison of Algorithm 1 (diffusion model training) and Algorithm 2 (progressive distillation) side-by-side, where the relative changes in progressive distillation are highlighted in green.
相关阅读
扩散模型三
参考 What are Diffusion Models? Weng, Lilian. (Jul 2021). What are diffusion models? Lil’Log. https://lilianweng.github.io/posts/2021-07-11-diffusion-models/.