Llama - EXPLAINED!

CodeEmporium · Advanced ·🧠 Large Language Models ·2y ago

Key Takeaways

The video explains the Llama model, providing resources and links to dissertations, code, and tutorials on how to use and fine-tune the model.

Full Transcript

in this video we're going to talk about llama 2 what is llama 2 how is it trained how does it compare it to GPT variants and chat GPT and its architecture and code so let's get to it what's important to understand first is that llama 2 is a suite of pre-trained language models while llama2 chat is a fine-tuned chatbot that uses reinforcement learning through human feedback and this is analogous to gpt3 which is a suite of pre-trained language models and chat GPT which is also a fine tune chatbot that has reinforcement learning through human feedback so llama 2 is comparable to gpt3 and llama2 chat is comparable to chat GPT let's take a look at these individual buzzwords starting with pre-trained and language models with a language model we take in previous words in order to predict the next word and this is exactly what we want from llama and GPT and in order to do this we would feed it hundreds of thousands of examples of input sequences as well as their next token and in this way we tune the parameters of the model and this training is known as the pre-training and so we pre-train an architecture to understand how to perform language modeling now that we got pre-trained and language model out of the way let's talk about the fine-tuned chat bot so we have a chat bot and for a chatbot we'll take an input question and it will deliver a response to that question and this is exactly what we want from llama to chat and chat GPT now in this case we are still training the model to understand how to perform question answering but this training phase is known as fine tuning now that we got those two concepts out of the way let's talk about reinforcement learning through human feedback so let's say now we have this chat bot this chatbot which is either a llama2 chat or chat gbt is already trained to answer questions now this chatbot though can produce multiple answers for the same question and you can actually see this in action with chat GPT where we ask the same question it gives us multiple answers now at this point we want to check which is one of the better answers here and in this case we would check let's say the second one over here and in order to determine which answer is better we have a group of human reviewers take a look at well for this question of these three answers which is the best so essentially we have humans determining the best answer and this is then acted as feedback to the chatbot where we're basically saying hey we want you chatbot to produce more answers that look like this for this kind of question we quantify this to the chatbot via reinforcement learning and so this entire process is reinforcement learning with human feedback and this chat bot is now tuned to answer questions more like this now that we kind of tackle all of the major buzzwords here let's actually go through the entire training overview end to end so first we have an architecture that's just some untrained model we'll talk about details after this section we then train this model to predict the words that come after the input sequence this is language modeling and we introduce multiple hundreds of thousands of examples so that it truly understands how to model language now this language model is now Lama two so llama 2 is a pre-trained language model now we take this llama2 which is pre-trained on language modeling and then we further train it to answer questions and we feed it in you know hundreds of thousands of questions until eventually this model becomes Lama 2 chat this model is now fine-tuned to answer questions and llama to chat is now made to produce for a single question multiple responses we then have human reviewers determine which is the most appropriate response and then we then make sure that llama to chat understands that hey we want you to produce more answers that look like this via reinforcement learning and we again train this on multiple examples and this is how llama 2 chat becomes safe helpful and non-toxic now that we've taken a look at the overall training overview let's take a look at the model architecture and its code side by side this here is the approximate model architecture for how llama 2 looks now this is a decoder only Transformer architecture and what that means is that these are the stack of the decoder part of the Transformer neural network and it's in a slightly more simplified form note like I mentioned this is an approximate version of llama but it is very close the only main differences are that this normalization layer happens a little before the feed forward Network and this normalization layer also happens before the attention layer to see this in action let's actually take a look at the code so this here is the Facebook research repository for llama and specifically this is now updated to be llama 2 at the time of recording this video and you can see this model architecture is really only just like 300 lines of code and we can take a look at the Crux of this architecture right here in this Transformer block so looking at the forward pass here you can see that first we perform some form of normalization followed by attention and then we'll add it to the input and what we saw in this original figure was attention followed by addition and normalization so this normalization actually comes before next we'll take the output that we received we will again perform normalization feed forward and then addition whereas here we perform feed forward addition and normalization so once again this normalization operation should have come here this is just one Transformer block but the architecture consists of a stack of such blocks and it's preceded by some input embedding layer which will perform some sort of positional encodings too you can kind of also see this in the code where we go to this Transformer section where we're iterating over the layers of the Transformer block and then we want to also perform other operations now let's now look at the model forward pass so this is the code that will be executed when you want to make a prediction given some input what is like the next word or token for llama because llama remember is a language model so we first take the input we'll then try to get its token embeddings this is done by Computing the original embeddings of each token that is each word or byte pair encoding and adding it to or applying it to I should say in this case to the positional embedding to get this final embedding H for every single by pair encoding we'll then create a mask this masking is required because over here you see we're performing masked multi-head attention this is done so that the decoder cannot cheat especially during the training time because it has access to information that comes before and after a current word but it should not be able to look at the information after that current word and hence we need the mask there with inference we don't really have that information so we're just adding masking for the sake of uniformity and so we'll add that masking over here in code then we will make sure that the input goes through all of the layers all the Transformer blocks and then we'll perform some no realization and get the output if you want me to do a much deeper dive on llama code and also a little more deeper dive on the architecture do comment down below let's not compare these llama architectures with these GPT architectures the first here is that llama is open source that is we know the code that actually runs the core model for language modeling that is llama itself whereas GPT is more proprietary code and we can only make assumptions of how the model looks and how the code looks llama is trained on public data whereas GPT is not Lama has limited GPU requirements for fine-tuning at least in comparison to GPT it's also a smaller architecture with more training data so the Llama Suite of Architecture is contained between 7 billion parameters to like 70 billion parameters whereas gbt3 contains with its largest model 175 billion parameters which is multiple times more than that of llama however it is still able to have comparable performance and sometimes even much better performance than gpt3 in multiple places and this is owing to the more training data that it uses it I think Lama 2 uses of the order 2 trillion byte parent Coatings now owing to its small architecture we can also say that llama has a faster inference time than gpt3 this is because the architecture is smaller so there are more operations that need to be done in that forward inference pass and so if you have like a real-time production grade system llama 2 is faster than gpt3 now where do I start coding if I want to make some inference from these models so you can go to hugging face repository there'll be a bunch of these pre-trained llama models as well as some that are fine-tuned and they'll give you some code Snippets where you can see how you can actually use it in your own projects now if you want to go a little deeper and fine tune your llama models you can use certain tools like Colora which provides tools for efficiently training models using like CPU and memory constraints and here's the entire code where you know they're loading data sets loading their models and you can create like a little trainer and eventually just start training this model and you can see that you know over time you will actually be able to train and also you know push this to to hugging face Hub once you're done now this is not my code but I will link to the YouTube channel that actually created this and provided a good schematic for this code and the link to this will be down in the description below another really fun tool that I found here is called Auto Train where you can fine tune any language model or any supported language model and I believe llama2 should be supported in this case and they provide this one line code to start fine-tuning your llama models even on your local machine so I'll link to all of these resources down in the description below now hopefully all of these resources are good for you to understand this wonderful 77-page dissertation on llama2 and I hope that we were able to demystify llama 2 for what it is thank you all so much for watching and I will see you in another video bye-bye

