File size: 16,444 Bytes
59843e3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
trelis_voice2_0.wav|I'm going to walk you through 10 quick tips for fine tuning. For each of those, I'll point you to one or two trellis videos on YouTube and also point you to the right branch if you're working out of the trellis advanced fine tuning repository.|1 trelis_voice2_1.wav|Tip number one is to start with a small model. I recommend starting with something like Lama 3 8B or Phi 3 Mini. And the reason is because fine tuning is about experimentation and you want to be able to try many things quickly.|1 trelis_voice2_2.wav|If you start off with Lama 3 8 or 70B, it's going to take you much more time in order to test out what's working and what's not. You can always start small and scale up later. The video I recommend here is memorization.|1 trelis_voice2_3.wav|This one, I use a relatively small model as I do in many of my fine tuning tutorials, just because it's quicker to learn fast. Tip number two is to use LoRa or QLoRa. I don't recommend starting off with full fine-tuning for a few reasons.|1 trelis_voice2_4.wav|First of all, LoRa and QLoRa allow you to start with fewer GPUs or a smaller GPU. That's going to make iteration faster. But for small datasets, the performance might even be better than full fine-tuning because full fine-tuning can tend to overfit.|1 trelis_voice2_5.wav|So I'd recommend even if you eventually want to do full fine-tuning, start off with LoRa or QLoRa and try to get it working before you want to spend more on GPU rental and more of your time.|1 trelis_voice2_6.wav|So you want to create 10 question answer pairs and use those to choose which base model is going to perform best. So just by running those on different base models, you can see which one is going to give you the best baseline for starting off your fine tuning.|1 trelis_voice2_7.wav|Then after you do any training run, you want to run that manual test. and just evaluate whether the model is doing well. This gives you probably a better sense than solely looking at the eval and training loss during the fine-tuning process.|1 trelis_voice2_8.wav|This is what I do in this memorization video as well, which you can check out on YouTube, and you'll see in the memorization scripts how I allow you to set up this manual dataset. That's also possible in the unsloth branch and the multi-GPU branch, which I'll get to later.|1 trelis_voice2_9.wav|And I'm checking all the time whether my performance is actually improving or whether just my dataset design is completely off. If you do want to automate a little more how you generate synthetic data sets, you can check out this video here on data set preparation with LLMs.|1 trelis_voice2_10.wav|Tip number six is always use a validation data set. If you don't have one, you can just split off 10 to 20% of your training data set. You want to be checking your training loss as you progress along the process.|1 trelis_voice2_11.wav|Make sure it's not too bumpy and your learning rate is not too high or your batch size or virtual batch size is too small. You also want to check your validation loss, and this should be monotonically decreasing in a smooth way.|1 trelis_voice2_12.wav|If it's ever upticking, that means you might be overfitting and you're training for too many epochs, or you may not have enough data. Here, I recommend the Trellis repo branches of Unsloth or MultiGPU. They each allow you to split off validation, split from your base training set.|1 trelis_voice2_13.wav|If you really need to increase VRAM, say from what is on a T4 with Colab, then consider paying maybe 70 cents an hour for a 48 GB GPU like an A6000 or an A100 for 80 GB of VRAM.|1 trelis_voice2_14.wav|I think you're better off to just fit it on one GPU, because when you move to multi GPU, you have data that's moving between them, the training becomes more complicated, it's easier to make mistakes, and it can be slower in some ways.|1 trelis_voice2_15.wav|I've got a one-click template here for RunPod, and you can use that to consistently have the same environment on which to install the final packages you need for fine tuning. Tip number eight is to use weights and biases.|1 trelis_voice2_16.wav|This is a tool that allows you to track the losses and the rewards as you move through your training run. You can include this in a script with pip install wandb, then set the environment variable for wandb project to a project name.|1 trelis_voice2_17.wav|This is supported in the Onslaught and the multi-GPU branches and also in many of the Jupyter notebooks that are throughout all the branches of the advanced fine-tuning repo. Before I move to tips 8 and 9, I want to comment on scaling up.|1 trelis_voice2_18.wav|Start by increasing the rows of data on a small model, then move QLoRa to LoRa. If you really want to try full fine-tuning, test it out on a small model and see if it really improves performance.|1 trelis_voice2_19.wav|If you want to understand the pros and cons of full fine-tuning versus QLORA or LoRa, take a look at this video. And if you want to understand the complexities of doing multi-GPU training, check out multi-GPU fine-tuning. Moving to two last tips.|1 trelis_voice2_20.wav|Tip number nine is to use unsupervised fine-tuning. This can be useful if you have a large data set. I'm going to say larger than 10,000 rows of data. Here, you'll need to use Python scripts in order to clean up, say, repeated characters or too much new lines.|1 trelis_voice2_21.wav|You can also use language models in order to clean up the data set chunk by chunk. The video of relevance here is the Wikipedia video I made, where I first extract data from Wikipedia, clean it, and then use it for fine-tuning.|1 trelis_voice2_22.wav|Last of all, my tip number 10 is to do preference fine-tuning. This is where you have a data set with chosen, which are better or preferred responses, and rejected, which are the responses to the same prompts but are of lower quality.|1 trelis_voice2_23.wav|You might have a set of data like this if you have production data from customers or from a chatbot. You may have some conversational data that you consider of good quality. You may even have corrected or annotated versions of those conversations where you've improved the assistance responses.|1 trelis_voice2_24.wav|Here I recommend the Orpo YouTube video, and there's also a branch by that name in Advanced Fine Tuning. Orpo is also supported in the Unslot branch, where there's a Python Jupyter notebook and also just a Python.py script you can run.|1 trelis_voice2_25.wav|And Orpo is supported as an option in the Multi-GPU branch too. So to recap these 10 tips, start with a small model, use LoRa or QLoRa, not full fine-tuning. Always create 10 manual test questions or maybe a few more.|1 trelis_voice2_26.wav|Make sure you know that the data type and the data set that you've set up is actually the right one. Number six, always use a validation set. Just split one off from a training set if you don't have one.|1 trelis_voice2_27.wav|And when you're scaling from small to large, increase first the rows, then move to using more VRAM with LoRa instead of QLoRa or full fine tuning instead of LoRa. By the way, there's a factor of four roughly in VRAM difference between each of those.|1 trelis_voice2_28.wav|Now, this approach here I've talked about for language models, but it also works for video and speech or images, multimodal models. So you can check out this video here on multimodal text plus image, where I prepare a data set and bring it through fine tuning.|1 trelis_voice2_29.wav|So there are four different sections, four playlists and four repositories that go with them. There's the LLM fine tuning playlist, which is all about fine tuning language models. Then there's a repo for that advanced fine tuning. There's the vision playlist, which is for multimodal models and repo link.|1 trelis_voice2_30.wav|And so here is the link for this. I'll note as well that within this repo, there's some scripts that allow you to redact information, personally identifiable information like names, emails, or credit card numbers before you send the data to a third-party LLM.|1 trelis_voice2_31.wav|Last of all, these repos, of which there are four, they're available for purchase individually, but you can also now buy a repo bundle, which will give you lifetime access to all four of these repositories, which includes any future updates made to those repos.|1 trelis_voice2_32.wav|And likewise, if you go to the supervised fine tuning branch, there is also a script or multiple scripts for generating Q&A data from a base data set right there. Then there are two important branches here, unsloth and multi-GPU.|1 trelis_voice2_33.wav|The unsloth branch allows you to run fine tuning in either a notebook or as a Python script. Whereas the multi-GPU branch allows you to run Python scripts that will deploy multi-GPU training that's fully shared data parallel or distributed data parallel.|1 trelis_voice2_34.wav|Now, the notebook is recommended if you want to go through the training the first time, you can see step by step what's happening and easily print out things at intermediate points. But when you've got your script honed, it can be a lot faster to run a Python script.|1 trelis_voice2_35.wav|And that's why I have made this script available, which you just run from the command line and it will go through everything within the training. Just to give you a sense of how you configure the training and test setup, you'll set a model slug.|1 trelis_voice2_36.wav|You can decide to test either from a set of messages that you have prepared manually, or you can use the training, or you can use the validation split of a test set that's on Hugging Face by setting use data set to test equal to true right here.|1 trelis_voice2_37.wav|You can either download from a split that's on Hugging Face called test or validation, but you can also generate a validation split from the train split. If you just set this to true, it will sequester 20% of the training data to use as validation.|1 trelis_voice2_38.wav|You set the project name, and then for each run, you can use a different name here for running in Weights and Biases. You can set up your HuggingFace username. This will be used when pushing models to Hub.|1 trelis_voice2_39.wav|And this can be useful if your answers are quite short and you don't want the loss on all of the prompts to kind of crowd out or cloud out the information or the signal that's coming from training on the response or the answer.|1 trelis_voice2_40.wav|So you set the completions to true here. Sometimes I use this for function calling, fine tuning. And then you need to let the model know where your answer is starting. So in a Lama 3 model, the answer will start after assistant and header ID.|1 trelis_voice2_41.wav|In a Lama 2 model, it will start after inst. And then I think this is maybe a chat ML format. the answer will start after I am start assistant. So this allows the training loop to check within your prompt.|1 trelis_voice2_42.wav|the number of epochs, the learning rate, an output directory for your training model and results, whether you want to train with BrainFloat 16 or not. You can set your scheduler. You can decide whether to save the model at a certain number of steps of training.|1 trelis_voice2_43.wav|set your max sequence length, gradient checkpointing, and whether to use re-entrancy, which allows you to speed up the training. Next, you can decide whether you want to use ORPO or not. By default, I've got that set to false.|1 trelis_voice2_44.wav|If you're using ORPO, you need a column that's called chosen and one called rejected. and you can set your max prompt length. And then the beta, the beta basically weighs how much of the preference fine-tuning, what's the importance of that loss relative to the standard SFT loss.|1 trelis_voice2_45.wav|Last of all, you can push to hub, so you can set a target model name if you want to push to hub. So very quickly, if we take a look at the test script, this will simply load the model.|1 trelis_voice2_46.wav|It will set up the tokenizer, set up the chat template, load the dataset, either from your manual data that's in the repo or from Hugging Face, and then it will run inference through all of those samples and print the results out to file.|1 trelis_voice2_47.wav|So here is some fine-tuning on TouchRugby, and you'll see there is a prompt, a question, and it'll print out the correct response, and it'll also print out the generated response. And then you can just manually compare whether these answers are good or not.|1 trelis_voice2_48.wav|Now, just one other script I'll point out here, which is viewModules. You can just run Python viewModules if you want to see what modules are within the given model. This allows you to pick out which modules you might want to fine tune using LoRa.|1 trelis_voice2_49.wav|It does not work if you're fine tuning on multi GPU, which is why I have the multi GPU branch and the multi GPU branch is configured much in a similar way to unsloth, except that it allows you to run in fully sharded data parallel or in distributed data parallel.|1 trelis_voice2_50.wav|It has a config file that you can set up. It has the test.py and the train.py file that will allow you to run testing and training. And I'll just briefly show you the config file. So at the start here, you'll see this parameter that's not in the unsloth branch.|1 trelis_voice2_51.wav|That can be done by running config, accelerate config, and you'll see the instructions if you head over to the multi-GPU branch for doing that. So this is the Advanced Fine Tuning repo, and you can find out more at trials.com forward slash advanced dash fine dash tuning.|1 trelis_voice2_52.wav|The next repo I'll briefly go through is the Advanced Vision repo. This does much of the same, but for multimodal text plus image models. It allows you to prepare your data and push it up to create a Hugging Face dataset.|1 trelis_voice2_53.wav|Then you can fine tune Lava, IdaFix and, or IdaFix and Moondream models. You can do multimodal server setup with text generation inference. There's a one-click template for running an IdaFix server, including on a custom model.|1 trelis_voice2_54.wav|And last of all, there is a script for fine-tuning multimodal text plus video models. This is basically a variation on text plus image models where you split the video into multiple images. The next repo is the Advanced Inference repo.|1 trelis_voice2_55.wav|This allows you to set up a server so that you can hit an endpoint for a custom model. You can do so on RunPod, Vast AI, or using a Llama CPP type server. There's also the option to deploy serverlessly using RunPod.|1 trelis_voice2_56.wav|It's quite useful for batch jobs that are less time sensitive, because it means you're not paying for the server when it's not being used, and it will just turn on when you need it, which is going to save you cost.|1 trelis_voice2_57.wav|There are also a number of scripts for making API calls, simple API calls, OpenAI style or TGI style, function calling API calls if you want to test out function calling performance of a model. Then there are speed tests for single queries and multiple queries.|1 trelis_voice2_58.wav|And there's also a more advanced technique called LLM-RAG, which is a version of RAG, but you retrieve the relevant snippets from a data set by using a language model as a classifier to tell you whether that snippet is going to be relevant or not.|1 trelis_voice2_59.wav|There's also a folder now on privacy, which allows you to basically hide information, like personal information on credit cards, names, email addresses, before you send it to a third-party API so that you can reduce any data privacy risks. Last of all, there's the advanced transcription repository.|1 trelis_voice2_60.wav|This one here allows you to generate data if you want to fine tune a whisper model and then do the fine tuning. And again, much of the 10 tips that I provided earlier are going to apply here for transcription. And that is it for my 10 tips on fine-tuning.|1 trelis_voice2_61.wav|If I've left anything out, please let me know below in the comments and I'll get back to you. In the meantime, if you want more information on Trellis resources, including free and paid, try out trellis.com. That's T-R-E-L-L-I-S.com forward slash about.|1 |