exp012 shipped: blob v1 honest negative BUT the role-aligned gauge reveals multiband beats monolith ~10% on HIGH-band foreground structure; ANIMA R0b all green (dtype violation caught+fixed)
Browse files
exp012_blob_supervised/README.md
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# exp012_blob_supervised — blob supervision v1 + THE ROLE-ALIGNED GAUGE
|
| 2 |
+
# DISCOVERY (CANDIDATE s0; s1 running) + ANIMA R0b CERTIFICATION
|
| 3 |
+
|
| 4 |
+
**Blob supervision v1** (foreground-weighted LP-x0 on the HIGH band, λ=0.5):
|
| 5 |
+
HONEST NEGATIVE on both instruments — training-side blob gauge moved +0.03%
|
| 6 |
+
(0.111495 vs uniform 0.111528; P1 technical hit, economically nil); the
|
| 7 |
+
image battery (P4) showed mild dilution (grounding +0.1931 vs +0.2135;
|
| 8 |
+
HIGH-lesion LP-dominance 0.0662 vs 0.0727 — not sharpened). The eps term
|
| 9 |
+
dominates at this dose; stronger coupling or pure-band phases are the
|
| 10 |
+
follow-ups.
|
| 11 |
+
|
| 12 |
+
**THE KEEPER — the role-aligned gauge (in-bed reference gauging):**
|
| 13 |
+
|
| 14 |
+
| arm | HIGH-band foreground-LP-x0 gauge |
|
| 15 |
+
|---|---|
|
| 16 |
+
| frozen | 0.15549 |
|
| 17 |
+
| monolith r48 | 0.12339 |
|
| 18 |
+
| **uniform multiband** | **0.11153** |
|
| 19 |
+
| **blob multiband** | **0.11150** |
|
| 20 |
+
|
| 21 |
+
**The first gauge where multiband CLEARLY beats the matched monolith (~10%)**
|
| 22 |
+
— band specialists are better at foreground coarse structure in the
|
| 23 |
+
HIGH-noise band, exactly where the coarse-to-fine role map says they should
|
| 24 |
+
be. Every aggregate-eps comparison had hidden this. Band assignment's payer
|
| 25 |
+
is role-aligned MEASUREMENT — the specialists were already earning.
|
| 26 |
+
|
| 27 |
+
**ANIMA R0b (bundled: `r0b_probe.py`): ALL GATES GREEN.** 28/28 DiT blocks
|
| 28 |
+
carry relays (14,275,716 bf16 params), freeze-by-lr-0 exact, zero-init +
|
| 29 |
+
toggle exact. The gate CAUGHT a dtype-law violation live (fresh relays
|
| 30 |
+
attached fp32 on the bf16 trunk via a meta-tensor sniff; fixed to the
|
| 31 |
+
DECLARED dtype, fork commit on feat/aleph-adapter). exp004 training is
|
| 32 |
+
ready.
|
| 33 |
+
|
| 34 |
+
**Caveats.** s0 (s1 running); one λ; one coupling form. Cost ≈ 1.6 GPU-h
|
| 35 |
+
+ 0.2h battery + R0b probes.
|
exp012_blob_supervised/dexp012_blob_supervised.py
ADDED
|
@@ -0,0 +1,235 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""dexp012_blob_supervised.py — exp012: SEGMENTATION-BLOB SUPERVISION on the
|
| 2 |
+
HIGH-noise band (Phil's blobbing role, first real qualitatively-different
|
| 3 |
+
supervision; day-3 plan item 2 — design preregistered there).
|
| 4 |
+
|
| 5 |
+
Coupling (conservative, controlled): foreground-weighted LOW-PASS x0 loss on
|
| 6 |
+
the HIGH band only:
|
| 7 |
+
x0_hat = (x_t - sqrt(1-abar_t) * eps_hat) / sqrt(abar_t)
|
| 8 |
+
L_blob = mean( blob ⊙ (LP(x0_hat) - LP(x0))^2 ), lambda = 0.5
|
| 9 |
+
routed by the crossfade windows (w2 only). Differs from exp009's inert
|
| 10 |
+
reweighting: x0-space structural prediction at high noise + EXTERNAL
|
| 11 |
+
segmentation information (the rebuilt 100%-non-empty blob targets).
|
| 12 |
+
|
| 13 |
+
In-bed gauges for ALL arms (blob-mb3 trained here; uniform-mb3 + mono48
|
| 14 |
+
loaded from exp011 ckpts; frozen): common eps gauge per band + BLOB GAUGE
|
| 15 |
+
(foreground LP-x0 error) per band. Prereg P1-P4 in the day-3 plan.
|
| 16 |
+
|
| 17 |
+
Pod: bash pod2/run_exp012.sh [DEXP12_SEED=0 DEXP12_LAMBDA=0.5]
|
| 18 |
+
"""
|
| 19 |
+
from __future__ import annotations
|
| 20 |
+
|
| 21 |
+
import json
|
| 22 |
+
import os
|
| 23 |
+
import sys
|
| 24 |
+
import time
|
| 25 |
+
|
| 26 |
+
sys.path[:0] = ["pod2", "."]
|
| 27 |
+
|
| 28 |
+
import torch
|
| 29 |
+
import torch.nn.functional as F
|
| 30 |
+
|
| 31 |
+
from pod_ledger import ledger_run, note, burn_down
|
| 32 |
+
from d1_substrate import MEM_FRACTION
|
| 33 |
+
from dexp006_sd15core_relay import make_schedule, add_noise
|
| 34 |
+
from dexp008_multiband import (MultibandDelta, MonoDelta, band_weights,
|
| 35 |
+
band_of, attach, load_unet, N_BANDS)
|
| 36 |
+
from dexp009_bandroles import lp
|
| 37 |
+
|
| 38 |
+
N_TRAIN, N_VAL = 4096, 256
|
| 39 |
+
BATCH = int(os.environ.get("DEXP12_BATCH", "16"))
|
| 40 |
+
STEPS = int(os.environ.get("DEXP12_STEPS", "3000"))
|
| 41 |
+
SEED = int(os.environ.get("DEXP12_SEED", "0"))
|
| 42 |
+
LAM = float(os.environ.get("DEXP12_LAMBDA", "0.5"))
|
| 43 |
+
LR, CFG_DROPOUT = 1e-3, 0.1
|
| 44 |
+
D11 = ("/workspace/data/dexp011" if os.path.isdir("/workspace")
|
| 45 |
+
else "./data/dexp011")
|
| 46 |
+
D11_CKPT = ("/workspace/ckpts2/dexp011" if os.path.isdir("/workspace")
|
| 47 |
+
else D11)
|
| 48 |
+
DATA_DIR = ("/workspace/data/dexp012" if os.path.isdir("/workspace")
|
| 49 |
+
else os.path.join(os.environ.get("GEOLIP_DATA", "./data"),
|
| 50 |
+
"dexp012"))
|
| 51 |
+
CKPT_DIR = ("/workspace/ckpts2/dexp012" if os.path.isdir("/workspace")
|
| 52 |
+
else DATA_DIR)
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def x0_from_eps(noisy, eps, t, acp):
|
| 56 |
+
a = acp[t].sqrt()[:, None, None, None]
|
| 57 |
+
s = (1 - acp[t]).sqrt()[:, None, None, None]
|
| 58 |
+
return (noisy - s * eps) / a.clamp_min(1e-4)
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
def blob_lp_err(x0_hat, x0, blob):
|
| 62 |
+
"""Foreground-weighted LP-x0 squared error, per sample (B,)."""
|
| 63 |
+
d2 = (lp(x0_hat) - lp(x0)) ** 2 # (B,4,64,64)
|
| 64 |
+
m = blob[:, None] # (B,1,64,64)
|
| 65 |
+
denom = m.sum(dim=(1, 2, 3)).clamp_min(1.0) * d2.shape[1]
|
| 66 |
+
return (d2 * m).sum(dim=(1, 2, 3)) / denom
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
def run(device="cuda"):
|
| 70 |
+
torch.cuda.set_per_process_memory_fraction(MEM_FRACTION, 0)
|
| 71 |
+
os.makedirs(CKPT_DIR, exist_ok=True)
|
| 72 |
+
os.makedirs(DATA_DIR, exist_ok=True)
|
| 73 |
+
acp = make_schedule(device)
|
| 74 |
+
cache = torch.load(os.path.join(D11, "cache.pt"), map_location="cpu",
|
| 75 |
+
weights_only=True)
|
| 76 |
+
assert int(cache["blob_empty_count"]) == 0, \
|
| 77 |
+
"blob targets not the rebuilt ones — run fix_blob_targets first"
|
| 78 |
+
|
| 79 |
+
def set_w(wraps, s01):
|
| 80 |
+
w = band_weights(s01)
|
| 81 |
+
for wr in wraps:
|
| 82 |
+
wr.w_bands = w
|
| 83 |
+
return w
|
| 84 |
+
|
| 85 |
+
def loss_of(unet, wraps, lat, ehs, blob, gen):
|
| 86 |
+
bsz = lat.shape[0]
|
| 87 |
+
drop = torch.rand(bsz, generator=gen, device=device) < CFG_DROPOUT
|
| 88 |
+
ehs = ehs.clone()
|
| 89 |
+
ehs[drop] = 0
|
| 90 |
+
t = torch.randint(0, 1000, (bsz,), generator=gen, device=device)
|
| 91 |
+
w = set_w(wraps, t.float() / 1000.0)
|
| 92 |
+
noise = torch.randn(lat.shape, generator=gen, device=device)
|
| 93 |
+
noisy = add_noise(lat, noise, t, acp)
|
| 94 |
+
pred = unet(noisy, t, ehs, return_dict=False)[0]
|
| 95 |
+
base = ((pred - noise) ** 2).mean(dim=(1, 2, 3))
|
| 96 |
+
x0h = x0_from_eps(noisy, pred, t, acp)
|
| 97 |
+
blob_term = blob_lp_err(x0h, lat, blob)
|
| 98 |
+
return (base + LAM * w[:, 2] * blob_term).mean()
|
| 99 |
+
|
| 100 |
+
@torch.no_grad()
|
| 101 |
+
def val(unet, wraps):
|
| 102 |
+
"""Common + blob gauges per band, identical math for every arm."""
|
| 103 |
+
per_band = {0: [], 1: [], 2: []}
|
| 104 |
+
blob_band = {0: [], 1: [], 2: []}
|
| 105 |
+
tot = []
|
| 106 |
+
for i in range(0, N_VAL, 32):
|
| 107 |
+
lat = cache["val_lat"][i:i + 32].to(device)
|
| 108 |
+
ehs = cache["val_ehs"][i:i + 32].to(device)
|
| 109 |
+
noise = cache["val_noise"][i:i + 32].to(device)
|
| 110 |
+
t = cache["val_t"][i:i + 32].to(device)
|
| 111 |
+
blob = cache["val_blob"][i:i + 32].float().to(device)
|
| 112 |
+
set_w(wraps, t.float() / 1000.0)
|
| 113 |
+
noisy = add_noise(lat, noise, t, acp)
|
| 114 |
+
pred = unet(noisy, t, ehs, return_dict=False)[0]
|
| 115 |
+
mse = ((pred - noise) ** 2).mean(dim=(1, 2, 3))
|
| 116 |
+
bg = blob_lp_err(x0_from_eps(noisy, pred, t, acp), lat, blob)
|
| 117 |
+
tot += mse.tolist()
|
| 118 |
+
for j, tv in enumerate((t.float() / 1000.0).tolist()):
|
| 119 |
+
b = band_of(tv)
|
| 120 |
+
per_band[b].append(mse[j].item())
|
| 121 |
+
blob_band[b].append(bg[j].item())
|
| 122 |
+
return (sum(tot) / len(tot),
|
| 123 |
+
{f"band{b}": round(sum(v) / max(len(v), 1), 6)
|
| 124 |
+
for b, v in per_band.items()},
|
| 125 |
+
{f"band{b}": round(sum(v) / max(len(v), 1), 6)
|
| 126 |
+
for b, v in blob_band.items()})
|
| 127 |
+
|
| 128 |
+
results = {"config": {"lambda": LAM, "steps": STEPS, "batch": BATCH,
|
| 129 |
+
"seed": SEED, "coupling":
|
| 130 |
+
"foreground-weighted LP-x0, HIGH band only"}}
|
| 131 |
+
|
| 132 |
+
# references gauged IN-BED (the exp009 instrument lesson)
|
| 133 |
+
with ledger_run(f"dexp012 reference gauges s{SEED}", budget_h=0.4) as h:
|
| 134 |
+
unet = load_unet(device)
|
| 135 |
+
v, pb, bb = val(unet, [])
|
| 136 |
+
results["frozen"] = {"val": v, "per_band": pb, "blob_gauge": bb}
|
| 137 |
+
del unet
|
| 138 |
+
torch.cuda.empty_cache()
|
| 139 |
+
for label, mk, fn in (("uniform_mb3", lambda d: MultibandDelta(d),
|
| 140 |
+
"multiband3_s0.pt"),
|
| 141 |
+
("monolith", lambda d: MonoDelta(d),
|
| 142 |
+
"monolith_s0.pt")):
|
| 143 |
+
unet = load_unet(device)
|
| 144 |
+
mods, wraps = attach(unet, mk)
|
| 145 |
+
ck = torch.load(os.path.join(D11_CKPT, fn), map_location="cpu",
|
| 146 |
+
weights_only=True)
|
| 147 |
+
for m, sd in zip(mods, ck["mods"]):
|
| 148 |
+
m.load_state_dict(sd, strict=True)
|
| 149 |
+
v, pb, bb = val(unet, wraps)
|
| 150 |
+
results[label] = {"val": v, "per_band": pb, "blob_gauge": bb}
|
| 151 |
+
del unet, mods
|
| 152 |
+
torch.cuda.empty_cache()
|
| 153 |
+
h["verdict"] = "refs gauged"
|
| 154 |
+
|
| 155 |
+
with ledger_run(f"dexp012 blob-mb3 s{SEED}", budget_h=2.5) as h:
|
| 156 |
+
unet = load_unet(device)
|
| 157 |
+
mods, wraps = attach(unet, lambda d: MultibandDelta(d))
|
| 158 |
+
for m in mods:
|
| 159 |
+
m.assert_zero_init()
|
| 160 |
+
opt = torch.optim.Adam(mods.parameters(), lr=LR, weight_decay=0.0)
|
| 161 |
+
gen = torch.Generator(device=device).manual_seed(SEED + 42)
|
| 162 |
+
idx = torch.Generator().manual_seed(SEED + 7)
|
| 163 |
+
t0 = time.time()
|
| 164 |
+
for step in range(1, STEPS + 1):
|
| 165 |
+
sel = torch.randint(0, N_TRAIN, (BATCH,), generator=idx)
|
| 166 |
+
loss = loss_of(unet, wraps, cache["lat"][sel].to(device),
|
| 167 |
+
cache["ehs"][sel].to(device),
|
| 168 |
+
cache["blob"][sel].float().to(device), gen)
|
| 169 |
+
loss.backward()
|
| 170 |
+
opt.step()
|
| 171 |
+
opt.zero_grad(set_to_none=True)
|
| 172 |
+
if step == 50 or step % 500 == 0:
|
| 173 |
+
print(f"[blob] step {step}: loss {loss.item():.4f} | "
|
| 174 |
+
f"{(time.time() - t0) / step:.2f}s/step", flush=True)
|
| 175 |
+
v, pb, bb = val(unet, wraps)
|
| 176 |
+
for m in mods:
|
| 177 |
+
m.enabled = False
|
| 178 |
+
v_off, _, _ = val(unet, wraps)
|
| 179 |
+
d = abs(v_off - results["frozen"]["val"])
|
| 180 |
+
assert d < 1e-9, f"toggle parity broken: {d}"
|
| 181 |
+
for m in mods:
|
| 182 |
+
m.enabled = True
|
| 183 |
+
torch.save({"mods": [m.state_dict() for m in mods]},
|
| 184 |
+
os.path.join(CKPT_DIR, f"blob_mb3_s{SEED}.pt"))
|
| 185 |
+
results["blob_mb3"] = {"val": v, "per_band": pb, "blob_gauge": bb,
|
| 186 |
+
"val_toggled_off": v_off}
|
| 187 |
+
del unet, mods
|
| 188 |
+
torch.cuda.empty_cache()
|
| 189 |
+
h["verdict"] = f"val {v:.5f} blobH {bb['band2']}"
|
| 190 |
+
|
| 191 |
+
bm, um = results["blob_mb3"], results["uniform_mb3"]
|
| 192 |
+
results["verdict"] = {
|
| 193 |
+
"P1_blob_gauge_high_band":
|
| 194 |
+
{"blob_mb3": bm["blob_gauge"]["band2"],
|
| 195 |
+
"uniform_mb3": um["blob_gauge"]["band2"],
|
| 196 |
+
"hit": bm["blob_gauge"]["band2"] < um["blob_gauge"]["band2"]},
|
| 197 |
+
"P2_common_undegraded":
|
| 198 |
+
abs(bm["val"] - um["val"]) / um["val"] < 0.005
|
| 199 |
+
or bm["val"] < um["val"],
|
| 200 |
+
"common_val": {"blob": bm["val"], "uniform": um["val"],
|
| 201 |
+
"mono": results["monolith"]["val"]},
|
| 202 |
+
"note": "P4 (image battery on the blob ckpt) runs via dexp010 env; "
|
| 203 |
+
"1-seed CANDIDATE",
|
| 204 |
+
}
|
| 205 |
+
with open(os.path.join(DATA_DIR, "results.json" if SEED == 0
|
| 206 |
+
else f"results_s{SEED}.json"), "w") as f:
|
| 207 |
+
json.dump(results, f, indent=2)
|
| 208 |
+
note(f"dexp012: {json.dumps(results['verdict']['P1_blob_gauge_high_band'])}")
|
| 209 |
+
print(json.dumps(results["verdict"], indent=2))
|
| 210 |
+
burn_down()
|
| 211 |
+
return results
|
| 212 |
+
|
| 213 |
+
|
| 214 |
+
def smoke():
|
| 215 |
+
acp = torch.linspace(0.9999, 0.05, 1000)
|
| 216 |
+
x = torch.randn(2, 4, 64, 64)
|
| 217 |
+
n = torch.randn_like(x)
|
| 218 |
+
t = torch.tensor([100, 900])
|
| 219 |
+
a = acp[t].sqrt()[:, None, None, None]
|
| 220 |
+
s = (1 - acp[t]).sqrt()[:, None, None, None]
|
| 221 |
+
noisy = a * x + s * n
|
| 222 |
+
x0h = x0_from_eps(noisy, n, t, acp)
|
| 223 |
+
assert (x0h - x).abs().max() < 1e-4, "x0 inversion wrong"
|
| 224 |
+
blob = torch.zeros(2, 64, 64)
|
| 225 |
+
blob[0, 10:30, 10:30] = 1
|
| 226 |
+
e = blob_lp_err(x0h, x, blob)
|
| 227 |
+
assert e.shape == (2,) and e[0] < 1e-6 and e[1] == 0, e
|
| 228 |
+
print("dexp012 smoke PASSED (x0 inversion exact + fg-weighted gauge)")
|
| 229 |
+
|
| 230 |
+
|
| 231 |
+
if __name__ == "__main__":
|
| 232 |
+
if "--run" in sys.argv:
|
| 233 |
+
run()
|
| 234 |
+
else:
|
| 235 |
+
smoke()
|
exp012_blob_supervised/r0b_probe.py
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""r0b_probe.py — ANIMA R0b: the fork-integration gate (runs INSIDE the pod
|
| 2 |
+
clone of diffusion-pipe @ feat/aleph-adapter). Certifies, without a dataset:
|
| 3 |
+
G1 anima weights load through CosmosPredict2Pipeline (dit_config printed);
|
| 4 |
+
G2 aleph relays attach post-materialization (site count, param count);
|
| 5 |
+
G3 DTYPE LAW: relay dtype == block dtype (bf16);
|
| 6 |
+
G4 param groups: aleph_relay bucket present, trunk freezable by lr=0;
|
| 7 |
+
G5 zero-init: all-off/enabled-at-init forward delta == 0 through one block.
|
| 8 |
+
Full exp004 training goes to the evening slot per the day-3 plan.
|
| 9 |
+
Run: cd /workspace/geolip2/diffusion-pipe && python3 ../pod2/r0b_probe.py
|
| 10 |
+
"""
|
| 11 |
+
from __future__ import annotations
|
| 12 |
+
|
| 13 |
+
import sys
|
| 14 |
+
|
| 15 |
+
import torch
|
| 16 |
+
|
| 17 |
+
sys.path.insert(0, ".")
|
| 18 |
+
import utils.common # bind the fork utils BEFORE ComfyUI (regular-pkg shadowing)
|
| 19 |
+
sys.path.append("submodules/ComfyUI")
|
| 20 |
+
|
| 21 |
+
CFG = {
|
| 22 |
+
"model": {
|
| 23 |
+
"type": "anima",
|
| 24 |
+
"transformer_path":
|
| 25 |
+
"/workspace/models/anima/split_files/diffusion_models/"
|
| 26 |
+
"anima-base-v1.0.safetensors",
|
| 27 |
+
"llm_path": "/workspace/models/anima/split_files/text_encoders/"
|
| 28 |
+
"qwen_3_06b_base.safetensors",
|
| 29 |
+
"vae_path": "/workspace/models/anima/split_files/vae/"
|
| 30 |
+
"qwen_image_vae.safetensors",
|
| 31 |
+
"dtype": torch.bfloat16,
|
| 32 |
+
"aleph_relay": True,
|
| 33 |
+
"aleph_relay_every": 1,
|
| 34 |
+
"aleph_relay_lr": 1e-3,
|
| 35 |
+
"self_attn_lr": 0, "cross_attn_lr": 0, "mlp_lr": 0, "mod_lr": 0,
|
| 36 |
+
"llm_adapter_lr": 0,
|
| 37 |
+
},
|
| 38 |
+
"optimizer": {"lr": 0},
|
| 39 |
+
"reentrant_activation_checkpointing": False,
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def main():
|
| 44 |
+
import os
|
| 45 |
+
for k, v in (("MASTER_ADDR", "127.0.0.1"), ("MASTER_PORT", "29571"),
|
| 46 |
+
("RANK", "0"), ("WORLD_SIZE", "1"), ("LOCAL_RANK", "0")):
|
| 47 |
+
os.environ.setdefault(k, v)
|
| 48 |
+
import deepspeed
|
| 49 |
+
deepspeed.init_distributed()
|
| 50 |
+
from models.cosmos_predict2 import CosmosPredict2Pipeline
|
| 51 |
+
pipe = CosmosPredict2Pipeline(CFG)
|
| 52 |
+
print("[G1] pipeline constructed (text encoder loaded, name="
|
| 53 |
+
f"{pipe.name})", flush=True)
|
| 54 |
+
pipe.load_diffusion_model()
|
| 55 |
+
tr = pipe.transformer
|
| 56 |
+
relays = [getattr(b, "aleph_relay", None) for b in tr.blocks]
|
| 57 |
+
n_sites = sum(r is not None for r in relays)
|
| 58 |
+
n_params = sum(p.numel() for r in relays if r is not None
|
| 59 |
+
for p in r.parameters())
|
| 60 |
+
print(f"[G2] {n_sites}/{len(tr.blocks)} blocks carry relays, "
|
| 61 |
+
f"{n_params:,} adapter params", flush=True)
|
| 62 |
+
assert n_sites == len(tr.blocks) > 0
|
| 63 |
+
|
| 64 |
+
r0 = next(r for r in relays if r is not None)
|
| 65 |
+
b0 = tr.blocks[0]
|
| 66 |
+
bdt = next(p for n, p in b0.named_parameters()
|
| 67 |
+
if "aleph_relay" not in n).dtype
|
| 68 |
+
rdt = next(r0.parameters()).dtype
|
| 69 |
+
print(f"[G3] block dtype {bdt} | relay dtype {rdt}", flush=True)
|
| 70 |
+
assert rdt == bdt == torch.bfloat16, "dtype law violated"
|
| 71 |
+
|
| 72 |
+
params = [p for p in tr.parameters()]
|
| 73 |
+
for p, (n, _) in zip(params, tr.named_parameters()):
|
| 74 |
+
pass
|
| 75 |
+
groups = pipe.get_param_groups(
|
| 76 |
+
[p for p in tr.parameters() if hasattr(p, "original_name")])
|
| 77 |
+
n_trainable = sum(p.numel() for g in groups for p in g["params"])
|
| 78 |
+
print(f"[G4] {len(groups)} param groups, trainable {n_trainable:,} "
|
| 79 |
+
f"(should == adapter count {n_params:,})", flush=True)
|
| 80 |
+
assert n_trainable == n_params, "freeze-by-lr-0 leaked trunk params"
|
| 81 |
+
|
| 82 |
+
r0.assert_zero_init()
|
| 83 |
+
x = torch.randn(1, 2, 4, 4, tr.model_channels, dtype=bdt)
|
| 84 |
+
with torch.no_grad():
|
| 85 |
+
out_on = r0(x)
|
| 86 |
+
r0.enabled = False
|
| 87 |
+
out_off = r0(x)
|
| 88 |
+
r0.enabled = True
|
| 89 |
+
assert torch.equal(out_on, x) and out_off is x, "zero-init/toggle broken"
|
| 90 |
+
print("[G5] zero-init + toggle exact on the DiT relay", flush=True)
|
| 91 |
+
print("R0B ALL GATES GREEN — fork integration certified; exp004 train "
|
| 92 |
+
"is evening-slot ready", flush=True)
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
if __name__ == "__main__":
|
| 96 |
+
main()
|
exp012_blob_supervised/results.json
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"config": {
|
| 3 |
+
"lambda": 0.5,
|
| 4 |
+
"steps": 3000,
|
| 5 |
+
"batch": 16,
|
| 6 |
+
"seed": 0,
|
| 7 |
+
"coupling": "foreground-weighted LP-x0, HIGH band only"
|
| 8 |
+
},
|
| 9 |
+
"frozen": {
|
| 10 |
+
"val": 0.14243539798007987,
|
| 11 |
+
"per_band": {
|
| 12 |
+
"band0": 0.293931,
|
| 13 |
+
"band1": 0.071764,
|
| 14 |
+
"band2": 0.010422
|
| 15 |
+
},
|
| 16 |
+
"blob_gauge": {
|
| 17 |
+
"band0": 0.002656,
|
| 18 |
+
"band1": 0.021497,
|
| 19 |
+
"band2": 0.15549
|
| 20 |
+
}
|
| 21 |
+
},
|
| 22 |
+
"uniform_mb3": {
|
| 23 |
+
"val": 0.1352152533709159,
|
| 24 |
+
"per_band": {
|
| 25 |
+
"band0": 0.280633,
|
| 26 |
+
"band1": 0.066728,
|
| 27 |
+
"band2": 0.009562
|
| 28 |
+
},
|
| 29 |
+
"blob_gauge": {
|
| 30 |
+
"band0": 0.001986,
|
| 31 |
+
"band1": 0.015805,
|
| 32 |
+
"band2": 0.111528
|
| 33 |
+
}
|
| 34 |
+
},
|
| 35 |
+
"monolith": {
|
| 36 |
+
"val": 0.1341835820844608,
|
| 37 |
+
"per_band": {
|
| 38 |
+
"band0": 0.278893,
|
| 39 |
+
"band1": 0.065772,
|
| 40 |
+
"band2": 0.009564
|
| 41 |
+
},
|
| 42 |
+
"blob_gauge": {
|
| 43 |
+
"band0": 0.001943,
|
| 44 |
+
"band1": 0.015434,
|
| 45 |
+
"band2": 0.123388
|
| 46 |
+
}
|
| 47 |
+
},
|
| 48 |
+
"blob_mb3": {
|
| 49 |
+
"val": 0.13531021448216052,
|
| 50 |
+
"per_band": {
|
| 51 |
+
"band0": 0.280604,
|
| 52 |
+
"band1": 0.066751,
|
| 53 |
+
"band2": 0.009977
|
| 54 |
+
},
|
| 55 |
+
"blob_gauge": {
|
| 56 |
+
"band0": 0.001991,
|
| 57 |
+
"band1": 0.015801,
|
| 58 |
+
"band2": 0.111495
|
| 59 |
+
},
|
| 60 |
+
"val_toggled_off": 0.14243539798007987
|
| 61 |
+
},
|
| 62 |
+
"verdict": {
|
| 63 |
+
"P1_blob_gauge_high_band": {
|
| 64 |
+
"blob_mb3": 0.111495,
|
| 65 |
+
"uniform_mb3": 0.111528,
|
| 66 |
+
"hit": true
|
| 67 |
+
},
|
| 68 |
+
"P2_common_undegraded": true,
|
| 69 |
+
"common_val": {
|
| 70 |
+
"blob": 0.13531021448216052,
|
| 71 |
+
"uniform": 0.1352152533709159,
|
| 72 |
+
"mono": 0.1341835820844608
|
| 73 |
+
},
|
| 74 |
+
"note": "P4 (image battery on the blob ckpt) runs via dexp010 env; 1-seed CANDIDATE"
|
| 75 |
+
}
|
| 76 |
+
}
|
exp012_blob_supervised/results_blob_mb3_s0.json
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"config": {
|
| 3 |
+
"steps": 30,
|
| 4 |
+
"guidance": 7.5,
|
| 5 |
+
"seed": 1234,
|
| 6 |
+
"ckpt": "blob_mb3_s0",
|
| 7 |
+
"sampler": "DDIM step-gated"
|
| 8 |
+
},
|
| 9 |
+
"all_on": {
|
| 10 |
+
"round_trip": {
|
| 11 |
+
"cond": 0.7236,
|
| 12 |
+
"shuffled": 0.5305,
|
| 13 |
+
"gap": 0.1931
|
| 14 |
+
},
|
| 15 |
+
"diversity": 0.24882
|
| 16 |
+
},
|
| 17 |
+
"lesion_band0": {
|
| 18 |
+
"round_trip": {
|
| 19 |
+
"cond": 0.7071,
|
| 20 |
+
"shuffled": 0.529,
|
| 21 |
+
"gap": 0.1781
|
| 22 |
+
},
|
| 23 |
+
"vs_all_on": {
|
| 24 |
+
"lp_change": 0.003908,
|
| 25 |
+
"hp_change": 0.003013,
|
| 26 |
+
"total_change": 0.011374
|
| 27 |
+
},
|
| 28 |
+
"diversity": 0.26582
|
| 29 |
+
},
|
| 30 |
+
"lesion_band1": {
|
| 31 |
+
"round_trip": {
|
| 32 |
+
"cond": 0.7046,
|
| 33 |
+
"shuffled": 0.5425,
|
| 34 |
+
"gap": 0.1621
|
| 35 |
+
},
|
| 36 |
+
"vs_all_on": {
|
| 37 |
+
"lp_change": 0.021867,
|
| 38 |
+
"hp_change": 0.004201,
|
| 39 |
+
"total_change": 0.03785
|
| 40 |
+
},
|
| 41 |
+
"diversity": 0.29886
|
| 42 |
+
},
|
| 43 |
+
"lesion_band2": {
|
| 44 |
+
"round_trip": {
|
| 45 |
+
"cond": 0.7024,
|
| 46 |
+
"shuffled": 0.5551,
|
| 47 |
+
"gap": 0.1474
|
| 48 |
+
},
|
| 49 |
+
"vs_all_on": {
|
| 50 |
+
"lp_change": 0.066186,
|
| 51 |
+
"hp_change": 0.00481,
|
| 52 |
+
"total_change": 0.086765
|
| 53 |
+
},
|
| 54 |
+
"diversity": 0.29093
|
| 55 |
+
},
|
| 56 |
+
"frozen": {
|
| 57 |
+
"round_trip": {
|
| 58 |
+
"cond": 0.6692,
|
| 59 |
+
"shuffled": 0.5446,
|
| 60 |
+
"gap": 0.1247
|
| 61 |
+
},
|
| 62 |
+
"vs_all_on": {
|
| 63 |
+
"lp_change": 0.074492,
|
| 64 |
+
"hp_change": 0.005201,
|
| 65 |
+
"total_change": 0.09682
|
| 66 |
+
},
|
| 67 |
+
"diversity": 0.33191
|
| 68 |
+
},
|
| 69 |
+
"prereg": {
|
| 70 |
+
"G2_high_band_moves_LP_most": true,
|
| 71 |
+
"G2_low_band_moves_HP_most": false,
|
| 72 |
+
"G3_high_lesion_cuts_diversity": false,
|
| 73 |
+
"note": "image-space coarse-to-fine test; 1-seed battery"
|
| 74 |
+
}
|
| 75 |
+
}
|