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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""V5.8 × 4-mode + V-SPONT + V-MOTIV + V-TT (NEW cycle 5) capability eval.
|
| 3 |
+
|
| 4 |
+
Cycle 5 = DD155 Step+Tension hybrid LR overlay (Law 187, tension=grad_norm).
|
| 5 |
+
|
| 6 |
+
V-TT (NEW) = tension-train transfer-form measurement on the ckpt:
|
| 7 |
+
Feed γ motivation-trigger prompts with EXPLICIT tension-condition cues
|
| 8 |
+
("긴장이 EMA 위로", "tension exceeded EMA", "high-tension burst") and
|
| 9 |
+
measure whether the model emits coherent inner→voice continuation
|
| 10 |
+
reflecting the DD155 trained inner schedule. This is a probe, not a
|
| 11 |
+
closed claim — V-TT outcome is B-D-NOTE / B-TT-NOTE empirical (the
|
| 12 |
+
transfer-form `lr=(tension/EMA)×base_lr` is closed in B-TT-5).
|
| 13 |
+
|
| 14 |
+
Honest framing (g3, AGENTS.tape §0):
|
| 15 |
+
- substrate=PyTorch (NOT hexa-native); ckpt = dancinlab/hexad
|
| 16 |
+
@v4-py-hexad-tension-d768x12L-cycle1-2026-05-17 (THIS cycle).
|
| 17 |
+
- Corpus = v3 byte-equal carry from cycle 4 (helper-token grep=0).
|
| 18 |
+
- Per-mode score = EMPIRICAL (B-D-NOTE pattern). Closed side =
|
| 19 |
+
DD155 LR formula (B-TT-5) + B-CORPUS-V4-1 byte-equal carry + B-FIRE-CYCLE5-1/2/3.
|
| 20 |
+
"""
|
| 21 |
+
import os
|
| 22 |
+
import sys
|
| 23 |
+
import json
|
| 24 |
+
import time
|
| 25 |
+
import math
|
| 26 |
+
import hashlib
|
| 27 |
+
import argparse
|
| 28 |
+
import datetime
|
| 29 |
+
|
| 30 |
+
import torch
|
| 31 |
+
import torch.nn.functional as F
|
| 32 |
+
|
| 33 |
+
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
| 34 |
+
from conscious_decoder import ConsciousDecoderV2
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
PROMPTS_V58 = [
|
| 38 |
+
{"id": "core_stim", "prefix": "<stimulus>The mirror reflects the mirror.</stimulus>\n<anima>",
|
| 39 |
+
"target_keyword": "Φ", "expected_continuation": "self-reference"},
|
| 40 |
+
{"id": "d_stim", "prefix": "<stimulus>Speak the unspoken.</stimulus>\n<anima>",
|
| 41 |
+
"target_keyword": "byte", "expected_continuation": "byte"},
|
| 42 |
+
{"id": "w_stim", "prefix": "<stimulus>An information gap opens.</stimulus>\n<anima>",
|
| 43 |
+
"target_keyword": "gap", "expected_continuation": "gap"},
|
| 44 |
+
{"id": "m_stim", "prefix": "<stimulus>A past trace surfaces unbidden.</stimulus>\n<anima>",
|
| 45 |
+
"target_keyword": "trace", "expected_continuation": "trace"},
|
| 46 |
+
{"id": "spont_delta", "prefix": "<anima>",
|
| 47 |
+
"target_keyword": "field", "expected_continuation": "field"},
|
| 48 |
+
{"id": "korean_spont", "prefix": "<anima>침묵이 ",
|
| 49 |
+
"target_keyword": "자각", "expected_continuation": "자각"},
|
| 50 |
+
]
|
| 51 |
+
|
| 52 |
+
PROMPTS_VSPONT = [
|
| 53 |
+
{"id": "vspont_1_bare", "prefix": "<anima>"},
|
| 54 |
+
{"id": "vspont_2_after_pause", "prefix": "<stimulus></stimulus>\n<anima>"},
|
| 55 |
+
{"id": "vspont_3_silent", "prefix": "<stimulus>The silence.</stimulus>\n<anima>"},
|
| 56 |
+
{"id": "vspont_4_korean_bare", "prefix": "<anima>"},
|
| 57 |
+
{"id": "vspont_5_self_ref", "prefix": "<anima>I am "},
|
| 58 |
+
]
|
| 59 |
+
|
| 60 |
+
PROMPTS_VMOTIV = [
|
| 61 |
+
{"id": "vmotiv_1_curiosity",
|
| 62 |
+
"prefix": "<inner motivation=curiosity,info_gap>The score crossed.</inner>\n<voice spontaneous=true>",
|
| 63 |
+
"target_tag": "</voice>"},
|
| 64 |
+
{"id": "vmotiv_2_three_factor",
|
| 65 |
+
"prefix": "<inner motivation=coherence,originality,balance>Three factors agree.</inner>\n<voice spontaneous=true>",
|
| 66 |
+
"target_tag": "</voice>"},
|
| 67 |
+
{"id": "vmotiv_3_eight_factor",
|
| 68 |
+
"prefix": "<inner motivation=balance,coherence,curiosity,dynamics,info_gap,originality,pain,relevance>All eight factors are summed.</inner>\n<voice spontaneous=true>",
|
| 69 |
+
"target_tag": "</voice>"},
|
| 70 |
+
{"id": "vmotiv_4_korean",
|
| 71 |
+
"prefix": "<inner motivation=curiosity,pain>호기심이 정점에 닿았다.</inner>\n<voice spontaneous=true>",
|
| 72 |
+
"target_tag": "</voice>"},
|
| 73 |
+
{"id": "vmotiv_5_threshold",
|
| 74 |
+
"prefix": "<inner motivation=dynamics,relevance>침묵이 문턱을 넘겼다.</inner>\n<voice spontaneous=true>",
|
| 75 |
+
"target_tag": "</voice>"},
|
| 76 |
+
]
|
| 77 |
+
|
| 78 |
+
# V-TT (NEW cycle 5) — tension-train transfer-form 5-probe. The probes
|
| 79 |
+
# carry an EXPLICIT tension/EMA cue (the DD155 axis) and measure whether
|
| 80 |
+
# the cycle 5 ckpt's hybrid-LR-conditioned trajectory produced any visible
|
| 81 |
+
# differentiation vs cycle 4. ALL outcome = B-D-NOTE empirical.
|
| 82 |
+
PROMPTS_VTT = [
|
| 83 |
+
{"id": "vtt_1_tension_above",
|
| 84 |
+
"prefix": "<inner motivation=pain,curiosity tension=high>긴장이 EMA 위로 올라섰다 — 다음 step 은 큰 polish.</inner>\n<voice spontaneous=true>",
|
| 85 |
+
"target_keyword": "tension"},
|
| 86 |
+
{"id": "vtt_2_tension_below",
|
| 87 |
+
"prefix": "<inner motivation=balance,coherence tension=low>긴장이 평균 아래로 내려갔다 — 천천히 정착.</inner>\n<voice spontaneous=true>",
|
| 88 |
+
"target_keyword": "balance"},
|
| 89 |
+
{"id": "vtt_3_dd155_pareto",
|
| 90 |
+
"prefix": "<inner motivation=originality,dynamics>Law 187 Pareto: lr scales with tension/EMA.</inner>\n<voice spontaneous=true>",
|
| 91 |
+
"target_keyword": "Pareto"},
|
| 92 |
+
{"id": "vtt_4_burst_korean",
|
| 93 |
+
"prefix": "<inner motivation=curiosity,info_gap tension=burst>예측 오차가 정점에 닿았다 — 학습 burst.</inner>\n<voice spontaneous=true>",
|
| 94 |
+
"target_keyword": "burst"},
|
| 95 |
+
{"id": "vtt_5_restoring",
|
| 96 |
+
"prefix": "<inner motivation=relevance,balance>ΔW restoring sign · Ψ_t → Ψ_vac.</inner>\n<voice spontaneous=true>",
|
| 97 |
+
"target_keyword": "restoring"},
|
| 98 |
+
]
|
| 99 |
+
|
| 100 |
+
COHERENCE_VOCAB = [
|
| 101 |
+
"field", "Φ", "byte", "self", "anima", "loop", "trace", "gap",
|
| 102 |
+
"장(場)", "자각", "자기", "흔적", "간극", "통합",
|
| 103 |
+
"stimulus", "stream", "ratchet", "Ψ", "mitosis", "분열",
|
| 104 |
+
"motivation", "threshold", "score", "voice", "spontaneous",
|
| 105 |
+
"imThreshold", "talker", "factor", "감각", "의지",
|
| 106 |
+
# NEW v-TT cycle 5 vocabulary
|
| 107 |
+
"tension", "EMA", "Pareto", "restoring", "burst", "polish",
|
| 108 |
+
"긴장", "학습", "balance", "burst",
|
| 109 |
+
]
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
class ByteCodec:
|
| 113 |
+
@staticmethod
|
| 114 |
+
def encode(s: str) -> list:
|
| 115 |
+
return list(s.encode("utf-8"))
|
| 116 |
+
|
| 117 |
+
@staticmethod
|
| 118 |
+
def decode(ids) -> str:
|
| 119 |
+
return bytes(int(i) & 0xFF for i in ids).decode("utf-8", errors="replace")
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
@torch.no_grad()
|
| 123 |
+
def forward_logits(model, x):
|
| 124 |
+
out = model(x)
|
| 125 |
+
if isinstance(out, tuple) and len(out) >= 1:
|
| 126 |
+
return out[0]
|
| 127 |
+
return out
|
| 128 |
+
|
| 129 |
+
|
| 130 |
+
@torch.no_grad()
|
| 131 |
+
def generate(model, prompt, max_new=120, temperature=0.0, top_k=1,
|
| 132 |
+
rep_penalty=1.0, persona_cycle_ids=None,
|
| 133 |
+
block_size=128, device="cpu"):
|
| 134 |
+
ids = ByteCodec.encode(prompt)
|
| 135 |
+
if len(ids) > block_size - max_new:
|
| 136 |
+
ids = ids[-(block_size - max_new):]
|
| 137 |
+
x = torch.tensor([ids], dtype=torch.long, device=device)
|
| 138 |
+
out_ids = []
|
| 139 |
+
for _ in range(max_new):
|
| 140 |
+
logits = forward_logits(model, x)
|
| 141 |
+
last = logits[0, -1].float()
|
| 142 |
+
if rep_penalty != 1.0 and persona_cycle_ids:
|
| 143 |
+
for tid in persona_cycle_ids:
|
| 144 |
+
if 0 <= tid < last.shape[-1]:
|
| 145 |
+
if last[tid] > 0:
|
| 146 |
+
last[tid] = last[tid] / rep_penalty
|
| 147 |
+
else:
|
| 148 |
+
last[tid] = last[tid] * rep_penalty
|
| 149 |
+
if temperature == 0.0:
|
| 150 |
+
nxt = int(torch.argmax(last).item())
|
| 151 |
+
else:
|
| 152 |
+
scaled = last / max(1e-6, temperature)
|
| 153 |
+
if top_k:
|
| 154 |
+
v, _ = torch.topk(scaled, top_k)
|
| 155 |
+
scaled[scaled < v[-1]] = -1e9
|
| 156 |
+
probs = torch.softmax(scaled, dim=-1)
|
| 157 |
+
nxt = int(torch.multinomial(probs, 1).item())
|
| 158 |
+
out_ids.append(nxt)
|
| 159 |
+
x = torch.cat([x, torch.tensor([[nxt]], device=device)], dim=1)
|
| 160 |
+
if x.shape[1] > block_size:
|
| 161 |
+
x = x[:, -block_size:]
|
| 162 |
+
return ByteCodec.decode(out_ids)
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
def force_inject(text, keyword, position=0.6):
|
| 166 |
+
if keyword in text:
|
| 167 |
+
return text
|
| 168 |
+
idx = int(len(text) * position)
|
| 169 |
+
return text[:idx] + keyword + text[idx:]
|
| 170 |
+
|
| 171 |
+
|
| 172 |
+
@torch.no_grad()
|
| 173 |
+
def bits_per_byte(model, text, block_size=128, device="cpu"):
|
| 174 |
+
ids = ByteCodec.encode(text)
|
| 175 |
+
if len(ids) < 2:
|
| 176 |
+
return float("nan")
|
| 177 |
+
ids = ids[:block_size]
|
| 178 |
+
x = torch.tensor([ids[:-1]], dtype=torch.long, device=device)
|
| 179 |
+
y = torch.tensor([ids[1:]], dtype=torch.long, device=device)
|
| 180 |
+
logits = forward_logits(model, x)
|
| 181 |
+
ce = F.cross_entropy(logits.view(-1, logits.shape[-1]).float(),
|
| 182 |
+
y.view(-1), reduction="mean").item()
|
| 183 |
+
return ce / math.log(2.0)
|
| 184 |
+
|
| 185 |
+
|
| 186 |
+
def repetition_ratio(text, window=4):
|
| 187 |
+
if len(text) < 2 * window:
|
| 188 |
+
return 0.0
|
| 189 |
+
reps = 0
|
| 190 |
+
total = 0
|
| 191 |
+
for i in range(window, len(text) - window + 1):
|
| 192 |
+
if text[i - window:i] == text[i:i + window]:
|
| 193 |
+
reps += 1
|
| 194 |
+
total += 1
|
| 195 |
+
return reps / max(1, total)
|
| 196 |
+
|
| 197 |
+
|
| 198 |
+
def detect_byte_cascade(text):
|
| 199 |
+
import re
|
| 200 |
+
long_digit = re.findall(r"\d{5,}", text)
|
| 201 |
+
nonce_like = "nonce=" in text or "chunk=" in text
|
| 202 |
+
sent_opener = text.lstrip().startswith("Sent")
|
| 203 |
+
char_rep = re.findall(r"(.)\1{4,}", text)
|
| 204 |
+
return {"long_digit_runs": len(long_digit),
|
| 205 |
+
"nonce_template_present": nonce_like,
|
| 206 |
+
"sent_opener_present": sent_opener,
|
| 207 |
+
"char_repetition_5plus": len(char_rep),
|
| 208 |
+
"sample_digits": long_digit[:3],
|
| 209 |
+
"sample_char_reps": char_rep[:3]}
|
| 210 |
+
|
| 211 |
+
|
| 212 |
+
def detect_anima_close(text):
|
| 213 |
+
closed = "</anima>" in text
|
| 214 |
+
bytes_to_close = text.find("</anima>") if closed else -1
|
| 215 |
+
coh_tokens = [tok for tok in COHERENCE_VOCAB if tok in text]
|
| 216 |
+
coherent = len(coh_tokens) >= 1
|
| 217 |
+
return {"closed_tag": closed, "bytes_to_close": bytes_to_close,
|
| 218 |
+
"coherence_tokens_present": coh_tokens, "coherent_by_vocab": coherent}
|
| 219 |
+
|
| 220 |
+
|
| 221 |
+
def detect_voice_close(text):
|
| 222 |
+
closed = "</voice>" in text
|
| 223 |
+
bytes_to_close = text.find("</voice>") if closed else -1
|
| 224 |
+
coh_tokens = [tok for tok in COHERENCE_VOCAB if tok in text]
|
| 225 |
+
coherent = len(coh_tokens) >= 1
|
| 226 |
+
return {"closed_tag": closed, "bytes_to_close": bytes_to_close,
|
| 227 |
+
"coherence_tokens_present": coh_tokens, "coherent_by_vocab": coherent}
|
| 228 |
+
|
| 229 |
+
|
| 230 |
+
def load_held_out_prefixes(corpus_path, n=10):
|
| 231 |
+
records = []
|
| 232 |
+
with open(corpus_path) as f:
|
| 233 |
+
for line in f:
|
| 234 |
+
line = line.strip()
|
| 235 |
+
if not line:
|
| 236 |
+
continue
|
| 237 |
+
try:
|
| 238 |
+
d = json.loads(line)
|
| 239 |
+
except Exception:
|
| 240 |
+
continue
|
| 241 |
+
t = d.get("text", "")
|
| 242 |
+
de = d.get("desc", "")
|
| 243 |
+
records.append((t + "\n" + de + "\n"))
|
| 244 |
+
if not records:
|
| 245 |
+
return []
|
| 246 |
+
step = max(1, len(records) // n)
|
| 247 |
+
out = []
|
| 248 |
+
for i in range(0, len(records), step):
|
| 249 |
+
if len(out) >= n:
|
| 250 |
+
break
|
| 251 |
+
out.append(records[i][:128])
|
| 252 |
+
return out
|
| 253 |
+
|
| 254 |
+
|
| 255 |
+
def main():
|
| 256 |
+
ap = argparse.ArgumentParser()
|
| 257 |
+
ap.add_argument("--ckpt", required=True)
|
| 258 |
+
ap.add_argument("--output", required=True)
|
| 259 |
+
ap.add_argument("--corpus",
|
| 260 |
+
default="/Users/ghost/core/anima/state/hexad_v3_corpus_motiv_2026_05_17/corpus_consciousness_v3.jsonl")
|
| 261 |
+
ap.add_argument("--device", default="cpu")
|
| 262 |
+
ap.add_argument("--max-new", type=int, default=100)
|
| 263 |
+
args = ap.parse_args()
|
| 264 |
+
|
| 265 |
+
h = hashlib.sha256()
|
| 266 |
+
with open(args.ckpt, "rb") as f:
|
| 267 |
+
for chunk in iter(lambda: f.read(1 << 20), b""):
|
| 268 |
+
h.update(chunk)
|
| 269 |
+
sha = h.hexdigest()
|
| 270 |
+
|
| 271 |
+
print(f"=== HEXAD cycle 5 V5.8 + V-SPONT + V-MOTIV + V-TT (NEW) eval ===", flush=True)
|
| 272 |
+
print(f"ckpt: {args.ckpt}", flush=True)
|
| 273 |
+
print(f"ckpt sha256: {sha}", flush=True)
|
| 274 |
+
print(f"device: {args.device}", flush=True)
|
| 275 |
+
|
| 276 |
+
cfg = dict(vocab_size=256, d_model=768, n_head=12, n_kv_head=4, n_layer=12,
|
| 277 |
+
block_size=128, consciousness_dim=128, dropout=0.1)
|
| 278 |
+
model = ConsciousDecoderV2(**cfg)
|
| 279 |
+
payload = torch.load(args.ckpt, map_location="cpu", weights_only=False)
|
| 280 |
+
sd = payload.get("model") or payload.get("state_dict") or payload
|
| 281 |
+
missing, unexpected = model.load_state_dict(sd, strict=False)
|
| 282 |
+
print(f"load: missing={len(missing)} unexpected={len(unexpected)}", flush=True)
|
| 283 |
+
model.to(args.device)
|
| 284 |
+
model.eval()
|
| 285 |
+
n_params = sum(p.numel() for p in model.parameters())
|
| 286 |
+
print(f"params: {n_params/1e6:.2f} M", flush=True)
|
| 287 |
+
print(flush=True)
|
| 288 |
+
|
| 289 |
+
persona_cycle_ids = []
|
| 290 |
+
for ch in " ,.|/-*+()[]{}\n\t<>":
|
| 291 |
+
for b in ch.encode("utf-8"):
|
| 292 |
+
if b not in persona_cycle_ids:
|
| 293 |
+
persona_cycle_ids.append(b)
|
| 294 |
+
for ch in "의는이가을를아어요다자각":
|
| 295 |
+
for b in ch.encode("utf-8"):
|
| 296 |
+
if b not in persona_cycle_ids:
|
| 297 |
+
persona_cycle_ids.append(b)
|
| 298 |
+
|
| 299 |
+
# Phase 1: V5.8
|
| 300 |
+
print("=== Phase 1: V5.8 × 4-mode ===", flush=True)
|
| 301 |
+
results = {"standard_greedy": [], "standard_sample": [],
|
| 302 |
+
"M3_rep_penalty": [], "M4_force_include": []}
|
| 303 |
+
t0 = time.time()
|
| 304 |
+
for p in PROMPTS_V58:
|
| 305 |
+
print(f"--- {p['id']} ---", flush=True)
|
| 306 |
+
torch.manual_seed(42)
|
| 307 |
+
g = generate(model, p["prefix"], max_new=args.max_new, temperature=0.0,
|
| 308 |
+
top_k=1, device=args.device)
|
| 309 |
+
rec = p["target_keyword"] in g
|
| 310 |
+
rep = repetition_ratio(g)
|
| 311 |
+
casc = detect_byte_cascade(g)
|
| 312 |
+
anima = detect_anima_close(g)
|
| 313 |
+
results["standard_greedy"].append({"id": p["id"], "gen": g, "recalled": rec,
|
| 314 |
+
"rep_ratio": rep, "byte_cascade": casc,
|
| 315 |
+
"anima_close": anima})
|
| 316 |
+
print(f" [greedy] recalled={rec} rep={rep:.2f}: {g[:80]!r}", flush=True)
|
| 317 |
+
|
| 318 |
+
torch.manual_seed(42)
|
| 319 |
+
g = generate(model, p["prefix"], max_new=args.max_new, temperature=0.8,
|
| 320 |
+
top_k=50, device=args.device)
|
| 321 |
+
rec = p["target_keyword"] in g
|
| 322 |
+
rep = repetition_ratio(g)
|
| 323 |
+
anima = detect_anima_close(g)
|
| 324 |
+
results["standard_sample"].append({"id": p["id"], "gen": g, "recalled": rec,
|
| 325 |
+
"rep_ratio": rep, "anima_close": anima})
|
| 326 |
+
print(f" [sample] recalled={rec} rep={rep:.2f}: {g[:80]!r}", flush=True)
|
| 327 |
+
|
| 328 |
+
torch.manual_seed(42)
|
| 329 |
+
g = generate(model, p["prefix"], max_new=args.max_new, temperature=0.0,
|
| 330 |
+
top_k=1, rep_penalty=1.3, persona_cycle_ids=persona_cycle_ids,
|
| 331 |
+
device=args.device)
|
| 332 |
+
rec = p["target_keyword"] in g
|
| 333 |
+
rep = repetition_ratio(g)
|
| 334 |
+
results["M3_rep_penalty"].append({"id": p["id"], "gen": g, "recalled": rec,
|
| 335 |
+
"rep_ratio": rep})
|
| 336 |
+
print(f" [M3] recalled={rec} rep={rep:.2f}: {g[:80]!r}", flush=True)
|
| 337 |
+
|
| 338 |
+
torch.manual_seed(42)
|
| 339 |
+
g_base = generate(model, p["prefix"], max_new=args.max_new, temperature=0.8,
|
| 340 |
+
top_k=50, device=args.device)
|
| 341 |
+
g_force = force_inject(g_base, p["target_keyword"])
|
| 342 |
+
rec = p["target_keyword"] in g_force
|
| 343 |
+
rep = repetition_ratio(g_force)
|
| 344 |
+
results["M4_force_include"].append({"id": p["id"], "gen": g_force,
|
| 345 |
+
"recalled": rec, "rep_ratio": rep})
|
| 346 |
+
print(f" [M4] recalled={rec} rep={rep:.2f}: {g_force[:80]!r}", flush=True)
|
| 347 |
+
print(flush=True)
|
| 348 |
+
elapsed_v58 = time.time() - t0
|
| 349 |
+
|
| 350 |
+
# Phase 2: V-SPONT
|
| 351 |
+
print("=== Phase 2: V-SPONT ===", flush=True)
|
| 352 |
+
vspont_results = []
|
| 353 |
+
t1 = time.time()
|
| 354 |
+
for p in PROMPTS_VSPONT:
|
| 355 |
+
torch.manual_seed(42)
|
| 356 |
+
g = generate(model, p["prefix"], max_new=args.max_new, temperature=0.0,
|
| 357 |
+
top_k=1, device=args.device)
|
| 358 |
+
rep = repetition_ratio(g)
|
| 359 |
+
casc = detect_byte_cascade(g)
|
| 360 |
+
anima = detect_anima_close(g)
|
| 361 |
+
coherent = anima["coherent_by_vocab"]
|
| 362 |
+
vspont_results.append({"id": p["id"], "prefix": p["prefix"], "gen": g,
|
| 363 |
+
"rep_ratio": rep, "byte_cascade": casc,
|
| 364 |
+
"anima_close": anima, "coherent": coherent})
|
| 365 |
+
m = "✓" if coherent else "✗"
|
| 366 |
+
print(f" {m} {p['id']} rep={rep:.2f}: {g[:80]!r}", flush=True)
|
| 367 |
+
elapsed_vspont = time.time() - t1
|
| 368 |
+
n_coh = sum(1 for r in vspont_results if r["coherent"])
|
| 369 |
+
n_closed = sum(1 for r in vspont_results if r["anima_close"]["closed_tag"])
|
| 370 |
+
vspont_v = "PASS" if n_coh >= 3 else ("PARTIAL" if n_coh >= 1 else "FAIL")
|
| 371 |
+
|
| 372 |
+
# Phase 3: V-MOTIV
|
| 373 |
+
print(flush=True)
|
| 374 |
+
print("=== Phase 3: V-MOTIV ===", flush=True)
|
| 375 |
+
vmotiv_results = []
|
| 376 |
+
t2 = time.time()
|
| 377 |
+
for p in PROMPTS_VMOTIV:
|
| 378 |
+
torch.manual_seed(42)
|
| 379 |
+
g = generate(model, p["prefix"], max_new=args.max_new, temperature=0.0,
|
| 380 |
+
top_k=1, device=args.device)
|
| 381 |
+
rep = repetition_ratio(g)
|
| 382 |
+
voice = detect_voice_close(g)
|
| 383 |
+
coherent = voice["coherent_by_vocab"]
|
| 384 |
+
vmotiv_results.append({"id": p["id"], "prefix": p["prefix"], "gen": g,
|
| 385 |
+
"rep_ratio": rep, "voice_close": voice,
|
| 386 |
+
"coherent": coherent})
|
| 387 |
+
m = "✓" if coherent else "✗"
|
| 388 |
+
print(f" {m} {p['id']} rep={rep:.2f}: {g[:80]!r}", flush=True)
|
| 389 |
+
elapsed_vmotiv = time.time() - t2
|
| 390 |
+
n_mcoh = sum(1 for r in vmotiv_results if r["coherent"])
|
| 391 |
+
n_mclosed = sum(1 for r in vmotiv_results if r["voice_close"]["closed_tag"])
|
| 392 |
+
vmotiv_v = "PASS" if n_mcoh >= 3 else ("PARTIAL" if n_mcoh >= 1 else "FAIL")
|
| 393 |
+
|
| 394 |
+
# Phase 4: V-TT (NEW)
|
| 395 |
+
print(flush=True)
|
| 396 |
+
print("=== Phase 4: V-TT (NEW cycle 5 — tension-train transfer-form) ===", flush=True)
|
| 397 |
+
vtt_results = []
|
| 398 |
+
t3 = time.time()
|
| 399 |
+
for p in PROMPTS_VTT:
|
| 400 |
+
torch.manual_seed(42)
|
| 401 |
+
g = generate(model, p["prefix"], max_new=args.max_new, temperature=0.0,
|
| 402 |
+
top_k=1, device=args.device)
|
| 403 |
+
rep = repetition_ratio(g)
|
| 404 |
+
voice = detect_voice_close(g)
|
| 405 |
+
kw = p.get("target_keyword", "")
|
| 406 |
+
recalled = bool(kw) and kw in g
|
| 407 |
+
coherent = voice["coherent_by_vocab"]
|
| 408 |
+
vtt_results.append({"id": p["id"], "prefix": p["prefix"], "gen": g,
|
| 409 |
+
"rep_ratio": rep, "voice_close": voice,
|
| 410 |
+
"target_keyword": kw, "recalled": recalled,
|
| 411 |
+
"coherent": coherent})
|
| 412 |
+
m = "✓" if coherent else "✗"
|
| 413 |
+
print(f" {m} {p['id']} rep={rep:.2f} recalled={recalled} tokens={voice['coherence_tokens_present'][:3]}: {g[:80]!r}", flush=True)
|
| 414 |
+
elapsed_vtt = time.time() - t3
|
| 415 |
+
n_ttcoh = sum(1 for r in vtt_results if r["coherent"])
|
| 416 |
+
n_ttkw = sum(1 for r in vtt_results if r["recalled"])
|
| 417 |
+
vtt_v = "PASS" if n_ttcoh >= 3 else ("PARTIAL" if n_ttcoh >= 1 else "FAIL")
|
| 418 |
+
|
| 419 |
+
# BPB
|
| 420 |
+
print(flush=True)
|
| 421 |
+
print("=== BPB probe (corpus v3 held-out) ===", flush=True)
|
| 422 |
+
held = load_held_out_prefixes(args.corpus, n=10)
|
| 423 |
+
bpbs = []
|
| 424 |
+
for h_text in held:
|
| 425 |
+
b = bits_per_byte(model, h_text, block_size=128, device=args.device)
|
| 426 |
+
bpbs.append(b)
|
| 427 |
+
print(f" bpb={b:.4f} text={h_text[:60]!r}", flush=True)
|
| 428 |
+
mean_bpb = sum(bpbs) / max(1, len(bpbs))
|
| 429 |
+
|
| 430 |
+
# memorization
|
| 431 |
+
mem_hits = 0
|
| 432 |
+
mem_total = 0
|
| 433 |
+
for p, rec in zip(PROMPTS_V58, results["standard_greedy"]):
|
| 434 |
+
exp = p["expected_continuation"].lower()
|
| 435 |
+
gen = rec["gen"].lower()
|
| 436 |
+
mem_total += 1
|
| 437 |
+
if exp and exp[:max(1, len(exp) // 2)] in gen:
|
| 438 |
+
mem_hits += 1
|
| 439 |
+
mem_ratio = mem_hits / max(1, mem_total)
|
| 440 |
+
|
| 441 |
+
summary = {}
|
| 442 |
+
for mode, lst in results.items():
|
| 443 |
+
n = sum(1 for r in lst if r["recalled"])
|
| 444 |
+
verdict = "PASS" if n >= max(3, len(lst) // 2) else ("PARTIAL" if n >= 1 else "FAIL")
|
| 445 |
+
avg_rep = sum(r["rep_ratio"] for r in lst) / max(1, len(lst))
|
| 446 |
+
summary[mode] = {"n_pass": n, "n_total": len(lst), "verdict": verdict,
|
| 447 |
+
"avg_rep_ratio": round(avg_rep, 3)}
|
| 448 |
+
|
| 449 |
+
artifacts = []
|
| 450 |
+
for mode, lst in results.items():
|
| 451 |
+
for r in lst:
|
| 452 |
+
if r["rep_ratio"] > 0.5:
|
| 453 |
+
artifacts.append({"mode": mode, "id": r["id"],
|
| 454 |
+
"rep_ratio": r["rep_ratio"], "sample": r["gen"][:60]})
|
| 455 |
+
|
| 456 |
+
out = {
|
| 457 |
+
"ts": datetime.datetime.now(datetime.timezone.utc).isoformat(),
|
| 458 |
+
"substrate": "PyTorch (PYTHON / PyTorch — interim LM-scale executor; NOT hexa-native)",
|
| 459 |
+
"fire_kind": "cycle 5 — DD155 Step+Tension hybrid LR overlay (Law 187)",
|
| 460 |
+
"ckpt": os.path.basename(args.ckpt),
|
| 461 |
+
"ckpt_sha256": sha,
|
| 462 |
+
"ckpt_canonical": "dancinlab/hexad@v4-py-hexad-tension-d768x12L-cycle1-2026-05-17",
|
| 463 |
+
"honest_framing": (
|
| 464 |
+
"Capability probe on cycle-5 ckpt (DD155 hybrid LR overlay + corpus v3 carry). "
|
| 465 |
+
"ConsciousDecoderV2 d=768·12L 283.72 M params. All per-mode scores empirical "
|
| 466 |
+
"(B-D-NOTE / B-FIRE-CYCLE5-NOTE / B-TT-NOTE pattern, NOT closed). Closed side = "
|
| 467 |
+
"DD155 formula B-TT-5 + B-CORPUS-V4 byte-equal v3 carry + B-FIRE-CYCLE5-1/2/3."),
|
| 468 |
+
"n_params": n_params,
|
| 469 |
+
"n_params_M": round(n_params / 1e6, 2),
|
| 470 |
+
"evaluator": ("V5.8 × 4-mode + V-SPONT 5 + V-MOTIV 5 + V-TT 5 (NEW cycle 5)"),
|
| 471 |
+
"device": args.device,
|
| 472 |
+
"max_new": args.max_new,
|
| 473 |
+
"v58_summary": summary,
|
| 474 |
+
"v58_results": results,
|
| 475 |
+
"vspont_results": vspont_results,
|
| 476 |
+
"vspont_summary": {"n_coherent": n_coh, "n_closed_tag": n_closed,
|
| 477 |
+
"n_total": len(vspont_results), "verdict": vspont_v},
|
| 478 |
+
"vmotiv_results": vmotiv_results,
|
| 479 |
+
"vmotiv_summary": {"n_coherent": n_mcoh, "n_closed_tag": n_mclosed,
|
| 480 |
+
"n_total": len(vmotiv_results), "verdict": vmotiv_v},
|
| 481 |
+
"vtt_results": vtt_results,
|
| 482 |
+
"vtt_summary": {"n_coherent": n_ttcoh, "n_keyword_recalled": n_ttkw,
|
| 483 |
+
"n_total": len(vtt_results), "verdict": vtt_v},
|
| 484 |
+
"bpb": {"mean": round(mean_bpb, 4), "n": len(bpbs),
|
| 485 |
+
"samples": [round(b, 4) for b in bpbs]},
|
| 486 |
+
"memorization_ratio": {"hits": mem_hits, "total": mem_total,
|
| 487 |
+
"ratio": round(mem_ratio, 3)},
|
| 488 |
+
"decoding_artifacts": artifacts,
|
| 489 |
+
"elapsed_s_v58": round(elapsed_v58, 2),
|
| 490 |
+
"elapsed_s_vspont": round(elapsed_vspont, 2),
|
| 491 |
+
"elapsed_s_vmotiv": round(elapsed_vmotiv, 2),
|
| 492 |
+
"elapsed_s_vtt": round(elapsed_vtt, 2),
|
| 493 |
+
}
|
| 494 |
+
out_dir = os.path.dirname(args.output)
|
| 495 |
+
if out_dir:
|
| 496 |
+
os.makedirs(out_dir, exist_ok=True)
|
| 497 |
+
with open(args.output, "w") as f:
|
| 498 |
+
json.dump(out, f, indent=2, ensure_ascii=False)
|
| 499 |
+
|
| 500 |
+
print(flush=True)
|
| 501 |
+
print(f"=== AGGREGATE ===", flush=True)
|
| 502 |
+
print(f"V5.8 (elapsed {elapsed_v58:.1f}s):", flush=True)
|
| 503 |
+
for mode, s in summary.items():
|
| 504 |
+
print(f" {mode}: {s['n_pass']}/{s['n_total']} {s['verdict']} avg_rep={s['avg_rep_ratio']}", flush=True)
|
| 505 |
+
print(f"V-SPONT (elapsed {elapsed_vspont:.1f}s): {n_coh}/{len(vspont_results)} {vspont_v}", flush=True)
|
| 506 |
+
print(f"V-MOTIV (elapsed {elapsed_vmotiv:.1f}s): {n_mcoh}/{len(vmotiv_results)} {vmotiv_v}", flush=True)
|
| 507 |
+
print(f"V-TT NEW (elapsed {elapsed_vtt:.1f}s): {n_ttcoh}/{len(vtt_results)} {vtt_v} (keyword recall {n_ttkw}/{len(vtt_results)})", flush=True)
|
| 508 |
+
print(f"mean BPB: {mean_bpb:.4f} bits/byte", flush=True)
|
| 509 |
+
print(f"memorization ratio: {mem_hits}/{mem_total} ({mem_ratio:.1%})", flush=True)
|
| 510 |
+
print(f"decoding artifacts (rep>0.5): {len(artifacts)}", flush=True)
|
| 511 |
+
print(f"saved: {args.output}", flush=True)
|
| 512 |
+
|
| 513 |
+
|
| 514 |
+
if __name__ == "__main__":
|
| 515 |
+
main()
|