Coding LLaMA 2 from scratch in PyTorch - KV Cache, Grouped Query Attention, Rotary PE, RMSNorm

แชร์
ฝัง
  • เผยแพร่เมื่อ 29 ก.ย. 2024

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

  • @TheMzbac
    @TheMzbac 8 หลายเดือนก่อน +4

    Highly recommended for anyone who wants to understand open source LLM inside and out.

  • @gabchen
    @gabchen ปีที่แล้ว +6

    Haven't watched the full video yet but thanks for the promising content. please keep it going.
    Would like to see more of the environment set up and the debugging process.

  • @ravimandliya1881
    @ravimandliya1881 ปีที่แล้ว +4

    Very excited for this!!! Weekend is going to be fun!

  • @pi5549
    @pi5549 ปีที่แล้ว +15

    Might you consider creating a Discord guild? I'd love to hang with the people that are watching these videos!

    • @umarjamilai
      @umarjamilai  ปีที่แล้ว +7

      Hi! I am considering it, will let you know with a public post when it's online 🤖🦾

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

      Yep, such great people

    • @Umar-Ateeq
      @Umar-Ateeq 3 หลายเดือนก่อน

      Great idea man!!

  • @hussainshaik4390
    @hussainshaik4390 ปีที่แล้ว +4

    Thanks

    • @umarjamilai
      @umarjamilai  ปีที่แล้ว +2

      Thank you for your support!

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

    amazing

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

    why is the context window size limited? Is it because these models are based on transformers and for a given transformer architecture, long distance semantic relationship detection will be bounded by the number of words/context length ?

  • @خالدالحارثي-ع7ض
    @خالدالحارثي-ع7ض 10 หลายเดือนก่อน +1

    We need one more video to explain download weights and inferencing, because it is not clear.

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

      Hi! To download the LLaMA weights, you need to request access to it by using the following link: ai.meta.com/resources/models-and-libraries/llama-downloads/
      Meta will send you an email with the details on how to download the model.

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

    Thanks! I learned a lot from your excellent video.

  • @sounishnath513
    @sounishnath513 ปีที่แล้ว +10

    No comments.... Need to learn many things... Thank you very much for creating such interesting and helpful content...
    I am fortunate - that I found your channel.

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

    would love to see lighterweight llms trained on custom datasets, thanks for the video! this channel is a gold mine.

  • @thelonejordan
    @thelonejordan 17 วันที่ผ่านมา

    Shouldn't the start_pos should be current_pos - 1. (in the model foward line within the completion function) If you look at the kv caching, you are never caching keys and values for position 0.

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

    I got a lot of questions to ask
    what is in checklist.chk file ?
    what is in cosolidated.00.pth file ?
    what is in tokenizer.model?
    I got error in here
    model = LLaMA.build(
    checkpoints_dir='llama-2-7b/',
    tokenizer_path='tokenizer.model',
    load_model=True,
    max_seq_len=1024,
    max_batch_size=3,
    device=device
    )
    please kindly explain and guide me thank you

  • @dongdongqiaqia
    @dongdongqiaqia ปีที่แล้ว +4

    Marked for my next watch. Thanks for producing high quality video for the series. Hope you have fun in China.

  • @marshallmcluhan33
    @marshallmcluhan33 ปีที่แล้ว +5

    Thanks for explaining all of these concepts. Keep up the good work 😎

  • @riyajatar6859
    @riyajatar6859 3 วันที่ผ่านมา

    Great video . would you do some videos one increasing context length of models.
    With any bert based model or decoder model.🎉

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

    Can somebody help to explain why when calculating theta, we are not including the -2, e.g., theta = theta ** (-2 * theta_numerator / head_dim)

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

    Very good video. You have a knack for conveying complex content in understandable format. Thank you and keep up the great work

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

    Does it answer to our questions just like chatgot do??? Anyone please answer me

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

    Thank you so much for sharing this, it was really well done!

  • @riyajatar1311
    @riyajatar1311 4 วันที่ผ่านมา

    if i want to use this code for training what needs to be changed

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

    Thanks! I learned a lot from your excellent video.

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

    You are a hidden gem, great explanation with theoretical and technical concepts.

  • @Ianlee-t2d
    @Ianlee-t2d ปีที่แล้ว +3

    This is the way!

  • @oiooio7879
    @oiooio7879 ปีที่แล้ว +3

    Great video very educational

  • @modaya3382
    @modaya3382 10 หลายเดือนก่อน +2

    Thank you very much for your efforts

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

    Great video! one question though: In th-cam.com/video/oM4VmoabDAI/w-d-xo.htmlsi=TBFoV5Kj0lnbNaee&t=4272, Why do we have to have the "gamma" of all one? I did comparison on the code with and without the self.weight, the outputs are the same

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

      Oh forgive me dummy question - for anyone else who's thinking about it, the self.weight is learnable

  • @wangqis
    @wangqis 52 นาทีที่ผ่านมา

    Thank you

  • @RayGuo-bo6nr
    @RayGuo-bo6nr 10 หลายเดือนก่อน +2

    Thanks! 谢谢你!

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

    Do you’ve a discord channel

  • @stsouko
    @stsouko ปีที่แล้ว +2

    Wow. Now I got this trick

  • @tljstewart
    @tljstewart ปีที่แล้ว +3

    Great content as usual! Thanks

  • @МихаилЮрков-т1э
    @МихаилЮрков-т1э 8 หลายเดือนก่อน +1

    Thank you for such a detailed analysis of the architecture and implementation features of the model! You are very good at presenting information!

  • @mathlife5495
    @mathlife5495 ปีที่แล้ว +1

    A suggestion for all your videos is to increase the font size or the zoom level. They are kind of unreadable.

    • @umarjamilai
      @umarjamilai  ปีที่แล้ว +1

      Thanks for your feedback! I'll keep that in mind 🤗

  • @tarequeovi4051
    @tarequeovi4051 ปีที่แล้ว +2

    Great Content

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

    oh boy this amazing video

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

    please do mistral

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

    this is hardcore machine learning engineering!

  • @hussainshaik4390
    @hussainshaik4390 ปีที่แล้ว +2

    great content !

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

    Great video @Umar.
    I think line 47 , The transformation goes from (B, Seq_Len, H, Head_Dim) -> (B, Seq_Len, H, Head_Dim/2, 2)

  • @umarjamilai
    @umarjamilai  ปีที่แล้ว +7

    As always the PDF slides and the source code are available on GitHub: github.com/hkproj/pytorch-llama/
    Prerequisites:
    1) Transformer explained: th-cam.com/video/bCz4OMemCcA/w-d-xo.html
    2) LLaMA explained: th-cam.com/video/Mn_9W1nCFLo/w-d-xo.html

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

    Lets say a llm application has a context window of 4000 words. It also supports historical chats. So user can effectively send more than allowed words in a given prompt, and yet get answers related to the previous historical conversation? How does this work ?

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

    watch again

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

    Thanks for your lecture, and I have a question. What happens if the start_pos is longer than the query cache size? If this code is not dealing with such a situation, which kind of additional modification do we need?

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

    Incredible explanation!

  • @德发王-h6i
    @德发王-h6i 7 หลายเดือนก่อน +1

    great video❤

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

    I tried loading the model from M1 mac 8GB RAM but it seems that it requires more memory (I am guessing 28GB RAM)

  • @jiaxingyu8300
    @jiaxingyu8300 ปีที่แล้ว +1

    Thank you so much for sharing!

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

    awesome work boss

  • @Titu-z7u
    @Titu-z7u 8 หลายเดือนก่อน

    Hi, I want to fine tune the model. In that case, will it be required to get rid of the k-v caching?

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

    What are the system requirements to run the inference for this model? By the way, its a great video

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

    Can i use llama2 model open source for life time or can i code along with you and use the model

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

    EXCELENT! I would like to see the se series with Llava.

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

    anyone know how to execute the code on cuda 4090gpu , i faced the out of memoery error

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

    Great video
    So what about the dataset used in this video?

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

    Thank you Umar very much for the efforts here. One question, is there any PPO and finetuning on above of this in next videos?

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

    Thanks!

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

      谢谢你!

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

    Wouldn't it be 'cur_pos - 1' for start_pos argument (line 81 in inference.py, 2:45:58)?

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

      Agreed.

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

    Thanks!

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

      Thank you Diego for your support!

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

    Please can we get the training code too?

  • @hautran-uc8gz
    @hautran-uc8gz 6 หลายเดือนก่อน

    thank you

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

    Amazing work Umar.

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

    🎉🎉

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

    Umar bhai, your tutorials on transformer architectures and open-source LLMs are truly remarkable. As a Pakistani, seeing your expertise in deep learning is incredibly inspiring. Have you ever considered creating Urdu versions of your content? It could make your valuable knowledge more accessible to a wider audience. Your contributions are invaluable to the global tech community. Keep up the fantastic work! Huge fan of your work. May ALLAH bless you with health and success!

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

      He's Italian, I doubt he knows urdu

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

      @@azain47 oh, i thought he was Pakistani, but nvm, it's really good to see a Muslim working and sharing his knowledge and expertise to the rest of the world, generally we don't see Muslim people making great content regarding to CS

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

      @@sharjeel_mazhar be the change you wish to see, brother.

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

    55:44 "I could have also written the code and not tell you and not tell you anything but I like to give proof to what i do " Wow thank you for going that extra mile we really appreciate it.

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

    where do you apply the causal mask?

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

      and the sliding window attention. Thank you

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

      causal mask is not needed since kv cache is used

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

    is llama 2 encoder only or decoder only model ?

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

      People call it "Decoder-Only", because it resembles the Decoder of the Transformer, but it lacks the Cross Attention. Technically it's the Encoder of the Transformer plus a Linear Layer and Softmax. But commonly, people call LLaMA a "decoder only" and BERT a "Encoder only" model.

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

      @@umarjamilai Thanks a lot for your prompt reply. And amazing video

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

    its an honor to me, to be in those 23500 viewers who watched this video, thank you so much umar jamil for your content

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

    Thank you for the wonderful lecture. I wondering why you use torch.matmul / transpose things in the video, but use torch.einsum in the slides? They are mathematically equal, but how about their efficiency, which one will be run faster?