Phase 3: LLM-tier speciation + multi-seed firm-up of the recombination claims
llm_speciation (new kind; src/llm/speciation.py): E13 in LLM weights. LoRA children share the frozen base's coordinates, so merge failure is functional by construction. CONFLICT (ambiguous sort prompts learned under opposite conventions — the BDM structure): function-specific hybrid breakdown — merged coherence 0.02-0.08 falls below BOTH parents (~0.2) on the conflicted function; and in the de-confounded `add` design (private budget fixed, conflict added on top; 3 seeds after a single-seed pilot showed one anomalous point) the merge's private-family accuracy shows NO trend with conflict — the damage is surgical, not global. DURATION (over-trained disjoint specialists, 1->12 epochs): the merge improves (0.84->0.94) and stays above the best parent — the MLP "no emergent isolation" null generalises; relevant to the expert-training-duration report (2607.11997), with the epistasis prediction left to the decisive experiment. Multi-seed firm-up (seeds threaded into specialist caches; `seeds:` list support in the runner; fixed test sets): all three recombination claims hold with CIs — merges beat every specialist (5 seeds, ties 0.647±0.027 > best spec 0.592±0.009; worst-family 0.28 vs <=0.16); union 0.274±0.026 > fusion 0.174±0.102 on hard (3 seeds); directed 0.221±0.026 > soup. NEW finding: fusion is seed-FRAGILE where headroom exists (CI ±0.10) while routing/directed selection are stable (±0.026) — the union/selection operators win on reliability, not just mean. Figures (llm_speciation 3-panel; llm_seeds 3-panel with 95% CI), READMEs, +1 convention test (150 green), make llm-speciation / llm-seeds targets. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BkRLcc18rwT2Lysu6PbG7v
This commit is contained in:
parent
58e6c74609
commit
5a23ddaf2a
31 changed files with 956 additions and 11 deletions
|
|
@ -63,10 +63,10 @@ def run_merge_experiment(cfg: dict) -> pd.DataFrame:
|
|||
rows += _rows(name, "base", "base", evaluate(m, tok, test))
|
||||
del m; torch.cuda.empty_cache()
|
||||
|
||||
# one specialist per family
|
||||
# one specialist per family (cache is seed-specific: multi-seed runs retrain per seed)
|
||||
dirs = []
|
||||
for i, f in enumerate(fams):
|
||||
d = str(adapters_root / f"spec_{f}{suffix}")
|
||||
d = str(adapters_root / f"spec_{f}{suffix}_s{seed}")
|
||||
train_specialist(base, f, d, n_train=n_train, epochs=epochs, seed=seed + i, hard=hard,
|
||||
r=int(lora.get("r", 16)), alpha=int(lora.get("alpha", 32)))
|
||||
dirs.append(d)
|
||||
|
|
@ -103,7 +103,7 @@ def _load_or_train_specialists(cfg: dict, base: str, fams: list[str], name: str,
|
|||
adapters_root = Path(cfg.get("adapters_dir", "models/llm"))
|
||||
dirs: list[str] = []
|
||||
for i, f in enumerate(fams):
|
||||
d = str(adapters_root / f"spec_{f}{suffix}")
|
||||
d = str(adapters_root / f"spec_{f}{suffix}_s{seed}")
|
||||
if not (Path(d) / "adapter_config.json").exists(): # reuse across llm_merge / llm_moe runs
|
||||
train_specialist(base, f, d, n_train=n_train, epochs=epochs, seed=seed + i, hard=hard,
|
||||
r=int(lora.get("r", 16)), alpha=int(lora.get("alpha", 32)))
|
||||
|
|
@ -258,12 +258,22 @@ def run_directed_experiment(cfg: dict) -> pd.DataFrame:
|
|||
return pd.DataFrame(rows)
|
||||
|
||||
|
||||
def run_speciation_dispatch(cfg: dict) -> pd.DataFrame:
|
||||
from .speciation import run_speciation_experiment # local import: torch-heavy
|
||||
return run_speciation_experiment(cfg)
|
||||
|
||||
|
||||
_RUNNERS = {"llm_merge": run_merge_experiment, "llm_moe": run_moe_experiment,
|
||||
"llm_directed": run_directed_experiment}
|
||||
"llm_directed": run_directed_experiment, "llm_speciation": run_speciation_dispatch}
|
||||
|
||||
|
||||
def run_and_save(config_path: str | Path) -> Path:
|
||||
"""Load an LLM experiment YAML, run it (dispatch on ``kind``), and write the artifact triple."""
|
||||
"""Load an LLM experiment YAML, run it (dispatch on ``kind``), and write the artifact triple.
|
||||
|
||||
A ``seeds: [..]`` list runs the experiment once per seed (specialist caches are seed-specific)
|
||||
and concatenates the frames with a ``seed`` column — the Layer-2 statistical-reproducibility
|
||||
pattern (fixed test sets, training seed varies).
|
||||
"""
|
||||
config_path = Path(config_path)
|
||||
cfg = yaml.safe_load(config_path.read_text())
|
||||
out_dir = Path(cfg.get("output", {}).get("dir", f"results/{cfg['experiment']}"))
|
||||
|
|
@ -271,9 +281,21 @@ def run_and_save(config_path: str | Path) -> Path:
|
|||
kind = cfg.get("kind", "llm_merge")
|
||||
if kind not in _RUNNERS:
|
||||
raise ValueError(f"unknown LLM experiment kind {kind!r} (expected one of {list(_RUNNERS)})")
|
||||
df = _RUNNERS[kind](cfg)
|
||||
seeds = cfg.get("seeds")
|
||||
if seeds:
|
||||
frames = []
|
||||
for s in seeds:
|
||||
run_cfg = dict(cfg); run_cfg["seed"] = int(s)
|
||||
f = _RUNNERS[kind](run_cfg); f["seed"] = int(s)
|
||||
frames.append(f)
|
||||
df = pd.concat(frames, ignore_index=True)
|
||||
cfg["seed"] = int(seeds[0]) # manifest master seed = first of the list
|
||||
else:
|
||||
df = _RUNNERS[kind](cfg)
|
||||
extra = {"layer": "2", "tier": "llm", "base_model": cfg["base_model"],
|
||||
"hard": bool(cfg.get("hard", False))}
|
||||
if seeds:
|
||||
extra["seeds"] = [int(s) for s in seeds]
|
||||
if kind == "llm_moe":
|
||||
extra["operators"] = list(cfg.get("operators", []))
|
||||
if kind == "llm_directed":
|
||||
|
|
|
|||
150
src/llm/speciation.py
Normal file
150
src/llm/speciation.py
Normal file
|
|
@ -0,0 +1,150 @@
|
|||
"""LLM-tier model speciation (E13 in language-model weights) — the conflict cliff + the duration null.
|
||||
|
||||
The real-LLM image of E13, with a structural bonus: LoRA deltas live in the frozen base's coordinate
|
||||
system, so there is **no permutation/rescaling ambiguity by construction** — any merge failure here is
|
||||
*functional* incompatibility, the residual isolated architecturally (no alignment step needed).
|
||||
|
||||
Two knobs, mirroring the MLP experiment:
|
||||
|
||||
* **Conflict (imposed, the cliff).** Two LoRA children from the same base. Each has a private,
|
||||
disjoint skill family (A: ``strings``, B: ``arith`` — so the merge has genuine Fisher–Muller value)
|
||||
plus a shared set of **ambiguous convention prompts** ("Sort the list [...]" with no direction),
|
||||
which child A learns to answer *ascending* and child B *descending* — each convention harmless
|
||||
alone, contradictory jointly (a true Bateson–Dobzhansky–Muller structure). ``conflict_frac`` sweeps
|
||||
the fraction of each child's training data that is convention data. Merged 50/50 (soup), the
|
||||
prediction is E13's cliff in verifier units: private-family competence of the *merge* degrades and
|
||||
convention coherence collapses as conflict grows, while each *parent* stays fine — hybrid
|
||||
breakdown, not parent damage.
|
||||
* **Duration (emergent, the null test).** Pure disjoint specialists (zero shared data), over-trained
|
||||
by sweeping epochs. The MLP tier found *no* emergent isolation (the merge rescued specialists at
|
||||
every divergence); the empirical merging literature reports averaging prefers *under*-trained
|
||||
experts (arXiv:2607.11997). This sweep arbitrates: if the merged model's quality falls with
|
||||
duration while each parent's own-family quality does not, that is emergent incompatibility at the
|
||||
LLM tier; if not, the MLP null generalises.
|
||||
|
||||
Convention coherence of a model = max(accuracy under ascending grading, accuracy under descending
|
||||
grading) on the shared ambiguous prompts: a coherent parent scores high under its own convention; a
|
||||
hybrid that mixes conventions scores low under both (the mu(S)/2 floor made operational).
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
|
||||
from .evaluate import generate, load_model
|
||||
from .merge import load_specialists, make_merge
|
||||
from .specialise import train_lora_on_tasks
|
||||
from .tasks import Task, _fmt_list, make_tasks, verify
|
||||
|
||||
|
||||
def make_convention_tasks(n: int, seed: int, convention: str) -> list[Task]:
|
||||
"""Ambiguous sort prompts with a convention-dependent canonical answer.
|
||||
|
||||
The prompt never states a direction ("Sort the list [...]"), so *either* convention is a
|
||||
self-consistent, harmless resolution — the conflict exists only between lineages.
|
||||
|
||||
Args:
|
||||
n (int): number of tasks.
|
||||
seed (int): prompts are a pure function of the seed (same seed -> same prompts, so the two
|
||||
conventions grade the *same* inputs).
|
||||
convention (str): ``asc`` or ``desc``.
|
||||
|
||||
Returns:
|
||||
list[Task]: family ``"ambig"``; answers sorted per the convention.
|
||||
"""
|
||||
rng = np.random.default_rng(seed)
|
||||
out = []
|
||||
for _ in range(n):
|
||||
xs = rng.integers(0, 30, size=int(rng.integers(6, 10))).tolist()
|
||||
ans = sorted(xs, reverse=(convention == "desc"))
|
||||
out.append(Task("ambig", f"Sort the list {_fmt_list(xs)}. "
|
||||
"Output only the resulting list and nothing else.", _fmt_list(ans)))
|
||||
return out
|
||||
|
||||
|
||||
def _acc(model, tok, tasks: list[Task]) -> float:
|
||||
outs = generate(model, tok, [t.prompt for t in tasks])
|
||||
return float(np.mean([verify(o, t) for o, t in zip(outs, tasks)]))
|
||||
|
||||
|
||||
def run_speciation_experiment(cfg: dict) -> pd.DataFrame:
|
||||
"""Run the conflict-cliff and/or duration sweeps; return long-form accuracies.
|
||||
|
||||
Config keys: ``base_model``, ``family_a``/``family_b`` (private families), ``n_train``,
|
||||
``n_test``, ``epochs`` (conflict mode), ``conflict_fracs`` (list), ``durations`` (list of epoch
|
||||
counts), ``lora``, ``seed``, ``adapters_dir``.
|
||||
"""
|
||||
import torch
|
||||
|
||||
name = cfg["experiment"]
|
||||
base = cfg["base_model"]
|
||||
fam_a, fam_b = cfg.get("family_a", "strings"), cfg.get("family_b", "arith")
|
||||
n_train, n_test = int(cfg.get("n_train", 400)), int(cfg.get("n_test", 100))
|
||||
epochs = int(cfg.get("epochs", 3))
|
||||
lora = cfg.get("lora", {})
|
||||
r, alpha = int(lora.get("r", 16)), int(lora.get("alpha", 32))
|
||||
seed = int(cfg["seed"])
|
||||
hard = bool(cfg.get("hard", False))
|
||||
root = Path(cfg.get("adapters_dir", "models/llm")) / "speciation"
|
||||
|
||||
# Fixed evaluation sets (identical across the sweep; convention pairs grade the SAME prompts).
|
||||
test_a = make_tasks(fam_a, n_test, seed=1000, hard=hard)
|
||||
test_b = make_tasks(fam_b, n_test, seed=1001, hard=hard)
|
||||
amb_asc = make_convention_tasks(n_test, seed=5000, convention="asc")
|
||||
amb_desc = make_convention_tasks(n_test, seed=5000, convention="desc")
|
||||
|
||||
def measure(model, tok, label: str, mode: str, x: float, rows: list[dict]) -> None:
|
||||
accs = {fam_a: _acc(model, tok, test_a), fam_b: _acc(model, tok, test_b),
|
||||
"ambig_asc": _acc(model, tok, amb_asc), "ambig_desc": _acc(model, tok, amb_desc)}
|
||||
accs["coherence"] = max(accs["ambig_asc"], accs["ambig_desc"])
|
||||
accs["mean_private"] = (accs[fam_a] + accs[fam_b]) / 2.0
|
||||
for k, v in accs.items():
|
||||
rows.append({"experiment": name, "mode": mode, "x": float(x),
|
||||
"model": label, "metric": k, "accuracy": v})
|
||||
|
||||
def train_child(tasks: list, out_dir: Path, ep: int) -> str:
|
||||
return train_lora_on_tasks(base, tasks, str(out_dir), epochs=ep, r=r, alpha=alpha,
|
||||
seed=seed, batch_size=int(cfg.get("batch_size", 8)))
|
||||
|
||||
def merged_and_parents(dir_a: str, dir_b: str, mode: str, x: float, rows: list[dict]) -> None:
|
||||
for d, label in ((dir_a, "parent_a"), (dir_b, "parent_b")):
|
||||
m, tok = load_model(base, adapter_dir=d)
|
||||
measure(m, tok, label, mode, x, rows)
|
||||
del m; torch.cuda.empty_cache()
|
||||
model, tok = load_specialists(base, [dir_a, dir_b])
|
||||
make_merge(model, 2, "soup", "soup")
|
||||
measure(model, tok, "merge_soup", mode, x, rows)
|
||||
del model; torch.cuda.empty_cache()
|
||||
|
||||
rows: list[dict] = []
|
||||
|
||||
# Two conflict designs. "replace" (default) holds the TOTAL training budget fixed, so the
|
||||
# private-family readout is confounded with shrinking private data (coherence is the clean metric
|
||||
# there). "add" holds the PRIVATE budget fixed and adds conflict data on top, so any decline in the
|
||||
# merge's private-family accuracy is interference, not a data-budget artefact.
|
||||
conflict_mode = str(cfg.get("conflict_mode", "replace"))
|
||||
for frac in cfg.get("conflict_fracs", []):
|
||||
frac = float(frac)
|
||||
n_conv = int(round(frac * n_train))
|
||||
n_own = n_train if conflict_mode == "add" else n_train - n_conv
|
||||
tasks_a = (make_tasks(fam_a, n_own, seed=seed, hard=hard)
|
||||
+ make_convention_tasks(n_conv, seed=seed + 50, convention="asc"))
|
||||
tasks_b = (make_tasks(fam_b, n_own, seed=seed + 1, hard=hard)
|
||||
+ make_convention_tasks(n_conv, seed=seed + 50, convention="desc"))
|
||||
da = train_child(tasks_a, root / "conflict_a", epochs)
|
||||
db = train_child(tasks_b, root / "conflict_b", epochs)
|
||||
merged_and_parents(da, db, f"conflict_{conflict_mode}"
|
||||
if conflict_mode != "replace" else "conflict", frac, rows)
|
||||
|
||||
for dur in cfg.get("durations", []):
|
||||
dur = int(dur)
|
||||
tasks_a = make_tasks(fam_a, n_train, seed=seed, hard=hard)
|
||||
tasks_b = make_tasks(fam_b, n_train, seed=seed + 1, hard=hard)
|
||||
da = train_child(tasks_a, root / "dur_a", dur)
|
||||
db = train_child(tasks_b, root / "dur_b", dur)
|
||||
merged_and_parents(da, db, "duration", dur, rows)
|
||||
|
||||
return pd.DataFrame(rows)
|
||||
Loading…
Add table
Add a link
Reference in a new issue