---
title: 【Diffusion勉強会】CADS: Unleashing the diversity of diffusion models through condition-annealed sampling
tags: 
author: [Deep Learning JP](https://docswell.com/user/DeepLearning2023)
site: [Docswell](https://www.docswell.com/)
thumbnail: https://bcdn.docswell.com/page/YJ6Q5RMPJV.jpg?width=480
description: YouTubeはこちら→https://youtu.be/XLhImReiNo4
published: July 16, 24
canonical: https://docswell.com/s/DeepLearning2023/5P2WP1-2024-11-22-161159
---
# Page. 1

![Page Image](https://bcdn.docswell.com/page/YJ6Q5RMPJV.jpg)

DEEP LEARNING JP
[DL Papers]
CADS: Unleashing the diversity of diffusion models
through condition-annealed sampling
2024.07.16 Akihiro Nakano, D2, Matsuo Lab
http://deeplearning.jp/
1


# Page. 2

![Page Image](https://bcdn.docswell.com/page/GJ5RY8ZP74.jpg)

書誌情報
“CADS: Unleashing the diversity of diffusion models through
condition-annealed sampling”
• 著者：Seyedmorteza Sadat, Jakob Buhmann, Derek Bradley, Otmar
Hilliges, Romann M. Weber
• 所属：ETH Zurich, DisneyResearch
– 同じ1stとlast authorで別の論⽂も出ている
• ICLR2024にてspotlightとして採択
2


# Page. 3

![Page Image](https://bcdn.docswell.com/page/LE3P5896J5.jpg)

概要
• 拡散モデルによる条件付け⽣成において，⽣成物の多様性が低い問題
に対し，どんなモデルでも推論時に適⽤できる⼿法（CADS,
Condition-Annealed Diffusion Sampler）を提案
– Text-to-imageに限らず，幅広い条件付⽣成タスクにおいて性能評価を⾏って
いる
• 単純にDDPMを⽤いたサンプリングをするのに⽐べて，FIDと多様性
の観点において性能向上を確認
– DDPM以外のサンプラーでも性能向上
– CFGの重みをただ変化させるよりもうまく⽣成できることを確認
3


# Page. 4

![Page Image](https://bcdn.docswell.com/page/8EDLDMGMJG.jpg)

背景
• Classifier-free guidance [1]を⽤いた条件付け⽣成を⾏う場合，
guidance scale 𝑤を上げることで⽣成品質が上がることが知られて
いる
∇𝒙 log 𝑝&quot; 𝒙|𝒄 = ∇𝒙 log 𝑝 𝒙|∅ + 𝑤 ∇𝒙 log 𝑝 𝒙|𝒄 − ∇𝒙 log 𝑝(𝒙|∅)
– ⼀⽅，scaleを上げると⽣成結果の多様性が減ることが知られている
– データセットのサイズが⼩さい場合は，低いscaleでも多様性が⾼くないこと
が知られている
4


# Page. 5

![Page Image](https://bcdn.docswell.com/page/V7P2XR3Q78.jpg)

関連研究①：Autoguidance [2]
• CFGではunconditionalを⽤いてguidanceを⾏うのに対し，より⼩さ
なコストで学習させたモデルを⽤いたguidance（autoguidance）を
提案
– 例：earlier checkpoint of the model itself
• より⼩さなコストで学習させている分，分布の裾がデータ分布から
離れる⽅向に広くなっている
#!
• Denoisingの過程では を⼤きく
#&quot;
させる⽅向に進む
→よりデータにfitする⽅向に進む
5


# Page. 6

![Page Image](https://bcdn.docswell.com/page/2JVDLR4PJQ.jpg)

関連研究②：Analysis of CFG Weight Schedulers [3]
• CFGにおいてguidance scaleを
変化させることで⽣成品質と
多様性を改善できることを提案
– Guidance scaleの変化させ⽅を
分析，単調増加なschedulerが最も
性能向上につながることを確認
6


# Page. 7

![Page Image](https://bcdn.docswell.com/page/5EGYXM1QEL.jpg)

⼿法
• 推論時，各時刻における条件付け信号に対して以下のように
annealingを適⽤する
0 = 𝛾 𝑡 𝒚 + 𝑠 1 − 𝛾 𝑡 𝒏,
𝒚
𝒏 ∼ 𝒩 𝟎, 𝑰
– 𝑠: 初期ノイズスケール， 𝛾 𝑡 : annealingスケジュール（ハイパラ）
• Annealingスケジュールとして，以下の関数を使⽤
1 if 𝑡 ≤ 𝜏$
𝜏% − 𝑡
if 𝜏$ &lt; 𝑡 &lt; 𝜏%
𝛾 𝑡 =
𝜏% − 𝜏$
0 if 𝑡 ≥ 𝜏%
– 𝜏!, 𝜏&quot; ∈ 0,1 : ユーザ指定の閾値（ハイパラ）
→ ⽣成の最初の⽅は⾼いannealing，𝑡 ≤ 𝜏$ ではannealing無し
7


# Page. 8

![Page Image](https://bcdn.docswell.com/page/4JQM8RDW7P.jpg)

⼿法
• Conditioningにノイズを加えると，平均と分散が変わってしまう
→ 元の平均と分散に⼀致するようにrescalingを⾏う
• 以下の更新式でrescalingを⾏う
0 − mean 𝒚
0
𝒚
0&amp;&#039;()*+&#039;, =
𝒚
𝜎-. + 𝜇-.
0
std 𝒚
0/-.*+ = 𝜓0
0
𝒚
𝒚&amp;&#039;()*+&#039;, + 1 − 𝜓 𝒚
– 𝜓 ∈ 0,1 : mixing factor（ハイパラ）
– ⾼いノイズスケール 𝑠 を設定したときに発散するのを防げるが，多様性は若⼲
下がる
8


# Page. 9

![Page Image](https://bcdn.docswell.com/page/K74V28Z1J1.jpg)

⼿法
Intuition
• CFGはBayes則と関連づけて説明できる
0|𝒛0
𝑝0,&quot; 𝒛0 |0
𝒚 ∝ 𝑝 𝒛0 𝑝 𝒚
&quot;
∝ 𝑝 𝒛0
𝑝 𝒛0 |0
𝒚
⋅
𝑝(𝒛0 )
&quot;
より，
∇𝒛# log 𝑝&quot; 𝒛0 |0
𝒚 = ∇𝒛# log 𝑝 𝒛0 |∅ + 𝑤 ∇𝒛# log 𝑝 𝒛0 |0
𝒚 − ∇𝒛# log 𝑝(𝒛0 |∅)
• したがって，
, ≈ 𝑠𝒏 より，完全にunconditional
– 𝑡 = 1 に近いと，𝛾 𝑡 ≈ 0 なので 𝒚
– 𝑡 = 0 に近づくと，徐々にconditionalの信号が増えていく
→ 推論時，最初に探索を増やすことで多様性を上げる
9


# Page. 10

![Page Image](https://bcdn.docswell.com/page/LJ13M2R57G.jpg)

⼿法とScore smoothingの関連性
• CFGはBayes則より ∇𝒛# log 𝑝0 𝒛0 |𝒚 = ∇𝒛# log 𝑝0 𝒛0 + ∇𝒛# log 𝑝0 𝒚|𝒛0
• ノイズを加えると第2項がどう変化するかについて分析するために，
まず近似を求める．
• 𝑝0 𝒚|𝒛0 = ∫𝒙 𝑝0 (𝒚|𝒙) 𝑝0 𝒙|𝒛0 𝑑𝒙 のうち，分布𝑝0 𝒙|𝒛0 はintractable
00 , 𝜆𝑰 で近似する．
なので，ガウス分布，𝑝0 𝒙|𝒛0 ≈ 𝒩 𝒙
• 拡散モデルのforward過程が 𝒛0 = 𝒙 + 𝜎 𝑡 𝜺 のとき，分布 𝑝0 𝒙|𝒛0 の
00 = 𝔼 𝒙|𝒛0 = 𝒛0 + 𝜎 𝑡 ∇𝒛# log 𝑝0 𝒛0 に
平均はTweedieの公式より 𝒙
よって計算できる
10


# Page. 11

![Page Image](https://bcdn.docswell.com/page/GJWP3R1W72.jpg)

⼿法とScore smoothingの関連性
• したがって，transformation matrix 𝐓 を⽤いると，
𝑝0 𝒚|𝒛0 ≈ 𝒩 𝐓0
𝒙0 , 𝜆% 𝐓𝐓 3
と書ける．これは，𝒚|𝒛0 = 𝐓0
𝒙0 + 𝜆𝐓𝒖, 𝒖 ∼ 𝒩 𝟎, 𝑰 と書けることを意味
する．
• よって，ノイズがさらに加えられたとき，0
𝒚|𝒛0 = 𝐓0
𝒙0 + 𝜆𝐓𝒖 + 𝜎4 𝒏な
ので，
0|𝒛0 ≈ 𝒩 𝐓0
𝑝0 𝒚
𝒙0 , 𝜆% 𝐓𝐓 3 + 𝜎4% 𝑰
• これより，
𝒙0
5$ 𝜕0
3
%
3
%
0|𝒛0 = 𝒚
0 − 𝐓0
∇𝒛# log 𝑝0 𝒚
𝒙0 𝜆 𝐓𝐓 + 𝜎4 𝑰 𝐓
𝜕𝒛0
• ノイズがない場合（𝜎4 = 0）に⽐べ，正則化の働きをしている
11


# Page. 12

![Page Image](https://bcdn.docswell.com/page/4EZKVRP2E3.jpg)

実験
• タスク・使⽤モデル
タスク
データセット
モデル
ノイズの乗せ方
Class-conditioned
ImageNet
DiT-XL/2 (pretrained)
Class embeddingsに加える
Pose-to-image
DeepFashion, SHHQ
LDM (train from scratch)
Pose imageに直接加える
ID3PM (pretrained)
Face-ID embeddingsに加える
Identity-conditioned
Text-to-image
COCO2014 validation set
Stable Diffusion (pretrained) Text embeddingsに加える
– いずれもDDPMをサンプラーとして採⽤
• ベースライン
– CFG
– Dynamic CFG: CFGにおいてguidance scaleを変化させる
– CADS
12


# Page. 13

![Page Image](https://bcdn.docswell.com/page/Y76Q5R467V.jpg)

実験
• 評価指標
– ⽣成品質
• FID
• Inception score
• Precision [4]
– 多様性
• Recall [4]
– Ground truth画像と⽣成画像の埋め込み表現のmanifoldがどれくらい近いかを測る
• Mean Similarity Score (MSS)
– SSCD [5]での埋め込み表現間のpairwise cosine similarityの平均
• Vendi Score
– SSCD [5]での埋め込み表現間のpairwise cosine similarity matrixのVon Neumann entropy
13


# Page. 14

![Page Image](https://bcdn.docswell.com/page/G75RY8Q5E4.jpg)

結果
• CADSを⽤いることでFIDも
改善しつつ，多様性も改善
Pose-to-image
Identity-conditioned
Class-conditioned
Text-to-image
14


# Page. 15

![Page Image](https://bcdn.docswell.com/page/9J2DGKPGJR.jpg)

結果
• CFG scale vs. metrics
– 品質と多様性のトレードオフ関係を
軽減
• サンプラーによる効果
– どのサンプラーに対しても有効
• Dynamic CFG vs. CADS
– ただguidance scaleを調整するより
ノイズを⼊れる⽅が多様性が上がる
• Condition alignment
– Competitiveな性能
15


# Page. 16

![Page Image](https://bcdn.docswell.com/page/DEY2VN5GEM.jpg)

結果
Ablations
• ノイズスケール 𝑠，閾値 𝜏$ ，
mixing factor 𝜓
• 閾値 𝜏%
– 𝜏!を固定して 𝜏&quot; を変えたが傾向は
⼀概には⾔えなさそう
– Mixing factorを増やすと（より強い
正則化）FIDは改善するが多様性は
下がる（トレードオフ）
– ノイズスケールと 𝜏! の設定が重要
かつ難しそう
• その他のablation
– Annealing schedule
– Noiseの分布
16


# Page. 17

![Page Image](https://bcdn.docswell.com/page/VJN8MXN878.jpg)

まとめ
• どの拡散モデルに対しても適⽤できるかつ学習不要な，条件付け⽣成
物の多様性を向上させる⼿法，CADS，を提案
– CFGを⽤いる際，条件付け信号にannealingを加える⼿法
– 幅広い条件付け⽣成タスクにおいて⽣成品質と多様性の向上を確認
• 加えるノイズのスケールやノイズを加えるタイミングが重要なハイ
パラか
疑問など
• Embeddingにノイズを加えるとそれは別の信号になるのでは？
– 例：text embeddingにノイズを加えると別のtextでconditionすることになる？
• ⽣成過程が線形でないのに対し，annealingをどう⼯夫するかはもう
少し分析ができそう
17


# Page. 18

![Page Image](https://bcdn.docswell.com/page/YE9KN8RXE3.jpg)

参考⽂献
[1] Ho J, Salimans T. Classifier-free diffusion guidance. arXiv preprint arXiv:2207.12598. 2022 Jul 26.
[2] Karras T, Aittala M, Kynkäänniemi T, Lehtinen J, Aila T, Laine S. Guiding a Diffusion Model with a Bad Version of Itself.
arXiv preprint arXiv:2406.02507. 2024 Jun 4.
[3] Wang X, Dufour N, Andreou N, Cani MP, Abrevaya VF, Picard D, Kalogeiton V. Analysis of Classifier-Free Guidance
Weight Schedulers. arXiv preprint arXiv:2404.13040. 2024 Apr 19.
[4] Kynkäänniemi T, Karras T, Laine S, Lehtinen J, Aila T. Improved precision and recall metric for assessing generative
models. Advances in neural information processing systems. 2019;32.
[5] Pizzi E, Roy SD, Ravindra SN, Goyal P, Douze M. A self-supervised descriptor for image copy detection. InProceedings
of the IEEE/CVF Conference on Computer Vision and Pattern Recognition 2022 (pp. 14532-14542).
18


# Page. 19

![Page Image](https://bcdn.docswell.com/page/GE8RK8W9JD.jpg)

Appendix A. Pseudocode
19


# Page. 20

![Page Image](https://bcdn.docswell.com/page/LELKZRNMJR.jpg)

Appendix B. Dynamic CFG vs. CADS
• Dynamic CFGよりはCADSの⽅が改善幅は⼤きい
• 組み合わせることによってさらに性能向上が⾒られる場合もあるが，
CFG scaleが⼤きいのみ場合のみか
20


