1 of 46

Introduction to Diffusion Models

230103

Sejong Yang

2 of 46

References

  • Understanding Diffusion Models: A Unified Perspective, arXiv 2022.08
  • Denoising Diffusion Probabilistic Models, NeurIPS 2020
  • Denoising Diffusion Implicit Models, ICLR 2021

NVIDIA에서 발표한 Diffusion Tutorial

어영정 교수님네 학생이 발표한 Diffusion Tutorial

3 of 46

이 세미나에서 얻어가셔야할 것

  • 그리고 내 Task에서 Diffusion을 쓸 수 있는지? / 써야하는지? 에 대한 이야기
  • [1] 대부분의 생성 모델 자체 혹은 활용할 수 있는 연구의 경우 - Yes
  • [2] Representation Learning이 필요한 경우 - Helpful
  • [4] Spatial Complexity가 낮아야하는 경우 - Helpful
  • [3] Temporal Complexity가 낮아야하는 경우 - Nooooo

3

4 of 46

수식에 너무 매몰되지 말자

  • [1] Diffusion Model을 위한 새로운 학습 방법을 알고 싶다
    • 흐름뿐 아니라 디테일한 수식 전개 테크닉까지
  • [2] 관련 연구를 하고 싶고, Diffusion 논문을 읽고 싶다
    • 결국 디퓨전 모델이 무엇을 하는지? (e.g. input and output이 무엇인지?)
    • 수식에서 어떤 가정, 결론 그리고 중간 조건을 가지고 전개해서 이를 이론적으로 정당화 하는지?
  • [3] 모델을 돌려보고 싶다 / 그냥 생성 모델 Prior 정도로 활용하고 싶다
    • 결론만 알아도 됩니다 + 결국 모델이 뭘, 왜 학습해서 어떻게 쓰는지!
  • 오늘의 세미나는 주로 [3], 가끔 [2]가 나올 예정

Diffusion Model 수학이 포함된 tutorial, https://youtu.be/uFoGaIVHfoE

3

[3]이 목적이신 분들은 2일 땐 잠시 쉬어도 좋습니다

5 of 46

시작하기 전에 알아야할것들

  • Auto-Encoder (AE)
  • Evidence Lower Bound (ELBO)
  • Variational Auto-Encoder (VAE)
  • Hierarchical VAE

Ian Goodfellow et al. (2016) Deep Learning. http://www.deeplearningbook.org

https://www.deeplearningbook.org/

그냥 심심할 때 마다 recap하면 좋은 책

아래의 박스친 부분을 알고 있다는 전제하에 세미나를 진행하겠습니다

2

6 of 46

시작하기 전에 알아야할것들

  • Auto-Encoder (AE)
  • Evidence Lower Bound (ELBO)
  • Variational Auto-Encoder (VAE)
  • Hierarchical VAE

https://www.deeplearningbook.org/

그냥 심심할 때 마다 recap하면 좋은 책

아래의 박스친 부분을 알고 있다는 전제하에 세미나를 진행하겠습니다

까먹으신 분도 이해할 수 있게 노력해보겠습니다

2

7 of 46

오늘의 목적지

3

Diffusion Model 수학이 포함된 tutorial, https://youtu.be/uFoGaIVHfoE

열역학에서 파생된 분자운동 예측

8 of 46

브라운 운동과 확산 (Diffusion)

3

Diffusion Model 수학이 포함된 tutorial, https://youtu.be/uFoGaIVHfoE

열역학이 분자, 양자를 고려하게 되면서

불확실성을 다루는 방법들을 많이 고민

→ 통계학과 확률론의 발전에 지대한 공헌

세상에 쓸데없는 수학은 없고 대부분 이상한 물리학적 난제를 설명하려다가 나오는듯

중세 시대엔 대수학이 그런 역할을 했던듯

→ 머신러닝쟁이, 딥러닝쟁이들이 잘 쓰고 있다

e.g. 힌튼이 제시한 볼츠만 머신

e.g. 홉필드 네트워크; 물리학적 스핀 모델에서 착안

