Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions .github/workflows/bpd-rlt-exit-transfer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: RLT exit frozen difficulty-transfer evaluation

on:
push:
branches:
- research/rlt-exit-difficulty-transfer-20261121
paths:
- "mechinterp/bpd/experiments/inkling_reader_v0/exit_difficulty_transfer.py"
- "mechinterp/bpd/experiments/inkling_reader_v0/test_exit_difficulty_transfer.py"
- ".github/workflows/bpd-rlt-exit-transfer.yml"
pull_request:
paths:
- "mechinterp/bpd/experiments/inkling_reader_v0/exit_difficulty_transfer.py"
- "mechinterp/bpd/experiments/inkling_reader_v0/test_exit_difficulty_transfer.py"
- ".github/workflows/bpd-rlt-exit-transfer.yml"
workflow_dispatch:

permissions:
contents: read
actions: read

concurrency:
group: rlt-exit-frozen-transfer-${{ github.ref }}
cancel-in-progress: true

jobs:
frozen-transfer:
runs-on: ubuntu-latest
timeout-minutes: 20
env:
HF_HUB_DISABLE_TELEMETRY: "1"
HF_HUB_DISABLE_XET: "1"
OMP_NUM_THREADS: "2"
OPENBLAS_NUM_THREADS: "1"
MKL_NUM_THREADS: "2"
PYTHONDONTWRITEBYTECODE: "1"
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install bounded CPU inference runtime
run: |
python -m pip install "torch==2.5.1+cpu" --index-url https://download.pytorch.org/whl/cpu
python -m pip install "numpy>=1.24,<3" "huggingface_hub>=0.24,<1"
- name: Run unique Sudoku and frozen evaluation smoke tests
run: python -m unittest mechinterp.bpd.experiments.inkling_reader_v0.test_exit_difficulty_transfer -v
- name: Download immutable first learned-controller experiment
uses: actions/download-artifact@v4
with:
name: bpd-rlt-learned-exit-first-dev
path: runs/frozen_train
run-id: 44911864342
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Evaluate frozen controller on 40 and 52 blank new roots
if: github.event_name == 'push'
run: |
timeout --signal=TERM --kill-after=15s 850s \
python -m mechinterp.bpd.experiments.inkling_reader_v0.exit_difficulty_transfer \
--source runs/frozen_train --model gaoxin492 \
--roots-per-panel 24 --out runs/rlt_exit_difficulty_transfer
- name: Retain paired difficulty shift receipts
if: always()
uses: actions/upload-artifact@v4
with:
name: bpd-rlt-frozen-difficulty-transfer
path: runs/rlt_exit_difficulty_transfer/
if-no-files-found: warn
retention-days: 14
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# RLT-EXIT-03: frozen learned controller under Sudoku difficulty shift

