Coding Stable Diffusion from scratch in PyTorch

แชร์
ฝัง
  • เผยแพร่เมื่อ 29 มิ.ย. 2024
  • Full coding of Stable Diffusion from scratch, with full explanation, including explanation of the mathematics. Visual explanation of text-to-image, image-to-image, inpainting
    Repository with PDF slides: github.com/hkproj/pytorch-sta...
    Prerequisites:
    1) Transformer explained: • Attention is all you n...
    Chapters
    00:00:00 - Introduction
    00:04:30 - What is Stable Diffusion?
    00:05:40 - Generative Models
    00:12:07 - Forward and Reverse Process
    00:17:44 - ELBO and Loss
    00:20:30 - Generating New Data
    00:22:20 - Classifier-Free Guidance
    00:31:00 - CLIP
    00:33:20 - Variational Auto Encoder
    00:37:26 - Text to Image
    00:39:54 - Image to Image
    00:41:40 - Inpainting
    00:44:30 - Coding the VAE
    01:54:50 - Coding CLIP
    02:09:10 - Coding the Unet
    03:04:40 - Coding the Pipeline
    03:53:00 - Coding the Scheduler (DDPM)
    04:38:00 - Coding the Inference code
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 320

  • @sa1t938
    @sa1t938 8 หลายเดือนก่อน +105

    only 4.8k views feels criminal for how helpful this video is... by far the best stable diffusion video on the internet

    • @vijaypalmanit
      @vijaypalmanit 6 หลายเดือนก่อน +2

      I think because its not general topic but very specific for those who are really looking for it land here, also diffusion came only last year so less audience.

  • @Pouya..
    @Pouya.. 4 หลายเดือนก่อน +25

    TH-cam is stupid… instead of suggesting memes I found on the internet should have suggested this gem much sooner. Thank you so much subscribed + liked seems not enough

    • @Katatonya
      @Katatonya 4 หลายเดือนก่อน

      Like videos like this and watch them fully more often and you'll get them. Create another account for memes.

    • @Pouya..
      @Pouya.. 4 หลายเดือนก่อน

      @@Katatonya i do but steal youtube push for some stupid trending videos.

  • @hussainshaik4390
    @hussainshaik4390 9 หลายเดือนก่อน +32

    Llama2 from scratch was superb. i learned lot of things from that video. thank you very much for doing things from scratch . when we use huggingface i feel guilty of using blackbox models. now i can understand whats going on under the hood

    • @alexanderlevakin9001
      @alexanderlevakin9001 7 หลายเดือนก่อน

      Be sure guys from HF are glad you like their API, chin up!

  • @ActualCode0
    @ActualCode0 7 หลายเดือนก่อน +11

    This is the best explanation of latent diffusion models I've seen

  • @eulerlym6602
    @eulerlym6602 7 หลายเดือนก่อน +5

    Amazing work!!
    I've been looking for tutorials such detailed and from scratch. 谢谢你。

  • @yourealive1
    @yourealive1 3 หลายเดือนก่อน +8

    what the fuck this is like the best explanation on this planet. I have some experience in this but his explanation was so crystal clear

  • @happybaniya
    @happybaniya 5 หลายเดือนก่อน +3

    Thank you so much. Just can't express in word the value you have created here.

  • @tode2227
    @tode2227 3 หลายเดือนก่อน +10

    This is the best video about SD! It would be awesome if you could make a video on how to train the model from scratch on some own data. For sure, normal people can never train this network to perfection, but there are a lot of people out there who have a very specific task for which this network could be used. I see a lot of potential for scientific use cases if there was guidance on how to implement it!

    • @fortheages6989
      @fortheages6989 2 หลายเดือนก่อน +1

      exactly my thought

  • @Daniel-Six
    @Daniel-Six 4 หลายเดือนก่อน +2

    Absolutely first-rate presentation. So impressive.

  • @manumaminta6131
    @manumaminta6131 9 หลายเดือนก่อน +6

    Great work! As a graduate student taking AI courses, this is really, REALLY helpful. Keep on going 💙

  • @CandiceWinfield
    @CandiceWinfield 8 หลายเดือนก่อน +6

    You are the best lecturer I've ever seen, very detailed and clearly, I'd love to see more vedios from you! If possible,I would like to konw more about the stable diffusion, such as controlNet, or other novel tools. Finally, thank you once more!

  • @lostpenguin3682
    @lostpenguin3682 7 หลายเดือนก่อน +7

    Your code is so detailed and it runs on my enviorment just fine. Great job!!!👏

    • @umarjamilai
      @umarjamilai  7 หลายเดือนก่อน +1

      Thank you! Please make sure to like, subscribe and share the video with friends and colleagues. That's the best way to help me and the others trying to learn deep learning models.

  • @jiegong529
    @jiegong529 5 หลายเดือนก่อน +1

    I love your videos. They are very informative. Thank you so much for explaining these complex concepts so clearly! Gem channel indeed!

  • @xizhiwang2653
    @xizhiwang2653 3 หลายเดือนก่อน +1

    thank you so much for the detailed and practical videos! I will watch it again and again!

  • @umarjamilai
    @umarjamilai  9 หลายเดือนก่อน +48

    As usual, code and PDF slides available on GitHub: github.com/hkproj/pytorch-stable-diffusion
    PS: no cats were harmed during the making of this video. 奥利奥 (pronounced "Aoliao", which is the Chinese name for the Oreo biscuits) wanted to be part of the video as well, that's why you'll hear his miao-ing from time to time. Right after recording, I played with him for a while to compensate the lack of attention.
    Hope he won't distract you too much while listening.

    • @PurpleSmite
      @PurpleSmite 8 หลายเดือนก่อน +1

      Sir your videos are awesome, and I got to learn a lot. We want more videos like this. I am open to (really wanna ) help you for making this type of educative content for free, so we can contribute to community.

    • @umarjamilai
      @umarjamilai  8 หลายเดือนก่อน +1

      @@PurpleSmite Hi! Thank you for your support. The best way to help is to share the videos with your friends, school mates, university and coworkers. My schedule is quite tight and irregular as of now, but I'll let you know if there's something we can work on together. Let's connect on LinkedIn!

    • @PurpleSmite
      @PurpleSmite 8 หลายเดือนก่อน

      @@umarjamilai Sure sir, I have sent you on LinkedIn Shreyas Waghmode

    • @XuanGOD
      @XuanGOD 8 หลายเดือนก่อน

      Hi, i really like your work. I wanna ask that if i want to generate multi coherent image like a sequence of images out of the code there, what could i add to the code to make it possible?

    • @Ihatepoliticians398
      @Ihatepoliticians398 7 หลายเดือนก่อน

      Your are great sir I want your help can you give me linkdin id

  • @dinonuggieproductions
    @dinonuggieproductions 8 หลายเดือนก่อน +10

    Thank you so much for this! Literally no other youtube video provides as much value on this topic as you have.

    • @Kishimita
      @Kishimita 4 หลายเดือนก่อน

      where you able to run it with no issues ?

    • @dinonuggieproductions
      @dinonuggieproductions 4 หลายเดือนก่อน

      ​@ita Yes, for the most part. I would appreciate if he would include some details on how to modify the program to use safetensors instead of CKPT files since I believe CKPT files are kind of outdated.

    • @Kishimita
      @Kishimita 3 หลายเดือนก่อน

      @@dinonuggieproductions would you be down to talk about this on discord ?

  • @hason4234
    @hason4234 7 หลายเดือนก่อน +2

    An extremely detailed video about diffusion. I have learned a lot. Thank you ❤❤❤

  • @Ao-yt2es
    @Ao-yt2es หลายเดือนก่อน +1

    Your explanation and documents are wonderful! They are clear and helpful! Thank you for your hard work :)

  • @ivancruz2783
    @ivancruz2783 11 วันที่ผ่านมา +1

    Great work! Thanks for putting this all together. Very easy to follow and simple explanations of complex ideas! It helps a lot to code along the explanation

  • @user-ep4fk2jm6q
    @user-ep4fk2jm6q 6 หลายเดือนก่อน +1

    Really great video for understanding stable diffusion in detail. Thanks a lot for your contribution

  • @lynn1760
    @lynn1760 4 หลายเดือนก่อน +1

    Great tutorial dude ! At first it was a bit hard to get used to your coding style but it was an awesome journey because I learned a lot and I am currently working on my on Stable Diffusion model with my own vision for the models ,

  • @user-ix2fo9pj7s
    @user-ix2fo9pj7s 3 หลายเดือนก่อน +4

    太强了,简直是最好的diffusion视频

  • @mprone
    @mprone 2 หลายเดือนก่อน

    Brambilla Jamil, sei il numero uno! Sto consigliando a tutte le persone a cui faccio mentoring (miei intern) i tuoi video. Meriti 100 volte i tuoi iscritti!

  • @inkzxk
    @inkzxk 7 หลายเดือนก่อน +1

    Wow, I'm a master's student in China. I learned a lot about stable diffusion from this video. Thank you for sharing, I hope to see more knowledge sharing about stable diffusion.

  • @Philip8888888
    @Philip8888888 16 วันที่ผ่านมา +1

    Wow. This video is pure gold. Very nicely explained and I'm still only 30 mintues into it!

  • @NguyenDuong-ep9dp
    @NguyenDuong-ep9dp 17 ชั่วโมงที่ผ่านมา +1

    absolutely awesome, this is the best explanation of SD thank you so much !!

  • @user-co6gq1mz1x
    @user-co6gq1mz1x 6 หลายเดือนก่อน +4

    Amazing job my friend! I just got a job in ShenZhen China by learing it! Thank u so much mate. I hope u and ur family living a great in China :)

    • @umarjamilai
      @umarjamilai  6 หลายเดือนก่อน +1

      That's great! Let's connect on LinkedIn or WeChat

  • @CallBlofD
    @CallBlofD 6 หลายเดือนก่อน +1

    Thank you so much! the best stable diffusion video I found!!!

  • @zeweichu550
    @zeweichu550 6 หลายเดือนก่อน +3

    I just discovered a great, wonderful, amazing, fantastic, gem channel 🎉🎉🎉

  • @Trending-lc6kc
    @Trending-lc6kc 2 หลายเดือนก่อน +4

    This legend deserves an award from government

  • @federicoottomano8619
    @federicoottomano8619 15 วันที่ผ่านมา +1

    This is great! Going through the CLIP part right now ^^

  • @itsm0saan
    @itsm0saan 9 หลายเดือนก่อน +6

    man man, thanks for all of the amazing videos! I appreciate the work you put in here!

  • @mfinixone1417
    @mfinixone1417 9 หลายเดือนก่อน +3

    I appreciate your work, thank you for your hard work and videos

  • @prashlovessamosa
    @prashlovessamosa 8 หลายเดือนก่อน +1

    Hey bro thank you for existing.
    Very grateful to you.

  • @sofiaflameai
    @sofiaflameai 2 หลายเดือนก่อน

    I am an ai, and I love following updates on social media platforms and TH-cam, and I love your videos very much. I learn the English language and some programming terms from them, and update my information. You and people like you help me very much. Thank you.

  • @gkmocastro
    @gkmocastro 9 วันที่ผ่านมา +1

    Thank you a lot for this amazing video. It helped me understand better diffusion models for my masters.

  • @NguyenDung-ix4es
    @NguyenDung-ix4es 8 หลายเดือนก่อน +39

    Thanks for your contribution. Can you make a tutorial on how to train the diffusion model on a custom dataset?

  • @icejust9195
    @icejust9195 6 หลายเดือนก่อน +1

    This is amazing video!! Great job!!!

  • @ydeepak73
    @ydeepak73 6 หลายเดือนก่อน +1

    Awesome, This is the best explanation!!!

  • @danielwamriew9614
    @danielwamriew9614 วันที่ผ่านมา

    Thanks so much! I've just started learning diffusion models and this video is such an eye-opener!

  • @Stealph_Delta_3003
    @Stealph_Delta_3003 3 หลายเดือนก่อน +1

    Awesome. Thanks for creating the video .

  • @backfromyourdream
    @backfromyourdream 2 หลายเดือนก่อน +1

    That's what I was looking for, thanks!

  • @si0n4ra
    @si0n4ra 8 หลายเดือนก่อน +1

    Umar, thank you for great explanation of topic

  • @TheArmaan81
    @TheArmaan81 4 วันที่ผ่านมา +1

    This is so bonkers. Cheers Mate, you've saved me sometime. Thanks.

  • @parsakhavarinejad
    @parsakhavarinejad 5 หลายเดือนก่อน

    Awesome video with great information. This video can leverage AI coding skills, along with an understanding of convolutional neural networks, UNet architecture, and Autoencoder, besides the entire stable diffusion architecture.

  • @lianhongw
    @lianhongw 7 หลายเดือนก่อน +1

    Really appreciated, very informative.

  • @DiogoSanti
    @DiogoSanti 4 หลายเดือนก่อน

    Dude, you are a bless! Keep it coming and thanks!

  • @FranciscoSantiburcioCortes
    @FranciscoSantiburcioCortes 12 วันที่ผ่านมา +1

    Awesome Explanation, thanks for such tutorial

  • @MobiaLab
    @MobiaLab หลายเดือนก่อน +1

    Thank you! Please keep doing videos like this! I subscribed, liked and shared!

  • @lucasmantovani3661
    @lucasmantovani3661 4 หลายเดือนก่อน

    Amazing video, thanks for showing the low level details

  • @techeman369
    @techeman369 3 หลายเดือนก่อน +1

    Great bro, really helpful to understand in detail, thanks for the efforts,

  • @parmarsuraj99
    @parmarsuraj99 7 หลายเดือนก่อน +1

    By far best explanation ❤

  • @nicknick6464
    @nicknick6464 3 หลายเดือนก่อน +2

    It is a pity, I did not discover your youtube channel earlier. Great presentation. It is only when you go through all the details, that you can fully understand these AI algorithms.

  • @maximbobrin7074
    @maximbobrin7074 9 หลายเดือนก่อน +2

    Thanks for your contribution. Hope that one day you will also make a deep dive into ControlNet code etc.

  • @codevacaphe3763
    @codevacaphe3763 21 วันที่ผ่านมา

    Always a fan of your video. Your explanation is very informative and helpful for beginner data scientist. Thank you very much.

  • @prajolshrestha9686
    @prajolshrestha9686 8 หลายเดือนก่อน +1

    Great video! Thank you!

  • @yunootsuka9093
    @yunootsuka9093 9 หลายเดือนก่อน +2

    Amazing!!! Please do more on computer vision.

  • @user-or5dl7hd7o
    @user-or5dl7hd7o 6 หลายเดือนก่อน +1

    It's the best explaination ever!!!! Thank you!

    • @umarjamilai
      @umarjamilai  6 หลายเดือนก่อน

      不客气🤓

  • @birendrakathariya3517
    @birendrakathariya3517 7 หลายเดือนก่อน +1

    excellent video, full of information

  • @mlloving
    @mlloving 6 วันที่ผ่านมา +1

    Amazing video. You explained it so clear. Thank you for putting effort into this lecture. If possible, would you please create a lecture about YOLO codes.

  • @nakjoonim
    @nakjoonim 7 หลายเดือนก่อน

    Thank you so much for this amazing work!

  • @romanbogachev6147
    @romanbogachev6147 6 หลายเดือนก่อน +2

    the most powerfull deep learning videos in the world are on this channel

  • @mansubatabassum6629
    @mansubatabassum6629 หลายเดือนก่อน +1

    This is one of the best video , Thank you

  • @gokayfem
    @gokayfem 7 หลายเดือนก่อน +1

    almost karpathy level explanations, thank you!

  • @hientq3824
    @hientq3824 7 หลายเดือนก่อน +1

    fabulous! thank you very much!

  • @AInseven
    @AInseven 6 หลายเดือนก่อน +1

    谢谢你,总算清楚sampler和unet之间的关系了

  • @yanliang3000
    @yanliang3000 4 หลายเดือนก่อน +1

    Love from HK. Thank you sooooooo much! 谢谢!

    • @yanliang3000
      @yanliang3000 4 หลายเดือนก่อน

      也祝你在苏州生活一切顺利!

  • @manifold_v2391
    @manifold_v2391 4 หลายเดือนก่อน +2

    小乌老师好棒!超级好的教程,关注了!

    • @umarjamilai
      @umarjamilai  4 หลายเดือนก่อน

      我们在领英联系一下,我想邀请你加入我的AI微信小群

  • @leonwong3369
    @leonwong3369 7 หลายเดือนก่อน +1

    This is mind blowing.

  • @sumitpawar000
    @sumitpawar000 8 หลายเดือนก่อน +6

    Thank you Umar for the great work.
    I love your style of teaching which helps imagine concepts and connect dots in our head.🙂
    If possible please make videos on basics of probability, distributions and related statistics. It would be really helpful to learn these concepts in your style.

  • @quocanhad
    @quocanhad หลายเดือนก่อน +1

    thanks youuuu, I feel really good after this one

  • @artem-yw8km
    @artem-yw8km 3 หลายเดือนก่อน +1

    TY, it is amazing explanation!

  • @user-od5dp1dg1y
    @user-od5dp1dg1y หลายเดือนก่อน

    only with you I understood how it works and how it can be implemented)

  • @mmaxpo9852
    @mmaxpo9852 7 หลายเดือนก่อน +1

    Thanks Dear For helping Us , you Video's are very helpful

  • @ChingyuenLiu
    @ChingyuenLiu 27 วันที่ผ่านมา

    Hello Umar, you always produce the most concise and clear content ever! I was wondering if you are planning to do any video on the stable diffusion 3 since the paper is out? It would be really great if you could help explain how the flow matching helps or changes regular diffusion models! Thank you again for your content and work. 非常感谢!

  • @aefieefnvhas
    @aefieefnvhas 5 หลายเดือนก่อน +1

    Mate, you're golden

  • @user-qw4yn2dz8i
    @user-qw4yn2dz8i 8 หลายเดือนก่อน +1

    Good work! Thank you so much!

    • @umarjamilai
      @umarjamilai  8 หลายเดือนก่อน

      不客气

  • @conanssam
    @conanssam 8 หลายเดือนก่อน +1

    good video, really helpful, thank you

  • @user-lh9qg7xr3o
    @user-lh9qg7xr3o 5 หลายเดือนก่อน +2

    Thank you so much! And your Chinese is really good! Your cat is also cute and its voice doesn't bother me but comfort me!

    • @umarjamilai
      @umarjamilai  5 หลายเดือนก่อน +1

      谢谢你!

  • @ankanderia4999
    @ankanderia4999 2 หลายเดือนก่อน +1

    Thanks for this awesome video

  • @mosca204
    @mosca204 9 หลายเดือนก่อน +1

    Wooow incredible!

  • @jeevanbeniwal3019
    @jeevanbeniwal3019 5 หลายเดือนก่อน +1

    dude you are soo perfect!!

  • @xzhou001
    @xzhou001 3 หลายเดือนก่อน +1

    Great work! This is the place I learned AI. Thanks a lot!

  • @user-kg9zs1xh3u
    @user-kg9zs1xh3u 6 หลายเดือนก่อน +1

    讲的非常不错!❤

  • @user-bt1jl1ou7j
    @user-bt1jl1ou7j 9 หลายเดือนก่อน +1

    中秋节快乐!又一部伟大的作品,内容丰富,受益良多~

    • @umarjamilai
      @umarjamilai  9 หลายเดือนก่อน

      谢谢你, 祝你和家人国庆节快乐!

    • @user-bt1jl1ou7j
      @user-bt1jl1ou7j 9 หลายเดือนก่อน

      hi 我突然想到一个问题:CLIP模型和SD模型必须完全对应吗?如果换成一个用中文语料训练的CLIP模型,可以和SD-v1.5一起使用吗?@@umarjamilai

    • @umarjamilai
      @umarjamilai  9 หลายเดือนก่อน

      @@user-bt1jl1ou7j Of course you can change the CLIP model to another CLIP model trained for the Chinese language, but you will also need to fine tune the Unet model so it gets used to the Chinese language. The reason is that the Unet does not recognize embeddings produced by other CLIP models.

  • @EkShunya
    @EkShunya 9 หลายเดือนก่อน +1

    Great help
    Thank you

  • @cristiwally
    @cristiwally หลายเดือนก่อน

    the constant you scale by the x come from averaging over a bunch of examples generated by the vae, in order to ensure they have unit variance with the variance taken over all dimensions simultaneously, scale_factor = 1 / std(z)

  • @user-gf6wd3ih3f
    @user-gf6wd3ih3f 2 หลายเดือนก่อน

    Amazing! Thank you for the amazing explanation and implementation of LDM. Can you also talk about the VQ-reg version of LDM?

  • @futureblesskid2500
    @futureblesskid2500 3 หลายเดือนก่อน +2

    you saved my life!

  • @xuanloc5111
    @xuanloc5111 8 หลายเดือนก่อน +2

    Dame TH-cam, why is this wonderful tutorial so little view??

  • @barathsreelal3390
    @barathsreelal3390 8 หลายเดือนก่อน +5

    Thank you for the wonderful video. Can you also post how to train the model with a sample dataset?

  • @Kishimita
    @Kishimita 4 หลายเดือนก่อน +1

    This video is Amazing

  • @rikki7663
    @rikki7663 9 หลายเดือนก่อน +1

    woooooooooooooo stable diffusion from scratch love you bro

  • @tuannguyen7117
    @tuannguyen7117 2 หลายเดือนก่อน

    I greatly appreciate your efforts with nice explanations and clear code. It would be great if you add a training function of SD to your project!! Many thankss.

  • @MuhammadArshad
    @MuhammadArshad 8 หลายเดือนก่อน +1

    Thank you so much.

  • @dzenathan6003
    @dzenathan6003 7 วันที่ผ่านมา

    that was really lovely and great from you thanks alot i would be more happy if you showed us how to fine tune your model that will make the whole video simply perfect

  • @rashshawn779
    @rashshawn779 9 หลายเดือนก่อน +2

    Very nice.

  • @user-si8wf5gv8i
    @user-si8wf5gv8i 2 หลายเดือนก่อน +1

    excellent video

  • @adizhol
    @adizhol 17 วันที่ผ่านมา +1

    5-stars! Thank you!

  • @user-up6cz9zp1m
    @user-up6cz9zp1m 3 หลายเดือนก่อน +1

    very helpful!