NOEON / scripts /analyze_compat.py
Frankenstein-Labs's picture
NOEON: official identity (Frankenstein-Labs) + premium model card; proprietary-weights structure
67aa1dc verified
Raw History Blame Contribute Delete
4.08 kB
#!/usr/bin/env python3
"""Verify NOEON's integration assumptions against the REAL source tensors.
Checks, from weights/source_tensors.json (real safetensors headers):
1. vision vs computer_use: are the key sets / shapes identical after
stripping the differing top-level prefixes?
2. What is each source's real hidden width, and does it match NOEON's shared
dim (2560)?
3. Where can each source expose a (B, T, d) hidden stream for the bridges?
Writes docs/COMPAT.md and exits non-zero if an assumption fails.
Usage:
python scripts/analyze_compat.py
"""
from __future__ import annotations
import json
import re
from collections import Counter
from pathlib import Path
ROOT = Path(__file__).resolve().parent.parent
T = json.loads((ROOT / "weights" / "source_tensors.json").read_text())
SHARED_DIM = 2560
def shapes_of(key: str) -> dict:
return {n: tuple(t["shape"]) for n, t in T[key]["tensors"].items()}
def strip_prefix(name: str) -> str:
# drop leading "model." / "language_model." style container prefixes so the
# the two VL-slot variants can be compared on their own merits
for p in ("model.", "language_model.", "module.", "base_model."):
if name.startswith(p):
return name[len(p):]
return name
def hidden_widths(key: str) -> Counter:
"""Most common last dim across 2-D weight matrices = the model width."""
c = Counter()
for n, t in T[key]["tensors"].items():
sh = t["shape"]
if len(sh) == 2:
c[sh[0]] += 1
c[sh[1]] += 1
return c
def main() -> int:
lines = ["# NOEON source compatibility (verified against real tensors)", "",
"Derived from `weights/source_tensors.json`, which is read directly",
"from each source's safetensors headers. Nothing here is assumed.",
""]
ok = True
# 1. vision vs computer_use
vl = {strip_prefix(n): s for n, s in shapes_of("vision").items()}
cw = {strip_prefix(n): s for n, s in shapes_of("computer_use").items()}
common = set(vl) & set(cw)
same_shape = sum(1 for k in common if vl[k] == cw[k])
diff = [k for k in common if vl[k] != cw[k]]
lines += ["## vision vs computer_use", "",
f"- vision tensors: {T['vision']['n_tensors']}",
f"- computer_use tensors: {T['computer_use']['n_tensors']}",
f"- common names (after prefix strip): {len(common)}",
f"- identical shapes among common: {same_shape}",
f"- shape conflicts: {len(diff)}",
f"- vision-only: {len(set(vl)-set(cw))}",
f"- computer_use-only: {len(set(cw)-set(vl))}", ""]
if diff:
ok = False
lines.append(f"CONFLICTS: {diff[:10]}")
lines.append("")
# 2. hidden widths
lines += ["## Real hidden widths (most common 2-D axis)", ""]
for key in ("vision", "computer_use", "generation"):
c = hidden_widths(key)
top = c.most_common(6)
lines.append(f"- **{key}**: {top}")
lines.append("")
# 3. NOEON shared dim check
lines += ["## NOEON shared dimension", ""]
for key in ("vision", "computer_use", "generation"):
c = hidden_widths(key)
has = SHARED_DIM in c
lines.append(f"- {key}: hidden dim {SHARED_DIM} present: **{has}** "
f"(count {c.get(SHARED_DIM, 0)})")
lines.append("")
# 4. candidate hidden-stream tensors
lines += ["## Candidate hidden-stream tensors (for bridge inputs)", ""]
for key in ("vision", "computer_use", "generation"):
cands = [n for n, t in T[key]["tensors"].items()
if len(t["shape"]) == 2 and SHARED_DIM in t["shape"]]
lines.append(f"- **{key}**: {len(cands)} tensors touch dim {SHARED_DIM}")
for n in cands[:4]:
lines.append(f" - `{n}` {tuple(T[key]['tensors'][n]['shape'])}")
lines.append("")
(ROOT / "docs" / "COMPAT.md").write_text("\n".join(lines) + "\n")
print("\n".join(lines))
return 0 if ok else 1
if __name__ == "__main__":
raise SystemExit(main())