papachengo commited on
Commit
d29779d
·
verified ·
1 Parent(s): 9b6025f

Upload 4 files

Browse files
Files changed (4) hide show
  1. README.md +20 -4
  2. checker.js +178 -0
  3. data.js +0 -0
  4. index.html +497 -17
README.md CHANGED
@@ -1,11 +1,27 @@
1
  ---
2
  title: Base Checker
3
- emoji: 📚
4
- colorFrom: blue
5
- colorTo: pink
6
  sdk: static
7
  pinned: false
8
  license: mit
 
9
  ---
10
 
11
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  title: Base Checker
3
+ emoji: 🌳
4
+ colorFrom: green
5
+ colorTo: blue
6
  sdk: static
7
  pinned: false
8
  license: mit
9
+ short_description: Catch a wrong base_model before merging LLMs
10
  ---
11
 
12
+ # Base Checker: lineage-aware model merging
13
+
14
+ Interactive demo for **Lineage-Aware Model Merging for Large Language Models**
15
+ (B.Tech AI & Data Science major project, SMIT, 2026; Gourabdipta Ghosh and Arko Chakraborty;
16
+ guide Mr. Suraj Dey).
17
+
18
+ Merging methods add up each model's change from a hand-picked `base_model`. If the models
19
+ share a closer ancestor, its update is counted repeatedly and the merge can collapse
20
+ (68.0/48.0 vs 6.5/0.0 on GSM8K/MBPP for the same three Qwen2.5-1.5B fine-tunes). This page
21
+ finds the closest common ancestor from the weights alone and checks a mergekit-style config.
22
+
23
+ It runs entirely in the browser on precomputed weight statistics (Gram matrices of 196
24
+ attention/MLP matrices) for 7 Qwen2.5-1.5B-family models. The JavaScript checker gives the
25
+ same verdicts as the Python tool on all 5,740 tested configurations.
26
+
27
+ Code, results and the command-line tool: https://github.com/GourabDG36/lineage-aware-merging
checker.js ADDED
@@ -0,0 +1,178 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Base Checker logic, ported line by line from lineage.py and base_checker.py
3
+ * (github.com/GourabDG36/lineage-aware-merging). Works in the browser and in Node.
4
+ * Input: Gram matrices G[c][i][j] = <W_i, W_j> for every attention/MLP matrix c.
5
+ */
6
+ (function (root) {
7
+ "use strict";
8
+
9
+ var METHODS = {
10
+ task_arithmetic: "sum", dare_linear: "sum", breadcrumbs: "sum", della_linear: "sum",
11
+ ties: "trim", dare_ties: "trim", breadcrumbs_ties: "trim", della: "trim", sce: "trim",
12
+ linear: "none", slerp: "none", nuslerp: "none", passthrough: "none", karcher: "none",
13
+ model_stock: "other", nearswap: "other"
14
+ };
15
+ var DEFAULT_GATE = 0.10, DEFAULT_COS = 0.30;
16
+
17
+ function sqDist(G, i, j) {
18
+ return G.map(function (m) { return Math.max(m[i][i] + m[j][j] - 2 * m[i][j], 0); });
19
+ }
20
+ function mean(a) { var s = 0; for (var k = 0; k < a.length; k++) s += a[k]; return s / a.length; }
21
+
22
+ function distanceMatrix(G) {
23
+ var N = G[0].length, D = [];
24
+ for (var i = 0; i < N; i++) { D.push(new Array(N).fill(0)); }
25
+ for (i = 0; i < N; i++) {
26
+ for (var j = i + 1; j < N; j++) {
27
+ var sq = sqDist(G, i, j);
28
+ var v = mean(G.map(function (m, c) { return Math.sqrt(sq[c]) / Math.sqrt((m[i][i] + m[j][j]) / 2); }));
29
+ D[i][j] = D[j][i] = v;
30
+ }
31
+ }
32
+ return D;
33
+ }
34
+
35
+ function relFrom(G, k, r) {
36
+ if (k === r) return 0;
37
+ var sq = sqDist(G, k, r);
38
+ return mean(G.map(function (m, c) { return Math.sqrt(sq[c]) / Math.sqrt(m[r][r]); }));
39
+ }
40
+
41
+ function tauCos(G, a, b, r) {
42
+ if (r === a || r === b) return NaN;
43
+ var sa = sqDist(G, a, r), sb = sqDist(G, b, r), vals = [];
44
+ G.forEach(function (m, c) {
45
+ var na = Math.sqrt(sa[c]), nb = Math.sqrt(sb[c]);
46
+ if (na > 0 && nb > 0) vals.push((m[a][b] - m[a][r] - m[b][r] + m[r][r]) / (na * nb));
47
+ });
48
+ return vals.length ? mean(vals) : NaN;
49
+ }
50
+
51
+ function minimumSpanningTree(D) {
52
+ var N = D.length, inTree = [0], edges = [];
53
+ while (inTree.length < N) {
54
+ var best = null, order = inTree.slice().sort(function (x, y) { return x - y; });
55
+ order.forEach(function (i) {
56
+ for (var j = 0; j < N; j++) {
57
+ if (inTree.indexOf(j) < 0 && (best === null || D[i][j] < D[best[0]][best[1]])) best = [i, j];
58
+ }
59
+ });
60
+ edges.push([Math.min(best[0], best[1]), Math.max(best[0], best[1])]);
61
+ inTree.push(best[1]);
62
+ }
63
+ return edges.sort(function (x, y) { return x[0] - y[0] || x[1] - y[1]; });
64
+ }
65
+
66
+ function adjacency(edges, N) {
67
+ var adj = []; for (var i = 0; i < N; i++) adj.push([]);
68
+ edges.forEach(function (e) { adj[e[0]].push(e[1]); adj[e[1]].push(e[0]); });
69
+ return adj;
70
+ }
71
+
72
+ function steinerNodes(edges, N, members) {
73
+ var adj = adjacency(edges, N);
74
+ function path(a, b) {
75
+ var prev = {}; prev[a] = -1; var q = [a];
76
+ while (q.length) {
77
+ var u = q.shift();
78
+ adj[u].forEach(function (v) { if (!(v in prev)) { prev[v] = u; q.push(v); } });
79
+ }
80
+ var out = [], u2 = b;
81
+ while (u2 !== -1) { out.push(u2); u2 = prev[u2]; }
82
+ return out;
83
+ }
84
+ var nodes = {};
85
+ members.forEach(function (m) { nodes[m] = true; });
86
+ for (var k = 1; k < members.length; k++) path(members[0], members[k]).forEach(function (n) { nodes[n] = true; });
87
+ return Object.keys(nodes).map(Number).sort(function (x, y) { return x - y; });
88
+ }
89
+
90
+ function chooseReference(G, edges, members, gate) {
91
+ var N = G[0].length, cands = steinerNodes(edges, N, members), cost = {};
92
+ cands.forEach(function (r) { cost[r] = Math.max.apply(null, members.map(function (m) { return relFrom(G, m, r); })); });
93
+ var best = cands.slice().sort(function (x, y) { return cost[x] - cost[y] || x - y; })[0];
94
+ return { best: best, cost: cost[best], candidates: cands };
95
+ }
96
+
97
+ /*
98
+ * cfg = {method, base (index or null), models: [{index, weight}], normalize (bool or null)}
99
+ * Returns the same report fields as base_checker.check().
100
+ */
101
+ function check(G, names, cfg, opts) {
102
+ opts = opts || {};
103
+ var gate = opts.gate == null ? DEFAULT_GATE : opts.gate, cosThr = opts.cos == null ? DEFAULT_COS : opts.cos;
104
+ var kind = METHODS[cfg.method] || "other";
105
+ var models = cfg.models.filter(function (m) { return m.index !== cfg.base; });
106
+ if (!models.length) throw new Error("choose at least one model to merge (other than the base)");
107
+ var mi = models.map(function (m) { return m.index; });
108
+ var normalize = cfg.normalize == null ? (cfg.method === "linear") : !!cfg.normalize;
109
+ var D = distanceMatrix(G), edges = minimumSpanningTree(D);
110
+ var ch = chooseReference(G, edges, mi, gate), best = ch.best, cost = ch.cost, di = cfg.base;
111
+
112
+ function pairCos(r) {
113
+ var v = [];
114
+ for (var x = 0; x < mi.length; x++) for (var y = x + 1; y < mi.length; y++) {
115
+ var t = tauCos(G, mi[x], mi[y], r); if (isFinite(t)) v.push(t);
116
+ }
117
+ return v.length ? mean(v) : null;
118
+ }
119
+ var wsum = models.reduce(function (s, m) { return s + m.weight; }, 0);
120
+ var counted = normalize ? 1 : wsum;
121
+ var rep = {
122
+ method: cfg.method, method_kind: kind, declared_base: di == null ? null : names[di],
123
+ closest_common_ancestor: names[best], best_index: best,
124
+ candidates_on_tree_path: ch.candidates.map(function (c) { return names[c]; }),
125
+ tree_links: edges.map(function (e) { return [names[e[0]], names[e[1]], D[e[0]][e[1]]]; }),
126
+ edges: edges, D: D,
127
+ distance_from_ancestor: {}, task_vector_cos_from_ancestor: pairCos(best),
128
+ weights_sum: wsum, normalize: normalize, ancestor_update_counted_times: counted, gate: gate
129
+ };
130
+ mi.forEach(function (i) { rep.distance_from_ancestor[names[i]] = relFrom(G, i, best); });
131
+ if (di != null) {
132
+ rep.distance_from_declared_base = {};
133
+ mi.forEach(function (i) { rep.distance_from_declared_base[names[i]] = relFrom(G, i, di); });
134
+ rep.task_vector_cos_from_declared_base = pairCos(di);
135
+ }
136
+
137
+ if (cost > gate) {
138
+ var far = mi.filter(function (i) { return relFrom(G, i, best) > gate; }).map(function (i) { return names[i]; });
139
+ rep.verdict = "TOO_FAR";
140
+ rep.message = "No common ancestor is close enough: " + far.join(", ") + (far.length === 1 ? " is" : " are") +
141
+ " more than " + Math.round(gate * 100) + "% away from the best base (" + names[best] +
142
+ "). Merging is unsafe from any base; keep these models separate.";
143
+ return rep;
144
+ }
145
+ if (di == null) { rep.verdict = "WARNING"; rep.message = "No base_model given; the closest common ancestor is " + names[best] + "."; return rep; }
146
+ if (di === best) { rep.verdict = "OK"; rep.message = "base_model " + names[di] + " is the closest common ancestor of the merged models."; return rep; }
147
+ if (kind === "none") {
148
+ rep.verdict = "INFO";
149
+ rep.message = cfg.method + " does not use the base to form task vectors, so the base choice does not cause double counting. (Closest ancestor: " + names[best] + ".)";
150
+ return rep;
151
+ }
152
+ var shared = rep.task_vector_cos_from_declared_base;
153
+ var sharedTxt = (shared != null && rep.task_vector_cos_from_ancestor != null) ?
154
+ " Measured from " + names[di] + ", the task vectors have cosine " + shared.toFixed(2) +
155
+ " (from " + names[best] + ": " + rep.task_vector_cos_from_ancestor.toFixed(2) + ")." : "";
156
+ if (kind === "sum" && counted > 1.05 && (shared == null || shared > cosThr)) {
157
+ rep.verdict = "WRONG_BASE";
158
+ rep.message = "The merged models share a closer ancestor, " + names[best] + ". With base_model " + names[di] +
159
+ ", every task vector contains that ancestor's own update, and " + cfg.method + " adds them with total weight " +
160
+ fmt(counted) + ", so the update is counted " + fmt(counted) + " times instead of once." + sharedTxt +
161
+ " Use base_model: " + names[best] + ".";
162
+ } else {
163
+ var why = (counted <= 1.05 && kind === "sum") ? "weights are normalised to sum to 1" :
164
+ (kind === "trim" ? cfg.method + " trims and sign-votes task vectors, which removes much of a repeated update" :
165
+ "the effect on " + cfg.method + " was not measured");
166
+ rep.verdict = "WARNING";
167
+ rep.message = "A closer common ancestor exists: " + names[best] + " (declared: " + names[di] + "). The risk is lower because " +
168
+ why + ", but " + names[best] + " is still the better base." + sharedTxt;
169
+ }
170
+ return rep;
171
+ }
172
+
173
+ function fmt(x) { return String(Math.round(x * 1e6) / 1e6); }
174
+
175
+ var api = { METHODS: METHODS, distanceMatrix: distanceMatrix, relFrom: relFrom, tauCos: tauCos,
176
+ minimumSpanningTree: minimumSpanningTree, steinerNodes: steinerNodes, chooseReference: chooseReference, check: check };
177
+ if (typeof module !== "undefined" && module.exports) module.exports = api; else root.LAMChecker = api;
178
+ })(this);
data.js ADDED
The diff for this file is too large to render. See raw diff
 
