model-debugger 0.4.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.
- mdb/__init__.py +43 -0
- mdb/__main__.py +5 -0
- mdb/analysis/__init__.py +34 -0
- mdb/analysis/circuits/__init__.py +6 -0
- mdb/analysis/circuits/build.py +690 -0
- mdb/analysis/circuits/test.py +600 -0
- mdb/analysis/features/__init__.py +5 -0
- mdb/analysis/features/basis.py +685 -0
- mdb/analysis/features/sae.py +374 -0
- mdb/analysis/features/watch.py +268 -0
- mdb/analysis/measure/__init__.py +7 -0
- mdb/analysis/measure/branches.py +806 -0
- mdb/analysis/measure/bridge.py +379 -0
- mdb/analysis/measure/changes.py +201 -0
- mdb/analysis/measure/compare.py +348 -0
- mdb/analysis/measure/donors.py +193 -0
- mdb/analysis/measure/novelty.py +227 -0
- mdb/analysis/measure/paths.py +146 -0
- mdb/analysis/measure/pools.py +454 -0
- mdb/analysis/measure/readout.py +387 -0
- mdb/analysis/measure/reads.py +455 -0
- mdb/analysis/measure/sweep.py +215 -0
- mdb/analysis/numerics/__init__.py +6 -0
- mdb/analysis/numerics/accumulation.py +180 -0
- mdb/analysis/numerics/finite.py +1712 -0
- mdb/analysis/numerics/labels.py +80 -0
- mdb/analysis/numerics/pooling.py +89 -0
- mdb/analysis/numerics/stability.py +183 -0
- mdb/analysis/numerics/summary.py +306 -0
- mdb/analysis/numerics/units.py +86 -0
- mdb/analysis/numerics/verdict.py +244 -0
- mdb/analysis/numerics/why_frames.py +162 -0
- mdb/analysis/predict/__init__.py +7 -0
- mdb/analysis/predict/capture.py +265 -0
- mdb/analysis/predict/consumers.py +52 -0
- mdb/analysis/predict/explain.py +776 -0
- mdb/analysis/predict/forecast.py +635 -0
- mdb/analysis/predict/plan.py +248 -0
- mdb/analysis/predict/propagate.py +596 -0
- mdb/analysis/predict/rounding.py +95 -0
- mdb/analysis/predict/rowmodel.py +817 -0
- mdb/analysis/predict/supplied.py +103 -0
- mdb/analysis/predict/verify.py +433 -0
- mdb/analysis/predict/whatif.py +840 -0
- mdb/analysis/symbols/__init__.py +7 -0
- mdb/analysis/symbols/binding.py +138 -0
- mdb/analysis/symbols/candidates.py +320 -0
- mdb/analysis/symbols/circuit_map.py +592 -0
- mdb/analysis/symbols/components.py +436 -0
- mdb/analysis/symbols/frame.py +451 -0
- mdb/analysis/symbols/hop.py +439 -0
- mdb/analysis/symbols/liveness.py +292 -0
- mdb/analysis/symbols/probe.py +393 -0
- mdb/analysis/symbols/rows.py +400 -0
- mdb/analysis/symbols/sealed.py +149 -0
- mdb/analysis/symbols/subspace.py +380 -0
- mdb/analysis/symbols/symbol_finite.py +417 -0
- mdb/analysis/symbols/symbol_runs.py +683 -0
- mdb/analysis/symbols/table.py +1110 -0
- mdb/cli.py +105 -0
- mdb/core/__init__.py +4 -0
- mdb/core/address.py +1353 -0
- mdb/core/bounded.py +101 -0
- mdb/core/checkpoint_schema.py +202 -0
- mdb/core/checkpoint_store.py +377 -0
- mdb/core/circuit_pages.py +117 -0
- mdb/core/custody.py +629 -0
- mdb/core/errors.py +51 -0
- mdb/core/foreign_names.py +152 -0
- mdb/core/graph_seal.py +426 -0
- mdb/core/index.py +403 -0
- mdb/core/kinds.py +255 -0
- mdb/core/locate.py +161 -0
- mdb/core/migrate.py +280 -0
- mdb/core/neuronpedia.py +116 -0
- mdb/core/plugins.py +78 -0
- mdb/core/pointers.py +621 -0
- mdb/core/project.py +248 -0
- mdb/core/project_read.py +1038 -0
- mdb/core/recipe.py +457 -0
- mdb/core/records.py +1027 -0
- mdb/core/resolve.py +296 -0
- mdb/core/settings.py +718 -0
- mdb/engine/__init__.py +21 -0
- mdb/engine/attention_observer.py +53 -0
- mdb/engine/attention_port.py +903 -0
- mdb/engine/breakpoints.py +1465 -0
- mdb/engine/bundle.py +137 -0
- mdb/engine/checkpoint.py +1265 -0
- mdb/engine/core_file.py +306 -0
- mdb/engine/edits.py +323 -0
- mdb/engine/holds.py +256 -0
- mdb/engine/models.py +172 -0
- mdb/engine/ports.py +1424 -0
- mdb/engine/refs.py +223 -0
- mdb/engine/run.py +2162 -0
- mdb/engine/selfcheck.py +347 -0
- mdb/engine/trace.py +536 -0
- mdb/interop/__init__.py +17 -0
- mdb/interop/circuit_tracer_graph.py +253 -0
- mdb/interop/circuit_tracer_names.py +44 -0
- mdb/interop/clone.py +22 -0
- mdb/interop/names.py +295 -0
- mdb/interop/nn.py +431 -0
- mdb/interop/pyvene_compat.py +40 -0
- mdb/interop/pyvene_names.py +82 -0
- mdb/interop/tl.py +149 -0
- mdb/interop/verify.py +85 -0
- mdb/machines/__init__.py +53 -0
- mdb/machines/x86/__init__.py +13 -0
- mdb/machines/x86/address.py +171 -0
- mdb/machines/x86/binary.py +285 -0
- mdb/machines/x86/grid.py +188 -0
- mdb/machines/x86/index.py +184 -0
- mdb/machines/x86/interchange.py +156 -0
- mdb/machines/x86/lanes.py +281 -0
- mdb/machines/x86/method.py +252 -0
- mdb/machines/x86/method_v2.py +105 -0
- mdb/machines/x86/mlp.py +430 -0
- mdb/machines/x86/records.py +138 -0
- mdb/machines/x86/session.py +631 -0
- mdb/machines/x86/trace.py +351 -0
- mdb/ops/__init__.py +31 -0
- mdb/ops/builtin.py +1977 -0
- mdb/ops/context.py +60 -0
- mdb/ops/debugger.py +926 -0
- mdb/ops/errors.py +8 -0
- mdb/ops/features.py +513 -0
- mdb/ops/graph.py +58 -0
- mdb/ops/inspect.py +906 -0
- mdb/ops/lines.py +496 -0
- mdb/ops/named.py +672 -0
- mdb/ops/predict.py +450 -0
- mdb/ops/registry.py +332 -0
- mdb/ops/sets.py +988 -0
- mdb/ops/sweep.py +574 -0
- mdb/repl/__init__.py +5 -0
- mdb/repl/__main__.py +244 -0
- mdb/repl/config.py +213 -0
- mdb/repl/remote.py +324 -0
- mdb/repl/render.py +1699 -0
- mdb/repl/shell.py +409 -0
- mdb/serve/__init__.py +17 -0
- mdb/serve/__main__.py +180 -0
- mdb/serve/_legacy.py +97 -0
- mdb/serve/app.py +526 -0
- mdb/serve/blobs.py +280 -0
- mdb/serve/caps.py +148 -0
- mdb/serve/export.py +9 -0
- mdb/serve/guard.py +216 -0
- mdb/serve/live.py +412 -0
- mdb/serve/live_reduce.py +90 -0
- mdb/serve/recorded.py +515 -0
- mdb/serve/reduce.py +449 -0
- mdb/serve/schema.py +969 -0
- mdb/serve/states.py +125 -0
- mdb/serve/static/assets/index-BJpByNCO.js +58 -0
- mdb/serve/static/assets/index-H9zlNeqq.css +1 -0
- mdb/serve/static/index.html +14 -0
- mdb/serve/static/manifest.json +5 -0
- mdb/serve/stored.py +34 -0
- mdb/serve/typegen.py +131 -0
- mdb/serve/views/__init__.py +1 -0
- mdb/serve/views/common.py +201 -0
- mdb/serve/views/frame.py +235 -0
- mdb/serve/views/graph.py +224 -0
- mdb/serve/views/live.py +402 -0
- mdb/serve/views/records.py +557 -0
- mdb/serve/views/sessions.py +151 -0
- mdb/serve/views/symbols.py +185 -0
- mdb/serve/views/timeline.py +121 -0
- model_debugger-0.4.0.dist-info/METADATA +1516 -0
- model_debugger-0.4.0.dist-info/RECORD +177 -0
- model_debugger-0.4.0.dist-info/WHEEL +4 -0
- model_debugger-0.4.0.dist-info/entry_points.txt +2 -0
- model_debugger-0.4.0.dist-info/licenses/LICENSE +202 -0
- model_debugger-0.4.0.dist-info/licenses/NOTICE +6 -0
mdb/core/index.py
ADDED
|
@@ -0,0 +1,403 @@
|
|
|
1
|
+
"""Project index: sealed records, the cursor, replay recipes and occurrence locations.
|
|
2
|
+
|
|
3
|
+
Functions take a project, duck-typed: ``mdb.core.project.Project`` (the engine's own), the lane
|
|
4
|
+
``mdb_lanes.project.Project`` or ``mdb.core.project_read.ProjectReader``. What is used is
|
|
5
|
+
``read_only``, ``session(sid)``, ``store`` and a connection: the public ``db()`` of the engine
|
|
6
|
+
project, else the ``_db()`` the two other classes offer (the one duck-typed fallback, so this
|
|
7
|
+
module imports neither class nor a framework). Row text is ``saturn.values.canonical``.
|
|
8
|
+
|
|
9
|
+
The index is purely additive to a schema-3 project (``user_version`` stays 3, so every other
|
|
10
|
+
checkout opens the same directory)::
|
|
11
|
+
|
|
12
|
+
records(id PRIMARY KEY, session_id, kind, schema, body) # mdb-record-v3 or -v2, stored_form
|
|
13
|
+
cursor(session_id PRIMARY KEY, record_id)
|
|
14
|
+
recipes(id PRIMARY KEY, session_id, body)
|
|
15
|
+
occurrences(session_id, address, recipe_id, event_id, cut_id, blob_id,
|
|
16
|
+
PRIMARY KEY(session_id, address))
|
|
17
|
+
|
|
18
|
+
The four tables are created with ``CREATE TABLE IF NOT EXISTS`` in ONE transaction, lazily, by
|
|
19
|
+
the first write through this module (``ensure_tables``); never on a read and never on a
|
|
20
|
+
read-only connection. A reader treats a missing table as empty. ``circuit_records`` and
|
|
21
|
+
``circuit_focus`` are the tables ``circuit_investigation`` creates and writes, untouched:
|
|
22
|
+
``list_records``/``get_record`` pass legacy ``mdb-circuit-investigation-v1`` rows through
|
|
23
|
+
(read-only, marked by their own schema string) and return v3 and v2 rows from ``records``.
|
|
24
|
+
A v3 row stores ``execution_sha256`` in place of the execution profile; the reader takes the
|
|
25
|
+
profile from the session row (the record's binding), so a row bound to another profile is
|
|
26
|
+
refused. Writes of v3 (and verified v2) records go only to ``records``; legacy writes stay with
|
|
27
|
+
``circuit_investigation``.
|
|
28
|
+
"""
|
|
29
|
+
from __future__ import annotations
|
|
30
|
+
|
|
31
|
+
import json
|
|
32
|
+
|
|
33
|
+
from saturn.values import canonical
|
|
34
|
+
|
|
35
|
+
from .pointers import RecordError, _sha
|
|
36
|
+
from .records import (
|
|
37
|
+
LEGACY_SCHEMAS,
|
|
38
|
+
SCHEMAS,
|
|
39
|
+
kind_spec,
|
|
40
|
+
load_record,
|
|
41
|
+
parse_line,
|
|
42
|
+
seal_digest,
|
|
43
|
+
stored_form,
|
|
44
|
+
verify_legacy,
|
|
45
|
+
verify_record,
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
LEGACY_CIRCUIT = LEGACY_SCHEMAS[0]
|
|
49
|
+
MAX_RECIPE_BYTES = 256 * 1024
|
|
50
|
+
|
|
51
|
+
TABLES = ("records", "cursor", "recipes", "occurrences")
|
|
52
|
+
_TABLE_STATEMENTS = (
|
|
53
|
+
"""CREATE TABLE IF NOT EXISTS records (
|
|
54
|
+
id TEXT PRIMARY KEY, session_id TEXT NOT NULL, kind TEXT NOT NULL,
|
|
55
|
+
schema TEXT NOT NULL, body TEXT NOT NULL)""",
|
|
56
|
+
"CREATE INDEX IF NOT EXISTS records_session ON records(session_id, kind)",
|
|
57
|
+
"""CREATE TABLE IF NOT EXISTS cursor (
|
|
58
|
+
session_id TEXT PRIMARY KEY, record_id TEXT NOT NULL)""",
|
|
59
|
+
"""CREATE TABLE IF NOT EXISTS recipes (
|
|
60
|
+
id TEXT PRIMARY KEY, session_id TEXT NOT NULL, body TEXT NOT NULL)""",
|
|
61
|
+
"""CREATE TABLE IF NOT EXISTS occurrences (
|
|
62
|
+
session_id TEXT NOT NULL, address TEXT NOT NULL, recipe_id TEXT,
|
|
63
|
+
event_id INTEGER, cut_id TEXT, blob_id TEXT,
|
|
64
|
+
PRIMARY KEY (session_id, address))""",
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
class NotIndexed(LookupError):
|
|
69
|
+
"""The project index holds no such record, recipe or cursor."""
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def _connect(project):
|
|
73
|
+
"""A connection context of ``project``: its public ``db()``, else its ``_db()``."""
|
|
74
|
+
opener = getattr(project, "db", None)
|
|
75
|
+
return opener() if callable(opener) else project._db()
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def _text(value):
|
|
79
|
+
"""The canonical JSON text a row is stored as (what every project writer's ``_json`` is)."""
|
|
80
|
+
return canonical(value).decode("utf-8")
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def _tables(db):
|
|
84
|
+
return {r[0] for r in db.execute("SELECT name FROM sqlite_master WHERE type='table'")}
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def migrate(db):
|
|
88
|
+
"""Ensure the additive tables on an open writable connection (idempotent, one transaction).
|
|
89
|
+
|
|
90
|
+
Kept for callers of the earlier schema-4 name; it changes nothing else (no data moves, no
|
|
91
|
+
``user_version``).
|
|
92
|
+
"""
|
|
93
|
+
if set(TABLES) <= _tables(db):
|
|
94
|
+
return
|
|
95
|
+
if not db.in_transaction:
|
|
96
|
+
db.execute("BEGIN IMMEDIATE")
|
|
97
|
+
for statement in _TABLE_STATEMENTS:
|
|
98
|
+
db.execute(statement)
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def ensure_tables(project):
|
|
102
|
+
"""Create the four index tables if absent, atomically. Called by every write below."""
|
|
103
|
+
_writable(project)
|
|
104
|
+
with _connect(project) as db:
|
|
105
|
+
migrate(db)
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def _exists(db, table):
|
|
109
|
+
return table in _tables(db)
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def _writable(project):
|
|
113
|
+
if project.read_only:
|
|
114
|
+
raise RecordError("writing the project index requires a writable project")
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def _binding(project, sid):
|
|
118
|
+
row = project.session(sid)
|
|
119
|
+
return json.loads(row["identity"]), json.loads(row["execution"])
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
# --------------------------------------------------------------------------- records
|
|
123
|
+
|
|
124
|
+
def _same_binding(record, identity, execution):
|
|
125
|
+
"""Seal digests, not ``==`` (``1 == 1.0``, but they seal differently)."""
|
|
126
|
+
try:
|
|
127
|
+
return (seal_digest(record.get("model_identity")) == seal_digest(identity)
|
|
128
|
+
and seal_digest(record.get("execution")) == seal_digest(execution))
|
|
129
|
+
except (RecordError, ValueError, TypeError):
|
|
130
|
+
return False
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def put_record(project, record):
|
|
134
|
+
"""Index a sealed record (v3, or a verified v2) under its session; returns its id.
|
|
135
|
+
Idempotent."""
|
|
136
|
+
_writable(project)
|
|
137
|
+
record = verify_record(record)
|
|
138
|
+
identity, execution = _binding(project, record["session_id"])
|
|
139
|
+
if not _same_binding(record, identity, execution):
|
|
140
|
+
raise RecordError("record belongs to another model or execution than its session")
|
|
141
|
+
body = stored_form(record) # the bytes the size bound, the digest and the row all share
|
|
142
|
+
ensure_tables(project)
|
|
143
|
+
with _connect(project) as db:
|
|
144
|
+
db.execute("INSERT OR IGNORE INTO records VALUES (?,?,?,?,?)",
|
|
145
|
+
(record["id"], record["session_id"], record["kind"], record["schema"], body))
|
|
146
|
+
existing = db.execute("SELECT body FROM records WHERE id=?", (record["id"],)).fetchone()
|
|
147
|
+
if existing[0] != body:
|
|
148
|
+
raise RecordError("record identity collision")
|
|
149
|
+
return record["id"]
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
def _row(db, sid, identifier):
|
|
153
|
+
"""(kind, schema, body) of one indexed record: a v3/v2 row first, then a legacy circuit row."""
|
|
154
|
+
if _exists(db, "records"):
|
|
155
|
+
row = db.execute("SELECT kind, schema, body FROM records WHERE session_id=? AND id=?",
|
|
156
|
+
(sid, identifier)).fetchone()
|
|
157
|
+
if row is not None:
|
|
158
|
+
return row["kind"], row["schema"], row["body"]
|
|
159
|
+
if _exists(db, "circuit_records"):
|
|
160
|
+
row = db.execute("SELECT kind, body FROM circuit_records WHERE session_id=? AND id=?",
|
|
161
|
+
(sid, identifier)).fetchone()
|
|
162
|
+
if row is not None:
|
|
163
|
+
return row["kind"], LEGACY_CIRCUIT, row["body"]
|
|
164
|
+
return None
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
def _verified(project, sid, identifier, kind, schema, body):
|
|
168
|
+
identity, execution = _binding(project, sid)
|
|
169
|
+
value = parse_line(body, "record index row") # size first; not JSON, a huge integer, deep
|
|
170
|
+
# nesting or a duplicate key are RecordErrors
|
|
171
|
+
if schema in SCHEMAS:
|
|
172
|
+
if value.get("schema") != schema:
|
|
173
|
+
raise RecordError("record index row differs from its schema column")
|
|
174
|
+
value = load_record(value, execution=execution)
|
|
175
|
+
if value["id"] != identifier or value["kind"] != kind or value["session_id"] != sid:
|
|
176
|
+
raise RecordError("record index row differs from its seal")
|
|
177
|
+
elif schema in LEGACY_SCHEMAS:
|
|
178
|
+
value = verify_legacy(value, identifier)
|
|
179
|
+
if value.get("kind") != kind or value.get("session_id") != sid:
|
|
180
|
+
raise RecordError("legacy record index row differs from its seal")
|
|
181
|
+
else:
|
|
182
|
+
raise RecordError(f"unknown record schema {schema!r}")
|
|
183
|
+
if not _same_binding(value, identity, execution):
|
|
184
|
+
raise RecordError("record seal or session binding changed")
|
|
185
|
+
return value
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
def get_record(project, sid, identifier):
|
|
189
|
+
"""A verified record: a logical v3 or v2 envelope, or a legacy circuit record
|
|
190
|
+
``{record_id, **body}``."""
|
|
191
|
+
with _connect(project) as db:
|
|
192
|
+
row = _row(db, sid, identifier)
|
|
193
|
+
if row is None:
|
|
194
|
+
raise NotIndexed(f"record {identifier} is not indexed in session {sid}")
|
|
195
|
+
return _verified(project, sid, identifier, *row)
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
def list_records(project, sid, *, kind=None, schema=None, strict=False):
|
|
199
|
+
"""Verified records of a session: legacy circuit records (their rowid order), then v3/v2.
|
|
200
|
+
|
|
201
|
+
The two kinds live in different tables, so their relative insertion order is not kept:
|
|
202
|
+
legacy rows come first, each group in insertion order. Missing tables read as empty.
|
|
203
|
+
|
|
204
|
+
One bad row never fails the whole listing. A row that cannot be returned verified is a
|
|
205
|
+
placeholder in its position, ``{id, kind, schema, verified: False, state, reason}``:
|
|
206
|
+
``state`` ``"unresolved"`` when its kind is not declared in this process (another process
|
|
207
|
+
may declare it), ``"refused"`` when it fails verification for any other reason (a tampered
|
|
208
|
+
seal, a changed session binding). ``strict=True`` raises on the first such row instead, as
|
|
209
|
+
``get_record`` does.
|
|
210
|
+
"""
|
|
211
|
+
project.session(sid)
|
|
212
|
+
rows = []
|
|
213
|
+
with _connect(project) as db:
|
|
214
|
+
if _exists(db, "circuit_records"):
|
|
215
|
+
rows += [(r[0], r[1], LEGACY_CIRCUIT, r[2]) for r in db.execute(
|
|
216
|
+
"SELECT id, kind, body FROM circuit_records WHERE session_id=? ORDER BY rowid",
|
|
217
|
+
(sid,))]
|
|
218
|
+
if _exists(db, "records"):
|
|
219
|
+
rows += [tuple(r) for r in db.execute(
|
|
220
|
+
"SELECT id, kind, schema, body FROM records WHERE session_id=? ORDER BY rowid",
|
|
221
|
+
(sid,))]
|
|
222
|
+
out = []
|
|
223
|
+
for i, k, s, b in rows:
|
|
224
|
+
if (kind is not None and k != kind) or (schema is not None and s != schema):
|
|
225
|
+
continue
|
|
226
|
+
if not strict and s in SCHEMAS and kind_spec(k) is None:
|
|
227
|
+
out.append({"id": i, "kind": k, "schema": s, "verified": False, "state": "unresolved",
|
|
228
|
+
"reason": f"record kind {k!r} is not declared in this process"})
|
|
229
|
+
continue
|
|
230
|
+
try:
|
|
231
|
+
out.append(_verified(project, sid, i, k, s, b))
|
|
232
|
+
except (RecordError, ValueError, KeyError, TypeError, RecursionError) as error:
|
|
233
|
+
if strict:
|
|
234
|
+
raise
|
|
235
|
+
out.append({"id": i, "kind": k, "schema": s, "verified": False, "state": "refused",
|
|
236
|
+
"reason": str(error)})
|
|
237
|
+
return out
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
# --------------------------------------------------------------------------- cursor
|
|
241
|
+
|
|
242
|
+
def set_cursor(project, sid, record_id):
|
|
243
|
+
"""Point the session cursor at an indexed record."""
|
|
244
|
+
_writable(project)
|
|
245
|
+
get_record(project, sid, record_id)
|
|
246
|
+
ensure_tables(project)
|
|
247
|
+
with _connect(project) as db:
|
|
248
|
+
db.execute("INSERT INTO cursor VALUES (?,?) ON CONFLICT(session_id) "
|
|
249
|
+
"DO UPDATE SET record_id=excluded.record_id", (sid, record_id))
|
|
250
|
+
return record_id
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
def get_cursor(project, sid):
|
|
254
|
+
"""The record id under the session cursor, or None when no cursor is set."""
|
|
255
|
+
project.session(sid)
|
|
256
|
+
with _connect(project) as db:
|
|
257
|
+
if not _exists(db, "cursor"):
|
|
258
|
+
return None
|
|
259
|
+
row = db.execute("SELECT record_id FROM cursor WHERE session_id=?", (sid,)).fetchone()
|
|
260
|
+
return None if row is None else row[0]
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
# --------------------------------------------------------------------------- recipes
|
|
264
|
+
|
|
265
|
+
def recipe_fingerprint(body):
|
|
266
|
+
"""The ``native_replay_recipe.fingerprint`` convention (sha256 of ASCII canonical JSON)."""
|
|
267
|
+
import hashlib
|
|
268
|
+
|
|
269
|
+
text = json.dumps(body, sort_keys=True, separators=(",", ":"), allow_nan=False)
|
|
270
|
+
return hashlib.sha256(text.encode()).hexdigest()
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
def put_recipe(project, sid, recipe):
|
|
274
|
+
"""Index a recipe (sealed with ``fingerprint`` or sealed here); returns its id.
|
|
275
|
+
|
|
276
|
+
Recipes are content-addressed and global to the project: the same recipe saved from two
|
|
277
|
+
sessions is stored once, under the first session.
|
|
278
|
+
"""
|
|
279
|
+
_writable(project)
|
|
280
|
+
project.session(sid)
|
|
281
|
+
value = json.loads(json.dumps(recipe, allow_nan=False))
|
|
282
|
+
if not isinstance(value, dict):
|
|
283
|
+
raise RecordError("a recipe is a JSON object")
|
|
284
|
+
expected = value.pop("fingerprint", None)
|
|
285
|
+
identifier = recipe_fingerprint(value)
|
|
286
|
+
if expected is not None and expected != identifier:
|
|
287
|
+
raise RecordError("recipe seal differs from its content")
|
|
288
|
+
sealed = {**value, "fingerprint": identifier}
|
|
289
|
+
body = _text(sealed)
|
|
290
|
+
if len(body.encode()) > MAX_RECIPE_BYTES:
|
|
291
|
+
raise RecordError(f"recipe exceeds {MAX_RECIPE_BYTES} bytes")
|
|
292
|
+
ensure_tables(project)
|
|
293
|
+
with _connect(project) as db:
|
|
294
|
+
db.execute("INSERT OR IGNORE INTO recipes VALUES (?,?,?)", (identifier, sid, body))
|
|
295
|
+
existing = db.execute("SELECT body FROM recipes WHERE id=?", (identifier,)).fetchone()
|
|
296
|
+
if existing[0] != body:
|
|
297
|
+
raise RecordError("recipe identity collision")
|
|
298
|
+
return identifier
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
def recipe_ids(project, sid):
|
|
302
|
+
"""Ids of the recipes indexed under a session, in insertion order."""
|
|
303
|
+
project.session(sid)
|
|
304
|
+
with _connect(project) as db:
|
|
305
|
+
if not _exists(db, "recipes"):
|
|
306
|
+
return []
|
|
307
|
+
return [r[0] for r in db.execute(
|
|
308
|
+
"SELECT id FROM recipes WHERE session_id=? ORDER BY rowid", (sid,))]
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
def get_recipe(project, identifier):
|
|
312
|
+
"""A verified recipe by id."""
|
|
313
|
+
with _connect(project) as db:
|
|
314
|
+
row = (db.execute("SELECT body FROM recipes WHERE id=?", (identifier,)).fetchone()
|
|
315
|
+
if _exists(db, "recipes") else None)
|
|
316
|
+
if row is None:
|
|
317
|
+
raise NotIndexed(f"recipe {identifier} is not indexed")
|
|
318
|
+
value = json.loads(row[0])
|
|
319
|
+
body = {k: v for k, v in value.items() if k != "fingerprint"}
|
|
320
|
+
if value.get("fingerprint") != identifier or recipe_fingerprint(body) != identifier:
|
|
321
|
+
raise RecordError("recipe seal differs from its index id")
|
|
322
|
+
return value
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
# --------------------------------------------------------------------------- occurrences
|
|
326
|
+
|
|
327
|
+
_OCCURRENCE_COLUMNS = ("recipe_id", "event_id", "cut_id", "blob_id")
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
def _occurrence_key(address, ports, global_ports, layers):
|
|
331
|
+
from . import address as addresses
|
|
332
|
+
from .pointers import _occurrence_address
|
|
333
|
+
|
|
334
|
+
occurrence = _occurrence_address(address, ports, global_ports)
|
|
335
|
+
if not isinstance(occurrence, addresses.Occurrence):
|
|
336
|
+
raise RecordError("only port occurrences are indexed (a state cell has no clock)")
|
|
337
|
+
try:
|
|
338
|
+
occurrence = addresses.value_key(occurrence, layers=layers)
|
|
339
|
+
except addresses.AddressError as error:
|
|
340
|
+
raise RecordError(f"occurrence address: {error}") from error
|
|
341
|
+
return addresses.format_address(occurrence)
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
def index_occurrence(project, sid, address, *, layers, recipe_id=None, event_id=None, cut_id=None,
|
|
345
|
+
blob_id=None, ports=None, global_ports=None):
|
|
346
|
+
"""Record where an occurrence value can be found or rebuilt.
|
|
347
|
+
|
|
348
|
+
Keyed by the canonical address text. Re-indexing may fill fields that were null; a field
|
|
349
|
+
that is already set must not change. ``blob_id`` must name a tensor in the project store.
|
|
350
|
+
Address text is parsed against ``ports``/``global_ports`` (default: the Qwen2 list).
|
|
351
|
+
``layers`` (the model's layer count) is required: the row is keyed by ``address.value_key``,
|
|
352
|
+
so ``tN.emb`` and ``tN.L0.h`` (or ``tN.Lk.h_out`` and ``tN.L{k+1}.h``) are one row, equal
|
|
353
|
+
selected sets (``h=1|2``, ``h=1:3``) are one row, and a resolved logits token is ``i``.
|
|
354
|
+
"""
|
|
355
|
+
_writable(project)
|
|
356
|
+
project.session(sid)
|
|
357
|
+
key = _occurrence_key(address, ports, global_ports, layers)
|
|
358
|
+
if event_id is not None and (isinstance(event_id, bool) or not isinstance(event_id, int)
|
|
359
|
+
or event_id < 0):
|
|
360
|
+
raise RecordError("event_id must be a non-negative recipe event index")
|
|
361
|
+
if cut_id is not None:
|
|
362
|
+
cut_id = _sha(cut_id, "cut id")
|
|
363
|
+
if blob_id is not None:
|
|
364
|
+
blob_id = _sha(blob_id, "blob id")
|
|
365
|
+
if not project.store.has_tensor(blob_id, verify=True):
|
|
366
|
+
raise RecordError(f"tensor {blob_id} is not in the project store (or is corrupt)")
|
|
367
|
+
if recipe_id is not None:
|
|
368
|
+
with _connect(project) as db:
|
|
369
|
+
if not _exists(db, "recipes") or db.execute(
|
|
370
|
+
"SELECT 1 FROM recipes WHERE id=?", (recipe_id,)).fetchone() is None:
|
|
371
|
+
raise RecordError(f"recipe {recipe_id} is not indexed")
|
|
372
|
+
ensure_tables(project)
|
|
373
|
+
new = dict(zip(_OCCURRENCE_COLUMNS, (recipe_id, event_id, cut_id, blob_id)))
|
|
374
|
+
with _connect(project) as db:
|
|
375
|
+
db.execute("BEGIN IMMEDIATE")
|
|
376
|
+
row = db.execute("SELECT * FROM occurrences WHERE session_id=? AND address=?",
|
|
377
|
+
(sid, key)).fetchone()
|
|
378
|
+
merged = dict(new)
|
|
379
|
+
if row is not None:
|
|
380
|
+
for column in _OCCURRENCE_COLUMNS:
|
|
381
|
+
old = row[column]
|
|
382
|
+
if old is not None and new[column] is not None and old != new[column]:
|
|
383
|
+
raise RecordError(f"occurrence {key} already has a different {column}")
|
|
384
|
+
merged[column] = old if new[column] is None else new[column]
|
|
385
|
+
db.execute("INSERT INTO occurrences VALUES (?,?,?,?,?,?) "
|
|
386
|
+
"ON CONFLICT(session_id, address) DO UPDATE SET recipe_id=excluded.recipe_id, "
|
|
387
|
+
"event_id=excluded.event_id, cut_id=excluded.cut_id, blob_id=excluded.blob_id",
|
|
388
|
+
(sid, key, *(merged[c] for c in _OCCURRENCE_COLUMNS)))
|
|
389
|
+
return {"session_id": sid, "address": key, **merged}
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
def find_occurrence(project, sid, address, *, layers, ports=None, global_ports=None):
|
|
393
|
+
"""The index row for an occurrence, or None when it was never indexed.
|
|
394
|
+
|
|
395
|
+
``layers`` (required): look up under ``value_key`` (see ``index_occurrence``)."""
|
|
396
|
+
key = _occurrence_key(address, ports, global_ports, layers)
|
|
397
|
+
project.session(sid)
|
|
398
|
+
with _connect(project) as db:
|
|
399
|
+
if not _exists(db, "occurrences"):
|
|
400
|
+
return None
|
|
401
|
+
row = db.execute("SELECT * FROM occurrences WHERE session_id=? AND address=?",
|
|
402
|
+
(sid, key)).fetchone()
|
|
403
|
+
return None if row is None else dict(row)
|
mdb/core/kinds.py
ADDED
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
"""Record kinds of the analysis layer, declared where every reader finds them.
|
|
2
|
+
|
|
3
|
+
``mdb.core.records`` loads this module, so a process that only reads a project (no torch, no
|
|
4
|
+
``mdb.analysis``) can verify ``forecast``, ``whatif``, ``circuit`` and ``symbol-table``
|
|
5
|
+
records. The analysis modules use these same constants; re-declaring an identical spec is a
|
|
6
|
+
no-op and a different one fails, so the two can never drift apart silently.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
from .records import declare_kind
|
|
12
|
+
|
|
13
|
+
# The prefill split a record's numbers were computed under: ``prefill`` prompt rows
|
|
14
|
+
# batched, ``first_row`` the run's first stepped row (its root), ``prompt_rows`` the prompt
|
|
15
|
+
# length. Optional in every kind below (records written before the split was recorded lack it;
|
|
16
|
+
# their cut fingerprint alone binds the split); ``sweep`` requires it.
|
|
17
|
+
PROCEDURE = ("procedure.prefill", "procedure.first_row", "procedure.prompt_rows")
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def procedure(run) -> dict:
|
|
21
|
+
"""The ``procedure`` field of a record about ``run``: its prefill split as plain data."""
|
|
22
|
+
prefill = int(run.prefill)
|
|
23
|
+
rows = len(run.tokens)
|
|
24
|
+
first = int(getattr(run, "first_row", prefill))
|
|
25
|
+
batched = "no row batched" if prefill == 0 else f"rows 0..{prefill - 1} batched"
|
|
26
|
+
out = {"prefill": prefill, "first_row": first, "prompt_rows": rows,
|
|
27
|
+
"default": prefill == rows - 1,
|
|
28
|
+
"text": f"prefill={prefill}: {batched}, first stepped row t{first}"}
|
|
29
|
+
origin = getattr(run, "from_checkpoint", None)
|
|
30
|
+
if origin is not None:
|
|
31
|
+
# the run is rooted at a checkpoint whose path is trusted, not recomputed, until
|
|
32
|
+
# verified (``Run.from_checkpoint``)
|
|
33
|
+
out["from_checkpoint"] = dict(origin)
|
|
34
|
+
return out
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
FORECAST = declare_kind(
|
|
38
|
+
"forecast",
|
|
39
|
+
required=("schema", "target", "sealed_at", "method", "operands", "predicted", "bound"),
|
|
40
|
+
plain_numeric=("sealed_at.row", "sealed_at.index", "sealed_at.transition",
|
|
41
|
+
"sealed_at.receipts.count", "target.row", "target.index", "target.indices",
|
|
42
|
+
"operands.*.shape", "predicted.shape", "predicted.token",
|
|
43
|
+
"edits_at_seal.*.row", "edits_at_seal.*.layer",
|
|
44
|
+
"method.summary.count", "method.summary.global_steps.count",
|
|
45
|
+
"method.summary.proof_counts.*.count", "method.summary.layer_counts.*.layer",
|
|
46
|
+
"method.summary.layer_counts.*.count", "method.summary.chain_pointer.bytes",
|
|
47
|
+
"operands_summary.count", "operands_summary.listed",
|
|
48
|
+
"operands_summary.rest.count", "operands_summary.pointer.bytes",
|
|
49
|
+
"emulated.shape", "emulated.token", "emulated.rounding_origin.head",
|
|
50
|
+
"staged.count", "staged.included.*.*.row", "staged.included.*.*.layer",
|
|
51
|
+
"staged.included.*.*.value.shape", "staged.included.cells.*.rows",
|
|
52
|
+
"staged.included.cells.*.kv", "staged.included.cells.*.d",
|
|
53
|
+
*PROCEDURE),
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
WHATIF = declare_kind(
|
|
57
|
+
"whatif",
|
|
58
|
+
required=("schema", "edit", "consumer", "sealed_at", "mode", "prediction"),
|
|
59
|
+
plain_numeric=("edit.row", "edit.layer", "edit.mask_count", "edit.shape", "consumer.row",
|
|
60
|
+
"consumer.index", "consumer.indices", "sealed_at.row", "sealed_at.index",
|
|
61
|
+
"sealed_at.transition", "operands.*.shape", "edit.cell.**",
|
|
62
|
+
"edit.origin.shape", "operands_summary.count", "operands_summary.listed",
|
|
63
|
+
"operands_summary.rest.count", "operands_summary.pointer.bytes", *PROCEDURE),
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
CIRCUIT = declare_kind(
|
|
67
|
+
"circuit",
|
|
68
|
+
required=("schema", "consumer", "where", "root", "closure"),
|
|
69
|
+
plain_numeric=("k", "depth", "count", "edits.count", *PROCEDURE),
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
# ``circuit test ID ref=NAME``: a circuit patched natively from a reference run (or a prompt
|
|
73
|
+
# set's mean). Every number is labelled; the component list is a sha256-checked blob.
|
|
74
|
+
CIRCUIT_TEST = declare_kind(
|
|
75
|
+
"circuit-test",
|
|
76
|
+
required=("schema", "circuit", "consumer", "where", "reference", "components", "margins",
|
|
77
|
+
"resolution", "ratios"),
|
|
78
|
+
plain_numeric=PROCEDURE,
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
SYMBOL_TABLE = declare_kind(
|
|
82
|
+
"symbol-table",
|
|
83
|
+
required=("schema", "where", "consumer", "bindings", "unbound", "page"),
|
|
84
|
+
plain_numeric=("page.offset", "page.limit", "page.total", "rows", "bindings.*.rows",
|
|
85
|
+
"bindings.*.token", "bindings.*.omitted", "bindings.*.count",
|
|
86
|
+
"accounting.heads", *PROCEDURE, "bindings.*.content.*.best",
|
|
87
|
+
"bindings.*.content.*.size", "bindings.*.content.*.truth_rank",
|
|
88
|
+
"bindings.*.content.vocab_top.tokens", "bindings.*.hop.edge.mlp.*.layer",
|
|
89
|
+
"bindings.*.hop.edge.mlp.*.omitted.count", "bindings.*.hop.edge.reread.*.layer",
|
|
90
|
+
"bindings.*.hop.edge.mlp.*.spectral.bins",
|
|
91
|
+
"bindings.*.hop.edge.mlp.*.spectral.top_bins",
|
|
92
|
+
"bindings.*.hop.edge.mlp.*.spectral.neurons_at_same_fraction",
|
|
93
|
+
# candidate flags, nulls, co-readouts, switched
|
|
94
|
+
# readouts, foreign names, feature components, candidate-set provenance
|
|
95
|
+
"bindings.*.content.*.truth", "bindings.*.content.*.lexical_null.best",
|
|
96
|
+
"bindings.*.content.*.lexical_null.truth_rank",
|
|
97
|
+
"bindings.*.content.*.lexical_null.source_token",
|
|
98
|
+
"bindings.*.content.*.co.*.rank", "bindings.*.content.*.co.*.*.best",
|
|
99
|
+
"bindings.*.content.*.co.*.*.truth_rank",
|
|
100
|
+
"bindings.*.content.*.switched.best", "bindings.*.content.*.switched.truth",
|
|
101
|
+
"bindings.*.content.*.switched.decoded",
|
|
102
|
+
"bindings.*.content.*.switched.truth_rank",
|
|
103
|
+
"bindings.*.labels.**", "bindings.*.position", "bindings.*.full.bytes",
|
|
104
|
+
"bindings.*.full.tensor.shape.*",
|
|
105
|
+
"bindings.*.pieces_of_word.index", "bindings.*.pieces_of_word.count", "bindings.*.foreign.**", "bindings.*.readers.*.foreign.**",
|
|
106
|
+
"bindings.*.finite.full.bytes", "bindings.*.finite.full.tensor.shape.*",
|
|
107
|
+
"bindings.*.causal.doses.policy.n", "bindings.*.causal.doses.policy.budget",
|
|
108
|
+
"bindings.*.causal.doses.policy.tokens", "bindings.*.causal.doses.runs",
|
|
109
|
+
"bindings.*.causal.doses.points.*.winner",
|
|
110
|
+
"bindings.*.causal.doses.points.*.predicted",
|
|
111
|
+
"bindings.*.causal.doses.winners",
|
|
112
|
+
"bindings.*.causal.doses.envelope.segments.*.winner",
|
|
113
|
+
"bindings.*.causal.doses.envelope.omitted",
|
|
114
|
+
"interactions.order", "interactions.runs",
|
|
115
|
+
"ledger.rows", "ledger.count",
|
|
116
|
+
"labels.**", "candidate_sets.*.size", "candidate_sets.*.truth",
|
|
117
|
+
"candidate_sets.*.words_collide_within", "candidate_sets.*.multi_piece_words",
|
|
118
|
+
"candidate_sets.*.first_tokens_shared_across",
|
|
119
|
+
"components.*.reader_row", "components.*.components.*.feature",
|
|
120
|
+
"components.*.components.*.saelens.feature",
|
|
121
|
+
"components.*.components.*.ct_node.**", "components.*.basis.k",
|
|
122
|
+
"components.*.components.*.content.*.best",
|
|
123
|
+
"components.*.components.*.content.*.size",
|
|
124
|
+
"components.*.components.*.content.*.truth_rank",
|
|
125
|
+
"components.*.components.*.content.vocab_top.tokens",
|
|
126
|
+
# machine backends (mdb.machines): a binding over site-bit x
|
|
127
|
+
# tick-interval cells (docs/SYMBOL-TABLE-SCHEMA.md "Machine bindings")
|
|
128
|
+
"bindings.*.cells.**", "bindings.*.n_cells", "bindings.*.weight",
|
|
129
|
+
"bindings.*.lifetime.**", "bindings.*.cells_full.**", "unbound.**",
|
|
130
|
+
"machine.**", "method.**"),
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
# ``symbol NAME = whatif|compare.a|EACH:ITEM``: a named symbol declared from a transplant
|
|
134
|
+
# result: the writer without its row (role), the source row (role-relative or absolute, with the
|
|
135
|
+
# prompt's and prefix's sha256), the readers as ``reads`` lists them, the consumer and the
|
|
136
|
+
# measured effect, the donor and the run. Labelled numbers and pointers only.
|
|
137
|
+
SYMBOL = declare_kind(
|
|
138
|
+
"symbol",
|
|
139
|
+
required=("schema", "name", "role", "row", "consumer", "evidence", "origin"),
|
|
140
|
+
plain_numeric=("role.writer.layer", "role.readers.rows", "role.readers.count",
|
|
141
|
+
"role.readers.listed.*.row", "role.readers.listed.*.layer", "row.row",
|
|
142
|
+
"row.token", "row.prompt_rows", "consumer.row", "consumer.indices",
|
|
143
|
+
*PROCEDURE),
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
# ``sweep PORT rows= layers= = ORIGIN --consumer C``: the position x layer patching table.
|
|
147
|
+
# The table itself is a sha256-checked JSON blob (``table``, a ``core.bounded`` pointer);
|
|
148
|
+
# the record keeps the base, the top cells, the cost and the procedure of both runs.
|
|
149
|
+
SWEEP = declare_kind(
|
|
150
|
+
"sweep",
|
|
151
|
+
required=("schema", "port", "origin", "consumer", "stop", "rows", "layers", "base", "top",
|
|
152
|
+
"table", "cost", "procedure"),
|
|
153
|
+
plain_numeric=("top.*.row", "top.*.layer", "cells.count", *PROCEDURE,
|
|
154
|
+
*(p.replace("procedure", "origin_procedure") for p in PROCEDURE)),
|
|
155
|
+
)
|
|
156
|
+
|
|
157
|
+
# ``supplied-forecast``: a scalar forecast made by a library
|
|
158
|
+
# (nnsight gradient x activation, a transcoder edge, a TL patch) sealed beside mdb's own exact and
|
|
159
|
+
# linear terms before the native arm runs. ``supplied`` is the library's number with its
|
|
160
|
+
# library, version and the address map it used; ``exact``/``linear`` are mdb's, when computed.
|
|
161
|
+
SUPPLIED_FORECAST = declare_kind(
|
|
162
|
+
"supplied-forecast",
|
|
163
|
+
required=("schema", "target", "edit", "supplied", "library", "address_map", "sealed_at"),
|
|
164
|
+
plain_numeric=("target.row", "target.indices", "edit.row", "edit.layer", *PROCEDURE),
|
|
165
|
+
)
|
|
166
|
+
|
|
167
|
+
# Sealed traces, watch hits and circuit maps.
|
|
168
|
+
# The payload (a trace's per-step records; a watch's per-step truth values; a map's exact JSON)
|
|
169
|
+
# is a sha256-checked JSON blob (``core.bounded.put_json``); the record keeps what a reader
|
|
170
|
+
# needs to find and check it: counts, names, predicate texts and the payload's sha256.
|
|
171
|
+
TRACE = declare_kind(
|
|
172
|
+
"trace",
|
|
173
|
+
required=("schema", "trace_kind", "count", "payload", "sha256"),
|
|
174
|
+
plain_numeric=("count", "payload.bytes", "payload.tensor.shape.*", "meta.**",
|
|
175
|
+
"columns.count"),
|
|
176
|
+
)
|
|
177
|
+
|
|
178
|
+
WATCH_HITS = declare_kind(
|
|
179
|
+
"watch-hits",
|
|
180
|
+
required=("schema", "trace", "predicate", "mode", "n", "hits"),
|
|
181
|
+
plain_numeric=("n", "hits", "hits_omitted", "fired_at", "fired_index", "crossings",
|
|
182
|
+
"undefined", "payload.bytes", "payload.tensor.shape.*"),
|
|
183
|
+
)
|
|
184
|
+
|
|
185
|
+
CIRCUIT_MAP = declare_kind(
|
|
186
|
+
"circuit-map",
|
|
187
|
+
required=("schema", "digest", "slots", "edges", "payload"),
|
|
188
|
+
plain_numeric=("slots.**", "candidate_sets.*.size", "n_items", "payload.bytes",
|
|
189
|
+
"payload.tensor.shape.*", "table.bytes", "table.tensor.shape.*"),
|
|
190
|
+
)
|
|
191
|
+
|
|
192
|
+
# Debugger objects. ``branches``: named native branches from
|
|
193
|
+
# one checkpoint, every arm measured at one consumer against ONE floor, with its edits (origins
|
|
194
|
+
# included), holds, kernel path and effect in floors. ``pool``: values collected at one address
|
|
195
|
+
# over a prompt set, one per item with its origin, as a sha256-checked blob. Both always carry
|
|
196
|
+
# ``custody``.
|
|
197
|
+
BRANCHES = declare_kind(
|
|
198
|
+
"branches",
|
|
199
|
+
required=("schema", "name", "at", "consumer", "base", "floor", "arms", "custody"),
|
|
200
|
+
plain_numeric=("at.row", "at.transitions", "at.path_edits.**",
|
|
201
|
+
"at.path_cells.**", "consumer.row", "consumer.a", "consumer.b",
|
|
202
|
+
"consumer.i", "arms.*.argmax", "arms.*.edits.**", "arms.*.cells.**",
|
|
203
|
+
"arms.*.holds.**", "arms.*.stepped.argmax",
|
|
204
|
+
"base.argmax", "arms_omitted", "n_arms", *PROCEDURE),
|
|
205
|
+
)
|
|
206
|
+
|
|
207
|
+
POOL = declare_kind(
|
|
208
|
+
"pool",
|
|
209
|
+
required=("schema", "name", "address", "items", "items_sha256", "payload", "custody"),
|
|
210
|
+
plain_numeric=("n", "shape.*", "payload.bytes", "payload.tensor.shape.*", "items.**",
|
|
211
|
+
"labels.**", "items_omitted", "duplicates"),
|
|
212
|
+
)
|
|
213
|
+
|
|
214
|
+
# ``core-file``: a run's prefix (K/V of every layer at a row start, the prompt,
|
|
215
|
+
# captured values) written once; the record holds every tensor's sha256 so a reload is checked.
|
|
216
|
+
CORE_FILE = declare_kind(
|
|
217
|
+
"core-file",
|
|
218
|
+
required=("schema", "split", "prompt", "shape", "source", "tensors", "custody"),
|
|
219
|
+
plain_numeric=("split.row", "split.tokens", "prompt.tokens", "prompt.length", "shape.**",
|
|
220
|
+
"procedure.**", "path_edits.**", "post_split_edits", "tensors.count"),
|
|
221
|
+
)
|
|
222
|
+
|
|
223
|
+
# ``checkpoint-state`` (``mdb.engine.checkpoint``): a run's state at a cut as
|
|
224
|
+
# content-addressed tensors. The record holds the sha256 of the state document and of every
|
|
225
|
+
# tensor part (``tensors.sha256``: packed hex, 60 digests per string), the cut and root
|
|
226
|
+
# fingerprints, the prompt digest, the procedure, the lineage and custody.
|
|
227
|
+
CHECKPOINT_STATE = declare_kind(
|
|
228
|
+
"checkpoint-state",
|
|
229
|
+
required=("schema", "where", "cut", "root", "history", "prompt", "procedure", "shape",
|
|
230
|
+
"lineage", "recipe", "document", "tensors", "custody"),
|
|
231
|
+
plain_numeric=("cut.transitions", "cut.row", "root.transitions", "root.row", "marks",
|
|
232
|
+
"stored_cuts", "prompt.tokens", "prompt.length", "shape.**", "recipe.**",
|
|
233
|
+
"document.bytes", "document.tensor.shape.*", "tensors.count",
|
|
234
|
+
"lineage.**", *PROCEDURE),
|
|
235
|
+
)
|
|
236
|
+
|
|
237
|
+
# ``each`` over a prompt set: the summary record (``mdb.ops.sets``). Declared here so a reader
|
|
238
|
+
# (and ``mdb records migrate``) verifies it without running ``each`` first.
|
|
239
|
+
PROMPT_SET = declare_kind(
|
|
240
|
+
"prompt-set",
|
|
241
|
+
required=("set", "line", "items", "statistics"),
|
|
242
|
+
plain_numeric=("items.*.bytes", "items.*.prefill", "items.*.blob.bytes",
|
|
243
|
+
"items.*.blob.tensor.shape.*", "total", "statistics.n",
|
|
244
|
+
"items_blob.bytes", "items_blob.tensor.shape.*",
|
|
245
|
+
"items_omitted", "shard.k", "shard.n", "shard.items", "shard.set_total",
|
|
246
|
+
"statistics.numeric.*.n", "statistics.numeric.*.agree.count",
|
|
247
|
+
"statistics.numeric.*.by_authority.*.n",
|
|
248
|
+
"statistics.numeric.*.by_authority.*.agree.count",
|
|
249
|
+
"statistics.verdicts.*.counts.*.count",
|
|
250
|
+
"statistics.omitted.count", "statistics.partial.count"),
|
|
251
|
+
)
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
__all__ = ["BRANCHES", "CHECKPOINT_STATE", "CORE_FILE", "POOL", "CIRCUIT", "CIRCUIT_MAP", "TRACE", "WATCH_HITS", "CIRCUIT_TEST", "FORECAST", "PROCEDURE", "PROMPT_SET", "SUPPLIED_FORECAST", "SWEEP", "SYMBOL", "SYMBOL_TABLE",
|
|
255
|
+
"WHATIF", "procedure"]
|