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 @@
|
|
|
1
|
+
:root{color-scheme:light dark;--bg: #fbfbfa;--panel: #ffffff;--panel-2: #f3f3f1;--ink: #1c1c1e;--ink-2: #55555b;--ink-3: #8a8a90;--rule: #dcdcd8;--focus: #1c1c1e;--cursor: #1c1c1e;--cell: #2b2b2f;--cell-empty: transparent;--refused-bg: #f6efe6;--role-symbol: #2f6fb3;--role-input: #4a8a3c;--role-output: #b2462e;--role-intervention: #8a4fb0;--role-state: #5a6270;--role-cache: #b07a1f;--role-other: #7b7b82;--sign-pos: #2f6fb3;--sign-neg: #b2462e;--font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;--mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;--gap: 8px;--radius: 4px}@media(prefers-color-scheme:dark){:root:not([data-theme=light]){--bg: #141416;--panel: #1b1b1e;--panel-2: #232327;--ink: #ececee;--ink-2: #b2b2b8;--ink-3: #7c7c84;--rule: #34343a;--focus: #ececee;--cursor: #ececee;--cell: #d8d8dc;--refused-bg: #2b241c;--role-symbol: #6aa6e6;--role-input: #7fbf6c;--role-output: #e07a62;--role-intervention: #b98ae0;--role-state: #9aa2b0;--role-cache: #e0aa4c;--role-other: #a0a0a8;--sign-pos: #6aa6e6;--sign-neg: #e07a62}}:root[data-theme=dark]{--bg: #141416;--panel: #1b1b1e;--panel-2: #232327;--ink: #ececee;--ink-2: #b2b2b8;--ink-3: #7c7c84;--rule: #34343a;--focus: #ececee;--cursor: #ececee;--cell: #d8d8dc;--refused-bg: #2b241c;--role-symbol: #6aa6e6;--role-input: #7fbf6c;--role-output: #e07a62;--role-intervention: #b98ae0;--role-state: #9aa2b0;--role-cache: #e0aa4c;--role-other: #a0a0a8;--sign-pos: #6aa6e6;--sign-neg: #e07a62}*{box-sizing:border-box}html,body,#root{height:100%;margin:0}body{background:var(--bg);color:var(--ink);font:13px/1.4 var(--font)}button,input,select{font:inherit;color:inherit;background:var(--panel);border:1px solid var(--rule);border-radius:var(--radius);padding:2px 6px}button{cursor:pointer}button:focus-visible,input:focus-visible,select:focus-visible,[tabindex]:focus-visible{outline:2px solid var(--focus);outline-offset:1px}code,.mono{font-family:var(--mono);font-size:12px}.muted{color:var(--ink-2)}.faint{color:var(--ink-3)}table{border-collapse:collapse;width:100%}th,td{text-align:left;padding:3px 6px;border-bottom:1px solid var(--rule);vertical-align:top}th{font-weight:600;color:var(--ink-2)}.ev-chip{display:inline-block;border:1px solid var(--ink-3);border-radius:8px;padding:0 5px;font-size:11px;color:var(--ink-2);margin-left:4px}.num{font-family:var(--mono);font-variant-numeric:tabular-nums}.num>.ev-chip{white-space:normal}.json-str{overflow-wrap:anywhere;word-break:break-all}.num-unresolved{display:inline-block;min-width:3.5em;border:1px dashed var(--ink-3);border-radius:var(--radius);color:var(--ink-3);padding:0 4px;font-size:11px}.num-refused{display:inline-block;background:var(--refused-bg);border-radius:var(--radius);padding:0 4px;font-size:11px}.panel{background:var(--panel);border:1px solid var(--rule);border-radius:var(--radius);overflow:auto;min-height:0;min-width:0}.panel>h2{font-size:12px;margin:0;padding:6px 8px;border-bottom:1px solid var(--rule);position:sticky;top:0;background:var(--panel);z-index:1;display:flex;gap:var(--gap);align-items:center}.panel-body{padding:8px}.chip{display:inline-flex;align-items:center;gap:4px;border:1px solid var(--rule);border-radius:10px;padding:0 6px;font-size:11px;background:var(--panel-2);max-width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.na{border:1px dashed var(--ink-3);border-radius:var(--radius);padding:8px;color:var(--ink-2)}.row-button{all:unset;cursor:pointer;display:block;width:100%}.row-button:focus-visible{outline:2px solid var(--focus)}.selected-row{background:var(--panel-2)}.app{display:grid;height:100%;gap:var(--gap);padding:var(--gap);grid-template-columns:minmax(300px,1.5fr) minmax(0,3fr) minmax(280px,1.2fr);grid-template-rows:auto auto minmax(0,1fr) minmax(120px,34vh);grid-template-areas:"header header header" "banner banner banner" "left centre right" "bottom bottom bottom"}.app-header{grid-area:header;display:flex;flex-wrap:wrap;gap:var(--gap);align-items:center;min-width:0}.address-bar{display:flex;gap:4px;flex:1 1 14em;min-width:0}.address-bar button{flex:none}.address-input{flex:1 1 auto;min-width:0}.header-chip{flex:none;max-width:100%}.app-banner{grid-area:banner}.app-left{grid-area:left;display:grid;min-height:0}.app-centre{grid-area:centre;display:grid;grid-template-rows:minmax(0,1fr) minmax(0,1fr);gap:var(--gap);min-height:0;min-width:0}.app-right{grid-area:right;display:grid;min-height:0}.app-bottom{grid-area:bottom;display:grid;min-height:0}.records-body{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1fr);gap:var(--gap)}.overlay{position:fixed;top:0;right:0;bottom:0;left:0;background:color-mix(in srgb,var(--bg) 70%,transparent);display:flex;align-items:flex-start;justify-content:center;padding-top:10vh;z-index:10}.command{position:fixed;left:50%;top:12vh;transform:translate(-50%);width:min(640px,calc(100vw - 32px));background:var(--panel);border:1px solid var(--rule);border-radius:var(--radius);padding:8px;z-index:11}@media(max-width:900px){.app{grid-template-columns:minmax(0,1fr);grid-template-rows:auto auto auto auto auto auto;grid-template-areas:"header" "banner" "centre" "right" "left" "bottom";height:auto}.app-header{flex-wrap:wrap}.records-body{grid-template-columns:minmax(0,1fr)}}.panel-col{display:flex;flex-direction:column;overflow:hidden}.panel-col-body{flex:1 1 auto;min-height:0;display:flex;flex-direction:column}.panel-scroll{flex:1 1 auto;min-height:0;overflow:auto}.panel-foot{flex:none;padding-top:4px}.arms-table td,.arms-table th{white-space:nowrap}.arms-table>table{min-width:44em}.table-scroll{overflow-x:auto;max-width:100%}.panel-body{min-width:0;overflow-wrap:break-word}.table-scroll>table{min-width:16em}.panel>h2{flex-wrap:wrap}.panel select,.panel input{max-width:100%}.records-body{grid-template-columns:minmax(0,3fr) minmax(26em,2fr)}@media(max-width:900px){.records-body{grid-template-columns:minmax(0,1fr)}}.app-centre-live{grid-template-rows:minmax(0,1fr)}.live{display:grid;gap:var(--gap)}.live h3{font-size:12px;margin:0 0 4px}.live-status{display:flex;flex-wrap:wrap;gap:6px;align-items:baseline}.live-state{margin-left:auto}.live-controls,.live-controls form,.live form{display:flex;flex-wrap:wrap;gap:4px;align-items:center}.live-stops{display:flex;flex-wrap:wrap;gap:2px}.live-stop{font-family:var(--mono);font-size:11px;padding:0 3px;border:1px solid var(--rule);background:transparent;color:var(--ink-3)}.live-stop.done{color:var(--ink);background:var(--panel-2)}.live-stop.here{outline:2px solid var(--cursor);color:var(--ink)}.live-stop[data-edited=yes]{border-style:dashed;border-color:var(--role-intervention)}.live-row-here{outline:1px solid var(--cursor)}.live-port.here{background:var(--panel-2)}.live-port[data-computed=no]{color:var(--ink-3)}.live-tables{display:grid;grid-template-columns:repeat(auto-fit,minmax(240px,1fr));gap:var(--gap)}.live-console pre{max-height:16em;overflow:auto;white-space:pre-wrap;margin:0 0 4px}.linklike{border:none;background:none;padding:0;color:inherit;text-decoration:underline dotted;cursor:pointer;font:inherit}.live-edit-cell{min-width:9em}.live-mark{white-space:normal;overflow:visible;display:inline;line-height:1.6}.live-more{margin:2px 0}.live-clip{max-width:16em;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.live-tabs{display:flex;flex-wrap:wrap;gap:2px;border-bottom:1px solid var(--rule)}.live-tab{border-bottom-left-radius:0;border-bottom-right-radius:0;border-bottom:none;background:transparent}.live-tab.here{background:var(--panel-2);font-weight:600;box-shadow:inset 0 -2px 0 var(--ink)}.live-pane{display:grid;gap:var(--gap);min-width:0}.seek-line{border:1px solid var(--ink-2);border-radius:var(--radius);padding:6px 8px;background:var(--panel-2)}.slot-running{display:flex;gap:6px;align-items:center}.verdict-chip,.status-chip{font-family:var(--mono)}.status-chip.status-edited{border-style:dashed;border-color:var(--role-intervention)}.status-chip.status-unread{color:var(--ink-3)}.arch{display:grid;gap:4px;min-width:0}.arch-grid-wrap{overflow-x:auto;max-width:100%}.arch-grid{width:auto;border-collapse:separate;border-spacing:2px}.arch-grid th,.arch-grid td{padding:0;border:none;font-size:10px;font-weight:400;text-align:center}.arch-grid th[scope=row]{text-align:right;padding-right:4px;color:var(--ink-2)}.arch-here-col{color:var(--ink);font-weight:600!important;text-decoration:underline}.arch-cell,.arch-port{display:inline-block;min-width:18px;height:16px;padding:0 2px;border:1px solid var(--ink-3);border-radius:2px;font-size:10px;line-height:14px;vertical-align:middle}.arch-legend .arch-cell{min-width:12px;height:10px}.arch-full{background:color-mix(in srgb,var(--ink) 28%,var(--panel))}.arch-partial{background:linear-gradient(90deg,color-mix(in srgb,var(--ink) 28%,var(--panel)) 50%,var(--panel) 50%)}.arch-cache{background:repeating-linear-gradient(45deg,var(--panel),var(--panel) 2px,var(--rule) 2px,var(--rule) 4px)}.arch-empty{background:transparent;border-style:dashed}.arch-cursor{outline:2px solid var(--cursor);outline-offset:1px}.arch-node{box-shadow:inset 0 0 0 2px var(--role-symbol)}.arch-ports{display:flex;flex-wrap:wrap;gap:2px;align-items:center}.arch-port{min-width:0;font-family:var(--mono)}.live-symbols,.circuit-view,.predict{display:grid;gap:var(--gap);min-width:0}.symbols-consumer,.circuit-build,.symbols-declare form{display:flex;flex-wrap:wrap;gap:4px;align-items:center}.symbols-table{min-width:40em}.symbols-table td{font-size:12px}.symbol-row.unbound td{background:var(--panel-2)}.site{display:inline}.lifetime{display:grid;gap:1px}.life-row{display:flex;gap:1px;align-items:center}.life-row>.faint{min-width:2.2em;font-size:10px}.life-cell{display:inline-block;width:14px;height:12px;border:1px solid var(--ink-3);font-size:9px;line-height:10px;text-align:center;vertical-align:middle}.life-read{background:var(--ink-2)}.life-below{background:repeating-linear-gradient(90deg,var(--panel),var(--panel) 2px,var(--rule) 2px,var(--rule) 3px)}.life-pending{border-style:dashed;background:transparent}.life-none{border-color:transparent;background:transparent;box-shadow:inset 0 0 0 1px var(--rule)}.life-cursor{outline:2px solid var(--cursor);outline-offset:0}.life-legend{display:flex;flex-wrap:wrap;gap:4px 12px;align-items:center}.circuit-graph{overflow:auto;max-height:60vh;border:1px solid var(--rule);border-radius:var(--radius)}.circuit-graph:focus-visible{outline:2px solid var(--focus)}.cnode-value{font-size:10px;white-space:nowrap;display:inline-block;background:var(--panel);padding-right:2px}.cnode-value .ev-chip{display:none}.circuit-legend svg{vertical-align:middle}.circuit-node-line,.circuit-focus,.circuit-head{overflow-wrap:anywhere}.circuit-mark{color:var(--role-symbol);margin-left:2px}.live-port[data-circuit=yes]>td:first-child{box-shadow:inset 3px 0 0 var(--role-symbol)}.predict-panel{display:grid;gap:4px;min-width:0}.predict-panel form{display:flex;flex-wrap:wrap;gap:4px;align-items:center}.whatif-table th{white-space:nowrap;width:9em}.split>svg{display:block;max-width:100%}.split-terms{margin:2px 0;padding-left:1.4em}.forecast{font-size:11px}.live-forecast{min-width:16em}.op-summary{white-space:normal}.table-scroll>table.forecast-table{min-width:60em}.live,.live-pane,.live-symbols,.circuit-view,.predict,.predict-panel,.arch{grid-template-columns:minmax(0,1fr);min-width:0}.labels-off .num>.ev-chip{display:none}.view-legend{display:flex;flex-wrap:wrap;gap:2px 10px;align-items:center;font-size:11px}.view-legend-toggle{margin-left:auto}td.n,th.n{text-align:right;white-space:nowrap}.app.app-live{grid-template-columns:minmax(0,1fr) auto;grid-template-rows:auto auto minmax(0,1fr) auto;grid-template-areas:"header header" "banner banner" "centre right" "bottom bottom"}.app-live .app-right{width:min(360px,32vw);grid-template-rows:auto minmax(0,1fr);gap:4px;align-content:start}.app-live .app-right.app-right-closed{width:auto}.inspector-panel{display:grid;min-height:0}.app-right-closed .inspector-toggle{writing-mode:vertical-rl;padding:8px 2px}.app-live .app-bottom{max-height:34vh;overflow:auto}@media(max-width:900px){.app.app-live{grid-template-columns:minmax(0,1fr);grid-template-rows:auto;grid-template-areas:"header" "banner" "centre" "right" "bottom"}.app-live .app-right{width:auto}.app-right-closed .inspector-toggle{writing-mode:horizontal-tb;padding:2px 8px}}.symbol-row>td{vertical-align:middle}.symbol-row[data-open=yes]>td{border-bottom:none}.symbol-name{white-space:nowrap}.disclosure{border:none;background:none;padding:0 2px;color:var(--ink-2);cursor:pointer}.symbol-sub>td{padding:0 6px 6px 26px;background:var(--panel-2)}.sub-line{padding:3px 0}.sub-line .site{margin-right:8px}.reader-lines{display:grid;grid-template-columns:minmax(8em,max-content) minmax(7em,max-content) minmax(8em,max-content) minmax(0,1fr);column-gap:14px;margin-bottom:4px}.reader-line{display:contents}.reader-line>span{padding:1px 0;min-width:0}.reader-line>.n{text-align:right;white-space:nowrap}.reader-head>span{font-size:11px;border-bottom:1px solid var(--rule)}.verdict .chip{margin-right:2px}.unbound-parts{display:flex;flex-wrap:wrap;gap:2px 16px}.unbound-part{white-space:nowrap}.circuit-zoom{scroll-margin-top:40px;display:flex;flex-wrap:wrap;gap:4px;align-items:center;font-size:11px;margin-bottom:2px}.circuit-zoom button{padding:0 6px}.circuit-zoom button[aria-pressed=true]{outline:1px solid var(--ink-2)}.scroll-cue{margin-left:auto;color:var(--ink-2)}.circuit-graph-overflow{box-shadow:inset -14px 0 10px -10px var(--ink-3)}.test-result td.edits{white-space:normal;overflow-wrap:anywhere;min-width:14em}.unbound-meaning summary{cursor:pointer;font-size:11px}.num{white-space:nowrap}@media(max-width:600px){.table-scroll>table.symbols-table{min-width:0}.symbols-table thead{display:none}.symbols-table,.symbols-table tbody,.symbols-table tr,.symbols-table td{display:block}.symbols-table tr.symbol-row{display:flex;flex-wrap:wrap;gap:2px 10px;align-items:center;padding:3px 0;border-top:1px solid var(--rule)}.symbols-table tr.symbol-row>td{border:none;padding:0}.symbols-table tr.symbol-row>td.symbol-name{flex:1 0 100%}.symbols-table td.n[data-label]:before{content:attr(data-label) " ";color:var(--ink-3);font-size:11px}.symbols-table td.n:empty{display:none}.symbol-sub>td{padding-left:10px}.reader-lines{grid-template-columns:minmax(6em,1fr) max-content max-content;column-gap:10px}.reader-line>span:last-child{grid-column:1 / -1;padding-left:10px;min-width:0;overflow-wrap:anywhere}.reader-line .verdict{white-space:normal}.reader-head>span:last-child{display:none}}td.n .op-summary>span{display:block}.verdict-not{color:var(--sign-neg)}.app.app-records{grid-template-columns:minmax(360px,3fr) minmax(0,3fr) minmax(170px,.6fr)}.app-centre-records{grid-template-rows:auto minmax(0,1fr)}.app-left-stack,.app-centre-stack{display:grid;grid-template-rows:auto minmax(0,1fr);gap:var(--gap);min-height:0;overflow:auto}.app-centre-stack{grid-template-rows:minmax(180px,1fr) minmax(300px,2fr)}.recorded-picker{display:flex;flex-wrap:wrap;gap:4px;align-items:center;margin-bottom:4px}.recorded-picker select{max-width:100%}.recorded-origin{margin-bottom:4px}.feature-graph{display:flex;align-items:center;gap:12px;overflow-x:auto;padding:8px 0}.feature-graph-sources{display:grid;gap:6px;min-width:260px}.feature-graph-node{border:1px solid var(--rule);border-radius:6px;padding:8px;min-width:150px}.feature-graph-node a{margin-left:8px}.symbols-result{container-type:inline-size}@container (max-width: 650px){.feature-graph{flex-direction:column;align-items:stretch}.feature-graph>span{align-self:center;transform:rotate(90deg)}.feature-graph-sources{min-width:0}}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<title>mdb</title>
|
|
7
|
+
<link rel="icon" href="data:," />
|
|
8
|
+
<script type="module" crossorigin src="/assets/index-BJpByNCO.js"></script>
|
|
9
|
+
<link rel="stylesheet" crossorigin href="/assets/index-H9zlNeqq.css">
|
|
10
|
+
</head>
|
|
11
|
+
<body>
|
|
12
|
+
<div id="root"></div>
|
|
13
|
+
</body>
|
|
14
|
+
</html>
|
mdb/serve/stored.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"""Typed reads of stored (untrusted) data: the one place a view asks "is this really a ...?".
|
|
2
|
+
|
|
3
|
+
A stored body is whatever JSON a writer put there; a view never assumes a field's type. A string
|
|
4
|
+
field is used only when it is a ``str``, a mapping only when it is a ``dict``, a list only when it
|
|
5
|
+
is a ``list``, a number only when it is a finite, non-bool ``int``/``float``.
|
|
6
|
+
"""
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def as_str(value, default: str = "") -> str:
|
|
11
|
+
return value if isinstance(value, str) else default
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def as_dict(value) -> dict:
|
|
15
|
+
return value if isinstance(value, dict) else {}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def as_list(value) -> list:
|
|
19
|
+
return value if isinstance(value, list) else []
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def is_number(value) -> bool:
|
|
23
|
+
"""A finite int/float that is not a bool."""
|
|
24
|
+
# the range test is False for NaN/inf and keeps float() of an int from overflowing
|
|
25
|
+
return isinstance(value, (int, float)) and not isinstance(value, bool) \
|
|
26
|
+
and -1e300 < value < 1e300
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def as_number(value, default=None):
|
|
30
|
+
return value if is_number(value) else default
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def as_int(value, default=None):
|
|
34
|
+
return value if isinstance(value, int) and not isinstance(value, bool) else default
|
mdb/serve/typegen.py
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"""Generate ``web/src/api/types.gen.ts`` from the pydantic view records' JSON Schema.
|
|
2
|
+
|
|
3
|
+
python -m mdb.serve.typegen --write # regenerate
|
|
4
|
+
python -m mdb.serve.typegen --check # exit 1 when the file is stale (also a test)
|
|
5
|
+
"""
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
import argparse
|
|
9
|
+
import json
|
|
10
|
+
import os
|
|
11
|
+
import sys
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
|
|
14
|
+
from pydantic.json_schema import models_json_schema
|
|
15
|
+
|
|
16
|
+
from .schema import CAP_BYTES, EXPORTED, SCHEMAS, STRUCTURAL_KEYS
|
|
17
|
+
|
|
18
|
+
# ``MDB_TYPEGEN_TARGET`` redirects the file (tests and CI use it to check a regenerated copy that
|
|
19
|
+
# has not been written into web/ yet).
|
|
20
|
+
TARGET = Path(os.environ.get("MDB_TYPEGEN_TARGET") or
|
|
21
|
+
Path(__file__).resolve().parents[3] / "web" / "src" / "api" / "types.gen.ts")
|
|
22
|
+
HEADER = """\
|
|
23
|
+
// GENERATED by `python -m mdb.serve.typegen --write` from mdb/serve/schema.py. Do not edit.
|
|
24
|
+
// A test (test_serve_api.py::test_generated_types_are_current) fails when this file is stale.
|
|
25
|
+
/* eslint-disable */
|
|
26
|
+
|
|
27
|
+
export interface Envelope<T> {
|
|
28
|
+
schema: string;
|
|
29
|
+
state: "resolved" | "unresolved" | "refused";
|
|
30
|
+
reason?: string | null;
|
|
31
|
+
data: T;
|
|
32
|
+
digest: string;
|
|
33
|
+
bytes: number;
|
|
34
|
+
omitted?: Omitted[] | null;
|
|
35
|
+
}
|
|
36
|
+
"""
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _ts(schema, defs) -> str:
|
|
40
|
+
if "$ref" in schema:
|
|
41
|
+
return schema["$ref"].rsplit("/", 1)[-1]
|
|
42
|
+
if "const" in schema:
|
|
43
|
+
return json.dumps(schema["const"])
|
|
44
|
+
if "enum" in schema:
|
|
45
|
+
return " | ".join(json.dumps(v) for v in schema["enum"])
|
|
46
|
+
for key in ("anyOf", "oneOf"):
|
|
47
|
+
if key in schema:
|
|
48
|
+
parts = list(dict.fromkeys(_ts(s, defs) for s in schema[key]))
|
|
49
|
+
return " | ".join(parts)
|
|
50
|
+
kind = schema.get("type")
|
|
51
|
+
if isinstance(kind, list):
|
|
52
|
+
return " | ".join(_ts({**schema, "type": k}, defs) for k in kind)
|
|
53
|
+
if kind == "string":
|
|
54
|
+
return "string"
|
|
55
|
+
if kind in ("integer", "number"):
|
|
56
|
+
return "number"
|
|
57
|
+
if kind == "boolean":
|
|
58
|
+
return "boolean"
|
|
59
|
+
if kind == "null":
|
|
60
|
+
return "null"
|
|
61
|
+
if kind == "array":
|
|
62
|
+
if "prefixItems" in schema:
|
|
63
|
+
return "[" + ", ".join(_ts(s, defs) for s in schema["prefixItems"]) + "]"
|
|
64
|
+
inner = _ts(schema.get("items", {}), defs)
|
|
65
|
+
return f"({inner})[]" if "|" in inner else f"{inner}[]"
|
|
66
|
+
if kind == "object":
|
|
67
|
+
extra = schema.get("additionalProperties")
|
|
68
|
+
if isinstance(extra, dict):
|
|
69
|
+
return f"Record<string, {_ts(extra, defs)}>"
|
|
70
|
+
return "Record<string, unknown>"
|
|
71
|
+
return "unknown"
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def _interface(name, schema, defs) -> str:
|
|
75
|
+
required = set(schema.get("required", []))
|
|
76
|
+
lines = [f"export interface {name} {{"]
|
|
77
|
+
for field, sub in schema.get("properties", {}).items():
|
|
78
|
+
optional = "" if field in required else "?"
|
|
79
|
+
lines.append(f" {field}{optional}: {_ts(sub, defs)};")
|
|
80
|
+
lines.append("}")
|
|
81
|
+
return "\n".join(lines)
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def render() -> str:
|
|
85
|
+
_, top = models_json_schema([(m, "serialization") for m in EXPORTED],
|
|
86
|
+
ref_template="#/$defs/{model}")
|
|
87
|
+
defs = top.get("$defs", {})
|
|
88
|
+
blocks = [HEADER]
|
|
89
|
+
for name in sorted(defs):
|
|
90
|
+
schema = defs[name]
|
|
91
|
+
if schema.get("type") == "object" or "properties" in schema:
|
|
92
|
+
blocks.append(_interface(name, schema, defs))
|
|
93
|
+
else:
|
|
94
|
+
blocks.append(f"export type {name} = {_ts(schema, defs)};")
|
|
95
|
+
blocks.append("export type PointerSpec = SlotPointer | BlobPointer | OccurrencePointer;")
|
|
96
|
+
blocks.append("export type ReduceResult =\n | StatsResult\n | TopkResult\n | SliceResult\n"
|
|
97
|
+
" | HistogramResult\n | TileResult\n | ProjectResult;")
|
|
98
|
+
blocks.append("export type Ev = Num['ev'];")
|
|
99
|
+
blocks.append(f"export const CAP_BYTES = {CAP_BYTES};")
|
|
100
|
+
keys = ", ".join(json.dumps(k) for k in STRUCTURAL_KEYS)
|
|
101
|
+
blocks.append("// Keys whose own value is structure (an int or a list of ints), never a "
|
|
102
|
+
"measurement:\n"
|
|
103
|
+
"// everything else numeric is a Num/NumList with an evidence class.\n"
|
|
104
|
+
f"export const STRUCTURAL_KEYS: readonly string[] = [{keys}];")
|
|
105
|
+
schemas = ",\n".join(f" {k if k.isidentifier() else json.dumps(k)}: {json.dumps(v)}"
|
|
106
|
+
for k, v in SCHEMAS.items())
|
|
107
|
+
blocks.append(f"export const SCHEMAS = {{\n{schemas},\n}} as const;")
|
|
108
|
+
return "\n\n".join(blocks) + "\n"
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def main(argv=None):
|
|
112
|
+
parser = argparse.ArgumentParser(description=__doc__.splitlines()[0])
|
|
113
|
+
group = parser.add_mutually_exclusive_group(required=True)
|
|
114
|
+
group.add_argument("--write", action="store_true")
|
|
115
|
+
group.add_argument("--check", action="store_true")
|
|
116
|
+
args = parser.parse_args(argv)
|
|
117
|
+
text = render()
|
|
118
|
+
if args.write:
|
|
119
|
+
TARGET.parent.mkdir(parents=True, exist_ok=True)
|
|
120
|
+
TARGET.write_text(text)
|
|
121
|
+
print(f"wrote {TARGET}")
|
|
122
|
+
return 0
|
|
123
|
+
current = TARGET.read_text() if TARGET.is_file() else ""
|
|
124
|
+
if current != text:
|
|
125
|
+
print(f"{TARGET} is stale; run python -m mdb.serve.typegen --write", file=sys.stderr)
|
|
126
|
+
return 1
|
|
127
|
+
return 0
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
if __name__ == "__main__":
|
|
131
|
+
raise SystemExit(main())
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""View projections: pure functions from a recorded session model to a typed view record."""
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
"""Shared helpers for view projections: addresses, cells and pointer references."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import hashlib
|
|
5
|
+
import json
|
|
6
|
+
from types import SimpleNamespace
|
|
7
|
+
|
|
8
|
+
from saturn.values import digest
|
|
9
|
+
|
|
10
|
+
from ...core import address as addresses
|
|
11
|
+
from .. import _legacy, blobs
|
|
12
|
+
from ..schema import PointerRef
|
|
13
|
+
from ..stored import as_dict, as_list, as_str
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class ViewError(ValueError):
|
|
17
|
+
"""A request the view cannot answer (bad address, unknown id): refused, not a crash."""
|
|
18
|
+
|
|
19
|
+
def __init__(self, reason, detail, status=422):
|
|
20
|
+
super().__init__(detail)
|
|
21
|
+
self.reason, self.detail, self.status = reason, detail, status
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def short(value, n=12):
|
|
25
|
+
return value if isinstance(value, str) and len(value) <= n else str(value)[:n]
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def spec_digest(spec: dict) -> str:
|
|
29
|
+
raw = json.dumps(spec, sort_keys=True, separators=(",", ":")).encode()
|
|
30
|
+
return hashlib.sha256(raw).hexdigest()
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def layers_for(model, address):
|
|
34
|
+
"""The ``layers=`` to give ``mdb.core.address``/``index`` for this address, or None.
|
|
35
|
+
|
|
36
|
+
``known``: the model's count. ``inferred`` (the highest recorded layer index, a lower bound):
|
|
37
|
+
``max(inferred, layer + 1)``, so a layer is never declared nonexistent from a guess; a lookup
|
|
38
|
+
under it either misses (unresolved) or hits the row indexed under the true count. ``unknown``:
|
|
39
|
+
None for a hidden-state port (``h``/``h_out``: no key without a count); ports whose key does
|
|
40
|
+
not depend on the count get the placeholder 1."""
|
|
41
|
+
if model.layers_status == "known":
|
|
42
|
+
return model.n_layers
|
|
43
|
+
if model.layers_status == "inferred":
|
|
44
|
+
layer = getattr(address, "layer", None)
|
|
45
|
+
return max(model.n_layers, layer + 1) if isinstance(layer, int) else model.n_layers
|
|
46
|
+
hidden = isinstance(address, addresses.Occurrence) and address.port in ("h", "h_out")
|
|
47
|
+
return None if hidden else 1
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def occurrence_row(model, address):
|
|
51
|
+
"""The occurrence index row for an address, or None.
|
|
52
|
+
|
|
53
|
+
Looked up under ``value_key`` (``tN.emb`` = ``tN.L0.h``; ``tN.Lk.h_out`` = ``tN.L{k+1}.h``),
|
|
54
|
+
so one value has one key; core requires the layer count (``layers_for``). Absent index tables
|
|
55
|
+
read as "not indexed", and so does a hidden-state address in a recording whose layer count is
|
|
56
|
+
unknown.
|
|
57
|
+
"""
|
|
58
|
+
from ...core.index import find_occurrence
|
|
59
|
+
|
|
60
|
+
try:
|
|
61
|
+
parsed = addresses.coerce(address)
|
|
62
|
+
except ValueError:
|
|
63
|
+
parsed = None # find_occurrence below reads it with the pointer's own port list
|
|
64
|
+
layers = layers_for(model, parsed)
|
|
65
|
+
if layers is None:
|
|
66
|
+
return None
|
|
67
|
+
try:
|
|
68
|
+
return find_occurrence(model.project, model.sid, address, layers=layers)
|
|
69
|
+
except (ValueError, LookupError):
|
|
70
|
+
return None
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def parse(text):
|
|
74
|
+
try:
|
|
75
|
+
return addresses.parse(text)
|
|
76
|
+
except addresses.AddressError as error:
|
|
77
|
+
raise ViewError("bad_address", str(error)) from error
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def point_of(model, cut):
|
|
81
|
+
"""The execution point a cut was recorded at, shaped like ``ExecutionPoint`` (what
|
|
82
|
+
``mdb.core.address.to_state_address(point=...)`` reads)."""
|
|
83
|
+
p = model.cuts[cut]["execution_point"]
|
|
84
|
+
return SimpleNamespace(logical_step=p.get("logical_step"), phase=p.get("phase"),
|
|
85
|
+
index=p.get("index"), fingerprint=p.get("fingerprint"))
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def cell_address(model, x, y, *, origin=""):
|
|
89
|
+
"""Address text of timeline cell (x, y) from the server-supplied tick fragments, or None
|
|
90
|
+
for a boundary no occurrence address names (``AxisTick.addressable`` False)."""
|
|
91
|
+
token = f"t{x}"
|
|
92
|
+
tick = model.depth.axis().ticks[y]
|
|
93
|
+
if not tick.addressable:
|
|
94
|
+
return None
|
|
95
|
+
parts = [token] + ([tick.frag] if tick.frag else [])
|
|
96
|
+
return origin + ".".join(parts) + "." + (tick.port or "h")
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def address_cell(model, address):
|
|
100
|
+
"""``(x, y)`` of an occurrence address; y is None for a port the depth axis lacks."""
|
|
101
|
+
if not isinstance(address, addresses.Occurrence):
|
|
102
|
+
return None, None
|
|
103
|
+
return address.token, model.depth.tick_of_address(address)
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def location_address(model, location: dict) -> str:
|
|
107
|
+
"""Canonical address text of a ``StateAddress`` dict, or ``slot[selector]`` when the
|
|
108
|
+
decoder mapping has no address for it."""
|
|
109
|
+
from saturn.contracts import StateAddress
|
|
110
|
+
|
|
111
|
+
location = as_dict(location)
|
|
112
|
+
selector = tuple(x for x in as_list(location.get("selector"))
|
|
113
|
+
if isinstance(x, int) and not isinstance(x, bool))
|
|
114
|
+
slot = as_str(location.get("slot")) or "?"
|
|
115
|
+
point_digest = as_str(location.get("execution_point"))
|
|
116
|
+
point = None
|
|
117
|
+
for cut, desc in model.cuts.items():
|
|
118
|
+
if point_digest and digest(desc["execution_point"]) == point_digest:
|
|
119
|
+
p = desc["execution_point"]
|
|
120
|
+
point = SimpleNamespace(logical_step=p.get("logical_step"), phase=p.get("phase"),
|
|
121
|
+
index=p.get("index"), fingerprint=None)
|
|
122
|
+
break
|
|
123
|
+
try:
|
|
124
|
+
state = StateAddress(slot, selector, as_str(location.get("role")))
|
|
125
|
+
if point is None and slot not in ("keys", "values"):
|
|
126
|
+
raise addresses.NoStateSlot("no retained point")
|
|
127
|
+
return addresses.format_address(addresses.from_state_address(
|
|
128
|
+
state, point or SimpleNamespace(logical_step=0, phase="", index=None,
|
|
129
|
+
fingerprint=None),
|
|
130
|
+
layers=model.n_layers, granularity=model.granularity,
|
|
131
|
+
limits=None if model.first_step is None else {"first_step": model.first_step}))
|
|
132
|
+
except (addresses.NoStateSlot, addresses.AddressError, ValueError, TypeError):
|
|
133
|
+
return slot + (json.dumps(list(selector)) if selector else "")
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def slot_ref(model, cut, slot, *, item=None, select=(), addr=None) -> PointerRef:
|
|
137
|
+
spec = {"kind": "slot", "cut": cut, "slot": slot, "item": item, "select": list(select)}
|
|
138
|
+
via = [f"cut {short(cut)}", f"slot {slot}"]
|
|
139
|
+
try:
|
|
140
|
+
info = model.slot_info(cut, slot, item)
|
|
141
|
+
except (blobs.BlobError, OSError, ValueError) as error:
|
|
142
|
+
reason = getattr(error, "reason", str(error))
|
|
143
|
+
return PointerRef(digest=spec_digest(spec), addr=addr, spec=spec, via=via,
|
|
144
|
+
status="frontier", reason=reason)
|
|
145
|
+
shape = info["shape"]
|
|
146
|
+
if shape is not None and select:
|
|
147
|
+
if len(select) > len(shape) or any(not 0 <= s < n for s, n in zip(select, shape)):
|
|
148
|
+
return PointerRef(digest=spec_digest(spec), addr=addr, spec=spec, via=via,
|
|
149
|
+
status="frontier", reason="selector is outside the slot tensor")
|
|
150
|
+
shape = shape[len(select):]
|
|
151
|
+
return PointerRef(digest=spec_digest(spec), addr=addr, spec=spec, via=via,
|
|
152
|
+
status="resolvable", shape=shape, dtype=info["dtype"])
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def blob_ref(model, ref, *, addr=None, via=()) -> PointerRef:
|
|
156
|
+
spec = {"kind": "blob", "ref": ref}
|
|
157
|
+
try:
|
|
158
|
+
info = _legacy.tensor_info(model.project, ref)
|
|
159
|
+
except (OSError, ValueError) as error:
|
|
160
|
+
return PointerRef(digest=spec_digest(spec), addr=addr, spec=spec,
|
|
161
|
+
via=[*via, f"tensor {short(ref)}"], status="frontier",
|
|
162
|
+
reason=str(error))
|
|
163
|
+
return PointerRef(digest=spec_digest(spec), addr=addr, spec=spec,
|
|
164
|
+
via=[*via, f"tensor {short(ref)}"], status="resolvable",
|
|
165
|
+
shape=info["shape"], dtype=info["dtype"])
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
def descriptor_ref(desc: dict, *, addr=None, why="descriptor only") -> PointerRef:
|
|
169
|
+
"""A sealed tensor descriptor whose bytes the project does not retain."""
|
|
170
|
+
desc = as_dict(desc)
|
|
171
|
+
sha = as_str(desc.get("sha256")) or as_str(desc.get("tensor"))
|
|
172
|
+
shape = desc.get("shape")
|
|
173
|
+
if not (isinstance(shape, list) and len(shape) <= 16 and all(
|
|
174
|
+
isinstance(n, int) and not isinstance(n, bool) for n in shape)):
|
|
175
|
+
shape = None
|
|
176
|
+
return PointerRef(digest=spec_digest({"kind": "descriptor", "sha256": sha}), addr=addr,
|
|
177
|
+
via=[f"sha256 {short(sha)}"], status="frontier",
|
|
178
|
+
reason=f"{why}: tensor bytes are not retained in the project store",
|
|
179
|
+
shape=shape, dtype=str(desc.get("dtype", ""))[:40].replace(
|
|
180
|
+
"torch.", "") or None)
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
def cut_refs(record: dict) -> list[str]:
|
|
184
|
+
"""Cut ids a record names (circuit records, v2 records, findings)."""
|
|
185
|
+
out = []
|
|
186
|
+
for key in ("supporting_cut", "input_cut", "result_cut", "cut_id", "source_cut"):
|
|
187
|
+
if isinstance(record.get(key), str):
|
|
188
|
+
out.append(record[key])
|
|
189
|
+
body = record.get("body") if isinstance(record.get("body"), dict) else {}
|
|
190
|
+
history = body.get("history") if isinstance(body.get("history"), dict) else {}
|
|
191
|
+
if isinstance(history.get("parent_cut"), str):
|
|
192
|
+
out.append(history["parent_cut"])
|
|
193
|
+
for pointer in as_list(record.get("pointers")):
|
|
194
|
+
if isinstance(pointer, dict) and isinstance(pointer.get("cut"), str):
|
|
195
|
+
out.append(pointer["cut"])
|
|
196
|
+
return list(dict.fromkeys(out))
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
def record_id(record: dict) -> str:
|
|
200
|
+
"""The record's id when it is a string, else ""."""
|
|
201
|
+
return as_str(as_dict(record).get("id")) or as_str(as_dict(record).get("record_id"))
|
mdb/serve/views/frame.py
ADDED
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
"""Frame at the cursor (one occurrence address) and the branch tree of a recorded session."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
from ...core import address as addresses
|
|
5
|
+
from ..recorded import NOT_RECORDED
|
|
6
|
+
from ..schema import (
|
|
7
|
+
BranchInfo,
|
|
8
|
+
BranchNode,
|
|
9
|
+
BranchTree,
|
|
10
|
+
Frame,
|
|
11
|
+
FrameFocus,
|
|
12
|
+
LiveState,
|
|
13
|
+
OccAddr,
|
|
14
|
+
PointerRef,
|
|
15
|
+
)
|
|
16
|
+
from .common import (
|
|
17
|
+
ViewError,
|
|
18
|
+
address_cell,
|
|
19
|
+
blob_ref,
|
|
20
|
+
cell_address,
|
|
21
|
+
cut_refs,
|
|
22
|
+
layers_for,
|
|
23
|
+
occurrence_row,
|
|
24
|
+
parse,
|
|
25
|
+
point_of,
|
|
26
|
+
record_id,
|
|
27
|
+
slot_ref,
|
|
28
|
+
spec_digest,
|
|
29
|
+
)
|
|
30
|
+
from .symbols import symbol_cells
|
|
31
|
+
|
|
32
|
+
OFFLINE = "recorded project: no engine attached, nothing runs"
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def _scope(model, origin):
|
|
36
|
+
"""Candidate cuts in history order, and the branch name they belong to."""
|
|
37
|
+
if origin is None:
|
|
38
|
+
return model.main, "main"
|
|
39
|
+
if origin.cut is not None:
|
|
40
|
+
matches = [c for c in model.cut_ids if c.startswith(origin.cut)]
|
|
41
|
+
if len(matches) != 1:
|
|
42
|
+
raise ViewError("unknown_cut", f"cut reference {origin.cut!r} matches "
|
|
43
|
+
f"{len(matches)} retained cuts", 404)
|
|
44
|
+
return model.lineage(matches[0]), model.branch[matches[0]]
|
|
45
|
+
cuts = model.branch_cuts(origin.branch)
|
|
46
|
+
if not cuts:
|
|
47
|
+
raise ViewError("unknown_branch", f"no branch {origin.branch!r} in {model.sid}", 404)
|
|
48
|
+
return cuts, origin.branch
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def _history(model, cuts):
|
|
52
|
+
"""Recorded cells in clock order along a lineage (cuts and the transitions between them)."""
|
|
53
|
+
keep, cells = set(cuts), set()
|
|
54
|
+
for cut in cuts:
|
|
55
|
+
if model.cell_of_cut.get(cut):
|
|
56
|
+
cells.add(model.cell_of_cut[cut])
|
|
57
|
+
for receipt in model.receipts:
|
|
58
|
+
if receipt.get("result") in keep:
|
|
59
|
+
for step in receipt.get("transitions") or []:
|
|
60
|
+
for key in ("before", "after"):
|
|
61
|
+
cell = model.place(step.get(key))
|
|
62
|
+
if cell:
|
|
63
|
+
cells.add(cell)
|
|
64
|
+
return sorted(cells)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
LAYERS_UNKNOWN = "unresolved: layer count unknown"
|
|
68
|
+
HIDDEN_PORTS = ("h", "h_out")
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def _hidden(address):
|
|
72
|
+
return isinstance(address, addresses.Occurrence) and address.port in HIDDEN_PORTS
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def _needs_layers(model, address):
|
|
76
|
+
"""True when the address is a hidden-state port and the recording has no layer count."""
|
|
77
|
+
return _hidden(address) and model.layers_status == "unknown"
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def _state_point(model, address):
|
|
81
|
+
if _needs_layers(model, address):
|
|
82
|
+
return None, LAYERS_UNKNOWN
|
|
83
|
+
try:
|
|
84
|
+
return addresses.state_clock(address, granularity=model.granularity,
|
|
85
|
+
layers=layers_for(model, address)), None
|
|
86
|
+
except (addresses.NoStateSlot, ValueError) as error:
|
|
87
|
+
return None, str(error)
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def _matches(point, clock):
|
|
91
|
+
have = {"logical_step": point.get("logical_step"), "phase": point.get("phase"),
|
|
92
|
+
"index": point.get("index") if point.get("phase") == "layer" else None}
|
|
93
|
+
return have == clock
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def default_address(model):
|
|
97
|
+
"""The selected cut's cell, else the last addressable recorded cell of ``main``."""
|
|
98
|
+
cell = model.cell_of_cut.get(model.selected)
|
|
99
|
+
if cell is not None and cell_address(model, *cell):
|
|
100
|
+
return cell_address(model, *cell)
|
|
101
|
+
cells = [c for c in _history(model, model.main) if cell_address(model, *c)]
|
|
102
|
+
if not cells:
|
|
103
|
+
raise ViewError("empty_session", f"session {model.sid} has no addressable cut", 404)
|
|
104
|
+
return cell_address(model, *cells[-1])
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def frame(model, addr=None) -> Frame:
|
|
108
|
+
text = addr or default_address(model)
|
|
109
|
+
address = parse(text)
|
|
110
|
+
canonical = addresses.format_address(address)
|
|
111
|
+
cuts, branch = _scope(model, address.origin)
|
|
112
|
+
x, y = address_cell(model, address)
|
|
113
|
+
clock, no_slot = _state_point(model, address)
|
|
114
|
+
frontier = [OFFLINE]
|
|
115
|
+
chosen, note = None, None
|
|
116
|
+
if clock is not None:
|
|
117
|
+
exact = [c for c in cuts if _matches(model.cuts[c]["execution_point"], clock)]
|
|
118
|
+
if not exact:
|
|
119
|
+
exact = [c for c in model.cut_ids if _matches(model.cuts[c]["execution_point"], clock)]
|
|
120
|
+
if exact:
|
|
121
|
+
note = f"no retained cut on {branch} at this clock; showing branch " \
|
|
122
|
+
f"{model.branch[exact[-1]]}"
|
|
123
|
+
chosen = exact[-1] if exact else None
|
|
124
|
+
if chosen is None:
|
|
125
|
+
frontier.append("no retained cut holds this state; replay needs the engine")
|
|
126
|
+
at_cell = [c for c in cuts if model.cell_of_cut.get(c) == (x, y)]
|
|
127
|
+
if at_cell:
|
|
128
|
+
chosen = at_cell[-1]
|
|
129
|
+
op = model.cuts[chosen]["execution_point"].get("next_operation")
|
|
130
|
+
note = (f"this address's state is not retained; showing the retained boundary "
|
|
131
|
+
f"at this cell (before {op})")
|
|
132
|
+
elif x is not None and y is not None:
|
|
133
|
+
at_cell = [c for c in cuts if model.cell_of_cut.get(c) == (x, y)]
|
|
134
|
+
chosen = at_cell[-1] if at_cell else None
|
|
135
|
+
note = (f"{no_slot}; nearest retained boundary shown" if chosen else no_slot)
|
|
136
|
+
else:
|
|
137
|
+
note = no_slot or "address has no clock (a cache cell reads at the current clock)"
|
|
138
|
+
if isinstance(address, addresses.StateCell):
|
|
139
|
+
chosen = cuts[-1] if cuts else None
|
|
140
|
+
note = "cache cell read at the latest cut of the branch"
|
|
141
|
+
if chosen is None and _hidden(address) and model.layers_status == "inferred":
|
|
142
|
+
note = NOT_RECORDED
|
|
143
|
+
pointers = []
|
|
144
|
+
if _needs_layers(model, address):
|
|
145
|
+
# The value exists in the recording's terms but cannot be located without the layer
|
|
146
|
+
# count: shown as an unresolved frontier pointer, never as absent.
|
|
147
|
+
pointers.append(PointerRef(digest=spec_digest({"addr": canonical, "why": "layers"}),
|
|
148
|
+
addr=canonical, status="frontier", reason=LAYERS_UNKNOWN))
|
|
149
|
+
elif chosen is not None:
|
|
150
|
+
limits = {}
|
|
151
|
+
if model.layers_known:
|
|
152
|
+
limits["layers"] = model.n_layers
|
|
153
|
+
if model.first_step is not None: # sample/logits need the session's first stepped row
|
|
154
|
+
limits["first_step"] = model.first_step
|
|
155
|
+
limits = limits or None
|
|
156
|
+
state = None
|
|
157
|
+
try:
|
|
158
|
+
state = addresses.to_state_address(
|
|
159
|
+
address, point=point_of(model, chosen), granularity=model.granularity,
|
|
160
|
+
layers=layers_for(model, address), limits=limits)
|
|
161
|
+
except addresses.NoStateSlot as error:
|
|
162
|
+
if "stepped" in str(error): # sample/logits of a row the session never stepped
|
|
163
|
+
pointers.append(PointerRef(
|
|
164
|
+
digest=spec_digest({"addr": canonical, "why": "unstepped"}),
|
|
165
|
+
addr=canonical, status="frontier", reason=f"unresolved: {str(error)[:300]}"))
|
|
166
|
+
# otherwise this address names no state slot at this point
|
|
167
|
+
except (ValueError, addresses.AddressError) as error:
|
|
168
|
+
# not "no slot": a refusal with its reason, shown as an unresolved pointer
|
|
169
|
+
pointers.append(PointerRef(digest=spec_digest({"addr": canonical, "why": "refused"}),
|
|
170
|
+
addr=canonical, status="frontier",
|
|
171
|
+
reason=f"refused: {str(error)[:300]}"))
|
|
172
|
+
if state is not None:
|
|
173
|
+
sel = list(state.selector)
|
|
174
|
+
item = sel.pop(0) if state.slot in ("keys", "values") else None
|
|
175
|
+
if item is not None and sel[:1] == [0]:
|
|
176
|
+
sel = sel[1:]
|
|
177
|
+
pointers.append(slot_ref(model, chosen, state.slot, item=item,
|
|
178
|
+
select=sel, addr=canonical))
|
|
179
|
+
if isinstance(address, addresses.Occurrence):
|
|
180
|
+
row = occurrence_row(model, address)
|
|
181
|
+
if row and row.get("blob_id"):
|
|
182
|
+
pointers.append(blob_ref(model, row["blob_id"], addr=canonical,
|
|
183
|
+
via=["occurrence index"]))
|
|
184
|
+
elif row:
|
|
185
|
+
frontier.append("occurrence indexed without a blob: rebuilding it needs replay")
|
|
186
|
+
sym = symbol_cells(model).get((x, y), []) if x is not None else []
|
|
187
|
+
records = [record_id(r) for r in [*model.records(), *model.findings()]
|
|
188
|
+
if chosen and chosen in cut_refs(r)]
|
|
189
|
+
records = [r for r in records if r]
|
|
190
|
+
receipts = [r["fingerprint"] for r in model.receipts
|
|
191
|
+
if chosen and chosen in (r.get("result"), r.get("parent"))]
|
|
192
|
+
focus = FrameFocus(cut=chosen, point=model.cuts[chosen]["execution_point"] if chosen else None,
|
|
193
|
+
receipts=receipts[:16], symbols=sym[:16], records=records[:16],
|
|
194
|
+
pointers=pointers[:8], note=note)
|
|
195
|
+
history = [c for c in _history(model, cuts) if cell_address(model, *c)]
|
|
196
|
+
prev = nxt = None
|
|
197
|
+
if x is not None and y is not None:
|
|
198
|
+
before = [c for c in history if c < (x, y)]
|
|
199
|
+
after = [c for c in history if c > (x, y)]
|
|
200
|
+
origin = "" if address.origin is None else addresses._format_origin(address.origin)
|
|
201
|
+
prev = cell_address(model, *before[-1], origin=origin) if before else None
|
|
202
|
+
nxt = cell_address(model, *after[0], origin=origin) if after else None
|
|
203
|
+
sel = addresses._format_selector(address.selector) or None
|
|
204
|
+
key = None
|
|
205
|
+
if model.layers_known: # aliases depend on the model's layer count: never from an inferred one
|
|
206
|
+
try:
|
|
207
|
+
key = addresses.format_address(addresses.value_key(address, layers=model.n_layers))
|
|
208
|
+
except (addresses.AddressError, ValueError):
|
|
209
|
+
key = None
|
|
210
|
+
return Frame(addr=canonical, key=key,
|
|
211
|
+
occ=OccAddr(run=model.sid, branch=branch, cut=chosen,
|
|
212
|
+
clock={"token": x, "layer": y}, sel=sel),
|
|
213
|
+
axes=model.axes(), pos={"token": x, "layer": y},
|
|
214
|
+
live=LiveState(state="offline", frontier=frontier), focus=focus,
|
|
215
|
+
prev=prev, next=nxt, stateClock=clock)
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
def branches(model) -> BranchTree:
|
|
219
|
+
nodes = []
|
|
220
|
+
for cut in model.cut_ids:
|
|
221
|
+
desc = model.cuts[cut]
|
|
222
|
+
receipt = model.producer.get(cut)
|
|
223
|
+
kind = receipt["operation"] if receipt else ("root" if not desc["parent"] else "capture")
|
|
224
|
+
cell = model.cell_of_cut.get(cut)
|
|
225
|
+
nodes.append(BranchNode(cut=cut, parent=desc["parent"], branch=model.branch[cut],
|
|
226
|
+
clock={"token": cell[0] if cell else None,
|
|
227
|
+
"layer": cell[1] if cell else None},
|
|
228
|
+
kind=kind, retained=True,
|
|
229
|
+
receipt=receipt["fingerprint"] if receipt else None))
|
|
230
|
+
infos = []
|
|
231
|
+
for name in dict.fromkeys(model.branch[c] for c in model.cut_ids):
|
|
232
|
+
members = [c for c in model.cut_ids if model.branch[c] == name]
|
|
233
|
+
base = model.cuts[members[0]]["parent"]
|
|
234
|
+
infos.append(BranchInfo(name=name, head=members[-1], base=base, cuts=len(members)))
|
|
235
|
+
return BranchTree(run=model.sid, active=model.selected, nodes=nodes, branches=infos)
|