2026-11-21. **Development-only native pretrained evaluation.**
Original CI [44913713826](https://github.com/MoralityLabAI/BPD/actions/runs/44913713826) succeeded,
including unit tests, checkpoint custody checks and two actual native model sweeps.
Its artifact [bpd-rlt-frozen-difficulty-transfer](https://github.com/MoralityLabAI/BPD/actions/runs/44913713826)
contains all 48 independently generated source worlds and per-policy receipts.

## Frozen policy and separate roots

The controller was fitted and calibrated in merged BPD PR #140 exclusively on
50-blank Sudoku tasks. This study loads the exact prior report whose SHA-256 is
dda473da08434484f4d67e8f0e6fa77b4296d9fa1489a810f529c699dc94a7e1,
including logistic weights, feature mean/scales, and stop threshold
0.5656608144205763. The pretrained gaoxin492/TRM checkpoint SHA-256 is
932b5e0df4e90021c21a064d4e716154086c46fda7afa676ea294484a30e38c3.

No training, threshold fitting or posterior selection took place on the new
cohorts. Roots were generated with disjoint source seed families:
40 blanks starts 20261311; 52 blanks starts 20261312. Both advance by 101
per independently generated Sudoku. Each puzzle has a unique verified
solution and source hashes are disjoint from all original TRAIN, CAL and
DEVELOPMENT roots. No sealed confirmation roots were used.

## Results

| Difficulty | Policy | Exact solves | Outer steps | Native CPU seconds | Incorrect early exits |
| --- | --- | ---: | ---: | ---: | ---: |
| 40 blanks | Fixed 1 | 24/24 | 24 | N/A (offline first-visit diagnostic) | 0 |
| 40 blanks | Fixed 2 | 24/24 | 48 | 11.540951 | 0 |
| 40 blanks | Exact verifier exit | 24/24 | 24 | 5.813416 | 0 |
| 40 blanks | Learned, original threshold | 24/24 | 24 | 5.790907 | 0 |
| 40 blanks | Matched random (CAL stop rate) | 24/24 | 39 | 9.449739 | 0 |
| 52 blanks | Fixed 1 | 8/24 | 24 | N/A (offline first-visit diagnostic) | 16 |
| 52 blanks | Fixed 2 | 22/24 | 48 | 11.637567 | 0 |
| 52 blanks | Exact verifier exit | 22/24 | 40 | 9.647101 | 0 |
| 52 blanks | Learned, original threshold | 21/24 | 41 | 9.866530 | **1** |
| 52 blanks | Matched random (CAL stop rate) | 17/24 | 39 | 9.428214 | 6 |

At 40 blanks all 24 puzzles were already solved at the first recurrent
step, so the model's learned threshold stopped perfectly and used half
of the fixed two-step budget. This easy shift has a performance ceiling.

At 52 blanks, a single incorrect learned first-step exit cost an
otherwise recovered second-step solution. The remaining cases yielded
21/24 valid solutions, seven steps fewer than fixed-depth, and
about 15.2% less measured native forward time.
A threshold chosen to make zero false stops on 48 CAL roots at the
50-blank source distribution did NOT provide the same property after
difficulty shift. This is a negative stress finding that should
remain visible in later comparisons and controller training.

The random gate's CAL stop rate is 22/48. It uses a deterministic
per-root pseudo-random decision and may consume fewer steps than
the learned gate in a particular cohort. The control is
rate-matched in expectation, not guaranteed to spend the exact same
number of recurrent visits.

The fixed-one diagnostic comes from the first visit of an independent
full-depth model rollout. It does not provide a separate timing estimate.
CPU wall-time variation across separate model invocations limits
precise relative runtime comparisons; visit counts are exact.

## Next registered experiment

An applicability guard may restrict learned stopping to tasks whose
public difficulty metadata falls within a previously designated
safe support set, allowing an otherwise fixed-depth fallback.
One natural monotone guard is to enable learned stopping for at most
50 Sudoku blanks while requiring two steps for harder boards.
This is a **posthoc idea prompted by the observed failure**.
Its evaluation must use fresh, previously untouched development
seeds, with the rule frozen before the run. The already opened
52-blank cohort is excluded from rule assessment and cannot be
called a confirmation sample.

Lean proof and MCP tool calls require distinct independent
verifiers and observable state features; transfer across those task
families remains untested. The observed Sudoku result validates
a bounded native-model difficulty stress test only.
Original file line number Diff line number Diff line change
@@ -0,0 +1,244 @@
"""Frozen learned-exit transfer to different Sudoku clue regimes on actual pretrained TRM.

Only the upstream TRAIN/CAL controller weights and threshold are used. This
development experiment independently rechecks original model source custody
and runs new, disjoint uniquely solvable puzzles at two difficulty levels.
"""

from __future__ import annotations

import argparse
import hashlib
import json
import math
import time
from pathlib import Path
from typing import Any

import torch

from mechinterp.bpd.adapters.trm import build_mini_trm, load_pretrained_trm
from mechinterp.bpd.experiments.inkling_reader_v0.learned_exit_controller import (
_row, evaluate,
)
from mechinterp.bpd.experiments.inkling_reader_v0.native_trm_exit import native_rollout
from mechinterp.bpd.experiments.inkling_reader_v0.native_trm_pilot import (
_permute_sudoku, verify_sudoku,
)
from mechinterp.loopscope02.scripts.trm_sudoku import TRM_CHECKPOINTS

BASELINE_REPORT_SHA256 = "dda473da08434484f4d67e8f0e6fa77b4296d9fa1489a810f529c699dc94a7e1"
MODEL_SHA256 = "932b5e0df4e90021c21a064d4e716154086c46fda7afa676ea294484a30e38c3"
SCHEMA = "bpd.trm_exit_difficulty_transfer.v1"
COHORTS = ((40, 20261311), (52, 20261312))


def sha(path: Path) -> str:
return hashlib.sha256(path.read_bytes()).hexdigest()


def load_frozen(source: Path) -> tuple[dict[str, Any], set[str]]:
report = source / "report.json"
if sha(report) != BASELINE_REPORT_SHA256:
raise ValueError("learned controller source report does not match pinned artifact")
obj = json.loads(report.read_text(encoding="utf-8"))
if (
obj.get("schema_version") != "bpd.trm_learned_exit.v1"
or obj.get("model_sha256") != MODEL_SHA256
or obj.get("evidence_class") != "native_pretrained_development_learned_exit"
or obj.get("holes") != 50
or obj.get("feature_names") != obj.get("training", {}).get("features")
or obj.get("calibration", {}).get("false_stops") != 0
):
raise ValueError("invalid original checkpoint/controller evidence")
prior = set()
for split in ("train", "calibration", "development"):
path = source / f"{split}.jsonl"
if sha(path) != obj["data_sha256"][path.name]:
raise ValueError(f"frozen {split} corpus digest changed")
for line in path.read_text(encoding="utf-8").splitlines():
row = json.loads(line)
if row.get("split") != split or row.get("model_sha256") != MODEL_SHA256:
raise ValueError("bad source split/model identity")
digest = row.get("task_digest")
if not isinstance(digest, str) or digest in prior:
raise ValueError("duplicate source task across original splits")
prior.add(digest)
expected = sum(obj["root_counts"].values())
if len(prior) != expected:
raise ValueError("source root census changed")
return obj, prior


def generate_verified_rows(
model: torch.nn.Module, *, sha256: str, holes: int, seed: int, roots: int,
prohibited: set[str],
) -> list[dict[str, Any]]:
if type(roots) is not int or not 2 <= roots <= 48:
raise ValueError("root count must lie in 2..48")
if holes not in (40, 52):
raise ValueError("difficulty transfer accepts only predeclared 40/52 blank panels")
seen = set()
rows = []
for index in range(roots):
q, target = _permute_sudoku(seed + 101 * index, holes=holes)
if not verify_sudoku(q, target):
raise ValueError("generated Sudoku solution invalid")
observed, _ = native_rollout(model, q, max_outer_steps=2, stop_when_verified=False)
if any(s["sudoku_checker_passed"] != (s["candidate"] == target) for s in observed):
raise ValueError("solver target and exact Sudoku checker disagreed")
row = _row("development", index, q, observed, sha256)
if row["task_digest"] in seen or row["task_digest"] in prohibited:
raise ValueError("repeated source world across difficulty or fit splits")
seen.add(row["task_digest"])
row["root_id"] = f"transfer-h{holes}-s{seed + 101 * index}"
row["difficulty_holes"] = holes
row["split"] = "development"
row["training_eligible"] = False
rows.append(row)
return rows


def _add_fixed_one(rows: list[dict[str, Any]], result: dict[str, Any]) -> None:
"""First-visit baseline is computed from the separately checked fixed trace."""
correct = sum(row["first_pass_verified"] for row in rows)
result["scores"]["fixed1"] = {
"solved": correct, "total": len(rows),
"total_outer_steps": len(rows), "stopped_after_first": len(rows),
"incorrect_early_exits": len(rows) - correct,
"native_seconds": None, "checker_seconds": None,
"source": "same checkpoint frozen first-visit predictions; no additional model calls",
}


def run_transfer(
model: torch.nn.Module, original: dict[str, Any], prohibited: set[str],
*, roots_per_panel: int = 24, cohorts: tuple[tuple[int, int], ...] = COHORTS,
) -> tuple[dict[str, Any], dict[int, list[dict[str, Any]]]]:
if not cohorts or len({holes for holes, _ in cohorts}) != len(cohorts):
raise ValueError("distinct declared transfer difficulties required")
if original.get("model_sha256") != MODEL_SHA256:
raise ValueError("model checkpoint changed")
if original["calibration"]["threshold"] <= 0 or original["calibration"]["threshold"] > 1.1:
raise ValueError("frozen stop threshold invalid")
model.eval()
blocked = set(prohibited)
outputs: dict[int, list[dict[str, Any]]] = {}
receipts = []
begin = time.monotonic()
for holes, seed in cohorts:
rows = generate_verified_rows(
model, sha256=MODEL_SHA256, holes=holes, seed=seed,
roots=roots_per_panel, prohibited=blocked,
)
blocked.update(r["task_digest"] for r in rows)
results, evaluated = evaluate(
model, rows, original["training"], original["calibration"],
)
if len(evaluated) != len(rows):
raise ValueError("incomplete policy comparison")
_add_fixed_one(rows, results)
outputs[holes] = [
{
"schema_version": "bpd.trm_exit_transfer_case.v1",
"source_split": "development",
"training_eligible": False,
"root_id": row["root_id"],
"task_digest": row["task_digest"],
"question": row["question"],
"holes": holes, "seed": seed,
"first_pass_valid": row["first_pass_verified"],
"second_pass_valid": row["second_pass_verified"],
"first_pass_candidate": row["first_candidate"],
"second_pass_candidate": row["second_candidate"],
"frozen_controller_score": evaluated[i]["learned_score"],
"policies": evaluated[i]["policies"],
}
for i, row in enumerate(rows)
]
receipts.append({
"holes": holes, "seed": seed, "roots": len(rows),
"results": results,
"source_digest": hashlib.sha256(
json.dumps([(r["root_id"], r["task_digest"]) for r in rows],
sort_keys=True, separators=(",", ":")).encode()
).hexdigest(),
})
return {
"schema_version": SCHEMA,
"evidence_class": "pretrained_native_out_of_difficulty_development",
"checkpoint_sha256": MODEL_SHA256,
"frozen_training_report_sha256": BASELINE_REPORT_SHA256,
"source_training_roots_excluded": len(prohibited),
"calibration_threshold_frozen": original["calibration"]["threshold"],
"calibration_stop_rate_frozen": original["calibration"]["random_stop_probability"],
"model_observation": "first_pass_digit_logits_only",
"evaluation_uses_first_pass_verifier_result": False,
"source_roots_per_panel": roots_per_panel,
"cohorts": receipts,
"total_wall_seconds": round(time.monotonic() - begin, 4),
"claim_boundary": (
"Two development-only Sudoku difficulty shifts with frozen single-model "
"weights and an already calibrated stop classifier. No online retraining, "
"threshold tuning, Lean/MCP generalization or Inkling routing was performed."
),
}, outputs


def main() -> int:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--source", type=Path, required=True)
parser.add_argument("--out", type=Path, required=True)
parser.add_argument("--model", choices=("gaoxin492", "mini"), default="gaoxin492")
parser.add_argument("--roots-per-panel", type=int, default=24)
args = parser.parse_args()
if args.out.exists():
parser.error("output must be a fresh directory")
torch.set_num_threads(2)
original, protected = load_frozen(args.source)
if args.model == "gaoxin492":
model = load_pretrained_trm("gaoxin492", dtype=torch.float32, verify_sha256=True)
if TRM_CHECKPOINTS["gaoxin492"]["sha256"] != MODEL_SHA256:
raise ValueError("pretrained model SHA changed")
else:
model = build_mini_trm(
hidden_size=32, num_heads=4, l_layers=1, h_cycles=2,
l_cycles=1, puzzle_emb_len=4, seq_len=81, seed=43,
)
report, rows = run_transfer(
model, original, protected, roots_per_panel=args.roots_per_panel,
)
if args.model == "mini":
report["evidence_class"] = "untrained_mini_plumbing_smoke"
report["checkpoint_sha256"] = "untrained_mini_seed_43"
args.out.mkdir(parents=True)
files = {}
for holes, examples in rows.items():
path = args.out / f"transfer_h{holes}.jsonl"
with path.open("x", encoding="utf-8", newline="\n") as handle:
for row in examples:
handle.write(json.dumps(row, sort_keys=True, separators=(",", ":"), allow_nan=False) + "\n")
files[path.name] = sha(path)
report["files_sha256"] = files
report["source_sha256"] = sha(Path(__file__))
(args.out / "report.json").write_text(
json.dumps(report, sort_keys=True, indent=2, allow_nan=False) + "\n",
encoding="utf-8",
)
print(json.dumps({
"out": str(args.out),
"cohorts": [
{
"holes": c["holes"],
"roots": c["roots"],
"fixed2": c["results"]["scores"]["fixed2"],
"learned": c["results"]["scores"]["learned"],
"random_matched": c["results"]["scores"]["random_matched"],
} for c in report["cohorts"]
],
}, sort_keys=True, allow_nan=False))
return 0


if __name__ == "__main__":
raise SystemExit(main())
Loading
Loading