How To Fine Tune LLAMA2 LLM Models With Custom Data With Graident AI Cloud #generativeai #genai

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello all my name is krishn and welcome to my YouTube channel so guys in this video we are going to discuss about how we can finetune our own llm models with our own custom data for this purpose we will be specifically using this platform which is called as gradient. a now gradient actually provides you a lot of llm models on top of that you can probably do a lot of fine-tuning with your own custom data set custom data sets can just be formatted in a specific way to give it and later on the fine tuning can really happen in a quicker way so probably when I will be doing the fine tuning it hardly takes 7 to 8 minutes this is the demo that I really want to show you in this specific video by doing this you will get an idea if you have a custom data set and you want to also create your own custom llm model you can definitely do it with the help of gradient. a now let's understand what does gradient. a provides you it is a one platform unlimited AI it not only does the fine tuning it helps you to develop it deploy it and even for the inferencing part so over here you can create your own private LMS your own models fully unlocked model right and you can build with any languages it provides you three SDK I think JavaScript Python and Java so that is also provided we will be specifically using python SDK we will be using Google collab and we will be fine-tuning our own model so it is the only AI platform that allows you to combine industry expert AI with your private data and here is all the other information that you can see that it also provides accelate AI transformation deploy AI to solve Mission critical problem 10 into fast with gradients AI Cloud platform we handle the infrastructure for you so it is an amazing platform alog together where you can not only uh build your model even you can inference it you can even fine tune it so in order to go ahead with first of all you need to go ahead and sign up so for sign up you can probably put your entire details I've already sign out uh signed up so I'm going to probably do the login over here as soon as I do this loging it will ask you to create a new workspace so this is the first important step that you have to do so for creating a new work workspace you just need to create like just click on this particular button create a new workspace you can give your own workspace name and just submit it once you submit it like in this case I have created a test workspace you need to know this specific ID because this ID is nothing but it is the workspace ID so I will copy this workspace ID so that I will be using it in my coding when I probably do it in the Google collab the next thing that is specifically required you need to click on the access tokens right one is the workspace ID and the other one is the ACC token again to generate the excess token I have already generated it I have kept it uh in my coding environment all you need to do is that just click on generate new access token and you have to just put your password submit it and it will give you the exess token there you just need to do the copy over there so what I will do I will go ahead and uh uh give my password as soon as I do this so here you can probably see that you get your secret access token you can copy it over here one amazing thing about gradient AI is that it provides you all the necessary documentation over here you can just go and refer the documentation it provides you the entire code that is actually required with respect to python SDK and trust me guys just with a minimal lines of code you can probably find T your entire model in an easier way right so if you probably go to the guides here you have something called as python SDK example so with respect to python SDK you can probably see this is the code for fine tuning I will copy the same code and I'll probably run it but here I'm going to make some changes with respect to my data set along with that you can also have you can also go ahead and see the entire documentation whatever things you specifically require the integration it specifically provides for Lang chain llama index mongodb htag so whatever things is specifically required mongodb and all you can probably do the vector dat you can create it as a vector database and probably store all the vectors over there now let me quickly log in again so once I log in if you probably go to the workspace okay so this is the workspace that I've actually created okay now inside this work workspace you can see all this are the models that I have already created for the fine tuning purpose if you probably go ahead and click on fine tuning and if you see if I just go ahead and select uh or create fine tuning over here it provides you three base models okay one is the bloom 560 one is Lama 27b chat one is NOS hermas 2 okay so these are different different models uh llm models you can use any one of them for the fine tuning purpose now in our example what I'm actually going to do is that I'm going to use this specific thing and and then what will happen is that with the help of python hdk I'm going to do the entire fine tuning process here then I will be able to see my fine tuning job also as I go ahead okay so here I have opened my Google collab let's go ahead step by step and let's see that how you can probably fine-tune your llm model so let me first of all make this spelling mistake correctly okay now the first step is that we will go ahead and install gradient AI so for this I will be using pip install gradient AI upgrade so once I execute this over here you'll be able to see that the installation will start taking place now it shows that requirement is already satisfied now the next thing is that the two important information as I said one is the gradient workspace ID I've already shown you from where you can probably get your workspace ID right uh initially in the workspace when we are probably checking it out that particular ID I copied it over here and I pasted it over here and the next ID that I really need to set it is my access token gradient access token so I will set up the environment by using import OS and then I'm going to probably use os. environment gradient workspace ID with my workspace ID itself so this is the ID which you will again get it from the gradient itself once you log in and the second thing is about the gradient access token so here also I have pasted the exess token so let me just go ahead and execute it and I have set up this environment variable one is the gradient workspace ID and gradient access token now is the most important thing this is the code of the entire fine tuning so let me go ahead step by step and see like how the fine tuning is basically done so first of all we will go ahead and import from gradient AI import gradient right so this gradient will be responsible in fine tuning in even calling the base model now I've created a function definition main now this is the function initially I have initialized gradient okay inside this gradient you have a method which is called as get base model and here the first parameter is something called as base model slug that basically means what model you are specifically calling and I have already shown you in the fine tuning right if you probably go ahead and create fine tuning through the UI you have this three models that is there Bloom 560 Lama 2 7B chat no hus 2 so in this case I'm going to specifically use NOS harmas 2 okay now NOS harmas 2 I'm going to do it see you can also do it with the help of UI but I really want to show you with the help of coding by using python hdk so here is the same model I have pasted it over here right so this specific model over here is my llm model that I'm going to find on top of it I'm going to fine tune it with my own custom data now once we created this base model so this line basically gets you the base model over here now this model will be responsible and we will try to create a model adapter right the reason we are creating a model adapter because this will be specifically my model let's say this is like Kish model over here and this model the reason we are creating as a model adapter because in further we will be doing fine tuning for this particular model itself so the first step is basically to create an adapter on front of it right and the name of that particular model will be uh Kish model itself so this is the second line of the code that we have executed now here we have created the model adapter with the ID new model adapter. ID so we will be getting the ID itself now is the most important step I will try to go ahead and create a query so this is my sample query the instruction see I've given some kind of format the instruction is who is Krishna so this is the question and usually what happens is that in gradient you really need to use a specific format in creating your custom data and for that you can refer this python SDK here you have some tips and tricks it will talk about like how you can probably create your entire uh data itself right with custom data so you can check it out this specific thing and with respect to that you'll get an idea like how your data set should be created in a form right so some format should be there so let's say if I ask any query right for a base model something like this I've given this three hash uh and then the instruction this is the question who is Krishna and then we are closing it with two end line okay and then we will be seeing the response so response over here is kept as blank because this response is going to come from this specific new model adapter okay which has the base model NOS Hermos okay now we will be printing this sample query so already it will be just going and printing this who with all all this information like instruction and response now this model Raptor when I say dot complete okay so dot complete is a method over here the first parameter I'll be giving my query that is my sample query the max generated token I will be giving 100 so it is going to probably um take 100 Max token in the form of output and then we are going to use dot generated output so this is what of the attribute that is present inside this R complete method okay so after this complete method we will be getting the generated output as soon as we get the generated output that basically means whatever questions I have asked over here who is Krishna I'm going to get the output over here itself right so generated before fine tuning now here is my output that I'll be getting and understand I have not started my fine tuning so that is the reason I have written a comment over here before fine tuning now before fine tuning if I ask who is Krishna obviously this model will not know unless and until I'm very much popular okay I'm not that much popular so it'll just say that if if it has heard somewhere krishn it'll give some information now what I will do I will go ahead and create my own sample data okay regarding Krishna because obviously over here in before fine tuning if I probably execute it I will not be able to get the output the right output now this will basically be my custom data so here you can see that the first question that I've asked the first uh sample that first input data that I have created which will be used for training is that who is Krishna then over here the response I have written as krishn is a popular mentor and YouTuber who uploads video on data science and uh llm and his channel channel and in his channel krishn so this is one of the input and the output that I have given the similarly second input I will again create who is this person named Krishna now I'm giving in a different format of text like question and answer right and again the response have written Krishna likes data science and AI make videos in YouTube and he's also a mentor right something like this then instruction again what do you know about Krishna okay so again I've created one more response Krishna is a popular Creator who specializes in the field of data science and channel name is krishn okay and again one more input like this I can create lot of inputs related to a single context now suppose if I have 100 of context I may probably create this kind of inputs and at the end of the day if in a real world scenario an end to end project if you see this all information will be coming from some kind of databases it can be a mongodb database it can be a SQL database and all right so this will be my sample of data it's just like more like a key value pair you know a list of key value pairs now this is done now what I'm going to Define after this my input is done my model before fine tuning is done now I need to do the fine tuning so for performing the fine tuning I need to have number of epochs one parameter I will initialize count is equal to Z now I'm saying while count is less than number of EPO and then I will start my fine tuning over here so fine tuning count plus one then I will say new model adapter do finetune is one method where I am giving my samples okay so samples over here these all samples I'll be giving it over here for the fine tuning purpose so in short I'm using a method which is called as do fine tune and we are specifically giving this samples over here and and then we are incrementing the count so that the epox keeps on increasing so first iteration one iteration 2 iteration 3 and then this entire fine tuning will happen okay now after this I am again writing this comment after fine tuning and I will execute the same method right over here by giving the same sample query who is Krishna right and over here the same thing is there and get the generated output I going to display the generated output and after doing this I am deleting my adapter because I will not require it afterwards uh if I wanted to use it further I can keep it like that otherwise I can just go ahead and delete it and here also I'm closing the gradient and this is where I'm starting my main so this is in short what we are doing is that before fine tuning I really want to see the response I created my sample data over here and then again I did the fine tuning with respect to number of apox and all and now let's go ahead and execute it so once I probably start executing it you can probably see it will it will start uh you know it may take hardly a couple of minutes since I've just done three iteration okay so here created model adapter with this particular ID uh the instruction is who is Krishna so it is waiting for the response let's see over here whether it has been created or not uh model testing let's see fine tuning so here also it will as soon as the fine tuning will happen here the model will get created and it will got deleted okay it will get deleted so here the response it it is getting that Krishna is a well-known Indian actor who has prepared in various films uh and television shows is best known for his uh Raj in the popular I have I've never worked in any industry guys okay so it is saying I'm an Indian actor I'm not an actor altogether okay so this is a very famous serial in India okay I have never acted over there I don't know whom it has considered okay that's also said that I've worked in D Chata hm nice so now I am doing the fine tuning so this is the response that I've got generated before fine tuning and now after fine tuning I have given the right kind of data with respect to input and the response uh the third iteration is getting overseas how fast it is happening in the cloud platform gradient Cloud platform that is quite amazing right and this is super super nice at the end of the day you'll be able to see this right beautiful right we already in the third iteration and now here I'm getting my output generated after fine tuning Kish is a popular YouTuber and data science he known for his data science python tutorials on his YouTube channel Krish naak now see just with this three sentence or four sentence how well it has done the fine tuning now just imagine the power guys right the entire fine tuning is happening in the gradient Cloud itself right if I probably give this kind of data and just increase the number of aox and train it how beautifully within 5 to 7 minutes you can actually train it and hardly you know just to put my input data it hardly took very less time right so this is one amazing application this is how you can probably do the fine tuning one task I really want to give it to you I okay let's let's reload this I think you'll be able to see my fine tune model also uh let's see the model uh okay I've already deleted it I think yeah I've deleted it so that is the reason you're not able to see it over here if I had not deleted that you could also see the models over here right so model testing see model is also not here right otherwise you could also see it uh put it over here and you can ask any question you want right this is quite amazing so at the end of the day if you don't want to delete it just don't delete it and keep it like this so I hope you like this particular video I hope you have understood how you can finetune our amazing llm models uh in with the help of gradient AI Cloud uh which is quite amazing you should definitely use it try to use it and try to see whether you're able to do this or not but uh just by seeing the code and all I think it is quite easy quite amazing again yes this was it for my side I hope you like this particular video I'll see you all in the next video have a great day thank you and all take care bye-bye
Info
Channel: Krish Naik
Views: 17,802
Rating: undefined out of 5
Keywords: yt:cc=on, llam2 models, how to fine tune llam2 models, how to fine tuning llama 2 models, how to fine tuning generative ai models, krish naik machine learning, krish naik deep learning, krish naik generative ai, llama2 meta models, llama2 open source
Id: _78rA4uV4jA
Channel Id: undefined
Length: 16min 38sec (998 seconds)
Published: Mon Jan 01 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.