index.html CHANGED
@@ -1,19 +1,499 @@
1
  <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  </html>
 
1
  <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1">
6
+ <title>Base Checker</title>
7
+ <meta name="description" content="Catch a wrong base_model before merging LLMs. Lineage-aware model merging, from the weights alone.">
8
+ <style>
9
+ :root {
10
+ color-scheme: light;
11
+ --page: #f9f9f7; --surface: #fcfcfb; --raise: #ffffff;
12
+ --ink: #0b0b0b; --ink-2: #52514e; --muted: #898781;
13
+ --grid: #e1e0d9; --axis: #c3c2b7; --border: rgba(11,11,11,0.10);
14
+ --s1: #2a78d6; --s2: #eb6834;
15
+ --good: #0ca30c; --warning: #fab219; --serious: #ec835a; --critical: #d03b3b;
16
+ --good-ink: #006300;
17
+ --wash-good: rgba(12,163,12,0.08); --wash-warning: rgba(250,178,25,0.14);
18
+ --wash-serious: rgba(236,131,90,0.12); --wash-critical: rgba(208,59,59,0.09); --wash-info: rgba(42,120,214,0.08);
19
+ --code: #f1f0ec;
20
+ }
21
+ @media (prefers-color-scheme: dark) {
22
+ :root:where(:not([data-theme="light"])) {
23
+ color-scheme: dark;
24
+ --page: #0d0d0d; --surface: #1a1a19; --raise: #20201f;
25
+ --ink: #f0efec; --ink-2: #c3c2b7; --muted: #898781;
26
+ --grid: #2c2c2a; --axis: #383835; --border: rgba(255,255,255,0.10);
27
+ --s1: #3987e5; --s2: #d95926; --good-ink: #0ca30c;
28
+ --wash-good: rgba(12,163,12,0.14); --wash-warning: rgba(250,178,25,0.12);
29
+ --wash-serious: rgba(236,131,90,0.14); --wash-critical: rgba(208,59,59,0.16); --wash-info: rgba(57,135,229,0.14);
30
+ --code: #262624;
31
+ }
32
+ }
33
+ :root[data-theme="dark"] {
34
+ color-scheme: dark;
35
+ --page: #0d0d0d; --surface: #1a1a19; --raise: #20201f;
36
+ --ink: #f0efec; --ink-2: #c3c2b7; --muted: #898781;
37
+ --grid: #2c2c2a; --axis: #383835; --border: rgba(255,255,255,0.10);
38
+ --s1: #3987e5; --s2: #d95926; --good-ink: #0ca30c;
39
+ --wash-good: rgba(12,163,12,0.14); --wash-warning: rgba(250,178,25,0.12);
40
+ --wash-serious: rgba(236,131,90,0.14); --wash-critical: rgba(208,59,59,0.16); --wash-info: rgba(57,135,229,0.14);
41
+ --code: #262624;
42
+ }
43
+ * { box-sizing: border-box; }
44
+ html, body { margin: 0; background: var(--page); color: var(--ink); }
45
+ body { font: 16px/1.55 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; }
46
+ .wrap { max-width: 1040px; margin: 0 auto; padding: 0 16px; }
47
+ header { padding: 48px 0 8px; }
48
+ .eyebrow { font-size: 13px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin: 0 0 8px; }
49
+ h1 { font-size: clamp(30px, 5vw, 44px); line-height: 1.1; margin: 0 0 14px; letter-spacing: -0.01em; }
50
+ h2 { font-size: 22px; margin: 0 0 6px; }
51
+ h3 { font-size: 16px; margin: 0 0 8px; }
52
+ p { margin: 0 0 12px; }
53
+ .lede { font-size: 18px; color: var(--ink-2); max-width: 720px; }
54
+ a { color: var(--s1); }
55
+ section { padding: 28px 0; }
56
+ .card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 20px; }
57
+ .hero-compare { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin: 22px 0 6px; max-width: 720px; }
58
+ .stat { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px 18px; }
59
+ .stat .k { font-size: 13px; color: var(--ink-2); }
60
+ .stat .v { font-size: 34px; font-weight: 650; font-variant-numeric: tabular-nums; line-height: 1.15; margin-top: 4px; }
61
+ .stat .v small { font-size: 15px; font-weight: 500; color: var(--ink-2); }
62
+ .stat .tag { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; margin-top: 6px; color: var(--ink-2); }
63
+ .dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }
64
+ .note { font-size: 14px; color: var(--ink-2); }
65
+
66
+ /* checker */
67
+ .grid-2 { display: grid; grid-template-columns: minmax(0, 340px) minmax(0, 1fr); gap: 16px; align-items: start; }
68
+ @media (max-width: 820px) { .grid-2 { grid-template-columns: minmax(0, 1fr); } .hero-compare { grid-template-columns: minmax(0, 1fr); } }
69
+ .presets { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 18px; }
70
+ button, select, input { font: inherit; color: inherit; }
71
+ .chip { border: 1px solid var(--border); background: var(--raise); border-radius: 999px; padding: 6px 12px; font-size: 14px; cursor: pointer; }
72
+ .chip:hover { border-color: var(--axis); }
73
+ .chip[aria-pressed="true"] { border-color: var(--ink); font-weight: 600; }
74
+ label.field { display: block; font-size: 13px; color: var(--ink-2); margin: 0 0 4px; }
75
+ select { width: 100%; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--raise); }
76
+ .fieldset { margin: 0 0 14px; }
77
+ .models { display: grid; gap: 6px; }
78
+ .mrow { display: grid; grid-template-columns: 20px minmax(0, 1fr) 64px; gap: 8px; align-items: center; font-size: 14px; }
79
+ .mrow input[type=number] { width: 64px; padding: 4px 6px; border-radius: 6px; border: 1px solid var(--border); background: var(--raise); font-variant-numeric: tabular-nums; }
80
+ .mrow input[type=number]:disabled { opacity: .4; }
81
+ .mrow .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
82
+ .check-inline { display: flex; gap: 8px; align-items: center; font-size: 14px; }
83
+
84
+ .verdict { border-radius: 10px; padding: 14px 16px; border: 1px solid var(--border); margin-bottom: 14px; }
85
+ .verdict .vh { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; margin-bottom: 4px; }
86
+ .verdict .vh svg { flex: none; }
87
+ .verdict p { margin: 0; color: var(--ink); }
88
+ .v-OK { background: var(--wash-good); } .v-INFO { background: var(--wash-info); }
89
+ .v-WARNING { background: var(--wash-warning); } .v-WRONG_BASE { background: var(--wash-critical); } .v-TOO_FAR { background: var(--wash-serious); }
90
+ .evidence { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-bottom: 14px; }
91
+ @media (max-width: 560px) { .evidence { grid-template-columns: minmax(0, 1fr); } }
92
+ .mini { background: var(--raise); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
93
+ .mini .k { font-size: 13px; color: var(--ink-2); margin-bottom: 8px; }
94
+ .barrow { display: grid; grid-template-columns: 116px minmax(0, 1fr) 46px; gap: 8px; align-items: center; font-size: 13px; margin: 6px 0; }
95
+ .track { height: 10px; background: var(--grid); border-radius: 4px; overflow: hidden; }
96
+ .fill { height: 100%; border-radius: 4px; }
97
+ .num { font-variant-numeric: tabular-nums; text-align: right; }
98
+ table { border-collapse: collapse; width: 100%; font-size: 14px; }
99
+ th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--grid); }
100
+ th { font-weight: 600; color: var(--ink-2); font-size: 13px; }
101
+ td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
102
+ .table-scroll { overflow-x: auto; }
103
+ pre { background: var(--code); border-radius: 8px; padding: 12px; font-size: 13px; overflow-x: auto; margin: 0; }
104
+ .yaml-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
105
+ @media (max-width: 680px) { .yaml-grid { grid-template-columns: minmax(0, 1fr); } }
106
+ .tree-box { background: var(--raise); border: 1px solid var(--border); border-radius: 10px; padding: 8px; margin-bottom: 14px; }
107
+ .tree-box svg { width: 100%; height: auto; display: block; }
108
+ .legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 13px; color: var(--ink-2); padding: 4px 8px 8px; }
109
+ .legend span { display: inline-flex; align-items: center; gap: 6px; }
110
+
111
+ /* charts */
112
+ .charts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
113
+ .charts .wide { grid-column: 1 / -1; }
114
+ @media (max-width: 820px) { .charts { grid-template-columns: minmax(0, 1fr); } }
115
+ .chart svg { width: 100%; height: auto; display: block; }
116
+ .chart .sub { font-size: 14px; color: var(--ink-2); margin: 0 0 10px; }
117
+ .clegend { display: flex; gap: 16px; font-size: 13px; color: var(--ink-2); margin: 0 0 6px; flex-wrap: wrap; }
118
+ .clegend span { display: inline-flex; gap: 6px; align-items: center; }
119
+ details { margin-top: 8px; font-size: 14px; }
120
+ summary { cursor: pointer; color: var(--ink-2); }
121
+ .tip { position: fixed; pointer-events: none; background: var(--raise); color: var(--ink); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 13px; box-shadow: 0 4px 16px rgba(0,0,0,.12); opacity: 0; transition: opacity .08s; z-index: 10; max-width: 260px; }
122
+ .tip b { font-variant-numeric: tabular-nums; }
123
+ .steps { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; counter-reset: s; }
124
+ @media (max-width: 820px) { .steps { grid-template-columns: minmax(0, 1fr); } }
125
+ .step { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px; font-size: 14px; }
126
+ .step::before { counter-increment: s; content: counter(s); display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--ink); color: var(--page); font-weight: 700; font-size: 13px; margin-bottom: 8px; }
127
+ .step b { display: block; margin-bottom: 4px; }
128
+ #chart-base, #chart-cos, #chart-sweep, .tree-box { overflow-x: auto; }
129
+ @media (max-width: 600px) {
130
+ #chart-base svg { min-width: 680px; } #chart-cos svg, #chart-sweep svg { min-width: 460px; } .tree-box svg { min-width: 640px; }
131
+ }
132
+ footer { padding: 28px 0 48px; color: var(--ink-2); font-size: 14px; border-top: 1px solid var(--grid); margin-top: 20px; }
133
+ .err { color: var(--critical); font-size: 14px; }
134
+ </style>
135
+ </head>
136
+ <body>
137
+ <div class="tip" id="tip" role="status" aria-live="polite"></div>
138
+
139
+ <header class="wrap">
140
+ <p class="eyebrow">Lineage-aware model merging</p>
141
+ <h1>Is your merge base the right one?</h1>
142
+ <p class="lede">Model merging adds up each model's change from a <b>base model</b> that you type by hand. If the models share a closer ancestor, its training gets added again and again, and the merge breaks. This page checks the base using the model weights alone.</p>
143
+ <div class="hero-compare" aria-label="Same three models, same method, different base">
144
+ <div class="stat">
145
+ <div class="k">Base = their closest common ancestor (Instruct)</div>
146
+ <div class="v">68.0 <small>/ 48.0</small></div>
147
+ <div class="tag"><span class="dot" style="background:var(--s1)"></span>GSM8K / MBPP accuracy, %</div>
148
+ </div>
149
+ <div class="stat">
150
+ <div class="k">Base = Qwen2.5-1.5B (the usual choice)</div>
151
+ <div class="v">6.5 <small>/ 0.0</small></div>
152
+ <div class="tag"><span class="dot" style="background:var(--s2)"></span>GSM8K / MBPP accuracy, %</div>
153
+ </div>
154
+ </div>
155
+ <p class="note">Three Qwen2.5-1.5B-Instruct fine-tunes (QwQ, MBPP, Business) merged with Task Arithmetic. Only the base differs.</p>
156
+ </header>
157
+
158
+ <main>
159
+ <section class="wrap" id="try">
160
+ <h2>Try the Base Checker</h2>
161
+ <p class="note">Runs in your browser on real data from the 7 models below (196 weight matrices each, measured on Kaggle). No data, no GPU. Pick a preset or build your own merge.</p>
162
+ <div class="presets" role="group" aria-label="Presets">
163
+ <button class="chip" data-preset="mistake">The real mistake</button>
164
+ <button class="chip" data-preset="fixed">Same merge, right base</button>
165
+ <button class="chip" data-preset="ties">TIES, wrong base</button>
166
+ <button class="chip" data-preset="far">Coder + Instruct</button>
167
+ </div>
168
+ <div class="grid-2">
169
+ <form class="card" id="form" onsubmit="return false">
170
+ <div class="fieldset">
171
+ <label class="field" for="method">merge_method</label>
172
+ <select id="method">
173
+ <option value="task_arithmetic">task_arithmetic</option>
174
+ <option value="ties">ties</option>
175
+ <option value="dare_ties">dare_ties</option>
176
+ <option value="dare_linear">dare_linear</option>
177
+ <option value="linear">linear</option>
178
+ </select>
179
+ </div>
180
+ <div class="fieldset">
181
+ <label class="field" for="base">base_model</label>
182
+ <select id="base"></select>
183
+ </div>
184
+ <div class="fieldset">
185
+ <span class="field" id="models-label">models to merge, with weight</span>
186
+ <div class="models" id="models" aria-labelledby="models-label"></div>
187
+ </div>
188
+ <label class="check-inline"><input type="checkbox" id="normalize"> normalize weights to sum to 1</label>
189
+ </form>
190
+ <div id="out" aria-live="polite"></div>
191
+ </div>
192
+ </section>
193
+
194
+ <section class="wrap" id="results">
195
+ <h2>What we measured</h2>
196
+ <p class="note">Qwen2.5-1.5B family on a Kaggle T4. Accuracy is the average of GSM8K and MBPP (first 200 test questions each). 42 merges in total; full tables on GitHub.</p>
197
+ <div class="charts">
198
+ <div class="card chart wide">
199
+ <h3>Choosing the right base fixes Task Arithmetic merges</h3>
200
+ <p class="sub">Same models and method; only the base changes. Lineage base wins 5 of 5.</p>
201
+ <div class="clegend"><span><span class="dot" style="background:var(--s1)"></span>Base = closest common ancestor (Instruct)</span><span><span class="dot" style="background:var(--s2)"></span>Base = Qwen2.5-1.5B</span></div>
202
+ <div id="chart-base"></div>
203
+ <details><summary>Show as table</summary><div class="table-scroll" id="table-base"></div></details>
204
+ </div>
205
+ <div class="card chart">
206
+ <h3>The wrong base makes task vectors look alike</h3>
207
+ <p class="sub">Cosine between two models' changes. Near 1: the same ancestor update counted twice.</p>
208
+ <div class="clegend"><span><span class="dot" style="background:var(--s1)"></span>From Instruct</span><span><span class="dot" style="background:var(--s2)"></span>From Qwen2.5-1.5B</span></div>
209
+ <div id="chart-cos"></div>
210
+ <details><summary>Show as table</summary><div class="table-scroll" id="table-cos"></div></details>
211
+ </div>
212
+ <div class="card chart">
213
+ <h3>How far is too far</h3>
214
+ <p class="sub">Stepping from Instruct towards Coder: healthy up to 10%, then it breaks.</p>
215
+ <div id="chart-sweep"></div>
216
+ <details><summary>Show as table</summary><div class="table-scroll" id="table-sweep"></div></details>
217
+ </div>
218
+ </div>
219
+ </section>
220
+
221
+ <section class="wrap" id="how">
222
+ <h2>How it works</h2>
223
+ <p class="note">Everything comes from the weight files. No test questions are used at any step.</p>
224
+ <div class="steps">
225
+ <div class="step"><b>Measure distance</b>How much two models' weights differ, averaged over 196 attention and MLP matrices.</div>
226
+ <div class="step"><b>Draw the family tree</b>Join the closest relatives first (minimum spanning tree), following MoTHer (ICLR 2025).</div>
227
+ <div class="step"><b>Find the ancestor</b>On the tree paths between the models you merge, pick the model closest to all of them.</div>
228
+ <div class="step"><b>Check double counting</b>Cosine between the models' changes from your base. High means a shared update is repeated.</div>
229
+ <div class="step"><b>Distance gate</b>If even the best base is more than 10% away from a model, the merge is unsafe from any base.</div>
230
+ </div>
231
+ </section>
232
+ </main>
233
+
234
+ <footer class="wrap">
235
+ <p><b>Lineage-Aware Model Merging for Large Language Models.</b> B.Tech (AI &amp; Data Science) major project, Sikkim Manipal Institute of Technology, 2026. Gourabdipta Ghosh and Arko Chakraborty; guide Mr. Suraj Dey.</p>
236
+ <p>Code, results and the command-line Base Checker for mergekit configs: <a href="https://github.com/GourabDG36/lineage-aware-merging">github.com/GourabDG36/lineage-aware-merging</a>.</p>
237
+ <p>Related work: model family trees from weights (MoTHer, ICLR 2025; modelDNA, arXiv 2607.10617); grouping and routing a model zoo (Model-GLUE, arXiv 2410.05357); predicting merge collapse with a fixed base (arXiv 2610.03199). To our knowledge, none of these uses model lineage to choose the merge base.</p>
238
+ <p>This page checks only the 7 models listed. For any other models, run <code>base_checker.py</code> from the repository.</p>
239
+ </footer>
240
+
241
+ <script src="data.js"></script>
242
+ <script src="checker.js"></script>
243
+ <script>
244
+ (function () {
245
+ "use strict";
246
+ var D = window.LAM_DATA, C = window.LAMChecker, N = D.names.length;
247
+ var SHORT = D.short, $ = function (id) { return document.getElementById(id); };
248
+ var idx = {}; D.names.forEach(function (n, i) { idx[n] = i; });
249
+ var BASE = idx["Qwen/Qwen2.5-1.5B"], INSTRUCT = idx["Qwen/Qwen2.5-1.5B-Instruct"];
250
+ var QWQ = idx["micaebe/Qwen2.5-1.5B-Instruct-QwQ"], MBPP = idx["jahyungu/Qwen2.5-1.5B-Instruct_mbpp"],
251
+ BUS = idx["joyboy5656n/business-assistant-llm"], CODER = idx["Qwen/Qwen2.5-Coder-1.5B-Instruct"];
252
+ var ORDER = [BASE, INSTRUCT, QWQ, MBPP, BUS, idx["Qwen/Qwen2.5-Coder-1.5B"], CODER];
253
+
254
+ function esc(s) { return String(s).replace(/[&<>"]/g, function (c) { return { "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;" }[c]; }); }
255
+ function shortOf(name) { return SHORT[idx[name]] || name; }
256
+
257
+ // ---------------- form
258
+ ORDER.forEach(function (i) {
259
+ var o = document.createElement("option"); o.value = i; o.textContent = SHORT[i]; $("base").appendChild(o);
260
+ var row = document.createElement("div"); row.className = "mrow";
261
+ row.innerHTML = '<input type="checkbox" id="m' + i + '" aria-label="merge ' + esc(SHORT[i]) + '">' +
262
+ '<label class="nm" for="m' + i + '" title="' + esc(D.names[i]) + '">' + esc(SHORT[i]) + '</label>' +
263
+ '<input type="number" id="w' + i + '" min="0" max="5" step="0.05" value="1" aria-label="weight of ' + esc(SHORT[i]) + '">';
264
+ $("models").appendChild(row);
265
+ });
266
+
267
+ var PRESETS = {
268
+ mistake: { method: "task_arithmetic", base: BASE, models: [[QWQ, 1], [MBPP, 1], [BUS, 1]], normalize: false },
269
+ fixed: { method: "task_arithmetic", base: INSTRUCT, models: [[QWQ, 1], [MBPP, 1], [BUS, 1]], normalize: false },
270
+ ties: { method: "ties", base: BASE, models: [[QWQ, 1], [MBPP, 1], [BUS, 1]], normalize: false },
271
+ far: { method: "task_arithmetic", base: BASE, models: [[CODER, 0.5], [INSTRUCT, 0.5]], normalize: false }
272
+ };
273
+ function applyPreset(key) {
274
+ var p = PRESETS[key];
275
+ $("method").value = p.method; $("base").value = p.base; $("normalize").checked = p.normalize;
276
+ ORDER.forEach(function (i) { $("m" + i).checked = false; $("w" + i).value = 1; });
277
+ p.models.forEach(function (m) { $("m" + m[0]).checked = true; $("w" + m[0]).value = m[1]; });
278
+ document.querySelectorAll("[data-preset]").forEach(function (b) { b.setAttribute("aria-pressed", b.dataset.preset === key ? "true" : "false"); });
279
+ run();
280
+ }
281
+ document.querySelectorAll("[data-preset]").forEach(function (b) { b.addEventListener("click", function () { applyPreset(b.dataset.preset); }); });
282
+ $("form").addEventListener("input", function () {
283
+ document.querySelectorAll("[data-preset]").forEach(function (b) { b.setAttribute("aria-pressed", "false"); });
284
+ run();
285
+ });
286
+
287
+ function readForm() {
288
+ var base = +$("base").value, models = [];
289
+ ORDER.forEach(function (i) {
290
+ var on = $("m" + i).checked; $("w" + i).disabled = !on || i === base;
291
+ if (on && i !== base) { var w = parseFloat($("w" + i).value); models.push({ index: i, weight: isFinite(w) ? w : 1 }); }
292
+ });
293
+ return { method: $("method").value, base: base, models: models, normalize: $("normalize").checked };
294
+ }
295
+
296
+ // ---------------- output
297
+ var ICONS = {
298
+ OK: '<path d="M5 10.5l3 3 7-7" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"/>',
299
+ INFO: '<path d="M10 9v5M10 6.2v.1" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round"/>',
300
+ WARNING: '<path d="M10 5.5v5.5M10 14.2v.1" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round"/>',
301
+ WRONG_BASE: '<path d="M6.5 6.5l7 7M13.5 6.5l-7 7" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round"/>',
302
+ TOO_FAR: '<path d="M6 10h8" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round"/>'
303
+ };
304
+ var VCOLOR = { OK: "var(--good)", INFO: "var(--s1)", WARNING: "var(--warning)", WRONG_BASE: "var(--critical)", TOO_FAR: "var(--serious)" };
305
+ var VLABEL = { OK: "OK: right base", INFO: "INFO: base not used by this method", WARNING: "WARNING: a better base exists",
306
+ WRONG_BASE: "WRONG BASE: the merge will double count", TOO_FAR: "STOP: too far apart to merge" };
307
+ var VINK = { WARNING: "#0b0b0b" };
308
+
309
+ function verdictHtml(r) {
310
+ var msg = r.message;
311
+ D.names.slice().sort(function (a, b) { return b.length - a.length; })
312
+ .forEach(function (n) { msg = msg.split(n).join("\u0000" + idx[n] + "\u0000"); });
313
+ msg = msg.replace(/\u0000(\d+)\u0000/g, function (_, i) { return SHORT[+i]; });
314
+ return '<div class="verdict v-' + r.verdict + '"><div class="vh">' +
315
+ '<svg width="22" height="22" viewBox="0 0 20 20" aria-hidden="true"><circle cx="10" cy="10" r="10" fill="' + VCOLOR[r.verdict] + '"/>' +
316
+ '<g style="color:' + (VINK[r.verdict] || "#ffffff") + '">' + ICONS[r.verdict] + '</g></svg>' +
317
+ esc(VLABEL[r.verdict]) + '</div><p>' + esc(msg) + '</p></div>';
318
+ }
319
+
320
+ function evidenceHtml(r, cfg) {
321
+ var parts = [];
322
+ if (r.task_vector_cos_from_ancestor != null) {
323
+ var rows = [];
324
+ if (r.task_vector_cos_from_declared_base != null)
325
+ rows.push(["From your base", r.task_vector_cos_from_declared_base, "var(--s2)"]);
326
+ rows.push(["From the ancestor", r.task_vector_cos_from_ancestor, "var(--s1)"]);
327
+ parts.push('<div class="mini"><div class="k">Double-counting score (task-vector cosine, 0 = independent, 1 = same update repeated)</div>' +
328
+ rows.map(function (x) {
329
+ var v = Math.max(0, Math.min(1, x[1]));
330
+ return '<div class="barrow"><span>' + x[0] + '</span><span class="track"><span class="fill" style="display:block;width:' + (v * 100).toFixed(1) + '%;background:' + x[2] + '"></span></span><span class="num">' + x[1].toFixed(2) + '</span></div>';
331
+ }).join("") + '</div>');
332
+ }
333
+ var counted = r.ancestor_update_counted_times;
334
+ parts.push('<div class="mini"><div class="k">Settings</div><div style="font-size:14px">' +
335
+ 'Closest common ancestor: <b>' + esc(shortOf(r.closest_common_ancestor)) + '</b><br>' +
336
+ 'Weights sum to <b>' + (Math.round(r.weights_sum * 1000) / 1000) + '</b>' + (r.normalize ? ' (normalised)' : '') +
337
+ ((r.verdict === "WRONG_BASE" || r.verdict === "WARNING") && (r.method_kind === "sum" || r.method_kind === "trim") ?
338
+ '<br>Shared update added <b>' + (Math.round(counted * 1000) / 1000) + '</b> time' + (counted === 1 ? '' : 's') : '') +
339
+ '</div></div>');
340
+ var t = '<div class="mini" style="grid-column:1/-1"><div class="k">Distance of each merged model (relative weight change; gate ' + Math.round(r.gate * 100) + '%)</div><div class="table-scroll"><table><thead><tr><th>Model</th><th class="num">From ancestor</th>' +
341
+ (r.distance_from_declared_base ? '<th class="num">From your base</th>' : '') + '</tr></thead><tbody>';
342
+ Object.keys(r.distance_from_ancestor).forEach(function (n) {
343
+ t += '<tr><td>' + esc(shortOf(n)) + '</td><td class="num">' + r.distance_from_ancestor[n].toFixed(4) + '</td>' +
344
+ (r.distance_from_declared_base ? '<td class="num">' + r.distance_from_declared_base[n].toFixed(4) + '</td>' : '') + '</tr>';
345
+ });
346
+ parts.push(t + '</tbody></table></div></div>');
347
+ return '<div class="evidence">' + parts.join("") + '</div>';
348
+ }
349
+
350
+ // ---------------- family tree (drawn from the checker's tree; laid out from Qwen2.5-1.5B for reading)
351
+ function treeSvg(r, cfg) {
352
+ var adj = []; for (var i = 0; i < N; i++) adj.push([]);
353
+ r.edges.forEach(function (e) { adj[e[0]].push(e[1]); adj[e[1]].push(e[0]); });
354
+ var root = BASE, depth = {}, kids = {}, q = [root]; depth[root] = 0;
355
+ while (q.length) { var u = q.shift(); kids[u] = []; adj[u].forEach(function (v) { if (!(v in depth)) { depth[v] = depth[u] + 1; kids[u].push(v); q.push(v); } }); }
356
+ var x = {}, slot = 0;
357
+ function place(u) { if (!kids[u].length) { x[u] = slot++; return; } kids[u].forEach(place); x[u] = (x[kids[u][0]] + x[kids[u][kids[u].length - 1]]) / 2; }
358
+ place(root);
359
+ var maxD = Math.max.apply(null, Object.keys(depth).map(function (k) { return depth[k]; }));
360
+ var W = Math.max(slot, 1) * 150, H = (maxD + 1) * 96 + 20;
361
+ function px(i) { return 75 + x[i] * 150; } function py(i) { return 34 + depth[i] * 96; }
362
+ var members = {}; cfg.models.forEach(function (m) { members[m.index] = true; });
363
+ var s = '<svg viewBox="0 0 ' + W + ' ' + H + '" role="img" aria-label="Family tree of the 7 models, drawn from their weights">';
364
+ r.edges.forEach(function (e) {
365
+ var a = e[0], b = e[1], d = r.D[a][b], far = d > r.gate;
366
+ s += '<line x1="' + px(a) + '" y1="' + py(a) + '" x2="' + px(b) + '" y2="' + py(b) + '" stroke="var(--axis)" stroke-width="2"' + (far ? ' stroke-dasharray="5 5"' : '') + '/>';
367
+ s += '<text x="' + ((px(a) + px(b)) / 2 + 6) + '" y="' + ((py(a) + py(b)) / 2) + '" font-size="12" fill="var(--muted)">' + (far ? 'far ' : '') + d.toFixed(4) + '</text>';
368
+ });
369
+ for (var k = 0; k < N; k++) {
370
+ var isM = members[k], isB = k === cfg.base, isA = k === r.best_index;
371
+ var ring = isA ? 'var(--good)' : (isB ? 'var(--critical)' : 'none');
372
+ if (ring !== 'none') s += '<circle cx="' + px(k) + '" cy="' + py(k) + '" r="15" fill="none" stroke="' + ring + '" stroke-width="3"/>';
373
+ s += '<circle cx="' + px(k) + '" cy="' + py(k) + '" r="9" fill="' + (isM ? 'var(--ink)' : 'var(--surface)') + '" stroke="var(--ink)" stroke-width="2"/>';
374
+ s += '<text x="' + px(k) + '" y="' + (py(k) + 32) + '" font-size="13" text-anchor="middle" fill="var(--ink)">' + esc(SHORT[k]) + '</text>';
375
+ }
376
+ return '<div class="tree-box"><div class="legend"><span><span class="dot" style="background:var(--ink)"></span>merged</span>' +
377
+ '<span><span class="dot" style="border:3px solid var(--good)"></span>closest common ancestor</span>' +
378
+ (cfg.base !== r.best_index ? '<span><span class="dot" style="border:3px solid var(--critical)"></span>your base</span>' : '') +
379
+ '<span>dashed = more than ' + Math.round(r.gate * 100) + '% apart</span></div>' + s + '</svg></div>';
380
+ }
381
+
382
+ function yaml(cfg, base) {
383
+ var y = "merge_method: " + cfg.method + "\nbase_model: " + D.names[base] + "\n";
384
+ if (cfg.normalize) y += "parameters:\n normalize: true\n";
385
+ y += "models:\n";
386
+ cfg.models.forEach(function (m) { y += " - model: " + D.names[m.index] + "\n parameters: {weight: " + m.weight + "}\n"; });
387
+ return y + "dtype: bfloat16\n";
388
+ }
389
+
390
+ function run() {
391
+ var cfg = readForm(), out = $("out");
392
+ if (!cfg.models.length) { out.innerHTML = '<div class="card"><p class="err">Tick at least one model to merge (other than the base).</p></div>'; return; }
393
+ var r;
394
+ try { r = C.check(D.G, D.names, cfg); } catch (e) { out.innerHTML = '<div class="card"><p class="err">' + esc(e.message) + '</p></div>'; return; }
395
+ var html = verdictHtml(r) + evidenceHtml(r, cfg) + treeSvg(r, cfg);
396
+ var fix = (r.verdict === "WRONG_BASE" || r.verdict === "WARNING") && r.best_index !== cfg.base;
397
+ html += '<div class="yaml-grid"><div><h3>Your mergekit config</h3><pre>' + esc(yaml(cfg, cfg.base)) + '</pre></div>' +
398
+ (fix ? '<div><h3>Corrected config</h3><pre>' + esc(yaml(cfg, r.best_index)) + '</pre></div>' : '') + '</div>';
399
+ out.innerHTML = html;
400
+ }
401
+
402
+ // ---------------- charts (measured results)
403
+ var tip = $("tip");
404
+ function showTip(e, html) { tip.innerHTML = html; tip.style.opacity = 1; moveTip(e); }
405
+ function moveTip(e) {
406
+ var x = e.clientX + 14, y = e.clientY + 14, w = tip.offsetWidth, h = tip.offsetHeight;
407
+ if (x + w > innerWidth - 8) x = e.clientX - w - 14; if (y + h > innerHeight - 8) y = e.clientY - h - 14;
408
+ tip.style.left = x + "px"; tip.style.top = y + "px";
409
+ }
410
+ function hideTip() { tip.style.opacity = 0; }
411
+ function bindTips(container) {
412
+ container.querySelectorAll("[data-tip]").forEach(function (el) {
413
+ el.addEventListener("mouseenter", function (e) { showTip(e, el.getAttribute("data-tip")); });
414
+ el.addEventListener("mousemove", moveTip);
415
+ el.addEventListener("mouseleave", hideTip);
416
+ });
417
+ }
418
+ function bar(x, y, w, h) { // rounded top (4px), square at the baseline
419
+ var r = Math.min(4, w / 2, h);
420
+ return "M" + x + "," + (y + h) + "V" + (y + r) + "Q" + x + "," + y + " " + (x + r) + "," + y + "H" + (x + w - r) + "Q" + (x + w) + "," + y + " " + (x + w) + "," + (y + r) + "V" + (y + h) + "Z";
421
+ }
422
+ function grouped(el, cats, a, b, opts) {
423
+ var W = opts.W, H = 260, L = 40, R = 10, T = 14, B = 46, ih = H - T - B, iw = W - L - R, max = opts.max;
424
+ var gw = iw / cats.length, bw = Math.min(28, (gw - 18) / 2);
425
+ var s = '<svg viewBox="0 0 ' + W + ' ' + H + '" role="img" aria-label="' + esc(opts.label) + '">';
426
+ opts.ticks.forEach(function (t) {
427
+ var y = T + ih - t / max * ih;
428
+ s += '<line x1="' + L + '" x2="' + (W - R) + '" y1="' + y + '" y2="' + y + '" stroke="' + (t === 0 ? 'var(--axis)' : 'var(--grid)') + '" stroke-width="1"/>';
429
+ s += '<text x="' + (L - 6) + '" y="' + (y + 4) + '" font-size="11" text-anchor="end" fill="var(--muted)">' + opts.fmt(t) + '</text>';
430
+ });
431
+ cats.forEach(function (c, i) {
432
+ var cx = L + gw * i + gw / 2;
433
+ [[a[i], "var(--s1)", -1, opts.na], [b[i], "var(--s2)", 1, opts.nb]].forEach(function (v) {
434
+ var h = Math.max(v[0] / max * ih, 1), x = v[2] < 0 ? cx - bw - 1 : cx + 1, y = T + ih - h;
435
+ var t = '<b>' + esc(c) + '</b><br>' + esc(v[3]) + ': <b>' + opts.fmt2(v[0]) + '</b>';
436
+ s += '<path d="' + bar(x, y, bw, h) + '" fill="' + v[1] + '"/>';
437
+ s += '<rect x="' + (x - 3) + '" y="' + T + '" width="' + (bw + 6) + '" height="' + ih + '" fill="transparent" data-tip="' + esc(t) + '"/>';
438
+ });
439
+ if (opts.label1 && opts.label1(i)) s += '<text x="' + (cx + 2) + '" y="' + (T + ih - Math.max(b[i] / max * ih, 1) - 6) + '" font-size="12" text-anchor="start" fill="var(--ink)" font-weight="600">' + opts.fmt2(b[i]) + '</text>';
440
+ if (opts.labelA && opts.labelA(i)) s += '<text x="' + (cx - 2) + '" y="' + (T + ih - 6) + '" font-size="12" text-anchor="end" fill="var(--ink)" font-weight="600">' + opts.labelA(i) + '</text>';
441
+ s += '<text x="' + cx + '" y="' + (H - B + 18) + '" font-size="12" text-anchor="middle" fill="var(--ink-2)">' + esc(c) + '</text>';
442
+ if (opts.sub) s += '<text x="' + cx + '" y="' + (H - B + 33) + '" font-size="11" text-anchor="middle" fill="var(--muted)">' + esc(opts.sub[i]) + '</text>';
443
+ });
444
+ el.innerHTML = s + '</svg>'; bindTips(el);
445
+ }
446
+ function table(el, head, rows) {
447
+ el.innerHTML = '<table><thead><tr>' + head.map(function (h, i) { return '<th' + (i ? ' class="num"' : '') + '>' + esc(h) + '</th>'; }).join("") +
448
+ '</tr></thead><tbody>' + rows.map(function (r) { return '<tr>' + r.map(function (c, i) { return '<td' + (i ? ' class="num"' : '') + '>' + esc(c) + '</td>'; }).join("") + '</tr>'; }).join("") + '</tbody></table>';
449
+ }
450
+
451
+ var SETS = ["QwQ+MBPP", "QwQ+Business", "MBPP+Legal", "Business+Legal", "QwQ+MBPP+Business"];
452
+ var TA_I = [56.5, 57.5, 50.25, 45.75, 58.0], TA_B = [46.5, 38.5, 39.5, 33.75, 3.25];
453
+ var RAW_I = ["70.0 / 43.0", "69.5 / 45.5", "58.0 / 42.5", "54.5 / 37.0", "68.0 / 48.0"], RAW_B = ["62.0 / 31.0", "40.0 / 37.0", "51.0 / 28.0", "41.0 / 26.5", "6.5 / 0.0"];
454
+ grouped($("chart-base"), SETS, TA_I, TA_B, { W: 900, max: 60, ticks: [0, 20, 40, 60], label: "Average accuracy of Task Arithmetic merges with the two bases",
455
+ fmt: function (t) { return t + "%"; }, fmt2: function (v) { return v.toFixed(2).replace(/\.?0+$/, "") + "%"; },
456
+ na: "Base = Instruct", nb: "Base = Qwen2.5-1.5B", label1: function (i) { return i === 4; },
457
+ sub: SETS.map(function (_, i) { return "+" + (TA_I[i] - TA_B[i]).toFixed(2).replace(/\.?0+$/, "") + " pts"; }) });
458
+ table($("table-base"), ["Merge (Task Arithmetic, sum)", "Base = Instruct (GSM8K / MBPP)", "Base = Qwen2.5-1.5B (GSM8K / MBPP)", "Gain, points"],
459
+ SETS.map(function (s, i) { return [s, RAW_I[i], RAW_B[i], "+" + (TA_I[i] - TA_B[i]).toFixed(2)]; }));
460
+
461
+ var PAIRS = ["QwQ+MBPP", "QwQ+Bus.", "QwQ+Legal", "MBPP+Bus.", "MBPP+Legal", "Bus.+Legal"];
462
+ var COS_I = [0.0046, 0.0001, 0.0001, 0.0043, 0.0043, 0.0054], COS_B = [0.9151, 0.8001, 0.8734, 0.8615, 0.9403, 0.8249];
463
+ grouped($("chart-cos"), PAIRS, COS_I, COS_B, { W: 520, max: 1, ticks: [0, 0.5, 1], label: "Task-vector cosine from each base",
464
+ fmt: function (t) { return t.toFixed(1); }, fmt2: function (v) { return v.toFixed(4); }, na: "From Instruct", nb: "From Qwen2.5-1.5B",
465
+ labelA: function (i) { return i === 0 ? "≈0" : ""; } });
466
+ table($("table-cos"), ["Pair", "From Instruct", "From Qwen2.5-1.5B"], PAIRS.map(function (p, i) { return [p, COS_I[i].toFixed(4), COS_B[i].toFixed(4)]; }));
467
+
468
+ (function sweep() {
469
+ var pts = [[0, 56.5, "75.0 / 38.0", "Instruct"], [5, 54.5, "67.0 / 42.0"], [10, 54.0, "67.5 / 40.5"], [20, 47.75, "61.0 / 34.5"],
470
+ [30, 35.25, "44.0 / 26.5", "199 of 200 maths answers run to the length limit"], [50, 0, "0.0 / 0.0", "collapsed"], [100, 51.25, "50.0 / 52.5", "Coder"]];
471
+ var W = 520, H = 260, L = 40, R = 14, T = 14, B = 40, iw = W - L - R, ih = H - T - B;
472
+ function X(v) { return L + v / 100 * iw; } function Y(v) { return T + ih - v / 60 * ih; }
473
+ var s = '<svg viewBox="0 0 ' + W + ' ' + H + '" role="img" aria-label="Average accuracy while stepping from Instruct towards Coder">';
474
+ [0, 20, 40, 60].forEach(function (t) {
475
+ s += '<line x1="' + L + '" x2="' + (W - R) + '" y1="' + Y(t) + '" y2="' + Y(t) + '" stroke="' + (t === 0 ? 'var(--axis)' : 'var(--grid)') + '"/>' +
476
+ '<text x="' + (L - 6) + '" y="' + (Y(t) + 4) + '" font-size="11" text-anchor="end" fill="var(--muted)">' + t + '%</text>';
477
+ });
478
+ [0, 10, 20, 30, 50, 100].forEach(function (t) {
479
+ s += '<text x="' + X(t) + '" y="' + (H - B + 18) + '" font-size="11" text-anchor="middle" fill="var(--muted)">' + t + '%</text>';
480
+ });
481
+ s += '<text x="' + (L + iw / 2) + '" y="' + (H - 6) + '" font-size="12" text-anchor="middle" fill="var(--ink-2)">step from Instruct towards Coder</text>';
482
+ s += '<line x1="' + X(10) + '" x2="' + X(10) + '" y1="' + T + '" y2="' + (T + ih) + '" stroke="var(--ink-2)" stroke-dasharray="4 4"/>' +
483
+ '<text x="' + (X(10) + 6) + '" y="' + (T + 12) + '" font-size="12" fill="var(--ink-2)">gate 10%</text>';
484
+ s += '<polyline fill="none" stroke="var(--s1)" stroke-width="2" stroke-linejoin="round" points="' + pts.map(function (p) { return X(p[0]) + "," + Y(p[1]); }).join(" ") + '"/>';
485
+ pts.forEach(function (p) {
486
+ s += '<circle cx="' + X(p[0]) + '" cy="' + Y(p[1]) + '" r="4.5" fill="var(--s1)" stroke="var(--surface)" stroke-width="2"/>';
487
+ var t = '<b>' + p[0] + '% step</b>' + (p[3] ? ' (' + esc(p[3]) + ')' : '') + '<br>GSM8K / MBPP: <b>' + p[2] + '</b><br>average <b>' + p[1] + '%</b>';
488
+ s += '<circle cx="' + X(p[0]) + '" cy="' + Y(p[1]) + '" r="14" fill="transparent" data-tip="' + esc(t) + '"/>';
489
+ });
490
+ s += '<text x="' + (X(50) + 8) + '" y="' + (Y(0) - 8) + '" font-size="12" fill="var(--ink)" font-weight="600">0%</text>';
491
+ $("chart-sweep").innerHTML = s + '</svg>'; bindTips($("chart-sweep"));
492
+ table($("table-sweep"), ["Step towards Coder", "GSM8K / MBPP", "Average"], pts.map(function (p) { return [p[0] + "%", p[2], p[1] + "%"]; }));
493
+ })();
494
+
495
+ applyPreset("mistake");
496
+ })();
497
+ </script>
498
+ </body>
499
  </html>