Original Description

ABOUT ME ⭕ Subscribe: https://www.youtube.com/c/CodeEmporium?sub_confirmation=1 📚 Medium Blog: https://medium.com/@dataemporium 💻 Github: https://github.com/ajhalthor 👔 LinkedIn: https://www.linkedin.com/in/ajay-halthor-477974bb/ RESOURCES [1 🔴] Llama 1 dissertation: https://arxiv.org/pdf/2302.13971.pdf [2 🔴] Llama 2 dissertation: https://scontent-lax3-1.xx.fbcdn.net/v/t39.2365-6/10000000_662098952474184_2584067087619170692_n.pdf?_nc_cat=105&ccb=1-7&_nc_sid=3c67a6&_nc_ohc=O3eQj9LEMfQAX_IC7oO&_nc_ht=scontent-lax3-1.xx&oh=00_AfDihQ7maFg_ebWGZCxpt1ZYmSfYupRr1HJMyexxrC7nwg&oe=64DA167F [3 🔴] Llama code: https://github.com/facebookresearch/llama/blob/main/llama/model.py [4 🔴] Where I got the decoder only transformer architecture: https://ai.stackexchange.com/questions/40179/how-does-the-decoder-only-transformer-architecture-work [5 🔴] Huggingface models on Llama that you can use for inference: https://huggingface.co/models?search=llama2 [6 🔴] Llama vs Alpaca: https://sapling.ai/llm/alpaca-vs-llama2 [7 🔴] Llama2 file using Qlora: https://colab.research.google.com/drive/12dVqXZMIVxGI0uutU6HG9RWbWPXL3vts?usp=sharing#scrollTo=C2EgqEPDQ8v6 [8 🔴] @1littlecoder 's video describing Qlora and how you can fine tune llama: https://www.youtube.com/watch?v=eeM6V5aPjhk [9 🔴] Autotrain repo for 1 line training: https://github.com/huggingface/autotrain-advanced [10 🔴] Video describing on how to use Autotrain (@abhishekkrthakur ) : https://www.youtube.com/watch?v=3fsn19OI_C8 PLAYLISTS FROM MY CHANNEL ⭕ Transformers from scratch playlist: https://www.youtube.com/watch?v=QCJQG4DuHT0&list=PLTl9hO2Oobd97qfWC40gOSU8C0iu0m2l4 ⭕ ChatGPT Playlist of all other videos: https://youtube.com/playlist?list=PLTl9hO2Oobd9coYT6XsTraTBo4pL1j4HJ ⭕ Transformer Neural Networks: https://youtube.com/playlist?list=PLTl9hO2Oobd_bzXUpzKMKA3liq2kj6LfE ⭕ Convolutional Neural Networks: https://youtube.com/playlist?list=PLTl9hO2Oobd9U0XHz62Lw6EgIMkQpfz74 ⭕ The Math You Should Know : htt
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from CodeEmporium · CodeEmporium · 0 of 60

