Transformers
recurrent-transformer
looped-transformer
inkling2
gemma4
qwen3
test-time-compute
zero-forgetting
dgx-spark
Instructions to use lookevink/inkling2-loop-retrofits with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use lookevink/inkling2-loop-retrofits with Transformers:
# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("lookevink/inkling2-loop-retrofits", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Download plot_results.py from lookevink/inkling2-loop-retrofits: direct link, hf CLI and curl.
- Browser
- Download file 59.1 kB
-
https://huggingface.co/lookevink/inkling2-loop-retrofits/resolve/main/plot_results.py
- Command line
-
hf download hf://lookevink/inkling2-loop-retrofits/plot_results.py
-
curl -L -o plot_results.py https://huggingface.co/lookevink/inkling2-loop-retrofits/resolve/main/plot_results.py
59.1 kB
#!/usr/bin/env python3
"""Generate Looski 'Spectral Silicon' publication figures for Inkling-2 loop experiments.
Implements the official Looski visual system (docs/STYLE_GUIDE.md & brand-mark.ts):
- Dark canvas (--night #07080c), raised surface (--night-soft #0b0f18)
- Official spectral palette (--spec-blue #75b4ff, --spec-mint #9ee5ce,
--spec-amber #f8d67b, --spec-pink #f3a7c7, --spec-violet #be9de6)
- 9-stop --sv-spectrum gradient hairline & clockwise 8-split geometric brand mark
- Space Grotesk headings + JetBrains Mono data/eyebrows
Run with:
uv run --with matplotlib --with numpy python3 plot_results.py results/ --out figures/
"""
from __future__ import annotations
import argparse
import json
from pathlib import Path
from typing import Any
import matplotlib
matplotlib.use("Agg")
import matplotlib.colors as mcolors
from matplotlib.collections import LineCollection
from matplotlib.font_manager import FontProperties, fontManager
import matplotlib.pyplot as plt
import numpy as np
# ---------------------------------------------------------------------------
# Official Looski 'Spectral Silicon' Tokens
# ---------------------------------------------------------------------------
NIGHT = "#07080c"
NIGHT_SOFT = "#0b0f18"
GLASS = "#121724"
GLASS_HI = "#171e2e"
LINE_NIGHT = "#1e2638"
GRID_NIGHT = "#171d2c"
INK = "#e9edf6"
INK_MUTED = "#97a2b8"
INK_DIM = "#69748c"
SPEC_BLUE = "#75b4ff"
SPEC_MINT = "#9ee5ce"
SPEC_AMBER = "#f8d67b"
SPEC_PINK = "#f3a7c7"
SPEC_VIOLET = "#be9de6"
SPEC_CORAL = "#f28b60"
SPEC_CYAN = "#32cbd1"
FUNC_BLUE = "#3578ef"
SPECTRUM_STOPS = [
"#3578ef",
"#32cbd1",
"#83d9b2",
"#bed965",
"#efc254",
"#f28b60",
"#e96399",
"#c476da",
"#8a78ed",
]
SPECTRUM_CMAP = mcolors.LinearSegmentedColormap.from_list("looski_spectrum", SPECTRUM_STOPS)
HEATMAP_CMAP = mcolors.LinearSegmentedColormap.from_list(
"looski_heat",
["#0d1220", "#162544", "#21447a", "#3578ef", "#32cbd1", "#83d9b2", "#f8d67b"],
)
# Model family color mapping in official spectrum order (Blue, Amber, Mint, Pink)
PALETTE = {
"Gemma-4-31B-it": SPEC_BLUE,
"Gemma-4-26B-A4B-it": SPEC_AMBER,
"Qwen3.8-27B": SPEC_MINT,
"Qwen3-4B": SPEC_PINK,
}
MODEL_ORDER = [
"Gemma-4-26B-A4B-it",
"Gemma-4-31B-it",
"Qwen3.8-27B",
"Qwen3-4B",
]
MODE_STYLES = {
"inkling2+var": {"ls": "-", "marker": "o", "lw": 2.6},
"inkling2": {"ls": "--", "marker": "s", "lw": 1.9},
"inkling2+var+lora": {"ls": "-", "marker": "D", "lw": 2.3},
"scalar_gate_loop+var": {"ls": ":", "marker": "^", "lw": 2.4},
"naive_loop": {"ls": "-.", "marker": "x", "lw": 2.0},
"naive_loop+lora": {"ls": "-.", "marker": "x", "lw": 2.0},
"lora_only": {"ls": "--", "marker": "*", "lw": 1.8},
}
# ---------------------------------------------------------------------------
# Font Registration (Space Grotesk + JetBrains Mono + Instrument Serif)
# ---------------------------------------------------------------------------
FONT_PROPS: dict[str, FontProperties] = {}
def init_looski_theme(fonts_dir: Path | None = None) -> None:
"""Register Space Grotesk & JetBrains Mono TTFs if present and configure rcParams."""
search_dirs: list[Path] = []
if fonts_dir and fonts_dir.is_dir():
search_dirs.append(fonts_dir)
# Also check common local cache directories
for cand in [
Path.home() / ".gemini/antigravity-cli/brain/37931aed-51c5-4a0e-8b4f-f9901ad210f8/scratch/fonts",
Path(__file__).resolve().parent / "fonts",
]:
if cand.is_dir() and cand not in search_dirs:
search_dirs.append(cand)
found: dict[str, Path] = {}
for d in search_dirs:
for ttf in sorted(d.glob("*.ttf")):
try:
fontManager.addfont(str(ttf))
found[ttf.stem] = ttf
except Exception:
pass
def _fp(name: str, fallback_family: str, weight: str = "normal", style: str = "normal", size: float = 10.0) -> FontProperties:
if name in found:
return FontProperties(fname=str(found[name]), size=size)
return FontProperties(family=fallback_family, weight=weight, style=style, size=size)
FONT_PROPS["sans"] = _fp("SpaceGrotesk-Regular", "sans-serif", "normal")
FONT_PROPS["sans_med"] = _fp("SpaceGrotesk-Medium", "sans-serif", "medium")
FONT_PROPS["sans_semi"] = _fp("SpaceGrotesk-SemiBold", "sans-serif", "semibold")
FONT_PROPS["sans_bold"] = _fp("SpaceGrotesk-Bold", "sans-serif", "bold")
FONT_PROPS["mono"] = _fp("JetBrainsMono-Regular", "monospace", "normal")
FONT_PROPS["mono_med"] = _fp("JetBrainsMono-Medium", "monospace", "medium")
FONT_PROPS["mono_bold"] = _fp("JetBrainsMono-Bold", "monospace", "bold")
FONT_PROPS["serif_italic"] = _fp("InstrumentSerif-Italic", "serif", "normal", "italic")
sans_name = "Space Grotesk" if "SpaceGrotesk-Regular" in found else "DejaVu Sans"
plt.rcParams.update({
"figure.facecolor": NIGHT,
"savefig.facecolor": NIGHT,
"axes.facecolor": NIGHT_SOFT,
"axes.edgecolor": LINE_NIGHT,
"axes.linewidth": 0.9,
"axes.grid": True,
"grid.color": GRID_NIGHT,
"grid.linestyle": "-",
"grid.linewidth": 0.7,
"axes.labelcolor": INK_MUTED,
"axes.titlecolor": INK,
"xtick.color": INK_MUTED,
"ytick.color": INK_MUTED,
"text.color": INK,
"font.family": sans_name,
"font.size": 10,
"axes.titlesize": 11.5,
"axes.titleweight": "bold",
"axes.labelsize": 9.8,
"legend.frameon": True,
"legend.facecolor": GLASS,
"legend.edgecolor": LINE_NIGHT,
"legend.framealpha": 0.94,
"legend.fontsize": 8.4,
})
def fp(key: str, size: float) -> FontProperties:
p = FONT_PROPS[key].copy()
p.set_size(size)
return p
# ---------------------------------------------------------------------------
# Signature Looski Brand Chrome (8-Split Geometric Mark + Spectrum Hairline)
# ---------------------------------------------------------------------------
def _looski_mark_segments() -> list[tuple[tuple[float, float], tuple[float, float]]]:
"""Exact clockwise halving, eight splits deep, matching looski-v2/packages/ui/src/lib/brand-mark.ts."""
x, y, width, height = 2.0, 2.0, 60.0, 60.0
segs: list[tuple[tuple[float, float], tuple[float, float]]] = []
for i in range(8):
direction = i % 4
horizontal = direction in (0, 2)
w = width if horizontal else width / 2.0
h = height / 2.0 if horizontal else height
left = x + w if direction == 1 else x
top = y + h if direction == 2 else y
corners = [
(left, top),
(left + w, top),
(left + w, top + h),
(left, top + h),
]
owned = [
top == 2.0 or direction == 2,
left + w == 62.0 or direction == 3,
top + h == 62.0 or direction == 0,
left == 2.0 or direction == 1,
]
for idx, is_owned in enumerate(owned):
if is_owned:
segs.append((corners[idx], corners[(idx + 1) % 4]))
if direction == 0:
y += h
if direction == 3:
x += w
if horizontal:
height = h
else:
width = w
return segs
def draw_looski_mark(ax_mark: plt.Axes) -> None:
"""Draw the exact 8-split Looski brand mark with 9-stop diagonal spectral gradient."""
ax_mark.set_facecolor("none")
ax_mark.set_xlim(0, 64)
ax_mark.set_ylim(64, 0) # match SVG y-down coordinates
ax_mark.set_aspect("equal")
ax_mark.axis("off")
sub_segs = []
t_vals = []
for (x0, y0), (x1, y1) in _looski_mark_segments():
n = 14
xs = np.linspace(x0, x1, n + 1)
ys = np.linspace(y0, y1, n + 1)
for k in range(n):
p0 = (xs[k], ys[k])
p1 = (xs[k + 1], ys[k + 1])
sub_segs.append([p0, p1])
mx = 0.5 * (p0[0] + p1[0])
my = 0.5 * (p0[1] + p1[1])
# Diagonal gradient projection from (2,2) -> (62,62)
t = np.clip(((mx - 2.0) + (my - 2.0)) / 120.0, 0.0, 1.0)
t_vals.append(t)
lc = LineCollection(
sub_segs,
cmap=SPECTRUM_CMAP,
norm=mcolors.Normalize(0.0, 1.0),
linewidths=1.45,
capstyle="round",
joinstyle="round",
)
lc.set_array(np.array(t_vals))
ax_mark.add_collection(lc)
def apply_looski_chrome(
fig: plt.Figure,
title: str,
subtitle: str,
eyebrow: str = "LABSKI / INKLING-2 RECURRENT LOOP RETROFIT · 4× DGX SPARK GB10",
footnote: str | None = None,
header_y: float = 0.962,
line_y: float = 0.900,
) -> None:
"""Add official Looski Spectral Silicon top bar, rainbow hairline, and footer."""
fig_w, fig_h = fig.get_size_inches()
# Square mark box cleanly above the hero title with generous breathing room
mark_h = 0.036 * (8.5 / fig_h)
mark_h = float(np.clip(mark_h, 0.028, 0.044))
mark_w = mark_h * (fig_h / fig_w)
left_x = 0.032
mark_bottom = header_y - mark_h * 0.42
ax_mark = fig.add_axes([left_x, mark_bottom, mark_w, mark_h])
draw_looski_mark(ax_mark)
# Wordmark vertically centered with geometric mark
mark_mid_y = mark_bottom + mark_h * 0.50
fig.text(
left_x + mark_w + 0.008,
mark_mid_y,
"Looski",
color=INK,
va="center",
ha="left",
fontproperties=fp("sans_semi", 13.5),
)
# Right-aligned monospace eyebrow
fig.text(
0.968,
mark_mid_y,
eyebrow,
color=INK_MUTED,
va="center",
ha="right",
fontproperties=fp("mono", 8.5),
)
# Main figure headline + subtitle (clean gap below mark)
title_y = line_y + 0.019
fig.text(
left_x,
title_y,
title,
color=INK,
va="bottom",
ha="left",
fontproperties=fp("sans_bold", 15.0),
)
if subtitle:
fig.text(
0.968,
title_y + 0.002,
subtitle,
color=INK_MUTED,
va="bottom",
ha="right",
fontproperties=fp("sans", 9.4),
)
# Full-width 2px Looski 9-stop spectral gradient hairline
bar_h = 0.0032 * (8.5 / fig_h)
bar_h = float(np.clip(bar_h, 0.0022, 0.0044))
ax_bar = fig.add_axes([left_x, line_y + 0.007, 0.968 - left_x, bar_h])
grad = np.linspace(0.0, 1.0, 512).reshape(1, -1)
ax_bar.imshow(grad, aspect="auto", cmap=SPECTRUM_CMAP, interpolation="bicubic")
ax_bar.axis("off")
# Quiet footer (with optional note centered above footer)
if footnote:
fig.text(
0.5,
0.032,
footnote,
color=INK_MUTED,
ha="center",
va="bottom",
fontproperties=fp("mono", 7.8),
)
fig.text(
left_x,
0.010,
"loo.ski · github.com/looskis/labski",
color=INK_DIM,
ha="left",
va="bottom",
fontproperties=fp("mono", 7.8),
)
fig.text(
0.968,
0.010,
"hf.co/lookevink/inkling2-loop-retrofits",
color=INK_DIM,
ha="right",
va="bottom",
fontproperties=fp("mono", 7.8),
)
def style_axes(ax: plt.Axes, hide_top_right: bool = True) -> None:
ax.set_facecolor(NIGHT_SOFT)
ax.grid(True, color=GRID_NIGHT, linewidth=0.7, zorder=0)
ax.set_axisbelow(True)
for sp in ("left", "bottom", "top", "right"):
ax.spines[sp].set_color(LINE_NIGHT)
ax.spines[sp].set_linewidth(0.9)
if hide_top_right:
ax.spines["top"].set_visible(False)
ax.spines["right"].set_visible(False)
ax.tick_params(colors=INK_MUTED, labelsize=8.8, length=3.5, width=0.8)
for lbl in ax.get_xticklabels() + ax.get_yticklabels():
lbl.set_fontproperties(fp("mono", 8.6))
# ---------------------------------------------------------------------------
# Data Loading Helpers
# ---------------------------------------------------------------------------
def mode_tag(m: dict[str, Any]) -> str:
ta = m["train_args"]
t = ta["mode"]
if ta.get("varloop"):
t += "+var"
if m["loop_config"].get("core_lora_rank", 0) > 0 and t != "lora_only":
t += "+lora"
return t
def short_model(label: str) -> str:
return (
label.replace("-it", "")
.replace("Gemma-4-26B-A4B", "G4-26B MoE")
.replace("Gemma-4-31B", "G4-31B")
)
def load_completed_runs(results_dir: Path) -> list[dict[str, Any]]:
runs = []
for sub in sorted(results_dir.iterdir()):
mp = sub / "metrics.json"
if mp.is_file():
m = json.loads(mp.read_text())
m["_dir"] = sub
m["_mode_tag"] = mode_tag(m)
runs.append(m)
return runs
def load_train_logs(results_dir: Path) -> dict[str, list[dict[str, Any]]]:
logs = {}
for sub in sorted(results_dir.iterdir()):
lp = sub / "train_log.jsonl"
if lp.is_file():
rows = [json.loads(l) for l in lp.read_text().splitlines() if l.strip()]
if rows:
logs[sub.name] = rows
return logs
def color_for_run(name: str, model_label: str | None = None) -> str:
if model_label and model_label in PALETTE:
return PALETTE[model_label]
if "31b" in name:
return PALETTE["Gemma-4-31B-it"]
if "26b" in name:
return PALETTE["Gemma-4-26B-A4B-it"]
if "qwen38" in name:
return PALETTE["Qwen3.8-27B"]
return PALETTE["Qwen3-4B"]
def _spread_labels(
items: list[tuple[float, str, str]],
ymin: float,
ymax: float,
min_gap_frac: float = 0.072,
) -> list[tuple[float, float, str, str]]:
if not items:
return []
ordered = sorted(items, key=lambda t: t[0])
min_gap = max((ymax - ymin) * min_gap_frac, 1e-3)
ys = [t[0] for t in ordered]
for _ in range(30):
moved = False
for i in range(1, len(ys)):
if ys[i] - ys[i - 1] < min_gap:
mid = 0.5 * (ys[i] + ys[i - 1])
ys[i - 1] = mid - 0.5 * min_gap
ys[i] = mid + 0.5 * min_gap
moved = True
if not moved:
break
low_lim = ymin + (ymax - ymin) * 0.03
high_lim = ymax - (ymax - ymin) * 0.04
if ys[0] < low_lim:
shift = low_lim - ys[0]
ys = [y + shift for y in ys]
if ys[-1] > high_lim:
shift = ys[-1] - high_lim
ys = [y - shift for y in ys]
return [(orig[0], adj_y, orig[1], orig[2]) for orig, adj_y in zip(ordered, ys)]
# ---------------------------------------------------------------------------
# Figure 1: Depth Scaling (P = 1..5) + Parameter-Matched 1-Pass LoRA Controls
# ---------------------------------------------------------------------------
def plot_depth_scaling(runs: list[dict[str, Any]], out_path: Path) -> None:
loop_runs = [r for r in runs if r["train_args"]["mode"] != "lora_only"]
lora_runs = [r for r in runs if r["train_args"]["mode"] == "lora_only"]
if not loop_runs:
return
fig, axes = plt.subplots(2, 2, figsize=(15.0, 10.2), sharex=True)
fig.patch.set_facecolor(NIGHT)
panels = [
(axes[0, 0], "overall_id", "acc", 100.0, "In-Distribution Accuracy (%) vs. Loop Passes", "Exact-Match Accuracy (%)"),
(axes[0, 1], "overall_ood", "acc", 100.0, "Out-of-Distribution (Deeper Hops) Accuracy (%)", "Exact-Match Accuracy (%)"),
(axes[1, 0], "overall_id", "mean_ans_nll", 1.0, "In-Distribution Gold-Answer NLL (Lower = Better)", "Cross-Entropy Loss (NLL)"),
(axes[1, 1], "overall_ood", "mean_ans_nll", 1.0, "Out-of-Distribution Gold-Answer NLL (Lower = Better)", "Cross-Entropy Loss (NLL)"),
]
for ax, split_key, metric_key, scale, title, ylabel in panels:
style_axes(ax)
ax.axvspan(3.35, 6.08, color=SPEC_VIOLET, alpha=0.075, zorder=0)
ax.axvline(3.35, color=SPEC_VIOLET, ls=":", lw=1.2, alpha=0.65, zorder=1)
ax.set_title(title, fontproperties=fp("sans_bold", 11.2), color=INK, pad=9, loc="left")
ax.set_ylabel(ylabel, fontproperties=fp("sans_med", 9.6), color=INK_MUTED)
ax.set_xticks([1, 2, 3, 4, 5])
ax.set_xticklabels(["P=1\nBase", "P=2", "P=3\nTrain Max", "P=4\nExtrap", "P=5\nExtrap"])
for lbl in ax.get_xticklabels():
lbl.set_fontproperties(fp("mono", 8.4))
ax.set_xlim(0.50, 6.08)
ann_by_x: dict[int, list[tuple[float, str, str]]] = {1: [], 3: [], 5: []}
for r in loop_runs:
ps = r["post_training"]["serial"]
xs, ys = [], []
for p in (1, 2, 3, 4, 5):
tag = f"P{p}"
if tag in ps:
xs.append(p)
ys.append(ps[tag][split_key][metric_key] * scale)
if not xs:
continue
col = color_for_run(r["run_name"], r["model_label"])
st = MODE_STYLES.get(r["_mode_tag"], {"ls": "-", "marker": "o", "lw": 2.0})
sm = short_model(r["model_label"])
lbl = f"{sm} ({r['_mode_tag']})"
is_hi = r["_mode_tag"] in ("inkling2+var", "scalar_gate_loop+var")
alpha = 0.98 if is_hi else 0.62
ax.plot(
xs, ys, color=col, linestyle=st["ls"], marker=st["marker"],
linewidth=st["lw"], markersize=6.8 if is_hi else 5.6,
markeredgecolor=NIGHT, markeredgewidth=0.7,
label=lbl, alpha=alpha, zorder=4 if is_hi else 3,
)
if is_hi:
for x, y in zip(xs, ys):
if x in (1, 3, 5):
txt = f"{y:.1f}%" if scale == 100.0 else f"{y:.2f}"
ann_by_x[x].append((y, txt, col))
lora_labels: list[tuple[float, str, str]] = []
for lr in lora_runs:
sd = lr["post_training"]["serial"].get("P1")
if not sd:
continue
val = sd[split_key][metric_key] * scale
col = color_for_run(lr["run_name"], lr["model_label"])
lbl = f"{short_model(lr['model_label'])} 1-Pass LoRA"
ax.axhline(val, color=col, linestyle="--", linewidth=1.35, alpha=0.58, label=lbl, zorder=2)
vtxt = f"{val:.1f}%" if scale == 100.0 else f"{val:.2f}"
lora_labels.append((val, f"LoRA {vtxt}", col))
ymin, ymax = ax.get_ylim()
pad = max((ymax - ymin) * 0.16, 1.2 if scale == 100.0 else 0.2)
ax.set_ylim(max(0.0, ymin - pad * 0.3), ymax + pad)
new_ymin, new_ymax = ax.get_ylim()
for x_pt, items in ann_by_x.items():
dedup: list[tuple[float, str, str]] = []
seen = set()
for yv, txt, col in items:
key = (round(yv, 2), col)
if key not in seen:
seen.add(key)
dedup.append((yv, txt, col))
spread = _spread_labels(dedup, new_ymin, new_ymax, min_gap_frac=0.072)
for orig_y, adj_y, txt, col in spread:
if x_pt == 1:
tx, ha = 0.88, "right"
elif x_pt == 5:
tx, ha = 5.10, "left"
else:
tx, ha = 3.07, "left"
if abs(adj_y - orig_y) > (new_ymax - new_ymin) * 0.025:
ax.plot([x_pt, tx], [orig_y, adj_y], color=col, lw=0.7, alpha=0.55, zorder=2)
ax.text(
tx, adj_y, txt, ha=ha, va="center", color=col,
fontproperties=fp("mono_bold", 7.8),
bbox=dict(boxstyle="round,pad=0.16", fc=NIGHT_SOFT, ec="none", alpha=0.82),
zorder=5,
)
for orig_y, adj_y, txt, col in _spread_labels(lora_labels, new_ymin, new_ymax, min_gap_frac=0.075):
ax.text(
6.02, adj_y, txt, ha="right", va="center", color=col,
fontproperties=fp("mono_bold", 7.4),
bbox=dict(boxstyle="round,pad=0.18", fc=GLASS, ec=col, lw=0.75, alpha=0.94),
zorder=6,
)
ax.text(
4.55, new_ymax - (new_ymax - new_ymin) * 0.035,
"UNSEEN DEPTH EXTRAPOLATION",
ha="center", va="top", color=SPEC_VIOLET, alpha=0.85,
fontproperties=fp("mono_med", 7.4),
)
handles, labels = axes[0, 0].get_legend_handles_labels()
leg = fig.legend(
handles, labels, loc="upper center", bbox_to_anchor=(0.5, 0.892),
ncol=4, prop=fp("mono", 7.8), facecolor=GLASS, edgecolor=LINE_NIGHT,
labelcolor=INK, framealpha=0.95, columnspacing=1.2, handlelength=2.2,
)
leg.get_frame().set_linewidth(0.8)
apply_looski_chrome(
fig,
title="Depth Scaling (P = 1..5) vs. 1-Pass LoRA Controls",
subtitle="Zero-forgetting latent recursion across 4 open-weight backbones",
header_y=0.972,
line_y=0.902,
)
fig.subplots_adjust(left=0.068, right=0.968, top=0.775, bottom=0.078, wspace=0.18, hspace=0.22)
fig.savefig(out_path, dpi=220, facecolor=NIGHT)
plt.close(fig)
# ---------------------------------------------------------------------------
# Figure 2: Compact Two-Panel Per-Task Heatmap (ID + GSM8K Top, OOD Bottom)
# ---------------------------------------------------------------------------
def plot_per_task_breakdown(runs: list[dict[str, Any]], out_path: Path) -> None:
if not runs:
return
tasks = ["graph_bfs", "pointer_chase", "mod_register", "perm_track"]
id_rows = [
("graph_bfs", "Graph BFS (ID)"),
("pointer_chase", "Pointer Chase (ID)"),
("mod_register", "Mod-19 Register (ID)"),
("perm_track", "S5 Cup-Swap (ID)"),
("gsm8k", "GSM8K Direct (No-CoT)"),
]
ood_rows = [
("graph_bfs", "Graph BFS (OOD Deeper)"),
("pointer_chase", "Pointer Chase (OOD 5–6 Hops)"),
("mod_register", "Mod-19 Register (OOD 5–6 Ops)"),
("perm_track", "S5 Cup-Swap (OOD 7–8 Swaps)"),
]
by_model: dict[str, dict[str, dict[str, Any]]] = {}
for r in runs:
by_model.setdefault(r["model_label"], {})[r["_mode_tag"]] = r
col_labels: list[str] = []
col_group_spans: list[tuple[str, int, int, str]] = []
id_cols: list[list[float]] = []
ood_cols: list[list[float]] = []
def extract_col(r: dict[str, Any], p_tag: str) -> tuple[list[float], list[float]]:
sd = r["post_training"]["serial"][p_tag]
id_v = [sd["per_task"][t]["id"]["acc"] * 100.0 for t in tasks]
gsm = (r["post_training"]["gsm8k_direct"].get(p_tag) or {}).get("acc")
id_v.append(gsm * 100.0 if gsm is not None else np.nan)
ood_v = [sd["per_task"][t]["ood"]["acc"] * 100.0 for t in tasks]
return id_v, ood_v
ordered_models = [m for m in MODEL_ORDER if m in by_model] + [m for m in by_model if m not in MODEL_ORDER]
for mlabel in ordered_models:
modes = by_model[mlabel]
start_c = len(col_labels)
var_r = modes.get("inkling2+var")
scalar_r = modes.get("scalar_gate_loop+var")
lora_r = modes.get("lora_only")
if var_r:
for p_tag, lbl in [("P1", "Base\nP=1"), ("P3", "Loop\nP=3"), ("P5", "Loop\nP=5")]:
if p_tag in var_r["post_training"]["serial"]:
iv, ov = extract_col(var_r, p_tag)
id_cols.append(iv)
ood_cols.append(ov)
col_labels.append(lbl)
if scalar_r and "P3" in scalar_r["post_training"]["serial"]:
iv, ov = extract_col(scalar_r, "P3")
id_cols.append(iv)
ood_cols.append(ov)
col_labels.append("Scalar\nP=3")
if lora_r and "P1" in lora_r["post_training"]["serial"]:
iv, ov = extract_col(lora_r, "P1")
id_cols.append(iv)
ood_cols.append(ov)
col_labels.append("1-Pass\nLoRA")
end_c = len(col_labels) - 1
if end_c >= start_c:
col_group_spans.append((short_model(mlabel), start_c, end_c, PALETTE.get(mlabel, INK)))
if not col_labels:
return
mat_id = np.array(id_cols, dtype=float).T
mat_ood = np.array(ood_cols, dtype=float).T
fig_w = max(14.5, 0.85 * len(col_labels) + 3.2)
fig, (ax_id, ax_ood) = plt.subplots(
2, 1, figsize=(fig_w, 8.8), sharex=True,
gridspec_kw={"height_ratios": [5, 4], "hspace": 0.28},
)
fig.patch.set_facecolor(NIGHT)
cmap = HEATMAP_CMAP.copy()
cmap.set_bad(color="#111622")
for ax, mat, rows, title, vmax in [
(ax_id, mat_id, id_rows, "A. In-Distribution Serial Reasoning & Direct No-CoT GSM8K (%)", 100.0),
(ax_ood, mat_ood, ood_rows, "B. Out-of-Distribution (Unseen Deeper Hops / Steps) (%)", 50.0),
]:
ax.set_facecolor(NIGHT_SOFT)
masked = np.ma.masked_invalid(mat)
im = ax.imshow(masked, cmap=cmap, aspect="auto", vmin=0.0, vmax=vmax)
ax.set_yticks(range(len(rows)))
ax.set_yticklabels([r[1] for r in rows], fontproperties=fp("sans_semi", 9.6), color=INK)
ax.set_title(title, fontproperties=fp("sans_bold", 11.2), color=INK, pad=36 if ax is ax_id else 10, loc="left")
ax.grid(False)
for sp in ax.spines.values():
sp.set_color(LINE_NIGHT)
sp.set_linewidth(0.9)
# Subtle cell gridlines
ax.set_xticks(np.arange(-0.5, mat.shape[1], 1), minor=True)
ax.set_yticks(np.arange(-0.5, mat.shape[0], 1), minor=True)
ax.grid(which="minor", color=NIGHT, linestyle="-", linewidth=1.2)
ax.tick_params(which="minor", length=0)
for i in range(mat.shape[0]):
for j in range(mat.shape[1]):
v = mat[i, j]
if np.isnan(v):
ax.text(j, i, "—", ha="center", va="center", color=INK_DIM, fontproperties=fp("mono", 9.0))
else:
txt_col = NIGHT if v > vmax * 0.56 else INK
ax.text(j, i, f"{v:.1f}%", ha="center", va="center", color=txt_col, fontproperties=fp("mono_bold", 8.5))
for _, sc, ec, _ in col_group_spans[:-1]:
ax.axvline(ec + 0.5, color=NIGHT, linewidth=4.2, zorder=4)
ax.axvline(ec + 0.5, color="#2e3952", linewidth=1.1, zorder=5)
cbar = fig.colorbar(im, ax=ax, fraction=0.018, pad=0.014)
cbar.set_label("Accuracy (%)", fontproperties=fp("mono", 8.4), color=INK_MUTED)
cbar.ax.tick_params(colors=INK_MUTED, labelsize=8.0)
for t in cbar.ax.get_yticklabels():
t.set_fontproperties(fp("mono", 8.0))
cbar.outline.set_edgecolor(LINE_NIGHT)
for name, sc, ec, col in col_group_spans:
mid = 0.5 * (sc + ec)
ax_id.text(
mid, -0.78, name, ha="center", va="bottom", color=col,
fontproperties=fp("sans_bold", 10.2),
bbox=dict(boxstyle="round,pad=0.28", fc=GLASS, ec=col, lw=1.1),
)
ax_ood.set_xticks(range(len(col_labels)))
ax_ood.set_xticklabels(col_labels, fontproperties=fp("mono_bold", 8.4), color=INK_MUTED)
ax_ood.tick_params(axis="x", colors=INK_MUTED, length=3.5)
apply_looski_chrome(
fig,
title="Per-Task Reasoning Breakdown: Base (P=1) vs. Looping vs. Controls",
subtitle="Includes 0.74M Scalar-Gate breakthrough on Qwen3-4B",
header_y=0.968,
line_y=0.892,
)
fig.subplots_adjust(left=0.175, right=0.945, top=0.805, bottom=0.095)
fig.savefig(out_path, dpi=220, facecolor=NIGHT)
plt.close(fig)
# ---------------------------------------------------------------------------
# Figure 3: Causal Message Ablations + Gate Telemetry + Hardware Frontier
# ---------------------------------------------------------------------------
def plot_causal_and_mechanistic(runs: list[dict[str, Any]], out_path: Path) -> None:
ab_runs = [
r for r in runs
if r.get("causal_ablations")
and r["_mode_tag"] in ("inkling2+var", "inkling2", "scalar_gate_loop+var")
]
fig, axes = plt.subplots(1, 3, figsize=(17.2, 6.2))
fig.patch.set_facecolor(NIGHT)
# Panel A: Causal message ablations at P=3 (ID NLL)
ax = axes[0]
style_axes(ax)
if ab_runs:
conds = [
("P1 Base", lambda r: r["post_training"]["serial"]["P1"]["overall_id"]["mean_ans_nll"], "#5e687f"),
("P2 Normal", lambda r: r["post_training"]["serial"]["P2"]["overall_id"]["mean_ans_nll"], SPEC_CYAN),
("P3 Normal", lambda r: r["post_training"]["serial"]["P3"]["overall_id"]["mean_ans_nll"], SPEC_BLUE),
("P3 Zero-Msg", lambda r: r["causal_ablations"]["zero"]["overall_id"]["mean_ans_nll"], SPEC_AMBER),
("P3 Shuf-Tok", lambda r: r["causal_ablations"]["shuffle_tokens"]["overall_id"]["mean_ans_nll"], SPEC_CORAL),
("P3 Freeze-P1", lambda r: r["causal_ablations"]["freeze_pass1"]["overall_id"]["mean_ans_nll"], SPEC_VIOLET),
]
x = np.arange(len(ab_runs))
w = 0.13
for idx, (clbl, fn, ccol) in enumerate(conds):
vals = [fn(r) for r in ab_runs]
offset = (idx - (len(conds) - 1) / 2.0) * w
bars = ax.bar(x + offset, vals, width=w, color=ccol, label=clbl, edgecolor=NIGHT, linewidth=0.5, zorder=3)
for b, v in zip(bars, vals):
ax.text(
b.get_x() + b.get_width() / 2, v + 0.14, f"{v:.2f}",
ha="center", va="bottom", color=INK_MUTED if v < 5 else ccol,
fontproperties=fp("mono_bold" if v >= 5 else "mono", 6.6), rotation=90,
)
xlabels = []
for r in ab_runs:
sm = short_model(r["model_label"]).replace(" MoE", "\nMoE")
mt = (
r["_mode_tag"]
.replace("inkling2+var", "var")
.replace("inkling2", "fix3")
.replace("scalar_gate_loop+var", "scalar")
)
xlabels.append(f"{sm}\n({mt})")
ax.set_xticks(x)
ax.set_xticklabels(xlabels, fontproperties=fp("mono", 7.6), color=INK_MUTED)
ax.set_ylabel("ID Gold-Answer NLL (Lower = Better)", fontproperties=fp("sans_med", 9.5))
ax.set_title("A. Causal Message Ablations at P=3", fontproperties=fp("sans_bold", 11.0), loc="left", pad=9)
ax.set_ylim(0, ax.get_ylim()[1] * 1.25)
ax.legend(prop=fp("mono", 7.2), ncol=2, loc="upper right", facecolor=GLASS, edgecolor=LINE_NIGHT, labelcolor=INK)
# Panel B: Per-Layer Gate Activation Magnitude (Pass 3)
ax = axes[1]
style_axes(ax)
primary_gate_runs = [r for r in ab_runs if r["_mode_tag"] == "inkling2+var"]
for r in primary_gate_runs:
diag = r["post_training"]["serial"].get("P3", {}).get("diagnostics")
if not diag or not diag.get("passes"):
continue
p3 = diag["passes"][-1]
if not p3["layers"] or "gates" not in p3["layers"][0] or "q" not in p3["layers"][0]["gates"]:
continue
layers = [l["layer_idx"] for l in p3["layers"]]
pos = np.linspace(0.0, 1.0, len(layers))
q_msg = [l["gates"]["q"]["message_rms"] for l in p3["layers"]]
q_fgt = [l["gates"]["q"]["forget_rms"] for l in p3["layers"]]
col = color_for_run(r["run_name"], r["model_label"])
sm = short_model(r["model_label"])
ax.plot(pos, q_msg, color=col, lw=2.3, marker="o", ms=4.0, markeredgecolor=NIGHT, markeredgewidth=0.5, label=f"{sm} msg", zorder=4)
ax.plot(pos, q_fgt, color=col, lw=1.35, ls="--", marker="x", ms=3.5, alpha=0.68, label=f"{sm} forget", zorder=3)
ax.set_title("B. Learned Gate Activity Across Core (Pass 3)", fontproperties=fp("sans_bold", 11.0), loc="left", pad=9)
ax.set_xlabel("Relative Core Layer Depth (0 = Start, 1 = End)", fontproperties=fp("sans_med", 9.2))
ax.set_ylabel("Gate RMS Magnitude (|tanh|)", fontproperties=fp("sans_med", 9.5))
ax.legend(prop=fp("mono", 7.2), ncol=2, loc="upper left", facecolor=GLASS, edgecolor=LINE_NIGHT, labelcolor=INK)
# Panel C: DGX Spark GB10 Hardware Cost (Latency & Energy vs Pass Count)
ax = axes[2]
style_axes(ax, hide_top_right=False)
ax.spines["top"].set_visible(False)
hw_seen = {}
for r in runs:
hw = r.get("hardware_forward_cost", {})
if "P3" in hw and r["model_label"] not in hw_seen:
hw_seen[r["model_label"]] = hw
if hw_seen:
ax2 = ax.twinx()
ax2.grid(False)
ax2.spines["top"].set_visible(False)
ax2.spines["left"].set_visible(False)
ax2.spines["bottom"].set_visible(False)
ax2.spines["right"].set_color(LINE_NIGHT)
ax2.tick_params(colors=INK_MUTED, labelsize=8.4)
for lbl in ax2.get_yticklabels():
lbl.set_fontproperties(fp("mono", 8.4))
for mlabel in MODEL_ORDER:
if mlabel not in hw_seen:
continue
hw = hw_seen[mlabel]
ps = [1, 2, 3]
ms = [hw[f"P{p}"]["ms_per_forward"] for p in ps]
jj = [hw[f"P{p}"]["joules_per_forward"] for p in ps]
col = color_for_run(mlabel, mlabel)
sm = short_model(mlabel)
ax.plot(ps, ms, color=col, lw=2.5, marker="o", ms=6.2, markeredgecolor=NIGHT, markeredgewidth=0.6, label=sm, zorder=4)
ax2.plot(ps, jj, color=col, lw=1.5, ls=":", marker="^", ms=5.2, alpha=0.82, zorder=3)
ax.set_xticks([1, 2, 3])
ax.set_xticklabels(["P=1", "P=2", "P=3"], fontproperties=fp("mono_bold", 8.8))
ax.set_ylabel("Latency (ms / forward · solid)", fontproperties=fp("sans_med", 9.3))
ax2.set_ylabel("GPU Energy (Joules / forward · dotted)", fontproperties=fp("sans_med", 9.3), color=INK_MUTED)
ax.set_title("C. DGX Spark GB10 Forward Cost vs. Depth", fontproperties=fp("sans_bold", 11.0), loc="left", pad=9)
leg = ax.legend(prop=fp("mono", 7.8), loc="upper left", title="SOLID = MS · DOTTED = JOULES", facecolor=GLASS, edgecolor=LINE_NIGHT, labelcolor=INK)
leg.get_title().set_fontproperties(fp("mono_bold", 7.0))
leg.get_title().set_color(INK_MUTED)
apply_looski_chrome(
fig,
title="Mechanistic Proof, Gate Telemetry & NVIDIA GB10 Hardware Cost",
subtitle="Token shuffling collapses Gemma 4 (0.8% / 3.7%) · Measured via 250ms nvidia-smi energy polling",
header_y=0.958,
line_y=0.858,
)
fig.subplots_adjust(left=0.052, right=0.942, top=0.775, bottom=0.145, wspace=0.25)
fig.savefig(out_path, dpi=220, facecolor=NIGHT)
plt.close(fig)
# ---------------------------------------------------------------------------
# Figure 4: Concurrent 4-Spark Training Trajectories
# ---------------------------------------------------------------------------
def plot_training_curves(logs: dict[str, list[dict[str, Any]]], out_path: Path) -> None:
if not logs:
return
fig, axes = plt.subplots(1, 3, figsize=(16.8, 6.2))
fig.patch.set_facecolor(NIGHT)
for ax in axes:
style_axes(ax)
for name, rows in sorted(logs.items()):
steps = [r["step"] for r in rows]
sloss = [r["serial_loss"] for r in rows]
val_steps = [r["step"] for r in rows if "val_id_nll" in r]
val_nll = [r["val_id_nll"] for r in rows if "val_id_nll" in r]
val_acc = [r["val_id_acc"] * 100.0 for r in rows if "val_id_acc" in r]
col = color_for_run(name)
if "control-1pass-lora" in name:
ls, mk, alp = "--", "*", 0.78
elif "fixed3" in name:
ls, mk, alp = "-.", "s", 0.72
elif "plus-lora" in name:
ls, mk, alp = "-", "D", 0.78
elif "scalar" in name:
ls, mk, alp = ":", "^", 0.98
elif "naive" in name:
ls, mk, alp = "-.", "x", 0.85
else:
ls, mk, alp = "-", "o", 0.95
short = (
name.replace("gemma4-26b-a4b", "G4-26B MoE")
.replace("gemma4-31b", "G4-31B")
.replace("qwen38-27b", "Qwen3.8-27B")
.replace("qwen3-4b", "Qwen3-4B")
.replace("-inkling2-varloop", " (loop+var)")
.replace("-control-1pass-lora", " (1-pass LoRA)")
.replace("-inkling2-plus-lora", " (loop+LoRA)")
.replace("-inkling2-fixed3", " (fixed3)")
.replace("-scalar-gate-loop", " (scalar 0.74M)")
.replace("-naive-loop-lora", " (naive loop)")
)
axes[0].plot(steps, sloss, color=col, ls=ls, lw=1.9, marker=mk, ms=3.8, label=short, alpha=alp)
if val_steps:
axes[1].plot(val_steps, val_nll, color=col, ls=ls, lw=2.1, marker=mk, ms=5.2, label=short, alpha=alp)
axes[2].plot(val_steps, val_acc, color=col, ls=ls, lw=2.1, marker=mk, ms=5.2, label=short, alpha=alp)
# Highlight step-0 naive loop shock cleanly
axes[0].annotate(
"Naive loop shock\n(loss 11.54 @ step 1)",
xy=(1, 11.54), xytext=(38, 10.3),
color=SPEC_CORAL, fontproperties=fp("mono_bold", 7.8),
arrowprops=dict(arrowstyle="->", color=SPEC_CORAL, lw=1.1),
bbox=dict(boxstyle="round,pad=0.22", fc=GLASS, ec=SPEC_CORAL, lw=0.8),
)
axes[0].set_title("A. Training Serial Loss vs. Optimizer Step", fontproperties=fp("sans_bold", 11.0), loc="left", pad=8)
axes[0].set_xlabel("Optimizer Step (8 seq / step)", fontproperties=fp("sans_med", 9.3))
axes[0].set_ylabel("Answer-Token Cross-Entropy Loss", fontproperties=fp("sans_med", 9.3))
axes[1].set_title("B. Mid-Run Validation ID NLL", fontproperties=fp("sans_bold", 11.0), loc="left", pad=8)
axes[1].set_xlabel("Optimizer Step", fontproperties=fp("sans_med", 9.3))
axes[1].set_ylabel("Validation NLL (Lower = Better)", fontproperties=fp("sans_med", 9.3))
axes[2].set_title("C. Mid-Run Validation ID Accuracy (%)", fontproperties=fp("sans_bold", 11.0), loc="left", pad=8)
axes[2].set_xlabel("Optimizer Step", fontproperties=fp("sans_med", 9.3))
axes[2].set_ylabel("Validation Exact-Match (%)", fontproperties=fp("sans_med", 9.3))
handles, labels = axes[0].get_legend_handles_labels()
leg = fig.legend(
handles, labels, loc="upper center", bbox_to_anchor=(0.5, 0.848),
ncol=5, prop=fp("mono", 7.5), facecolor=GLASS, edgecolor=LINE_NIGHT,
labelcolor=INK, columnspacing=1.0,
)
leg.get_frame().set_linewidth(0.8)
apply_looski_chrome(
fig,
title="Concurrent 4-Spark Training Trajectories (All 13 Runs)",
subtitle="Zero-init prelude-reset retrofits start smoothly vs. 11.54 step-0 shock on naive looping",
header_y=0.958,
line_y=0.862,
)
fig.subplots_adjust(left=0.055, right=0.968, top=0.695, bottom=0.135, wspace=0.20)
fig.savefig(out_path, dpi=220, facecolor=NIGHT)
plt.close(fig)
# ---------------------------------------------------------------------------
# Figure 5: Practical Reasoning Scoreboard (GSM8K + Biggest Gains + Causal Acc)
# ---------------------------------------------------------------------------
def plot_reasoning_scoreboard(runs: list[dict[str, Any]], out_path: Path) -> None:
var_runs = [r for r in runs if r["_mode_tag"] == "inkling2+var"]
if not var_runs:
return
by_model: dict[str, dict[str, dict[str, Any]]] = {}
for r in runs:
by_model.setdefault(r["model_label"], {})[r["_mode_tag"]] = r
fig = plt.figure(figsize=(16.2, 9.4))
fig.patch.set_facecolor(NIGHT)
gs = fig.add_gridspec(2, 2, width_ratios=[1.22, 1.0], left=0.185, right=0.968, top=0.822, bottom=0.120, wspace=0.22, hspace=0.36)
ax_gains = fig.add_subplot(gs[:, 0])
ax_gsm = fig.add_subplot(gs[0, 1])
ax_causal = fig.add_subplot(gs[1, 1])
style_axes(ax_gains)
style_axes(ax_gsm)
style_axes(ax_causal)
# Panel A (Left): Biggest Task-Level Reasoning Leaps (P=1 -> Best Loop P=2..5)
task_pretty = {
"graph_bfs": "Graph BFS",
"pointer_chase": "Pointer Chase",
"mod_register": "Mod-19 Reg",
"perm_track": "Cup-Swap",
}
leaps: list[tuple[float, str, float, float, str, str]] = []
# Include the 4 primary varloop runs + the standout Qwen3-4B 0.74M scalar-gate pointer chase leap!
leap_sources = list(var_runs)
q4_scalar = by_model.get("Qwen3-4B", {}).get("scalar_gate_loop+var")
if q4_scalar:
ps = q4_scalar["post_training"]["serial"]
b_v = ps["P1"]["per_task"]["pointer_chase"]["id"]["acc"] * 100.0
best_v = ps["P5"]["per_task"]["pointer_chase"]["id"]["acc"] * 100.0
leaps.append((best_v - b_v, "Qwen3-4B (0.74M) · Pointer Chase (ID)", b_v, best_v, "P5", SPEC_CYAN))
for r in leap_sources:
col = color_for_run(r["run_name"], r["model_label"])
sm = short_model(r["model_label"])
ps = r["post_training"]["serial"]
g1 = (r["post_training"]["gsm8k_direct"].get("P1") or {}).get("acc")
if g1 is not None:
best_gp, best_gv = "P1", g1 * 100.0
for pt in ("P2", "P3"):
gv = (r["post_training"]["gsm8k_direct"].get(pt) or {}).get("acc")
if gv is not None and gv * 100.0 > best_gv:
best_gp, best_gv = pt, gv * 100.0
if best_gv - g1 * 100.0 >= 5.0:
leaps.append((best_gv - g1 * 100.0, f"{sm} · GSM8K Direct", g1 * 100.0, best_gv, best_gp, col))
for task in ("graph_bfs", "pointer_chase", "mod_register", "perm_track"):
for split, stag in (("id", "ID"), ("ood", "OOD")):
base_v = ps["P1"]["per_task"][task][split]["acc"] * 100.0
best_p, best_v = "P1", base_v
for pt in ("P2", "P3", "P4", "P5"):
if pt not in ps:
continue
v = ps[pt]["per_task"][task][split]["acc"] * 100.0
if v > best_v:
best_p, best_v = pt, v
delta = best_v - base_v
if delta >= 10.0:
leaps.append((delta, f"{sm} · {task_pretty[task]} ({stag})", base_v, best_v, best_p, col))
leaps.sort(key=lambda t: t[0], reverse=False)
if leaps:
y_pos = np.arange(len(leaps))
for idx, (delta, lbl, base_v, best_v, best_p, col) in enumerate(leaps):
ax_gains.plot([base_v, best_v], [idx, idx], color=col, lw=3.2, alpha=0.88, zorder=2)
ax_gains.scatter([base_v], [idx], color=NIGHT_SOFT, edgecolor=col, s=70, lw=2.0, zorder=3, label="Base (P=1)" if idx == 0 else None)
ax_gains.scatter([best_v], [idx], color=col, s=90, edgecolor=NIGHT, lw=0.6, zorder=4, label="Best Loop (P=2..5)" if idx == 0 else None)
ax_gains.text(
best_v + 2.2, idx,
f"+{delta:.0f} pts ({base_v:.0f}% → {best_v:.0f}% @ {best_p})",
va="center", ha="left", color=col, fontproperties=fp("mono_bold", 8.0),
)
ax_gains.set_yticks(y_pos)
ax_gains.set_yticklabels([t[1] for t in leaps], fontproperties=fp("sans_semi", 9.0), color=INK)
ax_gains.set_xlim(-3, 148)
ax_gains.set_xlabel("Exact-Match Accuracy (%)", fontproperties=fp("sans_med", 9.5))
ax_gains.set_title("A. Biggest Task-Level Reasoning Leaps (Frozen Base)", fontproperties=fp("sans_bold", 11.2), loc="left", pad=10)
leg = ax_gains.legend(loc="lower right", prop=fp("mono", 8.2), facecolor=GLASS, edgecolor=LINE_NIGHT, labelcolor=INK)
leg.get_frame().set_linewidth(0.8)
# Panel B (Top Right): No-CoT GSM8K Direct Math Accuracy
models_present = [m for m in MODEL_ORDER if m in by_model]
x = np.arange(len(models_present))
series = [
("Base (P=1)", lambda modes: ((modes.get("inkling2+var") or modes.get("lora_only"))["post_training"]["gsm8k_direct"].get("P1") or {}).get("acc"), "#5e687f"),
("Loop (P=2)", lambda modes: (modes.get("inkling2+var", {}).get("post_training", {}).get("gsm8k_direct", {}).get("P2") or {}).get("acc"), SPEC_CYAN),
("Loop (P=3)", lambda modes: (modes.get("inkling2+var", {}).get("post_training", {}).get("gsm8k_direct", {}).get("P3") or {}).get("acc"), SPEC_BLUE),
("Scalar (0.74M)", lambda modes: (modes.get("scalar_gate_loop+var", {}).get("post_training", {}).get("gsm8k_direct", {}).get("P3") or {}).get("acc"), SPEC_MINT),
("1-Pass LoRA", lambda modes: (modes.get("lora_only", {}).get("post_training", {}).get("gsm8k_direct", {}).get("P1") or {}).get("acc"), SPEC_AMBER),
]
active_series = []
for slbl, fn, scol in series:
vals = [fn(by_model[m]) for m in models_present]
if any(v is not None for v in vals):
active_series.append((slbl, [v * 100.0 if v is not None else np.nan for v in vals], scol))
w = 0.78 / max(1, len(active_series))
for s_idx, (slbl, vals, scol) in enumerate(active_series):
offset = (s_idx - (len(active_series) - 1) / 2.0) * w
labeled = False
for m_idx, v in enumerate(vals):
if np.isnan(v):
continue
ax_gsm.bar(x[m_idx] + offset, v, width=w * 0.90, color=scol, edgecolor=NIGHT, lw=0.6, label=slbl if not labeled else None, zorder=3)
labeled = True
ax_gsm.text(
x[m_idx] + offset, v + 1.4, f"{v:.0f}%",
ha="center", va="bottom", color=INK if v > 0 else INK_DIM, fontproperties=fp("mono_bold", 7.4),
)
ax_gsm.legend(prop=fp("mono", 7.5), ncol=2, loc="upper left", facecolor=GLASS, edgecolor=LINE_NIGHT, labelcolor=INK)
ax_gsm.set_xticks(x)
ax_gsm.set_xticklabels([short_model(m) for m in models_present], fontproperties=fp("sans_semi", 8.8), color=INK)
ax_gsm.set_ylabel("Exact-Match Accuracy (%)", fontproperties=fp("sans_med", 9.3))
ax_gsm.set_ylim(0, 86)
ax_gsm.set_title("B. Direct No-CoT GSM8K Math", fontproperties=fp("sans_bold", 11.0), loc="left", pad=9)
# Panel C (Bottom Right): Causal Proof — ID Accuracy Under Message Shuffling
ab_var = [by_model[m]["inkling2+var"] for m in models_present if "inkling2+var" in by_model[m] and by_model[m]["inkling2+var"].get("causal_ablations")]
if ab_var:
xa = np.arange(len(ab_var))
aconds = [
("P=1 Base", lambda r: r["post_training"]["serial"]["P1"]["overall_id"]["acc"] * 100.0, "#5e687f"),
("P=3 Normal", lambda r: r["post_training"]["serial"]["P3"]["overall_id"]["acc"] * 100.0, SPEC_BLUE),
("P=3 Zero-Msg", lambda r: r["causal_ablations"]["zero"]["overall_id"]["acc"] * 100.0, SPEC_AMBER),
("P=3 Shuf-Tok", lambda r: r["causal_ablations"]["shuffle_tokens"]["overall_id"]["acc"] * 100.0, SPEC_CORAL),
]
wa = 0.78 / len(aconds)
for c_idx, (clbl, fn, ccol) in enumerate(aconds):
offset = (c_idx - (len(aconds) - 1) / 2.0) * wa
vals = [fn(r) for r in ab_var]
ax_causal.bar(xa + offset, vals, width=wa * 0.90, color=ccol, edgecolor=NIGHT, lw=0.6, label=clbl, zorder=3)
for xi, v in zip(xa, vals):
ax_causal.text(xi + offset, v + 1.0, f"{v:.1f}%", ha="center", va="bottom", color=INK if v > 5 else SPEC_CORAL, fontproperties=fp("mono_bold", 7.3))
ax_causal.set_xticks(xa)
ax_causal.set_xticklabels([short_model(r["model_label"]) for r in ab_var], fontproperties=fp("sans_semi", 8.8), color=INK)
ax_causal.set_ylabel("Serial ID Accuracy (%)", fontproperties=fp("sans_med", 9.3))
ax_causal.set_ylim(0, 52)
ax_causal.set_title("C. Causal Proof: Shuffling Messages Breaks Gemma 4", fontproperties=fp("sans_bold", 11.0), loc="left", pad=9)
ax_causal.legend(prop=fp("mono", 7.5), ncol=2, loc="upper right", facecolor=GLASS, edgecolor=LINE_NIGHT, labelcolor=INK)
apply_looski_chrome(
fig,
title="Practical Reasoning Scoreboard: Where Looping Helped vs. Hedged",
subtitle="Zero-forgetting latent recursion across dense, MoE, and hybrid LLMs",
footnote="Note: Qwen3.8-27B emitted leading blank lines on 58/214 base P=1 prompts (0/214 by P=2); its clean P=2→P=3 loop gain is +11.9 pts ID, +20 pts OOD Ptr, +3.1 pts GSM8K.",
header_y=0.968,
line_y=0.892,
)
fig.savefig(out_path, dpi=220, facecolor=NIGHT)
plt.close(fig)
# ---------------------------------------------------------------------------
# Figure 6: Architecture & Training Ablations (0.74M Scalar-Gate Discovery)
# ---------------------------------------------------------------------------
def plot_ablation_discovery(runs: list[dict[str, Any]], out_path: Path) -> None:
q4_runs = [r for r in runs if r["model_label"] == "Qwen3-4B"]
g26_runs = [r for r in runs if r["model_label"] == "Gemma-4-26B-A4B-it"]
if len(q4_runs) < 3:
return
fig, axes = plt.subplots(1, 3, figsize=(17.4, 6.4))
fig.patch.set_facecolor(NIGHT)
for ax in axes:
style_axes(ax)
q4_style = {
"qwen3-4b-scalar-gate-loop": ("Scalar-Gate Loop (0.74M · 0.02%)", SPEC_MINT, "-", "^", 2.9),
"qwen3-4b-inkling2-plus-lora": ("Inkling-2 + LoRA r16 (85.2M)", SPEC_BLUE, "-", "D", 2.2),
"qwen3-4b-inkling2-varloop": ("Inkling-2 varloop (63.2M)", SPEC_PINK, "-", "o", 2.2),
"qwen3-4b-inkling2-fixed3": ("Inkling-2 fixed P=3 (63.2M)", SPEC_CORAL, "--", "s", 1.9),
"qwen3-4b-naive-loop-lora": ("Naive Loop + LoRA (66.1M)", SPEC_VIOLET, "-.", "x", 2.0),
"qwen3-4b-control-1pass-lora": ("1-Pass LoRA Control (66.1M)", SPEC_AMBER, "--", "*", 1.7),
}
# Panel A: Qwen3-4B 6-Way Depth Scaling (ID Accuracy vs P=1..5)
ax = axes[0]
ax.axvspan(3.35, 5.55, color=SPEC_VIOLET, alpha=0.075, zorder=0)
ax.axvline(3.35, color=SPEC_VIOLET, ls=":", lw=1.2, alpha=0.65, zorder=1)
q4_by_name = {r["run_name"]: r for r in q4_runs}
for rname, (lbl, col, ls, mk, lw) in q4_style.items():
r = q4_by_name.get(rname)
if not r:
continue
ps = r["post_training"]["serial"]
if r["train_args"]["mode"] == "lora_only":
val = ps["P1"]["overall_id"]["acc"] * 100.0
ax.axhline(val, color=col, ls=ls, lw=lw, alpha=0.78, label=f"{lbl}: {val:.1f}%", zorder=2)
else:
xs, ys = [], []
for p in (1, 2, 3, 4, 5):
tag = f"P{p}"
if tag in ps:
xs.append(p)
ys.append(ps[tag]["overall_id"]["acc"] * 100.0)
ax.plot(xs, ys, color=col, ls=ls, marker=mk, lw=lw, ms=6.8, markeredgecolor=NIGHT, markeredgewidth=0.6, label=lbl, zorder=4 if "scalar" in rname else 3)
if rname in ("qwen3-4b-scalar-gate-loop", "qwen3-4b-inkling2-varloop", "qwen3-4b-inkling2-plus-lora", "qwen3-4b-naive-loop-lora"):
y_off = 0.0
if rname == "qwen3-4b-naive-loop-lora":
y_off = 1.2
elif rname == "qwen3-4b-inkling2-plus-lora":
y_off = -1.2
ax.text(xs[-1] + 0.09, ys[-1] + y_off, f"{ys[-1]:.1f}%", va="center", ha="left", color=col, fontproperties=fp("mono_bold", 8.0))
ax.set_xticks([1, 2, 3, 4, 5])
ax.set_xticklabels(["P=1\nBase", "P=2", "P=3", "P=4\nExtrap", "P=5\nExtrap"], fontproperties=fp("mono", 8.2))
ax.set_xlim(0.8, 5.62)
ax.set_ylim(0, 72)
ax.set_ylabel("In-Distribution Exact-Match (%)", fontproperties=fp("sans_med", 9.3))
ax.set_title("A. Qwen3-4B 6-Way Ablation vs. Depth", fontproperties=fp("sans_bold", 11.0), loc="left", pad=9)
ax.legend(prop=fp("mono", 7.1), loc="upper left", facecolor=GLASS, edgecolor=LINE_NIGHT, labelcolor=INK)
# Panel B: Qwen3-4B Multi-Metric Comparison
ax = axes[1]
order_b = [
("qwen3-4b-inkling2-varloop", "Rank-64\nvarloop\n63.2M"),
("qwen3-4b-inkling2-fixed3", "Rank-64\nfixed3\n63.2M"),
("qwen3-4b-inkling2-plus-lora", "Rank-64\n+LoRA\n85.2M"),
("qwen3-4b-naive-loop-lora", "Naive\nLoop\n66.1M"),
("qwen3-4b-scalar-gate-loop", "Scalar\nGate\n0.74M"),
("qwen3-4b-control-1pass-lora", "1-Pass\nLoRA\n66.1M"),
]
present_b = [(q4_by_name[k], lbl) for k, lbl in order_b if k in q4_by_name]
xb = np.arange(len(present_b))
wb = 0.25
id_vals, ood_vals, gsm_vals = [], [], []
for r, _ in present_b:
ps = r["post_training"]["serial"]
if r["train_args"]["mode"] == "lora_only":
id_vals.append(ps["P1"]["overall_id"]["acc"] * 100.0)
ood_vals.append(ps["P1"]["overall_ood"]["acc"] * 100.0)
gsm_vals.append((r["post_training"]["gsm8k_direct"].get("P1") or {}).get("acc", 0.0) * 100.0)
else:
p_tags = [t for t in ("P2", "P3", "P4", "P5") if t in ps]
best_p = max(p_tags, key=lambda t: ps[t]["overall_id"]["acc"])
id_vals.append(ps[best_p]["overall_id"]["acc"] * 100.0)
ood_vals.append(max(ps[t]["overall_ood"]["acc"] for t in p_tags) * 100.0)
g_tags = [t for t in ("P2", "P3") if t in r["post_training"]["gsm8k_direct"]]
gsm_vals.append(max(r["post_training"]["gsm8k_direct"][t]["acc"] for t in g_tags) * 100.0 if g_tags else 0.0)
# Subtle glow box behind the winning Scalar Gate column!
for i_b, (r_b, _) in enumerate(present_b):
if r_b["run_name"] == "qwen3-4b-scalar-gate-loop":
ax.axvspan(i_b - 0.44, i_b + 0.44, color=SPEC_MINT, alpha=0.09, zorder=0)
for offset, vals, clbl, col in [
(-wb, id_vals, "Best ID Acc", SPEC_BLUE),
(0.0, ood_vals, "Best OOD Acc", SPEC_MINT),
(wb, gsm_vals, "GSM8K Direct", SPEC_AMBER),
]:
bars = ax.bar(xb + offset, vals, width=wb * 0.90, color=col, edgecolor=NIGHT, lw=0.6, label=clbl, zorder=3)
for b, v in zip(bars, vals):
ax.text(b.get_x() + b.get_width() / 2, v + 0.9, f"{v:.0f}%", ha="center", va="bottom", color=INK, fontproperties=fp("mono_bold", 7.2))
ax.set_xticks(xb)
ax.set_xticklabels([lbl for _, lbl in present_b], fontproperties=fp("mono", 7.5), color=INK_MUTED)
ax.set_ylabel("Exact-Match Accuracy (%)", fontproperties=fp("sans_med", 9.3))
ax.set_ylim(0, 62)
ax.set_title("B. 0.74M Scalar Gate Beats 63.2M Rank-64", fontproperties=fp("sans_bold", 11.0), loc="left", pad=9)
ax.legend(prop=fp("mono", 7.6), loc="upper left", facecolor=GLASS, edgecolor=LINE_NIGHT, labelcolor=INK)
# Panel C: Gemma-4-26B-A4B-it 3-Way Retrofit Comparison
ax = axes[2]
g26_by_name = {r["run_name"]: r for r in g26_runs}
conds_c = []
if "gemma4-26b-a4b-inkling2-varloop" in g26_by_name:
r = g26_by_name["gemma4-26b-a4b-inkling2-varloop"]
conds_c.append(("Base\nP=1", r["post_training"]["serial"]["P1"]["overall_id"]["acc"] * 100.0,
r["post_training"]["serial"]["P1"]["overall_ood"]["acc"] * 100.0,
r["post_training"]["gsm8k_direct"]["P1"]["acc"] * 100.0))
conds_c.append(("Loop\nP=3\n52.1M", r["post_training"]["serial"]["P3"]["overall_id"]["acc"] * 100.0,
r["post_training"]["serial"]["P5"]["overall_ood"]["acc"] * 100.0,
r["post_training"]["gsm8k_direct"]["P3"]["acc"] * 100.0))
if "gemma4-26b-a4b-inkling2-plus-lora" in g26_by_name:
r = g26_by_name["gemma4-26b-a4b-inkling2-plus-lora"]
conds_c.append(("Loop+LoRA\nP=1\n63.3M", r["post_training"]["serial"]["P1"]["overall_id"]["acc"] * 100.0,
r["post_training"]["serial"]["P1"]["overall_ood"]["acc"] * 100.0,
r["post_training"]["gsm8k_direct"]["P1"]["acc"] * 100.0))
conds_c.append(("Loop+LoRA\nP=3/4\n63.3M", r["post_training"]["serial"]["P4"]["overall_id"]["acc"] * 100.0,
r["post_training"]["serial"]["P3"]["overall_ood"]["acc"] * 100.0,
r["post_training"]["gsm8k_direct"]["P3"]["acc"] * 100.0))
if "gemma4-26b-a4b-control-1pass-lora" in g26_by_name:
r = g26_by_name["gemma4-26b-a4b-control-1pass-lora"]
conds_c.append(("1-Pass\nLoRA\n44.6M", r["post_training"]["serial"]["P1"]["overall_id"]["acc"] * 100.0,
r["post_training"]["serial"]["P1"]["overall_ood"]["acc"] * 100.0,
r["post_training"]["gsm8k_direct"]["P1"]["acc"] * 100.0))
if conds_c:
xc = np.arange(len(conds_c))
wc = 0.25
for offset, idx_v, clbl, col in [
(-wc, 1, "ID Acc", SPEC_BLUE),
(0.0, 2, "OOD Acc", SPEC_MINT),
(wc, 3, "GSM8K Direct", SPEC_AMBER),
]:
vals = [c[idx_v] for c in conds_c]
bars = ax.bar(xc + offset, vals, width=wc * 0.90, color=col, edgecolor=NIGHT, lw=0.6, label=clbl, zorder=3)
for b, v in zip(bars, vals):
ax.text(b.get_x() + b.get_width() / 2, v + 1.0, f"{v:.0f}%", ha="center", va="bottom", color=INK if v > 0 else INK_DIM, fontproperties=fp("mono_bold", 7.2))
ax.set_xticks(xc)
ax.set_xticklabels([c[0] for c in conds_c], fontproperties=fp("mono", 7.5), color=INK_MUTED)
ax.set_ylabel("Exact-Match Accuracy (%)", fontproperties=fp("sans_med", 9.3))
ax.set_ylim(0, 74)
ax.set_title("C. G4-26B MoE: Joint Loop+LoRA Interaction", fontproperties=fp("sans_bold", 11.0), loc="left", pad=9)
ax.legend(prop=fp("mono", 7.6), loc="upper left", facecolor=GLASS, edgecolor=LINE_NIGHT, labelcolor=INK)
apply_looski_chrome(
fig,
title="Architecture & Training Ablations: The 2.9 MB Scalar-Gate Discovery",
subtitle="85× fewer parameters · 2× higher looped accuracy · Zero numeric mode-hedging",
header_y=0.958,
line_y=0.858,
)
fig.subplots_adjust(left=0.052, right=0.968, top=0.775, bottom=0.145, wspace=0.22)
fig.savefig(out_path, dpi=220, facecolor=NIGHT)
plt.close(fig)
def main():
ap = argparse.ArgumentParser()
ap.add_argument("results_dir", type=Path)
ap.add_argument("--out", type=Path, required=True)
ap.add_argument("--fonts-dir", type=Path, default=None)
args = ap.parse_args()
args.out.mkdir(parents=True, exist_ok=True)
init_looski_theme(args.fonts_dir)
runs = load_completed_runs(args.results_dir)
logs = load_train_logs(args.results_dir)
print(f"Loaded {len(runs)} completed runs and {len(logs)} training logs.")
plot_depth_scaling(runs, args.out / "fig1_depth_scaling.png")
plot_per_task_breakdown(runs, args.out / "fig2_per_task_breakdown.png")
plot_causal_and_mechanistic(runs, args.out / "fig3_causal_and_mechanistic.png")
plot_training_curves(logs, args.out / "fig4_training_curves.png")
plot_reasoning_scoreboard(runs, args.out / "fig5_reasoning_scoreboard.png")
plot_ablation_discovery(runs, args.out / "fig6_ablation_discovery.png")
print(f"Saved 6 Looski Spectral Silicon figures to {args.out}")
if __name__ == "__main__":
main()
#!/usr/bin/env python3
"""Generate Looski 'Spectral Silicon' publication figures for Inkling-2 loop experiments.
Implements the official Looski visual system (docs/STYLE_GUIDE.md & brand-mark.ts):
- Dark canvas (--night #07080c), raised surface (--night-soft #0b0f18)
- Official spectral palette (--spec-blue #75b4ff, --spec-mint #9ee5ce,
--spec-amber #f8d67b, --spec-pink #f3a7c7, --spec-violet #be9de6)
- 9-stop --sv-spectrum gradient hairline & clockwise 8-split geometric brand mark
- Space Grotesk headings + JetBrains Mono data/eyebrows
Run with:
uv run --with matplotlib --with numpy python3 plot_results.py results/ --out figures/
"""
from __future__ import annotations
import argparse
import json
from pathlib import Path
from typing import Any
import matplotlib
matplotlib.use("Agg")
import matplotlib.colors as mcolors
from matplotlib.collections import LineCollection
from matplotlib.font_manager import FontProperties, fontManager
import matplotlib.pyplot as plt
import numpy as np
# ---------------------------------------------------------------------------
# Official Looski 'Spectral Silicon' Tokens
# ---------------------------------------------------------------------------
NIGHT = "#07080c"
NIGHT_SOFT = "#0b0f18"
GLASS = "#121724"
GLASS_HI = "#171e2e"
LINE_NIGHT = "#1e2638"
GRID_NIGHT = "#171d2c"
INK = "#e9edf6"
INK_MUTED = "#97a2b8"
INK_DIM = "#69748c"
SPEC_BLUE = "#75b4ff"
SPEC_MINT = "#9ee5ce"
SPEC_AMBER = "#f8d67b"
SPEC_PINK = "#f3a7c7"
SPEC_VIOLET = "#be9de6"
SPEC_CORAL = "#f28b60"
SPEC_CYAN = "#32cbd1"
FUNC_BLUE = "#3578ef"
SPECTRUM_STOPS = [
"#3578ef",
"#32cbd1",
"#83d9b2",
"#bed965",
"#efc254",
"#f28b60",
"#e96399",
"#c476da",
"#8a78ed",
]
SPECTRUM_CMAP = mcolors.LinearSegmentedColormap.from_list("looski_spectrum", SPECTRUM_STOPS)
HEATMAP_CMAP = mcolors.LinearSegmentedColormap.from_list(
"looski_heat",
["#0d1220", "#162544", "#21447a", "#3578ef", "#32cbd1", "#83d9b2", "#f8d67b"],
)
# Model family color mapping in official spectrum order (Blue, Amber, Mint, Pink)
PALETTE = {
"Gemma-4-31B-it": SPEC_BLUE,
"Gemma-4-26B-A4B-it": SPEC_AMBER,
"Qwen3.8-27B": SPEC_MINT,
"Qwen3-4B": SPEC_PINK,
}
MODEL_ORDER = [
"Gemma-4-26B-A4B-it",
"Gemma-4-31B-it",
"Qwen3.8-27B",
"Qwen3-4B",
]
MODE_STYLES = {
"inkling2+var": {"ls": "-", "marker": "o", "lw": 2.6},
"inkling2": {"ls": "--", "marker": "s", "lw": 1.9},
"inkling2+var+lora": {"ls": "-", "marker": "D", "lw": 2.3},
"scalar_gate_loop+var": {"ls": ":", "marker": "^", "lw": 2.4},
"naive_loop": {"ls": "-.", "marker": "x", "lw": 2.0},
"naive_loop+lora": {"ls": "-.", "marker": "x", "lw": 2.0},
"lora_only": {"ls": "--", "marker": "*", "lw": 1.8},
}
# ---------------------------------------------------------------------------
# Font Registration (Space Grotesk + JetBrains Mono + Instrument Serif)
# ---------------------------------------------------------------------------
FONT_PROPS: dict[str, FontProperties] = {}