e.g. 오늘 다뤄볼 Diffusion Model

우리 필드에서 차용 가능할만한 수학적 개념을 찾는다면

물리학과의 수리통계학 1, 2 강의 추천합니다

9 of 46

시작하기 전에 알아야할것들

  • Auto-Encoder (AE)
  • Evidence Lower Bound (ELBO)
  • Variational Auto-Encoder (VAE)
  • Hierarchical VAE

3

Reconstruction Loss

10 of 46

시작하기 전에 알아야할것들

  • Auto-Encoder (AE)
  • Evidence Lower Bound (ELBO)
  • Variational Auto-Encoder (VAE)
  • Hierarchical VAE

3

그러면 Z에서 P라는 확률분포로 변환해주는 어떤 함수가 있다면

[1] 신경망으로 그 함수를 모사할 수 있을까? → Universal Approximation Theorem

Reconstruction Loss

이미지는 수의 집합

숫자 이미지의 집합은 수의 집합의 집합

숫자 이미지들을 표현하는 모분포가 존재

표본 추출된 데이터셋의 분포 P로 이걸 추론할 수 있다

11 of 46

시작하기 전에 알아야할것들

  • Auto-Encoder (AE)
  • Evidence Lower Bound (ELBO)
  • Variational Auto-Encoder (VAE)
  • Hierarchical VAE

3

그러면 Z에서 P라는 확률분포로 변환해주는 어떤 함수가 있다면

[1] 신경망으로 그 함수를 모사할 수 있을까? → Universal Approximation Theorem

[2] Z가 우리가 잘 알고있는 정규분포와 비슷하다면 생성 모델로의 가치도 있지 않을까? → Generative Model Learning

Reconstruction Loss

Norm (mean, var)

Z에서 z를 sample해 Decoder에 입력해주면 데이터 x’를 생성할 수 있으니까

Luo, C. (2022). Understanding diffusion models: A unified perspective. arXiv preprint arXiv:2208.11970.

이미지는 수의 집합

숫자 이미지의 집합은 수의 집합의 집합

숫자 이미지들을 표현하는 모분포가 존재

표본 추출된 데이터셋의 분포 P로 이걸 추론할 수 있다

12 of 46

시작하기 전에 알아야할것들

  • Auto-Encoder (AE)
  • Evidence Lower Bound (ELBO)
  • Variational Auto-Encoder (VAE)
  • Hierarchical VAE

likelihood = data

latent code

joint distribution

marginal likelihood

= evidence

될지 안 될지 애매한 paradox 상황에서 필요한 건 더 엄밀하고 바른 생각

latent variable z와 observation x를 통해 data distribution p(x)를 marginalize할 수 있다는 직관으로 출발해서

VAE 학습을 통해 구한 approximate distribution이 ELBO를 maximize한다는 사실 확인

ELBO

Luo, C. (2022). Understanding diffusion models: A unified perspective. arXiv preprint arXiv:2208.11970.

2

13 of 46

시작하기 전에 알아야할것들

  • Auto-Encoder (AE)
  • Evidence Lower Bound (ELBO)
  • Variational Auto-Encoder (VAE)
  • Hierarchical VAE

likelihood = data

latent code

marginal likelihood

= evidence

그냥 실제 데이터 분포는 세상에 존재하긴 하는데 우리가 구할 수 없는 친구 (intractable)

부분부분 쪼개서 관측을 통해 (marginalize) 학습한 분포 변환 모델(VAE)로도

실제 데이터 분포에 가까운 것을 모사 가능!

ELBO

Luo, C. (2022). Understanding diffusion models: A unified perspective. arXiv preprint arXiv:2208.11970.

3

14 of 46

시작하기 전에 알아야할것들

  • Auto-Encoder (AE)
  • Evidence Lower Bound (ELBO)
  • Variational Auto-Encoder (VAE)
  • Hierarchical VAE

Luo, C. (2022). Understanding diffusion models: A unified perspective. arXiv preprint arXiv:2208.11970.

