Introduction to Diffusion Models
230103
Sejong Yang
References
NVIDIA에서 발표한 Diffusion Tutorial
어영정 교수님네 학생이 발표한 Diffusion Tutorial
이 세미나에서 얻어가셔야할 것
Improving Diffusion Models as an Alternative To GANs, Part 1, https://developer.nvidia.com/blog/improving-diffusion-models-as-an-alternative-to-gans-part-1/
3
수식에 너무 매몰되지 말자
Diffusion Model 수학이 포함된 tutorial, https://youtu.be/uFoGaIVHfoE
3
[3]이 목적이신 분들은 2일 땐 잠시 쉬어도 좋습니다
시작하기 전에 알아야할것들
Ian Goodfellow et al. (2016) Deep Learning. http://www.deeplearningbook.org
2
시작하기 전에 알아야할것들
까먹으신 분도 이해할 수 있게 노력해보겠습니다
2
오늘의 목적지
3
Diffusion Model 수학이 포함된 tutorial, https://youtu.be/uFoGaIVHfoE
열역학에서 파생된 분자운동 예측
브라운 운동과 확산 (Diffusion)
3
Diffusion Model 수학이 포함된 tutorial, https://youtu.be/uFoGaIVHfoE
열역학이 분자, 양자를 고려하게 되면서
불확실성을 다루는 방법들을 많이 고민
→ 통계학과 확률론의 발전에 지대한 공헌
세상에 쓸데없는 수학은 없고 대부분 이상한 물리학적 난제를 설명하려다가 나오는듯
중세 시대엔 대수학이 그런 역할을 했던듯
→ 머신러닝쟁이, 딥러닝쟁이들이 잘 쓰고 있다
e.g. 힌튼이 제시한 볼츠만 머신
e.g. 홉필드 네트워크; 물리학적 스핀 모델에서 착안
e.g. 오늘 다뤄볼 Diffusion Model
우리 필드에서 차용 가능할만한 수학적 개념을 찾는다면
물리학과의 수리통계학 1, 2 강의 추천합니다
시작하기 전에 알아야할것들
3
Reconstruction Loss
시작하기 전에 알아야할것들
MNIST Dataset in CNN, https://www.javatpoint.com/tensorflow-mnist-dataset-in-cnn
3
그러면 Z에서 P라는 확률분포로 변환해주는 어떤 함수가 있다면
[1] 신경망으로 그 함수를 모사할 수 있을까? → Universal Approximation Theorem
Reconstruction Loss
이미지는 수의 집합
숫자 이미지의 집합은 수의 집합의 집합
숫자 이미지들을 표현하는 모분포가 존재
표본 추출된 데이터셋의 분포 P로 이걸 추론할 수 있다
시작하기 전에 알아야할것들
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로 이걸 추론할 수 있다
시작하기 전에 알아야할것들
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
시작하기 전에 알아야할것들
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
시작하기 전에 알아야할것들
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)
시작하기 전에 알아야할것들
Luo, C. (2022). Understanding diffusion models: A unified perspective. arXiv preprint arXiv:2208.11970.
Reconstruction Loss
KL Divergence with Gaussian Noise
3
VAE를 간결한 도식으로 표현하면 우측과 같다
시작하기 전에 알아야할것들
Luo, C. (2022). Understanding diffusion models: A unified perspective. arXiv preprint arXiv:2208.11970.
Reconstruction Loss
KL Divergence with Gaussian Noise
3
VAE를 간결한 도식으로 표현하면 우측과 같다
시작하기 전에 알아야할것들
Luo, C. (2022). Understanding diffusion models: A unified perspective. arXiv preprint arXiv:2208.11970.
VAE를 여러 번 중첩하면 어떨까?
VAE와 Diffusion Model의 중간 단계라고 생각할 수 있다
이것도 가능할 거 같긴한데… 학습이 가능한 구조인가?
이렇게 애매할 때는 뭐다?
3
시작하기 전에 알아야할것들
Luo, C. (2022). Understanding diffusion models: A unified perspective. arXiv preprint arXiv:2208.11970.
markov property를 활용해 Hierarchical VAE에서도 ELBO를 찾을 수 있다
2
ELBO
시작하기 전에 알아야할것들
Luo, C. (2022). Understanding diffusion models: A unified perspective. arXiv preprint arXiv:2208.11970.
그리고 ELBO를 잘 쪼개면 Loss term들을 찾을 수 있다
2
시작하기 전에 알아야할것들
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와 같도록 학습 시키는 것과 같다
시작하기 전에 알아야할것들
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
Variational Diffusion Models
3
Luo, C. (2022). Understanding diffusion models: A unified perspective. arXiv preprint arXiv:2208.11970.
Variational Diffusion Models
3
Luo, C. (2022). Understanding diffusion models: A unified perspective. arXiv preprint arXiv:2208.11970.
Fixed stochastic encoder인 것
Variational Diffusion Models
3
Luo, C. (2022). Understanding diffusion models: A unified perspective. arXiv preprint arXiv:2208.11970.
원래는 그냥 gaussian distribution
Variational Diffusion Models
Luo, C. (2022). Understanding diffusion models: A unified perspective. arXiv preprint arXiv:2208.11970.
2
ELBO
Loss term
Variational Diffusion Models
Luo, C. (2022). Understanding diffusion models: A unified perspective. arXiv preprint arXiv:2208.11970.
2
ELBO
Loss term
뒤에 나올 논문인 DDPM의 시작 수식과 동일
negative log likelihood인 것 빼고
Q & A Time
Denoising Diffusion Probabilistic Models
Ho, J., Jain, A., & Abbeel, P. (2020). Denoising diffusion probabilistic models. Advances in Neural Information Processing Systems, 33, 6840-6851.
3
Denoising Diffusion Probabilistic Models
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하기 쉬워지는 것
Denoising Diffusion Probabilistic Models
Ho, J., Jain, A., & Abbeel, P. (2020). Denoising diffusion probabilistic models. Advances in Neural Information Processing Systems, 33, 6840-6851.
3
Denoising Diffusion Probabilistic Models
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
Denoising Diffusion Probabilistic Models
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
Denoising Diffusion Probabilistic Models
Ho, J., Jain, A., & Abbeel, P. (2020). Denoising diffusion probabilistic models. Advances in Neural Information Processing Systems, 33, 6840-6851.
3
Denoising Diffusion Probabilistic Models
Ho, J., Jain, A., & Abbeel, P. (2020). Denoising diffusion probabilistic models. Advances in Neural Information Processing Systems, 33, 6840-6851.
3
Denoising Diffusion Probabilistic Models
Ho, J., Jain, A., & Abbeel, P. (2020). Denoising diffusion probabilistic models. Advances in Neural Information Processing Systems, 33, 6840-6851.
3
Denoising Diffusion Implicit Models
Song, J., Meng, C., & Ermon, S. (2021). Denoising diffusion implicit models. ICLR.
3
Denoising Diffusion Implicit Models
Improving Diffusion Models as an Alternative To GANs, Part 2. https://developer.nvidia.com/blog/improving-diffusion-models-as-an-alternative-to-gans-part-2/
3
diffusion
timestamp
t
(T ~ 0)
Noised coordinate sequence
at diffusion time t
Output
GT
Noise
Denoising Diffusion Decoder
MSE
Denoising Diffusion Implicit Models
Song, J., Meng, C., & Ermon, S. (2021). Denoising diffusion implicit models. ICLR.
3
아래의 기존의 식과 다르게 non-markovian
Denoising Diffusion Implicit Models
Song, J., Meng, C., & Ermon, S. (2021). Denoising diffusion implicit models. ICLR.
3
여기서 sigma가 얼마나�x_0를 활용해 deterministic해질 건지
x_t를 활용해 stocastci할건지
조절할 수 있게 된다
Denoising Diffusion Implicit Models
Song, J., Meng, C., & Ermon, S. (2021). Denoising diffusion implicit models. ICLR.
3
Denoising Diffusion Implicit Models
Song, J., Meng, C., & Ermon, S. (2021). Denoising diffusion implicit models. ICLR.
3
Denoising Diffusion Implicit Models
Song, J., Meng, C., & Ermon, S. (2021). Denoising diffusion implicit models. ICLR.
3
더 많은/dense한 step을 트레이닝 시키고 있다면
inference때는 subset diffusion step만 활용해도 된다
Denoising Diffusion Implicit Models
Song, J., Meng, C., & Ermon, S. (2021). Denoising diffusion implicit models. ICLR.
3
Denoising Diffusion Implicit Models
Song, J., Meng, C., & Ermon, S. (2021). Denoising diffusion implicit models. ICLR.
3
Q & A Time
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/
심현보, 강효림 님의 발표에서 다뤄질 예정입니다