---
title: 【拡散モデル勉強会】Introduction to Diffusion Models
tags: 
author: [Deep Learning JP](https://docswell.com/user/DeepLearning2023)
site: [Docswell](https://www.docswell.com/)
thumbnail: https://bcdn.docswell.com/page/KJ49DGL571.jpg?width=480
description: 【拡散モデル勉強会】Introduction to Diffusion Models by Deep Learning JP
published: June 26, 24
canonical: https://docswell.com/s/DeepLearning2023/ZNRE7Q-2024-06-26-095347
---
# Page. 1

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

DEEP LEARNING JP
[DL Papers]
Introduction to Diffusion Models:
In Response to the Emergence of Sora
M2 Yuta Oshima, Matsuo Lab
http://deeplearning.jp/


# Page. 2

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

本発表の⽬的
• OpenAIによる⼤規模動画⽣成モデル Sora が出現．
• デモを⾒る限りでは，これまでの動画⽣成AIを⼤きく凌ぐ⽣成を実現．
• 詳細は不明だが，Vision TransformerベースのLatent Diffusion Modelsで構成され
ていることがテクニカルレポートにて⽰唆されている．
• それを受け,近年⼤きな注⽬を集める⽣成モデルである拡散モデルについて,基礎
的な内容を共有する.
• ⽣成モデルの基礎から，ViTベースの動画⽣成モデルまでの内容をまとめた．
• ⽬標は, Soraのテクニカルレポートを読んだ際に，内容が理解できるようにな
ること.
2


# Page. 3

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

⽬次
1. ⽣成モデルの基礎
2. 拡散モデルの基礎（DDPMを中⼼にして）
3. 拡散モデルの派⽣
4. 動画⽣成拡散モデル
3


# Page. 4

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

⽬次
1. ⽣成モデルの基礎
2. 拡散モデルの基礎（DDPMを中⼼にして）
3. 拡散モデルの派⽣
4. 動画⽣成拡散モデル
4


# Page. 5

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

⽣成モデルとは
• 観測されたデータが従う分布（データ分布）をモデル化することで，それらと似
たデータを⽣成できるモデル．
データ分布 𝑝!&quot;#&quot; (𝑥)
モデル化 (近似)
生成
生成モデル 𝑝$ (𝑥)
生成
データの集合D = {𝑥 ! }&quot;#
5


# Page. 6

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

深層⽣成モデルとは
• ニューラルネットワークでモデル化された⽣成モデルを，特に深層⽣成モデルと
呼ぶ．
• ランダムにサンプリングされた初期値からデータを⽣成するモデルが多い．
𝑧
ランダムな
初期値
生成モデル
𝑝$ (𝑥|𝑧)
生成された
データ
6


# Page. 7

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

深層⽣成モデルとは
• 拡散モデル以前にも，多くの深層⽣成モデルの枠組みが提案されている[8]．
7


# Page. 8

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

条件付け⽣成モデルとは
• ランダムな初期値の他に，条件𝒄を⼊⼒に⽤いることで，指定した条件に合った
⽣成が可能となる．
• 例えばMNISTの⽣成なら，条件𝑐として数字ラベルを与えれば，その数字の画像を⽣成可能．
• 条件𝑐はラベルのような単純なものである必要はない．テキストなどでも．
c
𝑧
生成モデル
𝑝$ 𝑥 𝑧, 𝑐)
8


# Page. 9

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

⽬次
1. ⽣成モデルの基礎
2. 拡散モデルの基礎（DDPMを中⼼にして）
3. 拡散モデルの応⽤と派⽣
4. 動画⽣成拡散モデル
9


# Page. 10

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

拡散モデルとは
• 拡散モデルは，画像⽣成での成功を⽪切りに，⼤きく注⽬を集める⽣成モデル．
• 発展の契機となったのは，Denoising Diffusion Probabilistic Models (DDPM)[1]と
呼ばれるモデルの登場．
• GANなどの従来の⽣成モデルに⽐べ，⽣成品質や学習安定性の⾯で優れる．
10


# Page. 11

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

拡散モデルとは
• 拡散モデルでは，初期値のノイズから段階的にノイズを除去し，データを⽣成．
• 下の図における𝑥! は，ガウス分布からランダムにサンプリングされた初期値
となっている．
• ランダムな初期値テンソルからデータを⽣成する深層⽣成モデルの基本的な
設計に沿っている．
11


# Page. 12

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

拡散モデルの枠組み
Denoising Diffusion Probalistic Model (DDPM) [1]
• データx&quot;に徐々にガウシアンノイズを加えていき，完全なガウシアンノイズ
𝑥! ~𝑁(𝑥! ; 0, 𝐼)にする（拡散過程）．ここにはNNは使⽤しない．
• β# の値が⼤きいほど，ノイズの割合が⼤きい．
12


# Page. 13

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

拡散モデルの枠組み
Denoising Diffusion Probalistic Model (DDPM) [1]
• ⽣成は，拡散過程を逆向きに辿る（逆過程）．逆過程をNNでモデル化．
• ノイズの乗ったデータ𝑥$ と拡散時刻𝑡を⼊⼒とし， 𝑥#%&amp;の平均と分散を求める形
で定式化することができる．
13


# Page. 14

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

拡散モデルの枠組み
Denoising Diffusion Probalistic Model (DDPM) [1]
• 実際は， ノイズの乗ったデータ𝑥$ と拡散時刻𝑡を⼊⼒とし， 𝑥$ に載っているノイ
ズを予測する．このノイズ予測器にNNが⽤いられている．
画像引用元：深層生成モデル2024 第6回 講義資料
14


# Page. 15

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

拡散モデルの枠組み
Denoising Diffusion Probalistic Model (DDPM) [1]
• 実際は， ノイズの乗ったデータ𝑥$ と拡散時刻𝑡を⼊⼒とし， 𝑥$ に載っているノイ
ズを予測する．このノイズ予測器にNNが⽤いられている．
• ノイズ予測器で予測したノイズεを 𝑥$ から引くことで，反復的にノイズを除去．
画像引用元：深層生成モデル2024 第6回 講義資料
15


# Page. 16

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

拡散モデルのアーキテクチャ
Denoising Diffusion Probalistic Model (DDPM) [1]
• DDPMではノイズ除去器にU-Net [2] を⽤いる．各解像度の畳み込み層の前に空間
⽅向のAttention [3] を⼊れることが，⾼い⽣成性能のために必要．
16


# Page. 17

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

⽬次
1. ⽣成モデルの基礎
2. 拡散モデルの基礎（DDPMを中⼼にして）
3. 拡散モデルの派⽣
4. 動画⽣成拡散モデル
17


# Page. 18

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

条件付け拡散モデル
Text to Image (T2I) の拡散モデル [9]
• 条件付け⽣成モデルの枠組みを拡散モデルに応⽤した研究．
• ⾔語情報で条件付けることで，柔軟な指⽰を⽣成される画像に与えることが可能．
18


# Page. 19

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

軽量な拡散モデル
潜在拡散モデル [10]
• VQ-VAE[11][12]等と組み合わせることで，画像を低次元の潜在変数に
落とし込み，より少ない計算量で拡散モデルを学習する．
• より⾼解像度の⽣成も可能に．
19


# Page. 20

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

スケーラブルな拡散モデル
Scalable Diffusion Models with Transformers (DiT) [4]
• Vision Transformer (ViT) で構成された拡散モデル．
• ViT が持つスケーラビリティと拡散モデルを組み合わせることが動機．
20


# Page. 21

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

スケーラブルな拡散モデル
Scalable Diffusion Models with Transformers (DiT) [4]
• 画像をそのまま扱うわけではない．
• 潜在拡散モデル × パッチ化 で軽量化．
• 画像𝑥をまずVAEに⼊れ，潜在変数𝑧にする．
• 𝑥 256×256×3 → 𝑧 (32×32×4)
• その後，潜在変数𝑧をパッチ化する．
• 論⽂では𝑝 = 2, 4, 8 で実験している．
• 𝑝 はパッチサイズ．
21


# Page. 22

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

スケーラブルな拡散モデル
Scalable Diffusion Models with Transformers (DiT) [4]
• モデルサイズとパッチサイズを変えた場合の⽐較．
• モデルサイズ(S, B, L, XL)が⼤きくなる，パッチサイズ(表の凡例では /𝑝 で⽰さ
れる)が⼩さくなる(=計算量が増加する)ほど性能向上(スケーラブル)．
22


# Page. 23

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

⽬次
1. ⽣成モデルの基礎
2. 拡散モデルの基礎（DDPMを中⼼にして）
3. 拡散モデルの派⽣
4. 動画⽣成拡散モデル
23


# Page. 24

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

動画⽣成拡散モデル
Video Diffusion Models (VDM) [13]
• 画像⽣成の拡散モデルでは，2D UnetやViTなどに
より，空間⽅向の特徴を捉えている．これにより
画像⽣成において既存の⽣成モデルを凌ぐ．
• しかし，動画⽣成においては空間⽅向の特徴のみ
でなく，時間⽅向の特徴を捉える必要がある．
• そこで，VDMでは，空間⽅向のAttentionの他に，
時間⽅向のAttentionを，拡散モデルのUnetの内部
に追加することで，時間⽅向の特徴を捉える．
(a) Video Diffusion Models
24


# Page. 25

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

スケーラブルな動画⽣成拡散モデル
Video Diffusion Transformer (VDT) [14]
• 動画⽣成拡散モデルにDiTを⽤いた初期の研究．
• DiTに，時間⽅向の依存関係を捉えるAttentionを挿⼊した．
• VDMと同様に，Spatial Attn.とTemporal Attn.を繰り返す．
25


# Page. 26

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

スケーラブルな動画⽣成拡散モデル
Latte: Latent Diffusion Transformer for Video Generation [15]
• 動画⽣成拡散モデルにDiTを⽤いる場合について広範に検証した．
• スケーラビリティについての検証もされている(右)．
26


# Page. 27

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

参考⽂献
[1] Jonathan Ho, Ajay Jain, and Pieter Abbeel. Denoising diffusion probabilistic models. Advances in neural information processing systems, 33:6840–6851, 2020.
[2] Ronneberger, O., Fischer, P., &amp; Brox, T. (2015). U-net: Convolutional networks for biomedical image segmentation. In Medical Image Computing and Computer-Assisted Intervention–MICCAI 2015:
18th International Conference, Munich, Germany, October 5-9, 2015, Proceedings, Part III 18 (pp. 234-241). Springer International Publishing.
[3] Shen et al., 2018 &quot;Efficient Attention: Attention with Linear Complexities&quot;, arXiv:1812.01243
[4] William Peebles and Saining Xie. Scalable diffusion models with transformers. arXiv preprint arXiv:2212.09748, 2022.
[5] Albert Gu, Karan Goel, and Christopher R.. Efficiently modeling long sequences with structured state spaces. arXiv
preprint arXiv:2111.00396, 2021.
[6] Albert Gu, Karan Goel, Ankit Gupta, and Christopher R.. On the parameterization and initialization of diagonal state space
models. Advances in Neural Information Processing Systems, 35:35971–35983, 2022.
[7] Junxiong Wang, Jing Nathan Yan, Albert Gu, and Alexander M Rush. Pretraining without attention. arXiv preprint arXiv:2212.10544, 2022.
[8] https://lilianweng.github.io/posts/2021-07-11-diffusion-models/
[9] Ramesh, A., Dhariwal, P., Nichol, A., Chu, C., &amp; Chen, M. (2022). Hierarchical text-conditional image generation with clip latents. arXiv preprint arXiv:2204.06125, 1(2), 3.
[10] Rombach, Robin, et al. &quot;High-resolution image synthesis with latent diffusion models.&quot; Proceedings of the IEEE/CVF conference on computer vision and pattern recognition. 2022.
[11] Van Den Oord, Aaron, and Oriol Vinyals. &quot;Neural discrete representation learning.&quot; Advances in neural information processing systems 30 (2017).
[12] Razavi, Ali, Aaron Van den Oord, and Oriol Vinyals. &quot;Generating diverse high-fidelity images with vq-vae-2.&quot; Advances in neural information processing systems 32 (2019).
[13] Ho, Jonathan, et al. &quot;Video diffusion models.&quot; Advances in Neural Information Processing Systems 35 (2022): 8633-8646.
[14] Lu, Haoyu, et al. &quot;Vdt: General-purpose video diffusion transformers via mask modeling.&quot; The Twelfth International Conference on Learning Representations. 2023.
[15] Ma, Xin, et al. &quot;Latte: Latent diffusion transformer for video generation.&quot; arXiv preprint arXiv:2401.03048 (2024).
27


# Page. 28

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

スケーラブルな拡散モデル
Scalable Diffusion Models with Transformers (DiT) [4]
• 条件付け（CFG[17]）の⽅法
• In-context conditioning：𝑡, 𝑐のベクトル埋め込みを，⼊⼒シーケンスに連結するだけ．
• adaLN, adaLN-Zero：適応的なLayer Normalization．
28


# Page. 29

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

スケーラブルな動画⽣成拡散モデル
Video Diffusion Transformer (VDT) [14]
• Video DiffusionにDiTを⽤いた初期の研究．
• 多様な⽣成⽅法が可能なことが主張されている．
29


# Page. 30

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

スケーラブルな動画⽣成拡散モデル
Video Diffusion Transformer (VDT) [14]
• Video DiffusionにDiTを⽤いた初期の研究．
• 条件付けの⽅法についても⽐較がなされている．Token Concatが良さそう？
30


# Page. 31

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

VDT: Video Diffusion Transformer
• その実装の⼀部は，著者によってGithubに上げられている．
– https://github.com/RERV/VDT/tree/main?tab=readme-ov-file
• アルゴリズムのコードのみであり，学習や評価のコードは載せられていない．
• また，学習済みモデルは最近削除された(issueで不具合が申し⽴てられたから？)
31


# Page. 32

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

VDT: Video Diffusion Transformer
• ⾃⾝は，以前公開されていた，Physionで学習した重みを保存していたので，そち
らをまずは回した．
• 最初の8フレームで条件付けた推論．
32


# Page. 33

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

VDT: Video Diffusion Transformer
• DiTのtrain code (こちらは公開されている)を少しいじると学習ができるというissue
があったので，これをいじり，学習を実⾏した．
• 現在学習中．
• 画像⽣成を動画⽣成に移植する際のTipsとしては，画像と動画のデータ形式の違
いに注意すること．
– その前処理はしていいか？
– いつ，どのようにreshapeするか？
33


# Page. 34

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

SSMを⽤いた拡散モデル
Efficient State Space Models (SSMs) [5] [6]
• ⼀⽅で，近年ではAttentionの有望な代替として，SSMsの研究が盛ん．
• 特に初期化や学習を⼯夫することで，⻑期系列の依存関係を捉えられるように
なった（S4[5], S4D[6]など）[7]．詳細は，野中さん，岩澤さんの輪読会資料参照．
34


# Page. 35

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

SSMを⽤いた拡散モデル
Efficient State Space Models (SSMs) [5] [6]
• S4を始めとするSSMsが注⽬される理由は，その⾼い⻑期依存性の把握能⼒にも
関わらず，系列⽅向の計算が並列で⾏え，計算量やメモリ消費量も少ないため．
• 本研究では，SSMsの⼀つであるS4D [6] を⽤いて，Attentionを⽤いない拡散モデ
ルを提案する．
35


# Page. 36

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

SSMを⽤いた拡散モデル
Diffusion State Space Model (DiffuSSM)
• ViTにおけるTransformer Blockのように，DiffuSSM Blockを積み重ねる．
• 画像をパッチにして⼊⼒している．
36


# Page. 37

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

SSMを⽤いた拡散モデル
Diffusion State Space Model (DiffuSSM)
• ViTにおけるTransformer Blockのように，
DiffuSSM Blockを積み重ねる．
• S4DはBidirectionalにしている．
• MLPを⽤いる際には，Down-scaleやUp-scale
を⽤いて，系列⽅向に縮⼩している．
37