2

왜 VAE의 학습을 통해 얻어지는 approximate data distribution이 ELBO를 최대화 할 수 있는가?

ELBO를 잘 쪼개보면 결국 reconstruction term과 prior matching term (latent code z가 정규분포여야한다)

Reconstruction Loss

Norm (mean, var)

15 of 46

시작하기 전에 알아야할것들

  • Auto-Encoder (AE)
  • Evidence Lower Bound (ELBO)
  • Variational Auto-Encoder (VAE)
  • Hierarchical VAE

Luo, C. (2022). Understanding diffusion models: A unified perspective. arXiv preprint arXiv:2208.11970.

Reconstruction Loss

KL Divergence with Gaussian Noise

3

VAE를 간결한 도식으로 표현하면 우측과 같다

16 of 46

시작하기 전에 알아야할것들

  • Auto-Encoder (AE)
  • Evidence Lower Bound (ELBO)
  • Variational Auto-Encoder (VAE)
  • Hierarchical VAE

Luo, C. (2022). Understanding diffusion models: A unified perspective. arXiv preprint arXiv:2208.11970.

Reconstruction Loss

KL Divergence with Gaussian Noise

3

VAE를 간결한 도식으로 표현하면 우측과 같다

17 of 46

시작하기 전에 알아야할것들

  • Auto-Encoder (AE)
  • Evidence Lower Bound (ELBO)
  • Variational Auto-Encoder (VAE)
  • Hierarchical VAE

Luo, C. (2022). Understanding diffusion models: A unified perspective. arXiv preprint arXiv:2208.11970.

VAE를 여러 번 중첩하면 어떨까?

VAE와 Diffusion Model의 중간 단계라고 생각할 수 있다

이것도 가능할 거 같긴한데… 학습이 가능한 구조인가?

이렇게 애매할 때는 뭐다?

3

18 of 46

시작하기 전에 알아야할것들

  • Auto-Encoder (AE)
  • Evidence Lower Bound (ELBO)
  • Variational Auto-Encoder (VAE)
  • Hierarchical VAE

Luo, C. (2022). Understanding diffusion models: A unified perspective. arXiv preprint arXiv:2208.11970.

markov property를 활용해 Hierarchical VAE에서도 ELBO를 찾을 수 있다

2

ELBO

19 of 46

시작하기 전에 알아야할것들

  • Auto-Encoder (AE)
  • Evidence Lower Bound (ELBO)
  • Variational Auto-Encoder (VAE)
  • Hierarchical VAE

Luo, C. (2022). Understanding diffusion models: A unified perspective. arXiv preprint arXiv:2208.11970.

그리고 ELBO를 잘 쪼개면 Loss term들을 찾을 수 있다

2

20 of 46

시작하기 전에 알아야할것들

  • Auto-Encoder (AE)
  • Evidence Lower Bound (ELBO)
  • Variational Auto-Encoder (VAE)
  • Hierarchical VAE

Luo, C. (2022). Understanding diffusion models: A unified perspective. arXiv preprint arXiv:2208.11970.

3

reconstruction term은 VAE와 동일

prior matching term은 학습할 파라미터가 없음

consistency term은 markov property를 활용했기 때문에 각 스텝에서 latent code들이 gaussian noise와 같도록 학습 시키는 것과 같다

21 of 46

시작하기 전에 알아야할것들

  • Auto-Encoder (AE)
  • Evidence Lower Bound (ELBO)
  • Variational Auto-Encoder (VAE)
  • Hierarchical VAE

Luo, C. (2022). Understanding diffusion models: A unified perspective. arXiv preprint arXiv:2208.11970.

3

reconstruction term은 VAE와 동일

prior matching term은 학습할 파라미터가 없음

consistency term은 markov property를 활용했기 때문에 각 스텝에서 latent code들이 gaussian noise와 같도록 학습 시키는 것과 같다

Variational Diffusion Model과 동일한 Loss Term

22 of 46

