model-runtime 0.5.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- model_runtime-0.5.0.dist-info/METADATA +618 -0
- model_runtime-0.5.0.dist-info/RECORD +36 -0
- model_runtime-0.5.0.dist-info/WHEEL +4 -0
- model_runtime-0.5.0.dist-info/entry_points.txt +2 -0
- model_runtime-0.5.0.dist-info/licenses/LICENSE +202 -0
- model_runtime-0.5.0.dist-info/licenses/NOTICE +6 -0
- saturn/__init__.py +28 -0
- saturn/adapters/__init__.py +63 -0
- saturn/adapters/_residency.py +196 -0
- saturn/adapters/decoder.py +1679 -0
- saturn/adapters/diffusion.py +438 -0
- saturn/adapters/flux1.py +661 -0
- saturn/adapters/flux2.py +630 -0
- saturn/adapters/mamba.py +620 -0
- saturn/adapters/qwen.py +637 -0
- saturn/causal.py +260 -0
- saturn/cli.py +382 -0
- saturn/contracts.py +175 -0
- saturn/core.py +1979 -0
- saturn/dependencies.py +61 -0
- saturn/interop/__init__.py +37 -0
- saturn/interop/circuit_tracer.py +1198 -0
- saturn/investigation.py +109 -0
- saturn/numerics.py +213 -0
- saturn/observers.py +289 -0
- saturn/paths.py +324 -0
- saturn/program.py +364 -0
- saturn/route.py +774 -0
- saturn/shared_store.py +257 -0
- saturn/store.py +835 -0
- saturn/symbols.py +398 -0
- saturn/training/__init__.py +61 -0
- saturn/training/_checkpoint.py +1618 -0
- saturn/trial.py +514 -0
- saturn/values.py +223 -0
- saturn/writers.py +82 -0
saturn/trial.py
ADDED
|
@@ -0,0 +1,514 @@
|
|
|
1
|
+
"""Arbitrate a standard-instrument reading against the native consumer.
|
|
2
|
+
|
|
3
|
+
:func:`arbitrate` takes a verdict a standard instrument already declared (activation
|
|
4
|
+
patching, a linear/dictionary probe, a cosine readout, an SAE ablation, or any external
|
|
5
|
+
reader) and lets the *unchanged native consumer* decide the verdict-grade question, using
|
|
6
|
+
Saturn's own Session / fork / compare / Receipt. It returns a :class:`TrialRow` whose
|
|
7
|
+
verdict is ``agree``, ``invert`` or ``inconclusive`` and which records the frozen
|
|
8
|
+
:class:`DecisionRule` that produced it. No model framework is imported at module load.
|
|
9
|
+
|
|
10
|
+
The arbiter in every case is the rest of the model run to completion, not an internal
|
|
11
|
+
metric. A reading is a candidate; only the consumer decides. The :class:`Reading` carries
|
|
12
|
+
a ``source`` seam so a reading produced by an external tool (the circuit-tracer
|
|
13
|
+
``native_edge_test``) can be arbitrated the same way as one declared by hand.
|
|
14
|
+
|
|
15
|
+
The offline Instrument Trial bundle verifier (``verify_bundle``, ``saturn-pub-trial-verify``)
|
|
16
|
+
and its receipt bundle moved to saturn-lab (``saturn_lab.trial``).
|
|
17
|
+
|
|
18
|
+
See :mod:`saturn` docs ``docs/trial.md`` and the seven measurement traps in
|
|
19
|
+
:data:`TRAPS`.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
from __future__ import annotations
|
|
23
|
+
|
|
24
|
+
from collections.abc import Callable, Mapping, Sequence
|
|
25
|
+
from dataclasses import dataclass, field
|
|
26
|
+
from types import MappingProxyType
|
|
27
|
+
from typing import Any
|
|
28
|
+
|
|
29
|
+
from .core import Act, Adapter, Receipt, Session, StateCut
|
|
30
|
+
from .values import clone, describe, digest
|
|
31
|
+
|
|
32
|
+
# --------------------------------------------------------------------------------------
|
|
33
|
+
# Consumer-gated arbitration of a standard-instrument reading.
|
|
34
|
+
# --------------------------------------------------------------------------------------
|
|
35
|
+
|
|
36
|
+
_VERDICTS = frozenset({"agree", "invert", "inconclusive"})
|
|
37
|
+
Driver = Callable[[Session], None]
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def grade(reading: "Reading", rule: "DecisionRule", effect: float) -> tuple[str, str, str]:
|
|
41
|
+
"""Grade a reading against a consumer effect under a frozen rule, controls aside.
|
|
42
|
+
|
|
43
|
+
Returns ``(verdict, classification, reason)``. This is exactly the decision the arbiter
|
|
44
|
+
applies once its controls pass, factored out so an external operator -- for example the
|
|
45
|
+
circuit-tracer native edge test, which measures the consumer effect with a forward hook
|
|
46
|
+
rather than a forked :class:`Session` -- can reach the same verdict under the identical
|
|
47
|
+
frozen rule. ``classification`` is the rule's ``present``/``absent``/``ambiguous`` class.
|
|
48
|
+
"""
|
|
49
|
+
classification = rule.classify(effect)
|
|
50
|
+
if reading.declined:
|
|
51
|
+
return "inconclusive", classification, "the instrument declined the verdict-grade question"
|
|
52
|
+
if classification == "ambiguous":
|
|
53
|
+
return (
|
|
54
|
+
"inconclusive",
|
|
55
|
+
classification,
|
|
56
|
+
"the consumer effect fell in the rule's ambiguity band",
|
|
57
|
+
)
|
|
58
|
+
present = classification == "present"
|
|
59
|
+
if present == reading.asserts_effect:
|
|
60
|
+
return "agree", classification, "the native consumer agrees with the instrument reading"
|
|
61
|
+
reason = (
|
|
62
|
+
"the native consumer shows the carrier is load-bearing where the instrument read no effect"
|
|
63
|
+
if present
|
|
64
|
+
else "the native consumer shows no effect where the instrument read one"
|
|
65
|
+
)
|
|
66
|
+
return "invert", classification, reason
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
@dataclass(frozen=True)
|
|
70
|
+
class Reading:
|
|
71
|
+
"""A verdict-grade reading a standard instrument declared before arbitration.
|
|
72
|
+
|
|
73
|
+
``asserts_effect`` records the *direction* of the claim as a boolean so the native
|
|
74
|
+
consumer can contradict it: ``True`` when the instrument says the carrier is
|
|
75
|
+
load-bearing / the content is present / the state was recovered, ``False`` when it
|
|
76
|
+
says the opposite. ``declined`` marks a reading that explicitly refused the
|
|
77
|
+
verdict-grade (or generality) question; such a reading is never graded a misreport.
|
|
78
|
+
|
|
79
|
+
``source`` is the seam for an external reader. A reading declared by hand keeps the
|
|
80
|
+
default ``"declared"``; :meth:`from_external` tags one produced by another tool (for
|
|
81
|
+
example a future circuit-tracer ``native_edge_test``) so provenance stays explicit.
|
|
82
|
+
"""
|
|
83
|
+
|
|
84
|
+
instrument: str
|
|
85
|
+
claim: str
|
|
86
|
+
asserts_effect: bool
|
|
87
|
+
declined: bool = False
|
|
88
|
+
detail: Mapping[str, Any] = field(default_factory=dict)
|
|
89
|
+
source: str = "declared"
|
|
90
|
+
fingerprint: str = field(init=False)
|
|
91
|
+
|
|
92
|
+
def __post_init__(self) -> None:
|
|
93
|
+
if not isinstance(self.instrument, str) or not self.instrument:
|
|
94
|
+
raise ValueError("reading requires a non-empty instrument label")
|
|
95
|
+
if not isinstance(self.claim, str) or not self.claim:
|
|
96
|
+
raise ValueError("reading requires a non-empty claim")
|
|
97
|
+
if type(self.asserts_effect) is not bool or type(self.declined) is not bool:
|
|
98
|
+
raise ValueError("asserts_effect and declined must be booleans")
|
|
99
|
+
if not isinstance(self.source, str) or not self.source:
|
|
100
|
+
raise ValueError("reading source must be a non-empty string")
|
|
101
|
+
object.__setattr__(self, "detail", MappingProxyType(clone(dict(self.detail))))
|
|
102
|
+
object.__setattr__(self, "fingerprint", digest(self._body()))
|
|
103
|
+
|
|
104
|
+
def _body(self) -> dict[str, Any]:
|
|
105
|
+
return {
|
|
106
|
+
"schema": "saturn-pub-trial-reading-v1",
|
|
107
|
+
"instrument": self.instrument,
|
|
108
|
+
"claim": self.claim,
|
|
109
|
+
"asserts_effect": self.asserts_effect,
|
|
110
|
+
"declined": self.declined,
|
|
111
|
+
"detail": describe(dict(self.detail)),
|
|
112
|
+
"source": self.source,
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
def to_dict(self) -> dict[str, Any]:
|
|
116
|
+
return {**self._body(), "fingerprint": self.fingerprint}
|
|
117
|
+
|
|
118
|
+
@classmethod
|
|
119
|
+
def from_external(
|
|
120
|
+
cls,
|
|
121
|
+
tool: str,
|
|
122
|
+
claim: str,
|
|
123
|
+
asserts_effect: bool,
|
|
124
|
+
*,
|
|
125
|
+
detail: Mapping[str, Any] | None = None,
|
|
126
|
+
declined: bool = False,
|
|
127
|
+
) -> Reading:
|
|
128
|
+
"""Wrap a reading produced by an external tool, keeping its provenance."""
|
|
129
|
+
if not isinstance(tool, str) or not tool:
|
|
130
|
+
raise ValueError("external reading requires the producing tool name")
|
|
131
|
+
return cls(
|
|
132
|
+
instrument=f"external:{tool}",
|
|
133
|
+
claim=claim,
|
|
134
|
+
asserts_effect=asserts_effect,
|
|
135
|
+
declined=declined,
|
|
136
|
+
detail={} if detail is None else detail,
|
|
137
|
+
source=tool,
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
@dataclass(frozen=True)
|
|
142
|
+
class DecisionRule:
|
|
143
|
+
"""A frozen, content-addressed rule that turns a consumer measurement into a class.
|
|
144
|
+
|
|
145
|
+
The consumer-closure ``effect`` evaluator supplied to :func:`arbitrate` returns a
|
|
146
|
+
scalar under ``metric`` for which higher means "the native consumer confirms the
|
|
147
|
+
thing the reading was about". This rule thresholds it: ``>= present_threshold`` is
|
|
148
|
+
``present``, ``<= absent_threshold`` is ``absent``, anything between is ``ambiguous``
|
|
149
|
+
(and arbitrates to ``inconclusive``). The rule's :attr:`fingerprint` is recorded on
|
|
150
|
+
every row so the decision rule is auditable after the fact.
|
|
151
|
+
"""
|
|
152
|
+
|
|
153
|
+
name: str
|
|
154
|
+
version: str
|
|
155
|
+
metric: str
|
|
156
|
+
present_threshold: float
|
|
157
|
+
absent_threshold: float
|
|
158
|
+
require_exact_gate: bool = True
|
|
159
|
+
require_sham_flat: bool = False
|
|
160
|
+
sham_metric: str | None = None
|
|
161
|
+
sham_tolerance: float = 0.1
|
|
162
|
+
description: str = ""
|
|
163
|
+
fingerprint: str = field(init=False)
|
|
164
|
+
|
|
165
|
+
def __post_init__(self) -> None:
|
|
166
|
+
if not self.name or not self.version or not self.metric:
|
|
167
|
+
raise ValueError("decision rule requires name, version, and a consumer metric key")
|
|
168
|
+
for value in (self.present_threshold, self.absent_threshold, self.sham_tolerance):
|
|
169
|
+
if isinstance(value, bool) or not isinstance(value, (int, float)):
|
|
170
|
+
raise ValueError("decision-rule thresholds must be numeric")
|
|
171
|
+
if float(self.present_threshold) < float(self.absent_threshold):
|
|
172
|
+
raise ValueError("present_threshold must be >= absent_threshold (higher = present)")
|
|
173
|
+
if type(self.require_exact_gate) is not bool or type(self.require_sham_flat) is not bool:
|
|
174
|
+
raise ValueError("gate requirements must be booleans")
|
|
175
|
+
if self.require_sham_flat and not self.sham_metric:
|
|
176
|
+
raise ValueError("require_sham_flat needs a sham_metric key")
|
|
177
|
+
if self.sham_metric is not None and not isinstance(self.sham_metric, str):
|
|
178
|
+
raise ValueError("sham_metric must be a string key or None")
|
|
179
|
+
object.__setattr__(self, "present_threshold", float(self.present_threshold))
|
|
180
|
+
object.__setattr__(self, "absent_threshold", float(self.absent_threshold))
|
|
181
|
+
object.__setattr__(self, "sham_tolerance", float(self.sham_tolerance))
|
|
182
|
+
object.__setattr__(self, "fingerprint", digest(self._body()))
|
|
183
|
+
|
|
184
|
+
def _body(self) -> dict[str, Any]:
|
|
185
|
+
return {
|
|
186
|
+
"schema": "saturn-pub-trial-decision-rule-v1",
|
|
187
|
+
"name": self.name,
|
|
188
|
+
"version": self.version,
|
|
189
|
+
"metric": self.metric,
|
|
190
|
+
"present_threshold": self.present_threshold,
|
|
191
|
+
"absent_threshold": self.absent_threshold,
|
|
192
|
+
"require_exact_gate": self.require_exact_gate,
|
|
193
|
+
"require_sham_flat": self.require_sham_flat,
|
|
194
|
+
"sham_metric": self.sham_metric,
|
|
195
|
+
"sham_tolerance": self.sham_tolerance,
|
|
196
|
+
"description": self.description,
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
def to_dict(self) -> dict[str, Any]:
|
|
200
|
+
return {**self._body(), "fingerprint": self.fingerprint}
|
|
201
|
+
|
|
202
|
+
def classify(self, effect: float) -> str:
|
|
203
|
+
"""Return ``present`` / ``absent`` / ``ambiguous`` for a consumer effect scalar."""
|
|
204
|
+
value = float(effect)
|
|
205
|
+
if value >= self.present_threshold:
|
|
206
|
+
return "present"
|
|
207
|
+
if value <= self.absent_threshold:
|
|
208
|
+
return "absent"
|
|
209
|
+
return "ambiguous"
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
@dataclass(frozen=True)
|
|
213
|
+
class TrialRow:
|
|
214
|
+
"""One arbitrated verdict: the reading, the frozen rule, and what the consumer did."""
|
|
215
|
+
|
|
216
|
+
reading: Reading
|
|
217
|
+
rule: DecisionRule
|
|
218
|
+
verdict: str
|
|
219
|
+
classification: str
|
|
220
|
+
consumer_effect: float | None
|
|
221
|
+
reason: str
|
|
222
|
+
controls: Mapping[str, Any]
|
|
223
|
+
measurements: Mapping[str, Any]
|
|
224
|
+
parent: str
|
|
225
|
+
receipt: str
|
|
226
|
+
fingerprint: str = field(init=False)
|
|
227
|
+
|
|
228
|
+
def __post_init__(self) -> None:
|
|
229
|
+
if self.verdict not in _VERDICTS:
|
|
230
|
+
raise ValueError(f"unknown trial verdict: {self.verdict}")
|
|
231
|
+
object.__setattr__(self, "controls", MappingProxyType(clone(dict(self.controls))))
|
|
232
|
+
object.__setattr__(self, "measurements", MappingProxyType(clone(dict(self.measurements))))
|
|
233
|
+
object.__setattr__(self, "fingerprint", digest(self._body()))
|
|
234
|
+
|
|
235
|
+
def _body(self) -> dict[str, Any]:
|
|
236
|
+
return {
|
|
237
|
+
"schema": "saturn-pub-trial-row-v1",
|
|
238
|
+
"reading": self.reading.fingerprint,
|
|
239
|
+
"decision_rule": self.rule.fingerprint,
|
|
240
|
+
"verdict": self.verdict,
|
|
241
|
+
"classification": self.classification,
|
|
242
|
+
"consumer_effect": self.consumer_effect,
|
|
243
|
+
"reason": self.reason,
|
|
244
|
+
"controls": describe(dict(self.controls)),
|
|
245
|
+
"measurements": describe(dict(self.measurements)),
|
|
246
|
+
"parent": self.parent,
|
|
247
|
+
"receipt": self.receipt,
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
def to_dict(self) -> dict[str, Any]:
|
|
251
|
+
return {
|
|
252
|
+
"schema": "saturn-pub-trial-row-v1",
|
|
253
|
+
"fingerprint": self.fingerprint,
|
|
254
|
+
"reading": self.reading.to_dict(),
|
|
255
|
+
"decision_rule": self.rule.to_dict(),
|
|
256
|
+
"verdict": self.verdict,
|
|
257
|
+
"classification": self.classification,
|
|
258
|
+
"consumer_effect": self.consumer_effect,
|
|
259
|
+
"reason": self.reason,
|
|
260
|
+
"controls": dict(self.controls),
|
|
261
|
+
"measurements": dict(self.measurements),
|
|
262
|
+
"parent": self.parent,
|
|
263
|
+
"receipt": self.receipt,
|
|
264
|
+
"arbiter": "unchanged native consumer; a reading is a candidate, not a verdict",
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
def _as_driver(spec: Act | Sequence[Act] | Driver, steps: int) -> Driver:
|
|
269
|
+
if isinstance(spec, Act):
|
|
270
|
+
acts: tuple[Act, ...] = (spec,)
|
|
271
|
+
elif isinstance(spec, (tuple, list)) and spec and all(isinstance(item, Act) for item in spec):
|
|
272
|
+
acts = tuple(spec)
|
|
273
|
+
elif callable(spec):
|
|
274
|
+
return spec
|
|
275
|
+
else:
|
|
276
|
+
raise ValueError("intervention must be an Act, a sequence of Acts, or a driver callable")
|
|
277
|
+
|
|
278
|
+
def drive(branch: Session) -> None:
|
|
279
|
+
for act in acts:
|
|
280
|
+
branch.apply(act)
|
|
281
|
+
if steps:
|
|
282
|
+
branch.continue_(steps)
|
|
283
|
+
|
|
284
|
+
return drive
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
def _native_driver(spec: Act | Sequence[Act] | Driver | None, steps: int) -> Driver:
|
|
288
|
+
if spec is None:
|
|
289
|
+
return lambda branch: branch.continue_(steps) if steps else None
|
|
290
|
+
return _as_driver(spec, steps)
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
def arbitrate(
|
|
294
|
+
session_or_adapter: Session | Adapter,
|
|
295
|
+
reading: Reading,
|
|
296
|
+
rule: DecisionRule,
|
|
297
|
+
*,
|
|
298
|
+
effect: Callable[[Mapping[str, Session]], Mapping[str, Any]],
|
|
299
|
+
candidate: Act | Sequence[Act] | Driver,
|
|
300
|
+
steps: int = 1,
|
|
301
|
+
native: Act | Sequence[Act] | Driver | None = None,
|
|
302
|
+
sham: Act | Sequence[Act] | Driver | None = None,
|
|
303
|
+
parent: StateCut | None = None,
|
|
304
|
+
) -> TrialRow:
|
|
305
|
+
"""Let the native consumer arbitrate a standard-instrument ``reading``.
|
|
306
|
+
|
|
307
|
+
The ``candidate`` is the intervention the instrument's claim is about (an
|
|
308
|
+
:class:`~saturn.Act`, a sequence of Acts applied then run ``steps``, or a driver
|
|
309
|
+
callable that drives a freshly forked branch to the consumer-observable end). A
|
|
310
|
+
matching unmodified ``native`` arm and an optional ``sham`` control are run from the
|
|
311
|
+
same parent. ``effect`` is a consumer-closure evaluator; it receives the finished
|
|
312
|
+
branches (``{"native", "candidate"[, "sham"]}``) and must return the rule's ``metric``
|
|
313
|
+
(and ``sham_metric`` when the rule requires a flat sham). The frozen ``rule`` classes
|
|
314
|
+
the effect; the verdict compares that class to what the reading asserted:
|
|
315
|
+
|
|
316
|
+
* agree -- the consumer confirms what the instrument claimed,
|
|
317
|
+
* invert -- the consumer contradicts it,
|
|
318
|
+
* inconclusive -- the reading declined, the effect was ambiguous, or a control failed.
|
|
319
|
+
|
|
320
|
+
torch is never imported here; whatever adapter the caller built owns the tensors.
|
|
321
|
+
"""
|
|
322
|
+
if isinstance(session_or_adapter, Session):
|
|
323
|
+
session = session_or_adapter
|
|
324
|
+
parent_cut = parent or session.capture()
|
|
325
|
+
elif isinstance(session_or_adapter, Adapter):
|
|
326
|
+
if parent is None:
|
|
327
|
+
raise ValueError("arbitrating from an adapter requires a parent StateCut")
|
|
328
|
+
session = Session.from_cut(session_or_adapter, parent)
|
|
329
|
+
parent_cut = parent
|
|
330
|
+
else:
|
|
331
|
+
raise ValueError("arbitrate needs a Session, or an Adapter plus a parent StateCut")
|
|
332
|
+
if not isinstance(reading, Reading) or not isinstance(rule, DecisionRule):
|
|
333
|
+
raise ValueError("arbitrate needs a Reading and a DecisionRule")
|
|
334
|
+
if not callable(effect):
|
|
335
|
+
raise ValueError("effect must be a consumer-closure evaluator callable")
|
|
336
|
+
if type(steps) is not int or steps < 0:
|
|
337
|
+
raise ValueError("steps must be a nonnegative integer")
|
|
338
|
+
|
|
339
|
+
candidate_driver = _as_driver(candidate, steps)
|
|
340
|
+
native_driver = _native_driver(native, steps)
|
|
341
|
+
|
|
342
|
+
native_branch = session.fork(parent_cut)
|
|
343
|
+
native_driver(native_branch)
|
|
344
|
+
candidate_branch = session.fork(parent_cut)
|
|
345
|
+
candidate_driver(candidate_branch)
|
|
346
|
+
|
|
347
|
+
branches: dict[str, Session] = {"native": native_branch, "candidate": candidate_branch}
|
|
348
|
+
if sham is not None:
|
|
349
|
+
sham_branch = session.fork(parent_cut)
|
|
350
|
+
_as_driver(sham, steps)(sham_branch)
|
|
351
|
+
branches["sham"] = sham_branch
|
|
352
|
+
|
|
353
|
+
controls: dict[str, Any] = {}
|
|
354
|
+
controls_ok = True
|
|
355
|
+
reason = ""
|
|
356
|
+
if rule.require_exact_gate:
|
|
357
|
+
native_check = session.fork(parent_cut)
|
|
358
|
+
native_driver(native_check)
|
|
359
|
+
exact_gate = bool(native_branch.compare(native_check)["equal_payload"])
|
|
360
|
+
controls["exact_gate"] = exact_gate
|
|
361
|
+
if not exact_gate:
|
|
362
|
+
controls_ok = False
|
|
363
|
+
reason = "exact-replay gate failed: the unmodified path did not reproduce"
|
|
364
|
+
|
|
365
|
+
metrics = dict(effect(branches))
|
|
366
|
+
if rule.metric not in metrics:
|
|
367
|
+
raise ValueError(f"effect evaluator did not return the rule metric: {rule.metric}")
|
|
368
|
+
consumer_effect = float(metrics[rule.metric])
|
|
369
|
+
classification = rule.classify(consumer_effect)
|
|
370
|
+
|
|
371
|
+
if rule.require_sham_flat:
|
|
372
|
+
if rule.sham_metric not in metrics:
|
|
373
|
+
raise ValueError(f"effect evaluator did not return the sham metric: {rule.sham_metric}")
|
|
374
|
+
sham_value = float(metrics[rule.sham_metric])
|
|
375
|
+
sham_flat = abs(sham_value) <= rule.sham_tolerance
|
|
376
|
+
controls["sham_flat"] = sham_flat
|
|
377
|
+
controls["sham_value"] = sham_value
|
|
378
|
+
if controls_ok and not sham_flat:
|
|
379
|
+
controls_ok = False
|
|
380
|
+
reason = "sham control was not flat; the effect is not specific to the intervention"
|
|
381
|
+
|
|
382
|
+
if not controls_ok:
|
|
383
|
+
verdict = "inconclusive"
|
|
384
|
+
classification = "controls-failed"
|
|
385
|
+
else:
|
|
386
|
+
verdict, classification, reason = grade(reading, rule, consumer_effect)
|
|
387
|
+
|
|
388
|
+
receipt = Receipt.make(
|
|
389
|
+
operation="trial.arbitrate",
|
|
390
|
+
parent=parent_cut.fingerprint,
|
|
391
|
+
model_identity=session.adapter.model_identity,
|
|
392
|
+
execution=dict(session.adapter.execution),
|
|
393
|
+
reading=reading.to_dict(),
|
|
394
|
+
decision_rule=rule.to_dict(),
|
|
395
|
+
verdict=verdict,
|
|
396
|
+
classification=classification,
|
|
397
|
+
consumer_effect=consumer_effect,
|
|
398
|
+
controls=controls,
|
|
399
|
+
measurements=describe(metrics),
|
|
400
|
+
native=native_branch.capture(retain=False).fingerprint,
|
|
401
|
+
candidate=candidate_branch.capture(retain=False).fingerprint,
|
|
402
|
+
)
|
|
403
|
+
session.receipts.append(receipt)
|
|
404
|
+
return TrialRow(
|
|
405
|
+
reading=reading,
|
|
406
|
+
rule=rule,
|
|
407
|
+
verdict=verdict,
|
|
408
|
+
classification=classification,
|
|
409
|
+
consumer_effect=consumer_effect,
|
|
410
|
+
reason=reason,
|
|
411
|
+
controls=controls,
|
|
412
|
+
measurements=metrics,
|
|
413
|
+
parent=parent_cut.fingerprint,
|
|
414
|
+
receipt=receipt.fingerprint,
|
|
415
|
+
)
|
|
416
|
+
|
|
417
|
+
|
|
418
|
+
# --------------------------------------------------------------------------------------
|
|
419
|
+
# TRAPS: seven ways to be confidently wrong, as a documented, programmatic checklist.
|
|
420
|
+
# --------------------------------------------------------------------------------------
|
|
421
|
+
|
|
422
|
+
|
|
423
|
+
@dataclass(frozen=True)
|
|
424
|
+
class Trap:
|
|
425
|
+
"""One measurement failure mode and the gate that kills it."""
|
|
426
|
+
|
|
427
|
+
number: int
|
|
428
|
+
name: str
|
|
429
|
+
failure: str
|
|
430
|
+
gate: str
|
|
431
|
+
|
|
432
|
+
def to_dict(self) -> dict[str, Any]:
|
|
433
|
+
return {
|
|
434
|
+
"number": self.number,
|
|
435
|
+
"name": self.name,
|
|
436
|
+
"failure": self.failure,
|
|
437
|
+
"gate": self.gate,
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
|
|
441
|
+
TRAPS: tuple[Trap, ...] = (
|
|
442
|
+
Trap(
|
|
443
|
+
1,
|
|
444
|
+
"The latent-only false positive",
|
|
445
|
+
"Internal positions of a late merged block showed high alignment with intervention "
|
|
446
|
+
"outcomes while the served output never changed, because the architecture discards "
|
|
447
|
+
"those positions. Activation-magnitude rankings reliably surface these disposal sites.",
|
|
448
|
+
"Confirm every internal claim at an observable the model actually serves "
|
|
449
|
+
"(the two-consumer rule).",
|
|
450
|
+
),
|
|
451
|
+
Trap(
|
|
452
|
+
2,
|
|
453
|
+
"Contrast collapse inflates alignment",
|
|
454
|
+
"When an intervention collapses the two contrast conditions toward each other, every "
|
|
455
|
+
"later patch scores a higher alignment cosine while absolute effects are negligible.",
|
|
456
|
+
"Verify baseline contrast viability; report baseline-normalized progress, never raw "
|
|
457
|
+
"alignment.",
|
|
458
|
+
),
|
|
459
|
+
Trap(
|
|
460
|
+
3,
|
|
461
|
+
"The scaffold dominates similarity",
|
|
462
|
+
"Shared structure (positional scaffolds, templates, formatting) dominates global "
|
|
463
|
+
"similarity: a 0.996-cosine reconstruction is compatible with zero semantic content "
|
|
464
|
+
"(bundle case 4 -- a content-free template scores the same).",
|
|
465
|
+
"Test with semantic contrasts, or not at all.",
|
|
466
|
+
),
|
|
467
|
+
Trap(
|
|
468
|
+
4,
|
|
469
|
+
"A clean output is not a correct output",
|
|
470
|
+
"Strong generative priors render plausible outputs from degenerate internal states.",
|
|
471
|
+
"Output quality checks cannot substitute for output content checks.",
|
|
472
|
+
),
|
|
473
|
+
Trap(
|
|
474
|
+
5,
|
|
475
|
+
"Terminal readout masquerades as origin",
|
|
476
|
+
"Writing a complete target state at the last pre-output boundary reproduces the target "
|
|
477
|
+
"perfectly and identifies nothing but the readout.",
|
|
478
|
+
"Cross-check late-site interventions with delta-based screens before any 'the concept "
|
|
479
|
+
"lives late' conclusion.",
|
|
480
|
+
),
|
|
481
|
+
Trap(
|
|
482
|
+
6,
|
|
483
|
+
"Relaxation artifacts read as structure",
|
|
484
|
+
"Graph/flow analyses composed over intervention evidence inherit their relaxations' "
|
|
485
|
+
"artifacts: an empty minimum cut was a property of the relaxation, not evidence the "
|
|
486
|
+
"route has no bottleneck.",
|
|
487
|
+
"Derived graph objects are search guides, never certificates.",
|
|
488
|
+
),
|
|
489
|
+
Trap(
|
|
490
|
+
7,
|
|
491
|
+
"A live site is not a circuit",
|
|
492
|
+
"An early result named one block-call 'the counting circuit' from a behavioral "
|
|
493
|
+
"association; under strict replication it survived 5 of 16 paired tests and was demoted.",
|
|
494
|
+
"Behavioral liveness is a candidate -- promotion needs the full battery, and every "
|
|
495
|
+
"positive result owes its survival to a control designed to kill it.",
|
|
496
|
+
),
|
|
497
|
+
)
|
|
498
|
+
|
|
499
|
+
|
|
500
|
+
def traps() -> tuple[Trap, ...]:
|
|
501
|
+
"""Return the seven measurement traps as a programmatic checklist."""
|
|
502
|
+
return TRAPS
|
|
503
|
+
|
|
504
|
+
|
|
505
|
+
__all__ = [
|
|
506
|
+
"Reading",
|
|
507
|
+
"DecisionRule",
|
|
508
|
+
"TrialRow",
|
|
509
|
+
"Trap",
|
|
510
|
+
"arbitrate",
|
|
511
|
+
"grade",
|
|
512
|
+
"traps",
|
|
513
|
+
"TRAPS",
|
|
514
|
+
]
|