ANI

Fine Tuning Explained to Noobs (How Experienced Models Learn New Skills)

# Introduction

This article is part of my noob series where I write about questions that many people Google but may not understand because of the complicated math and everything. So, if you're here, you've probably heard of a good fix somewhere in the context of major linguistics types (LLMs) in particular. This concept already existed in traditional machine learning for years, but it gained popularity after LLMs because now suddenly everyone has access to these large, generic pre-trained models that you can adapt based on your tasks, your personal needs, and your voice. This act of adaptation is basically called fine tuningand it is now one of the most common things people do with LLMs. But you cannot understand it until you understand the step that comes before you, and that is “pre-training.” Fine-tuning is literally “tuning” something that already exists, and that “thing” is a pre-trained model. So, let's try to separate these concepts so that next time, when someone asks you about it, you know.

# What is Training?

If you start with a newly built model with millions or billions of parameters assigned to random numbers, and you try to teach it a specific task — let's say classifying movies into different categories — it has to learn the entire English language from scratch at the same time, which is impossible, especially with the limited dataset you might have. It's like teaching children biology before they understand language or basic science concepts first.

Pre-training solves this problem by learning robust and general objects once from a large amount of data. Computing and data requirements are very high in this category. But once you train it, you'll have a model that already understands the language. At this stage, you teach him a very simple skill: predicting the next word. You show the model a piece of text with the next hidden word, and it has to guess what comes next. A good guess gets a small loss, a bad guess gets a big one, and the model corrects.

Sketch of the first prototype

For example, in the diagram above, if we give a sentence “The cat is sitting on ____”the model reads that “mat” it's more likely than not “car”. Repeating this training on millions of sentences, books, and articles makes the model a predictor of the next word and forces it to absorb grammar, facts, thought patterns, and more. After pre-training, you have a model that already understands the language. All the work you build over time gets to stand on that foundation instead of starting at zero. That is why these are often called base models.

You probably haven't trained for anything beforehand. You download the finished result – a pre-trained model like Llama, The Mistralor Qwen – and start from there. This brings us to our real topic of fine tuning.

# What is Fine Tuning?

Many beginners think that once the model is trained, the weights are frozen forever. In fact, having a pre-trained model means that the weights are set to “good values” that combine intelligence and perform well in general tasks. Once you have this model, you can adapt that intelligence to your specific needs using task-specific data – and this is called “fine-tuning.” The data requirements for this stage are also much lower than for previous training, as you only need examples of the work you want to do.

It's very similar to how different chefs are trained at the same culinary school, and then when they join a restaurant, they learn restaurant-specific skills. Since we're not building something from scratch here, it's less expensive – similar to the idea that training someone completely new to a restaurant requires more effort than training someone who's already attended culinary school. The diagram below summarizes the difference between pre-training and planning.

Pretraining vs Fine-Tuning comparison diagram

# How is Fine Tuning Done?

We discussed the prediction of the next token and the pre-training process. Now, let's look at the fine-tuning loop.

A diagram of the training loop for fine tuning

You show the model an example of task-specific data – let's say a movie – ask it to categorize the movie and make a prediction, then compare its answer to the ideal, shift the weights a bit, and repeat the process until it gets better at the task below. There are also two major things that are done differently in fine tuning compared to pre-training:

  1. The data → Small, high-quality, task-specific data instead of the entire Internet.
  2. Reading level → Low learning rate and few passes, because we want the model to be flexible without overwriting its general capabilities.

# Two Common Types of Fine-tuning

Although you will find different definitions all over the internet, based on the number of parameter models you want to tune or adapt, fine-tuning falls into two categories:

Types of fine tuning diagram

  1. Perfect Tuning: In this setting, every parameter in your model is free to change. You use the above loop and all the billions of numbers are slowly converted into your function. The main problem with this method is the memory – you need enough to hold and update the whole model, which means that with a large LLM the hardware is critical. There is also the added risk of catastrophic forgetting, which means that a model becomes good at one task but loses its normal abilities at everything else.
  2. Parameter-Efficient Fine Tuning (PEFT): Instead of updating all the weights in the network, PEFT techniques fix the basic model – each original number remains locked – and introduce a small set of brand new, trainable numbers, to train those only. There are different techniques to achieve this, such as LoRA, QLoRA, and fast tuning, but the details of those are beyond the scope of this article. PEFT requires less memory and training time, with a lower risk of forgetting the information already learned. For most LLM courses, this is the default choice.

# Is Good Planning Always the Solution?

Tuning is great for teaching models a new skill, style, behavior, or task, but it's not the only tool – and often not the first one you should reach for. Better information can sometimes solve your problem without any training at all. Similarly, if it makes more sense to look up information on the Internet or in a database at the time of a query, retrieval-augmented generation (RAG) is a better fit, especially if the facts are large-volume or frequently changing. These methods are not competitors; in fact, many programs use them together. It's important to remember before you commit to a full planning run.

# Additional Services

If you want to practice debugging with LoRA, here are some recommended resources:

  • Face Hugging PEFT: A standard open source library for LoRA, QLoRA, fast tuning, and more. Start with the documentation and the repo.
  • TRL Face Hugs: Pairs with PEFT and gives you ready-made SFTTrainer in a supervised fine-tuning loop.
  • Misbehavior: A very beginner-friendly approach to LoRA/QLoRA, with free Colab and Kaggle books, ~2× faster training, and very low VRAM.
  • The Axolotl: Once you're comfortable, it's a popular config-driven (YAML) tool for fine-tuning pipelines without writing a lot of code.
  • The first LoRA paper: “LoRA: Low-Level Adaptation of Large-Scale Language Models.”
  • QLoRA paper: “QLoRA: Effective Preparation for LLMs.”

For a good starting project, grab a small tutorial model (something like an 8B Llama, Qwen, or Gemma), open the Unsloth QLoRA notebook, fine-tune it to a few hundred clean examples of your work, and watch the training losses drop. Once you've done it once, every term in this article will sound very clear.

Kanwal Mehreen is a machine learning engineer and technical writer with a deep passion for data science and the intersection of AI and medicine. He co-authored the ebook “Increasing Productivity with ChatGPT”. As a Google Generation Scholar 2022 for APAC, he strives for diversity and academic excellence. He has also been recognized as a Teradata Diversity in Tech Scholar, a Mitacs Globalink Research Scholar, and a Harvard WeCode Scholar. Kanwal is a passionate advocate for change, having founded FEMCodes to empower women in STEM fields.

Source link

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button