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/serve/states.py
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"""Cuts held by ``checkpoint-state`` records (``mdb.engine.checkpoint``), read for ``mdb serve``.
|
|
2
|
+
|
|
3
|
+
``Debugger.checkpoint`` stores the state of a cut as a sealed ``checkpoint-state`` record whose
|
|
4
|
+
document (a JSON blob) lists every kept trail mark's native cut (boundary, parent, execution
|
|
5
|
+
point, surface) and its payload, each tensor as parts that are ``put_tensor`` blobs of the
|
|
6
|
+
store. It stores no native cut beside it, so the recorded frame and timeline read these too: a
|
|
7
|
+
kept mark is a cut with the same id (its fingerprint) and the same descriptor fields as a native
|
|
8
|
+
one, and a slot tensor is its parts read verified (the record's seal, the document's sha256,
|
|
9
|
+
each part's payload sha256 against the document) and concatenated along the tensor's axis.
|
|
10
|
+
|
|
11
|
+
Nothing is recomputed: the fingerprint is the one the sealed record names (the engine recomputes
|
|
12
|
+
it from the content when it rehydrates the state; serve has no engine). Read-only, numpy only.
|
|
13
|
+
"""
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
from typing import Any
|
|
17
|
+
|
|
18
|
+
from . import blobs
|
|
19
|
+
|
|
20
|
+
KIND = "checkpoint-state"
|
|
21
|
+
SCHEMA = "mdb-checkpoint-v2"
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class StateCuts:
|
|
25
|
+
"""The kept marks of every ``checkpoint-state`` record of one session, by fingerprint
|
|
26
|
+
(first record wins), and ``cursor``: the newest record's cut."""
|
|
27
|
+
|
|
28
|
+
def __init__(self, project: Any, sid: str):
|
|
29
|
+
from ..core import index
|
|
30
|
+
from ..core.bounded import load_json
|
|
31
|
+
from ..core.kinds import CHECKPOINT_STATE # noqa: F401 (declares the kind)
|
|
32
|
+
|
|
33
|
+
self.project, self.store_root = project, project.store.root
|
|
34
|
+
self.cuts: dict[str, dict[str, Any]] = {}
|
|
35
|
+
self.cursor: str | None = None
|
|
36
|
+
self.problems: list[str] = []
|
|
37
|
+
for record in index.list_records(project, sid, kind=KIND):
|
|
38
|
+
body = record.get("body") or {}
|
|
39
|
+
if record.get("verified") is False or body.get("schema") != SCHEMA:
|
|
40
|
+
continue
|
|
41
|
+
try:
|
|
42
|
+
doc = load_json(body["document"], store=project.store)
|
|
43
|
+
marks = doc["marks"]
|
|
44
|
+
if (marks[-1]["fingerprint"] != body["cut"]["fingerprint"]
|
|
45
|
+
or marks[0]["fingerprint"] != body["root"]["fingerprint"]):
|
|
46
|
+
raise ValueError("document marks differ from the record")
|
|
47
|
+
except (ValueError, KeyError, TypeError, IndexError, OSError) as error:
|
|
48
|
+
self.problems.append(f"checkpoint {record['id'][:16]}: {error}")
|
|
49
|
+
continue
|
|
50
|
+
for i, mark in enumerate(marks):
|
|
51
|
+
cut = mark.get("cut")
|
|
52
|
+
if cut is None or mark["fingerprint"] in self.cuts:
|
|
53
|
+
continue
|
|
54
|
+
self.cuts[mark["fingerprint"]] = {
|
|
55
|
+
"descriptor": {
|
|
56
|
+
"fingerprint": mark["fingerprint"], "manifest": None,
|
|
57
|
+
"model_identity": doc["model_identity"], "parent": cut["parent"],
|
|
58
|
+
"boundary": cut["boundary"],
|
|
59
|
+
"execution_point": cut["execution_point"] or {},
|
|
60
|
+
"surface": cut["surface"] or {},
|
|
61
|
+
"checkpoint": {"record": record["id"], "mark": i, "name": doc["name"]}},
|
|
62
|
+
"payload": cut["payload"], "tensors": doc["tensors"],
|
|
63
|
+
"parts": doc["parts"], "record": record["id"]}
|
|
64
|
+
self.cursor = marks[-1]["fingerprint"]
|
|
65
|
+
|
|
66
|
+
def __contains__(self, cut: str) -> bool:
|
|
67
|
+
return cut in self.cuts
|
|
68
|
+
|
|
69
|
+
def slot_names(self, cut: str) -> set[str]:
|
|
70
|
+
payload = self.cuts[cut]["payload"]
|
|
71
|
+
return set(payload.get("items") or {}) if payload.get("kind") == "mapping" else set()
|
|
72
|
+
|
|
73
|
+
def _tensor(self, cut: str, slot: str, item: int | None) -> dict[str, Any]:
|
|
74
|
+
entry = self.cuts[cut]
|
|
75
|
+
encoded = (entry["payload"].get("items") or {}).get(slot)
|
|
76
|
+
if encoded is None:
|
|
77
|
+
raise blobs.BlobError(f"cut {cut[:12]} retains no slot {slot!r}")
|
|
78
|
+
kind = encoded.get("kind")
|
|
79
|
+
if kind in ("list", "tuple"):
|
|
80
|
+
items = encoded.get("items") or []
|
|
81
|
+
if item is None:
|
|
82
|
+
raise blobs.BlobError(f"slot {slot!r} is a sequence of {len(items)}; give an "
|
|
83
|
+
"item index")
|
|
84
|
+
if not 0 <= item < len(items):
|
|
85
|
+
raise blobs.BlobError(f"slot {slot!r} has no tensor at item {item}")
|
|
86
|
+
encoded = items[item]
|
|
87
|
+
elif item is not None and kind == "tensor":
|
|
88
|
+
raise blobs.BlobError(f"slot {slot!r} holds one tensor; no item index")
|
|
89
|
+
if encoded.get("kind") == "scalar":
|
|
90
|
+
raise blobs.BlobError(f"slot {slot!r} holds no tensor at this cut (scalar "
|
|
91
|
+
f"{encoded.get('value')!r})")
|
|
92
|
+
if encoded.get("kind") != "tensor":
|
|
93
|
+
raise blobs.BlobError(f"slot {slot!r} has unsupported kind {encoded.get('kind')!r}")
|
|
94
|
+
return entry["tensors"][encoded["t"]]
|
|
95
|
+
|
|
96
|
+
def slot_info(self, cut: str, slot: str, item: int | None = None) -> dict[str, Any]:
|
|
97
|
+
desc = self._tensor(cut, slot, item)
|
|
98
|
+
root = self.store_root
|
|
99
|
+
for index in desc["parts"]:
|
|
100
|
+
ref = self.cuts[cut]["parts"][index]["ref"]
|
|
101
|
+
if not blobs._store_file(root / "tensors" / f"{blobs._hex(ref, 'ref')}.safetensors"):
|
|
102
|
+
raise blobs.BlobError(f"slot {slot!r} part {ref[:12]} is not in the store")
|
|
103
|
+
return {"shape": list(desc["shape"]), "dtype": desc["dtype"]}
|
|
104
|
+
|
|
105
|
+
def cut_slot(self, cut: str, slot: str, item: int | None = None):
|
|
106
|
+
"""``(array, info)``: the slot tensor from its parts, each verified."""
|
|
107
|
+
import numpy as np
|
|
108
|
+
|
|
109
|
+
desc = self._tensor(cut, slot, item)
|
|
110
|
+
pointers = [self.cuts[cut]["parts"][i] for i in desc["parts"]]
|
|
111
|
+
arrays = []
|
|
112
|
+
for pointer in pointers:
|
|
113
|
+
array, info = blobs.tensor_blob(self.store_root, pointer["ref"])
|
|
114
|
+
if info["sha256"] != pointer["sha256"] or list(info["shape"]) != pointer["shape"]:
|
|
115
|
+
raise blobs.BlobError("checkpoint part differs from its document", refused=True)
|
|
116
|
+
arrays.append(np.asarray(array))
|
|
117
|
+
full = arrays[0] if len(arrays) == 1 else np.concatenate(arrays, axis=desc["axis"])
|
|
118
|
+
if list(full.shape) != list(desc["shape"]):
|
|
119
|
+
raise blobs.BlobError("checkpoint tensor parts differ from its shape", refused=True)
|
|
120
|
+
record = self.cuts[cut]["record"]
|
|
121
|
+
return full, {"shape": list(desc["shape"]), "dtype": desc["dtype"], "sha256": None,
|
|
122
|
+
"via": [f"cut {cut[:12]}", f"checkpoint {record[:12]}",
|
|
123
|
+
f"slot {slot}" + ("" if item is None else f"[{item}]"),
|
|
124
|
+
f"{len(pointers)} part(s)",
|
|
125
|
+
"each part's sha256 verified against the sealed document"]}
|