← Previous Next →
1 Linear Regression and Multiple Regression
Linear Regression and Multiple Regression
CodeEmporium
2 Logistic Regression - THE MATH YOU SHOULD KNOW!
Logistic Regression - THE MATH YOU SHOULD KNOW!
CodeEmporium
3 Generative Adversarial Networks - FUTURISTIC & FUN AI !
Generative Adversarial Networks - FUTURISTIC & FUN AI !
CodeEmporium
4 Deep Learning on the Cloud - GPU TO LEARN FASTER
Deep Learning on the Cloud - GPU TO LEARN FASTER
CodeEmporium
5 Deep Mind's AlphaGo Zero - EXPLAINED
Deep Mind's AlphaGo Zero - EXPLAINED
CodeEmporium
6 Mask Region based Convolution Neural Networks - EXPLAINED!
Mask Region based Convolution Neural Networks - EXPLAINED!
CodeEmporium
7 Attention in Neural Networks
Attention in Neural Networks
CodeEmporium
8 Depthwise Separable Convolution - A FASTER CONVOLUTION!
Depthwise Separable Convolution - A FASTER CONVOLUTION!
CodeEmporium
9 One Neural network learns EVERYTHING ?!
One Neural network learns EVERYTHING ?!
CodeEmporium
10 Neural Voice Cloning
Neural Voice Cloning
CodeEmporium
11 AI creates Image Classifiers…by DRAWING?
AI creates Image Classifiers…by DRAWING?
CodeEmporium
12 Unpaired Image-Image Translation using CycleGANs
Unpaired Image-Image Translation using CycleGANs
CodeEmporium
13 K-Means Clustering - EXPLAINED!
K-Means Clustering - EXPLAINED!
CodeEmporium
14 Random Forest Classification
Random Forest Classification
CodeEmporium
15 Data Science in Finance
Data Science in Finance
CodeEmporium
16 Hypothesis testing with Applications in Data Science
Hypothesis testing with Applications in Data Science
CodeEmporium
17 A/B Testing - Simply Explained
A/B Testing - Simply Explained
CodeEmporium
18 The Kernel Trick - THE MATH YOU SHOULD KNOW!
The Kernel Trick - THE MATH YOU SHOULD KNOW!
CodeEmporium
19 Support Vector Machines - THE MATH YOU  SHOULD KNOW
Support Vector Machines - THE MATH YOU SHOULD KNOW
CodeEmporium
20 Principal Component Analysis (PCA) - THE MATH YOU SHOULD KNOW!
Principal Component Analysis (PCA) - THE MATH YOU SHOULD KNOW!
CodeEmporium
21 History of Calculus - Animated
History of Calculus - Animated
CodeEmporium
22 Curiosity in AI
Curiosity in AI
CodeEmporium
23 DropBlock - A BETTER DROPOUT for Neural Networks
DropBlock - A BETTER DROPOUT for Neural Networks
CodeEmporium
24 Autoencoders - EXPLAINED
Autoencoders - EXPLAINED
CodeEmporium
25 Recurrent Neural Networks - EXPLAINED!
Recurrent Neural Networks - EXPLAINED!
CodeEmporium
26 LSTM Networks - EXPLAINED!
LSTM Networks - EXPLAINED!
CodeEmporium
27 Building an Image Captioner with Neural Networks
Building an Image Captioner with Neural Networks
CodeEmporium
28 10 Machine Learning Questions - ANSWERED!
10 Machine Learning Questions - ANSWERED!
CodeEmporium
29 How do neural networks work?
How do neural networks work?
CodeEmporium
30 Evolution of Face Generation |  Evolution of GANs
Evolution of Face Generation | Evolution of GANs
CodeEmporium
31 How does Google Translate's AI work?
How does Google Translate's AI work?
CodeEmporium
32 How to keep up with AI research?
How to keep up with AI research?
CodeEmporium
33 How does YouTube recommend videos? - AI EXPLAINED!
How does YouTube recommend videos? - AI EXPLAINED!
CodeEmporium
34 Variational Autoencoders - EXPLAINED!
Variational Autoencoders - EXPLAINED!
CodeEmporium
35 Logistic Regression - VISUALIZED!
Logistic Regression - VISUALIZED!
CodeEmporium
36 Gradient Descent - THE MATH YOU SHOULD KNOW
Gradient Descent - THE MATH YOU SHOULD KNOW
CodeEmporium
37 Boosting - EXPLAINED!
Boosting - EXPLAINED!
CodeEmporium
38 Transformer Neural Networks - EXPLAINED! (Attention is all you need)
Transformer Neural Networks - EXPLAINED! (Attention is all you need)
CodeEmporium
39 Loss Functions - EXPLAINED!
Loss Functions - EXPLAINED!
CodeEmporium
40 Optimizers - EXPLAINED!
Optimizers - EXPLAINED!
CodeEmporium
41 NLP with Neural Networks & Transformers
NLP with Neural Networks & Transformers
CodeEmporium
42 Batch Normalization - EXPLAINED!
Batch Normalization - EXPLAINED!
CodeEmporium
43 Activation Functions - EXPLAINED!
Activation Functions - EXPLAINED!
CodeEmporium
44 Data Scientist Answers Interview Questions
Data Scientist Answers Interview Questions
CodeEmporium
45 Why use GPU with Neural Networks?
Why use GPU with Neural Networks?
CodeEmporium
46 How do GPUs speed up Neural Network training?
How do GPUs speed up Neural Network training?
CodeEmporium
47 BERT Neural Network - EXPLAINED!
BERT Neural Network - EXPLAINED!
CodeEmporium
48 ConvNets Scaled Efficiently
ConvNets Scaled Efficiently
CodeEmporium
49 Transformer Neural Net makes music! (JukeboxAI)
Transformer Neural Net makes music! (JukeboxAI)
CodeEmporium
50 What do filters of Convolution Neural Network learn?
What do filters of Convolution Neural Network learn?
CodeEmporium
51 We're hosting a Machine Learning Conference!
We're hosting a Machine Learning Conference!
CodeEmporium
52 MLconfEU 2020: Machine Learning Conference for Software Engineers
MLconfEU 2020: Machine Learning Conference for Software Engineers
CodeEmporium
53 Are Neural Networks Intelligent?
Are Neural Networks Intelligent?
CodeEmporium
54 Time Series Forecasting with Machine Learning
Time Series Forecasting with Machine Learning
CodeEmporium
55 Few Shot Learning - EXPLAINED!
Few Shot Learning - EXPLAINED!
CodeEmporium
56 How does a Data Scientist Fight FRAUD?
How does a Data Scientist Fight FRAUD?
CodeEmporium
57 How would a Data Scientist analyze Customer Churn?
How would a Data Scientist analyze Customer Churn?
CodeEmporium
58 Expectations with Machine Learning
Expectations with Machine Learning
CodeEmporium
59 Why Logistic Regression DOESN'T return probabilities?!
Why Logistic Regression DOESN'T return probabilities?!
CodeEmporium
60 How you SHOULD code Machine Learning
How you SHOULD code Machine Learning
CodeEmporium

