exp002 shipped: guidepost-with-a-pulse (address inert beside text, live alone +0.0287; redesign = complementarity)
Browse files- README.md +1 -1
- exp002_sd15_addrcond/README.md +45 -0
- exp002_sd15_addrcond/addrcond_s0.pt +3 -0
- exp002_sd15_addrcond/dexp002_sd15_addrcond.py +345 -0
- exp002_sd15_addrcond/results.json +38 -0
README.md
CHANGED
|
@@ -71,7 +71,7 @@ resolution) so gaps live in a narrow band — the paired design is load-bearing.
|
|
| 71 |
| exp000_baselines | zero-shot baseline wall (above) | **shipped** |
|
| 72 |
| exp000b_natural | natural-paradigm wall: format specialization is a double dissociation; SDXL core tops the NL wall | **shipped (candidate, s0)** |
|
| 73 |
| exp001_sd15_relay | relay-all16 vs matched LoRA-r32 vs frozen: **relay beats both; LoRA lands below frozen; post-train toggle bit-exact** | **shipped (candidate, s0)** |
|
| 74 |
-
| exp002_sd15_addrcond |
|
| 75 |
| exp003_sigma_registers | sign-code separations: what is a diffusion "register"? (+prompt77 register) | running |
|
| 76 |
| exp004_anima_relay | relays on the 2B DiT via diffusion-pipe (bf16 per dtype law) | staged |
|
| 77 |
| exp005_sdxl_tree4a | the SDXL capacity battery (guidepost/scaffold/skeleton) | designed |
|
|
|
|
| 71 |
| exp000_baselines | zero-shot baseline wall (above) | **shipped** |
|
| 72 |
| exp000b_natural | natural-paradigm wall: format specialization is a double dissociation; SDXL core tops the NL wall | **shipped (candidate, s0)** |
|
| 73 |
| exp001_sd15_relay | relay-all16 vs matched LoRA-r32 vs frozen: **relay beats both; LoRA lands below frozen; post-train toggle bit-exact** | **shipped (candidate, s0)** |
|
| 74 |
+
| exp002_sd15_addrcond | addr-cond 4-arm causal: **GUIDEPOST with a pulse** — inert beside full text (real≈deranged), but the address ALONE steers (+0.029); redesign = complementarity | **shipped (candidate, s0)** |
|
| 75 |
| exp003_sigma_registers | sign-code separations: what is a diffusion "register"? (+prompt77 register) | running |
|
| 76 |
| exp004_anima_relay | relays on the 2B DiT via diffusion-pipe (bf16 per dtype law) | staged |
|
| 77 |
| exp005_sdxl_tree4a | the SDXL capacity battery (guidepost/scaffold/skeleton) | designed |
|
exp002_sd15_addrcond/README.md
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# exp002_sd15_addrcond — the frozen aleph address in the cond stream (CANDIDATE, s0)
|
| 2 |
+
|
| 3 |
+
**Question.** Does the canonical byte-trigram aleph address (caption →
|
| 4 |
+
byte-trigram render → frozen `geolip-aleph-void`, `aleph_byte_trigram_tied_
|
| 5 |
+
hard_K64`, logits mean-pooled → [32,128] — the exact sdxl-qwen-phase0 recipe)
|
| 6 |
+
carry usable scene information into the SD15-Lune predictive path?
|
| 7 |
+
|
| 8 |
+
**Design.** AlephCondAdapter(768): 32 extra cond positions appended after the
|
| 9 |
+
227-token json encoding; everything zero-init (exact-zero tokens at init);
|
| 10 |
+
toggle = LENGTH (the masked-append path measured non-bit-exact in the substrate
|
| 11 |
+
gates, 9.03e-04 — fallback adopted, never silent). Trained 2000 steps (adapter
|
| 12 |
+
only: proj + pos table + gate; pure Adam wd=0; CFG dropout zeroes text+addr
|
| 13 |
+
TOGETHER per the sdxl-aleph precedent). Judged post-train on exp000's exact 24
|
| 14 |
+
rows, paired seeds, 4 address arms at fixed real-text cond, plus an
|
| 15 |
+
address-only pair at zeroed text.
|
| 16 |
+
|
| 17 |
+
**Results** (`results.json`):
|
| 18 |
+
|
| 19 |
+
| gauge | value | reading |
|
| 20 |
+
|---|---|---|
|
| 21 |
+
| presence offset (zero-tokens vs no-append, at init) | −0.0001 val-MSE | appended exact-zeros are free |
|
| 22 |
+
| real − deranged (text present) | **−0.0009** | address adds nothing beyond the text |
|
| 23 |
+
| real − no_append (text present) | −0.0068 | appending ≈ neutral-to-slightly-worse |
|
| 24 |
+
| noise − deranged | −0.0086 | specificity control behaves |
|
| 25 |
+
| **addr-only: real − noise (text ZEROED)** | **+0.0287** | the address ALONE steers the UNet |
|
| 26 |
+
| gate trajectory | 0.047 → 0.0597 (grew) | trunk opted in |
|
| 27 |
+
| val flow-MSE (trained, appended) | 0.5211 vs 0.5224 no-append | mild improvement |
|
| 28 |
+
|
| 29 |
+
**Verdict (preregistered): GUIDEPOST — with a pulse.** The prereg honest-
|
| 30 |
+
negative fires: in the presence of full json text, the appended address is
|
| 31 |
+
marginally inert (real ≈ deranged), so scaling this configuration is not
|
| 32 |
+
justified. But the address-only channel is live (+0.0287 over a noise-address
|
| 33 |
+
floor after just 2k adapter steps), the gate grew, and val improved — the
|
| 34 |
+
address is *redundant in context*, not dead. Redesign target =
|
| 35 |
+
**complementarity**: inject the address where the text is not (reduced-text
|
| 36 |
+
regimes, σ-gated injection per exp003's sigma-register finding, or a stream
|
| 37 |
+
the text encoding doesn't reach) rather than alongside a text encoding of the
|
| 38 |
+
same caption.
|
| 39 |
+
|
| 40 |
+
**Consistency note.** This is the adapter-scale echo of the SDXL-aleph
|
| 41 |
+
Phase-1 reading (projection weight statistically > 0, formation unproven) —
|
| 42 |
+
now with a causal 4-arm control behind it.
|
| 43 |
+
|
| 44 |
+
**Caveats.** Single seed; n=24 judged rows; 2k steps; one injection site
|
| 45 |
+
(cond append). Cost ≈ 1.0 GPU-h. Checkpoint: `addrcond_s0.pt`.
|
exp002_sd15_addrcond/addrcond_s0.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:6fc1122c486369dd088127ae412af71fe984dd1f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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""dexp002_sd15_addrcond.py — exp002: the frozen aleph address into the SD15
|
| 2 |
+
cond stream (Tier A), 4-arm causal control.
|
| 3 |
+
|
| 4 |
+
Address = THE CANONICAL RECIPE (repos/geolip-sd-trainer.md, verified in
|
| 5 |
+
geolip_sd_trainer/data/aleph.py): caption -> byte-trigram render -> frozen
|
| 6 |
+
AbstractPhil/geolip-aleph-void (aleph_byte_trigram_tied_hard_K64) ->
|
| 7 |
+
aleph_logits mean over patches -> [32,128] in [-1,1]. Same recipe as
|
| 8 |
+
sdxl-qwen-phase0's aleph_address column — comparable by construction.
|
| 9 |
+
|
| 10 |
+
Adapter: AlephCondAdapter(768) — 32 extra cond positions appended after
|
| 11 |
+
encode_clip_225's 227; everything zero-init => exact-zero tokens at init.
|
| 12 |
+
TOGGLE = LENGTH (G5 verdict: encoder_attention_mask not bit-exact, 9.03e-04);
|
| 13 |
+
the PRESENCE OFFSET (append-exact-zeros vs no-append) is MEASURED at init on
|
| 14 |
+
paired val-MSE and ledgered — never silent.
|
| 15 |
+
|
| 16 |
+
Training: adapter params only (addr_proj + pos_table + gate), pure Adam wd=0,
|
| 17 |
+
trainer-verbatim flow objective; CFG dropout zeroes TEXT AND ADDR TOGETHER
|
| 18 |
+
(the sdxl-aleph precedent, so CFG stays clean at judge time).
|
| 19 |
+
|
| 20 |
+
Judged arms (post-train, text cond FIXED real, paired seeds, n=24 exp000 rows):
|
| 21 |
+
addr_real / addr_deranged / addr_noise / no_append -> round-trip CLIP-L.
|
| 22 |
+
Plus the addr-only pair: text ZEROED, {addr_real vs addr_noise} — what the
|
| 23 |
+
address alone carries.
|
| 24 |
+
Prereg (charter): real-vs-deranged gap > 0; real vs no_append positive;
|
| 25 |
+
noise ~ deranged (specificity). Honest negative: real ~ no_append =>
|
| 26 |
+
guidepost verdict — redesign before scale (Law 2 pressure point: the text
|
| 27 |
+
cond already parameterizes the scene; the address must add marginal signal).
|
| 28 |
+
|
| 29 |
+
Pod: bash pod2/run_exp002.sh (installs geolip-svae if missing)
|
| 30 |
+
"""
|
| 31 |
+
from __future__ import annotations
|
| 32 |
+
|
| 33 |
+
import io
|
| 34 |
+
import json
|
| 35 |
+
import os
|
| 36 |
+
import sys
|
| 37 |
+
import time
|
| 38 |
+
|
| 39 |
+
sys.path[:0] = ["pod2", "."]
|
| 40 |
+
|
| 41 |
+
import torch
|
| 42 |
+
import torch.nn.functional as F
|
| 43 |
+
|
| 44 |
+
from pod_ledger import ledger_run, note, burn_down
|
| 45 |
+
from aleph_diffusion_core import AlephCondAdapter, derangement
|
| 46 |
+
from d1_lune_sampler import encode_clip_225, flow_sample, decode
|
| 47 |
+
from d1_substrate import MEM_FRACTION
|
| 48 |
+
|
| 49 |
+
DATASET = "AbstractPhil/synthetic-object-relations-json"
|
| 50 |
+
SD_BASE = "stable-diffusion-v1-5/stable-diffusion-v1-5"
|
| 51 |
+
SD_REPO = "AbstractPhil/sd15-flow-lune-json-prompt"
|
| 52 |
+
SD_SUB = "checkpoint-00002500/unet"
|
| 53 |
+
VAE_SCALE, SHIFT, SEED = 0.18215, 2.5, 0
|
| 54 |
+
N_TRAIN, N_VAL, N_JUDGE = 4096, 256, 24
|
| 55 |
+
BATCH, LR, CFG_DROPOUT = 16, 1e-3, 0.1
|
| 56 |
+
STEPS = int(os.environ.get("DEXP2_STEPS", "2000"))
|
| 57 |
+
DATA_DIR = ("/workspace/data/dexp002" if os.path.isdir("/workspace")
|
| 58 |
+
else os.path.join(os.environ.get("GEOLIP_DATA", "./data"),
|
| 59 |
+
"dexp002"))
|
| 60 |
+
DEXP1_DIR = ("/workspace/data/dexp001" if os.path.isdir("/workspace")
|
| 61 |
+
else os.path.join(os.environ.get("GEOLIP_DATA", "./data"),
|
| 62 |
+
"dexp001"))
|
| 63 |
+
CKPT_DIR = ("/workspace/ckpts2/dexp002" if os.path.isdir("/workspace")
|
| 64 |
+
else DATA_DIR)
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
# ── the canonical address encoder (copy semantics; repo not edited) ─────────
|
| 68 |
+
|
| 69 |
+
class Addr:
|
| 70 |
+
def __init__(self, device="cuda"):
|
| 71 |
+
from geolip_svae import load_model
|
| 72 |
+
self.model, self.mcfg = load_model(
|
| 73 |
+
hf_version="aleph_byte_trigram_tied_hard_K64",
|
| 74 |
+
repo_id="AbstractPhil/geolip-aleph-void", device=device)
|
| 75 |
+
self.model.eval()
|
| 76 |
+
self.model.requires_grad_(False)
|
| 77 |
+
self.device = device
|
| 78 |
+
self._pdtype = next(self.model.parameters()).dtype
|
| 79 |
+
g = self.mcfg if isinstance(self.mcfg, dict) else {}
|
| 80 |
+
self.patch_size = int(getattr(self.model, "patch_size",
|
| 81 |
+
g.get("patch_size", 2)))
|
| 82 |
+
self.channels = int(getattr(self.model, "channels",
|
| 83 |
+
g.get("channels", 3)))
|
| 84 |
+
self.img_size = int(g.get("img_size", 64))
|
| 85 |
+
|
| 86 |
+
@torch.no_grad()
|
| 87 |
+
def encode(self, captions, bs=64):
|
| 88 |
+
from geolip_svae.inference.text import text_to_image
|
| 89 |
+
outs = []
|
| 90 |
+
for i in range(0, len(captions), bs):
|
| 91 |
+
imgs = torch.stack([
|
| 92 |
+
text_to_image(c, self.img_size, self.patch_size, "space",
|
| 93 |
+
self.channels)
|
| 94 |
+
for c in captions[i:i + bs]]).to(self.device, self._pdtype)
|
| 95 |
+
svd = self.model(imgs)["svd"]
|
| 96 |
+
outs.append(svd["aleph_logits"].mean(dim=1).float().cpu())
|
| 97 |
+
return torch.cat(outs) # (B, 32, 128) in [-1,1]
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
def _iter_prompts(need):
|
| 101 |
+
from huggingface_hub import HfApi, hf_hub_download
|
| 102 |
+
import pyarrow.parquet as pq
|
| 103 |
+
api = HfApi()
|
| 104 |
+
files = sorted(f for f in api.list_repo_files(DATASET, repo_type="dataset")
|
| 105 |
+
if f.endswith(".parquet"))
|
| 106 |
+
got = 0
|
| 107 |
+
for fname in files:
|
| 108 |
+
path = hf_hub_download(DATASET, fname, repo_type="dataset")
|
| 109 |
+
for r in pq.read_table(path, columns=["json_prompt"]).to_pylist():
|
| 110 |
+
jp = r["json_prompt"]
|
| 111 |
+
yield jp if isinstance(jp, str) else json.dumps(jp)
|
| 112 |
+
got += 1
|
| 113 |
+
if got >= need:
|
| 114 |
+
return
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
def build_addr_cache(device):
|
| 118 |
+
f = os.path.join(DATA_DIR, "addr.pt")
|
| 119 |
+
if os.path.exists(f):
|
| 120 |
+
print(f"[addr] exists: {f}")
|
| 121 |
+
return f
|
| 122 |
+
os.makedirs(DATA_DIR, exist_ok=True)
|
| 123 |
+
enc = Addr(device)
|
| 124 |
+
prompts = list(_iter_prompts(N_TRAIN + N_VAL))
|
| 125 |
+
addr = enc.encode(prompts)
|
| 126 |
+
assert addr.shape == (N_TRAIN + N_VAL, 32, 128), addr.shape
|
| 127 |
+
torch.save({"addr": addr[:N_TRAIN], "val_addr": addr[N_TRAIN:]}, f)
|
| 128 |
+
print(f"[addr] built {f}: {addr.shape}, range "
|
| 129 |
+
f"[{addr.min():.3f},{addr.max():.3f}]", flush=True)
|
| 130 |
+
del enc
|
| 131 |
+
torch.cuda.empty_cache()
|
| 132 |
+
return f
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
# ── objective (trainer-verbatim; text+addr dropped TOGETHER) ────────────────
|
| 136 |
+
|
| 137 |
+
def flow_loss(unet, adapter, lat, ehs, addr, gen, device):
|
| 138 |
+
bsz = lat.shape[0]
|
| 139 |
+
tokens = adapter.tokens(addr) # (B, 32, 768), grads
|
| 140 |
+
cond = torch.cat([ehs, tokens], dim=1) # (B, 259, 768)
|
| 141 |
+
drop = torch.rand(bsz, generator=gen, device=device) < CFG_DROPOUT
|
| 142 |
+
cond = cond * (~drop)[:, None, None] # text+addr together
|
| 143 |
+
s = torch.rand(bsz, generator=gen, device=device)
|
| 144 |
+
s = (SHIFT * s) / (1 + (SHIFT - 1) * s)
|
| 145 |
+
s4 = s[:, None, None, None]
|
| 146 |
+
noise = torch.randn(lat.shape, generator=gen, device=device)
|
| 147 |
+
pred = unet(noise * s4 + lat * (1 - s4), s * 1000, cond,
|
| 148 |
+
return_dict=False)[0]
|
| 149 |
+
return F.mse_loss(pred, noise - lat)
|
| 150 |
+
|
| 151 |
+
|
| 152 |
+
@torch.no_grad()
|
| 153 |
+
def val_mse(unet, cache, cond_fn, device):
|
| 154 |
+
tot = []
|
| 155 |
+
for i in range(0, N_VAL, 32):
|
| 156 |
+
lat = cache["val_lat"][i:i + 32].to(device)
|
| 157 |
+
noise = cache["val_noise"][i:i + 32].to(device)
|
| 158 |
+
s = cache["val_sigma"][i:i + 32].to(device)
|
| 159 |
+
s4 = s[:, None, None, None]
|
| 160 |
+
cond = cond_fn(i)
|
| 161 |
+
pred = unet(noise * s4 + lat * (1 - s4), s * 1000, cond,
|
| 162 |
+
return_dict=False)[0]
|
| 163 |
+
tot += ((pred - (noise - lat)) ** 2).mean(dim=(1, 2, 3)).tolist()
|
| 164 |
+
return sum(tot) / len(tot)
|
| 165 |
+
|
| 166 |
+
|
| 167 |
+
def run(device="cuda"):
|
| 168 |
+
torch.cuda.set_per_process_memory_fraction(MEM_FRACTION, 0)
|
| 169 |
+
os.makedirs(CKPT_DIR, exist_ok=True)
|
| 170 |
+
import numpy as np
|
| 171 |
+
from PIL import Image
|
| 172 |
+
from diffusers import UNet2DConditionModel, AutoencoderKL
|
| 173 |
+
from transformers import (CLIPTextModel, CLIPTokenizer, CLIPModel,
|
| 174 |
+
CLIPProcessor)
|
| 175 |
+
|
| 176 |
+
with ledger_run("dexp002 addr cache", budget_h=0.5):
|
| 177 |
+
build_addr_cache(device)
|
| 178 |
+
assert os.path.exists(os.path.join(DEXP1_DIR, "cache.pt")), \
|
| 179 |
+
"dexp001 latent cache required (shared rows) — run dexp001 first"
|
| 180 |
+
cache = torch.load(os.path.join(DEXP1_DIR, "cache.pt"),
|
| 181 |
+
map_location="cpu", weights_only=True)
|
| 182 |
+
ac = torch.load(os.path.join(DATA_DIR, "addr.pt"), map_location="cpu",
|
| 183 |
+
weights_only=True)
|
| 184 |
+
|
| 185 |
+
unet = UNet2DConditionModel.from_pretrained(
|
| 186 |
+
SD_REPO, subfolder=SD_SUB, torch_dtype=torch.float32).to(device)
|
| 187 |
+
unet.requires_grad_(False)
|
| 188 |
+
unet.eval()
|
| 189 |
+
unet.enable_gradient_checkpointing()
|
| 190 |
+
adapter = AlephCondAdapter(768).to(device).float()
|
| 191 |
+
adapter.assert_zero_init()
|
| 192 |
+
|
| 193 |
+
# presence-offset gauge at init (G5 fallback, MEASURED never silent)
|
| 194 |
+
def cond_plain(i):
|
| 195 |
+
return cache["val_ehs"][i:i + 32].to(device)
|
| 196 |
+
|
| 197 |
+
def cond_append(i):
|
| 198 |
+
e = cache["val_ehs"][i:i + 32].to(device)
|
| 199 |
+
a = ac["val_addr"][i:i + 32].to(device)
|
| 200 |
+
return torch.cat([e, adapter.tokens(a)], dim=1)
|
| 201 |
+
|
| 202 |
+
results = {"config": {"steps": STEPS, "batch": BATCH, "lr": LR,
|
| 203 |
+
"seed": SEED, "recipe":
|
| 204 |
+
"aleph_byte_trigram_tied_hard_K64 logits mean"}}
|
| 205 |
+
with ledger_run("dexp002 presence offset", budget_h=0.2) as h:
|
| 206 |
+
v_plain = val_mse(unet, cache, cond_plain, device)
|
| 207 |
+
v_zeros = val_mse(unet, cache, cond_append, device)
|
| 208 |
+
results["presence_offset"] = {
|
| 209 |
+
"val_no_append": round(v_plain, 6),
|
| 210 |
+
"val_append_zero_tokens": round(v_zeros, 6),
|
| 211 |
+
"delta": round(v_zeros - v_plain, 6)}
|
| 212 |
+
h["verdict"] = f"offset {v_zeros - v_plain:+.6f}"
|
| 213 |
+
|
| 214 |
+
# train the adapter
|
| 215 |
+
with ledger_run("dexp002 addr-cond train s0", budget_h=1.5) as h:
|
| 216 |
+
gen = torch.Generator(device=device).manual_seed(SEED + 42)
|
| 217 |
+
idx_gen = torch.Generator().manual_seed(SEED + 7)
|
| 218 |
+
params = list(adapter.parameters())
|
| 219 |
+
opt = torch.optim.Adam(params, lr=LR, weight_decay=0.0)
|
| 220 |
+
adapter.train()
|
| 221 |
+
torch.cuda.reset_peak_memory_stats()
|
| 222 |
+
t0 = time.time()
|
| 223 |
+
for step in range(1, STEPS + 1):
|
| 224 |
+
sel = torch.randint(0, N_TRAIN, (BATCH,), generator=idx_gen)
|
| 225 |
+
loss = flow_loss(unet, adapter, cache["lat"][sel].to(device),
|
| 226 |
+
cache["ehs"][sel].to(device),
|
| 227 |
+
ac["addr"][sel].to(device), gen, device)
|
| 228 |
+
loss.backward()
|
| 229 |
+
opt.step()
|
| 230 |
+
opt.zero_grad(set_to_none=True)
|
| 231 |
+
if step == 50 or step % 500 == 0:
|
| 232 |
+
print(f"[addrcond] step {step}: loss {loss.item():.4f} | "
|
| 233 |
+
f"{(time.time() - t0) / step:.2f}s/step | gate "
|
| 234 |
+
f"{torch.sigmoid(adapter.gate).item():.4f} | peak "
|
| 235 |
+
f"{torch.cuda.max_memory_allocated() / 2**30:.1f}GB",
|
| 236 |
+
flush=True)
|
| 237 |
+
adapter.eval()
|
| 238 |
+
torch.save(adapter.state_dict(),
|
| 239 |
+
os.path.join(CKPT_DIR, "addrcond_s0.pt"))
|
| 240 |
+
results["train"] = {
|
| 241 |
+
"s_per_step": round((time.time() - t0) / STEPS, 3),
|
| 242 |
+
"gate_final": round(torch.sigmoid(adapter.gate).item(), 5),
|
| 243 |
+
"pos_table_norm": round(adapter.pos_table.norm().item(), 4),
|
| 244 |
+
"proj_w_norm": round(adapter.addr_proj.weight.norm().item(), 4)}
|
| 245 |
+
results["val_trained_append"] = round(
|
| 246 |
+
val_mse(unet, cache, cond_append, device), 6)
|
| 247 |
+
h["verdict"] = f"gate {results['train']['gate_final']}"
|
| 248 |
+
|
| 249 |
+
# judged arms (round-trip on the exp000 rows)
|
| 250 |
+
with ledger_run("dexp002 judged arms", budget_h=0.8) as h:
|
| 251 |
+
from d1_exp000_baselines import load_rows, judge_selftest
|
| 252 |
+
rows = load_rows(N_JUDGE)
|
| 253 |
+
tok = CLIPTokenizer.from_pretrained(SD_BASE, subfolder="tokenizer")
|
| 254 |
+
te = CLIPTextModel.from_pretrained(
|
| 255 |
+
SD_BASE, subfolder="text_encoder",
|
| 256 |
+
torch_dtype=torch.float32).to(device).eval()
|
| 257 |
+
vae = AutoencoderKL.from_pretrained(
|
| 258 |
+
SD_BASE, subfolder="vae",
|
| 259 |
+
torch_dtype=torch.float32).to(device).eval()
|
| 260 |
+
clip = CLIPModel.from_pretrained(
|
| 261 |
+
"openai/clip-vit-large-patch14",
|
| 262 |
+
torch_dtype=torch.float32).to(device).eval()
|
| 263 |
+
cproc = CLIPProcessor.from_pretrained(
|
| 264 |
+
"openai/clip-vit-large-patch14")
|
| 265 |
+
feat = judge_selftest(clip, cproc, device)
|
| 266 |
+
prompts = [r["json_prompt"] for r in rows]
|
| 267 |
+
with torch.no_grad():
|
| 268 |
+
ehs = encode_clip_225(prompts, tok, te, device)
|
| 269 |
+
enc = Addr(device)
|
| 270 |
+
addr_real = enc.encode(prompts).to(device)
|
| 271 |
+
del enc
|
| 272 |
+
torch.cuda.empty_cache()
|
| 273 |
+
perm = derangement(N_JUDGE, seed=1234)
|
| 274 |
+
gn = torch.Generator().manual_seed(SEED + 5)
|
| 275 |
+
addr_arms = {
|
| 276 |
+
"addr_real": addr_real,
|
| 277 |
+
"addr_deranged": addr_real[perm.to(addr_real.device)],
|
| 278 |
+
"addr_noise": (torch.rand(addr_real.shape, generator=gn) * 2
|
| 279 |
+
- 1).to(device),
|
| 280 |
+
"no_append": None,
|
| 281 |
+
}
|
| 282 |
+
orig = torch.cat([
|
| 283 |
+
feat(Image.open(io.BytesIO(r["image_bytes"])).convert("RGB"))
|
| 284 |
+
for r in rows])
|
| 285 |
+
|
| 286 |
+
@torch.no_grad()
|
| 287 |
+
def judge(text_cond, addr):
|
| 288 |
+
if addr is None:
|
| 289 |
+
cond = text_cond
|
| 290 |
+
else:
|
| 291 |
+
cond = torch.cat([text_cond, adapter.tokens(addr)], dim=1)
|
| 292 |
+
cos = []
|
| 293 |
+
for i in range(0, N_JUDGE, 6):
|
| 294 |
+
latg = flow_sample(unet, cond[i:i + 6], n_steps=30,
|
| 295 |
+
guidance=6.0, seed=1234 + i, device=device)
|
| 296 |
+
imgs = decode(vae, latg)
|
| 297 |
+
pil = [Image.fromarray((im * 255).astype(np.uint8))
|
| 298 |
+
for im in imgs]
|
| 299 |
+
fs = torch.cat([feat(p) for p in pil])
|
| 300 |
+
cos += (fs * orig[i:i + 6]).sum(-1).tolist()
|
| 301 |
+
return round(sum(cos) / len(cos), 4)
|
| 302 |
+
|
| 303 |
+
arms = {k: judge(ehs, a) for k, a in addr_arms.items()}
|
| 304 |
+
zero_text = torch.zeros_like(ehs)
|
| 305 |
+
addr_only = {"real": judge(zero_text, addr_real),
|
| 306 |
+
"noise": judge(zero_text, addr_arms["addr_noise"])}
|
| 307 |
+
results["arms"] = arms
|
| 308 |
+
results["addr_only_text_zeroed"] = addr_only
|
| 309 |
+
results["verdict"] = {
|
| 310 |
+
"real_minus_deranged": round(arms["addr_real"]
|
| 311 |
+
- arms["addr_deranged"], 4),
|
| 312 |
+
"real_minus_no_append": round(arms["addr_real"]
|
| 313 |
+
- arms["no_append"], 4),
|
| 314 |
+
"noise_vs_deranged": round(arms["addr_noise"]
|
| 315 |
+
- arms["addr_deranged"], 4),
|
| 316 |
+
"addr_only_real_minus_noise": round(addr_only["real"]
|
| 317 |
+
- addr_only["noise"], 4),
|
| 318 |
+
"note": "prereg: real>deranged, real>no_append, noise~deranged; "
|
| 319 |
+
"real~no_append => guidepost. 1-seed CANDIDATE.",
|
| 320 |
+
}
|
| 321 |
+
h["verdict"] = json.dumps(results["verdict"])
|
| 322 |
+
|
| 323 |
+
with open(os.path.join(DATA_DIR, "results.json"), "w") as f:
|
| 324 |
+
json.dump(results, f, indent=2)
|
| 325 |
+
note(f"dexp002: {json.dumps(results['verdict'])}")
|
| 326 |
+
print(json.dumps(results, indent=2))
|
| 327 |
+
burn_down()
|
| 328 |
+
return results
|
| 329 |
+
|
| 330 |
+
|
| 331 |
+
def smoke():
|
| 332 |
+
a = AlephCondAdapter(768)
|
| 333 |
+
a.assert_zero_init()
|
| 334 |
+
x = torch.randn(2, 32, 128)
|
| 335 |
+
assert a.tokens(x).abs().max().item() == 0.0
|
| 336 |
+
p = derangement(N_JUDGE, seed=1234)
|
| 337 |
+
assert not (p == torch.arange(N_JUDGE)).any()
|
| 338 |
+
print("dexp002 smoke PASSED (parse + adapter zeros; GPU run is pod work)")
|
| 339 |
+
|
| 340 |
+
|
| 341 |
+
if __name__ == "__main__":
|
| 342 |
+
if "--run" in sys.argv:
|
| 343 |
+
run()
|
| 344 |
+
else:
|
| 345 |
+
smoke()
|
exp002_sd15_addrcond/results.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"config": {
|
| 3 |
+
"steps": 2000,
|
| 4 |
+
"batch": 16,
|
| 5 |
+
"lr": 0.001,
|
| 6 |
+
"seed": 0,
|
| 7 |
+
"recipe": "aleph_byte_trigram_tied_hard_K64 logits mean"
|
| 8 |
+
},
|
| 9 |
+
"presence_offset": {
|
| 10 |
+
"val_no_append": 0.52241,
|
| 11 |
+
"val_append_zero_tokens": 0.52229,
|
| 12 |
+
"delta": -0.000121
|
| 13 |
+
},
|
| 14 |
+
"train": {
|
| 15 |
+
"s_per_step": 1.661,
|
| 16 |
+
"gate_final": 0.05971,
|
| 17 |
+
"pos_table_norm": 33.2072,
|
| 18 |
+
"proj_w_norm": 32.5641
|
| 19 |
+
},
|
| 20 |
+
"val_trained_append": 0.521105,
|
| 21 |
+
"arms": {
|
| 22 |
+
"addr_real": 0.747,
|
| 23 |
+
"addr_deranged": 0.7479,
|
| 24 |
+
"addr_noise": 0.7393,
|
| 25 |
+
"no_append": 0.7538
|
| 26 |
+
},
|
| 27 |
+
"addr_only_text_zeroed": {
|
| 28 |
+
"real": 0.5706,
|
| 29 |
+
"noise": 0.5419
|
| 30 |
+
},
|
| 31 |
+
"verdict": {
|
| 32 |
+
"real_minus_deranged": -0.0009,
|
| 33 |
+
"real_minus_no_append": -0.0068,
|
| 34 |
+
"noise_vs_deranged": -0.0086,
|
| 35 |
+
"addr_only_real_minus_noise": 0.0287,
|
| 36 |
+
"note": "prereg: real>deranged, real>no_append, noise~deranged; real~no_append => guidepost. 1-seed CANDIDATE."
|
| 37 |
+
}
|
| 38 |
+
}
|