AI Engineer World's Fair 2024
Everything you need to know about Finetuning and Merging LLMs
Read the talk
Fine-tuning and merging LLMs: from instruction data to reusable weights
A base model can continue a question without answering it. Fine-tuning changes that behavior; model merging offers another way to reuse capabilities already learned by other models.
From a talk by Maxime Labonne
Before you start: Familiarity with language-model tokens, training loss and GPU memory will help; no prior fine-tuning or model-merging experience is required.
From completing questions to answering them
Why might a language model autocomplete your question instead of answering it? Pretraining teaches next-token prediction: given large amounts of raw text, the model learns to continue that text. The resulting base model has learned useful patterns, but an instruction is still text to continue. Supervised fine-tuning, or SFT, supplies question–answer pairs so that a similar prediction objective teaches the model to respond to instructions.
Preference alignment adds another stage. Instead of supplying only examples of answers, it supplies preferences about how the model should behave. In the lifecycle Maxime Labonne presents, raw-text pretraining produces a base model, SFT produces an instruction-following model, and preference alignment produces what is commonly called a chat model.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Establish whether prompting is enough
Fine-tuning starts with an evaluation problem. Begin with prompt engineering and establish what success means. Accuracy may require a custom benchmark for a niche application, or an existing open benchmark where one fits. Cost and latency belong in the same evaluation: a correct answer that is too expensive or too slow may still miss the requirement. If prompting meets those requirements, the problem is already solved.
If prompting falls short, ask whether you can create an instruction dataset: pairs of questions and desired answers. If you cannot, Labonne treats that as a reason to reconsider the project’s scope. If you can, fine-tuning becomes an option, and the evaluation framework you already built lets you test whether it helped.
The motivation is not exclusively technical. Labonne cites a16z’s 2024 enterprise report, whose interviews and survey emphasize control and customization as reasons to use open models. Fine-tuning is one way to exercise that customization. Those findings describe the enterprises surveyed, rather than a universal ordering of priorities.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Choose a training interface
After acknowledging Unsloth, covered in the preceding session, Labonne distinguishes three other training libraries by how you work with them.
| Library | Interface emphasized in the talk |
|---|---|
| TRL | Hugging Face library built on Transformers |
| Axolotl | Versatile training through YAML configurations |
| LLaMA-Factory | Built-in graphical interface |
These offer different entry points into training: a library integrated with the Transformers ecosystem, a configuration-driven workflow, or a graphical interface.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Separate context, answers and preferences
An SFT example separates the instruction from the answer. The system prompt steers behavior—for example, by asking for an explanation suitable for a five-year-old—while the user prompt supplies the task. Labonne’s task example asks the model to remove spaces from a sentence. In the training setup he describes, the system and user tokens remain available as context, but are masked out of the loss. The answer tokens receive the supervision. Masking therefore does not mean hiding the instruction from the model; it means not training the model to reproduce that part of the example.
Those answers need not all be written by people. Labonne describes synthetic data as common in SFT datasets and endorses generation with frontier models as a way to build high-quality examples. The generated answer is still the training target, so its quality matters just as much as a human-written answer’s quality.
Preference training changes the example format. Labonne names PPO, Direct Preference Optimization, KTO and IPO, describing DPO as the most popular in practice at the time. A preference example contains an instruction, a chosen answer and a rejected answer. The pair gives the model a positive and a negative example for the same request.
Labonne’s high-level intuition for DPO is to increase the probability of chosen answers relative to a reference version of the model that has not undergone this preference-training step. That is an intuition rather than a complete specification of the objective. His behavioral example prefers a refusal to a request for bomb-making instructions; preference training can also target better general performance, rather than refusal behavior alone.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Build data that teaches the intended behavior
What makes an instruction example useful? Labonne questions the reliability of human review alone and proposes three dimensions for judging samples:
- Accuracy: Answers should be factually correct and cleanly written. Training on false information risks damaging knowledge the model already has.
- Diversity: Cover the topics and writing styles relevant to the application. A specialized summarizer does not need the breadth of a general-purpose assistant, but it still benefits from variety within its scope.
- Complexity: Include tasks that demand more than retrieving a fact. Labonne points to reasoning-bearing answers, summarization and explanations for a five-year-old as examples that require the model to work with the prompt and transform information.
The preparation process is iterative:
- Start with existing open datasets where possible, combining sources that fit the intended application.
- Deduplicate with exact matching and fuzzy matching to remove repeated or near-repeated material.
- Filter for quality. Rules can remove unwanted response patterns; reward models or an LLM judge can score samples for filtering. Labonne’s rule-based example removes formulaic refusals, which is a choice about desired behavior rather than a universal quality rule.
- Inspect coverage. Lilac, Nomic Atlas and topic clustering can reveal how the dataset is distributed and suggest improvements.
- Generate additional data from those findings, then repeat the process.
Inspection feeds the next round of generation instead of serving only as a final check.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Decide which weights to train
Full fine-tuning takes the model and trains its weights on the instruction dataset. Labonne presents it as the strongest-performing but least efficient option in his comparison. LoRA reduces the trainable portion: it freezes the pretrained weights and adds trainable adapter matrices, A and B, at targeted layers. The adapters learn the update while the base weights remain fixed.
| Method | Trainable parameters | Base-weight storage described |
|---|---|---|
| Full fine-tuning | Model weights | Unquantized model |
| LoRA | Adapter matrices A and B | Frozen 16-bit weights |
| QLoRA | Adapter matrices | Frozen four-bit weights |
LoRA still requires loading the base model. QLoRA reduces that memory burden by quantizing the frozen base weights while retaining trainable adapters. Labonne warns about a performance trade-off, but degradation is not inevitable: the original QLoRA paper reports preserving 16-bit fine-tuning performance in its experiments. Neither that result nor the talk’s ordering guarantees the outcome for a particular task; the evaluation framework must settle it.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Find a stable learning rate and a workable memory budget
Learning rate is Labonne’s first tuning priority. It depends on the model and requires experiments. His suggested exploration is to try higher rates, observe where the loss becomes unstable, and reduce the rate from there. The exploding-loss graph illustrates a boundary to avoid, not a desirable training outcome.
The remaining choices interact:
- Epoch count: Choose how many passes to make with the size of the dataset in mind.
- Sequence length: Longer sequences consume more VRAM and constrain the batch size. Training does not have to use the pretrained model’s full context window.
- Batch size: Within memory limits, larger batches can improve GPU utilization.
- LoRA rank: This controls another part of the adapter setup, although Labonne names it without developing a detailed tuning procedure.
Sequence length and batch size therefore need to be chosen together: allocating more memory to each sequence leaves less room for sequences in a batch.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Reuse training already embodied in model weights
Model merging combines weights from existing fine-tuned models. Instead of creating every capability through your own training run, you can draw on models released by the open-source community, including those on Hugging Face Hub. The merging operation can run without a GPU; that does not eliminate the compute needed to run the resulting model.
Labonne reports that merged models occupy roughly the top eight to ten positions among 7B models in the Open LLM Leaderboard v1 snapshot shown in the talk. This is historical evidence: he says version two had launched that morning, while his slide still showed version one. The displayed ranking is a motivation to investigate merging, not a claim about current leaderboard standings.
His recommended tool is MergeKit, which implements multiple merging techniques. A source model can itself be a merge, so the ancestry quickly branches: the family-tree illustration connects models that were combined into other models, which were then merged again. Even the tree that fits on the slide is only a small example of that reuse.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Interpolate two models or combine sparse updates
SLERP, spherical linear interpolation, interpolates between two models’ weights. It merges two models at a time, but the interpolation factor can vary by layer, allowing different parts of the result to favor different sources. Labonne’s example is NeuralBeagle14-7B. Its ancestry matters: the model card identifies NeuralBeagle as a DPO fine-tune of Beagle14-7B, which was itself a merge. Its results therefore cannot be attributed to interpolation alone.
DARE takes a pruning-and-rescaling approach to reducing redundancy. Labonne describes this informally as retaining significant parameters. More precisely, the original DARE method randomly drops entries from the fine-tuning deltas—the changes relative to a base model—and rescales the retained deltas by 1 / (1 − p), where p is the drop probability. It does not select the largest raw model weights. This approach can be used to merge more than two source models.
For multi-model experiments, Labonne recommends trying seven or eight sources with DARE, based on his experience. That is practical guidance rather than a measured optimum: the useful distinction is that SLERP is pairwise, while the DARE-based approach he recommends can combine contributions from a larger group.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Repeat layers without another training run
Passthrough changes the construction more directly: concatenate layers from different LLMs, or reuse layers from the same model. The latter is a self-merge. Labonne describes creating Meta-Llama-3-120B-Instruct from Llama 3 70B Instruct by repeating a group of ten layers six times. This is layer stacking rather than interpolation between corresponding weights.
The counterintuitive part is that he did not train the enlarged model afterward. Labonne reports enthusiastic online reception, particularly for creative writing, while also describing the model as erratic. That is a reported use-case assessment, not evidence of general superiority. When a questioner asks whether there was any fine-tuning at all, he explicitly confirms there was none.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Assemble experts and initialize a router from prompts
A conventional mixture of experts, or MoE, is pretrained with a router and multiple feedforward networks. A FrankenMoE instead extracts feedforward layers from existing fine-tuned models, combines those layers as experts, and adds a router. The construction reuses already-trained components rather than pretraining the whole expert system from scratch.
For Beyonder, Labonne selects four fine-tuned sources with different specialties: chat, code, role-play and mathematics. The MergeKit configuration shown associates positive prompts with the experts. These prompts are not additional SFT examples in this construction; they help initialize routing.
The router’s decision happens for each token at each layer: which expert feedforward networks should process this token here? The described setup generally selects two experts. To initialize that behavior without a new fine-tuning run, the construction calculates embeddings from the positive prompts and uses those embeddings to initialize the routers. Further fine-tuning is possible, but it is not required for the assembly process Labonne demonstrates.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Evaluate the assembly against its sources
Labonne also describes Phixtral, for which he had to modify the implementation for compatibility with Phi-2. He reports that Phixtral outperformed its base model on multiple tasks. Even so, when performance is the priority, he recommends SLERP or DARE ahead of FrankenMoE, which he considers more experimental and less effective in his experience.
The final Beyonder comparison uses its own source models as baselines. Labonne reports that Beyonder outperforms those source models on multiple benchmarks. That makes the comparison particularly useful: it asks whether assembling the experts improves on the components already available, rather than comparing only with an unrelated model. The reported gains coexist with his preference for simpler merging techniques when seeking performance.
For hands-on continuation, Labonne points to his Large Language Model Course and its GitHub notebooks. The closing slide brings together entry points for merging, evaluation, SFT, DPO, Axolotl and quantization, so readers can move from these mechanisms to a concrete experiment.
Suggest correction
This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.
Resources
From the talk
Labonne's LLM learning roadmaps and practical Colab notebooks.
Tools and configuration documentation for merging pretrained language models.
Model card documenting NeuralBeagle's merged ancestry and subsequent DPO training.
Labonne's Llama 3 self-merge model card, including creative-writing guidance and limitations.
a16z's enterprise interviews and survey covering model selection, customization and spending intentions.
Further reading
A four-expert model assembled from chat, code, role-play and mathematics models.
Original research on randomly dropping and rescaling fine-tuning deltas before merging models.
Original QLoRA research explaining four-bit frozen base weights, trainable adapters and memory savings.
Read the complete timestamped transcript
- 0:00
[upbeat music] Hi, everyone.
- 0:15
Uh, in this session, we're gonna talk about, uh, everything you need to know about fine-tuning LLMs and model merging. Uh, quick intro, my name is Maxime Labonne. Uh, I'm a Staff Machine Learning Scientist at Liquid AI.
- 0:28
I'm also a Google Developer Expert. I write blog posts on these topics. I created the LLM Course, which is, uh, super popular on GitHub. Um, I also contributed to the open source community through models, uh, through tools, and I'm the author of, uh, Hands-On Graph Neural Networks using Python, uh, with Packt.
- 0:47
Um, so first of all, let's talk about fine-tuning. Uh, we saw a bit of fine-tuning in the previous session, so I'll try to not repeat too much. Uh, but basically, here's the LLM training lifecycle.
- 1:00
You see three stages. Uh, first of all, you have the pretraining stage, uh, where you give a lot of raw text to the model, and the idea is that the model learns to do, uh, next-token prediction.
- 1:12
The result of that is called a base model. This base model, uh, is really nice, uh, but if you ask it questions or instructions, it's going to autocomplete your question instead of answering it, which is why we have the supervised fine-tuning stage, where this time we give pairs of questions and answers to the model.
- 1:32
And, uh, we have a similar, uh, training objective, but the idea is that, uh, at the end of it, it's going to actually answer your questions and follow your instructions.
- 1:41
Then we have a third and final stage, the preference alignment stage, where we give, uh, human preferences to align the model to how we want it to behave, and the result is commonly referred to as chat model.
- 1:54
So when to use fine-tuning. Uh, here you can see a little flowchart that I've made. It's very high level. Uh, but basically, uh, there's a conversation about when to use prompt engineering, when to use fine-tuning.
- 2:07
I think it's good, in general, to start with prompt engineering if you can, and, uh, the idea is to have a really robust evaluation, uh, structure, where you have a lot of different metrics that you're interested in.
- 2:19
It can be, uh, the accuracy of the model. Uh, does it answer my question well? You can create a custom benchmark, uh, if you have a very niche use case, or you can reuse, um, open source benchmarks.
- 2:31
Also, in terms of cost, latency, because the question is, is it good enough? If it's good enough with just prompt engineering, then probably you don't need, uh, fine-tuning. The problem is solved.
- 2:40
Uh, congrats. Otherwise, the question is, can you make an instruction dataset? So can you create pairs of questions and answers, uh, to fine-tune the model? If it's not the case, it can be for multiple reasons, but it's probably a good sign that, uh, you need to rescope the project.
- 2:56
Uh, otherwise, fine-tuning is an option, and you can reuse the evaluation framework that you created, uh, to evaluate the model. Uh, so, so that was the technical answer, but you also have a non-technical answer to that.
- 3:08
Uh, here is a report from a16z, and the question is, why do enterprises care about open source? You can see that the, the two main items are actually control and customizability, and customizability is mostly about fine-tuning models.
- 3:22
So even if there's, like, arguments about the technical side and cost and agency, there's also, like, a strong argument for customizability and control over these models. So in terms of fine-tuning libraries, I think that you know about Unsloth now, uh, but I'm gonna talk about the other ones.
- 3:38
Uh, so TRL from, uh, Hugging Face, a great library built on top of Transformers, very easy to use. You have Axolotl, excellent library, uh, very versatile. Uh, you, you have a lot of, um, YAML config files.
- 3:51
And then you have LlamaFactory, uh, where you have a really good graphical user interface, uh, that is built in. So to talk a bit more about supervised fine-tuning, um, here you see an example of a sample that we, we give to the model.
- 4:06
So we have the instruction, which is both the system prompt and the user prompt, and the answer, which is the output. So in this, uh, in this case, the system prompt is used to steer the behavior of the model.
- 4:18
Uh, think like you're answering to a [REDACTED:age]. And the user actually gives the task, "Remove the spaces from the following sentence." We train the model usually, like, generally, on the output only, so we mask the rest.
- 4:32
It's used as context, and what we want to, to do is train the model to output the correct answer. Uh, most SFT datasets, I want you to say that use synthetic data, and that's perfectly fine.
- 4:42
Usually, it's generated with, uh, frontier models, and that's a, a great way of, uh, building high-quality datasets.
- 4:50
Then you have the preference alignments. I'm just gonna mention it here. Uh, there are a lot of different methods, PPO, DPO, KTO, IPO. Uh, in practice, Direct Preference Optimization is probably the most popular one.
- 5:01
Um, so here you see that you have a different format, uh, with an instruction, and you have a chosen answer, and a rejected answer. So the idea here is that you're going to show, like, a positive example, a negative example to the model.
- 5:14
And with DPO, the goal is to make sure that the model that you're currently training outputs higher probabilities, uh, for the chosen answers than the untrained version of the same model.
- 5:24
Not gonna delve, uh, too much into the details here, but this is the general idea and can be used to either censor the model. How to make a bomb, uh, the chosen answer would be, "As an AI assistant, I cannot tell you that."
- 5:35
Or it can also be used to, um, boost the performance of the model in general. Uh, how to create SFT datasets. So this is a very fundamental question, uh, in the post-training world.
- 5:47
Uh, and the, the main question is, okay, what's a good sample? Human evaluation is quite bad at, um, actually reviewing the samples, but what I like to define is, like, three main features.
- 5:59
The first one is the accuracy. We want the samples, the outputs to be, uh, factually correct. Um, maybe no typos would be good too. Uh, we don't want to compromise, uh, the knowledge of the model by giving it fake information.
- 6:15
Uh, then you have diversity. And diversity, you want to cover, um, as many topics as you can. Of course, it depends on your use case because if you do summarization, uh, you won't be as general as if you do, uh, general purpose fine-tuning.
- 6:28
Um, but it's always a good idea to include a lot of different, uh, topics, different writing styles, um, in this, uh, dataset. And finally, you have complexity. I think this one is, is a bit less trivial.
- 6:42
Uh, and it's about giving complex tasks to the model, forcing reasoning. So, for example, the output will have chain-of-thought reasoning because you want to train the model to have this kind of, of reasoning.
- 6:54
Or it can be task, like summarization, explain me like I'm a [REDACTED:age]. Uh, this kind of task really, um, force the model not to only answer the question like a QA with, um, answers you could find on Wikipedia.
- 7:08
It also forces it to reason over the, the prompt and, uh, give a more complex answer. So as a, a little recipe you can see here, um, I would recommend in general, uh, starting with open source datasets if you can.
- 7:22
Uh, combine some of them. Then you can apply different filters. The first one is data de-duplication. It can be either exact because you want to remove, uh, duplicates. It can be fuzzy, uh, so same, um, same idea.
- 7:36
And, uh, then you have data quality filters. Here you have different techniques. Can be rule-based filtering. Uh, for example, you want to remove every single row where you have, "As an AI assistant, I cannot..."
- 7:47
because people hate it. Uh, but you can also use, uh, more clever techniques like reward models or LLM-as-a-judge to evaluate the quality of each sample and filter out the bad samples.
- 7:59
And then you can use data exploration with different tools like Lilac, Atomic Atlas, text clustering to have, um, topic clustering to visualize your dataset, uh, to get ideas on how to improve it.
- 8:10
And with these ideas, you can, uh, go back to data generation and start the process all over again. In terms of L- SFT techniques, we have three main techniques.
- 8:19
Uh, full fine-tuning, this is like the most basic one. You take the base model and you just, uh, train it on the instruction, uh, dataset. It has the best performance, but is also, like, very inefficient in general.
- 8:31
A more efficient, uh, way of seeing it is LoRA. Uh, with LoRA, you are going to freeze all the pre-trained weights and you add adapters to each targeted layer.
- 8:41
Uh, these matrices A and B are these adapters. So you have, um... You don't train on all the parameters of the base model, you only train a subset of them.
- 8:53
Uh, so this is a, a lot faster, uh, but it can still be costly because you're still loading the entire model in, uh, six-bit, sixteen-bit precision here. So a more efficient way is to quantize, uh, the pre-trained model here in four-bit precision.
- 9:09
This is QLoRA, and, uh, you apply the same idea that you had with LoRA, but this time, uh, the, the weights are heavily quantized, so you have a lower VRAM usage.
- 9:19
But the problem is that it also degrades performance, so there's a trade-off here. Um, I want to briefly mention some hyperparameters, but Daniel al- already, uh, talked about a lot of them, so I, I'm gonna be brief.
- 9:30
I think the most important one is the learning rate. Uh, the learning rate is model-dependent. Uh, it requires a few experiments to be able to really tweak it and find the, the best one.
- 9:40
Generally, I would recommend to go as high as you can, uh, until your loss explodes, like in this graph. Uh, then you can, uh, reduce the size of the learning rate.
- 9:51
Uh, other super important hyperparameters, number of epochs. Um, I would say that depending on the size of your dataset, you can have, like, more or less epochs. Sequence length is also good, uh, because, um, it, it's a trade-off with the batch size because the longer, uh, sequence length you have...
- 10:08
So the, the bigger the context window, the more VRAM, uh, you're gonna use. Uh, but you don't need to use, uh, a sequence length that's as big as the pre-trained model.
- 10:17
Then you have the batch size. You want to maximize it to maximize the utilization of your GPUs. Um, and then you have, uh, the LoRA, uh, with the rank.
- 10:26
Um, this is, like, quite easy to, to, to fine-tune, so I don't want to go into the details here. Um, let's talk about model merging now. So model merging is the idea that you can take the weights of different fine-tuned models, and you can combine them together.
- 10:42
So you, you just can leverage, uh, what the open source community, uh, has, uh, produced on the Hugging Face, uh, Hub, for example.
- 10:53
Uh, it doesn't require any GPU, so it's super efficient, and it provides excellent results. Uh, so the Open LLM Leaderboard was updated this morning, uh, so we have a version two now.
- 11:04
But this is the version one. Uh, I haven't had time to update it. Uh, but you can see that for 7B, uh, parameter models, uh, the entire top eight or top 10 is just merged models.
- 11:16
Uh, so it really shows that, uh, this approach is extremely effective at producing high-quality models. Uh, and you can find similar results on, like, a really a lot of different datasets.
- 11:27
I would recommend using MergeKit. Uh, this is like the leading library in this, uh, in this space, uh, with a lot of different techniques that are implemented there. Um, so here you can see the family tree of, uh, merged models.
- 11:40
Uh, so in... You don't really need to see the, the name of the model, but you see that every node is actually a model. And we actually merge different merges together until it becomes like a giant family tree.
- 11:53
This one is actually quite small. Like, it can get a lot crazier than that, but it didn't fit in, on one slide, so I, I chose this one instead.
- 12:01
Um, about the merge techniques themselves, I want to mention- Like a few of them. The first one is called SLERP. It stands for spherical linear interpolation. So the idea is really to apply spherical but, uh, linear interpolation, uh, with the weights of different models.
- 12:19
You can only merge two models at the same time with this technique, uh, but you can really tweak it, uh, with different, uh, interpolation factors for different layers. Uh, here's a model that I've made, you know, Beagle, uh, 14-70 B, uh, which was a really, um, efficient way of, uh, leveraging, uh, the, uh, different models that were
- 12:39
created by the open source community. And then you have DARE. Uh, so in DARE you want to reduce the redundancy of the model parameters. Uh, to do that you're gonna use pruning.
- 12:49
You're gonna select the most significant parameters in your model weights, and you're gonna rescale, um, the weights of these, uh, source models. Uh, the advantage that it has is that you can merge different models, not just two, but even more together.
- 13:04
And, uh, I would advise, uh, I would recommend this technique, and not with just two model, not with three, but like, with seven or eight models. It works really, really well, uh, so I strongly recommend that.
- 13:17
Uh, then you have a very funny, um, uh, technique called passthrough. And in passthrough you can concanate, concatenate, uh, layers from different LLMs. Um, it can also be the same one.
- 13:28
We call it self-merge. Um, and so here you have an example that I've made, uh, recently. It's called Meta Llama 3 120B Instruct because I took Llama 3 70B Instruct and I just, uh, repeated 10 layers 6 times.
- 13:43
Uh, so you could say, like, this shouldn't work at all. Like, come on, uh, you, you haven't even trained the model. This is ridiculous. Uh, but actually, yeah, this is ridiculous.
- 13:52
Uh, people loved it on Twitter and Reddit and online in general. Uh, so it, it shows that, uh, there's a lot of things that we can still discover, uh, with these m- merge techniques, with these models.
- 14:06
Uh, they do not, um... They can be counterintuitive sometimes, and you can see that this model in particular was particularly good at, uh, creative writing. Uh, it was also quite unhinged in general, but, uh, really good at creative writing and, uh, now it's being used by a lot of people, uh, even though it's, it's super big.
- 14:24
But no kind of fine-tuning at all?
- 14:26
No, no fine-tuning. Nothing. Um, and then I want to mention the last techniques, uh, which is called mixture of experts. Uh, so in traditional mixture of experts you are going to pre-train a model, uh, with a router you can see on the bottom here, and different feedforward network layers.
- 14:46
And you pre-training, pre-train it from scratch. But you can do something quite smart, uh, with merging, where you extract the feedforward network layers from different fine-tune models and you combine them together, uh, like this.
- 15:00
So we call this a FrankenMoE. You add a router. You combine the FFN layers from different, uh, models, and this is how you create, like, your kind of, uh, mixture of experts.
- 15:12
It's actually, uh, pretty cool. It, it works pretty well in practice. Uh, you can see on the left a MergeKit config, uh, for the Beyonder, uh, model. Uh, so for this model I selected four different, uh, fine-tune models.
- 15:27
One, uh, as a chat model, one as a code model, one as a role play model, and one as a math model. You can see that I'm using positive prompts here.
- 15:35
So actually i- it's, it's a way to initialize the router, because if you go back to the previous, uh, slide, we can see that the router is supposed to, uh, select for each token and each layer where, like, which feedforward network, uh, layer is going to be used.
- 15:52
We used to, uh, in general. Um, and so how do we initialize it if we do not fine-tune it? Once again, we don't want to fine-tune it. We can, but we, we don't necessarily want to.
- 16:02
In this case, we're just going to use these positive prompts, uh, calculate the embeddings, and use these embeddings to initialize, uh, the routers, and that works really, really well.
- 16:11
So those are two models that I've used. For Fixtrol I had to modify it to make it compatible with Phi-2, and, uh, that outperformed the base model, uh, on a lot of task.
- 16:22
Um, so it's really a good technique to, to use in general. But I would say that, um, if you compare it to merging, uh, as we saw with SLERP and with DARE, I would say that, um, if you, uh, want to increase the performance, it's better to use, uh, SLERP and DARE instead of mixture of experts because
- 16:43
this is a bit more experimental. Uh, this doesn't... This will not bring you the same level of performance. Um, and here you can see the results of, uh, the Beyonder, uh, model.
- 16:55
Uh, you can see that the other models I'm comparing to are the source models that I've used in this, in this merge. Uh, so it, it's quite remarkable to see that it's actually performing better than the source models, um, on the, on a lot of different benchmarks.
- 17:11
Um, so yep, that's it for me. Uh, thank you for your attention. Uh, if you are interested in, uh, knowing more, if you want notebooks, uh, to, to run some code, I created the Large Language Model Course.
- 17:25
All these notebooks are available on GitHub, uh, llm-course. And, uh, yeah, thank you. [audience applauds] [upbeat music]