1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
#!/usr/bin/env python3
"""Audit and gate normalized response-mirror causal capture."""
import argparse
import glob
import json
import math
import os
SPLIT_HASH = "8328b206a97c420e49e54e3eca4abe3274c4756b084355784ea3fb8059e4515b"
RATES = (0.03, 0.1, 0.3)
def load(path):
with open(path) as handle:
record = json.load(handle)
args = record["args"]
mode = args.get("mode")
if mode not in ("hfa", "wm"):
raise ValueError(f"{path}: unexpected method")
expected = {
"depth": 20, "width": 16, "seed": 0, "loader_seed": 0,
"epochs": 0, "train_limit": 10000, "val_examples": 5000,
"split_seed": 2027, "eval_split": "validation", "eval_every": 0,
"normalization": "batchnorm", "a_scale": 1.0,
"alignment_probe": 64, "mirror_batch_size": 1,
"mirror_noise_std": 1.0, "mirror_seed": 3000,
}
for key, value in expected.items():
if args.get(key) != value:
raise ValueError(f"{path}: {key} drift")
expected_steps = 0 if mode == "hfa" else 20
if args.get("mirror_warmup_steps") != expected_steps:
raise ValueError(f"{path}: mirror warmup drift")
if mode == "wm" and float(args["mirror_eta"]) not in RATES:
raise ValueError(f"{path}: unregistered mirror rate")
if record["provenance"]["git_tracked_dirty"]:
raise ValueError(f"tracked-dirty result: {path}")
if record["split"]["validation_index_sha256"] != SPLIT_HASH:
raise ValueError(f"split drift: {path}")
if record["evaluation_protocol"]["test_evaluations"]:
raise ValueError(f"test touched: {path}")
expected_space = None if mode == "hfa" else "local_parent_child_response"
if record.get("calibration_metric_space") != expected_space:
raise ValueError(f"metric-space drift: {path}")
diagnostics = record["diagnostics"]
values = diagnostics["teaching_negative_gradient_cosine"]
early_count = max(1, len(values) // 3)
norm_ratios = diagnostics["feedback_forward_norm_ratio"]
feedback_cosines = diagnostics["feedback_forward_cosine"]
metrics = {
"early_third_alignment": sum(values[:early_count]) / early_count,
"all_layer_alignment": sum(values) / len(values),
"mean_feedback_forward_cosine": (
sum(feedback_cosines) / len(feedback_cosines)),
"min_feedback_forward_norm_ratio": min(norm_ratios),
"max_feedback_forward_norm_ratio": max(norm_ratios),
}
if mode == "wm":
warmup = record.get("mirror_warmup", {}).get("mean")
if warmup is None:
raise ValueError(f"missing mirror aggregate: {path}")
metrics.update({
"mean_mirror_update_rms": warmup["mirror_update_rms"],
"mean_mirror_estimate_rms": warmup["mirror_estimate_rms"],
})
finite = (bool(record["final"]["finite"])
and all(math.isfinite(value) for value in metrics.values()))
return {
"path": path, "mode": mode,
"mirror_eta": (None if mode == "hfa" else float(args["mirror_eta"])),
"metrics": metrics, "finite": finite,
"logical_batch_loss_queries": int(
record["work"]["logical_batch_loss_queries"]),
"mirror_events": int(record["counters"]["mirror_events"]),
"total_macs": int(record["work"]["total_macs_estimate"]),
"source_commit": record["provenance"]["git_commit"],
}
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--input", default="results/mirror_causal_capture")
parser.add_argument(
"--out", default="results/mirror_causal_capture_gate.json")
args = parser.parse_args()
rows = [load(path) for path in sorted(
glob.glob(os.path.join(args.input, "*.json")))]
references = [row for row in rows if row["mode"] == "hfa"]
candidates = [row for row in rows if row["mode"] == "wm"]
if len(references) != 1 or len(candidates) != len(RATES):
raise ValueError("incomplete WM-1 method grid")
if {row["mirror_eta"] for row in candidates} != set(RATES):
raise ValueError("incomplete WM-1 rate grid")
if len({row["source_commit"] for row in rows}) != 1:
raise ValueError("WM-1 source commits differ")
eligible = [row for row in candidates if row["finite"]]
eligible.sort(key=lambda row: (
-row["metrics"]["early_third_alignment"],
-row["metrics"]["all_layer_alignment"], row["mirror_eta"]))
selected = eligible[0] if eligible else None
checks = {
"all_four_records_finite": all(row["finite"] for row in rows),
"candidate_selected": selected is not None,
}
if selected is None:
checks.update({
"early_third_at_least_0.40": False,
"all_layer_at_least_0.50": False,
"mean_feedback_forward_cosine_at_least_0.85": False,
"feedback_norm_ratios_in_0.5_to_1.5": False,
"zero_task_loss_queries": False,
})
else:
metrics = selected["metrics"]
checks.update({
"early_third_at_least_0.40": (
metrics["early_third_alignment"] >= 0.40),
"all_layer_at_least_0.50": (
metrics["all_layer_alignment"] >= 0.50),
"mean_feedback_forward_cosine_at_least_0.85": (
metrics["mean_feedback_forward_cosine"] >= 0.85),
"feedback_norm_ratios_in_0.5_to_1.5": (
metrics["min_feedback_forward_norm_ratio"] >= 0.5
and metrics["max_feedback_forward_norm_ratio"] <= 1.5),
"zero_task_loss_queries": (
all(row["logical_batch_loss_queries"] == 0 for row in rows)),
})
output = {
"protocol": "normalized_response_mirror_capture_v1",
"status": "passed" if all(checks.values()) else "failed",
"checks": checks, "rows": rows, "matched_fixed_hfa": references[0],
"selected_wm": selected, "confirmation_test_seeds_touched": False,
"review_score_before": 5, "review_score_after": 5,
"score_change_rule": "inherited baseline capture cannot raise score",
}
os.makedirs(os.path.dirname(os.path.abspath(args.out)), exist_ok=True)
with open(args.out, "w") as handle:
json.dump(output, handle, indent=2, sort_keys=True)
handle.write("\n")
print(json.dumps({
"status": output["status"], "checks": checks,
"reference": references[0], "selected_wm": selected,
}, indent=2))
if __name__ == "__main__":
main()
|