The video provides an in-depth explanation of the Llama model, including its architecture, applications, and resources for further learning. Viewers can learn how to use and fine-tune the model for their own projects.

Key Takeaways
  1. Read the Llama dissertation
  2. Explore the Llama code on Github
  3. Use Huggingface models for inference
  4. Fine-tune the Llama model using Qlora or Autotrain
  5. Compare Llama with other models like Alpaca
💡 The Llama model is a powerful tool for natural language processing tasks, and can be fine-tuned and optimized for specific applications.

Related Reads

📰
Running NVIDIA Nemotron 3.5 ASR Locally with parakeet.cpp (and how it beat Whisper on my laptop)
Run NVIDIA Nemotron 3.5 ASR locally for offline speech-to-text capabilities without relying on cloud services or incurring API bills
Medium · LLM
📰
Building Production-Grade LLM Evaluation Pipelines: From Vibes to Metrics
Learn to build production-grade LLM evaluation pipelines by replacing subjective 'vibes' with quantitative metrics
Dev.to · Imus
📰
Building Production-Grade LLM Evaluation Pipelines: From Vibes to Metrics
Learn to build production-grade LLM evaluation pipelines to catch hallucinations before deployment, replacing manual 'vibe checks' with automated metrics
Dev.to AI
📰
AI is more likely than humans to form biases when hiring
AI hiring tools can form biases, even if trained on unbiased data, highlighting the need for careful evaluation and mitigation of these biases
MIT Technology Review
Up next
5 Levels of AI Agents - From Simple LLM Calls to Multi-Agent Systems
Dave Ebbelaar (LLM Eng)
Watch →