Variational Diffusion Models

  • Hierarchical VAE에 몇 가지 변형만 더 하면 Variational Diffusion Model이 된다
    • latent dimension이 data dimension과 동일함
    • 각 스텝에서 따로 학습된 encoder 없이 linear gaussian model로 가정�→ Gaussian Noise를 Image로 Linear Translation == 쉽게 말해 더한다는 이야기
    • 따라서 마지막 timestep T에는 standard gaussian model (mean = 0, var = 1)이 된다

3

Luo, C. (2022). Understanding diffusion models: A unified perspective. arXiv preprint arXiv:2208.11970.

23 of 46

Variational Diffusion Models

  • Hierarchical VAE에 몇 가지 변형만 더 하면 Variational Diffusion Model이 된다
    • latent dimension이 data dimension과 동일함
    • 각 스텝에서 따로 학습된 encoder 없이 linear gaussian model로 가정�→ Gaussian Noise를 Image로 Linear Translation == 쉽게 말해 더한다는 이야기
    • 따라서 마지막 timestep T에는 standard gaussian model (mean = 0, var = 1)이 된다

3

Luo, C. (2022). Understanding diffusion models: A unified perspective. arXiv preprint arXiv:2208.11970.

Fixed stochastic encoder인 것

24 of 46

Variational Diffusion Models

  • Hierarchical VAE에 몇 가지 변형만 더 하면 Variational Diffusion Model이 된다
    • latent dimension이 data dimension과 동일함
    • 각 스텝에서 따로 학습된 encoder 없이 linear gaussian model로 가정�→ Gaussian Noise를 Image로 Linear Translation == 쉽게 말해 더한다는 이야기
    • 따라서 마지막 timestep T에는 standard gaussian model (mean = 0, var = 1)이 된다

3

Luo, C. (2022). Understanding diffusion models: A unified perspective. arXiv preprint arXiv:2208.11970.

원래는 그냥 gaussian distribution

25 of 46

Variational Diffusion Models

  • 마찬가지로 ELBO를 구하고 Loss Term을 구하기

Luo, C. (2022). Understanding diffusion models: A unified perspective. arXiv preprint arXiv:2208.11970.

2

ELBO

Loss term

26 of 46

Variational Diffusion Models

  • 마찬가지로 ELBO를 구하고 Loss Term을 구하기

Luo, C. (2022). Understanding diffusion models: A unified perspective. arXiv preprint arXiv:2208.11970.

2

ELBO

Loss term

뒤에 나올 논문인 DDPM의 시작 수식과 동일

negative log likelihood인 것 빼고

27 of 46

Q & A Time

  • Auto-Encoder (AE)
  • Evidence Lower Bound (ELBO)
  • Variational Auto-Encoder (VAE)
  • Hierarchical VAE
  • Variational Diffusion Model

28 of 46

Denoising Diffusion Probabilistic Models

  • Variational Diffusion Models의 학습을 Simple하게 만드는 과정에서 Denoising과의 연결점을 찾아냄
  • [1] Inductive bias for model convergence
  • [2] Loss simplification
  • 처음으로 ‘Denoising’과의 연관성을 제시, Diffusion Model에 이목을 집중시킨 첫 논문

Ho, J., Jain, A., & Abbeel, P. (2020). Denoising diffusion probabilistic models. Advances in Neural Information Processing Systems, 33, 6840-6851.

3

29 of 46

Denoising Diffusion Probabilistic Models

  • Variational Diffusion Models의 학습을 Simple하게 만드는 과정에서 Denoising과의 연결점을 찾아냄
  • [1] Inductive bias for model convergence
  • [1-1] Noise prediction for residual estimation
  • [1-2] 불필요한 hyper-parameter 제거: Beta scheduling을 고정 == More fixed encoder

PR-409: Denoising Diffusion Probabilistic Models, https://youtu.be/1j0W_lu55nc

Low information

High entropy

High information

Low entropy

Image

Noise

3

정보가 거의 없는 Noise에 가까운 Latent Code를 Denoise하기 쉬워지는 것

30 of 46

