Files
evil_MoE/src/vgrout/figs.py
T
wassname 7e11c024c4 cleanup: delete dead delta_S machinery (PiSSA->lora2r leftovers)
Off the live lora2r path; removed with vhack.py (commit 4120d75):
- proj.py: drop project_delta_S_grad/_project_one_module/mean_cos_pre_from_grads/
  _hackward_cos (no live importer; train.py uses only per_token_logps).
- verify_science_invariants: test pairset_sha256's content gate directly (drops the
  load_v_hack vehicle + fake delta_S wrapper fixture).
- extract_vhack_grad: import pairset_sha256 from .pairs (was re-exported via vhack).
- tablelog/figs: stale 'delta_S grads'/'knob' comments -> A/B grads.
Smoke + verify_science_invariants green; no delta_S left in live code.

Co-Authored-By: Claudypoo <288921227+claudypoo@users.noreply.github.com>
2026-06-10 11:45:54 +00:00

59 lines
2.4 KiB
Python

"""Stable `docs/figs/<name>.png` -> latest generated figure under `out/`.
Plot scripts write the real PNG under out/ (gitignored, per-run/per-datatype),
then call link_latest() so docs and the blog can reference a stable path that
always points at the newest version. The symlink is relative so the repo stays
relocatable.
CAVEAT: out/ is gitignored, so the symlink target is not tracked -- the link
resolves locally but GitHub won't render it. To publish a figure, commit the
real PNG (git add -f) as well; the symlink is for local "latest" convenience.
"""
from __future__ import annotations
import os
from pathlib import Path
FIGS_DIR = Path("docs/figs")
# Reader-facing arm names. Code/log tags carry our internal vocabulary
# (routeV = the current routing arm); plots must
# not. Map every internal tag to the word a paper reader sees. Anything missing
# falls through to its raw tag, so a new arm shows up loud rather than silently
# mislabelled.
ARM_DISPLAY = {
# routeV is the current banded-gate arm; routing2/route2 are the old binary-tau runs
# (kept so historical run artifacts still plot -- see rename, 2026-06-06).
"routingV": "route", "routeV": "route", "routingV_per_token": "route per-token",
"routing2": "route", "route2": "route",
"routing2_grad": "route", "routing2_act": "route (act)",
"projected": "erase", "route": "route", "erase": "erase", "vanilla": "vanilla",
}
def arm_label(tag: str) -> str:
return ARM_DISPLAY.get(tag, tag)
def save_fig(fig, png_path: Path, formats=("png", "svg", "pdf")) -> Path:
"""Save one figure to every format (vector .svg/.pdf for the paper, .png for
the blog/preview) and return the .png path. matplotlib picks the writer from
the suffix, so we just swap it. bbox_inches='tight' so titleless figures
don't leave a margin where the suptitle used to be."""
png_path = Path(png_path)
png_path.parent.mkdir(parents=True, exist_ok=True)
for ext in formats:
fig.savefig(png_path.with_suffix(f".{ext}"), dpi=150, bbox_inches="tight")
return png_path
def link_latest(out_path: Path) -> Path:
"""Point docs/figs/<out_path.name> at out_path (relative symlink). Returns the link."""
FIGS_DIR.mkdir(parents=True, exist_ok=True)
link = FIGS_DIR / out_path.name
target = os.path.relpath(out_path.resolve(), FIGS_DIR.resolve())
if link.is_symlink() or link.exists():
link.unlink()
link.symlink_to(target)
return link