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/engine/bundle.py
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"""Bundles: a named checkpoint and the records that reference it, as one directory another project
|
|
2
|
+
imports (``export NAME to=DIR``; ``start from=DIR`` or ``Debugger.import_bundle(DIR)``).
|
|
3
|
+
|
|
4
|
+
Layout (a ``core.checkpoint_store.DirectoryStore`` plus a manifest and the recipe)::
|
|
5
|
+
|
|
6
|
+
<dir>/bundle.json schema, name, the checkpoint-state record id, the
|
|
7
|
+
checkpoint record and recipe ids (or null), record ids
|
|
8
|
+
<dir>/tensors/<sha256>.safetensors blobs: the state's document and parts, the recipe's
|
|
9
|
+
edit tensors and token ids, the records' tensor pointers
|
|
10
|
+
<dir>/records/<record id>.json sealed records
|
|
11
|
+
<dir>/recipes/<fingerprint>.json the replay recipe of the named checkpoint
|
|
12
|
+
|
|
13
|
+
The records that reference the checkpoint are every record of the project whose sealed JSON names
|
|
14
|
+
the checkpoint-state record id (a record about a run started from it carries the id in
|
|
15
|
+
``custody.from_checkpoint``). Blobs are checked against their sha256 and records against their
|
|
16
|
+
seals both ways (``checkpoint_store``); importing twice is a no-op.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
from __future__ import annotations
|
|
20
|
+
|
|
21
|
+
import json
|
|
22
|
+
from pathlib import Path
|
|
23
|
+
from typing import Any
|
|
24
|
+
|
|
25
|
+
SCHEMA = "mdb-bundle-v1"
|
|
26
|
+
MANIFEST = "bundle.json"
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def is_bundle(path: Any) -> bool:
|
|
30
|
+
return isinstance(path, (str, Path)) and (Path(path).expanduser() / MANIFEST).is_file()
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def _send(source: Any, target: Any, shas: list[str]) -> None:
|
|
34
|
+
for sha in dict.fromkeys(shas):
|
|
35
|
+
if not target.has(sha):
|
|
36
|
+
target.put(sha, source.get(sha))
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _recipe_blobs(recipe: dict[str, Any]) -> list[str]:
|
|
40
|
+
from mdb.core import recipe as recipes
|
|
41
|
+
|
|
42
|
+
refs = [p["ref"] for p in recipes.tensor_pointers(recipe)]
|
|
43
|
+
if isinstance(recipe["tokens"], dict):
|
|
44
|
+
refs.append(recipe["tokens"]["ref"])
|
|
45
|
+
return refs
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def _tensor_refs(record: dict[str, Any]) -> list[str]:
|
|
49
|
+
return [p["ref"] for p in record.get("pointers", ()) if p.get("kind") == "tensor"]
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def write(project: Any, name: str, path: Any, *, session_id: str | None = None) -> dict[str, Any]:
|
|
53
|
+
"""Write checkpoint ``name`` of ``project`` (``session_id``'s first, as ``restart``) and the
|
|
54
|
+
records that reference it to the directory ``path``; returns the manifest."""
|
|
55
|
+
from mdb.core import checkpoint_store as stores
|
|
56
|
+
from mdb.core import index
|
|
57
|
+
from mdb.core import recipe as recipes
|
|
58
|
+
|
|
59
|
+
from .checkpoint import find_named
|
|
60
|
+
|
|
61
|
+
state = find_named(project, name, session_id=session_id)
|
|
62
|
+
if state is None:
|
|
63
|
+
raise ValueError(f"no checkpoint named {name!r} in project {project.root} (checkpoint "
|
|
64
|
+
"NAME stores one)")
|
|
65
|
+
out = Path(path).expanduser().absolute()
|
|
66
|
+
if out.exists() and any(out.iterdir()):
|
|
67
|
+
raise ValueError(f"{out} is not empty: export writes a new bundle directory")
|
|
68
|
+
local, target = stores.ProjectStore(project), stores.DirectoryStore(out)
|
|
69
|
+
stores.copy(state, None, local, target)
|
|
70
|
+
checkpoint = recipes.find_checkpoint(project, name, session_id=state["session_id"])
|
|
71
|
+
recipe = None
|
|
72
|
+
if checkpoint is not None and checkpoint["body"]["cut"] == state["body"]["cut"]["fingerprint"]:
|
|
73
|
+
recipe = recipes.load(project, checkpoint["body"]["recipe"])
|
|
74
|
+
_send(local, target, _recipe_blobs(recipe))
|
|
75
|
+
target._put(f"recipes/{recipe['fingerprint']}.json",
|
|
76
|
+
json.dumps(recipe, sort_keys=True).encode())
|
|
77
|
+
target.put_record(checkpoint)
|
|
78
|
+
else:
|
|
79
|
+
checkpoint = None
|
|
80
|
+
referencing = []
|
|
81
|
+
for session in project.sessions():
|
|
82
|
+
for record in index.list_records(project, session["session_id"]):
|
|
83
|
+
if record.get("verified") is False or "pointers" not in record \
|
|
84
|
+
or record["id"] == state["id"] or state["id"] not in json.dumps(record):
|
|
85
|
+
continue
|
|
86
|
+
_send(local, target, _tensor_refs(record))
|
|
87
|
+
target.put_record(record)
|
|
88
|
+
referencing.append(record["id"])
|
|
89
|
+
manifest = {"schema": SCHEMA, "name": name, "state": state["id"],
|
|
90
|
+
"checkpoint": None if checkpoint is None else checkpoint["id"],
|
|
91
|
+
"recipe": None if recipe is None else recipe["fingerprint"],
|
|
92
|
+
"records": referencing}
|
|
93
|
+
(out / MANIFEST).write_text(json.dumps(manifest, indent=1, sort_keys=True) + "\n")
|
|
94
|
+
return manifest
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def read(project: Any, path: Any) -> dict[str, Any]:
|
|
98
|
+
"""Import the bundle at ``path`` into ``project``: blobs, the recipe, every record (each
|
|
99
|
+
opens its session under the record's model identity and execution). Returns the
|
|
100
|
+
checkpoint-state record as the project indexes it."""
|
|
101
|
+
from mdb.core import checkpoint_store as stores
|
|
102
|
+
from mdb.core import kinds # noqa: F401 (declares the record kinds a bundle may hold)
|
|
103
|
+
from mdb.core import recipe as recipes
|
|
104
|
+
|
|
105
|
+
from .checkpoint import find_record
|
|
106
|
+
|
|
107
|
+
root = Path(path).expanduser().absolute()
|
|
108
|
+
manifest = json.loads((root / MANIFEST).read_text())
|
|
109
|
+
if manifest.get("schema") != SCHEMA:
|
|
110
|
+
raise ValueError(f"{root} is not an {SCHEMA} bundle (schema {manifest.get('schema')!r})")
|
|
111
|
+
source, local = stores.DirectoryStore(root), stores.ProjectStore(project)
|
|
112
|
+
|
|
113
|
+
def record(identifier: str) -> dict[str, Any]:
|
|
114
|
+
found = source.find_record(identifier)
|
|
115
|
+
if found is None or found["id"] != identifier:
|
|
116
|
+
raise ValueError(f"bundle {root} lacks record {identifier}")
|
|
117
|
+
return found
|
|
118
|
+
|
|
119
|
+
state = record(manifest["state"])
|
|
120
|
+
stores.copy(state, None, source, local)
|
|
121
|
+
if manifest["recipe"] is not None:
|
|
122
|
+
data = source._get(f"recipes/{manifest['recipe']}.json")
|
|
123
|
+
if data is None:
|
|
124
|
+
raise ValueError(f"bundle {root} lacks recipe {manifest['recipe']}")
|
|
125
|
+
recipe = json.loads(data)
|
|
126
|
+
checkpoint = record(manifest["checkpoint"])
|
|
127
|
+
_send(source, local, _recipe_blobs(recipe))
|
|
128
|
+
local.put_record(checkpoint)
|
|
129
|
+
recipes.save(project, checkpoint["session_id"], recipe)
|
|
130
|
+
for identifier in manifest["records"]:
|
|
131
|
+
found = record(identifier)
|
|
132
|
+
_send(source, local, _tensor_refs(found))
|
|
133
|
+
local.put_record(found)
|
|
134
|
+
return find_record(project, state["id"])
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
__all__ = ["MANIFEST", "SCHEMA", "is_bundle", "read", "write"]
|