Denoising Diffusion Probabilistic Models

  • Variational Diffusion Models의 학습을 Simple하게 만드는 과정에서 Denoising과의 연결점을 찾아냄
  • [1] Inductive bias for model convergence
  • [1-1] Noise prediction for residual estimation
  • [1-2] 불필요한 hyper-parameter 제거: Beta scheduling을 고정 == More fixed encoder

Ho, J., Jain, A., & Abbeel, P. (2020). Denoising diffusion probabilistic models. Advances in Neural Information Processing Systems, 33, 6840-6851.

3

31 of 46

Denoising Diffusion Probabilistic Models

  • Variational Diffusion Models의 학습을 Simple하게 만드는 과정에서 Denoising과의 연결점을 찾아냄
  • [2] Loss simplification

Ho, J., Jain, A., & Abbeel, P. (2020). Denoising diffusion probabilistic models. Advances in Neural Information Processing Systems, 33, 6840-6851.

2

Apply noise reparametrization

(+) 식 12를 보면 langevin dynamics와 완전히 동일

(+) diffusion model의 variational bound는 denoising score matching으로도 해석할 수 있다는 뜻

Fixed beta scheduling과 Fixed variance 덕분에

L_T, L_0에서는 배울게 없음

input

output

gt

32 of 46

Denoising Diffusion Probabilistic Models

  • Final method

Ho, J., Jain, A., & Abbeel, P. (2020). Denoising diffusion probabilistic models. Advances in Neural Information Processing Systems, 33, 6840-6851.

input

output

gt

3

diffusion

timestamp

t

(T ~ 0)

Noised coordinate sequence

at diffusion time t

Output

GT

Noise

Denoising Diffusion Decoder

MSE

33 of 46

Denoising Diffusion Probabilistic Models

  • Quantitative Results
  • Table 1: SOTA GAN과 비슷한 성능
  • Table 2: Ablation study for [1-1] Noise prediction

Ho, J., Jain, A., & Abbeel, P. (2020). Denoising diffusion probabilistic models. Advances in Neural Information Processing Systems, 33, 6840-6851.

3

34 of 46

Denoising Diffusion Probabilistic Models

  • Figure 5, Figure 6: What happens on progressive generation?
  • Figure 7: Conditional generation
  • Figure 8: Image interpolation

Ho, J., Jain, A., & Abbeel, P. (2020). Denoising diffusion probabilistic models. Advances in Neural Information Processing Systems, 33, 6840-6851.

3

35 of 46

Denoising Diffusion Probabilistic Models

  • Figure 5, Figure 6: What happens on progressive generation?
  • Figure 7: Conditional generation
  • Figure 8: Image interpolation
  • 재밌는 부분 중 하나는 Inference에서 non-deterministic한 부분이 있음에도 불구하고 reconstruction이 잘 된다는 것
  • 특정 data sample에서 forward process를 밟았을 때 도달하는 latent code는 ‘거의 동일한’ data sample에 매칭된다 → 어느 정도 deterministic하다 → 이런 부분을 활용할 수는 없을까?

Ho, J., Jain, A., & Abbeel, P. (2020). Denoising diffusion probabilistic models. Advances in Neural Information Processing Systems, 33, 6840-6851.

3

36 of 46

Denoising Diffusion Implicit Models

  • DDPM으로 학습시킨 모델이 사실 non-markovian property를 가지고 있다면 굳이 1000번 다 step을 밟아야할까?
  • 또한 GAN과 같이 implicit하게 deterministic generative model을 가지고 있는 것으로 생각할 수 있다

Song, J., Meng, C., & Ermon, S. (2021). Denoising diffusion implicit models. ICLR.

3

37 of 46

Denoising Diffusion Implicit Models

  • DDPM 모델이 왼쪽처럼 거의 deterministic할 수 있는 이유는, 전체 diffusion timestamp를 (x_1 ~ x_T) 학습하는 게 아니라, marginals에 (x_t) 대해서만 학습하기 때문이다
  • 이런 marginal한 관측의 결과로 reverse process (denoising)이 x_t뿐 아니라 x_0에도 dependent
  • Appendix A에 상세한 증명이 있습니다

