How does Model Merging work?
- Authors
- Name
- Amit Shekhar
- Published on
Model merging is the process of combining the weights of two or more models into a single new model, using methods like SLERP, TIES, and DARE, without any new training.
In this blog, we will learn about how model merging works. We will also see why we need it, how simple averaging works, how SLERP, TIES, and DARE combine the weights of different models, how they differ, and when to use which one.
We will cover the following:
- What are weights?
- What is model merging?
- Why do we need model merging?
- The simplest merging: averaging the weights
- SLERP (Spherical Linear Interpolation)
- TIES (Trim, Elect Sign, and Merge)
- DARE (Drop And REscale)
- SLERP vs TIES vs DARE
- When to use which one
I am Amit Shekhar, Founder @ Outcome School, I have taught and mentored many developers, and their efforts landed them high-paying tech jobs, helped many tech companies in solving their unique problems, and created many open-source libraries being used by top companies. I am passionate about sharing knowledge through open-source, blogs, and videos.
I teach AI and Machine Learning at Outcome School.
Let's get started.
What are weights?
Before jumping into model merging, we must know what is inside a model. Inside every model, there are numbers. These numbers are called weights. They are learned during training, and they decide how the model behaves.
Let's say a model is a giant recipe. The weights are the exact quantities of each ingredient in that recipe. Change the quantities, and the dish tastes different. Change the weights, and the model behaves differently.
A small model has millions of weights. A large model has billions of weights. Each weight is just a number, like 0.42 or -1.3.
So, a model is a huge collection of numbers called weights. When we train a model, we update these numbers until the model becomes good at the task.
Now, it's time to learn about model merging.
What is model merging?
Model merging is the process of combining the weights of two or more models into a single new model.
In simple words, we take the numbers from many models and mix them together to make one model that has the strengths of all of them.
Means, we do not train a new model from scratch. We do not collect new data. We just take models that already exist and blend their weights.
The best way to learn this is by taking an example.
Let's say we have two models. One model is great at writing code. Another model is great at writing in the Hindi language. We want one single model that can do both. Instead of training a brand new model, we merge these two models. The merged model can now write code and write in Hindi.
So, we get a more capable model without spending money on training.
So, how is this even possible? The answer is that these models often share the same structure. They have the same number of weights arranged in the same way. So, the weight at one position in the first model lines up with the weight at the same position in the second model. Because they line up, we can combine them.
We can see this in a diagram like below:
Model A weights Model B weights
+----+----+----+ +----+----+----+
| .4 | .2 | .9 | | .8 | .6 | .1 |
+----+----+----+ +----+----+----+
| | | | | |
| | | | | |
↓ ↓ ↓ ↓ ↓ ↓
combine same positions together
| | |
↓ ↓ ↓
+----+----+----+
| .6 | .4 | .5 | Merged model
+----+----+----+
Here, we can see that each weight in Model A lines up with the weight at the same position in Model B. We combine the first weight with the first weight, the second with the second, and so on. The result is one merged model that has a value at every position.
Note: Model merging works only when the models have the same architecture. We cannot merge two models that are built differently. They must have the same shape so that their weights line up.
Now, let's understand why we need it.
Why do we need model merging?
Training a model is very expensive. It needs a lot of data, a lot of time, and a lot of computing power. Not everyone can afford this.
Model merging comes to the rescue.
A few reasons why model merging is useful:
- It is cheap. We do not need expensive training.
- It is fast. Merging takes minutes, not weeks.
- It needs no training data. We need only the existing models.
- It combines skills. One merged model can do many tasks.
Planning your move into AI?
No matter which tech domain you work in today, with your effort, you can transition to these roles:
- AI Engineer
- Forward Deployed Engineer
- AI Agent Engineer
- Harness Engineer
- Voice AI Engineer
- AI Architect
- LLM Engineer
- LLM Inference Engineer
- Gen AI Engineer
- MLOps Engineer
- ML Engineer
- Deep Learning Engineer
Our AI and Machine Learning Program at Outcome School takes you there.
Now, let's learn how to do it.
The simplest merging: averaging the weights
The simplest way to merge two models is to take the average of their weights.
Let's say the first model has a weight 0.4 at one position. The second model has a weight 0.8 at the same position. The average is (0.4 + 0.8) / 2 = 0.6. So, the merged model gets 0.6 at that position.
We do this for every single weight. We line them up and average them one by one.
Let's see the code for this simple averaging as below:
# weights from two models at the same position
model_a_weights = [0.4, 0.2, 0.9]
model_b_weights = [0.8, 0.6, 0.1]
merged_weights = []
for a, b in zip(model_a_weights, model_b_weights):
merged_weights.append(round((a + b) / 2, 2))
print(merged_weights)
This will print the following:
[0.6, 0.4, 0.5]
Here, we can see that we took each pair of weights and found the average. We round it to 2 decimal places to keep the output clean. The first pair 0.4 and 0.8 gave us 0.6. The second pair 0.2 and 0.6 gave us 0.4. The third pair 0.9 and 0.1 gave us 0.5. This is the merged model.
This averaging is also called Linear Interpolation. It draws a straight line between the two sets of weights and picks a point on that line.
Simple averaging often gives a weak result. When we average two strong models, the merged model can become worse than both. The skills get blurred instead of combined.
The issue with this approach is that when the two sets of weights point in different directions, straight-line averaging shrinks and blurs them. Let's see how the next approach solves this issue.
SLERP (Spherical Linear Interpolation)
SLERP stands for Spherical Linear Interpolation. It is a better way to blend two models.
We already learned that interpolation means picking a point between two values. The new word here is Spherical. It means we blend along a curve on a sphere, not along a straight line.
Now, the question is, why a curve and not a straight line?
The best way to understand this is by taking an example.
Suppose we are standing on the Earth, and we want to travel from one city to another city. The Earth is a ball, which means a sphere. If we dig a straight tunnel through the ground, that is the straight line. But we cannot travel like that. We travel along the curved surface of the Earth. That curved path is the natural path on a sphere.
SLERP does the same thing with weights. Instead of cutting a straight tunnel between two models, it walks along the smooth curve. This keeps the size of the weights steady and preserves their structure.
We can picture the two paths as below:
curved path (SLERP)
. . . . . . . . .
. .
. .
Model A - - - - - - - - - - - - Model B
start straight tunnel end
(simple averaging)
Here, we can see that simple averaging takes the straight tunnel directly between Model A and Model B. SLERP instead walks along the curved path on the surface. The curved path is the natural route on a sphere, so it keeps the size of the weights steady while moving from one model to the other.
Let's understand the blend amount. SLERP uses a value called t. This t decides how much of each model we take.
- When
t = 0, the merged model is fully the first model. - When
t = 1, the merged model is fully the second model. - When
t = 0.5, the merged model is a balanced mix of both.
So, we control the blend by changing t. If we want more of the first model, we keep t small. If we want more of the second model, we keep t large.
Here is the simple idea of SLERP in code as below:
import numpy as np
def slerp(model_a, model_b, t):
# angle between the two weight directions
angle = np.arccos(np.dot(model_a, model_b) /
(np.linalg.norm(model_a) * np.linalg.norm(model_b)))
sin_angle = np.sin(angle)
factor_a = np.sin((1 - t) * angle) / sin_angle
factor_b = np.sin(t * angle) / sin_angle
return factor_a * model_a + factor_b * model_b
Here, we can see what SLERP does. First, it finds the angle between the two sets of weights. Then, it uses that angle to walk along the curve instead of the straight line. The factor_a and factor_b are the amounts of each model based on the blend value t. The result is a smooth blend that respects the curved path.
The value inside np.arccos is the cosine similarity of the two sets of weights. We have a detailed blog on How does Cosine Similarity work? that explains how it measures the angle between two vectors.
Note: SLERP normally works with only two models at a time. If we want to merge more than two models, we merge two, then merge the result with the next one, and so on.
A quick note for you
No matter which tech domain you work in, get familiar with these topics:
- LLM
- RAG
- MCP
- Agent
- Fine-tuning
- Quantization
We put it all together in one video:
AI Engineering Explained: LLM, RAG, MCP, Agent, Fine-Tuning, and Quantization
No need to stop reading - bookmark it and watch later when you get time. Future you will thank you.
Now, let's get back to the topic.
Now, it's time to learn about TIES.
TIES (Trim, Elect Sign, and Merge)
When we merge many models at once, a new problem appears. The models start to conflict with each other.
Let's understand this conflict first.
Suppose three models are merging. For one weight, the first model wants to push it up, which means it wants a positive value. The second model also wants to push it up. But the third model wants to pull it down, which means it wants a negative value. This is a conflict. If we just average them, the conflict creates a weak and confused result.
So, here comes TIES to the rescue.
TIES stands for Trim, Elect Sign, and Merge. It is a method that handles conflicts when merging many models.
Before we go further, we must understand two important ideas called the base model and the delta.
A base model is the original model we start from before any extra training. Fine-tuning means taking that base model and training it a little more on a new task so it becomes good at that task.
The delta is the change that fine-tuning added to the base model.
Let's say we start with a base model. We fine-tune it to make it good at a new task. The fine-tuned weights are slightly different from the base weights. The difference between them is the delta.
TIES works on these deltas in three steps.
Step 1 (Trim): Most of the deltas are very small and do not matter much. TIES throws away the small ones and keeps only the largest, most important changes.
Step 2 (Elect Sign): For each weight, TIES looks at all the models and decides one direction. It adds up the deltas from all the models. If the total is positive, the final direction is up. If the total is negative, the final direction is down. This is like a voting system where bigger changes get bigger votes.
Step 3 (Merge): Now that we have decided the direction, TIES keeps only the deltas that agree with the elected direction. It averages those, and ignores the ones that disagree. Then it adds this result back to the base model.
We can see these three steps in a diagram like below:
Deltas for one weight position:
Model 1: +0.8 Model 2: +0.5 Model 3: -0.6
↓
Step 1: Trim (all three are big, so all three are kept)
↓
Step 2: Elect Sign (+0.8 + 0.5 - 0.6 = +0.7, so the sign is up)
↓
Step 3: Merge (keep +0.8 and +0.5, ignore -0.6)
↓
Average of the kept deltas = (0.8 + 0.5) / 2 = 0.65
↓
Add 0.65 to the base model weight
Here, we can see that three models each suggest a change for the same weight. Two of them push up and one pushes down. The total is positive, so the voting step elects up. The merge step keeps only the two deltas that agree with up, averages them, and ignores the one that disagrees. This removes the conflict.
Let's see the simple idea of TIES in code as below:
import numpy as np
def ties_merge(deltas):
# Step 1: Trim - keep only the larger changes (simplified)
trimmed = [np.where(np.abs(d) > 0.1, d, 0.0) for d in deltas]
# Step 2: Elect Sign - vote on the direction
total = np.sum(trimmed, axis=0)
elected_sign = np.sign(total)
# Step 3: Merge - keep only deltas that agree with the elected sign
merged = np.zeros_like(total)
count = np.zeros_like(total)
for d in trimmed:
agree = (np.sign(d) == elected_sign) & (d != 0)
merged += np.where(agree, d, 0.0)
count += agree
# average the kept deltas, then we add this to the base model
return merged / np.maximum(count, 1)
Here, we can see the three steps in action. First, trimmed drops the small changes and keeps the big ones. Then, elected_sign votes on the final direction for each weight. Finally, the loop keeps only the changes that agree with the elected direction, and we average them. The disagreeing changes are ignored, so the conflict is removed.
This is how TIES solves the conflict between models.
To learn Fine-tuning, Parameter-Efficient Fine-Tuning (PEFT), and how a base model changes during training, check out our AI and Machine Learning Program at Outcome School.
Now, let's learn about DARE.
DARE (Drop And REscale)
When we merge many fine-tuned models, their deltas overlap and interfere with each other. Interfere means the changes get in each other's way. Too many changes pile up at once and confuse the model.
So, here comes DARE to the rescue.
DARE stands for Drop And REscale. It reduces the interference by removing most of the deltas and fixing the leftover ones.
DARE works on the deltas in two steps.
Step 1 (Drop): DARE randomly throws away most of the deltas and sets them to zero. As per the DARE paper, we can often drop a very large portion, like ninety percent, and the model still works well.
Step 2 (Rescale): When we drop most of the deltas, the total effect becomes too weak. So, DARE makes the remaining deltas bigger to make up for the dropped ones. This rescaling keeps the overall strength the same.
Let's understand the rescaling with a simple example. Suppose we drop ninety percent of the deltas. That means we keep only ten percent. To keep the same total strength, we make the leftover deltas ten times bigger. So, we divide the kept values by the fraction we kept.
We have a detailed blog on Dropout in Neural Networks that explains this same drop-and-rescale idea step by step.
Let's see the simple idea of DARE in code as below:
import numpy as np
def dare(delta, drop_rate=0.9):
# Step 1: Drop - randomly keep some values, zero out the rest
keep_mask = np.random.rand(*delta.shape) > drop_rate
dropped = delta * keep_mask
# Step 2: Rescale - boost the survivors to keep the strength
rescaled = dropped / (1 - drop_rate)
return rescaled
Here, we can see the two steps. First, keep_mask randomly decides which deltas to keep and which to drop. With a drop_rate of 0.9, we drop about ninety percent and keep about ten percent. Then, rescaled divides the survivors by (1 - drop_rate), which is 0.1, making them ten times bigger. This keeps the total effect strong even after dropping so much.
Note: DARE is often used as a cleaning step before TIES. We first run DARE to thin out each model, then run TIES to merge them.
This is how DARE reduces interference. It keeps only a small part of each model's changes and makes them stronger.
Stay updated: Subscribe to our newsletter to get our latest AI and Machine Learning blogs straight to your inbox.
Now that we have learned about SLERP, TIES, and DARE, it's time to compare them.
SLERP vs TIES vs DARE
Let me tabulate the differences between SLERP, TIES, and DARE for your better understanding.
| Point | SLERP | TIES | DARE |
|---|---|---|---|
| Full form | Spherical Linear Interpolation | Trim, Elect Sign, and Merge | Drop And REscale |
| Main idea | Blend along a smooth curve | Vote on direction and remove conflicts | Drop most changes and rescale the rest |
| Number of models | Usually two at a time | Many models at once | Many models at once |
| Main problem it solves | Weak blend from straight-line averaging | Models fighting over directions | Changes piling up and interfering |
| Works on | The raw weights | The deltas from a base model | The deltas from a base model |
| Often combined with | Used alone for two models | Often used after DARE | Often used before TIES |
Now, we have understood the differences. Now, let's learn when to use which one.
When to use which one
- Use SLERP when we want to blend just two models smoothly. It is the simplest strong choice for two models.
- Use TIES when we are merging many models and they disagree with each other. It removes the conflicts by voting.
- Use DARE when many model changes are piling up and interfering. It thins them out and keeps the strength.
- Use DARE and TIES together when we want the best of both. First clean with DARE, then merge with TIES.
Now we must have understood how model merging works and how SLERP, TIES, and DARE combine models into one model without any new training.
Frequently Asked Questions
Can we merge two models with different architectures?
No. Model merging works only when the models have the same architecture. Their weights must have the same shape and be arranged in the same way, so that the weight at one position in the first model lines up with the weight at the same position in the second model. Models built differently cannot be merged.
Does model merging need training data or a GPU for training?
No. Model merging needs no new training and no training data. We only need the models that already exist, and we combine their weights directly. This is why merging is cheap and fast, taking minutes instead of the weeks that training can take.
Can SLERP merge more than two models?
Not in one step. SLERP normally works with only two models at a time. To merge more than two models with SLERP, we merge two models first, then merge the result with the next model, and so on until all the models are combined.
How much of the deltas can DARE drop?
A lot. As per the DARE paper, we can often drop a very large portion of the deltas, like ninety percent, and the model still works well. DARE then rescales the remaining deltas by dividing them by the fraction kept, so the overall strength stays the same.
That's it for now.
Thanks
Amit Shekhar
Founder @ Outcome School
You can connect with me on:
Follow Outcome School on:
