Coding Stable Diffusion from scratch in PyTorch

Sdílet
Vložit
  • čas přidán 28. 06. 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
  • Věda a technologie

Komentáře • 319

  • @sa1t938
    @sa1t938 Před 8 měsíci +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 Před 6 měsíci +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.

  • @hussainshaik4390
    @hussainshaik4390 Před 9 měsíci +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

  • @ActualCode0
    @ActualCode0 Před 7 měsíci +11

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

  • @Pouya..
    @Pouya.. Před 4 měsíci +25

    CZcams 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 Před 4 měsíci

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

    • @Pouya..
      @Pouya.. Před 4 měsíci

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

  • @tode2227
    @tode2227 Před 3 měsíci +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!

  • @NguyenDung-ix4es
    @NguyenDung-ix4es Před 8 měsíci +39

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

  • @happybaniya
    @happybaniya Před 5 měsíci +3

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

  • @eulerlym6602
    @eulerlym6602 Před 7 měsíci +5

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

  • @yourealive1
    @yourealive1 Před 3 měsíci +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

  • @CandiceWinfield
    @CandiceWinfield Před 8 měsíci +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!

  • @Daniel-Six
    @Daniel-Six Před 4 měsíci +2

    Absolutely first-rate presentation. So impressive.

  • @lostpenguin3682
    @lostpenguin3682 Před 7 měsíci +7

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

    • @umarjamilai
      @umarjamilai  Před 7 měsíci +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.

  • @manumaminta6131
    @manumaminta6131 Před 9 měsíci +6

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

  • @user-ix2fo9pj7s
    @user-ix2fo9pj7s Před 3 měsíci +4

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

  • @inkzxk
    @inkzxk Před 7 měsíci +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.

  • @dinonuggieproductions
    @dinonuggieproductions Před 8 měsíci +10

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

    • @Kishimita
      @Kishimita Před 4 měsíci

      where you able to run it with no issues ?

    • @dinonuggieproductions
      @dinonuggieproductions Před 4 měsíci

      ​@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 Před 3 měsíci

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

  • @sofiaflameai
    @sofiaflameai Před 2 měsíci

    I am an ai, and I love following updates on social media platforms and CZcams, 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.

  • @jiegong529
    @jiegong529 Před 5 měsíci +1

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

  • @ivancruz2783
    @ivancruz2783 Před 11 dny +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

  • @Ao-yt2es
    @Ao-yt2es Před měsícem +1

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

  • @Philip8888888
    @Philip8888888 Před 16 dny +1

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

  • @xizhiwang2653
    @xizhiwang2653 Před 3 měsíci +1

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

  • @hason4234
    @hason4234 Před 7 měsíci +2

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

  • @zeweichu550
    @zeweichu550 Před 6 měsíci +3

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

  • @Trending-lc6kc
    @Trending-lc6kc Před 2 měsíci +4

    This legend deserves an award from government

  • @danielwamriew9614
    @danielwamriew9614 Před dnem

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

  • @mprone
    @mprone Před 2 měsíci

    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!

  • @federicoottomano8619
    @federicoottomano8619 Před 14 dny +1

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

  • @lynn1760
    @lynn1760 Před 4 měsíci +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 ,

  • @NguyenDuong-ep9dp
    @NguyenDuong-ep9dp Před 7 hodinami +1

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

  • @CallBlofD
    @CallBlofD Před 6 měsíci +1

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

  • @user-ep4fk2jm6q
    @user-ep4fk2jm6q Před 6 měsíci +1

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

  • @mfinixone1417
    @mfinixone1417 Před 9 měsíci +3

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

  • @user-co6gq1mz1x
    @user-co6gq1mz1x Před 6 měsíci +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  Před 6 měsíci +1

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

  • @prashlovessamosa
    @prashlovessamosa Před 8 měsíci +1

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

  • @backfromyourdream
    @backfromyourdream Před 2 měsíci +1

    That's what I was looking for, thanks!

  • @gkmocastro
    @gkmocastro Před 8 dny +1

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

  • @icejust9195
    @icejust9195 Před 6 měsíci +1

    This is amazing video!! Great job!!!

  • @Stealph_Delta_3003
    @Stealph_Delta_3003 Před 3 měsíci +1

    Awesome. Thanks for creating the video .

  • @itsm0saan
    @itsm0saan Před 9 měsíci +6

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

  • @ydeepak73
    @ydeepak73 Před 6 měsíci +1

    Awesome, This is the best explanation!!!

  • @FranciscoSantiburcioCortes

    Awesome Explanation, thanks for such tutorial

  • @umarjamilai
    @umarjamilai  Před 9 měsíci +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 Před 8 měsíci +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  Před 8 měsíci +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 Před 8 měsíci

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

    • @XuanGOD
      @XuanGOD Před 8 měsíci

      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 Před 7 měsíci

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

  • @lianhongw
    @lianhongw Před 7 měsíci +1

    Really appreciated, very informative.

  • @si0n4ra
    @si0n4ra Před 8 měsíci +1

    Umar, thank you for great explanation of topic

  • @TheArmaan81
    @TheArmaan81 Před 4 dny +1

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

  • @parmarsuraj99
    @parmarsuraj99 Před 7 měsíci +1

    By far best explanation ❤

  • @codevacaphe3763
    @codevacaphe3763 Před 20 dny

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

  • @prajolshrestha9686
    @prajolshrestha9686 Před 8 měsíci +1

    Great video! Thank you!

  • @maximbobrin7074
    @maximbobrin7074 Před 9 měsíci +2

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

  • @DiogoSanti
    @DiogoSanti Před 4 měsíci

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

  • @lucasmantovani3661
    @lucasmantovani3661 Před 4 měsíci

    Amazing video, thanks for showing the low level details

  • @techeman369
    @techeman369 Před 3 měsíci +1

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

  • @nicknick6464
    @nicknick6464 Před 3 měsíci +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.

  • @AInseven
    @AInseven Před 6 měsíci +1

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

  • @mlloving
    @mlloving Před 5 dny +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.

  • @parsakhavarinejad
    @parsakhavarinejad Před 5 měsíci

    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.

  • @hientq3824
    @hientq3824 Před 7 měsíci +1

    fabulous! thank you very much!

  • @yunootsuka9093
    @yunootsuka9093 Před 9 měsíci +2

    Amazing!!! Please do more on computer vision.

  • @gokayfem
    @gokayfem Před 7 měsíci +1

    almost karpathy level explanations, thank you!

  • @user-or5dl7hd7o
    @user-or5dl7hd7o Před 6 měsíci +1

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

  • @MobiaLab
    @MobiaLab Před měsícem +1

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

  • @nakjoonim
    @nakjoonim Před 7 měsíci

    Thank you so much for this amazing work!

  • @birendrakathariya3517
    @birendrakathariya3517 Před 7 měsíci +1

    excellent video, full of information

  • @mansubatabassum6629
    @mansubatabassum6629 Před měsícem +1

    This is one of the best video , Thank you

  • @leonwong3369
    @leonwong3369 Před 7 měsíci +1

    This is mind blowing.

  • @romanbogachev6147
    @romanbogachev6147 Před 6 měsíci +2

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

  • @quocanhad
    @quocanhad Před měsícem +1

    thanks youuuu, I feel really good after this one

  • @kastrogerrard2905
    @kastrogerrard2905 Před 7 měsíci

    Great work. I love this so much. Which auto completion tool are you using in VScode btw?

  • @user-od5dp1dg1y
    @user-od5dp1dg1y Před měsícem

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

  • @artem-yw8km
    @artem-yw8km Před 3 měsíci +1

    TY, it is amazing explanation!

  • @barathsreelal3390
    @barathsreelal3390 Před 8 měsíci +5

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

  • @manifold_v2391
    @manifold_v2391 Před 4 měsíci +1

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

    • @umarjamilai
      @umarjamilai  Před 4 měsíci

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

  • @yanliang3000
    @yanliang3000 Před 4 měsíci +1

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

    • @yanliang3000
      @yanliang3000 Před 4 měsíci

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

  • @ChingyuenLiu
    @ChingyuenLiu Před 26 dny

    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. 非常感谢!

  • @ankanderia4999
    @ankanderia4999 Před 2 měsíci +1

    Thanks for this awesome video

  • @aefieefnvhas
    @aefieefnvhas Před 5 měsíci +1

    Mate, you're golden

  • @conanssam
    @conanssam Před 8 měsíci +1

    good video, really helpful, thank you

  • @mmaxpo9852
    @mmaxpo9852 Před 7 měsíci +1

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

  • @sumitpawar000
    @sumitpawar000 Před 8 měsíci +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.

  • @EkShunya
    @EkShunya Před 9 měsíci +1

    Great help
    Thank you

  • @jeevanbeniwal3019
    @jeevanbeniwal3019 Před 5 měsíci +1

    dude you are soo perfect!!

  • @user-qw4yn2dz8i
    @user-qw4yn2dz8i Před 8 měsíci +1

    Good work! Thank you so much!

  • @cristiwally
    @cristiwally Před 29 dny

    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-kg9zs1xh3u
    @user-kg9zs1xh3u Před 6 měsíci +1

    讲的非常不错!❤

  • @giopapas1
    @giopapas1 Před 5 měsíci

    Thank you so much Umar, that's an excellent video session-you combine theory and programming in an excellent way. One quick question, do you have any recommendations how to add a trainer so that the stable diffusion model will be trained/ inferenced in other types of images (medical images)? Also, do you have any suggestions, about how to fine-tune the existing model you present?

  • @mosca204
    @mosca204 Před 9 měsíci +1

    Wooow incredible!

  • @xzhou001
    @xzhou001 Před 3 měsíci +1

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

  • @user-ss3gh7pz8m
    @user-ss3gh7pz8m Před 8 měsíci

    Thank you very much for your video! Could you also review the training part?

  • @user-lh9qg7xr3o
    @user-lh9qg7xr3o Před 5 měsíci +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!

  • @MuhammadArshad
    @MuhammadArshad Před 8 měsíci +1

    Thank you so much.

  • @xuanloc5111
    @xuanloc5111 Před 8 měsíci +2

    Dame CZcams, why is this wonderful tutorial so little view??

  • @dzenathan6003
    @dzenathan6003 Před 7 dny

    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

  • @futureblesskid2500
    @futureblesskid2500 Před 3 měsíci +2

    you saved my life!

  • @rikki7663
    @rikki7663 Před 9 měsíci +1

    woooooooooooooo stable diffusion from scratch love you bro

  • @adizhol
    @adizhol Před 16 dny +1

    5-stars! Thank you!

  • @user-gf6wd3ih3f
    @user-gf6wd3ih3f Před 2 měsíci

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

  • @Kishimita
    @Kishimita Před 4 měsíci +1

    This video is Amazing

  • @signitureDGK
    @signitureDGK Před 5 měsíci

    Really great and informative. What is the difference between DDIM and DDPM models? Also can a UNET architecture be used for audio encoding also? At what layer would the audio be encoded ( assuming its a dense vector from a mel spec)

  • @ViralKiller
    @ViralKiller Před 8 měsíci +1

    instant subscribe