3

diffusion

timestamp

t

(T ~ 0)

Noised coordinate sequence

at diffusion time t

Output

GT

Noise

Denoising Diffusion Decoder

MSE

38 of 46

Denoising Diffusion Implicit Models

  • 방금 전의 직관을 받아들이고 간다면 forward process를 아래와 같이 non-markovian으로 정의할 수 있다

Song, J., Meng, C., & Ermon, S. (2021). Denoising diffusion implicit models. ICLR.

3

아래의 기존의 식과 다르게 non-markovian

39 of 46

Denoising Diffusion Implicit Models

  • 방금 전의 직관을 받아들이고 간다면 forward process를 아래와 같이 non-markovian으로 정의할 수 있다

Song, J., Meng, C., & Ermon, S. (2021). Denoising diffusion implicit models. ICLR.

3

여기서 sigma가 얼마나�x_0를 활용해 deterministic해질 건지

x_t를 활용해 stocastci할건지

조절할 수 있게 된다

40 of 46

Denoising Diffusion Implicit Models

  • 이를 활용해 몇몇 예외처리를 하면 (Section 3.2), DDPM과 똑같은 학습 목표를 얻게 된다

Song, J., Meng, C., & Ermon, S. (2021). Denoising diffusion implicit models. ICLR.

3

41 of 46

Denoising Diffusion Implicit Models

  • 결과 1: Sampling 과정에서의 deterministic함을 조절할 수 있다 (Section 4.1)
  • signal = 0일 때, 우리의 모델은 deterministic하며, 즉 generative process다

Song, J., Meng, C., & Ermon, S. (2021). Denoising diffusion implicit models. ICLR.

3

42 of 46

Denoising Diffusion Implicit Models

  • 결과 1: Sampling 과정에서의 deterministic함을 조절할 수 있다 (Section 4.1)
  • signal = 0일 때, 우리의 모델은 deterministic하며, 즉 generative process다
  • 결과 2: training step보다 더 적은 inference step을 가져가도 된다 (Section 4.2, Appendix C)

Song, J., Meng, C., & Ermon, S. (2021). Denoising diffusion implicit models. ICLR.

3

더 많은/dense한 step을 트레이닝 시키고 있다면

inference때는 subset diffusion step만 활용해도 된다

43 of 46

Denoising Diffusion Implicit Models

  • Experiments
  • Table 1: step size S와 deterministic한 정도 mu에 따른 FID 비교
  • Figure 3: 정성 결과

Song, J., Meng, C., & Ermon, S. (2021). Denoising diffusion implicit models. ICLR.

3

44 of 46

Denoising Diffusion Implicit Models

  • Experiments
  • Table 2: Reconstruction 결과
  • Figure 6: Interpolation 결과; DDPM 대비 더 semantic한 결과

Song, J., Meng, C., & Ermon, S. (2021). Denoising diffusion implicit models. ICLR.

3

45 of 46

Q & A Time

  • Denoising diffusion probabilistic models (DDPM)
  • Denoising Diffusion Implicit Models (DDIM)

46 of 46

More things

There are connections with energy-based model, score-based generative model

The real power of diffusion model comes from guidance (classifire guidance, classifier-free guidance, CLIP guidance, …)

왼쪽의 특성과 합쳐져서, unsupervised generation을 위한 probability mass를 해치지 않고,

오히려 도움이 되는 방향으로 condition에 대한 joint distribution을 학습할 수 있습니다.

Guidance: a cheat code for diffusion models, https://benanne.github.io/2022/05/26/guidance.html

홍윤표 님의 발표에서 다뤄질 예정입니다

Luo, C. (2022). Understanding diffusion models: A unified perspective. arXiv preprint arXiv:2208.11970.

Generative Modeling by Estimating Gradients of the Data Distribution, https://yang-song.net/blog/2021/score/

심현보, 강효림 님의 발표에서 다뤄질 예정입니다