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/resolve.py
ADDED
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
"""Resolve an occurrence pointer to its tensor (``mdb.resolve``), cheapest source first.
|
|
2
|
+
|
|
3
|
+
Tiers, tried in ``TIERS`` order (``tiers=`` picks a subset, in that order):
|
|
4
|
+
|
|
5
|
+
1. ``live``: the attached debugger's live run already holds the value in its port cache
|
|
6
|
+
(``Run.row_captures``; nothing is computed). Only for the attached session's own origin, and
|
|
7
|
+
only when the live run reached the occurrence from the pointer's cut with the recipe's edits.
|
|
8
|
+
2. ``blob``: the project's occurrence index (``mdb.core.index.find_occurrence``) names a tensor
|
|
9
|
+
blob for the address, recorded under the pointer's recipe and cut.
|
|
10
|
+
3. ``cut``: the pointer's cut is retained in the project store; the model restarts from it and
|
|
11
|
+
a read-only probe computes the value (needs the live model).
|
|
12
|
+
4. ``replay``: the recipe is replayed from the token ids (needs the live model).
|
|
13
|
+
|
|
14
|
+
Every answer is checked against the pointer's recorded payload digest (``value.sha256``, when
|
|
15
|
+
set): a different digest is a refusal and no later tier is tried. A resolved value carries the
|
|
16
|
+
tier that answered and its authority: what ``Run.read_info`` reports for the value in the
|
|
17
|
+
computing tiers (``measured`` for a value no edit wrote), the pointer's own ``authority`` (else
|
|
18
|
+
``measured``) for a stored blob.
|
|
19
|
+
|
|
20
|
+
Origins. An address with no origin, or with the attached session's id as its branch, reads the
|
|
21
|
+
attached session. Any other branch ``b`` is resolved only through a recipe for ``b`` held in
|
|
22
|
+
the project (a session ``b`` that indexed the pointer's recipe or has a cursor, or a checkpoint
|
|
23
|
+
named ``b``); otherwise the pointer is refused, never answered from the attached session. (The
|
|
24
|
+
core address mapping ``to_state_address`` does not look at origins; this module is the guard.)
|
|
25
|
+
An ``@cut`` origin must name the pointer's own cut. An edited origin ``@cut+ref+ref`` (a value
|
|
26
|
+
read under edits: ``mdb.core.recipe.edit_ref`` of each edit applied in the transition that
|
|
27
|
+
computes it) also needs the pointer's recipe and event, and every tier first checks that the
|
|
28
|
+
recipe applies exactly those edits at that event (``RecipeError("origin-edits")`` otherwise):
|
|
29
|
+
an edited value resolves bitwise or is refused, never to the value without its edits.
|
|
30
|
+
|
|
31
|
+
Without a live model tiers 3 and 4 cannot run: when 1 and 2 cannot answer either, the result is
|
|
32
|
+
``unresolved`` and ``needs`` says what would resolve it. This module needs no framework; the
|
|
33
|
+
computing tiers call the attached debugger (``mdb.ops.debugger.Debugger``) passed as
|
|
34
|
+
``session=``.
|
|
35
|
+
"""
|
|
36
|
+
from __future__ import annotations
|
|
37
|
+
|
|
38
|
+
import hashlib
|
|
39
|
+
from dataclasses import dataclass, field, replace
|
|
40
|
+
from pathlib import Path
|
|
41
|
+
from typing import Any
|
|
42
|
+
|
|
43
|
+
from . import address as addresses
|
|
44
|
+
from . import index
|
|
45
|
+
from . import recipe as recipes
|
|
46
|
+
from .errors import Refused
|
|
47
|
+
from .pointers import RecordError, Unresolved, validate_occurrence_pointer
|
|
48
|
+
|
|
49
|
+
TIERS = ("live", "blob", "cut", "replay")
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
@dataclass
|
|
53
|
+
class Resolution:
|
|
54
|
+
"""The outcome of one ``resolve``: ``state`` is ``resolved``, ``unresolved`` or ``refused``.
|
|
55
|
+
|
|
56
|
+
``value`` (a tensor), ``tier`` and ``authority`` are set only when resolved; ``reason`` says
|
|
57
|
+
why not otherwise and ``needs`` what would resolve an unresolved pointer. ``attempts`` lists
|
|
58
|
+
each tier tried, ``{tier, state, reason}``.
|
|
59
|
+
"""
|
|
60
|
+
state: str
|
|
61
|
+
value: Any = None
|
|
62
|
+
tier: str | None = None
|
|
63
|
+
authority: str | None = None
|
|
64
|
+
sha256: str | None = None
|
|
65
|
+
reason: str | None = None
|
|
66
|
+
needs: str | None = None
|
|
67
|
+
attempts: list = field(default_factory=list)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
class _Refusal(Exception):
|
|
71
|
+
def __init__(self, reason):
|
|
72
|
+
self.reason = reason
|
|
73
|
+
super().__init__(reason)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def _digest(value):
|
|
77
|
+
"""sha256 of the raw little-endian bytes (``mdb.engine.ports.tensor_digest``)."""
|
|
78
|
+
raw = value.detach().cpu().contiguous().reshape(-1).view(__import__("torch").uint8)
|
|
79
|
+
return hashlib.sha256(raw.numpy().tobytes()).hexdigest()
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def _open(project, session):
|
|
83
|
+
if project is None:
|
|
84
|
+
project = getattr(session, "project", None)
|
|
85
|
+
if project is None:
|
|
86
|
+
raise _Refusal("resolving an occurrence pointer needs project= (or a debugger attached "
|
|
87
|
+
"with project=)")
|
|
88
|
+
if isinstance(project, (str, Path)):
|
|
89
|
+
mine = getattr(session, "project", None)
|
|
90
|
+
if mine is not None and mine.root == Path(project).expanduser().resolve():
|
|
91
|
+
return mine
|
|
92
|
+
from .project import Project
|
|
93
|
+
|
|
94
|
+
return Project(project, read_only=True)
|
|
95
|
+
return project
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def recipes_for(project, branch, current):
|
|
99
|
+
"""Recipe ids that stand for origin ``branch``: recipes indexed by session ``branch``, the
|
|
100
|
+
recipe under its cursor, and the recipes of checkpoints named ``branch``."""
|
|
101
|
+
found = []
|
|
102
|
+
sessions = {r["session_id"] for r in project.sessions()}
|
|
103
|
+
if branch in sessions:
|
|
104
|
+
found += index.recipe_ids(project, branch)
|
|
105
|
+
cursor = index.get_cursor(project, branch)
|
|
106
|
+
if cursor is not None:
|
|
107
|
+
found.append(index.get_record(project, branch, cursor)["body"]["recipe"])
|
|
108
|
+
named = recipes.find_checkpoint(project, branch, session_id=current)
|
|
109
|
+
if named is not None:
|
|
110
|
+
found.append(named["body"]["recipe"])
|
|
111
|
+
return list(dict.fromkeys(found))
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def _target(pointer, occurrence, project, session):
|
|
115
|
+
"""``(session id the value belongs to, recipe id, own)``: ``own`` when that is the attached
|
|
116
|
+
session (so its live run may answer)."""
|
|
117
|
+
current = getattr(session, "session_id", None)
|
|
118
|
+
origin = occurrence.origin
|
|
119
|
+
wanted = pointer["recipe"]
|
|
120
|
+
if origin is not None and origin.cut is not None:
|
|
121
|
+
if origin.cut != pointer["cut"]:
|
|
122
|
+
raise _Refusal(f"origin @{origin.cut[:12]} is not this pointer's cut")
|
|
123
|
+
if origin.edits and wanted is None:
|
|
124
|
+
raise _Refusal(f"origin @{origin.cut[:12]}+{len(origin.edits)} edit(s): the pointer "
|
|
125
|
+
"names no recipe, so its edits cannot be reproduced: it was read "
|
|
126
|
+
"without a writable project, and the edit values (a tensor supplied "
|
|
127
|
+
"or taken from another run) were never stored. Read it again with "
|
|
128
|
+
"the debugger attached with project= (mdb.attach(model, project="
|
|
129
|
+
"PATH)): the recipe and every edit tensor are then stored as blobs")
|
|
130
|
+
if origin.edits and pointer["event"] is None:
|
|
131
|
+
raise _Refusal("an edited origin needs the pointer's recipe event")
|
|
132
|
+
origin = None
|
|
133
|
+
if origin is None or origin.branch == current:
|
|
134
|
+
if wanted is None and current is not None:
|
|
135
|
+
cursor = index.get_cursor(project, current)
|
|
136
|
+
if cursor is not None:
|
|
137
|
+
wanted = index.get_record(project, current, cursor)["body"]["recipe"]
|
|
138
|
+
return current, wanted, current is not None
|
|
139
|
+
branch = origin.branch
|
|
140
|
+
candidates = recipes_for(project, branch, current)
|
|
141
|
+
if not candidates:
|
|
142
|
+
raise _Refusal(f"address origin {branch}: is not the attached session "
|
|
143
|
+
f"{current!r} and the project holds no recipe for {branch!r}; it is "
|
|
144
|
+
"not read from the attached session")
|
|
145
|
+
if wanted is not None and wanted not in candidates:
|
|
146
|
+
raise _Refusal(f"the pointer's recipe {wanted[:12]} is not a recipe for origin "
|
|
147
|
+
f"{branch}:")
|
|
148
|
+
return branch, wanted or candidates[-1], False
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def _layers(session, recipe):
|
|
152
|
+
adapter = getattr(session, "adapter", None)
|
|
153
|
+
return recipe["layers"] if recipe is not None else getattr(adapter, "layers", None)
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def resolve(pointer, *, project=None, session=None, tiers=TIERS):
|
|
157
|
+
"""Resolve an occurrence pointer; returns a ``Resolution`` (see the module docstring).
|
|
158
|
+
|
|
159
|
+
``project``: an ``mdb.core.project.Project`` or its path (opened read-only), default the
|
|
160
|
+
attached debugger's. ``session``: the attached debugger (``mdb.attach(..., project=)``),
|
|
161
|
+
needed for the ``live``, ``cut`` and ``replay`` tiers.
|
|
162
|
+
"""
|
|
163
|
+
unknown = [t for t in tiers if t not in TIERS]
|
|
164
|
+
if unknown or not tiers:
|
|
165
|
+
raise ValueError(f"tiers are a non-empty subset of {', '.join(TIERS)}")
|
|
166
|
+
attempts = []
|
|
167
|
+
|
|
168
|
+
def refused(reason):
|
|
169
|
+
return Resolution("refused", reason=reason, attempts=attempts)
|
|
170
|
+
|
|
171
|
+
try:
|
|
172
|
+
pointer = validate_occurrence_pointer(pointer)
|
|
173
|
+
occurrence = addresses.from_json(pointer["address"], check_ports=False)
|
|
174
|
+
project = _open(project, session)
|
|
175
|
+
sid, recipe_id, own = _target(pointer, occurrence, project, session)
|
|
176
|
+
recipe = recipes.load(project, recipe_id) if recipe_id is not None else None
|
|
177
|
+
except (_Refusal, RecordError, addresses.AddressError, index.NotIndexed) as error:
|
|
178
|
+
return refused(str(getattr(error, "reason", error)))
|
|
179
|
+
except ValueError as error: # an unopenable project, an unknown session
|
|
180
|
+
return refused(str(error))
|
|
181
|
+
expected = pointer["value"]["sha256"]
|
|
182
|
+
text = addresses.format_address(replace(occurrence, origin=None, program=None))
|
|
183
|
+
port = (occurrence.port if occurrence.layer is not None and occurrence.port != "h_out"
|
|
184
|
+
else None)
|
|
185
|
+
origin = occurrence.origin
|
|
186
|
+
edits = list(origin.edits) if origin is not None and origin.cut is not None else None
|
|
187
|
+
context = {"pointer": pointer, "recipe": recipe, "address": text, "port": port,
|
|
188
|
+
"selected": bool(occurrence.selector), "edits": edits,
|
|
189
|
+
"sid": sid, "own": own, "project": project, "session": session}
|
|
190
|
+
for tier in tiers:
|
|
191
|
+
try:
|
|
192
|
+
value, authority = _TIER[tier](context)
|
|
193
|
+
except (_Refusal, Refused) as error:
|
|
194
|
+
attempts.append({"tier": tier, "state": "refused", "reason": error.reason})
|
|
195
|
+
return refused(error.reason)
|
|
196
|
+
except Unresolved as error:
|
|
197
|
+
attempts.append({"tier": tier, "state": "unresolved", "reason": error.reason})
|
|
198
|
+
continue
|
|
199
|
+
got = _digest(value)
|
|
200
|
+
if expected is not None and got != expected:
|
|
201
|
+
reason = (f"the {tier} tier produced digest {got[:12]}, the pointer records "
|
|
202
|
+
f"{expected[:12]} (digest mismatch)")
|
|
203
|
+
attempts.append({"tier": tier, "state": "refused", "reason": reason})
|
|
204
|
+
return refused(reason)
|
|
205
|
+
attempts.append({"tier": tier, "state": "resolved", "reason": None})
|
|
206
|
+
state = "refused" if authority is None else "resolved"
|
|
207
|
+
return Resolution(state, value=value if authority else None, tier=tier,
|
|
208
|
+
authority=authority, sha256=got, attempts=attempts,
|
|
209
|
+
reason=None if authority else f"the {tier} value's label was refused")
|
|
210
|
+
model = getattr(getattr(session, "adapter", None), "model_identity", None)
|
|
211
|
+
needs = None
|
|
212
|
+
if model is None and any(t in tiers for t in ("cut", "replay")):
|
|
213
|
+
identity = recipe["model_identity"] if recipe is not None else "the recorded model"
|
|
214
|
+
needs = (f"attach the model with identity {str(identity)[:16]} (same numeric scope) "
|
|
215
|
+
"and pass session= so the cut or replay tier can compute the value")
|
|
216
|
+
return Resolution("unresolved", reason="; ".join(f"{a['tier']}: {a['reason']}"
|
|
217
|
+
for a in attempts),
|
|
218
|
+
needs=needs, attempts=attempts)
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
# --------------------------------------------------------------------------- tiers
|
|
222
|
+
|
|
223
|
+
def _engine(context, tier):
|
|
224
|
+
session = context["session"]
|
|
225
|
+
if getattr(session, "adapter", None) is None:
|
|
226
|
+
raise Unresolved(f"the {tier} tier needs the attached debugger (session=) and its model")
|
|
227
|
+
if context["recipe"] is None:
|
|
228
|
+
raise Unresolved("the pointer names no recipe and the session has no cursor recipe")
|
|
229
|
+
if context["pointer"]["event"] is None:
|
|
230
|
+
raise Unresolved("the pointer records no recipe event")
|
|
231
|
+
if context["selected"]:
|
|
232
|
+
raise Unresolved("an address with selectors is resolved from a stored blob only")
|
|
233
|
+
return session
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
def _checkpoint(context):
|
|
237
|
+
pointer = context["pointer"]
|
|
238
|
+
try:
|
|
239
|
+
return recipes.occurrence_checkpoint(context["recipe"], where=context["address"],
|
|
240
|
+
cut=pointer["cut"], event=pointer["event"],
|
|
241
|
+
port=context["port"], edits=context["edits"])
|
|
242
|
+
except recipes.RecipeError as error:
|
|
243
|
+
raise _Refusal(str(error)) from error
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
def _live(context):
|
|
247
|
+
session = _engine(context, "live")
|
|
248
|
+
if not context["own"]:
|
|
249
|
+
raise Unresolved("the live run belongs to another session than the address origin")
|
|
250
|
+
return session.live_occurrence(_checkpoint(context))
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
def _blob(context):
|
|
254
|
+
project, pointer, recipe = context["project"], context["pointer"], context["recipe"]
|
|
255
|
+
if context["edits"]:
|
|
256
|
+
_checkpoint(context) # the recipe must apply the origin's edits (else refused)
|
|
257
|
+
layers = _layers(context["session"], recipe)
|
|
258
|
+
if context["sid"] is None or layers is None:
|
|
259
|
+
raise Unresolved("no session or layer count to look the occurrence up under")
|
|
260
|
+
row = index.find_occurrence(project, context["sid"], pointer["address"], layers=layers)
|
|
261
|
+
if row is None or row["blob_id"] is None:
|
|
262
|
+
raise Unresolved("no stored blob is indexed for this occurrence")
|
|
263
|
+
for column, mine in (("recipe_id", pointer["recipe"]), ("cut_id", pointer["cut"])):
|
|
264
|
+
if mine is not None and row[column] is not None and row[column] != mine:
|
|
265
|
+
raise Unresolved(f"the stored blob was recorded under another {column}")
|
|
266
|
+
try:
|
|
267
|
+
if not project.store.has_tensor(row["blob_id"]):
|
|
268
|
+
raise Unresolved(f"blob {row['blob_id']} is missing from the store")
|
|
269
|
+
value = project.store.get_tensor(row["blob_id"], framework="torch")
|
|
270
|
+
except ValueError as error:
|
|
271
|
+
raise _Refusal(f"blob {row['blob_id']} is corrupt: {error}") from error
|
|
272
|
+
return value, pointer.get("authority", "measured")
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
def _cut(context):
|
|
276
|
+
session = _engine(context, "cut")
|
|
277
|
+
cut_id = context["pointer"]["cut"]
|
|
278
|
+
if cut_id is None:
|
|
279
|
+
raise Unresolved("the pointer records no cut")
|
|
280
|
+
project = context["project"]
|
|
281
|
+
holders = [s["session_id"] for s in project.sessions()]
|
|
282
|
+
for sid in [context["sid"], *holders]:
|
|
283
|
+
if sid is not None and cut_id in project.cut_ids(sid):
|
|
284
|
+
return session.compute_occurrence(_checkpoint(context), context["recipe"],
|
|
285
|
+
project.store, root=project.load_cut(sid, cut_id))
|
|
286
|
+
raise Unresolved(f"cut {cut_id[:12]} is not retained in the project")
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
def _replay(context):
|
|
290
|
+
session = _engine(context, "replay")
|
|
291
|
+
return session.compute_occurrence(_checkpoint(context), context["recipe"],
|
|
292
|
+
context["project"].store, root=None)
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
_TIER = {"live": _live, "blob": _blob, "cut": _cut, "replay": _replay}
|
|
296
|
+
_recipes_for = recipes_for # old private name, kept for one commit
|