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
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
"""The accumulation precision a matmul ``bound`` may assume, from the run's numeric scope.
|
|
2
|
+
|
|
3
|
+
Every ``bound`` on a native matmul (``forecast``/``propagate`` affine maps, scores and value
|
|
4
|
+
mixes; ``reads`` value-mix and head-write checks; ``circuits`` down_proj remainders;
|
|
5
|
+
``explain``'s head bound) uses the Higham sum bound ``|fl(sum) - sum| <= gamma_n sum |terms|``,
|
|
6
|
+
``gamma_n = n u / (1 - n u)``, with ``u`` the unit roundoff of the precision the partial sums are
|
|
7
|
+
kept in. For a 16-bit model that is float32 only when the backend keeps them in float32:
|
|
8
|
+
|
|
9
|
+
* CUDA with ``torch.backends.cuda.matmul.allow_bf16_reduced_precision_reduction`` (or the fp16
|
|
10
|
+
twin) True, the torch default: cuBLAS may round partial sums (split-K) to the 16-bit dtype. The
|
|
11
|
+
split count is not observable, so the premise is the worst case, every partial sum rounded to
|
|
12
|
+
the model dtype: ``u = 2^-8`` (bf16) or ``2^-11`` (fp16). ``gamma_n`` then exists only for
|
|
13
|
+
``n u < 1`` (n < 256 terms in bf16); a longer sum has no bound and the bound is refused.
|
|
14
|
+
Unless the run's scope holds a measurement (``numeric_scope["accumulation"]``, made when the
|
|
15
|
+
adapter was built by ``saturn.numerics.measure_accumulation``: native linear stages
|
|
16
|
+
recomputed at batch 1 and compared with float32-accumulate-then-round). When it supports
|
|
17
|
+
fp32-then-round the premise is that, ``u = 2^-24``, labelled measured, and ``gamma`` widens by
|
|
18
|
+
the measured deviation (``max_deviation_milli``/1000, in ``eps x sum|terms|``) where it is not zero. When it does not
|
|
19
|
+
support it, the per-partial-sum premise above stands and its refusal carries the measurement.
|
|
20
|
+
* CUDA float32 with TF32 allowed (``tf32_matmul`` True or ``float32_matmul_precision`` not
|
|
21
|
+
``highest``): products of TF32-rounded inputs, which the float32 premise does not cover: refused.
|
|
22
|
+
* Otherwise (CPU; CUDA with the flag False): float32 accumulation, ``u = 2^-24``.
|
|
23
|
+
|
|
24
|
+
``scope_flags(owner)`` is the one place the flags are read: the run's recorded numeric scope
|
|
25
|
+
(``adapter.execution["numeric_scope"]``, bound when the adapter was built and checked on every
|
|
26
|
+
native call), falling back to the live torch global when the scope does not record a field.
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
from __future__ import annotations
|
|
30
|
+
|
|
31
|
+
from dataclasses import dataclass
|
|
32
|
+
from typing import Any
|
|
33
|
+
|
|
34
|
+
U32 = 2.0 ** -24
|
|
35
|
+
PREMISE_FAILS = "premise fails: "
|
|
36
|
+
FP32_PREMISE = "matmul accumulates in float32 in any order (gamma_n bound)"
|
|
37
|
+
FIELDS = ("bf16_reduced_precision_reduction", "fp16_reduced_precision_reduction",
|
|
38
|
+
"tf32_matmul", "float32_matmul_precision")
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def _torch():
|
|
42
|
+
import torch
|
|
43
|
+
|
|
44
|
+
return torch
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def _live(field: str) -> Any:
|
|
48
|
+
torch = _torch()
|
|
49
|
+
matmul = getattr(getattr(torch.backends, "cuda", None), "matmul", None)
|
|
50
|
+
if field == "float32_matmul_precision":
|
|
51
|
+
return torch.get_float32_matmul_precision()
|
|
52
|
+
name = {"tf32_matmul": "allow_tf32"}.get(field, f"allow_{field}")
|
|
53
|
+
try:
|
|
54
|
+
return getattr(matmul, name)
|
|
55
|
+
except (AttributeError, RuntimeError):
|
|
56
|
+
return "absent"
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def scope_flags(owner: Any) -> dict[str, tuple[Any, str]]:
|
|
60
|
+
"""``{field: (value, source)}`` for the numeric fields a matmul bound depends on, plus
|
|
61
|
+
``device``. ``owner`` is a ``Run`` or an adapter. Source ``numeric scope`` when the run's
|
|
62
|
+
recorded scope holds the field, else ``torch global`` (the live setting)."""
|
|
63
|
+
adapter = getattr(owner, "adapter", owner)
|
|
64
|
+
execution = getattr(adapter, "execution", None) or {}
|
|
65
|
+
scope = execution.get("numeric_scope") or {}
|
|
66
|
+
out: dict[str, tuple[Any, str]] = {}
|
|
67
|
+
for field in FIELDS:
|
|
68
|
+
if field in scope:
|
|
69
|
+
out[field] = (scope[field], "numeric scope")
|
|
70
|
+
else:
|
|
71
|
+
out[field] = (_live(field), "torch global")
|
|
72
|
+
device = (execution.get("device") or {}).get("type")
|
|
73
|
+
if device is None:
|
|
74
|
+
device = getattr(getattr(adapter, "device", None), "type", "cpu")
|
|
75
|
+
out["device"] = (device, "execution" if execution.get("device") else "adapter")
|
|
76
|
+
return out
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def execution_scope(owner: Any) -> dict[str, Any]:
|
|
80
|
+
"""The run's recorded numeric scope (empty when it holds none)."""
|
|
81
|
+
adapter = getattr(owner, "adapter", owner)
|
|
82
|
+
return dict((getattr(adapter, "execution", None) or {}).get("numeric_scope") or {})
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def _off(value: Any) -> bool:
|
|
86
|
+
"""A flag recorded as off: False, or a list/tuple of Falses (some torch builds return a
|
|
87
|
+
tuple). Anything else, ``"absent"`` included, is taken as possibly on."""
|
|
88
|
+
if isinstance(value, (list, tuple)):
|
|
89
|
+
return bool(value) and all(item is False for item in value)
|
|
90
|
+
return value is False
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
@dataclass(frozen=True)
|
|
94
|
+
class Accumulation:
|
|
95
|
+
"""``u``: unit roundoff of the partial sums a matmul may keep (None: no premise holds, see
|
|
96
|
+
``failure``); ``premise``: the stated accumulation premise of every bound built on it."""
|
|
97
|
+
|
|
98
|
+
u: float | None
|
|
99
|
+
premise: str
|
|
100
|
+
failure: str | None = None
|
|
101
|
+
reduced: bool = False
|
|
102
|
+
deviation: float = 0.0 # measured |native - fp32-then-round| / (eps sum|terms|)
|
|
103
|
+
eps: float = 0.0 # relative ulp of the output dtype (machine epsilon)
|
|
104
|
+
|
|
105
|
+
def gamma(self, n: int) -> float | None:
|
|
106
|
+
"""``gamma_n`` (Higham) of an ``n``-term sum at this precision; None when it does not
|
|
107
|
+
exist (``n u >= 1``) or no premise holds."""
|
|
108
|
+
if self.u is None or n * self.u >= 1.0:
|
|
109
|
+
return None
|
|
110
|
+
base = n * self.u / (1.0 - n * self.u)
|
|
111
|
+
if self.deviation:
|
|
112
|
+
# native = fp32-then-round + at most d eps sum|terms| (measured), so it folds into
|
|
113
|
+
# gamma as d eps (times 1 + gamma: the measured sum|terms| is the float32 one)
|
|
114
|
+
base += self.deviation * self.eps * (1.0 + base)
|
|
115
|
+
return base
|
|
116
|
+
|
|
117
|
+
def refusal(self, n: int) -> str:
|
|
118
|
+
"""Why an ``n``-term sum has no bound under this accumulation."""
|
|
119
|
+
if self.failure is not None:
|
|
120
|
+
return self.failure
|
|
121
|
+
return (f"{PREMISE_FAILS}{self.premise}; an {n}-term sum at u = {self.u:.3g} has no "
|
|
122
|
+
f"gamma_n bound (n u = {n * self.u:.3g} >= 1)")
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def accumulation(owner: Any, dtype: Any = None) -> Accumulation:
|
|
126
|
+
"""The accumulation premise of a native matmul of ``owner`` (a ``Run`` or an adapter) with
|
|
127
|
+
16-bit or float32 inputs of ``dtype`` (default: the model dtype)."""
|
|
128
|
+
torch = _torch()
|
|
129
|
+
adapter = getattr(owner, "adapter", owner)
|
|
130
|
+
dtype = getattr(adapter, "dtype", None) if dtype is None else dtype
|
|
131
|
+
flags = scope_flags(owner)
|
|
132
|
+
device = flags["device"][0]
|
|
133
|
+
if device != "cuda":
|
|
134
|
+
return Accumulation(U32, FP32_PREMISE)
|
|
135
|
+
if dtype in (torch.bfloat16, torch.float16):
|
|
136
|
+
name = "bf16" if dtype == torch.bfloat16 else "fp16"
|
|
137
|
+
field = f"{name}_reduced_precision_reduction"
|
|
138
|
+
value, source = flags[field]
|
|
139
|
+
if _off(value):
|
|
140
|
+
return Accumulation(U32, f"{FP32_PREMISE}: CUDA allow_{field} = False ({source})")
|
|
141
|
+
eps = float(torch.finfo(dtype).eps)
|
|
142
|
+
u = eps / 2.0
|
|
143
|
+
measured = (execution_scope(owner).get("accumulation") or {})
|
|
144
|
+
milli = int(measured.get("max_deviation_milli") or 0)
|
|
145
|
+
if measured.get("dtype") == str(dtype):
|
|
146
|
+
summary = (f"{measured.get('stages')} stages, batch {measured.get('batch')}, "
|
|
147
|
+
f"max deviation {milli / 1000:g} eps sum|terms| "
|
|
148
|
+
f"(ulp-index max {measured.get('max_ulp_index')}); by type "
|
|
149
|
+
f"{ {k: v / 1000 for k, v in (measured.get('by_type_milli') or {}).items()} }")
|
|
150
|
+
if measured.get("premise") == "fp32-then-round":
|
|
151
|
+
return Accumulation(
|
|
152
|
+
U32, f"matmul = fp32 accumulate then round once to {name}, measured on this "
|
|
153
|
+
f"device ({summary}); CUDA allow_{field} = {value!r} ({source}); "
|
|
154
|
+
f"measured on linear stages with synthetic inputs, premise for the "
|
|
155
|
+
f"rest", deviation=milli / 1000.0, eps=eps)
|
|
156
|
+
note = (f" (measurement does not support fp32-then-round: {summary})")
|
|
157
|
+
else:
|
|
158
|
+
note = ""
|
|
159
|
+
state = "True" if value is True else f"{value!r} (not False)"
|
|
160
|
+
return Accumulation(u, f"CUDA allow_{field} = {state} ({source}): cuBLAS may round "
|
|
161
|
+
f"partial sums to {name}, so every partial sum is taken as rounded "
|
|
162
|
+
f"to {name} (u = {u:.3g}), any order{note}", reduced=True)
|
|
163
|
+
if dtype == torch.float32:
|
|
164
|
+
tf32, source = flags["tf32_matmul"]
|
|
165
|
+
precision, psource = flags["float32_matmul_precision"]
|
|
166
|
+
if not _off(tf32) or precision != "highest":
|
|
167
|
+
return Accumulation(None, "float32 matmul", failure=(
|
|
168
|
+
f"{PREMISE_FAILS}CUDA float32 matmul may use TF32 (tf32_matmul = {tf32!r} "
|
|
169
|
+
f"({source}), float32_matmul_precision = {precision!r} ({psource})): products "
|
|
170
|
+
"of TF32-rounded inputs are outside the float32 accumulation premise"))
|
|
171
|
+
return Accumulation(U32, FP32_PREMISE)
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
def bound_state(reason: str | None) -> str:
|
|
175
|
+
"""``refused`` for a bound whose premise fails, else ``unresolved``."""
|
|
176
|
+
return "refused" if reason is not None and reason.startswith(PREMISE_FAILS) else "unresolved"
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
__all__ = ["FP32_PREMISE", "execution_scope", "PREMISE_FAILS", "U32", "Accumulation", "accumulation", "bound_state",
|
|
180
|
+
"scope_flags"]
|