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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# AIM: does activation-informed merging change what makes a merge work?
|
| 2 |
+
|
| 3 |
+
**Status: INTERIM.** The mechanism analysis (section 2) is complete and stands on its own. The
|
| 4 |
+
paired property panel (section 3) is running; this file is appended to as cells land. Namespaced
|
| 5 |
+
to `results/aim/`, `figures/aim/` — nothing here touches the MergeBench analysis.
|
| 6 |
+
|
| 7 |
+
**Substrate.** `ahn1376/aim-merged-checkpoints-with-aim` and
|
| 8 |
+
`ahn1376/aim-merged-checkpoints-baseline-w-o-aim`, 20 merged 13B checkpoints each (each collection
|
| 9 |
+
also lists the arXiv id `2502.02421`, which is not a model), perfectly matched on
|
| 10 |
+
operator × task combination: {TaskArithmetic, Ties, DARETaskArithmetic, DARETies, WIDEN} ×
|
| 11 |
+
{Code-Math, Code-Instruction_Tuned, Math-Instruction_Tuned, Code-Math-Instruction_Tuned}.
|
| 12 |
+
Base model `unsloth/llama-2-13b`; parents WizardLM-13B-V1.2, WizardMath-13B-V1.0,
|
| 13 |
+
llama-2-13b-code-alpaca. ω = 0.4, the paper's setting.
|
| 14 |
+
|
| 15 |
+
**No benchmark was run.** The merge-outcome column is the AIM paper's own published table,
|
| 16 |
+
transcribed from the method repo's README into `results/aim/published_scores.csv`: six benchmarks
|
| 17 |
+
(HumanEval, MBPP, MMLU, MATH, GSM8K, IFEval) plus the paper's HV gain, for all 40 merged
|
| 18 |
+
checkpoints and the four endpoints. Coverage of these checkpoints is complete, so the fallback
|
| 19 |
+
in the brief was not needed.
|
| 20 |
+
|
| 21 |
+
---
|
| 22 |
+
|
| 23 |
+
## 1. What AIM is, exactly
|
| 24 |
+
|
| 25 |
+
Read off `MergeModels/ActivationMerging/_utils.py::relax_on_merged` in the method repo. For every
|
| 26 |
+
weight matrix that is not an embedding table:
|
| 27 |
+
|
| 28 |
+
```
|
| 29 |
+
s_j = base model's mean |input activation| on input channel j (pile-val, 256 samples x 512 tok)
|
| 30 |
+
a_j = |s_j| / max_j |s_j| in [0, 1]
|
| 31 |
+
r_j = 1 - a_j (1 - omega) in [omega, 1]
|
| 32 |
+
W_AIM = W_base + (W_merged - W_base) * r_j broadcast over output rows
|
| 33 |
+
```
|
| 34 |
+
|
| 35 |
+
Three things follow immediately, and they frame everything below.
|
| 36 |
+
|
| 37 |
+
- **AIM does not change the merge.** It is a post-hoc, closed-form shrinkage of the *already
|
| 38 |
+
merged* model back toward the base model. `performAIM.py` takes a finished merged checkpoint as
|
| 39 |
+
input. Whatever operator produced `W_merged` is irrelevant to the transform.
|
| 40 |
+
- **It is a per-input-channel rescaling**, not a per-weight one: `r` is a vector of length
|
| 41 |
+
`in_features`, constant down each column.
|
| 42 |
+
- **`model.embed_tokens` is exempt** (the `'embed' not in name` guard), so the merged embedding
|
| 43 |
+
table survives untouched. `lm_head` is *not* exempt and is shrunk.
|
| 44 |
+
|
| 45 |
+
## 2. Does AIM do what it claims? (mechanism, complete)
|
| 46 |
+
|
| 47 |
+
### 2.1 The published checkpoints are exactly the closed form — recovered from public artefacts
|
| 48 |
+
|
| 49 |
+
`scripts/aim/aim_weight_mechanism.py` streams the three checkpoints (base, baseline merge, AIM
|
| 50 |
+
twin) tensor by tensor out of the safetensors shards and fits, per input channel, the
|
| 51 |
+
least-squares gain carrying `W_merged - W_base` to `W_AIM - W_base`. (Least squares, not
|
| 52 |
+
elementwise ratios: the checkpoints are stored in bf16, so the deltas carry ~2^-8 relative
|
| 53 |
+
quantisation noise that makes elementwise ratios meaningless while leaving the projection well
|
| 54 |
+
determined.)
|
| 55 |
+
|
| 56 |
+
On `TaskArithmetic / Code-Math`:
|
| 57 |
+
|
| 58 |
+
| quantity | predicted by the stated rule | recovered |
|
| 59 |
+
|---|---|---|
|
| 60 |
+
| min over channels of `r_j` | ω = 0.4 exactly | **0.396** (median over tensors) |
|
| 61 |
+
| max over channels of `r_j` | 1.0 exactly | **0.998** |
|
| 62 |
+
| variance of `W_AIM - W_base` explained by a per-channel gain | 1.0 | **R² = 0.9989** |
|
| 63 |
+
| `embed_tokens` Frobenius ratio | 1.0 (exempt) | **1.0000** |
|
| 64 |
+
|
| 65 |
+
### 2.2 The shrinkage is keyed to the *base model's* activations — confirmed independently
|
| 66 |
+
|
| 67 |
+
`scripts/aim/aim_salience_check.py` measures `s` itself: the same forward hook AIM uses, on the
|
| 68 |
+
base model, on pile-val (135 blocks × 512 tokens), and compares the salience **implied by the
|
| 69 |
+
published checkpoint pair**, `â_j = (1 - r_j)/(1 - ω)`, against the salience **measured from the
|
| 70 |
+
base model**.
|
| 71 |
+
|
| 72 |
+
Over 281 (tensor, module) pairs:
|
| 73 |
+
|
| 74 |
+
- median Pearson **r = 0.9921** (5th percentile 0.952, minimum 0.891)
|
| 75 |
+
- median absolute error **0.026** on a 0–1 scale, median fitted slope 1.04
|
| 76 |
+
|
| 77 |
+
So AIM's claim — that it preserves the weights the base model's activations single out — is
|
| 78 |
+
**true as stated, and verifiable without running the merge, the calibration, or a benchmark**.
|
| 79 |
+
|
| 80 |
+
### 2.3 But the intervention is far smaller, and far more concentrated, than the framing suggests
|
| 81 |
+
|
| 82 |
+
This is where the interesting part is.
|
| 83 |
+
|
| 84 |
+
- **Total weight change removed: 7.3%.** Summed over every non-embedding tensor,
|
| 85 |
+
`||ΔW_AIM||_F / ||ΔW_merge||_F = 0.927`. AIM keeps 93% of the merge's task vector.
|
| 86 |
+
Cosine between the AIM delta and the baseline delta is **0.999** (median per tensor).
|
| 87 |
+
- **The protection lands on almost nothing.** Because `a_j` is normalised by its *maximum* and
|
| 88 |
+
LLaMA's residual stream has massive activation outliers, the salience vector is extremely
|
| 89 |
+
peaked. Median fraction of input channels with `a_j > 0.5` (i.e. delta cut by more than 30%):
|
| 90 |
+
|
| 91 |
+
| module | frac. channels `a > 0.1` | frac. `a > 0.5` |
|
| 92 |
+
|---|---|---|
|
| 93 |
+
| `self_attn.{q,k,v}_proj` | 0.0098 | 0.0021 |
|
| 94 |
+
| `self_attn.o_proj` | 0.399 | 0.0018 |
|
| 95 |
+
| `mlp.{gate,up}_proj` | 0.9998 | 0.0031 |
|
| 96 |
+
| `mlp.down_proj` | 0.272 | 0.0005 |
|
| 97 |
+
| `lm_head` | 0.012 | 0.0008 |
|
| 98 |
+
|
| 99 |
+
Across all modules, **0.2% of input channels** carry `a_j > 0.5`.
|
| 100 |
+
|
| 101 |
+
- **A single scalar per tensor reproduces AIM to 99.85%.** Fitting one activation-*agnostic*
|
| 102 |
+
scalar per tensor instead of the full per-channel profile explains R² = 0.99846 of
|
| 103 |
+
`W_AIM - W_base`, against R² = 0.99885 for the full profile. The activation-informed targeting
|
| 104 |
+
accounts for a quarter of an already-tiny residual.
|
| 105 |
+
|
| 106 |
+
That last line is the reason section 3's control exists. If a magnitude-matched *uniform* shrink
|
| 107 |
+
reproduces 99.85% of what AIM does to the weights, then the burden is on the activation-informed
|
| 108 |
+
part to show it does something in *activation* space that the uniform control does not — which is
|
| 109 |
+
exactly AIM's claim, and exactly what a with/without benchmark comparison cannot separate.
|
| 110 |
+
|
| 111 |
+
### 2.4 Where the protection lands: AIM is mostly an MLP-input intervention
|
| 112 |
+
|
| 113 |
+
`a_j` is normalised by the **maximum** channel, not the mean, so how much AIM does to a weight
|
| 114 |
+
matrix is decided by how outlier-heavy that matrix's input is. LLaMA's residual stream has a few
|
| 115 |
+
massive activation channels; the layers that read it therefore get almost no protection anywhere
|
| 116 |
+
except on those channels, while the layers whose input is flatter get broad shrinkage.
|
| 117 |
+
|
| 118 |
+
Measured on the base model (`results/aim/base_calib_scale.npz`), median over the 40 blocks:
|
| 119 |
+
|
| 120 |
+
| module | max/mean salience ratio | frac. channels `a>0.1` | mean `a` | implied mean gain `r` | measured `‖ΔW_AIM‖/‖ΔW_merge‖` |
|
| 121 |
+
|---|---|---|---|---|---|
|
| 122 |
+
| `mlp.gate_proj` / `mlp.up_proj` | 5.0 | 1.000 | 0.199 | 0.881 | **0.891** |
|
| 123 |
+
| `self_attn.o_proj` | 9.4 | 0.399 | 0.107 | 0.936 | 0.956 |
|
| 124 |
+
| `mlp.down_proj` | 10.0 | 0.272 | 0.100 | 0.940 | 0.958 |
|
| 125 |
+
| `self_attn.{q,k,v}_proj` | 15.0 | 0.010 | 0.067 | 0.960 | **0.980** |
|
| 126 |
+
| `lm_head` | 23.9 | 0.012 | 0.042 | 0.975 | 0.981 |
|
| 127 |
+
| `model.embed_tokens` | — | — | — | exempt | **1.000** |
|
| 128 |
+
|
| 129 |
+
So AIM at ω = 0.4 removes about 11% of the merge's delta on the MLP gate and up projections and
|
| 130 |
+
about 2% on attention Q/K/V, and nothing at all from the embedding table. Calling it "preserving
|
| 131 |
+
the base model's salient weights" is accurate but undersells how uneven the result is: the same
|
| 132 |
+
hyperparameter buys a five-fold different intervention depending on how outlier-heavy the input to
|
| 133 |
+
a given matrix happens to be.
|
| 134 |
+
|
| 135 |
+
The protected residual-stream channels are the expected ones and are stable with depth — channels
|
| 136 |
+
{31, 110, 359, 371, 1160, 1419, 1554, 2200, 3837, 4283, 4923} carry `a > 0.5` in at least half the
|
| 137 |
+
blocks, and the top-8 sets of two randomly chosen blocks overlap 62% on average.
|
| 138 |
+
|
| 139 |
+
## 3. The activation-space test, and the property panel
|
| 140 |
+
|
| 141 |
+
Running (`scripts/aim/run_aim.sh`, two shards on GPUs 6 and 7, one matched pair on disk at a
|
| 142 |
+
time, resumable ledger at `results/aim/ledger_s*.json`). `scripts/aim/autopilot_aim.sh` appends
|
| 143 |
+
the numbers to this file when both shards stop, so the run finishes unattended. What it computes:
|
| 144 |
+
|
| 145 |
+
### 3.1 The test AIM's claim actually needs — and its control
|
| 146 |
+
|
| 147 |
+
AIM is closer to the base model than its baseline twin **by construction**: the delta is multiplied
|
| 148 |
+
by something in [ω, 1]. So "with-AIM merges stay closer to base" is not a finding, it is arithmetic,
|
| 149 |
+
and it is not what the paper claims either. The claim is that keying that shrink to the base
|
| 150 |
+
model's *activations* is what preserves the base model's behaviour.
|
| 151 |
+
|
| 152 |
+
That claim has a control, and section 2.3 is the reason it is needed: a **single scalar per tensor
|
| 153 |
+
reproduces AIM's weight change to R² = 0.9985**. So the sweep builds, for every baseline merge,
|
| 154 |
+
|
| 155 |
+
W_uniform = W_base + c_t · (W_merge − W_base), c_t = ‖ΔW_AIM‖_F / ‖ΔW_merge‖_F per tensor t
|
| 156 |
+
|
| 157 |
+
— the same weight-space move, the same distance from base on every tensor, with the activation
|
| 158 |
+
information deleted. AIM and its control sit on the same sphere around the base model. All three
|
| 159 |
+
arms (baseline merge, uniform control, with-AIM) are then run forward on the **same** 4096
|
| 160 |
+
calibration token positions from pile-val — AIM's own calibration source, which is the setting most
|
| 161 |
+
favourable to it — and compared to the base model's activations layer by layer:
|
| 162 |
+
|
| 163 |
+
ρ_W = ‖ΔW_AIM‖ / ‖ΔW_merge‖ weight-space shrink
|
| 164 |
+
ρ_A(x) = ‖H_x − H_base‖_F / ‖H_merge − H_base‖_F activation-space shrink, per layer
|
| 165 |
+
|
| 166 |
+
If the targeting does anything, **ρ_A(AIM) < ρ_A(uniform)**. If the two coincide, AIM's activation
|
| 167 |
+
information is doing nothing beyond choosing how far to pull the merge back toward the base — which
|
| 168 |
+
would mean the published gains are a shrinkage effect, reachable without any calibration set.
|
| 169 |
+
This needs no benchmark run.
|
| 170 |
+
|
| 171 |
+
### 3.2 The property panel
|
| 172 |
+
|
| 173 |
+
The F8 suite (`figures/final/F8_metric_families.png`'s 23 properties in five families, same
|
| 174 |
+
estimators, same 32-sentence probe, plus a 512-sentence extended probe as `geoX_`/`retX_`) computed
|
| 175 |
+
on **(merged model, base model)** rather than on a parent pair. The parent set is constant within a
|
| 176 |
+
task combination, so a pre-merge property cannot vary across the 20 cells; the object that does
|
| 177 |
+
vary is the merge's own relation to the base it was built from.
|
| 178 |
+
|
| 179 |
+
Two caveats stated up front, because they decide how the figure may be read.
|
| 180 |
+
|
| 181 |
+
- **Four points per operator.** Each operator has four task combinations, so a per-operator
|
| 182 |
+
correlation has n = 4 and its exact permutation p cannot go below 1/12. Every per-operator cell
|
| 183 |
+
in `F8_AIM_metric_families` will be struck through; that is the honest result, not a bug. The
|
| 184 |
+
bottom row pools all 20 after within-operator centring and uses an exact combo-clustered
|
| 185 |
+
permutation.
|
| 186 |
+
- **`F8b_AIM_property_deltas` is the panel with power**: the paired with-minus-without difference
|
| 187 |
+
in each property over 20 matched pairs, Wilcoxon signed rank on the pooled row.
|
| 188 |
+
|
| 189 |
+
## 4. What did not run, and why
|
| 190 |
+
|
| 191 |
+
- **No benchmark evaluation.** Ruled out on time grounds; published numbers cover all 40
|
| 192 |
+
checkpoints, so nothing was lost.
|
| 193 |
+
- `qmd` / `coordinate_gap` / `coord_fraction` are recorded NaN. Every checkpoint here is
|
| 194 |
+
`W_base + Δ`, so no permutation symmetry was ever broken between a merged model and its base:
|
| 195 |
+
the residual-basis map is the identity by construction and the coordinate component is zero a
|
| 196 |
+
priori. Measuring it would measure nothing. (Same reasoning as the MergeBench sweep.)
|
| 197 |
+
|
| 198 |
+
## 5. How to reproduce
|
| 199 |
+
|
| 200 |
+
```bash
|
| 201 |
+
source /root/.ms_hf_env # HF token; never echoed or committed
|
| 202 |
+
export PYTHONPATH=/root/mergeability/src
|
| 203 |
+
|
| 204 |
+
# (2.2) the salience correspondence test -- needs only the base model
|
| 205 |
+
CUDA_VISIBLE_DEVICES=7 /root/venvs/mergeability/bin/python \
|
| 206 |
+
scripts/aim/aim_salience_check.py --device cuda:0
|
| 207 |
+
|
| 208 |
+
# (2.1, 3) the sweep: one matched pair on disk at a time, resumable via results/aim/ledger*.json
|
| 209 |
+
bash scripts/aim/run_aim.sh 6 --shard 0 --n-shards 2
|
| 210 |
+
bash scripts/aim/run_aim.sh 7 --shard 1 --n-shards 2
|
| 211 |
+
setsid nohup bash scripts/aim/autopilot_aim.sh > logs/aim/autopilot.log 2>&1 < /dev/null &
|
| 212 |
+
|
| 213 |
+
# everything downstream (safe on partial coverage)
|
| 214 |
+
bash scripts/aim/finish_aim.sh
|
| 215 |
+
```
|
| 216 |
+
|
| 217 |
+
| file | what it is |
|
| 218 |
+
|---|---|
|
| 219 |
+
| `scripts/aim/make_published_scores.py` | transcribes the AIM repo's benchmark tables → `results/aim/published_scores.csv` |
|
| 220 |
+
| `scripts/aim/aim_weight_mechanism.py` | recovers AIM's per-channel gain from a published (base, merge, AIM) triple, streamed from safetensors |
|
| 221 |
+
| `scripts/aim/aim_salience_check.py` | measures the base model's activation scale independently and compares it to the recovered salience |
|
| 222 |
+
| `scripts/aim/aim_run.py` | the sweep: property panel + activation-space mechanism test + the uniform control |
|
| 223 |
+
| `scripts/aim/aim_mechanism_report.py` | `results/aim/mechanism_summary.csv`, `figures/aim/F9_AIM_mechanism.png` |
|
| 224 |
+
| `scripts/aim/aim_figures.py` | `figures/aim/F8_AIM_metric_families.png`, `F8b_AIM_property_deltas.png`, `results/aim/panel_stats.json` |
|
| 225 |
+
|
| 226 |
+
Reused rather than reimplemented, as instructed: `mergeschool.controlled.bridge_sweep`
|
| 227 |
+
(`_forward`, `geometry_block`, `retrieval_block`, `behaviour_block`, the 32-sentence probe) and
|
| 228 |
+
`mergeschool.mergebench.sweep` (`gradient_block_cached`, `weight_block`, `spectral_pair`,
|
| 229 |
+
`_ext_probe`) supply every property column; `report.final_figures.METRIC_FAMILIES` and
|
| 230 |
+
`geometry.gf_style` supply the F8 layout and colour conventions. Nothing under
|
| 231 |
+
`figures/mergebench/` or `RESULTS_MERGEBENCH.md` was touched.
|