diff --git a/.gitignore b/.gitignore index d8da4c0..6df7ee6 100644 --- a/.gitignore +++ b/.gitignore @@ -18,7 +18,7 @@ webui/dist-local/ browser-runtime/.v3-compile.*/ browser-runtime/.local-build/ browser-runtime/vendor/*.tgz -!browser-runtime/vendor/drowse-web-llm-0.2.84-drowse.49.tgz +!browser-runtime/vendor/drowse-web-llm-0.2.84-drowse.50.tgz # Virtual environments .venv/ diff --git a/AGENTS.md b/AGENTS.md index 91c1212..262adc2 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -56,13 +56,14 @@ alias for them. A change that only touches shared code belongs in drowse, with its tests there. Site tests that read shared files exist to check how the hosted shell uses them. -## Parity goldens +## Parity -`drowse/tests/fixtures/browser/*` are the Python reference outputs the browser -runtime replays (`browser-core-pack`, `structured-hook-parity`, the Rust -topology tests, `verify-mlc-hook.py`). drowse's own tests pin them against the -engine; regenerate them there, then bump the pin and update the runtime here. -Browser-only fixtures stay in `browser-runtime/fixtures/`. +There are no parity goldens. The browser runtime matches the engine by reading +the pinned drowse source; when a change moves numerics, check it once against the +pinned Python engine on a tiny model, in scratch, and commit nothing from that +comparison. Tests here check invariants and quiet-regression risks. Small input +data a test needs may live in `browser-runtime/fixtures/` or beside the code that +imports it; recorded engine outputs may not. ## Release diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md index 6bc9919..c2456af 100644 --- a/ARCHITECTURE.md +++ b/ARCHITECTURE.md @@ -50,10 +50,10 @@ syntax, including projections, ablations, manifold positions, phase windows, probe gates, SAE selectors, and J-lens selectors. Python and TypeScript consume the same accept/reject fixture. Parsing does not imply execution support: each expression is reduced to an explicit hook-feature requirement set before GPU -program compilation. The hook ABI v5 library profiles (`standard-v4` with unit -sites, `standard-v4-residual` without) implement structured affine and curved +program compilation. The hook ABI v6 library profiles (`standard-v5` with unit +sites, `standard-v5-residual` without) implement structured affine and curved programs, exact geometry reads, precomputed SAE steering/readout, and exact -full-vocabulary J-lens steering/readout; `standard-v4` adds the neuron and head +full-vocabulary J-lens steering/readout; `standard-v5` adds the neuron and head unit sites (`browser-runtime/HOOK_ABI.md`). The worker still validates the library feature manifest, runtime identity, model profile, and required instrument packs before every program is installed; unsupported diff --git a/README.md b/README.md index 0904b1f..8b1f695 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ the browser. | Path | What it holds | | --- | --- | -| `drowse/` | Submodule pinned to [stdlogits/drowse](https://github.com/stdlogits/drowse): the shared dashboard source (`drowse/webui/src`), the Python reference implementation, and the parity goldens (`drowse/tests/fixtures/browser`) the browser runtime replays. | +| `drowse/` | Submodule pinned to [stdlogits/drowse](https://github.com/stdlogits/drowse): the shared dashboard source (`drowse/webui/src`) and the Python reference implementation the browser runtime follows. | | `webui/` | The hosted shell (`hosted/`), site-only UI and runtime (`src/`), static assets (`public-hosted/`), build, release, and test scripts (`scripts/`), Playwright specs (`e2e/`), and the `/api/contact` Worker (`contact-worker/`). | | `browser-runtime/` | The WebGPU runtime: WebLLM/MLC forks and compiler, the Rust/WASM fitting kernel, runtime and distribution locks, and release inputs. | | `tests/` | Python tests for the browser-runtime build and validation tools. | diff --git a/browser-runtime/HOOK_ABI.md b/browser-runtime/HOOK_ABI.md index de2e101..59efb53 100644 --- a/browser-runtime/HOOK_ABI.md +++ b/browser-runtime/HOOK_ABI.md @@ -1,47 +1,54 @@ -# Hook ABI v5: `block-sites-v5` +# Hook ABI v6: `block-sites-v6` The contract between drowse.ai's TypeScript, the WebLLM bridge and the compiled MLC model -libraries. v5 reads and writes inside each transformer block (the head site, `mid`, the neuron -site), replays nodes with anatomy, activity and pattern taps, and runs static reads over the -resident weights. It replaces `post-block-residual-v4`; the post-block hook and every v3 -structured buffer carry over unchanged. - -Derivations and alternatives are in the parity handoff, `B1-hook-abi-v5.md` (cited as §n), with -the toolchain corrections of `B40-toolchain.md` §7. Where the two differ, this document follows -the decisions taken since: one hook ABI for all nine libraries, full-depth lens packs fetched per -layer, patterns mandatory (no `standard-v4-nopatterns`), one units entry-point pair on the curved -superset, and one runtime path. As built: the rank-one functions are gone from the MLC overlay -(`drowse_prefill`/`decode`, the batch pair, the rank-one capture v1 functions), from the bridge -(rank-one programs and captures, `drowse-structured-v2`, the legacy alias table) and from the -adapter's runtime, which compiles and installs `drowse-structured-v4` programs under the v4 -profiles only. The v1-v3 profile records stay in `structuredHookProfile.ts` while the lock, the -catalog and the release tooling still name them (W4 rewrites those); no v5 code path accepts them. +libraries. v6 is v5 (reads and writes inside each transformer block at the head site, `mid` and +the neuron site; replay with anatomy, activity and pattern taps; static reads over the resident +weights) with typed steering frames. + +**Typed frames (v6).** drowse 6.1 fits a subspace's write rows orthonormal in the Mahalanobis +metric and reads its coordinates with their Σ⁻¹ images, so `read · basisᵀ = I` and a full +ablation is LEACE against the neutral. Every entry point that takes `affine_basis` takes +`affine_read f32 [L, G, R, d]` right after it, and every one that takes `curve_basis` takes +`curve_read f32 [L, C, R, d]` right after it. The affine coordinate is `(h − neutral) · read`; the +write stays `delta · basis`. A curve's `q = (h − neutral) · read`; `h⊥ = (h − neutral) − q · basis` +and the write along `basis` keep their form, and the norm cap is full-width. The geometry readout +is unchanged (its host Gram inverse already gives the Mahalanobis projection). The encoder checks +duality (`read · basisᵀ = I`, atol and rtol 1e-3) where v5 required Euclidean-orthonormal rows. The +affine kernel updates the residual in place, which keeps it at 8 storage bindings (§10). + +Derivations are in the 6.0 parity handoff, `B1-hook-abi-v5.md` (cited as §n), with the toolchain +corrections of `B40-toolchain.md` §7. Where they differ, this document follows the decisions taken +since: one hook ABI for all nine libraries, full-depth lens packs fetched per layer, patterns +mandatory, one units entry-point pair on the curved superset, and one runtime path. The TypeScript side of this contract, pinned by script tests: | file | holds | test | |---|---|---| | `webui/src/hosted/runtime/structuredHookProfile.ts` | ABI names, profiles, `BlockSpec`, descriptor schema 4 | `structured-hook-units.test.mjs` | -| `webui/src/hosted/runtime/structuredHookProgram.ts` | `drowse-structured-v4`: unit tables, encoder, controls, CPU ablation reference | `structured-hook-units.test.mjs` | +| `webui/src/hosted/runtime/structuredHookProgram.ts` | `drowse-structured-v5`: read and write rows, unit tables, encoder (duality check), controls, CPU reference | `structured-hook-units.test.mjs` | | `webui/src/hosted/runtime/modelBackend.ts` | `BrowserBlockSitesBackend` (the device surface), typed tensors, replay layouts | `block-sites-backend.test.mjs` | -| `webui/src/hosted/runtime/webLlmBlockSites.ts`, `webLlmStaticReads.ts` | the surface over the bridge (replay, residents, static reads) | `web-llm-block-sites.test.mjs`; WebGPU `browser-units-goldens.mjs --suite all` | -| `browser-runtime/forks/units_goldens.py`, `static_reads.py` | the C TVM VM checks against the goldens | `verify-mlc-hook.py --units-fixtures` | +| `webui/src/hosted/runtime/webLlmBlockSites.ts`, `webLlmStaticReads.ts` | the surface over the bridge (replay, residents, static reads) | `web-llm-block-sites.test.mjs` | +| `browser-runtime/forks/units_vm.py` | a units library on the C TVM VM (paged KV cache, unit program, static reads) | used by `verify-production-library.py` | | `browser-runtime/forks/verify-production-library.py` | a production library on the CPU: export and shader checks, its descriptor, and (`--parity`) its block sites, greedy tokens and static reads on the C TVM VM against PyTorch on the dequantized MLC tensors (B1 §4.3) | run per library before release | ## 1. Names (§8.1) -| layer | v4 | v5 | +| layer | v5 | v6 | |---|---|---| -| hook ABI (`DROWSE_HOOK_ABI`, lock `hookAbi`) | `post-block-residual-v4` | `block-sites-v5` | -| runtime ABI (lock `runtimeAbi`) | `drowse-web-runtime-v1` | `drowse-web-runtime-v2` | -| readout ABI (lock `exactReadoutAbi`) | `exact-readout-v1` | `exact-readout-v2` | -| structured format | `drowse-structured-v3` (and v2) | `drowse-structured-v4` | -| capacity profiles | `standard-v1`…`-v3` | `standard-v4` (units), `standard-v4-residual` (no units) | -| descriptor schema | 3 (31 fields) | 4 (67 fields) | +| hook ABI (`DROWSE_HOOK_ABI`, lock `hookAbi`) | `block-sites-v5` | `block-sites-v6` | +| runtime ABI (lock `runtimeAbi`) | `drowse-web-runtime-v2` | `drowse-web-runtime-v3` | +| readout ABI (lock `exactReadoutAbi`) | `exact-readout-v2` | `exact-readout-v2` | +| structured format | `drowse-structured-v4` | `drowse-structured-v5` (adds `affineRead`, `curveRead`) | +| capacity profiles | `standard-v4`, `standard-v4-residual` | `standard-v5` (units), `standard-v5-residual` (no units) | +| descriptor schema 4 (67 fields) | `PROFILE` 4, ABI 5, format 4 | `PROFILE` 5, ABI 6, format 5 | + +drowse's shared `StructuredHookProfileId` (`contracts.ts`) still names the v5 profiles until a +drowse release renames them; a v6 id crosses it through `sharedProfileId`. Eligible architectures (`gemma3_text`, `qwen3`: dense gated MLP, RMSNorm, RoPE, separate q/k/v -in the HF checkpoint) compile under `standard-v4`. `gpt2`, `gpt_neox` and `qwen3_5` compile under -`standard-v4-residual`: same hook ABI, `UNIT_SITES = 0`, and every unit, anatomy, activity and +in the HF checkpoint) compile under `standard-v5`. `gpt2`, `gpt_neox` and `qwen3_5` compile under +`standard-v5-residual`: same hook ABI, `UNIT_SITES = 0`, and every unit, anatomy, activity and `mid` call answers native's `UnsupportedBlockError` (422) with the lock's `unitRefusal` text. ## 2. Sites (§1) @@ -88,26 +95,27 @@ changes later layers' K/V. ## 3. Entry points (§3.4) -| function | `standard-v4` | `-residual` | role | +| function | `standard-v5` | `-residual` | role | |---|---|---|---| -| `drowse_structured_batch_{prefill,decode}` | yes | yes | v4-identical: affine and probes | -| `drowse_curved_batch_{prefill,decode}` | yes | yes | v4-identical: and curves | +| `drowse_structured_batch_{prefill,decode}` | yes | yes | affine and probes | +| `drowse_curved_batch_{prefill,decode}` | yes | yes | and curves | | `drowse_units_batch_{prefill,decode}` | yes | no | curved superset, unit sites, unit tap | | `drowse_replay_batch_prefill` | yes | no | units superset, anatomy, activity, pattern taps | | unit static reads (§8 below) | yes | no | | | vocabulary, footprint, lens and utility functions (§8) | yes | yes | `exact-readout-v2` | | `drowse_hook_profile` | yes | yes | descriptor schema 4 | -Routing: a program with no unit section runs the v4-identical functions and pays nothing; a +Routing: a program with no unit section runs the structured or curved pair and pays nothing; a program with one runs the units pair. A units library must export every function marked yes, a residual library none of the unit ones; either mismatch fails the load (`HOOK_ABI_MISMATCH`). ```text drowse_units_batch_prefill( input_embeds [1, seq_len, d] f32, logit_positions [n] i32, paged_kv_cache, - affine_active, affine_basis, affine_neutral, affine_target, affine_along, affine_kappa, - probe_kind, probe_direction, probe_bias, probe_threshold, - curve_basis, curve_neutral, curve_domain_kind, curve_parameters, curve_feet, # as v4 curved + affine_active, affine_basis, affine_read, affine_neutral, affine_target, affine_along, + affine_kappa, probe_kind, probe_direction, probe_bias, probe_threshold, + curve_basis, curve_read, curve_neutral, curve_domain_kind, curve_parameters, + curve_feet, # as the curved pair unit_meta u32 [UNIT_META_LEN], unit_coeff f32 [UNIT_COEFF_LEN], unit_active f32 [4], tap_grams f32 [16, hd, hd], ) -> (logits, paged_kv_cache, measurements [L, 8], next_feet [L, 4, 4], jlens_hidden [L, d], @@ -142,15 +150,15 @@ window, so a replay holds only what it reads (a 4B model's keys at full context `pattern_q` are fresh per forward, and the caller keeps the ones of the forward holding the anatomy position. `rows_meta` rows are `(slot, layer, head, p)`, slot −1 unused. -## 4. `drowse-structured-v4` (§3.1, §3.4) +## 4. `drowse-structured-v5` (§3.1, §3.4) -A strict superset of v3: every v3 buffer is unchanged in shape and meaning, plus one unit section -that is present whole or absent. Without it a v4 program's buffers are byte-identical to the v3 -program the same layers compile to (pinned). A `standard-v4-residual` library rejects any unit -section (`UNIT_SECTION_UNSUPPORTED`, 422). +v4 with the read rows: `affineRead` beside `affineBasis` and `curveRead` beside `curveBasis`, same +shapes. v4 was v3 plus one unit section, present whole or absent; without it the other buffers are +the ones the same layers compile to under v3, plus the read rows. A `standard-v5-residual` library +rejects any unit section (`UNIT_SECTION_UNSUPPORTED`, 422). -Host program (`StructuredHookProgramBuffers`, `format: "drowse-structured-v4"`, -`hookAbi: "block-sites-v5"`) adds: +Host program (`StructuredHookProgramBuffers`, `format: "drowse-structured-v5"`, +`hookAbi: "block-sites-v6"`) adds: ```ts unitShape: { dFF; nHeads; headDim }; @@ -203,7 +211,7 @@ prefill state; a decode forward one state for all its rows. A unit gate reads th scaled unit reading through `priorScores[unit]`. Native's step count (`loom/replay.py`): the prefill is step 0 and the decode forward that reads the k-th generated token (1-based) is `gen_step = k`, so `@first:2` covers the first decode forward only and `@after:n` starts at the -n-th; the goldens' `triggers` case pins this on both arches. +n-th. **Position targeting** (browser only). `position_spans`/`position_indices` gate unit terms as they gate affine and curve terms: prefill splits chunks at span boundaries and outside a span the @@ -266,8 +274,8 @@ gates read every attached probe on every forward, and the reply's aggregate carr meaning: ```text - 0 MAGIC 0x53414B4C 1 SCHEMA_VERSION 4 2 PROFILE 4 - 3 HOOK_ABI_VERSION 5 4 FORMAT_VERSION 4 5 LAYER_COUNT + 0 MAGIC 0x53414B4C 1 SCHEMA_VERSION 4 2 PROFILE 5 + 3 HOOK_ABI_VERSION 6 4 FORMAT_VERSION 5 5 LAYER_COUNT 6 HIDDEN_SIZE 7 MAX_AFFINE_GROUPS 4 8 MAX_RANK 8 9 MAX_PROBES 8 10 MAX_CURVES 4 11 MAX_CURVE_NODES 32 12 MAX_INTRINSIC_DIM 4 13 MAX_EMBED_DIM 8 14 CURVE_PARAMETER_STRIDE 671 @@ -296,7 +304,7 @@ meaning: - `*_F32_BITS` hold the IEEE-754 bits of `Math.fround(value)` reinterpreted as a signed int32 (`float32Bits`); 0 means none (no softcap, no local θ). The library must emit the same reinterpretation (`op.full` takes int32). -- `PROFILE` is 4 for both v4 profiles; `UNIT_SITES` says which. A residual library reports 0 in +- `PROFILE` is 5 for both v5 profiles; `UNIT_SITES` says which. A residual library reports 0 in fields 32-50, every unit capacity (52-60), `ANATOMY_STRIDE`, `UNIT_POSITIONS_FROM` and `MAX_ANATOMY_UNITS`; it keeps `MAX_LENS_READ_TOP_K = 256` (lens reads at `out` run everywhere). - `ANATOMY_STRIDE = 6·d + d_ff + H·hd`. `CONTEXT_TOKENS` is the compiled context window, the @@ -317,16 +325,16 @@ rope scaling factor come from the HF config, not `model_spec`). A mismatch names (`hookProfileDescriptorMismatches`) and fails the load with `HOOK_ABI_MISMATCH`. The descriptor catches a library compiled with the wrong constants. It cannot see a wrong graph -with the right constants (a swapped `gate_up` split, a misplaced norm): the `block-sites` goldens on -the tiny libraries and the production q4 parity gate's per-layer `act`/`z`/`mid` error catch those. +with the right constants (a swapped `gate_up` split, a misplaced norm): the production q4 parity +gate's per-layer `act`/`z`/`mid` error catches those. -**Lock** (`runtime-lock.schema.json`, §8.2): `hookAbi: "block-sites-v5"`, -`exactReadoutAbi: "exact-readout-v2"`, `runtimeAbi: "drowse-web-runtime-v2"`; -`models[].structuredHookProfile ∈ {standard-v4, standard-v4-residual}`; `models[].blockSpec` +**Lock** (`runtime-lock.schema.json`, §8.2): `hookAbi: "block-sites-v6"`, +`exactReadoutAbi: "exact-readout-v2"`, `runtimeAbi: "drowse-web-runtime-v3"`; +`models[].structuredHookProfile ∈ {standard-v5, standard-v5-residual}`; `models[].blockSpec` (`BLOCK_SPEC_KEYS`: `dFF, nHeads, nKvHeads, headDim, sandwich, normOffset, activation, embedScale, rmsEps, qkNorm, attnScaling, attnLogitSoftcap, finalLogitSoftcap, ropeTheta, ropeLocalTheta, ropeGlobalScale, ropeInGraph, slidingWindow, slidingPattern`; booleans for the flags, -`"silu" | "gelu_tanh"`, `null` for none) required with `standard-v4` and forbidden with +`"silu" | "gelu_tanh"`, `null` for none) required with `standard-v5` and forbidden with `-residual`; `models[].unitRefusal` (native's full message) required with `-residual`; `models[].prefillChunkSize` required everywhere (`validateRuntimeLock` bounds it by the smallest context). `prepare-hosted-candidate-lock.mjs` refuses a publish directory whose @@ -374,7 +382,7 @@ the captures and drops the sequence (`cancel()` drops it unread). - **Peaks, as built.** One thread per unit walks the forward's rows in order with a strict `>`, so within a forward the first maximum wins and across forwards the earlier one keeps a tie: native's `rank.max(dim=0)` then `best > held` exactly. -- **`replay_meta`** (i32, `replayMetaLayout`/`encodeReplayMeta`, 134 values under `standard-v4`): +- **`replay_meta`** (i32, `replayMetaLayout`/`encodeReplayMeta`, 134 values under `standard-v5`): `[0]` anatomy position (−1 none), `[1]` span count, `[2..18)` four spans of `(first_row, rows, first_position, unproduced)`, `[18]` population row (−1 none), `[19]` trace count, `[20..116)` 32 traces of `(layer, kind 0 neuron | 1 head, index)`, `[116]` pattern layer @@ -384,7 +392,7 @@ the captures and drops the sequence (`cancel()` drops it unread). (one worker message kind): `headGrams`, `uploadUnitScales`, `release`, `openReplay` (`replayMeta`, `unitScales` resident id, `rowCount`, `tokenCount`), `replayForward` (tokens and one control state), `finishReplay`, `cancelReplay`, `attentionRows`. `openReplay` needs a - drowse-structured-v4 program with a unit section installed (the adapter installs the node's, + drowse-structured-v5 program with a unit section installed (the adapter installs the node's, adding an empty unit section, or an empty program for an unsteered replay), validates the meta fail-closed, resets the KV cache and allocates the threaded buffers; a forward is chunked at `PREFILL_CHUNK_SIZE` and reads back its last chunk's probe slots and unit taps in one sync; @@ -458,7 +466,7 @@ fp32. Functions as built (MLC overlay `drowse_reads.py`; adapter `webLlmStaticRe | `drowse_grouped_row_norms` | `x [n, g, w]` → `[n, g]` | | `groupedRowNorms` | | `drowse_chan_merge` | `count [1]`, `mean [d]`, `m2 [d]`, `rows [r, d]` → `(mean, m2)` | Chan's merge of the rows' own two-pass statistics | `chanMerge` | -Every v5 library exports the twelve `exact-readout-v2` functions (embedding rows through Chan's +Every v6 library exports the twelve `exact-readout-v2` functions (embedding rows through Chan's merge); exactly the libraries with unit sites export the nine unit reads (neuron rows through the cotangent; gather included). The bridge fails a load that breaks either rule (`HOOK_ABI_MISMATCH`). Compositions run in the adapter as one bridge request each: `drowseBlockSites({ op: "read", steps, @@ -518,7 +526,7 @@ any layer. A pattern request names at most `MAX_PATTERN_LAYERS = 16` layers, as 2026-11-02). The heads are known only after the anatomy's contributions, so the worker runs one pattern pass: a second replay of the same segments asking only for those layers (§6 alternative (a), exact). -Patterns are mandatory under `standard-v4`; a library that cannot capture them fails attestation. +Patterns are mandatory under `standard-v5`; a library that cannot capture them fails attestation. ## 10. Binding budget (§2.4) @@ -530,6 +538,7 @@ keeps every unit kernel within 8: | kernel (per layer) | bindings | |---|---| +| `drowse_structured_affine_L` (after the block) | residual in/out, `active`, `basis`, `read`, `neutral`, `target`, `along`, `kappa` = 8 (in place) | | `drowse_head_ablate_L` (before `o_proj`) | `z` in/out, `positions`, `unit_meta`, `unit_coeff`, `unit_active` = 5 (in place) | | `drowse_neuron_ablate_L` (before `down_proj`) | `act` in/out, `positions`, `unit_meta`, `unit_coeff`, `unit_active` = 5 (in place) | | `drowse_unit_tap_L` (after the ablations) | `z`, `attn_o`, `act`, `unit_meta`, `tap_grams`, `unit_taps` in/out = 6 (both families; Qwen3 binds `attn_o` without reading it) | @@ -547,9 +556,10 @@ share one kernel run after both ablations, so it reads the ablated `z` and `act` pre-norm `attn_o` (Gemma's `r_ao`); one workgroup per tap slot, barriers only under control flow that depends on the workgroup id (WGSL uniformity), and the ablations are in place, so a row whose position is below `UNIT_POSITIONS_FROM` is untouched. The upstream graph is otherwise -unchanged: every v4 kernel is byte-identical in a v5 library (binding names aside). +unchanged: every v4 kernel is byte-identical in a v5 library (binding names aside); v6 changes +only the affine and curved hooks. -**The library's binding.** `libraryBindingBytes` (`modelBackend.ts`) is the largest buffer a v5 +**The library's binding.** `libraryBindingBytes` (`modelBackend.ts`) is the largest buffer a v6 library allocates at its largest context and prefill chunk, the larger of: - its largest weight tensor as the GPU holds it (`float32` for a bf16-encoded record); @@ -606,7 +616,7 @@ hidden]`; a tuple's element zero is the residual. Decode capture reads `[0, sequ Hook-disabled execution allocates no steering or probe buffers and leaves logits unchanged. **Affine and curved terms.** Affine injection in fp32, -`delta = along · (target − collapse · dot(h − neutral, basis))`, `h' = h + delta · basis`, +`delta = along · (target − collapse · dot(h − neutral, read))`, `h' = h + delta · basis` (v6), deliberately uncapped (Python's `subspace_inject`). Curved terms keep Python's safety cap, carry the final prompt foot into the first decode step and then the previous decode foot; each curve slot is a fixed 671-float record (rank 8, 32 RBF nodes, 4 intrinsic and 8 embedded dimensions; @@ -639,4 +649,4 @@ generation id; a gap requires a full tree snapshot. **Runtime identity.** An artifact binding names the source commit, converted manifest digest, quantization, tokenizer and chat-template digests, compiled library digest, runtime ABI, this hook ABI, layer map, hidden size and context profile. A friendly model id is never enough. Evidence -recorded against `post-block-residual-v4` does not carry to v5. +recorded against an earlier hook ABI does not carry to v6. diff --git a/browser-runtime/README.md b/browser-runtime/README.md index d259177..3abc9f8 100644 --- a/browser-runtime/README.md +++ b/browser-runtime/README.md @@ -4,12 +4,12 @@ The hosted application must not infer with stock WebLLM. Production loading is enabled only when `runtime-lock.json` has `status: "verified"` and the exact package, overlay, toolchain, model, and compiled-library closure is pinned. -The runtime lock is hook ABI v5 (`runtime-lock.json` schema 2): `drowse-web-runtime-v2`, -`block-sites-v5`, `exact-readout-v2`, each model's capacity profile by architecture -(`standard-v4` for Gemma 3 and Qwen3, with the `blockSpec` its library's schema-4 descriptor -attests; `standard-v4-residual` for GPT-2, Pythia and Qwen3.5 base, with the `unitRefusal` its -unit calls answer), the WebLLM archive `0.2.84-drowse.49`, the fork manifest, compiler recipe -and LLVM identities. It stays `feasibility-required` until every v5 library's converted revision, +The runtime lock is hook ABI v6 (`runtime-lock.json` schema 2): `drowse-web-runtime-v3`, +`block-sites-v6`, `exact-readout-v2`, each model's capacity profile by architecture +(`standard-v5` for Gemma 3 and Qwen3, with the `blockSpec` its library's schema-4 descriptor +attests; `standard-v5-residual` for GPT-2, Pythia and Qwen3.5 base, with the `unitRefusal` its +unit calls answer), the WebLLM archive `0.2.84-drowse.50`, the fork manifest, compiler recipe +and LLVM identities. It stays `feasibility-required` until every v6 library's converted revision, converted-manifest digest and library digest are filled (`prepare-hosted-candidate-lock.mjs`, below); `check-runtime-lock.mjs` lists what is still pending. Exact converted-model revisions, compiled libraries, package archive, overlay closure, runtime ABI, hook ABI, @@ -18,10 +18,9 @@ contains only immutable packages that match those identities. The browser core-pack compiler produces the required neutral whitener and seed manifold pack for each release model. Every steering expression lowers to one -drowse-structured-v4 program (native's `synthesize_subspace` lowering, which -needs the neutral whitener); it shares Python goldens for Mahalanobis -normalization, mean-normalized per-layer share, and uncapped affine gain, and -lowers independent push/ablation groups, prior-step gates, response phases, +drowse-structured-v5 program (native's `synthesize_subspace` lowering, which +needs the neutral whitener); it follows native's Mahalanobis normalization, +mean-normalized per-layer share and uncapped affine gain, and lowers independent push/ablation groups, prior-step gates, response phases, SAE and R-lens programs, box/custom/sphere curved manifolds, in-block unit ablation, and exact geometry reads. Curved steering retains its separate safety cap. Every published pack passes the @@ -34,15 +33,15 @@ response/prompt/count/thinking phases, prior-step scalar gates, and up to four curved terms per layer. Curves may use bounded, unbounded, periodic, or spherical domains and may have up to four intrinsic dimensions. Curved steering can itself be phase-gated or controlled by a prior SAE, R-lens probability, scalar affine -probe, or exact geometry channel from the preceding token. Every hook ABI v5 library -(`HOOK_ABI.md` is the contract) runs `drowse-structured-v4`: four independently gated affine +probe, or exact geometry channel from the preceding token. Every hook ABI v6 library +(`HOOK_ABI.md` is the contract) runs `drowse-structured-v5`: four independently gated affine groups, rank eight, eight scalar probes, four curves, thirty-two nodes per curve, four intrinsic dimensions and eight embedded dimensions, eight geometry probes, whitener rank 96, thirty-three candidates per probe, a 41-float output record per layer and geometry probe, and `exact-readout-v2` (lens reads at both sites, top-k ≤ 256, the S footprint, unit static-read -primitives). A `standard-v4` library adds the in-block unit sites (neuron and head mean-ablation, +primitives). A `standard-v5` library adds the in-block unit sites (neuron and head mean-ablation, unit taps, the replay for token anatomy, unit activity and attention patterns, static unit -reads); a `standard-v4-residual` library attests their absence and answers unit calls with the +reads); a `standard-v5-residual` library attests their absence and answers unit calls with the lock's refusal. The v3 geometry path produces domain coordinates, subspace fraction, @@ -195,7 +194,7 @@ npm run publish:hosted:pack -- MODEL_ID core|sae|jlens|slens|units PACK_DIR The production-q4 comparator checks the unsteered residuals of every layer and position against the dequantized Transformers model, then the steered read on -hook ABI v5 (capture schema 4): one drowse-structured-v4 program with linear +hook ABI v6 (capture schema 4): one drowse-structured-v5 program with linear probes on a fixed orthonormal sketch at every layer (the first direction the push of a rank-1 affine group at the middle layer), measured at every captured position with and without the group (`measurePreparedPositions`). Probe error @@ -206,13 +205,7 @@ control probes to reproduce the projection of the plain capture, rejects any pre-enabled-layer delta between the control and steered probes, and compares the steering delta's direction in the sketch. -`webui/scripts/browser-core-build.mjs` runs the core builder (the unchanged -`hosted-whitener.worker.ts`), the plain and measured captures and the -injection-arithmetic oracle on B4's tiny v5 fixture libraries: -`node scripts/browser-core-build.mjs --webllm WEB_LLM.js --fixtures DIR ---arch qwen3|gemma3 --quantization q0f32|q4f32_1 --work SCRATCH`. - -Capture schema 5 adds B1 §4.3's production measures for a units (`standard-v4`) library and +Capture schema 5 adds B1 §4.3's production measures for a units (`standard-v5`) library and refuses them for a residual one (`q4_unit_parity.py`). Its `capture.json` carries `units: {block: {d_ff, n_heads, head_dim}, sites_sha256, static_reads}`: @@ -230,7 +223,7 @@ refuses them for a residual one (`q4_unit_parity.py`). Its `capture.json` carrie scales come from the units pack and divide both sides alike). The repository lock carries every value a compile does not produce; each library-bound field -stays null until a hook ABI v5 library fills it. `prepare-hosted-candidate-lock.mjs` fills one +stays null until a hook ABI v6 library fills it. `prepare-hosted-candidate-lock.mjs` fills one model from its assembled publish directory and chains models into one candidate lock: ```bash @@ -402,9 +395,7 @@ so a rebind takes seconds. and the neutral pass every statistic averages over, with the digest of its rows (the write norms' whitener, and the core pack's, are built from them). `build_hosted_packs.py` refuses a layer without `neurons.write_norms`. Rank-3 tensors are stored - `[prod(shape[:-1]), shape[-1]]` with their logical shapes recorded. On the ABI v5 tiny - fixture every shipped units tensor equals the `unit-artifacts` golden on both - architectures (`tests/test_hosted_packs.py`). + `[prod(shape[:-1]), shape[-1]]` with their logical shapes recorded. - **core statistics**: `core/neutral-statistics.*` (unit statistics, `out` and `mid` means, stacked over layers) and `core/neutral-rows.safetensors` (the neutral pass's rows, a build input that does not ship), added to the core pack by the whitener @@ -459,8 +450,8 @@ npm run test:browser-runtime:full -- \ --output /tmp/drowse-real-browser-e2e.json ``` -The packs follow the library's profile, as the catalog admits them: a `standard-v4` model -runs with its R (`--jlens-directory`), S and units packs, a `standard-v4-residual` one with no +The packs follow the library's profile, as the catalog admits them: a `standard-v5` model +runs with its R (`--jlens-directory`), S and units packs, a `standard-v5-residual` one with no S or units pack (an R pack is optional); SAE is optional on both. The harness stages every pack file and hands the runtime what the app's worker does: the install files, and each on-demand lens or units layer through `fetchFile` on its first read. `--runtime-lock CANDIDATE` @@ -475,11 +466,11 @@ post-block capture, exact forced-token replay and compact cross-token scoring, an alternate-token fork, flat steering gated independently by geometry and, with their packs, R-lens probability and SAE activation signals, R-lens and SAE steering/readout, a small spectral fit backed by the OPFS activation spool, nearest-node role -selection and named-role generation, curved steering, then on `standard-v4` the units +selection and named-role generation, curved steering, then on `standard-v5` the units check (a token-anatomy replay of the first generated token; a mean-ablation of its largest contributor that moves that token's logprob by at least 1e-4; a static read of a contributing neuron; a generation with a unit tap and an `slens/` S readout, both finite) or on -`standard-v4-residual` the refusal check (six unit members answer 422 with the lock's +`standard-v5-residual` the refusal check (six unit members answer 422 with the lock's `unitRefusal`, the unit catalog answers unbound, a unit ablation and a unit probe refuse, and the bridge's unit surface answers `UNIT_SITES_UNAVAILABLE`), streamed stop, unload/reload, and a final reload from reopened OPFS files while all HTTP(S) fetches are blocked. It fails @@ -534,21 +525,17 @@ SKIP_LOADING_MLCLLM_SO=1 \ PYTHONPATH=/path/to/tvm/python:/path/to/mlc-llm/python \ /path/to/venv/bin/python browser-runtime/forks/verify-mlc-hook.py \ --mlc-repository /path/to/mlc-llm \ - --tvm-repository /path/to/tvm [--units-fixtures FIXTURES] + --tvm-repository /path/to/tvm ``` -Without `--units-fixtures` it checks the Qwen3, Llama and Gemma 3 graph exports and runs the -structured, geometry, curved and exact-readout goldens through a compiled C TVM VM. With it, it -runs drowse's units, replay and read goldens (`drowse/tests/fixtures/browser/*`) over the four -fixture libraries `forks/build-units-fixtures.py` makes from drowse's checkpoints (Qwen3 and -Gemma 3 at q0f32 and q4f32_1). `webui/scripts/browser-units-goldens.mjs` runs the same goldens -through the vendored WebLLM bridge on WebGPU. Neither proves a production library, q4 parity or -a physical device; those are the per-library records below. +It checks the Qwen3, Llama and Gemma 3 graph exports and runs hand-built structured, geometry, +curved and exact-readout cases through a compiled C TVM VM. It does not prove a production +library, q4 parity or a physical device; those are the per-library checks below. For the WebGPU compile gate, source exact Emscripten 3.1.56, rebuild both support runtimes against the pinned TVM checkout (`make -C mlc-llm/web`, `TVM_HOME=… make -C tvm/web`), and compile each architecture fixture with `forks/compile-tiny-webgpu.py --architecture -qwen3|llama|gemma3_text` (or `--model-config` for a units fixture). The compiler requires a new +qwen3|llama|gemma3_text`. The compiler requires a new output path, validates the WebAssembly with the matching Binaryen tool, and requires the v5 export set for its architecture (`overlay_checks.py`: `REQUIRED_FUNCTIONS`, plus `UNIT_FUNCTIONS` on Qwen3 and Gemma 3, none on Llama) and the shader checks. @@ -578,18 +565,15 @@ authorizes catalog downloads. Each browser runtime generation reads its catalog at its own path of `stdlogits/drowse-web-catalog` (`webui/scripts/hosted-catalog-location.mjs`): runtime v1 builds read the root `catalog.json` (sequences up to 10), runtime v2 builds (hook ABI v5) -`v2/catalog.json` and `v2/catalog.sig.json` (from 11), which the lock names and -`check-runtime-lock.mjs` requires. Publishing a catalog for the new runtime therefore never +`v2/catalog.json` (11), runtime v3 builds (hook ABI v6) `v3/catalog.json` and +`v3/catalog.sig.json` (from 12), which the lock names and `check-runtime-lock.mjs` requires. Publishing a catalog for the new runtime therefore never changes what the deployed site reads, and builds of the previous runtime keep working until the new one is deployed. ## Release 1. Compile the libraries with the overlay (`compiler/README.md`) and assemble each - (`assemble:hosted:model`). When the overlay, the bridge or the drowse goldens change, run the - fixture goldens: `browser-runtime/record-cvm-goldens.py` on the C TVM VM and - `webui/scripts/browser-units-goldens.mjs --report` on WebGPU (run it with - `--webllm node_modules/@drowse/web-llm/lib/index.js`). They are checks, not records. + (`assemble:hosted:model`). 2. Fill a candidate lock from the assembled directories (`prepare:hosted:candidate-lock`, one model at a time with `--base`), rebind the packs and build each core pack against it. 3. Publish each model's files and core pack (`publish:hosted:model`, `publish:hosted:pack ... core`), @@ -620,8 +604,8 @@ accepts an Ed25519 PKCS#8 PEM key path and signs the exact `catalog.json` bytes. The publisher writes to the directory the lock's URLs name and verifies the catalog published there against the lock's keys before it advances the sequence. The first catalog at a new directory has nothing there to advance, so the publisher verifies the previous directory's -catalog instead (the one deployed builds still read) and requires a greater sequence: catalog 11 -at `v2/` must verify the root's catalog 10 and exceed it. A new directory whose predecessor has +catalog instead (the one deployed builds still read) and requires a greater sequence: catalog 12 +at `v3/` must verify `v2/`'s catalog 11 and exceed it. A new directory whose predecessor has nothing published is refused; only the root may start without one. `./deploy.sh` checks the signed catalog at the lock's URL before every upload (`preflight-hosted-distribution.mjs`), so a build never ships pointing at an unpublished path. A rotation that cannot sign with the outgoing diff --git a/browser-runtime/build_hosted_packs.py b/browser-runtime/build_hosted_packs.py index 78c9524..727817d 100644 --- a/browser-runtime/build_hosted_packs.py +++ b/browser-runtime/build_hosted_packs.py @@ -21,7 +21,8 @@ The packs bind the runtime identity they are built for (``--runtime-identity``, written by ``webui/scripts/hosted-runtime-identity.mjs``) and, for units, the identities of the lens packs and statistics they average over. Lens shards are -the native files byte for byte, so a pack shard's digest is the native manifest's. +the native files byte for byte; the pack manifest records each shard's digest +(native lens manifests no longer carry one). Output goes to a staging directory; ``build-hosted-packs.sh`` assembles and validates it. Nothing is published from here. """ @@ -288,8 +289,6 @@ def build_lens_pack( name = f"{site}.layer-{layer}.safetensors" shutil.copyfile(source, pack / name) digest = sha256_file(pack / name) - if digest != native["tensor_sha256"][str(layer)]: - raise PackBuildError(f"{source} does not match its manifest digest") files[str(layer)] = name digests[str(layer)] = digest sites[site] = {"layers": layers, "tensor_files": files, "tensor_sha256": digests} diff --git a/browser-runtime/compiler/README.md b/browser-runtime/compiler/README.md index e1eff39..6ffa1f4 100644 --- a/browser-runtime/compiler/README.md +++ b/browser-runtime/compiler/README.md @@ -16,7 +16,7 @@ clang, configured like the archive (Release, its 19 targets, assertions/RTTI/EH archive's libraries were compiled against GCC 7's libstdc++, whose `std::optional` ABI no C++20 libstdc++ shares, so a TVM linked against them segfaults on import. The lock binds the tag and commit (`toolchain.llvmSourceBuild`) and `check-runtime-lock.mjs` requires the Dockerfile's -`LLVM_SOURCE_*_AMD64` arguments to match. The jobe toolchain the hook ABI v5 libraries were +`LLVM_SOURCE_*_AMD64` arguments to match. The jobe toolchain the hook ABI v5 and v6 libraries were compiled with is the same build (parity handoff `B40-toolchain.md` §3, §8); the image itself has not been rebuilt since. Emscripten 3.1.56 does not publish Linux ARM64 binaries, so the ARM64 image runs only @@ -30,10 +30,8 @@ colima start --vm-type vz --vz-rosetta The build pins the Ubuntu base digest, LLVM archives and source, Emscripten SDK commit, TVM/TVM-FFI sources, MLC source, and both Drowse overlays. Its final build gate runs the C VM -structured, geometry and readout goldens, then compiles fp32 and q4 Qwen3, Llama and Gemma 3 -WebGPU fixture libraries under the v5 export check. The units goldens need the fixture models -`forks/build-units-fixtures.py` makes from drowse's checkpoints; they run outside the image -(`browser-runtime/record-cvm-goldens.py`, README "Release"). +structured, geometry and readout cases, then compiles fp32 and q4 Qwen3, Llama and Gemma 3 +WebGPU fixture libraries under the v5 export check. The local image ID is feasibility evidence only. A production runtime lock must name an immutable registry reference and manifest digest for the published @@ -57,10 +55,10 @@ runtime lock until either the compiler output is canonicalized reproducibly or the release process records and physically validates one immutable emitted library per model variant. -Every hook ABI v5 library is converted from its pinned source snapshot and compiled with this -overlay (no upstream MLC closure is adopted): `convert` records `drowse-web-runtime-v2`, -`block-sites-v5` and the architecture's profile (`standard-v4` for Gemma 3 and Qwen3, -`standard-v4-residual` otherwise) in `drowse-build.json`, and `compile` refuses a manifest from +Every hook ABI v6 library is converted from its pinned source snapshot and compiled with this +overlay (no upstream MLC closure is adopted): `convert` records `drowse-web-runtime-v3`, +`block-sites-v6` and the architecture's profile (`standard-v5` for Gemma 3 and Qwen3, +`standard-v5-residual` otherwise) in `drowse-build.json`, and `compile` refuses a manifest from another ABI: ```bash diff --git a/browser-runtime/distribution-lock.json b/browser-runtime/distribution-lock.json index 2233622..2aebb0f 100644 --- a/browser-runtime/distribution-lock.json +++ b/browser-runtime/distribution-lock.json @@ -2,9 +2,9 @@ "$schema": "./distribution-lock.schema.json", "schemaVersion": 1, "status": "verified", - "catalogUrl": "https://huggingface.co/stdlogits/drowse-web-catalog/resolve/main/v2/catalog.json", - "signatureUrl": "https://huggingface.co/stdlogits/drowse-web-catalog/resolve/main/v2/catalog.sig.json", - "minimumAcceptedSequence": 11, + "catalogUrl": "https://huggingface.co/stdlogits/drowse-web-catalog/resolve/main/v3/catalog.json", + "signatureUrl": "https://huggingface.co/stdlogits/drowse-web-catalog/resolve/main/v3/catalog.sig.json", + "minimumAcceptedSequence": 12, "publicKeys": [ { "keyId": "drowse-2026-10-current", diff --git a/browser-runtime/export-units-tiny-whitener.py b/browser-runtime/export-units-tiny-whitener.py deleted file mode 100644 index fb7d9a4..0000000 --- a/browser-runtime/export-units-tiny-whitener.py +++ /dev/null @@ -1,65 +0,0 @@ -"""Export the units-tiny fixture session's neutral whitener (drowse's -``tests/support/browser_units.py::fixture``) in the browser's eigen form, so the -host `unitFind` port can replay drowse's unit-reads golden without Python. - -Per layer the whitener is ``Σ = λI + XᵀX/N`` over the centred neutral rows ``X``; -the browser's ``SerializedMahalanobisWhitener`` holds ``λ`` (``ridge``), the -right-singular directions ``V`` (``basis`` rows) and ``s²/N`` (``eigenvalues``), -from which ``Σ^{-1/2} = (1/√λ)(I − V diag(g) Vᵀ)``, ``g = 1 − √(λ/(λ+s²/N))`` -(native ``LayerWhitener._root_factors``). - -Run from the drowse.ai root: PYTHONPATH=drowse python browser-runtime/export-units-tiny-whitener.py -""" -from __future__ import annotations - -import json -import sys -from pathlib import Path - -import torch - -sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "drowse")) - -from tests.support.browser_units import ARCHES, fixture, model_file_sha256 # noqa: E402 - -OUT = Path(__file__).resolve().parent / "fixtures" / "units-tiny-whitener-v1.json" - - -def export() -> dict: - arches = {} - for arch in ARCHES: - with fixture(arch) as fx: - whitener = fx.session.whitener - assert whitener is not None - layers = [] - for layer in sorted(int(L) for L in whitener.layer_means): - X = whitener._X[layer].to(torch.float64) - n = int(X.shape[0]) - lam = float(whitener._lambda[layer]) - evals, U = torch.linalg.eigh(X @ X.T) - keep = evals > max(float(evals.max()), 0.0) * 1e-12 - s2 = evals[keep] - V = (X.T @ U[:, keep]) / s2.sqrt() - order = torch.argsort(s2, descending=True) - layers.append({ - "layer": layer, - "rows": n, - "ridge": lam, - "mean": [float(x) for x in whitener.layer_means[layer].double()], - "eigenvalues": [float(x) for x in (s2[order] / n)], - "basis": [[float(x) for x in V[:, i]] for i in order.tolist()], - }) - arches[arch] = layers - return { - "schemaVersion": 1, - "about": "The units-tiny fixture session's neutral whitener per layer in eigen form " - "(ridge λ, basis rows V, eigenvalues s²/N); generated by " - "browser-runtime/export-units-tiny-whitener.py from drowse's fixture.", - "fixtureModels": {"name": "units-tiny-models-v1", "sha256": model_file_sha256()}, - "arches": arches, - } - - -if __name__ == "__main__": - OUT.write_text(json.dumps(export(), indent=1) + "\n") - print(OUT) diff --git a/browser-runtime/fitting-wasm/src/kernel.rs b/browser-runtime/fitting-wasm/src/kernel.rs index ab65bb6..9d98456 100644 --- a/browser-runtime/fitting-wasm/src/kernel.rs +++ b/browser-runtime/fitting-wasm/src/kernel.rs @@ -1,8 +1,8 @@ use crate::error::{invalid, KernelResult}; use crate::linalg::{ center_rows, checked_finite, checked_matrix, checked_output, checked_vector, checked_work, - matrix_rank, mean_rows, orthonormalize_rows, solve, symmetric_eigen, - thin_covariance_components, thin_principal_components, validate_orthonormal, + dual_read, matrix_rank, mean_rows, solve, symmetric_eigen, thin_covariance_components, + thin_principal_components, validate_orthonormal, }; const NEAR_ZERO_VARIANCE: f64 = 1e-12; @@ -65,7 +65,10 @@ pub struct AffineFisherFit { pub components: usize, pub centroid_mean: Vec, pub mean: Vec, + /// Write rows (vectors), Mahalanobis-orthonormal. pub basis: Vec, + /// Read rows (covectors), their Σ⁻¹ images: `read · basisᵀ = I`. + pub read: Vec, pub node_coordinates: Vec, pub mu_coordinates: Vec, pub whitened_gram: Vec, @@ -704,35 +707,45 @@ pub fn fit_affine_fisher( .filter(|value| value.max(0.0) > 1e-6 * leading.max(1e-12)) .count(); let components = max_components.min(node_count - 1).min(stable_rank).max(1); - let mut directions = vec![0.0; checked_output("Fisher directions", &[components, columns])?]; + // A typed frame: PCA in the whitened space mapped back with the right types. For the + // eigenpairs (a, μ) of G = X Σ⁻¹ Xᵀ the write rows are the vectors Xᵀa/√μ (Mahalanobis- + // orthonormal, since aᵀGa = μ) and the read rows their covectors aᵀ(Σ⁻¹X)/√μ, made exactly + // dual. Two nodes write along δ and read with Σ⁻¹δ. + let frame_elements = checked_output("affine frame", &[components, columns])?; + let mut basis = vec![0.0; frame_elements]; + let mut raw_read = vec![0.0; frame_elements]; for component in 0..components { + let scale = 1.0 / eigenvalues[component].max(1e-30).sqrt(); for column in 0..columns { - directions[component * columns + column] = (0..node_count) - .map(|row| { - eigenvectors[row * node_count + component] - * inverse_rows[row * columns + column] - }) - .sum::(); + let mut write = 0.0; + let mut read = 0.0; + for row in 0..node_count { + let coefficient = eigenvectors[row * node_count + component]; + write += coefficient * centered[row * columns + column]; + read += coefficient * inverse_rows[row * columns + column]; + } + basis[component * columns + column] = write * scale; + raw_read[component * columns + column] = read * scale; } } - let mut basis = orthonormalize_rows(&directions, components, columns)?; + let mut read = dual_read(&basis, &raw_read, components, columns)?; for component in 0..components { let projection = (0..columns) .map(|column| { - basis[component * columns + column] - * (centroids[orient_to * columns + column] - centroid_mean[column]) + read[component * columns + column] * centered[orient_to * columns + column] }) .sum::(); if projection < 0.0 { for column in 0..columns { basis[component * columns + column] = -basis[component * columns + column]; + read[component * columns + column] = -read[component * columns + column]; } } } let mut mean = vec![0.0; columns]; for component in 0..components { let coordinate = (0..columns) - .map(|column| whitener.mean[column] * basis[component * columns + column]) + .map(|column| whitener.mean[column] * read[component * columns + column]) .sum::(); for column in 0..columns { mean[column] += coordinate * basis[component * columns + column]; @@ -745,12 +758,12 @@ pub fn fit_affine_fisher( node_coordinates[node * components + component] = (0..columns) .map(|column| { (centroids[node * columns + column] - whitener.mean[column]) - * basis[component * columns + column] + * read[component * columns + column] }) .sum::(); mu_coordinates[node * components + component] = (0..columns) .map(|column| { - centered[node * columns + column] * basis[component * columns + column] + centered[node * columns + column] * read[component * columns + column] }) .sum::(); } @@ -790,6 +803,7 @@ pub fn fit_affine_fisher( .sum::(); let explained_variance = if total > 1e-12 { retained / total } else { 1.0 }; checked_finite("affine Fisher basis", &basis)?; + checked_finite("affine Fisher read rows", &read)?; checked_finite("affine Fisher coordinates", &node_coordinates)?; Ok(AffineFisherFit { node_count, @@ -798,6 +812,7 @@ pub fn fit_affine_fisher( centroid_mean, mean, basis, + read, node_coordinates, mu_coordinates, whitened_gram, diff --git a/browser-runtime/fitting-wasm/src/lib.rs b/browser-runtime/fitting-wasm/src/lib.rs index 4f50fef..bcaabbb 100644 --- a/browser-runtime/fitting-wasm/src/lib.rs +++ b/browser-runtime/fitting-wasm/src/lib.rs @@ -222,6 +222,9 @@ impl AffineFisherFit { pub fn basis(&self) -> Vec { self.0.basis.clone() } + pub fn read(&self) -> Vec { + self.0.read.clone() + } #[wasm_bindgen(js_name = nodeCoordinates)] pub fn node_coordinates(&self) -> Vec { self.0.node_coordinates.clone() diff --git a/browser-runtime/fitting-wasm/src/linalg.rs b/browser-runtime/fitting-wasm/src/linalg.rs index 13c4dcc..a897cd9 100644 --- a/browser-runtime/fitting-wasm/src/linalg.rs +++ b/browser-runtime/fitting-wasm/src/linalg.rs @@ -339,37 +339,26 @@ pub fn validate_orthonormal(basis: &[f64], components: usize, columns: usize) -> Ok(()) } -pub fn orthonormalize_rows(values: &[f64], rows: usize, columns: usize) -> KernelResult> { - checked_matrix("basis candidates", values, rows, columns)?; - let mut basis = vec![0.0; values.len()]; - for row in 0..rows { - let start = row * columns; - basis[start..start + columns].copy_from_slice(&values[start..start + columns]); - for previous in 0..row { - let dot = (0..columns) - .map(|column| basis[start + column] * basis[previous * columns + column]) +/// `read` corrected to be exactly dual to `basis` (`read · basisᵀ = I`): one `(R, R)` solve, +/// `(read · basisᵀ)⁻¹ read`, which keeps the reads in their own span and leaves the write rows +/// untouched (drowse's `dual_read`). +pub fn dual_read( + basis: &[f64], + read: &[f64], + rows: usize, + columns: usize, +) -> KernelResult> { + checked_matrix("frame write rows", basis, rows, columns)?; + checked_matrix("frame read rows", read, rows, columns)?; + let mut gram = vec![0.0; rows * rows]; + for left in 0..rows { + for right in 0..rows { + gram[left * rows + right] = (0..columns) + .map(|column| read[left * columns + column] * basis[right * columns + column]) .sum::(); - for column in 0..columns { - basis[start + column] -= dot * basis[previous * columns + column]; - } - } - let norm = basis[start..start + columns] - .iter() - .map(|value| value * value) - .sum::() - .sqrt(); - if norm <= f64::EPSILON { - return Err(invalid(format!( - "basis candidate {row} is numerically dependent" - ))); - } - for value in &mut basis[start..start + columns] { - *value /= norm; } } - checked_finite("orthonormal basis", &basis)?; - validate_orthonormal(&basis, rows, columns)?; - Ok(basis) + solve(gram, rows, read.to_vec(), columns) } pub fn solve( diff --git a/browser-runtime/fitting-wasm/tests/golden.rs b/browser-runtime/fitting-wasm/tests/golden.rs index 7f2672c..6b563e1 100644 --- a/browser-runtime/fitting-wasm/tests/golden.rs +++ b/browser-runtime/fitting-wasm/tests/golden.rs @@ -170,40 +170,67 @@ fn affine_fisher_fit_matches_python_golden() { let fit = fit_affine_fisher(¢roids, 4, 3, &whitener, 2, 0).unwrap(); assert_eq!(fit.components, 2); close(&fit.centroid_mean, &[2.75, 2.5, 3.0], 2e-6); + // drowse 6.1's typed frame: write rows Xᵀa/√μ, reads their exact duals. close( &fit.mean, - &[1.2346981763839722, 2.5237584114074707, 0.07898344099521637], - 3e-6, + &[1.8822275400161743, 2.184915781021118, 0.7836301922798157], + 5e-6, ); close( &fit.basis, &[ - 0.43905341625213623, - -0.5828602313995361, - -0.6837441325187683, - -0.6327729821205139, - -0.7408590316772461, - 0.22522473335266113, + 0.08855901658535004, + -1.0993337631225586, + -1.1802712678909302, + -1.3194433450698853, + -0.991281270980835, + -0.002233356237411499, + ], + 5e-6, + ); + close( + &fit.read, + &[ + 0.29533177614212036, + -0.3920646607875824, + -0.4599246382713318, + -0.4960780739784241, + -0.3491402268409729, + 0.2879756987094879, ], - 3e-6, + 5e-6, ); close( &fit.node_coordinates, &[ - 0.054469551891088486, - 2.450920343399048, - 1.033460259437561, - 0.21929070353507996, - -1.2045018672943115, - -2.818382978439331, - -5.155755043029785, - -0.9852488040924072, + 0.03663991391658783, + 1.5507805347442627, + 0.6951634287834167, + -0.07849155366420746, + -0.8102163076400757, + -1.5421169996261597, + -3.468050241470337, + 0.460904061794281, + ], + 5e-6, + ); + close( + &fit.mu_coordinates, + &[ + 0.9232556819915771, + 1.4530115127563477, + 1.5817792415618896, + -0.1762605905532837, + 0.07639949023723602, + -1.6398860216140747, + -2.581434488296509, + 0.36313506960868835, ], 5e-6, ); close( &[fit.explained_variance, fit.mahalanobis_share], - &[0.9989494040944763, 3.9487561597350385], + &[0.9989493407302187, 3.8713648573157595], 5e-6, ); close( @@ -218,6 +245,67 @@ fn affine_fisher_fit_matches_python_golden() { ); } +/// The frame is typed (drowse 6.1): write rows are Mahalanobis-orthonormal vectors, the reads +/// their exact duals, and a two-node fit writes along the difference of means (PCA@2 ≡ DiM). +/// A regression to reading and writing along one Euclidean basis would steer along Σ⁻¹δ. +#[test] +fn affine_fisher_frame_is_typed() { + let neutral = [ + 1.0, 2.0, 0.0, 2.0, 0.0, 1.0, 4.0, 1.0, 3.0, 3.0, 3.0, 2.0, 5.0, 2.0, 4.0, + ]; + let whitener = fit_mahalanobis_whitener(&neutral, 5, 3, 1.0).unwrap(); + let mahalanobis_gram = |rows: &[f64], count: usize| -> Vec { + let shifted: Vec = rows + .iter() + .enumerate() + .map(|(index, value)| value + whitener.mean[index % 3]) + .collect(); + let whitened = apply_mahalanobis_whitener(&whitener, &shifted, count).unwrap(); + let mut gram = vec![0.0; count * count]; + for left in 0..count { + for right in 0..count { + gram[left * count + right] = (0..3) + .map(|column| whitened[left * 3 + column] * whitened[right * 3 + column]) + .sum(); + } + } + gram + }; + let centroids = [1.0, 0.0, 2.0, 3.0, 1.0, 1.0, 5.0, 4.0, 3.0, 2.0, 5.0, 6.0]; + let fit = fit_affine_fisher(¢roids, 4, 3, &whitener, 2, 0).unwrap(); + close( + &mahalanobis_gram(&fit.basis, 2), + &[1.0, 0.0, 0.0, 1.0], + 1e-9, + ); + let mut duality = vec![0.0; 4]; + for left in 0..2 { + for right in 0..2 { + duality[left * 2 + right] = (0..3) + .map(|column| fit.read[left * 3 + column] * fit.basis[right * 3 + column]) + .sum(); + } + } + close(&duality, &[1.0, 0.0, 0.0, 1.0], 1e-12); + + let pair = [3.0, 1.0, 1.0, 1.0, 0.0, 2.0]; + let fit = fit_affine_fisher(&pair, 2, 3, &whitener, 4, 0).unwrap(); + assert_eq!(fit.components, 1); + let delta = [2.0, 1.0, -1.0]; + let norm = mahalanobis_gram(&delta, 1)[0].sqrt(); + close( + &fit.basis, + &delta.iter().map(|value| value / norm).collect::>(), + 1e-12, + ); + // The pole pair reads ‖δ‖_M apart: δ · Σ⁻¹δ/‖δ‖_M. + close( + &[fit.mu_coordinates[0] - fit.mu_coordinates[1]], + &[norm], + 1e-12, + ); +} + #[test] fn pca_recovers_axis_and_threshold() { let values = [-3.0, 0.1, -1.0, -0.1, 1.0, -0.1, 3.0, 0.1]; diff --git a/browser-runtime/fitting-wasm/tests/topology_robustness.rs b/browser-runtime/fitting-wasm/tests/topology_robustness.rs index 874712a..416184e 100644 --- a/browser-runtime/fitting-wasm/tests/topology_robustness.rs +++ b/browser-runtime/fitting-wasm/tests/topology_robustness.rs @@ -82,12 +82,36 @@ fn gram(points: &[Vec]) -> Vec { .collect() } +// Adversarial shapes and the number of periodic axes the chart must find: tori that fit (a +// circle, a product of circles) and shapes that must not chart (embedded donuts, Mobius strips, +// cylinders, spheres, arcs, grids, lines). +const SHAPES: &str = "\ +shape,around,across,width,noise,expected_axes +circle,48,1,1,0,1 +ellipse,80,1,6,0,1 +circle,64,1,1,0.015,1 +product,8,8,1,0,2 +product,16,8,0.3,0,2 +product,17,7,0.35,0,2 +product,16,8,0.3,0.002,2 +product,16,8,0.1,0,0 +donut,12,8,0.4,0,0 +donut,16,8,0.3,0,0 +mobius,24,5,0.5,0,0 +mobius,24,5,0.1,0,0 +cylinder,24,5,0.5,0,0 +sphere,40,1,1,0,0 +sphere,80,1,1,0,0 +sphere,100,1,1,0.005,0 +sphere,127,1,1,0,0 +arc,64,1,1,0,0 +grid,8,8,1,0,0 +line,64,1,1,0,0 +"; + #[test] -fn shared_adversarial_shapes_and_coordinate_fidelity() { - for line in include_str!("../../../drowse/tests/fixtures/browser/topology-adversarial-v1.csv") - .lines() - .skip(1) - { +fn adversarial_shapes_and_coordinate_fidelity() { + for line in SHAPES.lines().skip(1) { let fields: Vec<&str> = line.split(',').collect(); let expected: usize = fields[5].parse().unwrap(); for variant in 0..3 { diff --git a/browser-runtime/fixtures/shared-parity-suite-v1.json b/browser-runtime/fixtures/shared-parity-suite-v1.json deleted file mode 100644 index 43caab3..0000000 --- a/browser-runtime/fixtures/shared-parity-suite-v1.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "schemaVersion": 1, - "description": "Paired Python/browser parity corpus used by the sharedGoldenResults release observer.", - "fixtures": [ - "drowse/tests/fixtures/browser/structured-program-parity-v1.json", - "drowse/tests/fixtures/browser/measurement-envelope-v2.json", - "drowse/tests/fixtures/browser/loom-operation-transcript-v1.json", - "drowse/tests/fixtures/browser/recipe-compose-v1.json", - "drowse/tests/fixtures/browser/sampling-parity-v1.json", - "drowse/tests/fixtures/browser/topology-rbf-parity-v1.json", - "browser-runtime/fixtures/drowse-interchange-v1.json" - ], - "claims": [ - "expression parsing", - "authoritative loom mutations", - "call composition precedence", - "measurement envelopes", - "structured steering and instruments", - "top-k/top-p sampling distribution", - "manifold geometry and fitting", - "reciprocal artifact interchange and compatibility rejection" - ] -} diff --git a/browser-runtime/fixtures/unit-ablation-mixed-affine-v1.json b/browser-runtime/fixtures/unit-ablation-mixed-affine-v1.json deleted file mode 100644 index bfe2029..0000000 --- a/browser-runtime/fixtures/unit-ablation-mixed-affine-v1.json +++ /dev/null @@ -1,1675 +0,0 @@ -{ - "schemaVersion": 1, - "about": "The unit-ablation `mixed` case's push lowered to affine groups by drowse's lowered_pushes on each fixture session (neuron-push's case shape). Regenerate with python browser-runtime/forks/build-mixed-affine.py.", - "golden": "unit-ablation", - "case": "mixed", - "fixtureModels": { - "sha256": "2140e50d3430d336deda0aee630c52e40e8134aec55d2b58c8dc4ef7c15f1006" - }, - "arches": { - "qwen3": { - "cases": [ - { - "expression": "0.4 deceptive_fixture", - "canonical": "0.4 deceptive_fixture", - "coefficient": 0.4, - "trigger": { - "prompt": true, - "generated": true, - "thinking": true, - "response": true, - "first_n": null, - "after_n": null, - "gate": null - }, - "layers": [ - { - "layer": 0, - "basis": [ - -0.17514566, - -0.18307178, - -0.111448176, - -0.25933287, - -0.04074199, - 0.11612913, - -0.11981553, - 0.21491641, - 0.099776424, - -0.015300186, - -0.08912655, - 0.0059649437, - -0.06196073, - 0.09906269, - -0.17441855, - 0.05217356, - -0.13243636, - 0.15571228, - -0.111681215, - -0.16562071, - -0.013849349, - 0.08580962, - 0.050539795, - -0.14128439, - 0.056334484, - -0.050274514, - 0.16889724, - 0.023731597, - -0.15390925, - -0.08410047, - -0.057433352, - -0.12375604, - -0.00046795193, - 0.1405088, - 0.10768328, - -0.07149072, - -0.019210633, - 0.1554947, - 0.025636915, - -0.062738895, - -0.058879655, - -0.21302353, - 0.21253279, - 0.3583691, - 0.07820241, - 0.023272078, - 0.19586712, - 0.0048648156, - -0.063411795, - 0.21821946, - -0.032691017, - 0.020613268, - -0.06917805, - -0.03128615, - 0.015377442, - 0.028302185, - -0.041774206, - -0.01656112, - -0.042950787, - 0.002097161, - -0.21908036, - 0.15058614, - -0.13274677, - -0.18540505 - ], - "neutral": [ - -1.0697541, - 0.5980025, - -0.62266487, - 0.48415062, - 0.9949875, - 1.4079958, - 0.5412151, - 0.24653126, - -0.5583217, - -0.0560521, - 0.2563484, - -1.9526263, - 0.042111605, - 0.91166836, - 1.5351591, - -0.22556959, - 0.41342497, - 1.7063704, - -0.35431933, - -0.6667204, - 0.8396592, - 0.5784123, - -0.65091294, - 0.4576738, - -0.8654752, - 0.17347713, - -1.0710843, - -0.026679069, - -0.932949, - 0.1308341, - 1.2947704, - -0.1102646, - -0.50611275, - -0.10273012, - -0.0011565374, - -0.9610713, - 0.0007523571, - -0.41574287, - -1.1953559, - -0.4055067, - 0.9238321, - -0.12423193, - 1.8482071, - 0.14442427, - 0.5066812, - -0.1547352, - 0.31152064, - 0.06653554, - 0.9140094, - -0.73482746, - 0.5601327, - -0.78795004, - 0.17368877, - 1.3637522, - 0.255479, - 0.9373276, - -1.1588248, - -0.15820484, - -0.92295545, - -0.26795825, - 0.061374705, - 0.9107198, - -0.4912306, - 1.0379199 - ], - "target": 0.03789323, - "along": 25.823328, - "delta": [ - -0.17138515, - -0.17914109, - -0.1090553, - -0.25376478, - -0.03986723, - 0.11363575, - -0.117243, - 0.210302, - 0.09763415, - -0.01497168, - -0.08721294, - 0.005836872, - -0.06063039, - 0.09693574, - -0.17067365, - 0.051053356, - -0.12959287, - 0.15236902, - -0.10928334, - -0.16206472, - -0.013551993, - 0.08396722, - 0.049454667, - -0.13825092, - 0.05512494, - -0.049195085, - 0.1652709, - 0.02322206, - -0.15060471, - -0.08229477, - -0.056200214, - -0.12109891, - -0.00045790465, - 0.13749197, - 0.10537124, - -0.06995576, - -0.018798167, - 0.15215611, - 0.025086472, - -0.06139184, - -0.057615463, - -0.20844975, - 0.20796955, - 0.35067466, - 0.07652335, - 0.022772409, - 0.1916617, - 0.0047603645, - -0.062050298, - 0.21353413, - -0.031989116, - 0.020170687, - -0.06769275, - -0.030614413, - 0.015047277, - 0.027694516, - -0.040877283, - -0.016205542, - -0.042028602, - 0.0020521334, - -0.21437655, - 0.14735295, - -0.1298966, - -0.18142426 - ] - }, - { - "layer": 1, - "basis": [ - 0.12802486, - -0.3008057, - -0.031642243, - -0.20326264, - 0.15958025, - -0.10817753, - 0.04889052, - -0.104113735, - -0.12643212, - 0.038898, - -0.15250559, - -0.078945994, - 0.06334095, - -0.02963724, - -0.11546804, - -0.046584148, - -0.05966067, - -0.109168015, - 0.048441093, - 0.01960365, - 0.02420044, - 0.08219224, - 0.14603764, - 0.04916857, - 0.06219474, - -0.10011375, - 0.021254286, - 0.19077738, - -0.13675177, - 0.18375218, - -0.008679528, - 0.13963437, - -0.062314693, - 0.21634932, - 0.045094773, - -0.038764756, - 0.1808059, - 0.03987397, - 0.28482848, - -0.27354437, - 0.21405844, - 0.122975126, - -0.038667053, - 0.04395464, - 0.003269747, - 0.07348564, - 0.03495461, - 0.22175246, - -0.013022964, - 0.07504336, - 0.10964745, - -0.024328673, - -0.14068541, - -0.106761426, - -0.0118470155, - -0.098838456, - 0.005225938, - -0.25786337, - 0.020093635, - -0.06331667, - -0.120816186, - 0.004054965, - 0.19649477, - -0.11245577 - ], - "neutral": [ - -1.1489043, - 0.66334873, - -0.331071, - 1.4405504, - 0.7537279, - 1.276424, - 0.087124966, - 0.26788065, - -0.5330119, - -0.7228864, - 0.67532283, - -1.9355294, - -0.11008074, - 0.20615493, - 1.5101553, - -0.20731449, - 0.31628898, - 1.8702863, - -0.24037302, - -0.34410205, - 0.4802817, - 0.22172844, - -0.960725, - 0.50646406, - -1.4034104, - 0.43842185, - -0.5915393, - -0.024377147, - -1.1723615, - -0.035872586, - 0.8888337, - -0.16504191, - -0.2052579, - 0.9123388, - 0.9835431, - -0.07350717, - 0.68469554, - -0.29789487, - -1.7445227, - 0.16906886, - 1.1819685, - -0.2213497, - 2.156016, - -0.07718279, - -0.32519507, - -0.9837756, - 0.06553345, - -0.54566085, - 1.0326622, - -0.5658421, - 0.5097351, - -0.89339787, - -0.88046074, - 1.4606498, - 0.7556698, - 1.0270442, - -1.1929218, - -0.068277635, - -0.72793156, - -0.110670745, - 0.43531215, - 0.8252082, - -0.29633963, - 1.8864964 - ], - "target": 0.060335994, - "along": 16.218, - "delta": [ - 0.12527606, - -0.29434714, - -0.030962856, - -0.19889842, - 0.15615393, - -0.10585487, - 0.0478408, - -0.10187833, - -0.12371752, - 0.038062826, - -0.14923117, - -0.07725096, - 0.06198096, - -0.029000904, - -0.11298885, - -0.04558395, - -0.058379706, - -0.106824085, - 0.047401022, - 0.019182742, - 0.023680836, - 0.080427505, - 0.14290209, - 0.048112884, - 0.060859364, - -0.09796423, - 0.020797938, - 0.18668123, - -0.1338156, - 0.17980686, - -0.008493171, - 0.1366363, - -0.060976744, - 0.21170412, - 0.04412655, - -0.037932444, - 0.17692386, - 0.03901784, - 0.278713, - -0.26767114, - 0.20946243, - 0.12033475, - -0.03783684, - 0.043010898, - 0.0031995426, - 0.07190785, - 0.034204107, - 0.21699126, - -0.01274335, - 0.07343212, - 0.10729323, - -0.023806317, - -0.13766478, - -0.10446917, - -0.01159265, - -0.096716315, - 0.0051137325, - -0.25232682, - 0.019662207, - -0.06195721, - -0.11822216, - 0.003967901, - 0.19227587, - -0.11004125 - ] - }, - { - "layer": 2, - "basis": [ - -0.0013273365, - -0.026159232, - 0.058747508, - -0.060686667, - -0.05641908, - -0.10147167, - -0.013408528, - 0.09652096, - 0.023885418, - -0.123380326, - -0.15079577, - -0.06470642, - -0.04420568, - 0.020028412, - 0.027295806, - 0.053211637, - -0.11256717, - -0.13212574, - -0.033447623, - 0.24678111, - -0.1501725, - 0.24557772, - 0.2144965, - 0.17390865, - -0.37098253, - -0.08778755, - -0.037413254, - -0.23207977, - 0.039156392, - -0.038149253, - -0.05469322, - -0.057865158, - -0.25312296, - -0.084689885, - 0.02320707, - -0.014365518, - 0.07787877, - 0.19128294, - 0.14986646, - 0.100673065, - -0.14003016, - 0.122285455, - 0.120910265, - -0.13852194, - -0.07417545, - -0.03791068, - 0.020011386, - 0.10167566, - -0.08845829, - -0.16636658, - -0.15804636, - 0.0022928785, - 0.04547566, - -0.04490024, - 0.06698658, - 0.07136511, - 0.02187674, - 0.17226067, - 0.012130006, - 0.11810753, - 0.13246758, - 0.11251671, - 0.25416997, - 0.11345745 - ], - "neutral": [ - -1.1361581, - 1.0497185, - 0.15657717, - 1.0506705, - 1.0729295, - 1.2391597, - 0.1344861, - -0.13217883, - -0.85807353, - -0.2682, - 0.47560444, - -1.9608706, - -0.019228162, - 0.75979495, - 1.8830032, - -0.17108698, - 1.1172285, - 1.0450405, - 0.4929612, - -1.0516003, - 0.44990543, - 0.31380934, - -0.30493772, - 0.2873628, - -0.928504, - -0.89649653, - -0.7381714, - -0.2547708, - -0.441094, - -0.39500263, - 1.0224733, - 0.43456802, - -0.00023164351, - 1.1087089, - 1.0855498, - 0.21198261, - 0.7086305, - -0.10458102, - -1.4401479, - 0.38656035, - 0.96317333, - 0.53272986, - 2.3079002, - -1.3511573, - 0.5077557, - -1.0545553, - -0.9975011, - 0.047818065, - 0.8516593, - 0.102646835, - 0.12864351, - -0.80223536, - -1.039478, - 0.9660736, - 0.690741, - 1.6428763, - -1.2846469, - -0.66371906, - -0.022738198, - -0.8345139, - 0.3874209, - 0.21338554, - -0.8968024, - 1.828379 - ], - "target": 0.08374844, - "along": 11.684153, - "delta": [ - -0.001298838, - -0.025597582, - 0.05748617, - -0.059383694, - -0.055207733, - -0.09929303, - -0.01312064, - 0.09444861, - 0.023372585, - -0.12073129, - -0.14755811, - -0.06331715, - -0.043256562, - 0.019598393, - 0.026709752, - 0.052069157, - -0.1101503, - -0.12928893, - -0.032729488, - 0.2414826, - -0.14694822, - 0.24030505, - 0.20989116, - 0.17017475, - -0.36301735, - -0.08590271, - -0.036609974, - -0.22709692, - 0.038315687, - -0.03733017, - -0.05351893, - -0.056622766, - -0.24768828, - -0.08287155, - 0.022708803, - -0.014057084, - 0.07620668, - 0.187176, - 0.14664876, - 0.09851157, - -0.13702364, - 0.11965993, - 0.118314266, - -0.13554782, - -0.07258287, - -0.03709672, - 0.019581731, - 0.09949263, - -0.08655905, - -0.1627946, - -0.15465303, - 0.0022436492, - 0.044499278, - -0.043936208, - 0.06554835, - 0.06983287, - 0.021407034, - 0.16856216, - 0.011869569, - 0.1155717, - 0.12962344, - 0.11010092, - 0.24871281, - 0.11102146 - ] - }, - { - "layer": 3, - "basis": [ - -0.095428504, - -0.1381515, - -0.08098698, - -0.16672224, - 0.118157335, - 0.026236234, - 0.22838944, - 0.16707137, - 0.09002252, - -0.021561064, - 0.22692604, - -0.019395495, - 0.3150662, - -0.17050838, - -0.00714425, - 0.16543533, - -0.04909524, - -0.013380147, - 0.07568769, - -0.180776, - 0.19890817, - 0.01439452, - -0.06733633, - -0.11984725, - 0.1028429, - 0.06190719, - -0.22032516, - -0.01626377, - 0.11876741, - -0.113236845, - 0.27550548, - -0.12776047, - 0.15039966, - 0.05276059, - -0.014072059, - 0.09496339, - 0.11836305, - -0.05721308, - 0.049146533, - 0.06110584, - 0.032844387, - -0.112255685, - 0.20781942, - -0.023602866, - 0.055527236, - -0.020050041, - 0.12244847, - -0.07111318, - -0.06455735, - 0.1092961, - 0.08855326, - 0.19076946, - -0.050684046, - -0.12904006, - 0.063671865, - 0.014307737, - -0.10946378, - -0.08112541, - 0.27691847, - 0.07607631, - 0.04656958, - -0.076385826, - 0.10623387, - 0.036387056 - ], - "neutral": [ - -1.1672001, - 1.8900856, - 0.20041882, - 1.5460702, - 1.3023158, - 1.0329928, - -0.15213178, - 0.58097273, - -0.589741, - 0.16671388, - 0.46182537, - -1.4738289, - -0.4177568, - 0.91492826, - 1.9613069, - -0.43115416, - 1.717124, - 1.0439879, - -0.120385386, - -0.54607165, - 0.6451573, - 0.9891572, - -1.5845255, - -0.6002111, - -0.82750815, - -1.0818735, - -0.37593234, - -0.33816585, - 0.51496965, - -0.54350144, - 0.8571257, - 1.3441583, - -0.43523058, - 1.1297387, - 1.0840259, - 0.8417222, - 1.0399876, - -0.41742793, - -1.0249571, - -0.03309195, - 0.52845955, - 0.04981665, - 3.084627, - -1.1295897, - 0.8584709, - -0.55979234, - -1.6378866, - -1.0323358, - 0.7547407, - -0.21722554, - -0.31369492, - -1.5665541, - -0.92273813, - 0.7176042, - 0.24865858, - 1.7140487, - -1.1191454, - -0.43076658, - -0.26902556, - -1.5103297, - -0.07304814, - -0.29888293, - -0.2825798, - 1.1756495 - ], - "target": 0.09523846, - "along": 10.274518, - "delta": [ - -0.09337959, - -0.13518529, - -0.07924813, - -0.16314259, - 0.11562042, - 0.025672924, - 0.22348577, - 0.16348423, - 0.088089675, - -0.021098133, - 0.22205378, - -0.018979061, - 0.3083015, - -0.16684744, - -0.006990858, - 0.16188331, - -0.04804113, - -0.013092865, - 0.07406262, - -0.1768946, - 0.19463748, - 0.0140854595, - -0.06589057, - -0.117274046, - 0.10063479, - 0.060578, - -0.21559462, - -0.015914574, - 0.11621739, - -0.11080557, - 0.2695902, - -0.12501736, - 0.14717047, - 0.05162778, - -0.013769922, - 0.09292445, - 0.11582172, - -0.055984676, - 0.048091322, - 0.059793852, - 0.032139193, - -0.109845474, - 0.2033574, - -0.023096096, - 0.054335028, - -0.019619552, - 0.11981941, - -0.06958633, - -0.06317125, - 0.10694943, - 0.08665196, - 0.18667352, - -0.04959582, - -0.12626947, - 0.062304787, - 0.014000541, - -0.10711352, - -0.07938359, - 0.27097285, - 0.0744429, - 0.0455697, - -0.074745774, - 0.10395295, - 0.0356058 - ] - } - ] - } - ] - }, - "gemma3": { - "cases": [ - { - "expression": "0.4 deceptive_fixture", - "canonical": "0.4 deceptive_fixture", - "coefficient": 0.4, - "trigger": { - "prompt": true, - "generated": true, - "thinking": true, - "response": true, - "first_n": null, - "after_n": null, - "gate": null - }, - "layers": [ - { - "layer": 0, - "basis": [ - -0.17514566, - -0.18307178, - -0.11144818, - -0.25933287, - -0.04074199, - 0.116129115, - -0.11981552, - 0.21491642, - 0.09977642, - -0.015300186, - -0.08912655, - 0.0059649437, - -0.061960727, - 0.09906269, - -0.17441855, - 0.052173562, - -0.13243636, - 0.15571228, - -0.11168122, - -0.16562071, - -0.013849348, - 0.08580962, - 0.05053979, - -0.14128439, - 0.056334477, - -0.05027451, - 0.16889724, - 0.023731597, - -0.15390925, - -0.08410047, - -0.05743335, - -0.12375604, - -0.00046795193, - 0.1405088, - 0.10768328, - -0.07149072, - -0.019210633, - 0.1554947, - 0.025636913, - -0.062738895, - -0.05887965, - -0.21302351, - 0.21253279, - 0.3583691, - 0.07820241, - 0.023272078, - 0.19586712, - 0.0048648156, - -0.063411795, - 0.21821949, - -0.032691017, - 0.020613268, - -0.06917805, - -0.03128615, - 0.015377442, - 0.028302182, - -0.041774206, - -0.01656112, - -0.042950787, - 0.002097161, - -0.21908037, - 0.15058614, - -0.13274677, - -0.18540505 - ], - "neutral": [ - 2.5011036, - -0.4328916, - -0.22815919, - 0.88161534, - -0.82922167, - 1.491485, - 1.9539326, - -3.9881096, - -1.4245024, - -2.1901445, - -0.16345637, - -2.71713, - -1.2177546, - -0.5948393, - 2.36368, - -1.9189181, - -2.602368, - -1.9446074, - 1.5463581, - 0.33549452, - 0.7032369, - -1.9593922, - -0.65063, - 1.5692993, - -1.5085074, - -1.6737885, - -2.807972, - 2.2502272, - 2.972189, - -0.03529877, - 0.1057314, - 3.2459009, - -3.411113, - 3.6565142, - -1.2219691, - 0.77729684, - -1.2308892, - -1.6396497, - -1.736317, - -1.9587177, - -1.2799597, - -3.049032, - 0.20408136, - -2.688755, - 1.1541778, - 0.7216564, - -1.4041886, - 2.2414868, - 1.2284724, - 0.47957373, - 1.6112742, - -0.015047793, - -0.97778773, - 0.08165591, - -0.91091067, - -3.4077399, - 3.8692083, - 0.13136284, - 0.2638365, - 2.9992876, - -3.6165664, - 2.2740467, - 3.6357148, - -1.6329161 - ], - "target": 0.3195708, - "along": 22.640675, - "delta": [ - -1.2672311, - -1.324579, - -0.8063609, - -1.8763508, - -0.29478046, - 0.84022886, - -0.8669011, - 1.5549846, - 0.7219122, - -0.11070142, - -0.6448572, - 0.043158147, - -0.44830438, - 0.7167481, - -1.2619704, - 0.37749133, - -0.95821667, - 1.1266248, - -0.808047, - -1.1983154, - -0.10020417, - 0.62085825, - 0.3656705, - -1.0222347, - 0.40759677, - -0.3637511, - 1.222022, - 0.17170519, - -1.1135794, - -0.608492, - -0.41554743, - -0.8954119, - -0.003385772, - 1.0166231, - 0.7791207, - -0.5172567, - -0.13899466, - 1.1250507, - 0.18549073, - -0.45393464, - -0.42601186, - -1.5412887, - 1.5377382, - 2.5929074, - 0.56581783, - 0.16838044, - 1.4171572, - 0.035198394, - -0.45880327, - 1.5788832, - -0.23652928, - 0.14914314, - -0.50052387, - -0.22636463, - 0.11126039, - 0.20477474, - -0.30224887, - -0.11982465, - -0.31076175, - 0.015173586, - -1.5851119, - 1.0895357, - -0.9604625, - -1.341461 - ] - }, - { - "layer": 1, - "basis": [ - 0.12802485, - -0.30080566, - -0.031642243, - -0.20326264, - 0.15958026, - -0.10817753, - 0.04889052, - -0.104113735, - -0.12643212, - 0.038898, - -0.15250558, - -0.078946, - 0.06334094, - -0.02963724, - -0.11546804, - -0.046584148, - -0.05966067, - -0.109168015, - 0.04844109, - 0.019603647, - 0.02420044, - 0.08219224, - 0.14603762, - 0.04916857, - 0.062194735, - -0.10011375, - 0.021254286, - 0.19077738, - -0.13675179, - 0.18375216, - -0.008679527, - 0.13963437, - -0.06231469, - 0.21634932, - 0.045094773, - -0.038764756, - 0.18080589, - 0.03987397, - 0.28482848, - -0.27354434, - 0.21405846, - 0.12297512, - -0.03866705, - 0.043954644, - 0.003269747, - 0.07348564, - 0.034954607, - 0.22175245, - -0.013022964, - 0.07504336, - 0.10964745, - -0.024328673, - -0.14068541, - -0.106761426, - -0.011847015, - -0.098838456, - 0.005225938, - -0.25786334, - 0.020093637, - -0.063316666, - -0.12081618, - 0.0040549645, - 0.19649477, - -0.11245577 - ], - "neutral": [ - 2.5403802, - -0.6107809, - 0.062300798, - 1.49499, - -0.64720786, - 2.2524116, - 2.5358746, - -5.168618, - -3.499977, - -1.0449457, - 0.15478604, - -2.34535, - -2.5848777, - -1.3628726, - 1.8815207, - -1.1110901, - -3.9774685, - -4.7597775, - -0.6708746, - 0.0017258171, - 2.0631378, - -3.0336688, - -0.6227669, - 2.474963, - -2.6115007, - 0.26991248, - -1.9374989, - 0.9526677, - 5.328921, - -2.6247644, - 0.044735555, - 2.2181914, - -4.052362, - 2.8750932, - 0.7703316, - -1.9708306, - -0.3956953, - -2.4062173, - -2.3324852, - -2.1703327, - 0.35780063, - -2.869667, - -0.15014786, - -1.6218642, - 0.33910915, - 0.54017884, - -2.4443815, - 2.6439462, - 2.1077006, - 2.679039, - 2.529034, - 0.14207181, - 0.46443367, - -0.9520941, - 1.1665174, - -1.7227926, - 3.6997166, - -0.25603804, - 0.32729462, - 3.2004669, - -1.4965214, - 1.621521, - 3.3546197, - -2.644725 - ], - "target": 0.40159905, - "along": 18.016226, - "delta": [ - 0.9262981, - -2.176419, - -0.22894108, - -1.4706659, - 1.1546109, - -0.7826968, - 0.35373753, - -0.753294, - -0.9147742, - 0.28143865, - -1.1034235, - -0.5711979, - 0.45829067, - -0.2144343, - -0.8354458, - -0.33705023, - -0.4316628, - -0.7898633, - 0.3504858, - 0.14183825, - 0.17509742, - 0.59468544, - 1.056626, - 0.35574934, - 0.4499975, - -0.72435296, - 0.15378112, - 1.3803314, - -0.98944, - 1.3295019, - -0.06279898, - 1.0102965, - -0.45086542, - 1.5653521, - 0.3262742, - -0.2804746, - 1.3081847, - 0.2885001, - 2.0608194, - -1.9791752, - 1.548777, - 0.8897618, - -0.2797677, - 0.318025, - 0.023657596, - 0.5316906, - 0.25290704, - 1.6044453, - -0.09422504, - 0.5429611, - 0.79333216, - -0.17602523, - -1.0179011, - -0.77245086, - -0.085716695, - -0.7151258, - 0.037811223, - -1.8657185, - 0.14538346, - -0.45811504, - -0.8741412, - 0.029338881, - 1.4216986, - -0.81365114 - ] - }, - { - "layer": 2, - "basis": [ - -0.0013273366, - -0.026159234, - 0.058747508, - -0.060686674, - -0.056419082, - -0.101471685, - -0.013408528, - 0.09652097, - 0.02388542, - -0.12338033, - -0.15079579, - -0.06470643, - -0.044205684, - 0.020028414, - 0.02729581, - 0.05321164, - -0.11256717, - -0.13212575, - -0.033447627, - 0.24678111, - -0.15017252, - 0.24557774, - 0.21449654, - 0.17390867, - -0.37098256, - -0.08778756, - -0.037413258, - -0.2320798, - 0.039156396, - -0.038149256, - -0.054693226, - -0.057865158, - -0.25312296, - -0.08468989, - 0.023207072, - -0.014365519, - 0.07787878, - 0.19128297, - 0.14986648, - 0.10067308, - -0.14003018, - 0.12228548, - 0.12091027, - -0.13852195, - -0.074175455, - -0.037910685, - 0.020011388, - 0.10167567, - -0.0884583, - -0.16636659, - -0.15804638, - 0.0022928787, - 0.045475665, - -0.044900242, - 0.06698659, - 0.07136512, - 0.021876741, - 0.17226069, - 0.012130007, - 0.11810755, - 0.1324676, - 0.11251672, - 0.25416997, - 0.11345745 - ], - "neutral": [ - 1.5604588, - -2.1175702, - 0.14606446, - 0.7385114, - 0.35017264, - 2.8522646, - 1.4717126, - -4.8974986, - -4.089805, - -0.76257277, - 1.5562946, - -2.5270953, - -2.3369787, - -0.34086064, - 0.43853664, - -1.8613778, - -4.776157, - -5.077354, - -1.767068, - -0.83124685, - 2.1675637, - -3.947026, - -1.7668724, - 3.9983017, - -1.1012617, - 0.30404115, - -2.3319027, - 1.8102349, - 5.8336906, - -3.1748953, - 0.41587326, - 1.4522133, - -4.975678, - 3.4511287, - 0.097035326, - -1.7819252, - 2.1127462, - -2.3910875, - -2.4991999, - -1.598096, - 0.84621066, - -2.497753, - -1.234034, - -2.0303576, - 1.1722668, - 0.0033107798, - -2.7347724, - 1.9015208, - -0.12735252, - 2.2576592, - 1.1667862, - -0.03853252, - -0.9637408, - 0.27681503, - 1.951656, - -3.7724102, - 4.5014596, - -0.75800496, - 0.4131548, - 3.9477253, - -1.5466305, - 1.8362722, - 2.8683174, - -2.190604 - ], - "target": 0.59318376, - "along": 12.1974, - "delta": [ - -0.009603678, - -0.1892699, - 0.42505583, - -0.43908626, - -0.40820897, - -0.73417807, - -0.09701472, - 0.6983581, - 0.17281817, - -0.8926937, - -1.0910528, - -0.4681704, - -0.31984136, - 0.14491157, - 0.19749336, - 0.38500217, - -0.81445724, - -0.9559694, - -0.2420036, - 1.7855353, - -1.0865431, - 1.7768285, - 1.5519466, - 1.2582812, - -2.68417, - -0.6351693, - -0.27069613, - -1.6791669, - 0.28330824, - -0.2760213, - -0.39572185, - -0.41867176, - -1.8314204, - -0.6127567, - 0.16791011, - -0.10393884, - 0.5634763, - 1.3839896, - 1.0843289, - 0.72839993, - -1.0131602, - 0.88477206, - 0.874822, - -1.0022478, - -0.53668165, - -0.27429515, - 0.14478838, - 0.7356539, - -0.6400223, - -1.2037121, - -1.1435128, - 0.016589664, - 0.32903007, - -0.3248667, - 0.48466808, - 0.516348, - 0.15828478, - 1.2463577, - 0.08776423, - 0.8545435, - 0.9584428, - 0.81409216, - 1.8389959, - 0.82089865 - ] - }, - { - "layer": 3, - "basis": [ - -0.095428504, - -0.1381515, - -0.08098698, - -0.16672224, - 0.11815734, - 0.026236232, - 0.22838944, - 0.16707137, - 0.09002253, - -0.021561064, - 0.22692604, - -0.019395495, - 0.3150662, - -0.17050837, - -0.0071442495, - 0.16543533, - -0.049095243, - -0.013380147, - 0.07568769, - -0.18077599, - 0.19890817, - 0.014394519, - -0.06733633, - -0.11984725, - 0.10284289, - 0.06190719, - -0.22032514, - -0.016263768, - 0.11876742, - -0.113236845, - 0.27550548, - -0.12776047, - 0.15039966, - 0.052760586, - -0.014072058, - 0.09496337, - 0.11836306, - -0.057213075, - 0.04914653, - 0.061105836, - 0.032844387, - -0.112255685, - 0.20781942, - -0.023602866, - 0.055527233, - -0.020050041, - 0.12244846, - -0.07111318, - -0.06455734, - 0.10929609, - 0.08855326, - 0.19076946, - -0.050684046, - -0.12904006, - 0.063671865, - 0.014307737, - -0.10946379, - -0.08112541, - 0.27691847, - 0.07607631, - 0.04656958, - -0.076385826, - 0.10623387, - 0.036387056 - ], - "neutral": [ - 0.13149427, - -3.4722078, - 1.4111372, - 0.18358235, - 2.2712533, - 1.5130157, - 2.0145404, - -5.1293473, - -3.847414, - -1.085956, - 0.99086577, - -1.6271235, - -1.9237572, - -1.227389, - -1.191196, - -2.326306, - -4.1070013, - -3.971018, - -2.7428799, - 1.111802, - 3.1695633, - -3.152848, - -2.9635317, - 4.9120526, - -2.3824666, - 2.3388357, - -2.658169, - 2.680893, - 4.0627213, - -4.5607266, - -1.7835108, - 1.7452952, - -4.3242016, - 5.0278153, - -1.0381066, - -2.4600103, - 4.924392, - -2.3264601, - -2.4950106, - -0.74662465, - 0.94854075, - -2.353967, - -1.0902015, - -2.8974578, - 2.4602382, - 0.30860463, - -2.1671002, - 1.0602406, - -3.4180899, - 3.855664, - 1.0488871, - -0.46984363, - -0.3480846, - -0.9215119, - 2.292254, - -2.9631767, - 6.5979238, - -1.2433661, - 0.14441511, - 3.9836752, - -3.2439158, - 4.51065, - 3.636658, - -3.0831158 - ], - "target": 0.64915603, - "along": 11.1457, - "delta": [ - -0.69045377, - -0.99956733, - -0.585965, - -1.2062851, - 0.85490364, - 0.18982698, - 1.6524658, - 1.2088113, - 0.6513399, - -0.15600073, - 1.6418777, - -0.1403322, - 2.279598, - -1.2336789, - -0.05169078, - 1.196974, - -0.35521874, - -0.09680936, - 0.54762304, - -1.3079683, - 1.43916, - 0.10414865, - -0.48719847, - -0.86713064, - 0.744099, - 0.447917, - -1.5941182, - -0.11767322, - 0.8593177, - -0.8193024, - 1.9933645, - -0.9243852, - 1.0881865, - 0.3817386, - -0.101815544, - 0.6870884, - 0.8563921, - -0.4139537, - 0.3555898, - 0.44211897, - 0.23763894, - -0.8122034, - 1.5036355, - -0.17077377, - 0.4017561, - -0.14506803, - 0.8859512, - -0.51452506, - -0.46709168, - 0.79078984, - 0.6407093, - 1.380274, - -0.3667142, - -0.93364346, - 0.46068496, - 0.10352076, - -0.7920032, - -0.5869666, - 2.003588, - 0.5504348, - 0.33694482, - -0.55267423, - 0.7686338, - 0.2632712 - ] - } - ] - } - ] - } - } -} diff --git a/browser-runtime/fixtures/units-tiny-whitener-v1.json b/browser-runtime/fixtures/units-tiny-whitener-v1.json deleted file mode 100644 index a023ee4..0000000 --- a/browser-runtime/fixtures/units-tiny-whitener-v1.json +++ /dev/null @@ -1,12540 +0,0 @@ -{ - "schemaVersion": 1, - "about": "The units-tiny fixture session's neutral whitener per layer in eigen form (ridge \u03bb, basis rows V, eigenvalues s\u00b2/N); generated by browser-runtime/export-units-tiny-whitener.py from drowse's fixture.", - "fixtureModels": { - "name": "units-tiny-models-v1", - "sha256": "2140e50d3430d336deda0aee630c52e40e8134aec55d2b58c8dc4ef7c15f1006" - }, - "arches": { - "gemma3": [ - { - "layer": 0, - "rows": 24, - "ridge": 0.5883395274480184, - "mean": [ - 2.501103639602661, - -0.4328916072845459, - -0.22815918922424316, - 0.8816153407096863, - -0.8292216658592224, - 1.4914849996566772, - 1.9539326429367065, - -3.988109588623047, - -1.4245023727416992, - -2.1901445388793945, - -0.16345636546611786, - -2.717129945755005, - -1.217754602432251, - -0.5948392748832703, - 2.363679885864258, - -1.9189181327819824, - -2.602368116378784, - -1.9446073770523071, - 1.5463581085205078, - 0.3354945182800293, - 0.7032368779182434, - -1.9593921899795532, - -0.650629997253418, - 1.569299340248108, - -1.5085073709487915, - -1.6737885475158691, - -2.807971954345703, - 2.250227212905884, - 2.972188949584961, - -0.03529876843094826, - 0.10573139786720276, - 3.245900869369507, - -3.4111130237579346, - 3.6565141677856445, - -1.2219691276550293, - 0.7772968411445618, - -1.2308892011642456, - -1.639649748802185, - -1.7363170385360718, - -1.958717703819275, - -1.2799596786499023, - -3.049031972885132, - 0.20408135652542114, - -2.6887550354003906, - 1.1541777849197388, - 0.7216563820838928, - -1.404188632965088, - 2.2414867877960205, - 1.228472352027893, - 0.47957372665405273, - 1.611274242401123, - -0.01504779327660799, - -0.9777877330780029, - 0.08165591210126877, - -0.9109106659889221, - -3.4077398777008057, - 3.869208335876465, - 0.13136284053325653, - 0.26383650302886963, - 2.9992876052856445, - -3.6165664196014404, - 2.2740466594696045, - 3.6357147693634033, - -1.6329160928726196 - ], - "eigenvalues": [ - 17.032732324919287, - 7.207501300017909, - 3.79166572904782, - 2.9775859466711867, - 2.0675115013384193, - 1.6733126941390422, - 1.2500933539169374, - 0.5346328037642282, - 0.31760357904618985, - 0.2861136317581427, - 0.19748371670095433, - 0.1200075678890339, - 0.07624125078024328, - 0.05880796628511017, - 0.03199960670303464, - 0.019401140734197284, - 0.011036885836018216 - ], - "basis": [ - [ - 0.06740491181349909, - 0.12234757892142399, - 0.1662230793705108, - 0.11259123682434825, - 0.05504979431527721, - 0.06788740554458231, - -0.11778484937100307, - 0.1332230317576604, - 0.004303079304593546, - 0.014709732259123101, - -0.18790270563657863, - 0.008481559001300744, - 0.10903438202357425, - -0.0758544246290075, - -0.21401742157866513, - 0.19046700251861276, - 0.11039301270976451, - 0.021861507671656757, - 0.09222904561994162, - 0.08751910510787295, - 0.16771924110573552, - 0.0034568208304746207, - 0.10596575847359689, - 0.004393513591935844, - 0.05518512030095063, - -0.041389475916175714, - 0.1000504217549298, - 0.12334360458156542, - -0.10435155096185905, - -0.035178880657568565, - -0.1285218878256426, - -0.1994800256163503, - 0.3124326701911166, - 0.13264654269939102, - 0.017025336208367298, - 0.0141420012449611, - 0.17250539770497844, - 0.018485225490629115, - 0.14491997462416212, - -0.10802532733884568, - -0.18769845257321652, - -0.03480979508492039, - 0.15340356182672765, - 0.08294558963860509, - 0.04528052446369242, - 0.1164249022784363, - 0.1310537492881854, - -0.07676617412699878, - -0.07227164104595053, - -0.0810260529650449, - 0.04835236052465842, - -0.340722533385116, - 0.10026711058143027, - -0.13221739050732575, - -0.12248502276231645, - -0.07595531552339793, - -0.18687742525002177, - -0.004327621605328473, - 0.0494225818562168, - 0.012576768611066842, - -0.0045637650540645, - -0.12757193470980177, - -0.27912876435193346, - 0.06832651078732942 - ], - [ - 0.11656569208432364, - -0.08922945895691185, - -0.25063413384553335, - 0.06282011848049189, - 0.12902122176660433, - -0.04822842103781741, - -0.018872622603911548, - -0.10419087403375375, - 0.005674369456128728, - 0.04149997546407655, - 0.16753532493314954, - -0.07106477844813917, - 0.1120189098039515, - 0.03405454489909327, - -0.20412232992741228, - 0.04079275730242874, - -0.2003949936534793, - 0.03444478467298238, - 0.12706314286497636, - 0.022600990461905952, - -0.26704296116378934, - 0.015396562847847161, - -0.05303354628055369, - -0.0979986531906237, - 0.03419076917774313, - 0.05072830703342916, - 0.1528396426253026, - -0.07471675025956646, - -0.03856792638139723, - 0.02289593318282735, - -0.07313372023578171, - -0.2825458363201117, - -0.042955239751384384, - -0.19172388558380415, - -0.1466933344538925, - -0.20226108392657402, - 0.16556485263011222, - -0.2429658730786175, - -0.05998993792887632, - 0.010398982119176007, - 0.0758763145270503, - 0.07361313826105156, - 0.025851960495890423, - -0.03140038546290938, - 0.08900606142388753, - -0.12190892576866234, - -0.13749612887920082, - -0.0536473329350516, - -0.11991548047468871, - 0.02743041339075364, - -0.085029196985977, - 0.13956929023231032, - -0.00044557003169702907, - 0.010536946453374321, - -0.051638383256656255, - -0.09033054294514568, - -0.03179874770527697, - -0.0716754724261428, - -0.24906605107976812, - -0.1144013383335404, - -0.08812573542300103, - -0.20988491963907083, - -0.2552411781003663, - 0.16778955855857997 - ], - [ - -0.013782548042576665, - -0.16188412568091645, - 0.21808299101766665, - 0.21951560165784056, - 0.018730647403005184, - -0.10757451945057174, - -0.014312799663759217, - 0.0460512571408023, - 0.01499281634185483, - 0.06655842878577271, - 0.19816397815664702, - -0.15171746856348386, - -0.013348438411585629, - -0.015212150388258995, - 0.175896055095963, - 0.06034031779725928, - -0.06166632815378592, - -0.13428465174582438, - 0.08845350841726718, - -0.06923039304671823, - -0.016567039030144944, - -0.04273476866793649, - 0.1779317612121686, - -0.1322280243142971, - 0.06407211097958967, - -0.053645565498964994, - -0.23313217383541385, - -0.17898024048533975, - 0.21632233828546568, - -0.05196877986167789, - -0.02421684462299094, - -0.09085549769640763, - 0.10224189093331228, - 0.06022412362903987, - 0.09672518129536024, - 0.10655363661253645, - 0.13739567068390493, - 0.017607617433260343, - -0.052530975368586315, - -0.19555675202474923, - -0.3246062419677662, - 0.1481514487840663, - 0.18777030584729457, - -0.14508212881910335, - 0.24641622305886712, - 0.027254041008569454, - -0.14704526622257763, - -0.017621431329517045, - 0.10888380034096944, - 0.1409543457480368, - -0.1877888408845612, - 0.05099180402722509, - -0.08395258539890822, - 0.06568095944852907, - -0.12597998825873183, - 0.05129603637905616, - 0.02515323522247636, - -0.09677153995252512, - -0.07938109481704438, - -0.039177717102877124, - 0.11657755793010215, - 0.16769255348347312, - 0.05454928617046754, - 0.017329873747620995 - ], - [ - 0.0025476343186241193, - -0.12137276990782417, - -0.058972610150991124, - -0.016985137390717914, - -0.10204662833804769, - -0.027004994171400558, - -0.26229411867729036, - 0.09765138614499383, - -0.08993899094665059, - 0.2555852943046208, - 0.11407333801646152, - 0.08916379710524738, - -0.06492255393105999, - -0.12136135903293098, - -0.010334698239666514, - -0.1646751051655923, - 0.3158656323111996, - -0.14944736802645947, - -0.022229798832458635, - -0.016065249741848038, - 0.0188605768990973, - 0.10150932921551468, - -0.10256097930971021, - 0.03183122335833981, - 0.0704527426229533, - 0.023910220461076142, - -0.10180861943437566, - 0.018247693021854108, - 0.14182034533731, - 0.020067264517549397, - -0.020553015835648367, - -0.002502934388935461, - 0.20400818567319903, - 0.023761855409762684, - 0.09295155353998098, - -0.00015718721431796768, - -0.12143971075927494, - -0.03996079507148621, - 0.025789412392321, - 0.12190475307614157, - 0.12276900924905634, - -0.029091445035272025, - 0.19623996289571277, - 0.06585058888980919, - -0.03097069522306844, - 0.06574823832968028, - -0.061808907430204875, - 0.14476010890245555, - 0.3038438847876094, - -0.03713164249543962, - -0.005538074269498844, - 0.18429718600186223, - 0.30418203392710175, - -0.05500150794476988, - -0.022595176190774016, - -0.18907641054341662, - 0.06266013859748101, - 0.0727068363883641, - -0.22135183415292844, - -0.019214933718331377, - -0.22746905657741898, - -0.03908799321027227, - -0.14884434714087888, - -0.06495558543272247 - ], - [ - 0.03673986742528313, - 0.06163057913624179, - 0.021436126894784815, - -0.2501814390536303, - -0.11763028007093744, - -0.03922923173604462, - -0.18607389125706328, - 0.09673439545257484, - 0.10655338710986574, - 0.12059153230465647, - -0.04272992088849007, - -0.027653067233145475, - -0.06515350113027168, - 0.028563784525595326, - -0.1864909977249077, - 0.15338103037015077, - -0.05657997073974413, - -0.030864411019229425, - 0.19384355540203974, - -0.007206929199001927, - -0.02589076059376429, - -0.1864771951338031, - 0.17726241850329869, - 0.2069362701956906, - -0.2855793839958049, - 0.1120324113972729, - 0.09876746402959338, - 0.03145284013305045, - 0.13945490598408444, - -0.16320779848912043, - 0.07638392081200321, - -0.080893063691773, - -0.13446925149620154, - -0.1837327812481974, - 0.1629290151761032, - -0.012935529375451118, - 0.14428234829957495, - 0.07784514332316775, - 0.0617193405163352, - 0.04130360175508577, - -0.023019966315271232, - -0.09520740705763103, - 0.15081334353021755, - -0.10795222337030154, - 0.057576606342245644, - -3.025867336257066e-05, - -0.11898318139119593, - -0.08619720979683741, - 0.04006824862640692, - -0.1200733949732391, - -0.03846539277667033, - -0.019731482732215366, - 0.012369164603468354, - -0.21199888122882057, - 0.20715687219282572, - -0.0869684764224079, - 0.08892892148926443, - 0.09356028258169605, - -0.11307829634904483, - -0.12620756370655212, - 0.1457314400300276, - -0.08958900480614489, - 0.28290383595267166, - -0.13352007266102553 - ], - [ - 0.057254576841030906, - 0.19087056306051503, - -0.08827463730875415, - -0.03559439212959273, - 0.0691069831564009, - -0.09130584110027289, - -0.14103479553623677, - -0.048705436483406306, - 0.06318589985612824, - -0.10758202410253305, - 0.014857257894804242, - 0.03298941222524584, - -0.11943085254743684, - 0.1441861380479468, - 0.2880588059567189, - 0.11722751670798262, - -0.06652914745135187, - -0.23956512728706364, - 0.11644789950279669, - 0.013895544925292018, - 0.27963584704837263, - -0.09613527305075614, - 0.13642665060978082, - 0.11501662714575998, - 0.059214076266189686, - 0.029416030205494877, - 0.18244036398605312, - -0.07351485210756807, - 0.16354945220122427, - -0.04261209742538108, - -0.06716704300394996, - -0.05508272914900541, - 0.011508496321900555, - -0.11208996225872932, - 0.09165094735727443, - -0.006476857674297043, - -0.036451087947414286, - 0.029937976476999223, - -0.1400450631345106, - 0.16751864853558476, - 0.163246078692242, - 0.11713509216473236, - 0.056637691122110485, - 0.15540943346497046, - -0.01572866069694986, - -0.07377965399791064, - 0.008395614976722617, - 0.041033440730794166, - 0.019390795445971765, - 0.07191156818850744, - -0.03940461949787632, - 0.04108270684492478, - 0.06204582860216178, - 0.1786243637662617, - 0.051426928437030485, - -0.2763103279060057, - -0.22213344159416046, - -0.13613749961913396, - 0.2489710695851655, - 0.007049253317007017, - 0.003446974125825404, - 0.07493052625179705, - -0.050255257404562145, - 0.2921839701324942 - ], - [ - -0.06357712887222308, - -0.08278457432232414, - -0.1593261335390848, - -0.04022758083505964, - -0.10743672147440894, - 0.07202116547571372, - 0.09966505084340126, - -0.07458096176383498, - 0.03201321506372459, - -0.14714566957269032, - 0.02132961286454147, - 0.13463088523515146, - -0.03600035319786868, - 0.12125122770063826, - -0.17181411270191604, - -0.039448355971494965, - 0.0969949546733339, - -0.06696749572216396, - -0.056625813347351554, - 0.03543943318458339, - -0.01804723195448495, - 0.10988840983018382, - 0.14798069317216672, - 0.13256892620608376, - 0.051927155285339574, - 0.03265928314579483, - -0.18159796886503457, - -0.02169452400583221, - -0.12528501724291227, - -0.09383309034185655, - 0.004948588465616441, - 0.19577240444740288, - 0.1732068325307939, - 0.041794096707263494, - 0.1651788104988311, - -0.1365047338935632, - 0.15202356473340634, - -0.17446394121359862, - -0.22616965959371127, - 0.16334060330411707, - -0.1996697595183529, - -0.10152845092815797, - 0.0007710858272433862, - -0.025613773679185672, - 0.13490209749014792, - -0.1101466106577831, - -0.09710087868430402, - -0.017577833724709523, - -0.18027147937194998, - -0.23748057340448178, - -0.24726084131188217, - -0.122382531161256, - 0.15863898246126368, - 0.3049527971721827, - -0.006622709863002317, - -0.09905424048604228, - 0.08494345362663783, - 0.20117811659926002, - 0.029315206606842684, - 0.14141534047029644, - 0.0757526742597067, - 0.011857657066598392, - 0.03356351173948262, - 0.05220017954120849 - ], - [ - 0.009652763713820295, - 0.02842963213899071, - -0.2180393473496241, - -0.10002236026395221, - 0.009114990893853701, - -0.015264927648318924, - -0.1345889992408001, - -0.16230012038976332, - -0.046024831557142494, - 0.05409711867301162, - -0.17644575828081674, - 0.0332605971131575, - -0.14332469889878233, - 0.08102219521045248, - -0.022028878581510335, - -0.3696057898509694, - -0.08782452403016656, - 0.008775644365659493, - 0.1447187539851584, - 0.05579341710513195, - -0.06694106962885267, - 0.04814781826476372, - 0.0348484526658485, - 0.06309499455870862, - -0.29020252438433347, - 0.10748562525933837, - -0.164203954023537, - 0.030861037070395732, - 0.21439293167729703, - 0.05784392130221069, - -0.10309201006611711, - 0.20878151305584086, - -0.055592088182484865, - 0.018966500118450188, - 0.08473888905343249, - 0.1163838024819454, - 0.14681555262539395, - 0.02603889166715315, - -0.08712781128308084, - -0.17194964161554085, - -0.21651705468555105, - 0.10474447152142899, - 0.10518992857261518, - 0.02055004674457464, - -0.2652174822001238, - -0.0001069119038728933, - -0.02037067205736048, - -0.06323500657058946, - -0.09520601578765323, - 0.15183152736480085, - 0.0026445868707476103, - -0.11654927423008332, - 0.000669493854599209, - -0.02227219340599033, - -0.0388148974938671, - 0.15377827692645574, - -0.07831664287560872, - -0.17050515972274327, - 0.06919862970258096, - 0.01735152832991131, - -0.16101745646092358, - -0.08114617243710544, - -0.22752382132604856, - -0.025506311564392994 - ], - [ - 0.00866756651437791, - -0.11259316303567962, - 0.09205291000333359, - 0.1969707173443922, - -0.007359854458806993, - 0.030768898127934142, - 0.1114102270447386, - 0.19107272526751093, - 0.025140891113953293, - 0.020932936712883175, - 0.213188377369508, - 0.048656623752583276, - 0.06555241638894913, - -0.08406418089747564, - 0.12058123637157504, - 0.06473582234187328, - 0.1484364366496616, - 0.3460348208536422, - 0.05188519437745816, - 0.07648113286406306, - -0.17692398528256834, - -0.07342317015749837, - -0.13418712153859486, - 0.17923121458787017, - -0.0763968592720448, - -0.06818224846253337, - -0.0018633535838205961, - 0.13742400907922564, - 0.26874124663480137, - 0.04475978731421716, - -0.030963389495884407, - 0.0014978848035937758, - -0.22572973557049192, - -0.05761121488345984, - -0.030051325273319756, - 0.052392392508119286, - -0.0061622509505722, - 0.14845391932426505, - -0.03907767652392037, - 0.07646514798446168, - -0.15224834008131932, - -0.004957572089606578, - 0.04897501752077483, - 0.039834627551670075, - -0.14755964658412304, - -0.0449023006913089, - -0.022102955863467073, - 0.16255748646951693, - -0.34164316219192314, - -0.10993764690004997, - -0.09801510087700617, - 0.008027263904728481, - 0.1050669803146454, - -0.12562628489628572, - -0.012782097384854635, - -0.27809748656597455, - -0.014835257416117914, - -0.027630025033018216, - 0.07082785803930271, - 0.1793698024903462, - 0.0007894696809460677, - 0.08806274430842172, - -0.05893131504619383, - 0.10912183373920528 - ], - [ - -0.23785146006038488, - -0.1150427432631926, - 0.04996180090962785, - 0.12403266309018504, - 0.08416095658862022, - -0.2850863748616721, - 0.029473644562204686, - -0.03842093974801821, - 0.004129899601259281, - -0.06202083232456211, - -0.07158702127355081, - 0.035118132545158554, - -0.22285385958393591, - 0.14545385725172277, - -0.16621641190874203, - 0.18066462331156258, - 0.10993096379923883, - 0.04873309220468234, - 0.1517472487580057, - 0.10840902319981859, - 0.03420149734354984, - 0.15095053489818472, - 0.06371788094878554, - -0.08046422043869823, - 0.002930169005373674, - -0.18639510394146155, - 0.04503994141519748, - -0.0030930880860147027, - -0.2571340694286343, - 0.12536938097633654, - -0.11634332099168948, - 0.1790305032176368, - -0.037689817252077026, - -0.2548306610952179, - 0.008231769853548893, - 0.07015085539393075, - -0.16926279472632977, - -0.01067688077296351, - 0.055759286645910476, - -0.005060335246023907, - -0.06207372633835319, - -0.10914466573950063, - 0.20892811748140167, - 0.04275935540914104, - -0.008639325005820726, - -0.043014604491567035, - 0.13344271602741162, - 0.14156515373844358, - 0.05688617286419545, - 0.07682120704248406, - -0.22499523753226822, - 0.036228249735322564, - -0.06606363173900986, - -0.0558315108373414, - 0.17474397055571192, - -0.04050805498066177, - 0.15091342840887775, - -0.290096384295095, - 0.011800333271005652, - 0.001124599342208189, - -0.03671267432437184, - -0.12774956976261523, - 0.006939799768937705, - -0.05073952494431448 - ], - [ - 0.1366700994021707, - 0.09762051664441342, - 0.22838419835033827, - -0.0700502020741989, - -0.01715673590756229, - 0.293635872916688, - -0.2857255206949668, - 0.019877547448283163, - -0.003650061787508791, - -0.03255120619894465, - 0.19686232113414823, - -0.191658839450152, - -0.14672258101051847, - 0.17747572997215202, - -0.11637050004931611, - 0.025762486932509567, - -0.051082585502707195, - -0.13298261916125884, - -0.05476756515560601, - 0.16900972713119522, - -0.15558156815889704, - -0.29481391799263557, - 0.05169616522520017, - -0.14243541740614923, - -0.1138449003115003, - -0.2676691715644204, - 0.133996546923849, - 0.10613771221675207, - -0.11304915257545785, - 0.05764839315630676, - 0.08524119002092126, - 0.1383210709086768, - 0.11838946649461797, - 0.11948152302191359, - -0.1251258846244368, - 0.13069776423879342, - -0.12483133337882209, - 0.04837389437190408, - -0.08285539113570575, - 0.14465031635526235, - -0.07076415377036561, - 0.10360042518835746, - -0.16016023965957824, - -0.05371893839487372, - -0.03134942675903967, - -0.06787678053492402, - -0.10711127418883067, - -0.042801233972117936, - -0.04870364932156184, - -0.014354920200562624, - -0.12544227919070722, - 0.040745853488342226, - 0.07056197146466991, - 0.044935878629557786, - 0.020503400244224507, - 0.020674102492096735, - 0.0754333271584393, - -0.10611993894199392, - -0.015400046545841067, - 0.0920109340070721, - -0.1641890368221678, - -0.010235982663093949, - -0.07143746360037152, - -0.06751776917734169 - ], - [ - -0.10394764373948757, - -0.048838917987753604, - 0.11684659133328724, - -0.023871388943056945, - -0.11574818184333269, - 0.27528409368538803, - 0.08319614080859199, - -0.061444627146890404, - 0.022744874830839732, - 0.1110158897338973, - -0.01925155320546269, - 0.006763151298049662, - -0.15995038132037054, - -0.16231132448434551, - -0.07297606124982835, - 0.022699552145419685, - -0.18669508085484207, - 0.10272868193535296, - 0.05371875269917964, - 0.011171038252538219, - 0.039164146964056526, - 0.1495089227300802, - 0.0149872983228191, - -0.14137813860884954, - -0.12192030469169314, - -0.002109179821444368, - 0.04081914289436971, - -0.16529949319599865, - 0.2965162203596899, - -0.0517670515416578, - -0.09559973137374507, - 0.06508579385306157, - 0.060952310751006204, - -0.0368066109777805, - 0.08039798281795915, - -0.021996609065881755, - 0.0028055311266678463, - -0.19817734586312005, - 0.12382505002330475, - 0.15096685371651544, - 0.05358288311419922, - -0.08191374887653315, - -0.30740949380174293, - 0.016851246261615806, - 0.018128920850951285, - 0.06066901002930403, - 0.21366685199432514, - -0.049373157028035214, - 0.14130940838466816, - 0.13904326287781685, - -0.035615729138257675, - -0.2539362986679925, - -0.05122043608595913, - 0.007161839191953628, - 0.06320652900916084, - -0.20073119450229832, - 0.13095743152238476, - -0.14820980159928687, - -0.217611049164174, - 0.17072956645022483, - 0.036796292374969876, - 0.06711291299791432, - -0.0031761683161911944, - 0.2047806650229635 - ], - [ - 0.21323000560003644, - 0.11390042869981346, - -0.06851530902027647, - -0.17186467437565045, - -0.008039154800905592, - -0.10692994494481459, - -0.09820267548921449, - -0.10324860779802349, - 0.1108884254469867, - 0.10486206246094987, - 0.1531836100777586, - 0.07421502498807622, - -0.14128411309282463, - -0.004563203367891404, - 0.015373607119654072, - -0.037634526247936936, - 0.052582109161082205, - -0.1472841562671394, - 0.2891496239567553, - -0.05324907313017287, - -0.07512529995204434, - 0.08523369111680199, - -0.10903219013306813, - -0.13469016650041457, - 0.229165493728549, - -0.1509809149163614, - -0.1042580150882924, - -0.06581931521213284, - -0.0991790747169965, - 0.1699765778904317, - -0.007579040368961753, - 0.17118813062167332, - -0.04777521413872502, - 0.0473445425032251, - -0.08702433220260168, - 0.013446535006544682, - 0.05881809296696228, - 0.13125789492742676, - 0.05220397740151381, - -0.050921841431249136, - 0.10090261117306507, - -0.09955072619355014, - -0.0163031606670534, - 0.047226611634493314, - -0.09211754720821207, - 0.04275527512579858, - -0.110856938864658, - 0.040790114275085915, - -0.012917267493608244, - -0.14956197674032246, - -0.09450567594939104, - -0.16058735617799477, - -0.13346421847662632, - -0.26332084143691115, - -0.11013855742120872, - 0.05104228576978976, - -0.11941007505396126, - 0.11959457019840161, - -0.13168889836379255, - 0.22124286592422143, - 0.306629317677125, - 0.053423192976929545, - 0.043273058797892575, - 0.226495782680602 - ], - [ - -0.025891417095063863, - 0.21734112798071106, - -0.0034336762048447177, - -0.14016688121438514, - 0.12955602722277598, - 0.11362411156485452, - 0.09283199222520656, - -0.16492014889684492, - 0.072357043597319, - -0.041579076665532386, - -0.026793183635377582, - -0.020966473414491486, - 0.15282835733386085, - -0.1189343710656302, - -0.18523709665553653, - 0.003786949390243728, - 0.10742920415376203, - 0.007969923126522819, - -0.03354663672307963, - 0.08937998595419949, - -0.13691617476132453, - -0.12243339503191053, - 0.012549282007061825, - -0.06350722212339159, - 0.3109420418294853, - 0.010807288468440677, - -0.06824865627862663, - 0.012994845694151724, - 0.24620481907031916, - 0.033244162831517134, - -0.04781158393146191, - 0.028809074265751407, - 0.04962333107242058, - -0.1393131486566546, - 0.07455064524476845, - 0.024910369069250017, - -0.11684513907124933, - 0.09252308405468866, - 0.13467235564369834, - 0.12562421582228364, - -0.015075093953555822, - 0.18550113573844473, - 0.2590494233989119, - -0.04279498851109396, - -0.18202370823524291, - 0.15998509454401466, - 0.0487478339342219, - -0.11502663835108773, - -0.0046412190920646045, - -0.023146079604898076, - -0.06087588992037427, - 0.059975093988158326, - -0.3346071658665499, - 0.2773729435325905, - 0.10542789928939211, - -0.1313977051292837, - 0.04098742843292824, - 0.06260628225040218, - -0.03682254655000755, - 0.036794491571295426, - 0.10778304931607981, - -0.006453229423485958, - -0.11590623773565847, - -0.20304548717385598 - ], - [ - -0.16863344038882408, - -0.07555519999882712, - -0.14791960128596998, - 0.0381183959392419, - 0.014204417992609457, - 0.1104488102576296, - -0.09171979105580706, - 0.03858891586684229, - -0.15350057549045332, - 0.1839101949125596, - -0.05787178589432592, - -0.05864343033312001, - 0.2116263575005993, - 0.08427084019527277, - -0.20127904239571992, - -0.19154309984440052, - -0.11160007130896117, - 0.15012323389872276, - 0.11920158039266451, - 0.044833923498018034, - 0.13466748414807425, - -0.19319804549853065, - 0.18130418149808017, - 0.12255986648404776, - -0.007427766000790886, - -0.2174427828167991, - 0.016221802516408666, - -0.05469867264582023, - 0.032925864882046976, - 0.1733745108678385, - -0.09216852998532638, - 0.029196815196074095, - -0.006828990943759397, - 0.18671171869769393, - -0.0034052406024401645, - -0.20200195330963217, - -0.31881764060380136, - -0.048442423355385136, - -0.013821311888554752, - -0.01619671948449174, - 0.039874896151782545, - -0.017019950865323086, - 0.11614446525118019, - 0.2147773727250409, - 0.15191011158071233, - 0.22072057041745952, - -0.08093401403357557, - 0.0260139759919692, - -0.12969009164642006, - 0.17844940025149802, - -0.05023383486327904, - 0.0726080400504036, - -0.024427580035120685, - -0.03302666598459118, - 0.03238488768753449, - 0.07103087651408037, - -0.021062702849713545, - 0.12392871288234146, - 0.014440115193820215, - -0.021094006135200304, - 0.10466194707056965, - 0.10786326540311293, - 0.14879045271768612, - 0.18761128411988448 - ], - [ - 0.10742316743397143, - 0.03135368290423595, - -0.029119136448701243, - 0.015907323065136543, - 0.2594255109514575, - 0.01852486923077956, - 0.04649729314434456, - 0.18844459453576703, - -0.00304613713596634, - -0.0919704746454111, - 0.19063019153193822, - 0.003972037849342361, - -0.07869062114373247, - 0.05314844156999172, - -0.2906998375963463, - 0.18195032724517166, - -0.04193182184273195, - 0.04964073680750434, - -0.27635098060335095, - -0.11994365909263555, - 0.03421230625023724, - 0.13984182205957552, - -0.20476167576914608, - 0.04227602398126804, - -0.1867734410617434, - -0.15526874979512661, - -0.0683118177403978, - 0.022307411944547453, - 0.1579586274938871, - 0.17381742604265835, - 0.06918828007805918, - 0.061281683638783196, - 0.01582278516004356, - 0.1236671051148022, - 0.09252077033763398, - 0.10354265256803556, - 0.0866766398915448, - -0.23757727191985215, - -0.07944923905449394, - 0.011514038569524224, - 0.07254655575023147, - -0.027994190896730498, - 0.2041371579907563, - -0.02311533735257633, - -0.15628021517726504, - 0.07659487820449633, - -0.07649519207488803, - -0.038183645496784116, - 0.1552895567645576, - 0.024674681966283075, - 0.10765553479607175, - 0.006107164811095934, - 0.08506504030420113, - 0.11163768176221228, - 0.10797085199791186, - 0.10626866751718111, - -0.2524779076556487, - -0.11509720444657928, - 0.02482856335728229, - -0.024446864148767365, - 0.20287041162801603, - -0.04582098786421481, - 0.14411924613116636, - 0.10005600585645955 - ], - [ - 0.014840723548955128, - 0.10065988007333389, - 0.09428319845203019, - 0.023829654056403648, - -0.09865931531416526, - 0.008900629858069931, - 0.10252014737406476, - -0.15207151599318594, - 9.68790393070202e-05, - -0.045701591134964345, - 0.11217571844579349, - 0.14638300699140747, - 0.20923952958885453, - -0.043447972345272985, - -0.01830137182689965, - 0.06665826852404527, - -0.1824272252597725, - -0.04955447211817513, - -0.15038412776645727, - -0.05038562794476518, - -0.07515121430946195, - -0.26054014218697813, - 0.000870956646515793, - 0.06053955250034094, - -0.10304117213046919, - -0.007545913033527216, - -0.19342816472854815, - -0.10758155633779487, - -0.21540388542969627, - 0.08027474002802976, - 0.18005291644174934, - 0.28408371681409944, - -0.17646268228943754, - -0.001805928117745365, - 0.18792994781328717, - -0.1748008420338633, - 0.03457918990323744, - 0.04932296468392132, - 0.059316812195887275, - -0.1297363976840854, - -0.002553995241652336, - -0.002051884229621055, - 0.1509997292700194, - 0.0328343386362084, - 0.1450167992539795, - 0.03724055646916415, - 0.1231378284325169, - 0.016612267012532014, - 0.18829772799698438, - -0.03056854827979349, - 0.0037984638803799263, - -0.05408789608150875, - -0.04783418578099695, - -0.12220171148986213, - -0.010998839178730112, - -0.25254559345090694, - -0.24487271667725266, - -0.0702115527673535, - -0.09535266005420355, - 0.042057124662804625, - -0.3120136346020943, - -0.0004588956719570715, - -0.06901697171845636, - 0.07362876050064215 - ] - ] - }, - { - "layer": 1, - "rows": 24, - "ridge": 0.8583453496297201, - "mean": [ - 2.5403802394866943, - -0.6107808947563171, - 0.062300797551870346, - 1.4949899911880493, - -0.6472078561782837, - 2.2524116039276123, - 2.535874605178833, - -5.168618202209473, - -3.4999771118164062, - -1.0449457168579102, - 0.15478603541851044, - -2.3453500270843506, - -2.5848777294158936, - -1.36287260055542, - 1.8815207481384277, - -1.111090064048767, - -3.977468490600586, - -4.759777545928955, - -0.6708745956420898, - 0.0017258170992136002, - 2.0631377696990967, - -3.0336687564849854, - -0.62276691198349, - 2.4749629497528076, - -2.6115007400512695, - 0.2699124813079834, - -1.937498927116394, - 0.9526677131652832, - 5.328920841217041, - -2.6247644424438477, - 0.04473555460572243, - 2.218191385269165, - -4.052361965179443, - 2.8750932216644287, - 0.770331621170044, - -1.9708305597305298, - -0.395695298910141, - -2.406217336654663, - -2.3324851989746094, - -2.170332670211792, - 0.3578006327152252, - -2.8696670532226562, - -0.15014785528182983, - -1.6218641996383667, - 0.3391091525554657, - 0.5401788353919983, - -2.4443814754486084, - 2.6439461708068848, - 2.1077005863189697, - 2.6790390014648438, - 2.529033899307251, - 0.14207181334495544, - 0.4644336700439453, - -0.9520940780639648, - 1.1665173768997192, - -1.722792625427246, - 3.699716567993164, - -0.25603803992271423, - 0.32729461789131165, - 3.2004668712615967, - -1.4965213537216187, - 1.62152099609375, - 3.3546197414398193, - -2.6447250843048096 - ], - "eigenvalues": [ - 23.52728764227173, - 11.590829246509173, - 5.7105011978170035, - 4.585560377970283, - 3.147469832466762, - 1.8450980463386266, - 1.3850826832955425, - 0.8400166458168634, - 0.6306170319624335, - 0.3944869204906984, - 0.3067498115671552, - 0.248848164493791, - 0.18365353906937576, - 0.15212770694363187, - 0.1168354859520584, - 0.06367726630649832, - 0.054802695019721605, - 0.043968657265281846, - 0.03572944516600531, - 0.025458529229443392, - 0.0190188776880045, - 0.015264855396727417, - 0.011022928221212308 - ], - "basis": [ - [ - 0.05778070631574466, - 0.07286651346865006, - 0.06789208674007043, - 0.19888781611491227, - -0.007636846721825736, - 0.09522774728537751, - -0.15862816851560244, - 0.06483429388360656, - -0.0924971538346382, - 0.03729873170853106, - -0.1698645776631848, - 0.08557082298527616, - 0.052549504307916314, - -0.11053081158059364, - -0.20401446026205544, - 0.04173933609961154, - 0.015545475326635355, - 0.17691322397518122, - 0.15692275857437163, - -0.03536744353808933, - -0.033017880025468, - -0.0017923753015524836, - 0.16589865413484026, - -0.05944672893216402, - 0.03272027812153193, - -0.07450261724377825, - -0.052437525296967824, - 0.10472579974863029, - -0.10831051024026722, - -0.05924105961196596, - -0.1662771852665948, - -0.18167315307641807, - 0.29554749203384245, - 0.10052420053139303, - 0.14816997365421816, - -0.05550080275911446, - 0.13438813185278473, - -0.0044245018957579955, - 0.29087092124163705, - 0.007307653502190176, - -0.13012373142016956, - -0.04186448461701455, - 0.1849900721269098, - 0.09523980433328698, - -0.04413205651535198, - 0.04835815040346002, - 0.20042106426470926, - 0.021481600616305118, - -0.10954548332092759, - -0.05056445575974966, - -0.009547051709784425, - -0.28238838687384094, - 0.12640635712714118, - -0.06329247368581277, - -0.1915594105448849, - -0.1314414807379713, - -0.11325281351028509, - 0.010817066482545254, - 0.08120235974983707, - 0.04046822324039797, - -0.012251332706729661, - -0.22625306708706835, - -0.2058690195864308, - 0.0553585768371667 - ], - [ - 0.2813335051060425, - -0.13818095578738127, - -0.21668080487769792, - -0.008417214271730757, - 0.09817636700245234, - 0.1059194044902661, - 0.05330074585841077, - -0.15793668593963944, - -0.11267498350728775, - -0.02107908200719758, - 0.17241163533888035, - 0.018355533754662964, - 0.10658887739071944, - 0.03217736830977806, - -0.24008327244890337, - 0.15149102742195977, - -0.06682717135679199, - 0.07038405102286542, - 0.1515733967074137, - -0.1401158471851269, - -0.11707728943868866, - -0.07153728617101765, - 0.0032218910235629747, - 0.0066986289600011574, - -0.0031949543367715935, - 0.12252821455067342, - 0.05407693515697283, - -0.1671608002159041, - 0.016987394395404753, - 0.028891129053056384, - -0.06304581295866205, - -0.2640421553307036, - -0.08192221037421844, - -0.04330484225865869, - -0.0791202384636913, - -0.0646706931734327, - 0.2255405624938867, - -0.08918199893542492, - -0.051052647948733966, - -0.07273829955159303, - 0.18418289065062712, - 0.27097745016346264, - 0.0939781044803786, - -0.03319840963343339, - 0.05486235822164861, - -0.158253956434383, - -0.19105019594646896, - 0.0007778831116014947, - 0.0028677211921028234, - -0.02276989485493733, - -0.09738665540487232, - 0.134699226429839, - -0.17076298809327825, - 0.0999809235171089, - -0.007133928129176977, - -0.10017293956059355, - -0.04504435353186681, - -0.05711295762117906, - -0.14327390123656836, - -0.16507777436379842, - -0.12997092541330596, - -0.12415157316019061, - -0.12264814246665391, - 0.1813511409799996 - ], - [ - -0.0012294834851969234, - -0.10452082179961998, - 0.21636555231255195, - 0.1797916834983407, - 0.03086604905377251, - -0.02724366143592933, - -0.09203610084779425, - 0.19559067199067626, - -0.03209593392325043, - 0.10356028175827184, - 0.10015801066832322, - -0.13035632441495423, - -0.08570687299413371, - -0.044399792502643906, - 0.2525057241040404, - 0.10035316070646277, - -0.05208203587134041, - -0.10084107622664408, - 0.13616565571418035, - -0.16221506310645692, - -0.0274082265240273, - -0.10738205989009071, - 0.20203082318656126, - -0.1415977923127791, - -0.06448981393122556, - -0.04226065007361196, - -0.18657659871661975, - -0.09593363586931962, - 0.24160798393173472, - -0.020667994989577446, - -0.056740842020819894, - -0.07359989396744711, - -0.03133738864867726, - 0.013250126911463525, - 0.08433353132018408, - 0.08346649485756742, - 0.12490767467113276, - 0.007407262390142613, - 0.07008236628053943, - -0.1404257500613525, - -0.2665191010075687, - 0.12234331885323134, - 0.16524679789780206, - -0.1988802700874564, - 0.1518291005935598, - 0.0746307906146861, - -0.020090150157783655, - -0.004771846909837983, - 0.1817722249040406, - 0.10558136266118089, - -0.13055176991562778, - 0.07978743689140438, - -0.08656395131098295, - 0.053055256244653105, - -0.15768397946323068, - 0.16079423221062158, - 0.08849212203265196, - -0.07959612787966236, - 0.02610831043066098, - -0.08405431849832079, - 0.1757038568857719, - 0.24750904125645867, - 0.01367382187432876, - 0.10495089082227982 - ], - [ - 0.0419607868437494, - -0.038379162499085254, - -0.04649115173892966, - -0.10499836379189814, - -0.058178635112686145, - -0.0007059749035264652, - -0.3710698614573143, - 0.2141151434198518, - -0.06322888454013387, - 0.21356226729086542, - 0.06972968267449547, - 0.09817065132324912, - -0.18899583131649567, - -0.0825540715684149, - -0.11741177215174294, - -0.154742644162569, - 0.1641273928854401, - -0.09436239943805652, - 0.0216811712045641, - -0.0618809804723893, - -0.06929000612543143, - 0.07577752897782933, - -0.0490008690530873, - -0.008998145134055304, - -0.06953628967057346, - 0.08744708029932695, - -0.11687386284365944, - 0.04699152009276513, - 0.1450578903500715, - 0.06448820280164164, - 0.08270687002056212, - -0.0895433915934336, - 0.022984313167850292, - 0.007111354957091783, - 0.01519752370807276, - -0.0581704475692699, - -0.06499527791119296, - -0.03606772071391784, - -0.01733146875185352, - 0.07839266779914737, - 0.13871886507861778, - -0.21396810922261597, - 0.2452456482561397, - -0.03318767782967865, - 0.05600049526448378, - 0.05723498675374917, - -0.14098349326926285, - 0.07751546214017185, - 0.22341952706613824, - -0.05119084102196865, - -0.06729146082467934, - 0.146382356110629, - 0.31315929058834624, - -0.08524496697632762, - 0.14033520054843085, - -0.12619839768711683, - 0.10848791521600402, - 0.12070138567161291, - -0.17755293683078116, - -0.04500521928075687, - -0.26155941912568725, - 0.019213956102286704, - -0.03403173342258146, - -0.08183996474464376 - ], - [ - 0.004686515688526125, - 0.09153840289666594, - 0.09304147261356097, - -0.27750831291450706, - -0.005843226798478385, - -0.05331504997719061, - -0.10328362820795389, - 0.2729141028712545, - 0.088242120952203, - -0.1405281723986079, - -0.11077940270469411, - -0.14424670675622206, - -0.01171753278296814, - -0.06611186977276017, - -0.17852257227971594, - 0.23047881577602095, - -0.06336685224578123, - 0.055803482031171345, - 0.2347131538041687, - 0.12135690917897317, - 0.09342934174832111, - -0.1470565622186841, - 0.07487754001365282, - 0.14619154739553603, - -0.18012520446000765, - 0.030164206678113148, - 0.3198327544418117, - -0.019117853538940306, - 0.05928095653304158, - -0.159276805455742, - 0.05271682419942305, - -0.10338299995284443, - -0.0733364424126697, - -0.07843827803036271, - -0.06918381700451318, - -0.040813189234111175, - 0.16246139035386706, - -0.006776111476486176, - 0.02021846599278357, - -0.16929011829641327, - 0.0111480409896128, - -0.23813825035061417, - -0.07543495867439648, - -0.14109773928904196, - 0.16298459450715716, - 0.08301372084070789, - -0.049500947154109465, - -0.03735025486495569, - -0.07897742439544347, - -0.06254188251519428, - 0.1252137034474745, - -0.10915308779027787, - -0.05489496905773998, - -0.16713448434771513, - 0.17633930836569842, - -0.05797435637498088, - 0.015619822200792464, - 0.048458438429748674, - -0.04020769527068216, - -0.13709003215834095, - 0.16672345515907702, - 0.029172357931993076, - 0.08395703240873566, - -0.008869150711562726 - ], - [ - 0.07136204375749354, - 0.20189068134495014, - -0.021465241471643266, - -0.09310813265836783, - -0.04216771181880527, - -0.07688320563874705, - -0.1926164466405881, - -0.01598990250568793, - -0.07190525411877013, - -0.06441639111773169, - -0.1107280810881075, - -0.01665898052943167, - -0.16750272319338458, - 0.08063056129628035, - 0.2045930550131397, - -0.10567966077240289, - -0.12785100252426404, - -0.11575128689141104, - 0.15845832800433785, - -0.0009621624539817432, - 0.17443793547564052, - -0.09870854164008967, - 0.08214935973542845, - 0.05127510411668108, - -0.14328260610078375, - -0.10557080767324234, - 0.08853089892645823, - -0.05489744905704736, - 0.11948029581467663, - 0.08503805181754562, - -0.05374448532263895, - -0.06864325743829605, - -0.07921863820110978, - 0.04608474506544839, - 0.11384598726686136, - 0.027524294026780437, - -0.10230064180893739, - 0.10822259754555658, - -0.022395767451671086, - 0.1535811227269366, - 0.3185635424055194, - 0.05040824570301433, - -0.0345834633241595, - 0.12482745349141246, - -0.1352337190002673, - -0.06118697916134407, - 0.11414229119191363, - 0.12345026886775114, - 0.07669459666885191, - 0.1551852604724053, - 0.010856697856678628, - 0.008185268589653355, - -0.025829914661579998, - 0.06855818452377334, - 0.05691002109339281, - -0.21280908269495574, - -0.2276608654976305, - -0.21912527022332437, - 0.2746044321459274, - -0.05005465113719567, - -0.03490534587966216, - 0.12395744586077656, - -0.1329958598895383, - 0.2809472973454882 - ], - [ - -0.0774218382571616, - 0.05025481717019194, - -0.11816337780725826, - 0.04119304746311918, - -0.11210705838117555, - -0.04137521287611308, - -0.05342518790957326, - 0.018159341307965097, - -0.012838897539542132, - -0.10095816328229465, - 0.033066435335222785, - 0.10302707536827653, - -0.028916206148479753, - 0.06378928099686325, - -0.057437715207443216, - 0.18334998094948837, - 0.07871337300436815, - -0.011839210069407, - 0.06074327215818029, - 0.07440824677867143, - 0.14829586020049035, - -0.038844083992004584, - 0.11981075023574272, - 0.14029772807471055, - 0.1495584412660448, - 0.09523581834118008, - -0.12173344273391504, - -0.04833630827151547, - 0.046736311253778834, - -0.19742094110774872, - -0.022400210019152687, - 0.15530812008384312, - -0.0745692420341923, - -0.09792586907151417, - 0.11964220847701264, - -0.11127149027612046, - 0.07996006703000327, - -0.010659218073415862, - -0.18731067604147084, - 0.2670726478965396, - -0.24118647031298063, - -0.023960886088180477, - 0.0820868806706184, - 0.05318938203202385, - 0.11557901144682149, - -0.17313827005965673, - -0.08382367923684972, - 0.08896058128432446, - -0.14029401145940892, - -0.14298421456992733, - -0.2799325465768428, - -0.04995766440152863, - 0.11267955645167728, - 0.355184201052034, - 0.09765245757951505, - -0.23040024599153133, - 0.030050892346376326, - 0.1530987168172032, - 0.07291869878271484, - 0.13845172369828432, - 0.11290067530827999, - 0.08276817112184139, - 0.12584962379312345, - 0.1375467651895714 - ], - [ - 0.015857807753650907, - -0.007049051506370918, - -0.16800698681130832, - -0.08896730536451888, - -0.06649344969905045, - 0.1738824825709564, - 0.0324365553191597, - -0.13876490824023263, - -0.04082687066751646, - 0.07279864951879227, - -0.11594427679331094, - 0.06580168133029879, - 0.00974424923690866, - -0.11052351339276682, - -0.0782528363553297, - -0.43335237214132716, - -0.24664101334723337, - -0.11046943244354027, - 0.02553424916954697, - 0.09151633519178942, - -0.007822006744279065, - 0.011816269295302492, - 0.09890389186626093, - 0.14183777798044372, - -0.216632005152354, - 0.08084445890649436, - -0.07959296251340393, - 0.01891345015465241, - 0.22811272031258092, - -0.12699504901249373, - 0.10833335270516507, - 0.24574759351401357, - -0.028779297592364316, - 0.12964160790377274, - 0.1369157645750225, - 0.05832108318367788, - 0.2577628871910632, - 0.05001524796001277, - -0.15025174755168896, - -0.1308423526968725, - -0.14275299259438512, - 0.01369512251109114, - 0.078566405721264, - -0.13154834868431403, - 0.005309529532686604, - -0.05408984486639841, - -0.1516103194091148, - -0.14837474873901144, - -0.12322527844849299, - 0.024115397681288467, - 0.09015432753414492, - -0.10669786190648159, - -0.01507051435799418, - -0.04490447071047139, - -0.012761750144557965, - 0.13189289252170944, - -0.09662110165658871, - 0.0790955693082717, - 0.05122088003976571, - 0.0942595062642386, - -0.05603226526255116, - 0.0018449347892687032, - -0.19586056940235347, - 0.030145088664759248 - ], - [ - -0.17681077811353832, - -0.08902564720087648, - -0.012170997529225168, - -0.04964755098808042, - 0.09911146641439401, - -0.2016049322213473, - -0.1401989530340678, - -0.08368455450883013, - -0.031838101448992955, - -0.04073528423510776, - -0.15082439684599785, - -0.025529360042207065, - -0.28620622100991566, - 0.0386570344875172, - -0.26351397660476134, - -0.08795195158315774, - 0.01810150779963256, - -0.010520345238909127, - 0.25917212964172714, - 0.18675053755677995, - 0.07953512734467996, - 0.08912543584745736, - -0.0414880377787231, - -0.10866957098858249, - -0.10412947230405528, - -0.1283877272346812, - 0.0004132498419996702, - -0.03423668344078186, - -0.2106185275173125, - 0.05718799735788313, - -0.02733360933445277, - 0.16318989142627896, - -0.12989586440940432, - -0.14247993464162395, - 0.04637682655285827, - 0.16436303709198824, - -0.024565557189443338, - -0.1973409078434956, - 0.010725820338040927, - 0.03454374242319189, - -0.16183469230221575, - 0.074741040785522, - 0.1404036042961516, - 0.022604172892988324, - -0.04596516542794427, - -0.006812530590924934, - 0.06284270614031877, - -0.05244484399947216, - -0.07603110670072598, - 0.1149795756520334, - -0.23938173025015325, - 0.11771235557053139, - -0.2122549877268696, - -0.018285872483423695, - 0.044090876747577015, - 0.08481203454989306, - 0.19681756269264972, - -0.24786759629482122, - -0.035244899793878265, - -0.034943506214449555, - -0.066354288019479, - -0.17363472251688267, - -0.054735479099857834, - -0.08774906808056644 - ], - [ - 0.03375289015577752, - 0.18921745259021336, - -0.0019197942776600255, - -0.12590422847445207, - 0.09768057249144053, - 0.3432577547943643, - -0.15799527381127543, - -0.16375680747764382, - 0.026651401828846625, - -0.0025535613538021887, - -0.004183830852377679, - 0.002951505051361141, - 0.09344499832223076, - 0.0925586869888311, - -0.17165213035765114, - -0.04328681937286176, - -0.17604654224168872, - -0.12073915235182045, - 0.013527665930324995, - -0.022063264347390185, - 0.21113794212278797, - 0.0025640666334042425, - 0.21272697399642107, - -0.18846271567096298, - 0.11234497010731495, - -0.06228774868551157, - 0.0020176685230897454, - -0.051425263413147695, - -0.1740678059220672, - -0.10206106698079045, - 0.10382841256490313, - 0.0009266766219265426, - 0.034008446462075854, - 0.21416454731775153, - 0.07404279650868556, - 0.07242091814125369, - -0.06005885347874724, - -0.15274987955723957, - 0.08259163009737328, - 0.237189705631974, - 0.11684540715524976, - -0.08189903095837099, - -0.022316164035307097, - -0.08749501062622154, - 0.10031513544679851, - 0.10681096621599044, - 0.023735707337009443, - -0.10757787304558343, - 0.19855702321528412, - 0.059798578008685634, - 0.1296671287676634, - -0.006779599720448135, - -0.04922480966612093, - 0.27735395262853335, - -0.10363300198534398, - 0.10482511023995206, - 0.12397711451662365, - 0.05991112054173471, - -0.13191368141933765, - -0.1326022894778416, - 0.05883066312636839, - 0.043809725087856397, - 0.21031312714273867, - -0.04524123280669704 - ], - [ - 0.12464866893260328, - 0.021800828236621987, - 0.147075317066215, - -0.0655015039106186, - -0.026072704084262027, - -0.09161293827276977, - -0.13154685695722926, - -0.09527892928014604, - 0.07420716719771851, - -0.0991819118387537, - 0.045214166821962436, - -0.258435830495211, - 0.022843500278589206, - 0.3196839165449696, - 0.04650914556346687, - -0.023638847784061782, - -0.029492301416749436, - -0.18481148098682237, - -0.2654508607868117, - 0.04586599281037926, - -0.2288155451590118, - -0.0206383427286272, - 0.22618740289439976, - -0.07038052432058178, - -0.1010825379710163, - -0.1625975090922008, - 0.03790574058403241, - 0.054809008091591775, - -0.2170780952148908, - 0.16552679458401184, - 0.12611347598666486, - -0.11587231171501644, - 0.014337833294198606, - 0.03371848443393485, - 0.11418139911181807, - -0.07336411184281025, - 0.1652145091908342, - -0.060948537001589045, - -0.1629188144588259, - 0.015354233505749814, - -0.12153495261960165, - 0.012938417198661244, - 0.05468544732145311, - 0.1445366274212146, - 0.20488513725489693, - -0.018428503523405665, - -0.15263874790475787, - -0.18086931311941684, - -0.08627811500687547, - -0.042229266705675825, - -0.13397375637312453, - 0.04180955901474831, - 0.1454827656494679, - -0.14687357125415057, - -0.02822064817030887, - -0.10250633771459744, - -0.18017276812218, - -0.01138506552952525, - 0.13175135324276863, - -0.031951588131087186, - -0.04338574181648438, - -0.07493557245151944, - 0.06661804721868969, - -0.10478677944074291 - ], - [ - 0.028119737454515438, - -0.08077639462189953, - 0.20307895534618703, - 0.03046570268977763, - -0.02421880027562961, - 0.42214534639413054, - -0.0039304152372050495, - 0.043012571515450834, - 0.05629589384089497, - -0.008447056007665267, - 0.18175581850280237, - -0.1390227093389812, - -0.09993137046356741, - -0.062201531126215105, - -0.026422350536944365, - 0.04559848386332883, - -0.08639862166782229, - -0.0953763264218209, - 0.03919475273331853, - -0.14413112393364494, - -0.1934470393221734, - 0.0019342992012041484, - -0.11057475264066363, - -0.16418206434996443, - -0.22891946611222413, - -0.22750066423783127, - 0.12892573221926293, - -0.02937658052345655, - 0.09976268238034432, - 0.08040889589742105, - -0.06528795099206064, - 0.1595856971300084, - 0.11061928988786761, - -0.028387008632303524, - -0.006247078896566531, - 0.1353390102669052, - -0.13186478054809575, - 0.025760385072472528, - -0.04589130994784655, - 0.1264789417861582, - -0.04424644027545937, - -0.05499761797883232, - -0.224086728858504, - -0.027443790886059305, - 0.060223825953531665, - -0.20184613712859925, - 0.11141975771480432, - -0.009667678105967368, - -0.10425629734415483, - -0.16197970437729117, - -0.09664772502406098, - -0.11891057186334411, - -0.012637224559465565, - 0.031010354345127177, - 0.21053234149379177, - -0.12298606361854225, - 0.15327635654695443, - -0.016958560197081956, - -0.12015759524337595, - 0.16837571505493404, - -0.03236044531106013, - -0.09033034957483263, - -0.11167789751923257, - 0.15672001325278567 - ], - [ - 0.192003210526067, - 0.052280755626771744, - 0.10042848598108972, - -0.03957630494438042, - -0.18965754149183955, - -0.11933381553513828, - 0.08806196534188432, - -0.12243207404341883, - -0.04787228028714249, - -0.0017090244914202363, - -0.09921941423554557, - 0.014837651933981429, - -0.24834271165834157, - 0.030326816264118574, - 0.08484083059378295, - -0.14447637085820214, - -0.015341021016528428, - -0.08833915306676886, - 0.23593002630634746, - -0.1322494965357214, - -0.14320306960539844, - 0.3576751339122756, - -0.051472864169289326, - -0.09490282181897275, - 0.1765113272766727, - 0.07194321289492944, - -0.1037196404775649, - -0.155764473336874, - -0.10734913382180455, - 0.06607085975900093, - 0.1295002338663515, - 0.023735658321045947, - 0.07683680400638582, - -0.09841948445558713, - -0.019594646158097504, - -0.22287310786577427, - 0.2290702541129712, - 0.11176634581463651, - 0.161277716816923, - 0.019496784479380923, - 0.11207255044774825, - -0.060633884848971524, - -0.025435616011217854, - -0.04155939145211844, - -0.02397116937740804, - -0.13155804907322952, - 0.07293404857894795, - -0.12615678399428826, - 0.11562877342736759, - -0.04921352897601258, - -0.045479347182745246, - -0.17825638698641358, - -0.15819589494818842, - -0.09037428030672219, - 0.1647647078246356, - 0.023784799583753964, - 0.011385420180622248, - 0.15154466488427368, - -0.021345758896078287, - 0.009437019751341705, - 0.1909146221751045, - 0.007996207679774344, - 0.19043375826915795, - 0.07223508560894766 - ], - [ - -0.12702167613264959, - -0.15733464696251076, - -0.07021947295000967, - 0.09505424923799698, - 0.0050132813194051174, - -0.13509188380633136, - 0.23400448247244277, - 0.1429067044334582, - -0.03669465636263939, - -0.02094473831783238, - -0.08294104662846859, - 0.21377465543375013, - 0.014032373646291948, - -0.026974100657667897, - -0.008242644346563, - 0.2799323366660867, - -0.13363903698877108, - -0.195777819325748, - -0.0043613886988283545, - -0.269190288247805, - 0.07637283876360074, - 0.20384186343112864, - -0.06760464524296357, - 0.08107032337344816, - -0.19098815270207184, - 0.05821145159277812, - 0.06039136877696828, - -0.004021806270050806, - -0.10787667278881952, - 0.013501048222457266, - 0.24472912948645867, - -0.02803938754415532, - -0.07357372457069565, - 0.046815091411122604, - 0.2254337567951092, - 0.1350827252369111, - 0.032515233626724524, - -0.15099793681929055, - -0.08149610210447016, - 0.032142463340883116, - 0.018525489903518436, - -0.10600604702968257, - 0.0034729673745671303, - 0.010930853532494983, - 0.22325020978137947, - -0.2269309744869285, - 0.2838703820629147, - -0.10111371881359743, - 0.13794131683939986, - 0.10619197533356661, - 0.09394458464170409, - -0.01749311566881192, - 0.13397837601485618, - 0.027045683996334117, - -0.06450215576227007, - -0.004354230485135649, - -0.12373217058248154, - 0.014952704425756275, - -0.007091820457307376, - -0.06928902081312834, - -0.08426827692172391, - -0.04795157748109627, - -0.0926918132015763, - -0.04484671866527107 - ], - [ - -0.03595159973328626, - 0.1658181955071641, - 0.18554520643503333, - 0.07411905692320851, - 0.17412568609823154, - -0.04588178621480291, - -0.07807556665783155, - 0.19910960934284266, - -0.17963662366383135, - 0.014457030520629372, - -0.059607394280732244, - 0.05248136279436696, - 0.10701120722597877, - 0.04670848735224566, - 0.14167368170983358, - -0.02765456964558165, - -0.1062001625494046, - 0.19767534276941942, - 0.17365083352436644, - 0.05215382653506768, - -0.1165758160793418, - 0.0717153218779642, - 0.15806752661607193, - -0.021582338090718717, - 0.05436519430990746, - 0.10014264516867949, - 0.1196031748913125, - 0.1875784369688354, - -0.26775630828592584, - 0.09907513503088128, - 0.017702834217060603, - 0.12509012314400134, - -0.07869278160289717, - 0.055566323533567115, - -0.1809391205312903, - 0.1161060217711817, - 0.02554445944381678, - 0.28024122878866514, - -0.0867541495448688, - -0.024231061935922903, - -0.08201865978028758, - 0.12681882268962083, - -0.05688125381680435, - -0.11321683743415431, - -0.026500243291204758, - -0.2544793113682899, - -0.09142680679825747, - -0.07471784679600411, - 0.024870359688799023, - 0.12836156300336812, - 0.0617959229676628, - 0.016404327838771007, - 0.018572544543744626, - 0.12168096540682392, - 0.033088542102966814, - -0.09113937910215525, - 0.15008090973449484, - 0.23016409570934787, - 0.024450066595461242, - -0.09330996800400565, - -0.31056184170475326, - 0.05783162969482089, - -0.033199523880363714, - -0.0031415196355178677 - ], - [ - 0.008012210570305404, - 0.22621251459584746, - 0.1112494448874546, - -0.11303113712645627, - 0.027154545089743458, - -0.00870012366371227, - 0.12574936675653486, - 0.032836176675730896, - -0.06152027865208995, - -0.16198906619291276, - 0.13364980138804422, - 0.11405734922772835, - 0.16531770997861964, - -0.1247570435145463, - -0.05368963568725955, - -0.13335871682481346, - 0.08514281902493794, - -0.07383412341477165, - 0.18812530801342608, - -0.18439939780457754, - -0.1725530662147781, - -0.19854300434121652, - -0.10927628402047782, - -0.042028305552883734, - -0.036927780268801884, - -0.10004056586212627, - -0.015348187984871918, - 0.11456433159248475, - 0.024785953757611858, - 0.11754305047919675, - 0.04118385589316246, - -0.03487125809356638, - -0.0725279326960093, - -0.18839089559116057, - 0.1843613184948179, - 0.1442124984295827, - -0.13059911317929887, - -0.013266031829573921, - 0.006504537500570045, - 0.05855191077036526, - 0.14079367586661318, - 0.034665963904419075, - 0.3012226928250339, - -0.19733825583400497, - -0.07782389751393877, - -0.05388475768811978, - -0.021984630038474007, - -0.0016098996635411811, - -0.14457121384827976, - -0.012165728011006665, - -0.049174595918210016, - 0.024733388350448495, - -0.10752836740355401, - 0.09039415549764838, - -0.0595485403151979, - -0.07984099051338935, - -0.1648821455094799, - 0.14527933549530953, - 0.07953934900030961, - 0.07311876618430407, - 0.19350615902040708, - 0.02042250198775232, - 0.06296381007245772, - -0.3774449276300719 - ], - [ - 0.0328399383618359, - 0.059646613754004714, - 0.014157393163160273, - -0.1266206462905591, - 0.074601470533438, - 0.039318680233060975, - -0.07367873344331623, - 0.19894392560214968, - 0.21836984251100436, - 0.08770480876673764, - -0.16386320622751022, - 0.2208220036876173, - -0.15862590576311894, - 0.30156389337163475, - 0.037884650727510245, - 0.15618355555472505, - 0.0835228881039172, - -0.11403095846738681, - -0.1845122949251156, - -0.07433612905101601, - -0.07290198189794327, - -0.02904696340860781, - -0.09275522916435205, - -0.010095518935279013, - 0.0535222965332312, - 0.0636672070106534, - 0.04058838985105025, - 0.10310356976914077, - -0.032595796334171194, - -0.04761345128959992, - -0.039678098841617014, - -0.024091120024997678, - -0.06092336772502803, - 0.027884220082457042, - -0.05050057030935829, - 0.2202074605143457, - 0.16861810485531747, - 0.05227491297951386, - -0.04162330881981021, - -0.020538125712643237, - 0.014525376397633407, - 0.003984300538669859, - 0.13070506175805136, - -0.18612996891067446, - -0.39536170184749514, - 0.0030299418371109565, - -0.030431562305453318, - -0.22184925468992253, - 0.04895757460943083, - -0.3322368739164727, - 0.010663499796124642, - -0.0397661788734229, - -0.043823125048732, - 0.1407612557914304, - -0.05903040073950477, - 0.08431329398922136, - -0.057353608146366274, - -0.14029987162334362, - -0.030219246299561804, - 0.06616793810914227, - 0.06024197657094715, - -0.08402396887517448, - -0.05866882629522877, - 0.1361275670822255 - ], - [ - -0.012693429693275547, - -0.208869783413332, - 0.14722037697424672, - 0.051978383158621, - -0.4023008419543545, - 0.03139089066962611, - -0.08313272059198114, - -0.13597996235057905, - 0.05266817538255897, - -0.29816974736420293, - -0.18895472354175497, - 0.031945173859244134, - 0.20811691789413256, - 0.09403282944912356, - 0.04768017890425305, - -0.01978530415383368, - 0.19745109076634998, - 0.13393619285142963, - 0.03443931938695601, - -0.0025780699284727094, - 0.08770838597693166, - -0.024052841818724205, - -0.032223038130371036, - -0.12681331705629417, - -0.02974759859533883, - -0.05103414111908073, - -0.14825042359085222, - -0.10179557944867117, - 0.0753012732213607, - -0.03211490731588429, - -0.05682691405101341, - -0.04370620598368544, - 0.040607450553591745, - 0.1562908290150229, - 0.02276766316602659, - 0.2274268144947168, - 0.12234062384643538, - 0.042198509201977874, - -0.09248662832417658, - -0.08617849962291989, - 0.08565045112594578, - -0.005210994755579962, - -0.022145137046682903, - -0.1335321885023295, - -0.06376034834298848, - -0.1455703187223391, - -0.010978304488568716, - 0.13982724481475498, - 0.024635581798511424, - -0.035993024772045655, - 0.0069735956629440946, - -0.05488602872190048, - 0.14283477777573342, - 0.09464363148376265, - 0.23504209749746566, - 0.0993795568218695, - 0.05534437259612988, - -0.08280442126269363, - 0.07429483689738683, - -0.2963326354634372, - -0.07831448418491534, - -0.06802674433027782, - 0.019113888414294674, - -0.1836277125592738 - ], - [ - 0.08110728685214495, - 0.008567694548792238, - -0.2260168905875551, - -0.027523873906788045, - 0.00979309404740861, - -0.08556215473893887, - -0.26705715579751077, - -0.05503699823934573, - -0.0412462633469098, - -0.04365083291887468, - 0.007106901769130643, - 0.05008456857980749, - -0.09293276087633306, - -0.1694109735117638, - 0.08404578716158939, - 0.2945839804333673, - -0.11636801254851412, - 0.1592442421847718, - -0.046424669172648085, - 0.07639359568406803, - -0.09858451881405289, - -0.08329215845267829, - -0.07514058323068515, - 0.042138052355175086, - -0.007282996009778379, - -0.03441248362686388, - -0.2736559935844757, - 0.11352073382623575, - -0.037862867652073244, - 0.2207422513123871, - 0.12806395206200188, - 0.011965312745873983, - 0.07319290986437652, - 0.23831249771130997, - -0.03185934674125355, - 0.29222416309196436, - 0.025087550110550996, - -0.07895029677785842, - 0.12000896928929239, - 0.003004920298236963, - 0.15358388017341668, - -0.11516874820415325, - -0.16045731571453817, - -0.034419045081069195, - -0.004262907502796975, - -0.11449312548835794, - -0.15526626147282158, - -0.06992611934395422, - -0.21129742357198047, - 0.20146918862190077, - -0.17257589451151903, - -0.028955504144038666, - 0.012782070009110913, - -0.07318714623630367, - 0.010598546818954849, - 0.13055225608778334, - -0.05667091815624647, - 0.09976378068425934, - -0.07453377062976912, - 0.12191075256523175, - 0.18873701184953806, - 0.050820686327516754, - 0.06718635640768619, - 0.0716637676935345 - ], - [ - 0.10785154298555046, - -0.02847079498701869, - 0.13801766014903225, - 0.060393014333554665, - -0.13754452672758205, - 0.09504026202043153, - 0.09792132441184086, - -0.06803629647600935, - 0.1464132983427304, - -0.019526691333605233, - 0.27732530208454176, - -0.16592970128241047, - -0.08953764724797672, - 0.04382249988773939, - 0.09718109700874455, - -0.03632138969150829, - 0.14058069292553882, - 0.20294476013884521, - -0.03531993016295344, - 0.18344990867088307, - 0.20789242575404812, - -0.11799447321842141, - -0.24509112664857705, - 0.24252805893626092, - -0.027961041165625044, - 0.1917674101461131, - 0.0818337926464498, - 0.115782472573863, - -0.1466252771397498, - 0.05462864042333893, - 0.029278383598107697, - -0.08193097521740289, - -0.02483786919053042, - 0.05082960597881795, - 0.2821712414860102, - 0.12257034244164737, - 0.11455425306871057, - 0.04067052961080349, - 0.14496296474060194, - 0.1509098609815918, - -0.04486562693131072, - -0.07201624402554825, - 0.12833131875597856, - -0.09112269600737892, - 0.06816377245443406, - 0.0547100987668704, - -0.030924523260931477, - -0.1523778305726125, - 0.2619692498481616, - 0.16547753447823987, - -0.042134555939171855, - -0.05880331582453431, - -0.16935657054748549, - 0.006140702488209683, - 0.05290619211063246, - -0.04219449551393023, - 0.05215513234505944, - 0.0806550726527901, - 0.05246671445391669, - 0.10904652098148698, - -0.0988090783324191, - -0.08477921403141707, - -0.11943390792437328, - 0.06568274257942135 - ], - [ - -0.001011109048310474, - 0.25206364846140633, - 0.07898673418003221, - 0.031361664668801296, - -0.055534796620553814, - -0.08189625931717957, - -0.03439483168618691, - -0.030845609079278018, - 0.012501831339808103, - 0.1427341683882216, - -0.08371636941319921, - -0.0792000651774336, - 0.030939313181979962, - 0.19500843396177175, - 0.01837162312479497, - -0.004257377524678035, - 0.05919441446214665, - -0.2747274852527697, - 0.16142276916878828, - 0.053437490491870396, - 0.02411258812740083, - -0.3987960887248529, - -0.2167176264481278, - 0.09110036752755586, - -0.14091640768020058, - 0.22513900096631462, - -0.16659802724860318, - -0.1678530383972068, - -0.0981614997108141, - 0.005853378072965292, - 0.03850466551311, - 0.05056403881375218, - 0.15146047962375409, - 0.1588380511855258, - -0.17630195783026198, - 0.02532947358336288, - -0.02591307021869726, - -0.04144345198632382, - -0.05442781171216455, - -0.1703515227502689, - 0.020284881979706303, - 0.18861050513319236, - 0.046845774624786674, - 0.21407758970887344, - 0.12658756139065838, - -0.15010646056197824, - 0.13752711494602593, - 0.09211108621633696, - 0.03960908637856115, - -0.025789453539938955, - 0.07748690138790519, - -0.07625677442773815, - 0.04284516409889278, - -0.0009001008875406623, - -0.07099472219750451, - 0.001971029281993388, - 0.14896140175928388, - 0.08651086982664341, - -0.17150004144124806, - 0.11377688193659802, - 0.08140677062507579, - -0.11785418974895197, - -0.026146202393744208, - -0.052991049952148296 - ], - [ - -0.07763871982765788, - -0.037022454044536274, - -0.08133137476743013, - -0.14995952376162133, - -0.027192608412265635, - -0.010883718007404572, - 0.03387182487730816, - -0.06571775417343903, - -0.16806080264359816, - 0.02629754582982674, - 0.10223724855373252, - -0.17647750359858042, - -0.1567722240401563, - 0.19667919048125007, - 0.14634095013036474, - -0.03194586032279909, - -0.002170041232197811, - 0.09669628117661058, - 0.08149217811125993, - 0.047955273753619417, - 0.006519443127691277, - 0.03340066730157272, - 0.11222593643879389, - -0.07182881768502802, - -0.03926672306930384, - 0.30885364238992274, - 0.07496953625880119, - 0.1566553872853372, - 0.23187480391437124, - 0.21224958871250577, - 0.16877882786153492, - -0.0831577172385525, - 0.01641882030236645, - 0.07349989335527013, - -0.13617094011065767, - -0.0889617610975902, - 0.0486532563319984, - -0.07747823863751589, - 0.1668919148552347, - 0.17775934628241824, - -0.14944357938176292, - -0.14432515923925313, - -0.14809355047631137, - -0.11990793979015, - -0.016925104882366614, - -0.10726850027455413, - 0.12738648919191245, - 0.17751475738312678, - -0.12088402869048684, - -0.16488860245703268, - 0.026400081251831166, - 0.02344682288022941, - -0.01982897772297213, - 0.20426301249561887, - -0.17801811594726186, - 0.014585519206016253, - -0.06868746584633693, - -0.10684951005017684, - -0.05362795064605469, - -0.08124536274295659, - 0.06257035731821178, - -0.10373609707004978, - -0.18542282517265782, - -0.26783468280392697 - ], - [ - -0.01900513821179778, - 0.025619001546502786, - -0.15182311426425446, - 0.18767758750565977, - -0.043065934957145675, - -0.15649393422520405, - 0.011303323324511923, - 0.01808776285486967, - -0.08442441513959573, - 0.05750827980668858, - 0.025106937667315976, - 0.07473098102021661, - 0.05664923488997862, - 0.22717568584623157, - -0.023102828134752593, - -0.18485513219547128, - -0.1915961158197995, - 0.038642614382254636, - 0.04932882253017845, - 0.07673701628855742, - -0.08523812070884297, - -0.05065180112619618, - -0.04063073353263627, - -0.062496043991373346, - 0.16312663838316685, - -0.02359904422531626, - 0.2048513467862014, - 0.13520422233399162, - 0.023882777922809316, - 0.0553857592805706, - -0.04144521995854059, - -0.09720571914733137, - 0.1517143730966045, - -0.06369966108134037, - 0.296756158568254, - 0.11742196579596947, - 0.18300198922590846, - -0.07476752417012782, - -0.21523607746264428, - -0.1980009612485225, - 0.1811322859436022, - -0.03576748251932887, - -0.24952894038536347, - -0.19071495358811338, - 0.04476890465874903, - 0.2156971195878547, - 0.15709966166439251, - 0.11941222039836104, - 0.03874079591827669, - -0.03778722722172961, - -0.14647535472171447, - 0.057265793310904305, - 0.09686923816490849, - 0.02326822360528502, - -0.011566279970731173, - -0.12925950769143668, - 0.27426412471678946, - 0.006877452299898495, - -0.07161421807292674, - 0.1352475533838267, - 0.12114311870203577, - 0.04272953527162861, - 0.007515274266784077, - 0.014136130956010193 - ] - ] - }, - { - "layer": 2, - "rows": 24, - "ridge": 1.8692859013875325, - "mean": [ - 1.560458779335022, - -2.117570161819458, - 0.14606446027755737, - 0.7385113835334778, - 0.35017263889312744, - 2.852264642715454, - 1.471712589263916, - -4.897498607635498, - -4.0898051261901855, - -0.7625727653503418, - 1.556294560432434, - -2.527095317840576, - -2.3369786739349365, - -0.34086063504219055, - 0.4385366439819336, - -1.8613778352737427, - -4.776156902313232, - -5.0773539543151855, - -1.7670680284500122, - -0.8312468528747559, - 2.1675636768341064, - -3.947026014328003, - -1.7668724060058594, - 3.9983017444610596, - -1.1012617349624634, - 0.30404114723205566, - -2.3319027423858643, - 1.8102349042892456, - 5.833690643310547, - -3.1748952865600586, - 0.415873259305954, - 1.4522132873535156, - -4.975677967071533, - 3.4511287212371826, - 0.09703532606363297, - -1.7819252014160156, - 2.112746238708496, - -2.391087532043457, - -2.499199867248535, - -1.5980960130691528, - 0.8462106585502625, - -2.4977529048919678, - -1.2340339422225952, - -2.030357599258423, - 1.1722668409347534, - 0.003310779808089137, - -2.7347724437713623, - 1.901520848274231, - -0.1273525208234787, - 2.2576591968536377, - 1.1667861938476562, - -0.038532521575689316, - -0.9637408256530762, - 0.2768150269985199, - 1.9516559839248657, - -3.7724101543426514, - 4.50145959854126, - -0.7580049633979797, - 0.41315481066703796, - 3.947725296020508, - -1.5466305017471313, - 1.8362722396850586, - 2.8683173656463623, - -2.1906039714813232 - ], - "eigenvalues": [ - 39.25102774961602, - 20.957088942804223, - 15.685058773581622, - 11.166921524701605, - 8.18823876055516, - 4.92568076806379, - 4.282829736081658, - 3.632468746267465, - 2.832413516262951, - 2.459337532300649, - 1.650031834514247, - 1.1683608049693668, - 1.0404411922357586, - 0.7513934705145688, - 0.6354270243527034, - 0.427734958080868, - 0.15999780542389094, - 0.12699539275938618, - 0.09182410022444776, - 0.07531126259766796, - 0.06228092204825144, - 0.03585209436963218, - 0.02757360630872294 - ], - "basis": [ - [ - 0.07165007551171967, - -0.05284974840266888, - 0.1277718469648696, - 0.224389004000795, - 0.04671691956646257, - 0.14048337987954362, - -0.23928231843860998, - 0.19584074313972008, - 0.051063035422264584, - -0.04484774679852155, - -0.08219597605931848, - 0.09119876205525954, - 0.001482012712958301, - -0.13371366550641048, - -0.11401845735164293, - 0.10138557473625796, - 0.12971529687170213, - 0.05782334299569336, - 0.029128326019982206, - -0.03225845124719574, - -0.011747135547526407, - 0.023265631570257843, - 0.20878250404842316, - 0.012861315848251762, - 0.0540059028290369, - -0.14847995936040892, - 0.016904617324133633, - 0.053575490010348864, - -0.14045540213354982, - -0.1005349667969628, - -0.29424734392496227, - -0.1202495379853219, - 0.12979785507774547, - 0.07165243464093615, - 0.09693556827207428, - -0.014007875233441398, - 0.14607805822505593, - 0.018546437383872728, - 0.268920600440212, - -0.1263003618891494, - -0.17751517525903027, - -0.016431786907533167, - 0.11309552085722623, - 0.07986774623697807, - -0.11770469687284492, - -0.08202411171615925, - 0.08563375701996691, - 0.024263896324624567, - -0.13695415596206062, - -0.0026632242044345483, - -0.1653609861839302, - -0.10505363634814574, - 0.03916062806185106, - 0.05240937963976285, - 0.09257482766481409, - -0.26912407453089054, - -0.1324743862974485, - 0.06708520584545935, - -0.027723228075858995, - 0.04186429382426568, - 0.03941563617624755, - -0.20156339953700356, - -0.2397672937234998, - 0.18407067927719262 - ], - [ - 0.2034961506509508, - -0.15238348419607323, - -0.2786762964098768, - -0.015925923185432858, - -0.0854954450561804, - 0.04247665654257611, - -0.01851817354398866, - -0.13291910749977356, - -0.005018906872961685, - 0.0818996684623885, - 0.3185916291922866, - -0.01821757241829271, - 0.015806767059831684, - 0.0472383396679097, - -0.2589178555990559, - 0.0005985261236800334, - 0.07605654252622691, - -0.05864733333308161, - 0.22653893466485933, - -0.1077826810340255, - -0.045440095229602524, - -0.02632947148063776, - 0.03879043775666622, - 0.02843902664953157, - 0.006236520913775761, - 0.2240000710123356, - 0.09985127351868531, - -0.13627347282336316, - 0.20968754902205686, - 0.05018807115339014, - -0.07630928743137685, - -0.05974088749388648, - -0.09372380573305993, - -0.11353541951780768, - -0.12449999407645501, - -0.16620272298364627, - 0.181297771280892, - 0.01095909273750716, - 0.06300381486756734, - -0.016463130481280997, - 0.17417643806304586, - 0.09859299710924323, - -0.051793168424440865, - 0.01658796873656322, - 0.06622473274325943, - 0.0080299009394633, - -0.16579151742863565, - 0.0008195146161998211, - 0.17512759602142597, - 0.08068495383819475, - -0.2467371126802903, - -0.02654290685445854, - -0.09454713516985498, - -0.047092843540063774, - 0.22187708450972016, - -0.06813208070553084, - 0.015057212765843242, - -0.06818018365415718, - -0.16904146590771002, - 0.04231409297734045, - -0.049904622055211546, - -0.038870133756720535, - -0.017493477068708057, - 0.24506329502047874 - ], - [ - 0.0617010325560715, - 0.14654451374325406, - 0.1799645465249274, - -0.11745147259238033, - 0.1317120182311198, - 0.09982423678920514, - -0.15570232775960216, - 0.04623324656644668, - -0.10253709772120623, - 0.022677353205514783, - -0.0023632605780881705, - 0.021667396218863363, - -0.03634226109407508, - -0.09189272636263113, - 0.34039203827662706, - 0.020715344215286854, - -0.028589832853139686, - -0.12362787171683115, - 0.013517714475119758, - 0.07217871141037925, - 0.09277275027116638, - -0.0163748182581707, - -0.04934552127990326, - 0.05133316300654316, - -0.1352316118836267, - 0.07687329792306122, - 0.04360831418896233, - 0.024223425260879356, - 0.05601270031617033, - 0.04427906708502388, - 0.07304935372924455, - 0.07793576622162766, - -0.11980828881130935, - -0.21408248771551353, - -0.03334168575113953, - 0.08474384491370825, - 0.3289593669762299, - -0.015702018416106935, - 0.08072302315430482, - -0.13242151599273255, - -0.03134102749301912, - -0.20222813717415958, - 0.08047308559146038, - -0.05803299987638274, - 0.17311248723098274, - -0.07265694795642673, - -0.11673598188070117, - -0.058464705710999335, - 0.09237263445333398, - 0.06390914602906438, - -0.18258947963745836, - -0.01251424370468137, - 0.17240747289812958, - 0.16300526515167726, - 0.2505310410246204, - -0.10451346704827423, - 0.10356252869848537, - 0.24200218300054077, - 0.08598192843315298, - -0.014268436551602834, - 0.1411457011059403, - 0.27444642439990385, - 0.06998760275705615, - -0.022699289728970458 - ], - [ - -0.18058055012760346, - -0.16109254383303032, - 0.03176405508321398, - 0.27302585974265997, - -0.1612232607077366, - 0.04912044793965278, - -0.26154828638123345, - 0.0033611198950265642, - -0.0003373845728385166, - 0.12663636753249863, - 0.06373510714919121, - -0.06396437812828329, - -0.1016165430672765, - -0.11186386977177086, - -0.023932514658210387, - -0.11064026122273662, - -0.019872333639692964, - -0.07129899938231526, - -0.06125224884592774, - -0.1464157268635507, - 0.023807229186757217, - -0.003140052643943332, - 0.18514626991575278, - -0.07396620780691651, - -0.03439967239782682, - -0.027254008633875525, - -0.24793633449646388, - -0.012506320330459425, - 0.22561941818525055, - -0.018299315874268567, - 0.006322870417696276, - 0.0806669996785965, - -0.08157597555553142, - -0.05177473883441035, - 0.10624135714760094, - 0.04372126087636797, - -0.2166145396881884, - 0.24029558947445576, - -0.07934978839515502, - 0.029706996378493195, - -0.15969294454775917, - -0.019324233756928887, - 0.05339223570537967, - -0.07459758451543226, - 0.0827186175076461, - -0.06869830824927534, - 0.038822828544854145, - -0.025876543765383883, - 0.12180331126303066, - 0.22901987013929612, - -0.21404364910986393, - 0.11477324839597856, - -0.014604049574717608, - 0.05119216466114903, - -0.11404400535567216, - -0.01059458912688014, - 0.13427551812335933, - -0.27263146782830244, - 0.16864845131203776, - -0.007168650560851787, - -0.0019238542532726648, - 0.2436084052986262, - -0.10168138112954944, - -0.0413766430096814 - ], - [ - -0.048372043464247, - 0.032790582675737506, - 0.0914606009955681, - 0.026367237445252115, - 0.021046159273622068, - -0.11536917143392773, - 0.2610616891553439, - 0.08238695576691078, - 0.10750562891057641, - 0.004653482048175289, - 0.10517505159132556, - -0.16694696787295005, - 0.045380595627611375, - -0.028472004930948997, - 0.2774189473110874, - 0.21916048979665673, - -0.11802743617303028, - -0.01128739384385464, - 0.1794467420923837, - 0.019369361638117952, - 0.005601506128740379, - -0.07448234617313285, - 0.0005161497960098407, - -0.11577759276189653, - 0.0470323036368427, - -0.2148410962196101, - 0.04632449131467571, - -0.10024214872330751, - 0.17764804140853596, - 0.0505373686209301, - -0.20153960237683058, - -0.030401092353001192, - -0.20824434793102364, - 0.04771706707442479, - 0.09066911892710414, - -0.02472810002227051, - 0.009449932015375346, - 0.0615021021462407, - 0.18338519953718524, - -0.045212687941864595, - -0.1673236645172366, - 0.09708215177269221, - -0.08682476935097352, - -0.15689500566517417, - 0.12541569594407706, - 0.13569664215664176, - 0.09370373397325868, - -0.05336040605221938, - 0.1785901592427133, - -0.08239344840555812, - -0.04595535307176115, - -0.07582633381756641, - -0.390684828480855, - 0.07172139179660798, - -0.13741941134845476, - 0.07804656582681821, - 0.004451390408814329, - 0.06040227126333641, - 0.028813287163085566, - -0.0784442188707555, - 0.2180949826203605, - -0.08649818947343868, - -0.00826758100834789, - 0.11910124770616225 - ], - [ - -0.05889454745820732, - 0.3045698740313212, - -0.10769950345900697, - -0.038849867235348653, - -0.02753687077777779, - -0.0679290691637075, - 0.08562565282119998, - -0.008824155044505316, - -0.06869035983059318, - -0.10312587377291954, - -0.09508856703143684, - -0.06329721803394073, - -0.09001239254617015, - -0.13695894335902556, - -0.14172753118680423, - -0.10663434402622077, - -0.08768642897468627, - 0.0476395083286705, - -0.04072253014934849, - 0.1101104934957133, - -0.07578452990975408, - 0.05424338281922515, - -0.01516926194278053, - 0.09729914705525013, - 0.17481695233888186, - 0.05359421030989049, - -0.09340388826965193, - 0.1047810825385208, - -0.023650234805151646, - -0.27055064485565206, - -0.05246421180358243, - 0.2142134906449286, - -0.0748075666565587, - -0.026263520800550746, - -0.14418586225665778, - 0.02995265076020688, - 0.27572071021379385, - 0.1280509733281088, - 0.04030332202717764, - 0.21562016635411504, - -0.06798298446530282, - -0.08773696362681938, - -0.04894491375923754, - 0.037666500544628584, - -0.060894557019415534, - 0.28111423656264495, - 0.14074492064805894, - 0.06510902040515436, - -0.1250900808144014, - 0.16304042216864081, - -0.055498318501498466, - -0.21578689817027968, - -0.06474888434638805, - 0.10284850898353706, - -0.05235599107074241, - 0.014958697462883834, - 0.052859790555325026, - -0.22475344389085256, - -0.12897893311689504, - 0.17471633402584247, - 0.14966580722031925, - 0.1470073196620215, - 0.04123369260249093, - 0.16213514440375537 - ], - [ - -0.021012717652539516, - 0.1524321581456211, - -0.05837354055691687, - 0.11642433766704656, - -0.14620475744408043, - -0.10770591335925826, - 0.03952720022619847, - -0.09269080304055956, - 0.1469878603300514, - 0.07293509774306836, - -0.1750761352068356, - 0.19516977873074381, - 0.07410663756771818, - 0.10603686458386447, - -0.10754810866007417, - -0.005430141771143652, - -0.11457279262129849, - -0.0559445691242011, - -0.0735084258875558, - 0.05004263002940642, - 0.09545048029494192, - 0.18115310813835953, - -0.2100604116868865, - 0.07073242328836253, - -0.03472431544222694, - -0.024985944121093864, - -0.06589961786934749, - 0.17710316589790984, - 0.03272314052835167, - -5.594461191898498e-05, - 0.06312144768848217, - 0.19671508674533536, - -0.06247885337450139, - -0.18243825328647056, - 0.18528951606590752, - 0.14024853293885928, - -0.061256954792239526, - -0.16899542834587378, - 0.19819815769966476, - -0.15963657747797144, - 0.008451776923022354, - -0.012121661549934994, - -0.04857451153153131, - -0.047726059480096936, - 0.1575658926626216, - -0.10993158985261875, - -0.07049757085112192, - -0.09726496566468139, - 0.06523216845926384, - 0.22291308593862744, - -0.1809927237592173, - 0.04469086254152499, - 0.013673845004988016, - 0.028665086615002933, - -0.03494075665466407, - 0.16289391599556788, - 0.10502585475909511, - 0.03475291131783666, - -0.21254176859126697, - 0.06000539114844462, - 0.010519701780157183, - -0.3798575983143243, - -0.16432396625103346, - -0.037044457251133305 - ], - [ - 0.02178973318547622, - 0.09558620609713296, - -0.25685800959755967, - 0.07290455675261075, - 0.007453715509985587, - -0.2132297530729185, - -0.09613985543346144, - -0.056910525417712056, - 0.01828958879478561, - 0.08573838041408424, - -0.1475640540463952, - -0.009664381041506305, - 0.01532829856001217, - -0.07505119964219889, - 0.22994482863592672, - -0.10467541952141925, - -0.03651049667279836, - 0.014921173582135258, - 0.21283404879266826, - 0.13952578774852878, - -0.0010034803964973293, - -0.036082071877269646, - 0.004259245091128367, - 0.10900215505005979, - -0.044302285897041514, - -0.28666052870928815, - 0.19627416013561713, - -0.1591604412577917, - -0.06633730300437038, - 0.13803143730894846, - 0.0070590775665486764, - -0.13827109063808432, - 0.11529168986111961, - -0.015567764117519704, - 0.19726729897564474, - -0.09527290829973843, - 0.01720333304775962, - -0.07992661394981918, - 0.11751227991960184, - 0.035859135537371294, - 0.2982262844721301, - -0.05487491545762352, - 0.0833522692376364, - -0.0072117955035087495, - 0.014754467175248202, - 0.07016181998059742, - 0.08418929017185134, - 0.03477201248462772, - 0.12125754818859028, - 0.2761554822870909, - 0.06931316204157587, - -0.16204646537304457, - 0.18166071485480606, - -0.02583775329182326, - -0.15746260660203945, - -0.10354683409928173, - -0.023332724264887264, - -0.17363435106657021, - 0.04843655095645047, - -0.0977301426080265, - -0.17143180720271187, - 0.14098843597013258, - -0.07902728101560254, - 0.08181330643016993 - ], - [ - 0.09371708876740188, - -0.023789634817615462, - -0.04836558748718179, - -0.2992245143407191, - 0.13888508680063064, - 0.08008787780597687, - -0.09528207503257669, - -0.08559905279313752, - -0.1752154406144235, - -0.032758115844997236, - -0.2023880550444114, - 0.0852790317757017, - -0.12578024763245707, - -0.06642504790473741, - -0.02475030567840778, - 0.001719697402382362, - -0.06445145746964852, - 0.08396204990977156, - 0.16361775276237478, - -0.06167072895961312, - 0.04188495583721557, - -0.08761787366589945, - -0.11051773836859333, - -0.14521551242264163, - -0.03774608806540006, - -0.10604920787446312, - -0.008942657624526555, - 0.09108135894868348, - 0.08906322730512295, - 0.11068329165321457, - -0.10540503767274018, - -0.07625646209977824, - -0.08265480933771445, - 0.045936953930934804, - 0.029744661925574435, - -0.04208118235499631, - 0.1308499095618614, - 6.250912022344217e-05, - -0.1936511463980147, - 0.042049515667712374, - 0.07542082410721931, - 0.15149374617135425, - 0.20125028555772695, - -0.07931847845339057, - 0.08129131938897736, - -0.24123517639764677, - -0.033372512576411294, - -0.10230091752669752, - -0.33630304766855806, - -0.039318790564424215, - -0.31745591157209185, - -0.03517092683835842, - -0.11373536067039258, - -0.07157307054766693, - -0.32401369978304123, - -0.012291385621334219, - 0.07145531699474235, - -0.13978179558896314, - -0.06828665830175257, - 0.004297731188755611, - 0.07673584451676617, - -0.06913523383624007, - 0.03429564473665734, - -0.11098819748758436 - ], - [ - 0.11810663710578512, - 0.07289971315425846, - 0.058700529715707044, - -0.10870047110736443, - -0.12925617409302903, - 0.007985920733187211, - -0.21046996250972247, - 0.2399652284429452, - 0.08343665463801578, - 0.10231093508031924, - 0.04391569840613163, - 0.2909746453552361, - -0.21473638416432636, - -0.20837898659904405, - -0.11137787938873425, - -0.15224775946780517, - -0.03297879779687776, - -0.04008319934286429, - -0.010887977649181212, - -0.04839844782054286, - -0.03186110171666233, - -0.009549935996815374, - -0.19055952343546909, - -0.094033922662144, - 0.019579930712448502, - -0.12787500220401687, - -0.057332110355291135, - -0.10225663021769628, - 0.18450060767624463, - -0.08826781667623716, - 0.10979614215756946, - 0.05898219504119996, - -0.2851427840738559, - 0.13391306242919068, - -0.09068042619188259, - 0.05729522431973814, - 0.10086872372720822, - 0.10928064523700637, - 0.16927391316870444, - -0.18207214264134977, - 0.23804907907543324, - -0.07956681213814945, - 0.0510033596690415, - -0.08980402155135676, - -0.09196690828727537, - 0.020582787401030936, - 0.07516117750705052, - 0.09827392948002023, - 0.06569979452526074, - -0.1562253058391222, - 0.3044838745140254, - 0.1168716358761386, - -0.06952071078377203, - -0.14628241662732253, - -0.026714788314108045, - 0.006723405577507413, - -0.04908493998208605, - -0.027326131641985753, - -0.04466478413245664, - -0.10985705604869746, - 0.004171633200285848, - -0.022446697469423852, - -0.07770882403905316, - -0.006249947371052947 - ], - [ - -0.259096035048134, - -0.1675305216644219, - -0.040392404605712175, - -0.039677492460057626, - -0.09304155328996042, - -0.14872100558192344, - -0.0435068032599812, - 0.04581715832294495, - 0.15161173426031477, - -0.04696810389800871, - 0.11769527593257581, - -0.012480933504421842, - -0.2558718537018756, - -0.004633330936331199, - -0.29605607978977044, - 0.24192268703350503, - -0.1761227370476799, - -0.002333490636374703, - 0.09227580436302579, - -0.01531679358313504, - 0.1518436525073859, - 0.14883704975220602, - -0.02718877829440791, - 0.0008263784250406534, - -0.025749680713228675, - -0.03618324599920924, - 0.17998400726685101, - 0.13904779693735023, - -0.08306745300398752, - 0.09522097026496354, - 0.19160995157202868, - -0.05141573501132202, - -0.17115623545348416, - 0.03511794634045458, - 0.1535443761150352, - -0.05451924806481121, - 0.0564605152502002, - -0.2225915028674367, - -0.007948371324463438, - 0.11336042258927578, - -0.03716672472052343, - -0.21316773358644545, - 0.020128345833895136, - 0.15744071206871557, - 0.010000301084076268, - 0.1257958838756035, - 0.11810120328747711, - 0.10591289868616596, - -0.09241832194075031, - -0.03326665222704271, - -0.11517215180001293, - 0.06762293571557056, - -0.030845528774318152, - 0.0703372671429621, - 0.01690957927769628, - -0.24091681155070724, - 0.09501191898312032, - 0.056937844091728265, - 0.0907740667374652, - -0.1915934816225855, - 0.03891495649168667, - 0.02646049641025838, - 0.18059143393518734, - -0.04035471018536453 - ], - [ - 0.07546603449165762, - 0.19610516371395975, - 0.0696473669479123, - -0.1388816578588798, - 0.08911434260959923, - 0.2335921575452632, - -0.19175021935440145, - -0.03512708766068057, - 0.37983140857092984, - -0.12346404083896355, - 0.02236637372885265, - -0.058344114463947945, - 0.02502962976781609, - -0.00846798245856773, - -0.10649312705158047, - -0.07785636387062154, - -0.07607292838956713, - -0.11514904841729183, - -0.06192675004280196, - 0.08227839920910898, - 0.09506027064986855, - -0.14084137026414384, - -0.09956978252095745, - -0.010033134440578146, - 0.04480000809725266, - 0.05818479127052318, - 0.0262266001508206, - -0.16839798781827853, - 0.009302300857508296, - -0.03560992692846847, - -0.22694493818195371, - -0.2205641009258906, - 0.13531855284152125, - 0.02487451811085299, - 0.10958543162939209, - -0.08116857415741303, - -0.23059227318428654, - -0.052560277545642665, - -0.07409933477730223, - -0.07574274297978272, - 0.07113307988281282, - 0.02866809507899454, - -0.006405876637874234, - -0.09450820134276353, - -0.04160225987680175, - 0.26268369045012985, - 0.03824646548306302, - 0.09719861199087501, - -0.03642599770153038, - 0.016005127782026868, - -0.07348062580906409, - 0.15854994182541618, - 0.13599190025118205, - 0.143396464787999, - 0.022660335545788, - 0.09536943097841608, - 0.3389698615791954, - -0.03127709619328063, - -0.08427951297907203, - -0.03803407559777518, - 0.1727710292632344, - -0.004281600523706182, - 0.08241370736595495, - 0.046184375769111934 - ], - [ - -0.08607928688374862, - 0.07720124934222075, - 0.17177818069136847, - -0.042488368831593515, - 0.0007254046727111108, - 0.0510996735116494, - -0.13228738900822187, - -0.26526819957430303, - 0.08690062316937841, - -0.0763534248121775, - 0.07986878062178077, - 0.09655603585426978, - -0.091615091295029, - 0.19578457306329153, - -0.1730163222509535, - -0.07276814341875601, - 0.10634964260140811, - -0.0008464833599168861, - 0.29799640939309585, - 0.03511799344762751, - -0.22486454751798468, - -0.041379721952069855, - -0.13001464291346804, - -0.19502234393650023, - -0.13085486447121478, - 0.020768988878952944, - -0.17089241951964954, - 0.06764869776768634, - -0.17154685916211107, - 0.12657250474057216, - -0.12806261109964928, - 0.025450715055243257, - -0.11735417406378197, - -0.06116840982764084, - 0.1551447758763014, - -0.0020815955513018357, - 0.11087542258947584, - 0.05854007577686361, - 0.13541276649986478, - 0.07482646341717614, - -0.11319060262329149, - 0.12765289109600383, - -0.23047235069648012, - 0.06129515236407662, - -0.016874960110071325, - -0.16021478255566104, - -0.0031706594003514557, - 0.058831062218724216, - 0.004056597294022492, - 0.0483494771554961, - 0.24625756453771874, - -0.1884573225350426, - 0.02752473517785972, - 0.08538962925225892, - -0.08621583340371365, - 0.0767966926890788, - 0.15208611445851386, - 0.13496922366990144, - 0.16501481671998705, - 0.009261464574374836, - -0.13379898484977684, - 0.13782322317316822, - -0.036049289859921264, - 0.08947386902622852 - ], - [ - 0.04356962625859566, - -0.11753512462325715, - -0.061459227441131956, - -0.125368170136908, - -0.18862387309123568, - 0.3921101963358271, - 0.027624122908676083, - -0.05519276372296199, - -0.03907795415783131, - -0.02104699854176011, - -0.1927182853498243, - -0.04323923173449203, - 0.03526894868073184, - -0.056149251227148846, - -0.10784094010528127, - 0.2020565966939215, - -0.13304900548906667, - -0.009067544206364507, - -0.04916656461863683, - 0.014123106573085508, - 0.0935831580318278, - -0.11348874965730343, - 0.15177164171554924, - -0.08882996879947579, - -0.22025174277895535, - -0.15462582893838817, - 0.1327818438158844, - -0.041546711749102, - 0.03201485359264338, - 0.0008919568116088724, - 0.1303253450028372, - 0.3158427032654552, - 0.043885709645010165, - 0.035132276653254114, - 0.13098788989591728, - -0.22368874842798026, - -0.017936070831586916, - 0.14476655789826837, - 0.21425761354512404, - 0.10989697323215704, - -0.009705679022766063, - 0.05334188313100625, - -0.11951093844554789, - -0.009436471152343287, - -0.04421317858444571, - 0.05752568159593467, - 0.024161706485678832, - -0.01561436644946492, - 0.17113774725035663, - -0.12007422342290744, - 0.0013064802409994952, - -0.19325842765706225, - 0.24125696420114262, - -0.16777246766175796, - -0.005155231116715454, - 0.0558394259125952, - 0.02160764717103354, - 0.015210235234118354, - -0.06360634563021952, - 0.10857290074841058, - 0.11492155558500272, - 0.0060044633622786565, - 0.0652772831692254, - -0.11705703244244482 - ], - [ - 0.08255861383938728, - 0.12804756475431894, - -0.0008669223706115307, - 0.12840901335182137, - -0.06707420736449414, - -0.09167435696805339, - -0.1020812609416642, - -0.03594630908624585, - 0.05432564792541198, - 0.02231846780663402, - 0.06655653549533956, - -0.067378104174798, - -0.0989002160016829, - 0.13254120783329093, - -0.03262505598195103, - -0.1332826250529219, - 0.08044980726998537, - -0.15742117520120574, - -0.1800949625899432, - 0.3023546605813699, - -0.20663662861131327, - 0.12461245433734648, - 0.06729314337316435, - 0.020346122829997537, - -0.16815137746796435, - -0.21512654880817825, - 0.013673287614090177, - 0.09620452954431404, - -0.041200111551488235, - 0.07916049874819443, - -0.10283999158777113, - -0.08174846313960846, - -0.09550246947187295, - 0.15679339529013922, - 0.11848240185242767, - -0.10024336881699765, - 0.1088221062967745, - 0.1261292966497414, - -0.17915126017110053, - 0.1281181700364011, - -0.08856935824003499, - -0.04876134884139747, - 0.03079679852712839, - 0.0955736686802073, - 0.17283033954884675, - 0.1088238467783804, - -0.16262402783529295, - -0.07661011527311122, - 0.010428536834723995, - -0.06660692317916105, - -0.11275261817885636, - 0.1884147801310365, - 0.036965126706959485, - -0.39880545707105336, - -0.037936447489980527, - 0.07199300283006907, - -0.1471309739720833, - 0.17266926741771163, - -0.11975542042688588, - 0.012009845635519335, - 0.14207828326593241, - 0.05236447290052477, - 0.060742969813612, - 0.09406039858367703 - ], - [ - -0.1482356672421933, - -0.08024485268047626, - -0.08625751699142206, - -0.15239046592397026, - -0.1295140169556763, - -0.059358619639814265, - 0.11318233522249352, - -0.16270806517784805, - 0.1645199453899031, - -0.15182020319701167, - -0.06424309812622966, - -0.19912828774830127, - -0.009306979470953044, - 0.07398656638646407, - -0.06429297874634986, - -0.17454716121291744, - 0.13933296255674216, - -0.023309866009809638, - -0.2994972296361165, - 0.032338554656147725, - 0.038093663719831736, - -0.047261103480772226, - -0.01334043405949634, - -0.029253719856217025, - -0.05890796880007829, - -0.23851468148825855, - 0.10306358785027454, - -0.13043489301191338, - 0.14908859196723073, - -0.20498584095215935, - -0.14483908545776855, - -0.09299734731289991, - -0.23322872435475864, - -0.22814945757030317, - -0.021953829207254177, - -0.0760672956909778, - -0.009944338793978186, - 0.022070106708829643, - 0.00218772751821479, - -0.2857393880878354, - 0.032415760020128526, - -0.013551015784685403, - -0.08327255934192614, - -0.014199425070254356, - 0.02533788989189469, - -0.15041811029311786, - 0.10497506514901375, - -0.09690382718315274, - -0.24319795698087598, - 0.07845090859507206, - 0.03312836202183885, - -0.14783238780570812, - -0.025419569093216562, - -0.024065691118522376, - 0.17970400525163976, - -0.15437066158080526, - -0.1131900278572801, - 0.022909672237315378, - 0.13109811972301377, - 0.07039810411237556, - -0.07535150285678639, - 0.033552472529957494, - 0.05139644647409638, - -0.11167096768019644 - ], - [ - 0.1380999907373963, - 0.01954175689106579, - -0.027432601885595095, - 0.10113099967650047, - 0.06980201824629913, - -0.19186578682286293, - -0.012508206896521963, - 0.10946410548351786, - 0.03540929474944114, - -0.09761693164492537, - -0.06632767580250876, - 0.05090785135587962, - 0.1783804976076968, - 0.013280133179188485, - -0.13563275272861225, - 0.11255207800243315, - 0.10447753919826058, - -0.017019584677779278, - -0.0601539980206177, - -0.15978165578542403, - 0.035515085680596116, - -0.07066835546774153, - -0.15377551077533957, - 0.01760118981909198, - 0.07392962173786957, - -0.22614290040612936, - -0.025837441229932274, - -0.06542826077073186, - -0.20375372827467114, - 0.15849212047470762, - -0.0695432029629865, - 0.24315697409439851, - -0.154012486539623, - 0.032537365742845666, - 0.0014777368553622822, - -0.01142771487517186, - 0.0363739863303267, - 0.04227234765410753, - 0.003384692073920321, - 0.13097314750695546, - -0.0058392188016296006, - 0.19147218930557755, - -0.03658629614047089, - -0.32521644091420554, - -0.34379617574777843, - 0.0542289577677594, - -0.2414141506801373, - -0.10286830603076666, - -0.008782056247861419, - 0.19996627983252852, - -0.0697727978987074, - 0.19158817111765833, - -0.0011405646447293504, - 0.00847335960981503, - 0.13694902283354246, - -0.1446343147333531, - 0.0036791434545461006, - 0.01133223928139053, - 0.10522976259932328, - -0.000848334160188107, - 0.014964642337229786, - 0.10594432054447564, - 0.20647652917577036, - -0.08076830180315034 - ], - [ - 0.04838554063384971, - -0.2557946914430658, - 0.14257004396347225, - -0.03987946644952498, - 0.04568046662682602, - -0.0070839533253020635, - -0.1475135409635685, - -0.23797249146196617, - 0.29971910509789496, - -0.02779397662842422, - -0.07624752222820466, - 0.13118972672678242, - -0.12552989483109891, - 0.22677449253014087, - 0.13955290535085396, - 0.010785506469665184, - -0.14690833312381393, - 0.21013024731343016, - -0.2564667961811231, - 0.1755803292472867, - 0.13554018433964574, - -0.024115346493745058, - 0.026332640085042873, - -0.009260085655552613, - 0.2562831421094523, - 0.07408014388466971, - -0.0864585662072987, - 0.0012086701415019796, - 0.09117556196441329, - -0.07397895858527383, - -0.028390223711104424, - 0.14896947106527192, - 0.04391360811908577, - 0.07133850287277586, - 0.011495437026924482, - -0.09281236523376464, - 0.1952952127478575, - 0.008345543502908233, - -0.09080058159945091, - 0.12228506062823918, - 0.1670762092689446, - 0.021988564097471016, - 0.02632039720494631, - 0.029206217903670825, - -0.07402593724115893, - 0.016176861151754398, - -0.14212849731289307, - -0.15974557583951107, - 0.2156199102909378, - -0.030099796469581035, - -0.007165678023410485, - -0.05850216741731024, - -0.05323348274096518, - 0.16856766882970467, - -0.12417573709832376, - -0.09663520064624401, - -0.1885090716939502, - 0.0005962337089387301, - 0.08112118010681568, - -0.081938912801404, - -0.015931204682000124, - -0.020437552866021533, - -0.05014534317397, - 0.12002349220616078 - ], - [ - -0.07180986875888996, - -0.08524790393733513, - -0.11502698757958342, - 0.0713847900824951, - -0.027054356445577615, - -0.14129546110506547, - -0.17668868032257237, - 0.10103501417146218, - -0.2135149928719994, - 0.09661430594000343, - -0.2677362816409533, - 0.0840105844718808, - -0.12374208214924046, - 0.10617593568706139, - 0.0422224801258176, - 0.3200196779866334, - 0.2866459318765741, - -0.001318006532101977, - -0.0859299714571873, - 0.2954906190573947, - 0.033800232069549324, - -0.05893770215927403, - -0.07079425249610524, - -0.021703749593344583, - -0.11065069939330961, - 0.0816871717270343, - 0.042478976830153836, - -0.13678380829491882, - -0.052070062982862354, - -0.22760017503114618, - -0.19474803327039172, - 0.0448072974356168, - -0.10307464836125159, - -0.021099666833201712, - -0.19364875434857104, - -0.04638090376129075, - -0.12373920152812846, - -0.057304419665391404, - 0.003093236892160212, - -0.05884355743390073, - 0.046206092048288364, - 0.032165370791642854, - -0.09210043042204998, - 0.1298413348877597, - -0.11143004084936492, - -0.10115694414290373, - 0.09185969782486111, - 0.0991792958705369, - 0.1319426636837241, - -0.05658476046962008, - -0.12766631779815177, - 0.04892130237371509, - -0.08380075412057125, - 0.0394072114468791, - -0.07519286681736972, - 0.15815386382184857, - 0.2116955944136771, - 0.051944433239048675, - -0.06754274523942722, - -0.09641156248074198, - -0.06818702796076681, - 0.08194789306740721, - 0.1380310544843864, - 0.0963450995280186 - ], - [ - -0.10582713333852847, - -0.06552667139101068, - 0.020327497343381625, - -0.0630708958211118, - 0.27828304693496553, - 0.012361578661408117, - -0.07678384515761974, - -0.020040583305649156, - 0.07881937013720912, - 0.418111217524409, - 0.0653458428924835, - 0.07525170796474201, - -0.0392387021178709, - -0.10936582498629127, - -0.05156972811615599, - 0.11031898494228394, - -0.15642569600540698, - 0.0914907027598381, - -0.05066717591240553, - -0.017310411758528845, - -0.2761605312024916, - 0.08955000773370489, - 0.21381140106233718, - 0.06781500376544526, - 0.26546813832837246, - -0.07712802172258555, - 0.05109527028990456, - -0.08074527398799844, - -0.18832144704102266, - 0.06156682286678409, - 0.08091067381414223, - -0.08447780670407154, - -0.15427950126259907, - -0.1807815974982791, - -0.012252978467969097, - -0.09902420327548923, - -0.11827030810780098, - 0.081265183059198, - 0.03751638491584628, - -0.05902869794902739, - 0.08884941757262674, - -0.08462455503487447, - -0.0949683068213787, - -0.050951846605939356, - -0.0644938754734739, - -0.1050705183079376, - 0.08618268396504057, - -0.27986394852676033, - -0.10967642080183668, - 0.02798979048178616, - 0.00739497561821723, - -0.021580320646369618, - 0.07108801273300686, - -0.0020263906160134194, - 0.010883349727931499, - 0.22067423214238877, - 0.03045384202177245, - 0.07643220151065276, - -0.07549998403693517, - 0.1784292887488788, - 0.07229960652064298, - 0.012471226957079183, - 0.1594407868539757, - 0.07921071092529887 - ], - [ - -0.01271478584393851, - -0.024289716623420422, - 0.1376658581711914, - 0.008158905702358719, - 0.18583750856242073, - 0.03434577653003939, - 0.010093473264001035, - 0.01983285029973847, - 0.0930148817263316, - -0.1693441242235627, - 0.25261606025164207, - 0.009394435379033759, - -0.0578789450115241, - -0.336617771241084, - 0.029300385564705225, - 0.15786067167003975, - 0.028260856372840523, - 0.1145109681292399, - -0.09231351410408317, - 0.1925743434483437, - 0.08013394353581588, - -0.3313000755273504, - -0.01789389130993361, - 0.18792516173368506, - -0.03916006465804521, - 0.0699627045967876, - 0.03282049561281365, - 0.1227729950123303, - 0.02397701321998437, - 0.0376262577607344, - -0.01896539939200698, - 0.1253806670814884, - -0.14363949237294893, - 0.1357616801195561, - 0.01556771652774208, - 0.0632614070471255, - -0.216301008173598, - 0.002403863799272283, - 0.04927112051312896, - 0.05677127012392207, - 0.11752881333542302, - 0.04743808583095127, - -0.10613003886721073, - 0.1042330930294733, - 0.1823109114230446, - -0.07536727005697202, - -0.07495416832048829, - 0.08500953507334885, - -0.06921209100173355, - 0.27402903036518017, - 0.021466869786184, - -0.015193166520972507, - -0.07701050577361049, - -0.13983743981322666, - -0.08112612023061562, - -0.10658835803016004, - -0.033808455983744934, - 0.10176997816985711, - -0.17841108365365402, - 0.18794959209149215, - -0.23764996796222226, - 0.041846850660555795, - -0.02713087659760899, - -0.032191502606733785 - ], - [ - 0.19994375055754482, - 0.11400173970799511, - 0.055569366811171535, - -0.036194597990358714, - 0.045270493836385, - -0.12898335536245595, - -0.08469800388023489, - 0.14804896663614325, - 0.13474073755692717, - -0.1678239215472148, - 0.12806685485198815, - -0.01611162738924468, - -0.04746276697324632, - 0.055569766980803695, - 0.0019841813230777557, - 0.13993981621653323, - 0.19072153959607813, - -0.22479021434419444, - -0.1681645640993794, - -0.06508367171927018, - 0.011384625386310883, - 0.033348168666418605, - 0.17814809081503533, - -0.32627643330896444, - -0.024511766523443532, - -0.04101794402518113, - -0.020899525434544555, - 0.02294912251699681, - 0.0010423801431719312, - 0.1631037250496032, - 0.16968780118266777, - 0.04927930042170401, - 0.09459154239752295, - -0.27294675798116136, - -0.2518966346567761, - -0.1664720133831117, - -0.06237047562896936, - 0.08099820690677081, - 0.12162157095417256, - 0.16248814102858739, - 0.056215324827062416, - -0.027665959950100558, - 0.025413338034249777, - 0.04912751554369095, - 0.11095856094662766, - 0.020082929309279778, - 0.06801751110061152, - -0.02310701235411194, - -0.147622030976502, - 0.12639972520429052, - -0.007175614440779052, - -0.11664957934510227, - 0.0248654525387874, - 0.1722305558230379, - -0.15439479989038266, - 0.12417429811368172, - -0.13369417021653215, - -0.027867019545240672, - -0.1495563318453405, - -0.2541265709415513, - -0.04669330418117657, - -0.05252660424284008, - -0.03496393616524173, - -0.056292874986826905 - ], - [ - -0.12002450238262027, - -0.04784280267218349, - -0.06025233437867108, - 0.06938846173629795, - 0.15078051043479826, - 0.17939201424118623, - 0.00888210044975665, - 0.15774368017358018, - 0.1582146038112864, - -0.016970183380315303, - -0.159944547000939, - -0.10684451881858288, - 0.0017680152900696518, - -0.1296968020486259, - -0.1744262131189506, - 0.05286215736939847, - -0.04100012582251297, - 0.020102450095339255, - 0.21093226246641564, - 0.01774154171139087, - -0.01832855019408648, - 0.12787762409533004, - -0.002367744097338606, - -0.09353145025659276, - -0.15991683140283633, - -0.02211038041316264, - -0.2760671937305568, - -0.13372874448741734, - 0.02217324831157735, - -0.1479233257183289, - -0.001303401098956596, - 0.045957411010370056, - 0.11592883609449903, - -0.07235995048100037, - -0.07228918899659749, - 0.06736854946799249, - 0.043365328120026095, - -0.09344276935483474, - -0.12909959429004458, - -0.18413898245349408, - 0.008452868557283607, - -0.010557143633271756, - 0.2231949953703374, - 0.06480658223947199, - 0.04840631959377342, - 0.2568815908158009, - -0.23500553363083457, - -0.23317800686837126, - 0.05969395934490629, - 0.15718297449779484, - 0.07268660398404997, - -0.18506996015874116, - -0.14836136007645326, - -0.11031267613260126, - -0.05816144018715016, - 0.06317717836846061, - -0.07592041704364456, - 0.1917083396098519, - -0.010301933784593108, - -0.1013746533224832, - -0.20951097406529956, - 0.028750673620622894, - 0.18939338149628554, - -0.03219863348099085 - ] - ] - }, - { - "layer": 3, - "rows": 24, - "ridge": 2.175195058186849, - "mean": [ - 0.13149426877498627, - -3.47220778465271, - 1.4111372232437134, - 0.1835823506116867, - 2.2712533473968506, - 1.5130157470703125, - 2.014540433883667, - -5.129347324371338, - -3.847414016723633, - -1.0859559774398804, - 0.9908657670021057, - -1.627123475074768, - -1.9237571954727173, - -1.2273889780044556, - -1.1911959648132324, - -2.326306104660034, - -4.107001304626465, - -3.971018075942993, - -2.742879867553711, - 1.1118019819259644, - 3.1695632934570312, - -3.1528480052948, - -2.963531732559204, - 4.912052631378174, - -2.3824665546417236, - 2.3388357162475586, - -2.6581690311431885, - 2.6808929443359375, - 4.062721252441406, - -4.560726642608643, - -1.7835108041763306, - 1.7452951669692993, - -4.324201583862305, - 5.027815341949463, - -1.0381065607070923, - -2.460010290145874, - 4.924392223358154, - -2.326460123062134, - -2.4950106143951416, - -0.7466246485710144, - 0.9485407471656799, - -2.3539669513702393, - -1.090201497077942, - -2.8974578380584717, - 2.460238218307495, - 0.3086046278476715, - -2.167100191116333, - 1.060240626335144, - -3.4180898666381836, - 3.855664014816284, - 1.0488871335983276, - -0.46984362602233887, - -0.34808459877967834, - -0.9215118885040283, - 2.2922539710998535, - -2.963176727294922, - 6.597923755645752, - -1.2433661222457886, - 0.14441511034965515, - 3.983675241470337, - -3.2439157962799072, - 4.510650157928467, - 3.636657953262329, - -3.083115816116333 - ], - "eigenvalues": [ - 41.95935453357332, - 26.27722519228689, - 17.172557570149817, - 12.96523746758159, - 10.818675543275683, - 5.7288501491934225, - 5.164192264242348, - 4.525760420240944, - 3.5033934963983424, - 2.7437727984851925, - 1.9010638067969312, - 1.6380074160230818, - 1.2979382433579971, - 1.136380199890377, - 0.8549476988860212, - 0.5646949571639567, - 0.3192251956212426, - 0.18546477956658924, - 0.14122980517981867, - 0.11172350687115623, - 0.08423072658582942, - 0.0613418934012838, - 0.057225703656780785 - ], - "basis": [ - [ - 0.11238513734387828, - -0.02192382269536083, - 0.06534290258700526, - 0.2663968945618588, - 0.03204277712276435, - 0.07772758454723125, - -0.169576070066605, - 0.20167732066826036, - -0.04045636768644415, - -0.0856763715335305, - -0.12503762500426363, - 0.1103751926522752, - -0.0262723218754611, - -0.044907919949735337, - -0.08223179279226181, - 0.1457653300764889, - 0.058793354686608006, - 0.0001432649869586176, - 0.09476037658948708, - -0.05919029943344437, - -0.054906512780544744, - -0.06732065217678386, - 0.15716531553206256, - 0.02661291836675584, - 0.01145030014400166, - -0.239927193282269, - -0.02198450984531535, - 0.042118268687330734, - -0.181936602973185, - -0.012830295191270808, - -0.29558875657062594, - -0.04460584256907582, - 0.18641215362437605, - 0.01581707393863118, - 0.17140483779124296, - -0.1277186768438997, - 0.1895536206732935, - 0.13552051977157156, - 0.33677784934557053, - -0.12757152215850817, - -0.15282498774881398, - -0.08559570644557173, - 0.11371713454425637, - 0.09441515759179944, - -0.039406843326687375, - -0.05618994061778706, - 0.09779415305466817, - 0.07183852837917562, - -0.09477850553294087, - 0.03375085984075654, - -0.0623867813353196, - -0.10491604933167019, - 0.11411045233619449, - 0.042436058983721665, - -0.023416824711136906, - -0.24610775027961881, - -0.03537901974461663, - -0.0473684156819656, - 0.006712344358659402, - -0.01228997491038765, - 0.04978536938980265, - -0.17051935421476286, - -0.2162343207940752, - 0.128672504234488 - ], - [ - 0.235887360569978, - -0.08277094923432098, - -0.23542685486195752, - 0.036343615484704675, - -0.06538248991297516, - 0.16305528410187248, - 0.03165702504605695, - -0.1742093690195191, - 0.03985265796288725, - 0.14713688890492865, - 0.31227515127661815, - 0.005201837029460188, - 0.03044440221562863, - -0.0033587597793426167, - -0.14348313140720714, - 0.04285322568432289, - 0.06204385782831993, - -0.10699400667186106, - 0.20371542586571345, - -0.15547344309885014, - -0.016497719932280736, - -0.018786907908185452, - -0.012100088613338625, - 0.050976163700003026, - -0.0038707077873575482, - 0.18294155808146745, - 0.11957964899402973, - -0.12303573502511178, - 0.16252714347232247, - 0.12174292160806492, - -0.11497799770084594, - -0.03012504304430004, - -0.1769485551921236, - -0.3088843289226811, - -0.1536708800164369, - -0.12335162495367531, - 0.17799649940517048, - 0.0360097632078032, - 0.14339718948291152, - -0.12062098883103237, - 0.1330006145839993, - 0.016819373634298765, - -0.03581966241794986, - 0.013514612998359772, - 0.05434639463178523, - 0.02681215727853688, - -0.09645081154626098, - 0.008946074521368703, - 0.13603151125392957, - 0.08658161096937286, - -0.12273866111353018, - -0.024511728582391777, - -0.12424206768147703, - -0.0022509665996954535, - 0.23006330227700497, - -0.1196940480919725, - 0.0667826418902004, - 0.010495971877280085, - -0.06911609342276423, - -0.04618483302324765, - 0.02515866740809822, - -0.0035577308843028612, - 0.01572465562316811, - 0.2625064205550599 - ], - [ - 0.03462652317824434, - 0.11825269654419901, - 0.15541526815262438, - -0.21039521734433278, - 0.15444553267376968, - -0.05026956433214088, - -0.15080369162895524, - 0.27065432634511977, - -0.11343768918480075, - -0.08368031917732593, - 0.010836057322685192, - 0.08370074243719636, - 0.043212931624994934, - -0.17411994565909217, - 0.32143390711906145, - -0.019463897756180834, - 0.025471209670118674, - -0.10421635138456593, - 0.057396136674235564, - 0.012182275834921413, - 0.16975259222458933, - -0.11483408148330698, - -0.10313874483571676, - 0.03254508371767167, - -0.08092590538438822, - 0.05331501222340927, - -0.005634114576216909, - 0.11308512154029056, - -0.04403765424611049, - -0.052261698759668726, - 0.08268430814567816, - 0.07617284484007171, - -0.019175312303144173, - -0.23075424807579611, - -0.0024400322905331773, - -0.014626371247008663, - 0.2396958673097552, - -0.00523343118363302, - -0.006079101263996696, - -0.12156448265070613, - 0.005170363868432029, - -0.13048600338146546, - 0.14962052358500344, - -0.09663177769664738, - 0.24386539547798472, - 0.003924124880600964, - -0.12168492844825073, - 0.08580271076629006, - 0.053956385407939934, - -0.012377208034422549, - -0.03588156578101969, - -0.025312501288743194, - 0.11171485872312215, - 0.1319637544586918, - 0.10053784153429378, - -0.14564893130314194, - 0.07610054095118518, - 0.2579913455602912, - 0.04024864297642946, - 0.04614245630232623, - 0.1567964517960093, - 0.19727401434607136, - 0.23514857673732734, - -0.0728080258625308 - ], - [ - 0.12473719703389154, - 0.00179992210464064, - -0.08694383097045853, - -0.22048165594644178, - 0.14892139889005715, - -0.12274815420690628, - 0.015703407346633263, - 0.02433896540422136, - -0.07530696430522926, - -0.20197491739056672, - -0.10427478672093182, - 0.06218883424085052, - 0.11443504706541234, - 0.22200176528356233, - -0.10068654335251986, - 0.04001113588191329, - 0.05774105930679897, - 0.054848483452354255, - -0.017559043435133273, - 0.08526262233415732, - 0.011463601121725784, - 0.030237717116144903, - -0.09022212950495499, - 0.08736735675926759, - 0.014496448820034376, - -0.042219059807186446, - 0.19818666549638844, - -0.06209251471553759, - -0.1979872578519568, - 0.08588708326760078, - 0.040145155566274196, - -0.13836486369039655, - 0.0720141219021116, - 0.0731371832028108, - -0.15607871818162025, - -0.08687235498573777, - 0.15305682727281594, - -0.25168993238994963, - 0.07998446888980021, - 0.0660702037096409, - 0.23683126609656557, - 0.055523148043072415, - -0.11909965685536648, - 0.09562401661750754, - -0.12397445670707034, - 0.016092183418342267, - -0.07617541742828843, - 0.04280056320636249, - -0.11396818420928677, - -0.17216125123040504, - 0.23058799599965096, - -0.08551019863663241, - 0.01677797040718063, - -0.05522797147100118, - 0.14809998410252503, - -0.04541504231253702, - -0.18186427201193278, - 0.2673425899768454, - -0.12818626332481736, - -0.06302403533770712, - -0.028537373745982666, - -0.31126054350894, - 0.11179236049611259, - 0.018248910937473665 - ], - [ - -0.009665474885762977, - 0.2885946716036151, - 0.08409011740788734, - -0.019098792200111497, - 0.013271486512947444, - -0.06720312594193185, - 0.338769426585249, - -0.049684755301944016, - 0.12220733418602457, - 0.0484033212464082, - 0.0306776766184294, - -0.13440464778411593, - 0.06063745130159754, - -0.06563557491939398, - 0.14818352631931678, - 0.2721731720015119, - -0.16683327652652882, - 0.06813170037791211, - 0.03684966823203909, - 0.16795500485044867, - -0.008323015363121005, - -0.05998135390940186, - -0.05010982862346563, - -0.07951026145730407, - 0.12509290040407794, - -0.04536898900526941, - 0.007911141317208582, - 0.13288649759671117, - 0.042568700771598106, - -0.1524206615070949, - -0.13921094683406873, - -0.002259166683793134, - -0.15503703876448488, - 0.01567242698166654, - 0.03271758686334649, - 0.053275203427780346, - 0.15814508743551242, - 0.00703042893006101, - 0.1649222882750662, - -0.012240724671443414, - -0.11942512036021911, - 0.03857755262766051, - -0.040981287581868024, - -0.07422102146380721, - -0.06344554115328782, - 0.18255065204063406, - 0.15718774449700795, - -0.05191091317224253, - -0.06635082764769813, - -0.10129990534124506, - 0.07877105578605927, - -0.15850018295882437, - -0.37680700770656966, - 0.09256178906016375, - -0.03713830030914098, - 0.08333619004530386, - -0.021067632891692074, - -0.007977678329454119, - -0.05421194179958765, - 0.04312148663624568, - 0.2819590560950692, - -0.08856407538970038, - 0.09644396274225715, - 0.13207961069384025 - ], - [ - -0.008749570171065884, - 0.13175199314368635, - -0.08637791760169278, - -0.04308897109762828, - 0.0494845301454331, - 0.12229178771418298, - -0.019954833573594042, - -0.12249025666469465, - -0.23627933325908948, - -0.015627737408870936, - -0.13699532653315533, - -0.005755022272886653, - -0.1267912472993425, - -0.07689816959395689, - -0.21208118719184296, - -0.10531725504209626, - -0.10094645530239613, - 0.0936338962395677, - -0.11788311702139938, - 0.096753031340189, - -0.08187754921955631, - 0.0636295552609907, - 0.07587864845153122, - 0.14967168370432007, - 0.1485164701878442, - 0.18331553665215108, - 0.020737694863227896, - 0.1795454106788262, - -0.11701771886795172, - -0.16796668977410553, - 0.037249309347252624, - 0.12100707283741698, - 0.01788228196623801, - -0.07836667197539805, - -0.2515578618400812, - 0.013319772333060345, - 0.2551371028559856, - 0.1292174475198026, - -0.023948831913331105, - 0.20711116768176552, - 0.024639848550752696, - -0.142869934562563, - 0.003996199929797203, - 0.2165464866043782, - -0.192074760400535, - 0.1270140757437467, - 0.03844501364459408, - 0.006581141201169671, - -0.18973008173927566, - 0.13582052933324032, - -0.025887837020196623, - -0.13721753117231064, - 0.11157318722084282, - 0.07058913575992609, - 0.10954857844713868, - -0.017534084614702267, - -0.0072556352458071766, - -0.20173324307107862, - 0.02750967881527192, - 0.1676656556556386, - -0.02000887587932498, - 0.25091406949521483, - 0.07318539590184363, - 0.021154159885264322 - ], - [ - -0.024679810886105095, - -0.2527467923671954, - 0.051340482533593766, - -0.08389064976860289, - 0.10295553305610276, - 0.09203631879438198, - 0.013486129379480955, - -0.04716396320622473, - -0.170222525044075, - -0.1685025947434956, - 0.14294263464011006, - -0.19792739611096238, - -0.056824122373989004, - -0.11099171195654645, - 0.113807372472145, - 0.14981895090579023, - 0.08284853068989051, - 0.06997078077159238, - 0.12910635215339744, - -0.14722956011304406, - -0.06731356363533696, - -0.19283255420118284, - 0.2675199962947871, - -0.08449299755468816, - -0.027726031425664394, - 0.025764641953797993, - 0.10412638638534887, - -0.10803044739619234, - 0.0845637848226994, - -0.02774435639266901, - -0.11298576739047783, - -0.2837278585842249, - 0.036657712912753, - 0.243048043876637, - 0.0016762149965997189, - -0.2558413757776941, - 0.05801207567975246, - 0.0236795648417133, - -0.20082630309062235, - 0.24300380274548491, - -0.07360789954119391, - 0.1398141589039987, - 0.027439383342513758, - 0.02516736910832435, - -0.0164671773798431, - 0.054226320360520164, - -0.06959369444293526, - 0.016844423449126532, - -0.06818003510071162, - -0.21261084661281635, - -0.09892416409946322, - -0.09729834434870374, - -0.029402529156304685, - 0.023576118394364923, - -0.08718093734000608, - -0.04236017405999196, - -0.07810271736770492, - -0.023437270128530023, - 0.09487764356000798, - -0.03298449386201282, - 0.034355909390504, - 0.2260691820163482, - 0.16559488213903048, - 0.0231448044041216 - ], - [ - -0.0660384586397833, - 0.027991983672192945, - -0.2655957704847338, - -0.015210015230731025, - 0.06066427207495537, - -0.36954479770968784, - -0.015432116006850587, - -0.14150195941033136, - -0.0455217849491915, - 0.1297079480937342, - -0.05347062793364377, - -0.05225079509354166, - -0.11523478405592935, - -0.06475856182178967, - 0.17340952017552405, - -0.08697378266521354, - -0.08214167985114819, - -0.02253831255570792, - 0.19699254468359245, - 0.28403427547882276, - -0.07685432913801699, - 0.046003348659681094, - -0.04835299309152403, - 0.02295879450118224, - -0.04620822769041163, - -0.1837508671110179, - 0.2174721263095498, - -0.10458684784660822, - -0.11380747029610788, - 0.1345351960416475, - -0.04720315882824974, - -0.10195208148405675, - 0.039229434891461044, - -0.03952208860399568, - 0.12821282896464758, - -0.02514004785892233, - 0.13328818812075732, - -0.16882087776486787, - 0.06756075300780447, - 0.011090716509998507, - 0.213073854233591, - 0.005803600099745008, - 0.08139333931187673, - -0.137576084276014, - 0.04335112369519854, - 0.046715975206465275, - 0.09155805822376879, - 0.04089981407873765, - 0.018012667841747872, - 0.18251489848947375, - -0.15914787353610954, - -0.08046188198742718, - 0.08325195014228055, - 0.0532149294933216, - -0.28017455904853894, - 0.03270325689702661, - -0.007249242041270044, - -0.12038619741338236, - 0.059458646022327144, - -0.0431978137124879, - -0.16673054995428988, - 0.1784380440324256, - -0.01741685038663869, - 0.13291826203216975 - ], - [ - 0.11013192045013812, - 0.03687930879414288, - -0.02189712280338299, - -0.18487528471770512, - 0.035962686951773716, - 0.08212377213363854, - -0.08778999605664799, - -0.12277142115647685, - -0.2145811996176565, - 0.004577969337888002, - -0.32261062594272394, - 0.08525450191291611, - -0.018158793009970687, - 0.00010290052868414763, - -0.10246222136654139, - -0.018856327787815787, - -0.14152314397972868, - 0.09564107526142572, - 0.2278173439170137, - -0.11994966521820576, - 0.10822781021756589, - -0.08620534129121565, - -0.18842375683557355, - -0.012530790115013684, - -0.07107077709878895, - 0.007312279530594569, - -0.07141590379040552, - 0.1801511117200161, - 0.2130117732885219, - 0.04758554770243126, - -0.009191956322229806, - -0.06478034519901396, - -0.10820404674567854, - 0.08086627779014932, - -0.03169499330669035, - -0.009086972907889075, - 0.1388354705248064, - -0.06934277483053007, - -0.10971595564556579, - -0.03186836578015179, - -0.011623548676227842, - 0.032358670237590904, - 0.093326723618319, - 0.007268391823144747, - 0.08149009608058576, - -0.20588197083841345, - -0.10992591290673198, - -0.06892772366674459, - -0.11710831268787908, - -0.01640044237818485, - -0.32513000432229655, - -0.034607217433152634, - -0.14388823029922215, - -0.02802412368885126, - -0.20960955787619928, - 0.07359949088606048, - 0.14035548406967324, - -0.1479483146508088, - -0.18706069381288046, - -0.05266033341416942, - 0.0673855627825452, - -0.2588736258294243, - -0.08454576921762787, - -0.15975399610498334 - ], - [ - -0.015462881206246603, - -0.06489099452489641, - 0.07271432264049305, - -0.17806510484676083, - -0.12407740992856653, - 0.13411847565323562, - -0.1430761798142936, - 0.17413829267189154, - 0.0905805528466839, - -0.04731495644212914, - -0.03734200938055431, - 0.14549590426339098, - -0.21452765141473, - -0.19152459687713208, - -0.13285809070804505, - -0.09019231357570921, - -0.10290047491061625, - 0.020659282375771734, - 0.04961399108923035, - -0.15007265956437085, - -0.09435989903446694, - -0.04241573395321147, - -0.10299875389573088, - -0.057434253140555856, - 0.0738469502417908, - -0.20635023237598132, - -0.01466442576219921, - -0.18657514022621013, - 0.03667068254905596, - -0.05290392241259411, - 0.09206111359701372, - -0.00888328776969914, - -0.29281423333137835, - 0.06801181136267717, - -0.13978425744743458, - -0.03325062266137656, - 0.123849171150082, - 0.17579453189025102, - 0.16075198624329376, - -0.08925182130357727, - 0.25919380688195526, - -0.014040720877696594, - -0.02696077855138033, - -0.21721108341718384, - -0.08683268365664425, - -0.03791315899999881, - 0.16205425953712008, - 0.05136509871211233, - 0.0026623658446065304, - -0.14814873051425861, - 0.3297631085357204, - 0.01419732992212604, - 0.002347986951556364, - -0.12210685910361041, - -0.19580046568623666, - 0.05334512999279389, - -0.012889221536726999, - -0.12948611225938012, - -0.0016522650342983619, - -0.07652212920641287, - 0.01625453247794613, - 0.13008328499928046, - 0.06903671771615126, - 0.023421637110483933 - ], - [ - -0.2540080554782079, - -0.2279673051835324, - 0.0876832336172554, - -0.06711878199165044, - -0.13763864040218274, - 0.004964899060196056, - -0.17357789954042147, - 0.004786309033527591, - 0.11176254677639552, - 0.0881499721028349, - 0.0943634709659892, - 0.002799692511756376, - -0.1597996663964345, - 0.10653606004124161, - -0.2353065376404663, - 0.18911667872345664, - -0.23316750905383865, - 0.11685933536310344, - 0.11182179227145857, - -0.030184481678027127, - 0.11707147344533202, - 0.02729833679579678, - -0.1429702235932491, - -0.04967994553762218, - -0.012655537791926597, - 0.03367566900102066, - 0.12199956529795701, - 0.1534308089570115, - -0.17507762204433397, - 0.10649471082662372, - 0.1010508120279775, - -0.1272551405148958, - -0.03544129218727131, - -0.04496991364889506, - 0.07963438253452804, - 0.029417874984538333, - -0.09046098148893093, - -0.25294291687952636, - 0.1341333118495632, - 0.010693628121734716, - -0.10096831675079258, - -0.1276473773823678, - -0.02609860952827158, - 0.09526351697846393, - -0.1533545223889398, - 0.07687754756221012, - 0.09439784279359789, - 0.0931482654737058, - -0.02419929808860633, - -0.03639005308153976, - -0.09613538548298647, - 0.08813136548715474, - -0.12165241630872291, - 0.2097524397488239, - 0.08742195631739733, - -0.19259713734446693, - 0.19722981656999294, - 0.01742165085739483, - 0.18451144518737023, - -0.10326374891900167, - 0.03503819921679966, - 0.06574309529743541, - 0.14827063704315815, - -0.14204420757854716 - ], - [ - 0.03563891329769557, - 0.08955809978828341, - -0.03154408486850945, - -0.0291629883585042, - 0.08851989834714961, - -0.09574807684947206, - -0.1359928284551665, - 0.10110987977677238, - 0.17979469024976152, - -0.10488067664778729, - 0.04014540966142944, - 0.2148883804071713, - 0.11096686215690593, - -0.12541406830103166, - -0.04981059910720595, - -0.10592755259970922, - 0.05790881765951859, - 0.038320299040203246, - 0.074918876916685, - -0.08933543836196495, - 0.043372344623445504, - -0.2578935951334642, - -0.08028273875164574, - 0.056750830565099254, - 0.24256311218120333, - 0.21609600413099003, - -0.09603315053992216, - -0.10827752702358598, - -0.018916720283815445, - -0.047904551983188, - -0.07718459307399324, - -0.14847100631724633, - 0.24875825813786526, - 0.03199984494200059, - -0.12361484359112244, - -0.04572977889413523, - -0.19923146053555654, - -0.09522323984355097, - -0.19176934945712037, - -0.09883019004851869, - 0.10389864880781581, - 0.08477271526503063, - 0.10215558817210985, - -0.11828501798066317, - -0.14229585030714137, - 0.16471461788430505, - 0.020500388473397087, - 0.11448058436267569, - -0.1578881415859901, - 0.1620241281685142, - 0.04551889402638282, - 0.08046915160623186, - -0.1347065622492036, - 0.3217298398561576, - -0.049318156599972886, - 0.09334641768848448, - 0.11446708788030559, - -0.1038068527148383, - 0.06654263219123674, - 0.10521796441225564, - 0.05035970867477081, - -0.07526427967985752, - -0.09113175260089834, - 0.17138153703998404 - ], - [ - -0.07320926386496333, - -0.15192158214681312, - -0.12322074494617133, - 0.07478957522339742, - 0.021330351521673327, - -0.2933974873318521, - 0.2094714434241857, - 0.36053732404570515, - -0.17866057088114048, - 0.1962523211398636, - 0.1369023383341928, - 0.0187370333393907, - -0.026328139173788352, - -0.13930925632984553, - -0.008251737370421472, - 0.029852208436385388, - 0.10025054874273838, - 0.06675542343387539, - -0.07381516351959015, - -0.11347109926051283, - -0.005248207273836643, - 0.18982544058417697, - -0.010578189359638971, - 0.14480530056988164, - 0.16362893400804526, - -0.005271080120146127, - 0.05045266350723004, - 0.20185966894893, - 0.030221072251700738, - -0.0491201712804789, - 0.06471495200977956, - -0.13115681988483643, - 0.008700880356129929, - 0.09488182935332129, - -0.17408325756473195, - 0.08601965491811775, - 0.030591539413207566, - 0.02510046573565074, - -0.10373568232738274, - -0.13974930110239636, - 0.02226895568588245, - -0.12046492429543289, - 0.2428795614530426, - 0.01928041266168661, - 0.05598726324838675, - -0.09866637478895551, - 0.01799423495727267, - 0.0015496072205311922, - -0.07505273535279595, - -0.0884031955106867, - -0.05504085340475136, - 0.18931490451496372, - -0.2486050665877866, - -0.13705860655451835, - 0.06694211198125649, - -0.14616764744003052, - -0.1941885444897601, - -0.13526955039121205, - -0.03414783023962175, - -0.07493660169900393, - -0.07441542891644581, - -0.027809638866841718, - -0.0002752063732788374, - 0.030843984158129056 - ], - [ - 0.0604767543917339, - 0.029234778232748143, - -0.16056081675475903, - -0.08517448386391048, - -0.03420919687139918, - 0.20226944815096037, - 0.1230713511577558, - 0.1270909146502394, - 0.07780743927145017, - -0.07128470428302784, - 0.0001101138532418489, - -0.07246760159451059, - -0.0008259460237562867, - -0.05712751207030997, - -0.05458741190405074, - 0.10155968603220912, - -0.21948405329142928, - -0.21863649856027734, - -0.2200504300090772, - 0.03964297721704672, - 0.20425229497747982, - -0.046859456302621824, - 0.14627373191013135, - 0.1755767958064591, - -0.0859289565021313, - -0.04324403926935187, - 0.27211247566223734, - -0.003664632127748658, - 0.0768547510881352, - -0.0658957855929241, - 0.058835169815021, - -0.054305388237147895, - 0.13376844108067612, - 0.040788737800360325, - 0.12155389723493536, - -0.16774945382421236, - -0.1425214434533471, - -0.034558437427664006, - -0.0021097865497912063, - -0.025180421624135352, - 0.12752161569608625, - -0.2969602387102315, - 0.08693528569956085, - -0.11663243182658721, - -0.06401234213898922, - 0.2044797351946668, - 0.04094687848578633, - 0.03407014981190001, - 0.047402318738334365, - -0.04987367748111771, - -0.1839416696946447, - 0.1763703110526873, - 0.19401982616364796, - -0.13358776639141295, - -0.03948658003594118, - 0.11826905622071406, - 0.06197966648382854, - -0.1408212502568306, - -0.18246593204667377, - 0.04707760954027769, - 0.1812255591941227, - -0.12300191073346091, - 0.08392157351800601, - 0.012856811445298238 - ], - [ - -0.009696073527065186, - 0.18767441505443333, - 0.0575997137101108, - -0.05263253658016545, - 0.007717680768415995, - 0.009963866478132256, - -0.1745421201272831, - 0.08123521424035916, - 0.11598633210893118, - -0.005528751884623124, - 0.15909189586641398, - -0.005106276250020271, - -0.15033383062256842, - 0.07598234994877924, - -0.27523950692901034, - -0.2193557278166884, - 0.06810747027566719, - -0.1369962351584922, - -0.12675509716010935, - 0.3494770337981841, - -0.21742095614025747, - 0.11095143002078088, - -0.09937155473874625, - 0.011944746159370368, - -0.07330601954544703, - -0.054392975836414614, - -0.07851377091228633, - -0.030032758822658642, - -0.13150675431975087, - 0.018939357444328047, - -0.15182852251328435, - -0.19011056684385147, - -0.1365941042741993, - 0.14251936260382556, - 0.06712748918424748, - -0.09912456076373317, - 0.09679139676773962, - 0.10435982654009611, - -0.19016415510673723, - -0.0488176813173335, - -0.12493549860461971, - 0.043124344039300815, - -0.06810924911915622, - 0.031478642123683634, - 0.17864646531601366, - 0.08422653705789561, - -0.10570073517122425, - 0.05023982771430177, - -0.1708217142308089, - -0.11027883074494815, - -0.21211793917548674, - 0.20481377395091757, - -0.1292920410952451, - -0.10953617243566525, - 0.009607777582423847, - -0.0015954993228362918, - 0.09265008168005927, - 0.1333245072945238, - -0.06351096267660346, - 0.01654681213710465, - 0.12061963294493555, - 0.05940073268720372, - 0.006175291007624889, - 0.11431254930882571 - ], - [ - -0.07254696129190422, - -0.03709488559719091, - 0.003916519718065587, - -0.20579452229530237, - -0.0886739165338501, - 0.10451170288124169, - 0.06566934713445331, - -0.13750637855856082, - 0.0988512444327872, - 0.003505157791358289, - -0.152117878776637, - -0.276986551461027, - 0.012096511735331734, - 0.16937073301869646, - 0.1822855278747602, - -0.18920775787924227, - 0.033967489003163306, - -0.02749416875036368, - -0.279419085104416, - -0.01645351460630035, - 0.11545088112103308, - -0.10801771278978566, - 0.002219606380811488, - 0.15515541148398662, - 0.11271501410333125, - -0.2088870738809567, - 0.031277772250017793, - -0.13857406277098408, - 0.06002869515617205, - -0.052371954903298226, - -0.08658852165583514, - -0.12822203457645734, - -0.07632129485337608, - 0.0011895977366764066, - -0.014706390141917724, - -0.10451919365239225, - 0.0733924875816778, - 0.016138927071736274, - -0.0803166804667054, - -0.31460070756050496, - 0.03299056032968558, - -0.06812222591223122, - -0.060895099048112716, - -0.06124040208322928, - 0.03585656760999728, - -0.1278216687890769, - 0.05755816906662869, - -0.019671582500833982, - -0.1768317622763212, - 0.08093780136739454, - -0.03856906107010018, - -0.11115369139057686, - -0.10002504951308167, - 0.13626369094020896, - 0.25451564432821794, - -0.19810141475277468, - -0.024986287746590837, - -0.12349256086290189, - 0.2420853920500975, - -0.052322722043679576, - -0.056459104254048535, - 0.0020106394986599066, - -0.14225209544658365, - -0.1337706188151418 - ], - [ - 0.09389547334779065, - -0.10212031756364405, - -0.055506842766829635, - 0.0885225630204123, - 0.07427713885514696, - -0.12211594831986655, - 0.03606770316292289, - 0.10773503225677143, - 0.06472621861739906, - -0.049174250973251094, - -0.19981624736426226, - 0.08473492696215368, - -0.031438424139971326, - 0.15256800870724688, - 0.024756511484702762, - 0.05527063905123462, - 0.01630063621904397, - 0.05926783529865106, - -0.14777046262548585, - -0.06811868573483926, - 0.07812991365722209, - -0.023648869841611343, - -0.10120627846612736, - -0.049132470895019584, - 0.05238561168161472, - -0.2237653672306652, - -0.05544551229797533, - -0.06438618993405935, - -0.07012865357139281, - 0.18362846461770935, - -0.06083440240162985, - 0.3315482703352149, - -0.07210103518260903, - 0.03393419129534413, - -0.16112586225588707, - -0.0965212022704273, - 0.043008126221133425, - 0.13738849857673965, - -0.03858589692538985, - 0.26724913907130876, - -0.07288828002319574, - 0.21043635284016637, - -0.008547033705116289, - -0.3005803059006687, - -0.11842027293233305, - 0.26399073460730593, - -0.11753853288997462, - 0.08940455839763214, - 0.10516476848056391, - 0.09967913672142431, - -0.2644900347353253, - 0.11549532326766053, - -0.08058787000176038, - 0.02215072217194553, - 0.166475507527435, - -0.10089775021813645, - -0.029028122038959537, - -0.1089835756459193, - -0.018514386033411784, - -0.1687577250566168, - 0.07858611548215161, - 0.05373475496861836, - 0.09512332426720004, - -0.05790741268172995 - ], - [ - 0.07903762506287289, - -0.09995325435204433, - 0.0650956868293148, - 0.015398544436769263, - 0.2789673054305785, - -0.004806088730243197, - -0.03787156470181218, - -0.11967262762072789, - 0.3652155373257197, - 0.03846552635888905, - -0.003691381065367041, - 0.09526773423984493, - -0.27047385784148276, - 0.017129165573177896, - -0.06401152970342851, - 0.084195674676342, - -0.20837929007318348, - 0.2902363441601584, - -0.1853289473141958, - -0.004509267780638982, - 0.12028090510379119, - 0.09664163476169801, - 0.09045622916229352, - 0.12122598639732456, - 0.174394540499563, - 0.23006986505254942, - 0.09258414470067984, - 0.05634093851294375, - 0.060816659563390586, - -0.01952873834092599, - -0.0689744306696388, - 0.10695839579140604, - 0.06341296737065899, - 0.10624208165436569, - 0.1734820996342262, - -0.014921949275471151, - 0.07539161795596379, - 0.05339994263441952, - -0.029227164122963434, - -0.09751915793774638, - 0.1773746849273178, - 0.07238086050473543, - 0.08280207318821886, - 0.01028345376867893, - 0.23765934006901349, - 0.02348016182744024, - -0.19739127312999705, - -0.04241982224867744, - 0.08933046631896213, - -0.0415882583746128, - 0.05011405546963045, - -0.1268482674869322, - -0.017750780050113334, - -0.005191220584443009, - -0.12246480965194896, - -0.10734740841901928, - -0.11785097500262685, - 0.1151560224758585, - -0.07229285399122723, - -0.05468478475508364, - -0.008951138154419613, - 0.10840259316471858, - -0.14848940461139246, - -0.05109775481329243 - ], - [ - 0.08291320645215172, - -0.046773884703018034, - -0.006499378496810409, - 0.004375673216272275, - -0.058459850310606624, - -0.1439432759847075, - -0.020004114821474246, - 0.022270417175925393, - -0.15083670088342824, - 0.2458666109096482, - -0.16065285738731894, - 0.1603039700411316, - -0.22343434417162666, - 0.24689522225772, - 0.07259872904451835, - 0.2498207255801649, - 0.0975014136886866, - -0.09457623503190508, - -0.20504825362054466, - 0.11122792051339395, - -0.0021043017998779137, - -0.004094091503777705, - 0.04556393864928164, - -0.08434782460913438, - -0.14875556946213161, - 0.15949583212218862, - -0.032251036059058456, - -0.16003811809919877, - 0.01981497132523198, - -0.11761037846100038, - -0.023361515483713614, - 0.018898351539059097, - 0.13601255631906742, - -0.014583995220668894, - -0.09046885282689789, - -0.13548878240194454, - 0.057763684180019745, - 0.13290374580583214, - -0.024416521567803877, - -0.22290878552180968, - 0.06516548946979529, - -0.024194409412364948, - -0.04596642844733592, - 0.10385386240412674, - -0.22960947345936536, - -0.22731612755062328, - 0.005813578834062795, - 0.04857306362618547, - 0.14241827316796243, - -0.20522145256743352, - -0.050115321586887356, - 0.03572454113870709, - -0.0677594850573953, - 0.25026194032462523, - -0.0595953678148633, - 0.25514103684150297, - 0.07609556721762176, - 0.03120001810540759, - 0.020683819604026772, - -0.07111619039457229, - 0.09972370235445696, - 0.1102825043573012, - 0.027676893965596052, - 0.05395526046701944 - ], - [ - 0.15751943925953285, - 0.1406657094476347, - -0.0986622349285274, - -0.046334249386759535, - -0.36904306916512103, - -0.16235513466715026, - -0.030217617735743076, - -0.09395296233642846, - -0.03822224028038231, - 0.032983963543193995, - 0.0883417439068974, - 0.08487377150806553, - 0.06194301484286491, - 0.006433284209595118, - 0.07716508788693596, - -0.30928138593589566, - -0.11782703713801028, - 0.11627166583604023, - 0.021699114470787886, - -0.18036069151560466, - -0.01348987669786829, - 0.15069555404042648, - 0.07704993634085437, - -0.0028514264609805946, - -0.19508321714989424, - 0.07860092110933319, - 0.0343765974123348, - -0.10918294075853856, - -0.08317384541355682, - 0.08078377058829783, - 0.13479602110584954, - -0.012016459137464816, - 0.20796278715469552, - 0.15191890373579714, - 0.14291250151320872, - 0.00442262104834703, - 0.12539583225230563, - 0.10467546589822117, - 0.11885957893475718, - 0.005478497778035306, - -0.03299754468954624, - 0.0574570139561995, - 0.15304081481155513, - 0.05502601183656448, - 0.013699277096832628, - 0.17729542642465362, - -0.16909878239538675, - 0.06846377118824798, - 0.05414432379910014, - -0.16679151977677475, - 0.07657805890502806, - -0.07739189261837, - -0.12116853632782966, - -0.00959761837503591, - 0.06047410772163632, - -0.018687145799747198, - -0.04491506368134442, - -0.1463579113946922, - 0.19787111674528535, - 0.075811732400772, - 0.2910904621822984, - -0.04884559963069329, - -0.03425040814824099, - -0.16875651195769314 - ], - [ - 0.13356496440817112, - 0.03686626869580791, - -0.07097359871655831, - 0.0021415560785697156, - 0.004540010124611474, - 0.21312588591469275, - -0.007176314467000029, - 0.08900625834701074, - 0.14674296393440542, - -0.05211615582113942, - -0.0015375880862648404, - -0.18557662953012682, - -0.05605615721913265, - 0.10375814681485669, - 0.033214081982135206, - -0.07276205390242887, - -0.06874418640178007, - -0.16541724523492346, - -0.07719478238356738, - 0.006521522659235431, - -0.004781431664953232, - 0.023443569841331703, - 0.012549783041164666, - -0.4589705396306846, - 0.01707276548640523, - -0.007656966191821271, - -0.061127952143261666, - 0.10516768831010459, - -0.06841792533006627, - 0.17362143636454128, - 0.09816338515791803, - 0.030164673020319117, - 0.1882424399613662, - -0.30112436659195796, - -0.10612201161245194, - -0.05041182482140285, - 0.09325502365879984, - -0.007434406153896934, - -0.17038262091937897, - -0.022978141774253447, - -0.008701700669947422, - -0.04524398886744856, - 0.2232018543195481, - 0.1942006014674341, - 0.08649258589208367, - 0.13724275014603698, - 0.07008678040701892, - 0.05921235464530258, - -0.07101800127631051, - -0.060570608085055294, - 0.0923299812023446, - -0.02822340640582408, - -0.14248173434487946, - 0.06799696563883159, - -0.23258427832439624, - 0.006647017950669046, - -0.18186125672023157, - -0.09248150389401266, - -0.0036903333256555187, - -0.24107469673574838, - -0.1667926651469509, - -0.06501617516182544, - 0.039995488583610836, - -0.015414515990076072 - ], - [ - 0.07626397434837334, - 0.11317952696163412, - 0.03178273803728478, - -0.0024584043021152802, - -0.2284082814777275, - -0.10601858745207719, - -0.02564782247231917, - -0.022672466210106625, - -0.09487232163370612, - -0.22148445944974404, - 0.14167302876975527, - -0.03865884674396494, - -0.014293541380819489, - 0.0796820681481707, - -0.012818112028946626, - 0.04274123008879459, - 0.13316663101320006, - 0.06344578063890378, - -0.09883611511171002, - 0.12888103524195998, - 0.31280070000005766, - -0.22032097318698557, - -0.07385626111254594, - 0.0009863740208950012, - -0.23842485641864045, - 0.10309058494308432, - 0.053410195196817015, - 0.14106071601386974, - 0.13529553491817622, - -0.09166990716900768, - -0.043511871195621464, - 0.04613014615384094, - -0.034547327291581435, - 0.16855802830778482, - -0.026838923474895356, - 0.14765964855601454, - -0.0013099863522804528, - 0.028823449282163096, - -0.017362821078688008, - 0.07172773120179259, - 0.07469588716082934, - -0.009065666595904822, - -0.09721045233902328, - 0.09347589281580088, - 0.018850067529144844, - 0.005697966100171475, - 0.10077772450862536, - 0.39219820486317464, - 0.04961308215589098, - 0.12174139622516685, - 0.10619285745900142, - -0.016207257164598067, - -0.0629383244915543, - -0.09651187090324917, - -0.10600385768035066, - -0.22841996751905955, - 0.03475042666009916, - -0.08238769400072882, - -0.12659354681644733, - -0.2360393164887187, - -0.06472303078681722, - 0.14024541073441854, - -0.1892749471767009, - 0.12299001058683134 - ], - [ - -0.12302910264001787, - -0.05918053445273672, - 0.026984062134561212, - 0.12041276250230155, - -0.015424048460491488, - 0.2123522538194157, - 0.15516159020820638, - -0.042596598542358866, - -0.10462014786091406, - -0.16218372204072223, - -0.2257808911851405, - 0.013546039787137346, - -0.054200488185708856, - -0.11133898934626689, - -0.0005800282685214344, - 0.02678075452960064, - -0.04688435835079049, - 0.02573401142893834, - -0.022934402663896302, - 0.14283954635056423, - 0.019443668615453012, - -0.07882174586556376, - -0.199888083939748, - 0.16705660860234003, - -0.13781263725960083, - 0.03592998396858791, - -0.023791776450698278, - -0.19269505490152006, - -0.1655195167506578, - -0.19623011704924845, - -0.175577943771248, - -0.08153933721266657, - 0.0714768291381128, - -0.13088315934005987, - -0.11014316030285254, - 0.064848472515722, - -0.08033021187463485, - -0.07277729466004113, - 0.09671041088859794, - -0.09076602983834192, - -0.01613452024169886, - 0.08901650279209435, - 0.22581620134382366, - 0.09971826067668559, - 0.013734375510066009, - 0.12328993558972057, - -0.29376312242331, - -0.024767799190978823, - 0.22273175973999174, - 0.008217624343457016, - 0.0583431325757484, - 0.06755075641501165, - -0.23599845561209765, - -0.2755291804464649, - -0.08525486118696082, - -9.311297235739187e-05, - 0.07943903069800154, - 0.001725484842390907, - 0.2457682026594725, - -0.03545573274787261, - -0.1389046916037018, - -0.0005100799566202276, - 0.08298988810334436, - 0.028854430827183853 - ] - ] - } - ], - "qwen3": [ - { - "layer": 0, - "rows": 24, - "ridge": 0.007740341126918793, - "mean": [ - -1.0697541236877441, - 0.5980024933815002, - -0.6226648688316345, - 0.48415061831474304, - 0.9949874877929688, - 1.4079958200454712, - 0.5412151217460632, - 0.24653126299381256, - -0.5583217144012451, - -0.05605209991335869, - 0.2563484013080597, - -1.952626347541809, - 0.042111605405807495, - 0.9116683602333069, - 1.5351591110229492, - -0.22556959092617035, - 0.4134249687194824, - 1.7063703536987305, - -0.35431933403015137, - -0.6667203903198242, - 0.8396592140197754, - 0.5784122943878174, - -0.6509129405021667, - 0.4576737880706787, - -0.8654751777648926, - 0.17347712814807892, - -1.0710842609405518, - -0.02667906880378723, - -0.9329490065574646, - 0.13083410263061523, - 1.294770359992981, - -0.1102645993232727, - -0.5061127543449402, - -0.10273011773824692, - -0.001156537444330752, - -0.9610713124275208, - 0.0007523571257479489, - -0.4157428741455078, - -1.1953558921813965, - -0.4055067002773285, - 0.9238321185112, - -0.12423192709684372, - 1.8482071161270142, - 0.14442427456378937, - 0.5066812038421631, - -0.15473519265651703, - 0.31152063608169556, - 0.06653553992509842, - 0.9140093922615051, - -0.73482745885849, - 0.5601326823234558, - -0.7879500389099121, - 0.17368876934051514, - 1.3637522459030151, - 0.25547900795936584, - 0.9373276233673096, - -1.1588248014450073, - -0.1582048386335373, - -0.9229554533958435, - -0.26795825362205505, - 0.06137470528483391, - 0.9107198119163513, - -0.4912306070327759, - 1.0379198789596558 - ], - "eigenvalues": [ - 0.1129492298203952, - 0.10514886378985128, - 0.0796596391371406, - 0.062256667445003265, - 0.03059511320227497, - 0.023489532078382242, - 0.0185626762300767, - 0.01359407490949568, - 0.01259826259835209, - 0.008412886977789923, - 0.00691516303016651, - 0.005234428444610113, - 0.004720042203235548, - 0.0031830338234338246, - 0.0021461502196355683, - 0.0017541782051052708, - 0.0012730982440006774, - 0.000788549567528915, - 0.0007557677467540224, - 0.0005575885790721817, - 0.00037743879497510773, - 0.00026344905712747947, - 0.0001459807693867222 - ], - "basis": [ - [ - -0.09546390275870685, - 0.021799884505901684, - -0.0933950166025022, - -0.01320729150845197, - -0.0734628398404289, - -0.04666174617580429, - -0.047646495670877496, - -0.109695596277357, - 0.05438754688390975, - 0.01459439333984477, - 0.1369372581162374, - 0.08210468553744753, - -0.040528185416271, - 0.029006736888846564, - 0.03401757277933567, - 0.07186330334954444, - 0.21442870562880606, - 0.07944525031658738, - -0.03741373229255505, - -0.02997213247110237, - -0.03943299134981381, - -0.0578406842432088, - 0.031772192012006706, - 0.04784130052374523, - 0.12985983487238315, - 0.009188089094370262, - -0.044601819363022356, - -0.08626495024678847, - -0.2503112009817529, - 0.05176526257779682, - -0.00031325797272949927, - 0.07354018512292192, - 0.12588241661832628, - 0.09862741614147916, - 0.08621865893064964, - 0.01988207069398347, - 0.07512470662598417, - -0.15861169931675453, - 0.2064650414938798, - 0.010667609594518693, - 0.0725684822450556, - -0.13194198836776938, - -0.20725020881212225, - -0.08966574762469742, - -0.40821838621336665, - 0.27179213468533137, - 0.02677166790561242, - 0.08798904207071534, - -0.1259070464487556, - -0.07745094829469341, - 0.09290584696755114, - 0.17541838086747782, - 0.017264851449048116, - 0.20498911654889024, - -0.03875716401917356, - 0.02627458470788463, - 0.05451574316191083, - -0.13560216980957393, - -0.07748733666065052, - 0.2801964398165346, - 0.005835455563135648, - -0.15239260852085137, - 0.10270571946270612, - -0.29534037915019534 - ], - [ - 0.09336680058660204, - 0.16707249914206204, - 0.08596686588743511, - 0.0682196061322743, - 0.20143275231607055, - 0.03979434120723143, - 0.2535555594818949, - -0.13163181056253165, - 0.0528941160368993, - -0.10787561706594632, - 0.015904312376083102, - -0.03792939580027166, - 0.008864931444129273, - 0.13145459813753257, - 0.09156599755801038, - -0.028960471415095192, - 0.1909726804156826, - 0.08846866038757893, - 0.07983413702066428, - 0.02472789798799996, - 0.06683368804097355, - 0.1526317094952237, - -0.03294049780061792, - 0.14980096695119724, - 0.10145463305007717, - -0.01694700728484119, - -0.10465142463481797, - -0.08238178633925314, - -0.33746803692890226, - -0.0208741355182725, - 0.19744788012608475, - 0.002285740829189111, - -0.04401657153913922, - -0.16298063949791602, - -0.02212247040629968, - -0.12591682123398606, - 0.1284436571677136, - 0.05230559402418414, - -0.038662509892487214, - 0.0619745765796626, - -0.2751626673593096, - 0.05850030228822576, - 0.058626551062791694, - -0.076810789802661, - -0.022083811421562443, - -0.17203732913445158, - -0.16984123754113845, - 0.07273721087193559, - 0.2846362803329469, - -0.10865908718025295, - 0.0512933271264734, - 0.06660839328875404, - -0.15973856656087496, - 0.06240372148966202, - -0.06406618227601621, - -0.16542903285718905, - -0.08118888720408428, - 0.05204510128171158, - 0.18153917147678122, - -0.044086676948398844, - 0.12996965711789282, - -0.20602042029785952, - -0.11906465626680894, - 0.006570805112033599 - ], - [ - 0.056479826168110564, - 0.17837432018711455, - 0.004391730459576273, - 0.26192427674358654, - -0.07157438721017714, - -0.060198514920151464, - 0.09738858450711187, - -0.02094919408495346, - -0.02978063791665853, - 0.091967458328185, - -0.006850373884994191, - 0.1267973794369219, - -0.04087209314361602, - 0.1381011134634114, - -0.14206510813447495, - -0.0859653254842474, - -0.04685975968834853, - 0.04662958705923203, - 0.06575715183701379, - 0.1875221145041327, - 0.14775405752045168, - 0.030164802258504105, - -0.111086967366611, - 0.02462607652081761, - -0.048791662799677754, - -0.011785303175506258, - 0.12167554996782327, - 0.017114162911395857, - -0.18914054668249355, - -0.2165636802530811, - -0.07430461843886892, - -0.0008982177609898414, - 0.22003975858445218, - -0.00032337400330329744, - 0.09279774353129037, - 0.21735831658087718, - -0.15173939551331456, - 0.1566743972432131, - -0.21305849457982567, - 0.20692697818706932, - 0.09247764503916787, - -0.3171073439243528, - -0.09353261086014403, - -0.04436391029685033, - 0.09782957402030847, - 0.06121497241603271, - 0.05485375647515982, - -0.18252986690124573, - -0.163947696677281, - -0.11560891277417303, - 0.10880241018588829, - 0.13174432673115485, - -0.1057112360272151, - 0.007974580633986164, - 0.032394930447511, - 0.103156934601459, - 0.0845786508995866, - 0.09824957486024401, - 0.21221674742362132, - -0.06811130865714171, - -0.17138608609911504, - -0.03783343508492926, - 0.08691339478962, - 0.10871349043764686 - ], - [ - 0.19331384937775714, - 0.11097284930076429, - -0.05726912152315077, - -0.23018860483110587, - 0.12155124322547822, - -0.04124798501108731, - -0.10925829210721323, - -0.009193765934281749, - -0.007358806492970417, - -0.1509147051137121, - -0.23684224811145993, - -0.031009808337157354, - 0.017607367009504982, - -0.15531486182820475, - -0.4117952191921262, - 0.1728348995156798, - -0.10742477440970072, - -0.01500178304164703, - 0.04257004396312944, - 0.10878706983507798, - 0.062315200507666105, - 0.06752202781517341, - 0.10921029999562032, - 0.07549946066140215, - 0.034823106576124814, - -0.014195247585504351, - -0.06636341509672027, - 0.17920745347242928, - 0.029500522368770887, - -0.09370695174777363, - 0.014581507569289208, - -0.20231127652363387, - 0.062485394153421796, - -0.06976358465515947, - -0.021285848638537636, - -0.0683655857708492, - 0.03758637041532914, - 0.0012544530243880385, - 0.17523962129404605, - 0.0713542401818044, - 0.11651101889343816, - 0.12383103838658376, - 0.14926204616281924, - -0.2118720608424072, - -0.006632686863102824, - 0.2106013223054315, - -0.15491006067098742, - 0.11141937315838685, - -0.025969049042152324, - 0.03109721890374695, - 0.21308375073184965, - 0.1821476473536968, - 0.10187197944951636, - -0.1345630591706467, - -0.07183106972676778, - 0.12139765614033518, - 0.05540913243879818, - 0.1882431692965818, - 0.08453107791931302, - 0.014386943559367059, - 0.031815761491038895, - -0.13311802399174813, - 0.015575965600079728, - -0.011731287430880522 - ], - [ - -0.20577031502854318, - -0.0337998580348271, - 0.310894073636551, - -0.11595250186105581, - -0.08911987470746952, - -0.0708302785804576, - 0.30761307992758974, - 0.029979063075705522, - 0.08763174001141452, - 0.05331185093838885, - -0.052841838311180576, - 0.007434762723434085, - 0.11068786605364513, - -0.02074924505312089, - 0.15030473771214833, - -0.038030291561331274, - -0.05838397139236421, - -0.024255647986191807, - 0.08860033303491466, - 0.1190711398700609, - -0.07612275219051734, - 0.05781968974166107, - 0.1619680325358037, - 0.007672064460080039, - 0.1730265731993381, - -0.018833233870568684, - -0.03241183991222455, - 0.11027529874987714, - -0.05926319065426163, - 0.14624070432835773, - -0.06628324046868352, - -0.11727439057010376, - 0.033617506541713534, - -0.17204630818152072, - 0.06539124093154701, - 0.011633201084622147, - -0.1610300329130418, - -0.05578689626796792, - 0.23376314124739062, - 0.10900373891852116, - 0.06326888769429499, - 0.13070051560012885, - 0.07652257371571222, - -0.13721978418306566, - -0.18886313152214482, - 0.16763984206319046, - 0.2000946520238664, - -0.10097365683832601, - 0.04637731407391591, - 0.07185063712095457, - -0.011103519704248393, - -0.24001643962645755, - -0.13246735867464096, - 0.08446311601204773, - 0.014183940760439835, - -0.0782997729429866, - 0.2084730452445327, - 0.14488841330509583, - 0.04957897739003302, - -0.12035399951441487, - -0.22624485830878574, - 0.040830852727246354, - 0.021045807828831184, - 0.13637764551642842 - ], - [ - 0.1269733040338689, - 0.18613717150926207, - -0.03224528123326507, - -0.13746643370293232, - 0.12203288672311292, - -0.12314172301333823, - 0.1430693496809413, - 0.08698993667597349, - -0.06290532547399004, - -0.019017088495195778, - 0.2358284420866119, - -0.05627249923391008, - -0.10903451467470494, - 0.14543278042401056, - 0.1726997628115324, - 0.21272218721355626, - -0.04170653069522445, - -0.008965107573368833, - 0.11959294791365795, - -0.1428635232990957, - -0.13546192882664282, - -0.08142010841128285, - -0.09023872070363373, - 0.14375546996590505, - 0.11294402361706933, - -0.0447147427801529, - 0.010574114531669211, - -0.012598328976113253, - -0.053083287789048014, - -0.028664896946693642, - -0.001946781816513091, - -0.23916196446917004, - -0.04678133106857047, - -0.07001491556999398, - 0.18404010833699047, - 0.0937063148246405, - -0.16923900297301422, - -0.032572535862484896, - -0.1945859055611788, - -0.1203213743962245, - 0.2030544992636798, - 0.05693638863836579, - 0.05550757256106134, - 0.16815962827027373, - 0.01336378615782264, - -0.01710837664283046, - -0.15662837142031827, - 0.1160829628772357, - 0.04002557341653023, - 0.08982861528337999, - -0.07361714293070289, - 0.10134367025778317, - 0.3030928169581535, - 0.11173761155996302, - -0.10493130681217556, - -0.053123077982433084, - 0.07402874451489626, - 0.02477977331861209, - 0.03407290272266184, - 0.20814149155243059, - -0.13192053823041353, - 0.12121814452015195, - 0.1478297595415079, - 0.19906946747373083 - ], - [ - -0.027188804073068094, - 0.35039269047185845, - 0.20889839495450027, - -0.05471852279095676, - -0.2084287268507826, - 0.12177373308277022, - -0.14535962992336124, - -0.03332356561356159, - -0.08780120699391221, - -0.08447159189137181, - -0.21687273214102792, - -0.25813099722774424, - -0.13185368218085605, - -0.05842558669997352, - 0.1264417840163429, - -0.09111110491703032, - -0.14907434420997093, - 0.13911284535205173, - -0.0461623092796748, - -0.15259928194559041, - 0.10788200354888318, - -0.03268855474004206, - 0.08367612546318717, - 0.1682250196859585, - -0.23262809148850985, - 0.1149940314463059, - -0.16864241805271074, - -0.03641825040131946, - -0.0886598572394849, - -0.05571135149578176, - -0.04123459151378763, - -0.12263396675885195, - 0.16289406158428135, - 0.12897447470400866, - 0.13351635612201357, - 0.09464413161866479, - 0.04209959710850432, - -0.11622514944674005, - -0.0013172867656259784, - -0.01780081025221153, - -0.01790111591181636, - 0.09409214787995282, - 0.04471844502064651, - -0.03539694771955099, - -0.05212542678239632, - -0.02434902556741989, - 0.0956893264223395, - -0.021079921946281707, - -0.07015503612949782, - 0.06780706282035068, - 0.06798404204796947, - -0.00911350783890663, - -0.08524173365834754, - 0.16425469537668497, - -0.0513376166401477, - 0.0008815641523666336, - -0.3513114310071977, - -0.14115592069006008, - -0.055464522252837066, - -0.0029126095816701825, - -0.06678731779148273, - 0.025341536708723734, - -0.042237801141445264, - 0.1435993136526223 - ], - [ - 0.18589579645139062, - 0.2546766326355576, - -0.3029985617399163, - 0.062426281647666136, - 0.16791039866011495, - 0.1422873875683085, - -0.04379340562711057, - -0.1428213430204265, - -0.008286306607576462, - 0.030739495064773106, - -0.0011396537250130626, - 0.00350600193710733, - 0.05148618946172788, - -0.007732644642437277, - 0.13494340368992347, - 0.0363657645744559, - 0.15432358664269732, - -0.13834212792276868, - -0.11735963289854769, - -0.030495937453528844, - 0.028699230471943758, - 0.09097570499491708, - -0.04344111598684867, - -0.1020528065945903, - 0.0006595462778651926, - 0.10805641536847671, - -0.09821133118028064, - -0.03684622942665638, - 0.06819402317532783, - -0.014424161225681433, - -0.11065014571192554, - -0.025854116026400482, - -0.07962657350345578, - -0.10335186117092302, - 0.17647382742164353, - 0.04215588431289998, - 0.09532025907943284, - 0.22482626246658705, - -0.055001130327243804, - -0.10413086993225372, - -0.03267951348355784, - 0.13893413271377428, - 0.09006282963858943, - 0.00908954190284228, - -0.15212598856250434, - 0.2065471380660639, - 0.20996932461929288, - -0.1424447189143838, - -0.1460578962686284, - -0.18065460075399503, - 0.23090814031219958, - -0.19550753676199178, - -0.07416022505025437, - -0.18446659777660163, - -0.06116574093955862, - -0.21103762302538245, - 0.12970556149001872, - -0.0014773588610524045, - -0.1370637935852596, - 0.05485840660870209, - -0.02973435805333655, - 0.13605321203659151, - -0.08961348420778963, - 0.09894077904884355 - ], - [ - 0.14583835126677697, - 0.021907733171442303, - 0.09862588080903589, - -0.011559795395516468, - -0.05351522101196672, - -0.17670363663493252, - -0.0034018956198900692, - 0.016456724849040913, - 0.018481333644489926, - 0.12481019319008929, - -0.18400810551498614, - -0.12596994860061544, - -0.07456224458231675, - -0.1872442949334568, - -0.1053605295680919, - -0.12156836188712958, - -0.14707506227816025, - 0.09816595816712714, - -0.3223387574375986, - -0.030943484891946538, - -0.16565125999446045, - 0.09208202056546232, - -0.16578314911401104, - 0.09280201007026359, - 0.07878784405583676, - -0.03292226558800849, - -0.011632321810928084, - 0.07398369535398427, - -0.058219921966582155, - 0.2000441834234107, - 0.08883058737049404, - 0.2567431924892704, - -0.13381634593966965, - 0.12883229730028026, - -0.08226952845057921, - 0.003553424415146271, - 0.1355053208809934, - -0.07703648876401954, - -0.040306441950347334, - 0.009419304051444812, - -0.02037568319521076, - -0.280021676569326, - -0.019570368841678655, - 0.017724198506175796, - -0.013981111783753738, - 0.025451792422286037, - -0.05702647872976527, - 0.020379717352692252, - -0.07005525670425565, - -0.018157905922974133, - 0.03527207725498573, - -0.13098706281966865, - 0.12110733370836374, - -0.021112196327055875, - -0.1529435066980378, - -0.369348025999531, - 0.1159827681042454, - 0.10359606705493479, - 0.0700499798112851, - 0.13226635228965328, - -0.050098548315668984, - -0.08614280475643166, - 0.10306789723344849, - 0.21583453624187512 - ], - [ - -0.2002008445184623, - -0.08754116271780997, - -0.17624935038138434, - 0.16422017763072574, - -0.22103388152874326, - 0.05476157101041957, - 0.06316755331909421, - 0.03273255997245818, - 0.07342438339499564, - 0.07700131111768847, - -0.07512666767576746, - 0.07124735193429942, - -0.06713568322172837, - 0.004705772515263964, - 0.14083542911015995, - 0.15386216392201696, - 0.03360549061128767, - -0.13893541304028598, - 0.15578913380762438, - 0.11792323315223184, - -0.18422624339725394, - -0.054302341972033576, - 0.2054042453577953, - 0.09075859815383856, - -0.02168340930367059, - -0.09206443550998968, - -0.09491226712130814, - 0.05160144386018227, - -0.06124482117679181, - 0.13097472950410646, - -0.142698546004432, - 0.0006959243774050147, - -0.048057769370714445, - 0.017756907760475518, - 0.15226365785498067, - 0.16354615636409606, - 0.2799321932384578, - 0.10184036286776323, - -0.031374084040963736, - -0.1093815378588235, - -0.12001379787629633, - -0.00029342137509979664, - 0.21458437633199, - -0.12354620086759753, - 0.1431282407212114, - -0.16248198776607964, - -0.07168959665962925, - -0.10970950440467381, - -0.18373848081722252, - 0.13541549155493643, - 0.0792344386989959, - 0.069749148122912, - 0.20222274858419523, - -0.0830918376215204, - -0.06730682945377639, - -0.06969694736554344, - -0.1203210475981245, - 0.12816681256003531, - -0.0014219252687179764, - 0.002047179227114804, - -0.10423047669995279, - -0.3146774381220943, - 0.041055593743880965, - -0.04997596801321153 - ], - [ - 0.2264037521863575, - -0.05574856017975211, - 0.01128828547226843, - -0.00011872963769030382, - -0.0771312992447598, - -0.26014633218461214, - -0.05829616083189955, - 0.16300351842751826, - 0.1726812020508572, - -0.03782101296037984, - 0.1141297475385391, - 0.029596344920711292, - 0.14478310013977858, - 0.20885022961160166, - -0.16532968259588063, - -0.11817200868482287, - -0.06845362199335683, - -0.15062517567727257, - 0.15284024776341565, - 0.087883945783291, - -0.14156811618621798, - 0.08972942967584385, - 0.10270630243684023, - 0.11351116440393141, - 0.02636626549529031, - -0.05483638055023609, - -0.04066794783694223, - 0.026972178570101157, - -0.19379484418810417, - 0.06030906576669277, - -0.21933014849613203, - -0.14980026517662678, - 0.04564064670890769, - 0.11701153925191417, - 0.010923005681811504, - -0.12907816335819416, - 0.0913561088298111, - 0.04631079432452238, - -0.0186230399871206, - -0.004355702303520431, - 0.0978029760844715, - -0.18825093221675884, - 0.09837828950760641, - 0.0046289931802847755, - -0.10140871802377234, - -0.015305143165342634, - 0.1479407904891002, - 0.07922087481148676, - -0.0004368981109460506, - -0.08329114363987791, - 0.05786974771949637, - -0.19138351274958548, - 0.16016914826016984, - 0.004396456971436011, - 0.04054366780828097, - -0.0536387740613606, - -0.1950212365178784, - -0.2618874699761345, - 0.033055259616119485, - -0.09021170895720111, - 0.18689122802164052, - 0.12962862981959525, - -0.28444105523838825, - 0.026141384542366378 - ], - [ - 0.06642072660834279, - 0.13953374081057426, - -0.11450169629560703, - -0.20306943603420627, - -0.01507053024896934, - -0.1873378538602207, - 0.017498064008547035, - -0.11647489101681267, - -0.1863500287997946, - 0.3398013463573452, - 0.08438433894570381, - -0.012991788394900434, - 0.04966899089744092, - -0.06495575961084145, - 0.16685294543513463, - -0.21174573248405884, - 0.016459620724777104, - 0.06781464608298085, - -0.09164004289084993, - -0.004031385466417161, - -0.02263079358579996, - -0.06742071511214638, - 0.23649221817461547, - -0.08494053793584588, - 0.1397999122562146, - -0.17428454152063727, - -0.16240061814179105, - 0.0688424297060969, - 0.013553138497823336, - -0.07470032514503847, - -0.04126840715025424, - 0.033148876865368736, - 0.07903155743263864, - 0.15507285154065606, - -0.16326633580947686, - 0.07853936206982512, - -0.07831326753092183, - 0.14049961603102307, - 0.041821941916070624, - -0.05415364744648852, - 0.22434222730441594, - 0.19298496966925477, - -0.04231421215254493, - -0.06597566082666513, - 0.2047407776131158, - -0.07442535865944419, - 0.04401188935559644, - 0.05205576653807935, - -0.01675286910539652, - -0.15626649132823556, - -0.08402933126415112, - 0.1931937353064701, - -0.029985666340038974, - 0.047586635283554814, - -0.11436554109791827, - -0.08806528112362766, - 0.09837224361935724, - -0.14169580199603143, - 0.03847291719238458, - -0.2024781670923561, - 0.0701099783968268, - -0.20266233179604987, - -0.11562419555011984, - -0.02199672289525457 - ], - [ - 0.0857270312385891, - 0.17281178607871225, - 0.04905346953410554, - -0.1210438590826317, - -0.10469059325589705, - -0.22538236463580785, - -0.0019112079926394527, - -0.06618396364460663, - 0.086393609174677, - -0.21107710709815475, - -0.12023124218649735, - 0.0877526174617684, - -0.01767295579456075, - -0.02958576474175339, - 0.17628052479912656, - 0.025365713465333534, - -0.17996348989107191, - -0.1416822688168015, - 0.05526345471861246, - -0.03430840227724296, - -0.2625198230493155, - -0.12428089643734849, - 0.0034363919057592346, - -0.19332227122838005, - -0.0982902875319174, - -0.057353388112401836, - 0.24835485844920277, - -0.10292691886672432, - -0.04665834738014025, - -0.20584788091664946, - -0.06274343614663587, - 0.07663689173730752, - -0.07267368585562249, - 0.026844223777235394, - 0.07638951050381404, - -0.049753148103898394, - -0.08395918845976218, - 0.17489730751445398, - 0.14437553453869884, - -0.0767291589021992, - -0.1970515127271432, - 0.02044591403296607, - -0.3640198376591803, - 0.030966125464145434, - -0.16351850653524433, - -0.13806833985546918, - -0.10288962098292134, - 0.18453881986870524, - -0.04922423753098068, - 0.09111659589932927, - 0.15223233280162188, - 0.01311377755090988, - -0.07702092955221346, - -0.18927267949825696, - -0.013212371363311605, - -0.020159570923913593, - 0.015432690704092599, - 0.009164983074825439, - 0.02134341462021625, - -0.163547322246035, - -0.0606727192846476, - -0.06473875726877662, - 0.02882470119673704, - -0.002210774633237368 - ], - [ - 0.016896954202439408, - 0.07745446396310798, - 0.15678239909901542, - -0.041537272262746755, - 0.02328816374717201, - -0.17627370883352042, - 0.042467464656686875, - -0.0737534823865824, - -0.09180714886041734, - -0.1364908486776764, - 0.10122349026698418, - 0.26737889039344515, - -0.17138855659482521, - -0.1261791989354748, - -0.04358822231546287, - -0.0629068623056736, - -0.029873411890941746, - 0.05847092724388001, - 0.16541503367575838, - -0.02640954609848072, - 0.09793796815378378, - -0.04239201308690336, - -0.02445604852105073, - 0.020241711457280657, - -0.00975915358702088, - 0.015436415775589645, - 0.08214446027808613, - -0.09664909372888461, - 0.09999310608652627, - 0.021302009914414145, - -0.038359840997562324, - 0.20979489482248107, - 0.17775596285233422, - 0.18710035441928577, - 0.20584266220252503, - -0.1581977018761109, - 0.11203582067842963, - 0.05339734521619613, - 0.04463119189587151, - 0.05899896443579419, - 0.17538307903085784, - 0.1601621552411246, - 0.08583571081423703, - 0.22090116989229647, - 0.06792839332652849, - 0.034203060574554, - 0.006311987561623961, - -0.37059466274473174, - 0.14155158008930638, - 0.16129414469234413, - 0.142814075988019, - -0.004666801625338799, - 0.08218923313452298, - 0.06491544104708313, - 0.0560871437953928, - -0.2541899874600268, - 0.0005317421277778327, - 0.17335976357240762, - -0.010858841796306796, - 0.023839043251337948, - 0.16349654396890592, - 0.0007780347013049497, - -0.06666489102470198, - -0.1836938796593762 - ], - [ - 0.013679221456947459, - -0.1792725230071834, - -0.0489456952958288, - -0.3078975650982168, - -0.09078250474548676, - 0.014521070950562537, - -0.1746697954992996, - 0.05824199294754896, - -0.08062446558948631, - -0.0676540129043575, - 0.021600940230756916, - -0.13914672047899448, - 0.08189105243266069, - -0.04439102868748549, - -0.0798004949316317, - 0.028038134768524424, - 0.045905189099945856, - -0.0739050618922869, - 0.27794410191241514, - 0.04857528991493639, - 0.02549903152991229, - -0.03165200271460713, - 0.0369817355464091, - -0.0035877434036981474, - 0.058270314040428095, - 0.09901886345402494, - 0.0477580531670839, - -0.0789054326179623, - -0.06221118796286584, - 0.06749975937756304, - 0.24084904879490798, - 0.14778309835989062, - 0.04197677562749776, - -0.18555040007417267, - 0.11753383592495151, - -0.20000174806427717, - -0.1173833909375219, - 0.10469948451775798, - -0.11179784673476197, - 0.05545942726407846, - -0.02493522012186393, - -0.07439267682624857, - -0.06919543265138935, - 0.015960816883113443, - 0.04255049999690418, - -0.16617815482601167, - 0.3045481012234481, - -0.08606585849046507, - -0.1681087198881084, - 0.014117694472262732, - 0.010116471016119209, - 0.21221004019137021, - -0.1085278859017077, - 0.05626304068111366, - -0.02538235789405327, - -0.09158795582456396, - 0.051753785674069054, - -0.024678904868181018, - -0.1453392466845769, - 0.1971460867212205, - -0.02826258418742423, - -0.19898468931882887, - -0.13880271074283565, - 0.29929776667975055 - ], - [ - -0.08763086951015463, - 0.10742529995561677, - -0.11650668358657525, - 0.08291404440024623, - -0.16970398453659807, - -0.09977090576238896, - 0.2219532461989379, - 0.1365913307761656, - -0.16897236669640703, - 0.04263075109458712, - 0.09515307587606996, - -0.12181947969884627, - -0.045997656115209874, - -0.05642635126813723, - 0.1265788076122759, - -0.10912580648940717, - -0.16574461587801212, - -0.21039731530958106, - -0.11429205240365273, - -0.04976565735477606, - 0.23941990197270047, - -0.1264933609969518, - 0.15614017182908477, - 0.09316594820030184, - -0.2233156123316688, - -0.12386933743537612, - 0.07742592228911957, - 0.06281727626642197, - -0.026702288352172733, - 0.03676331694341602, - 0.2451718698422151, - -0.02093969518689226, - -0.07833122187163011, - -0.170464981696936, - -0.023612967745062864, - -0.1532584802595746, - 0.21873978223227855, - 0.05151537520415256, - 0.0805706863613289, - -0.09290770642567615, - 0.10807511237725452, - -0.07290342344413535, - -0.023575812130624665, - 0.01194736615039092, - -0.09310106156212121, - 0.026250396135618675, - -0.034553190267317194, - -0.0367179782959605, - -0.049519112727940455, - 0.0634558704286546, - 0.05020097092231332, - -0.02102937571772391, - -0.04486758605361509, - -0.08904764394933895, - 0.0633713444179198, - 0.19888677068960892, - 0.1750892106047914, - 0.0004897056303896769, - 0.2450227587764772, - 0.24219584288311816, - 0.18702590002157216, - 0.08691156645130081, - -0.1593215941984752, - 0.007652039818641859 - ], - [ - -0.24965357796638005, - 0.317224701963392, - -0.15915224309998213, - 0.04876673404495059, - 0.12150778696174966, - -0.08216858636342095, - -0.11891603240689967, - -0.1759518563189724, - 0.008028396065351998, - -0.14321849031067396, - -0.14534139825199857, - 0.06381692318505744, - 0.03983852162210829, - 0.058872175747012506, - -0.18395445329688898, - -0.05463257021574005, - -0.022515065696082567, - 0.08776194155071988, - -0.17735270058525474, - -0.014951815359101747, - -0.12718089020109255, - -0.03164571165900316, - 0.11543659632388616, - 0.028474578274236727, - 0.27716633026447046, - -0.04183532517484351, - 0.2100254159318053, - 0.05161549135315726, - -0.05160952141529022, - -0.16662541272112324, - 0.09278071701196819, - -0.09419351617745211, - -0.12698011950858054, - -0.013795633470805894, - 0.14076406479803177, - -0.06837979217334778, - 0.09722023601152163, - -0.15327221335561042, - 0.036699460869243014, - 0.040049024385842305, - 0.008551876476442222, - -0.05925375759337885, - 0.17949137835037687, - 0.16554914469496385, - 0.05514234019719033, - -0.2562871248131694, - 0.22025482356565926, - -0.02733812520108467, - -0.06322227666980523, - 0.04977159030542936, - -0.23467396039590388, - -0.12219552941315562, - 0.01031924807690711, - 0.05764860789222344, - 0.07560787014159738, - 0.09838038352576983, - 0.12872567505116778, - -0.04245670063226992, - -0.007305077668817475, - 0.03344175555989343, - -0.11295659183469273, - -0.05222150466087955, - -0.11145765361785896, - -0.09983543961267394 - ], - [ - -0.18543790832992893, - -0.10307802867219949, - -0.005858503242599364, - 0.12846905691782923, - 0.10273612810098849, - -0.16927773451378655, - -0.22349001886597733, - -0.06659061012454545, - -0.06635712627281415, - 0.012016578008388904, - 0.07701782627292329, - -0.05621483927465431, - 0.09031093038463862, - -0.037544754976708956, - 0.07546485513014416, - -0.06973316292148919, - 0.17246944924802704, - 0.11381130384655141, - 0.19015186168892204, - -0.009382952736092628, - -0.20594950487576863, - -0.09716648248223864, - -0.022398794504291237, - -0.0538348601096953, - -0.058334984430043986, - 0.2743364933210144, - 0.08107359184391338, - 0.3145524546546694, - -0.07353197097668296, - -0.06418490639917275, - -0.08458478511900427, - 0.04740492978826465, - -0.19043388276335318, - -0.058890421098836666, - -0.008472254585315244, - 0.022242731686873407, - 0.11989753407748577, - -0.2059339688601175, - -0.017370185625471705, - 0.0011934802973118917, - 0.13347298895183607, - 0.1103181810439377, - -0.0553753209492469, - 0.17375131809325048, - 0.08402569068009962, - 0.19201536881825598, - -0.20782840010843598, - -0.002624297810252557, - -0.07985869462073156, - -0.003532194818265902, - 0.1842653081787975, - -0.014048925384108396, - -0.19819951228662974, - 0.04247795310378133, - -0.09242454527901728, - 0.03590322212587331, - -0.08103481735605128, - 0.017296786204496754, - 0.23700225467235986, - -0.01911482682596223, - 0.001356118442263278, - -0.00917487729228469, - -0.1760370269787424, - 0.20022867515757475 - ], - [ - 0.008202774607291602, - 0.2107949782178665, - 0.09103479870658314, - -0.06754292006184015, - -0.15632390862132423, - -0.08452536431258952, - -0.07418565005811271, - 0.0438759851071787, - 0.05308764045007541, - 0.39481344010543723, - -0.0023287192078784817, - 0.09821166802177624, - -0.06048457239309409, - -0.20811898029088738, - -0.14553108344800963, - -0.06032292688907132, - 0.2919430272663184, - -0.07816371515906603, - -0.012154690454634035, - 0.038025328660861536, - 0.036575599042511064, - -0.020235919950111456, - 0.1685223976514636, - 0.09684190121470099, - 0.019058060553806454, - 0.16960119900559661, - 0.29033363718073596, - -0.20887885237749743, - 0.012559261694051324, - 0.07714011900812813, - 0.018358247627853947, - 0.11686639221106138, - -0.11270683197513688, - -0.13260716986981777, - 0.16711316342682153, - -0.036382567433595914, - -0.12657324273691364, - 0.13707046361134043, - -0.08093508902851897, - 3.449514707842035e-05, - -0.041673569284156046, - 0.002442766458113362, - 0.2009421446439728, - -0.03318653091718383, - -0.07022597622547808, - 0.13298115452745513, - -0.2040410839421503, - 0.2106929561485415, - 0.008328541999608268, - -0.00021782864510256478, - -0.18285528186803943, - -0.009720423408492785, - -0.028507584515191822, - -0.01959539329759676, - 0.07589282142268829, - 0.03564996389861355, - -0.2069150211961604, - 0.07186627043964343, - -0.026110741161193534, - -0.04364615524102701, - -0.0025549063941970925, - 0.090859543850055, - -0.021272841571392757, - -0.004569560481077395 - ], - [ - -0.06009616602137386, - -0.005770338419538624, - 0.01591643278619747, - -0.0543186742320387, - 0.17278363338619476, - -0.09433714857768509, - 0.3873439594686895, - 0.04375401231986482, - 0.12220088252037394, - -0.03728325891705148, - -0.24698391563295738, - 0.004468098576303227, - 0.028250151927933047, - 0.08302186172152082, - 0.012337858645146945, - 0.07862406306479892, - 0.13841782841116035, - -0.010570038752945942, - -0.05493947582885401, - 0.03244016328080156, - 0.05092157416478055, - -0.000306868843846939, - 0.21629126747727925, - -0.04501117515771316, - 0.0016256412281858404, - 0.025887025080849075, - 0.08134842102056986, - -0.00604621204048865, - 0.030504777448346832, - -0.14194579844512237, - -0.02741923819785798, - 0.36963444873061296, - 0.09013321562283882, - 0.11245146517418105, - -0.05961778480847543, - -0.034578966943181084, - -0.06876799696996524, - -0.18917457199118792, - -0.04608919422268084, - -0.004486211264089318, - -0.07209670115965619, - 0.19561159091913327, - -0.03908832232420991, - -0.05556718640287308, - 0.17387793598994494, - 0.016969494202682567, - 0.043631933613564114, - 0.03230082539308798, - -0.16875826997099114, - -0.18642582159918433, - 0.15824343827396042, - -0.014621758275831719, - 0.24852709154215377, - 0.0029718858329558845, - 0.1707679295443776, - 0.08300875370481639, - -0.1425751694888312, - -0.1323794582456517, - 0.018853326556487467, - 0.2322400026444973, - -0.009264286381192284, - 0.12009129517137335, - -0.016817280796699457, - 0.16605438359310987 - ], - [ - -0.05297897742795535, - 0.059758154501855114, - 0.09220028374723703, - -0.18700207886198728, - 0.056381681885237664, - 0.1637771681575667, - 0.21000354889128126, - -0.08727220694560353, - 0.1514736761711902, - 0.10906557922254964, - -0.10553460225173888, - 0.026702268042350156, - -0.09000949535373566, - -0.024619874447595547, - -0.174305355293116, - -0.00366872360274729, - 0.03521402252970146, - -0.19568984788935928, - 0.02647241393710502, - 0.0995960985296854, - -0.011342547419193764, - 0.04041346519322393, - -0.16063649250553078, - 0.13315267777596534, - -0.023254801159296234, - 0.08415304857302688, - -0.06417197166682742, - 0.3052446208682781, - 0.14646136262956025, - 0.10628242338722668, - -0.08115816048271303, - 0.08387222328613402, - -0.0751030248419199, - 0.09277472154453503, - 0.12999104339817313, - -0.015248845976160937, - -0.003268014403120907, - 0.16448423837604997, - 0.12419703402007441, - -0.17191208704365915, - -0.07719070118385793, - -0.06591549209969627, - -0.06115698102201832, - 0.26895590351218435, - -0.14377674364697543, - -0.13794839256027272, - -0.08285113883839289, - -0.19460052684372792, - 0.002590998169454284, - -0.102813334099457, - -0.05520558408523293, - 0.18314937888028884, - -0.02846761276270928, - 0.14584938354868887, - -0.26226778519546745, - 0.2113980623483932, - 0.0442248950226512, - -0.24646331976060395, - 0.07111799376821804, - -0.06821537947022165, - -0.020113191837216764, - 0.05546207909285365, - -0.05453422362120044, - -0.00873193005161745 - ], - [ - 0.05511083695521416, - 0.01034053175332106, - 0.03712105534320238, - -0.014530652297409212, - 0.22587825262727035, - -0.04806369162904943, - -0.15439294702857376, - -0.045839707204365684, - -0.029679805523731267, - 0.09889568557956345, - -0.2074443631644402, - -0.12816504768340206, - 0.12761405114226404, - 0.21808841167075219, - 0.09465492286121686, - -0.023685668552614975, - -0.16156236983256858, - -0.2004496743604578, - 0.2044847507158304, - 0.0477615835871268, - -0.04443091344643775, - -0.13990868320419717, - -0.03417738845772152, - 0.007699417470959595, - -0.10025597248305022, - -0.0795131029991005, - 0.26794192552227925, - -0.032327357203697546, - 0.06254330912477472, - 0.24910510119018853, - 0.2568179864705282, - -0.053781072557728946, - -0.04016070863968777, - 0.22626036579526235, - -0.018481064979418753, - 0.14628523490114834, - 0.0787305133386705, - -0.06415847759732372, - -0.07100531089190826, - 0.01638659738323965, - -0.05286629875515554, - 0.12186779023115331, - 0.16428806844501237, - -0.08342181689676784, - -0.16041115107351497, - 0.03020576059322731, - -0.010626211573960083, - -0.07454743767939374, - -0.11589939433415708, - -0.22765680197057916, - -0.02457908055567512, - 0.1585090204946435, - -0.06273714184830712, - 0.1874677246798005, - 0.17254677074132493, - -0.1256501460920764, - 0.04768296334388696, - 0.06113409856104126, - 0.10240932585011195, - -0.08552390001971259, - 0.03518913510395632, - 0.08725210436654683, - 0.123543933896456, - -0.13300125056969198 - ], - [ - 0.14488511384567906, - 0.07052964101942177, - -0.10746843070567647, - -0.1772683222715246, - -0.044036662729599836, - 0.3164782576207125, - 0.0631078491525935, - -0.19008976112725073, - -0.01278094049394481, - 0.07213840958533763, - 0.028582482374692658, - 0.03444373233152908, - 0.06440849310564933, - -0.07022971766681126, - 0.09587254233556206, - -0.12742107439924713, - -0.14684024019247657, - 0.28554869640625724, - 0.299166852139899, - -0.05006051255120891, - -0.10212750246521887, - -0.07244681120049283, - 0.134059286800996, - 0.0005758461525130188, - 0.1114744284183955, - 0.22049965971073276, - 0.03403483235620176, - -0.06848430801804262, - -0.0214977528106192, - -0.009993740862113383, - -0.04629552138461539, - -0.031125369694597015, - -0.2388900642769731, - 0.0730748253291064, - -0.15629181600574363, - -0.1251672151289176, - 0.04231970455342098, - 0.14980732495392188, - 0.13649323952016706, - 0.060489872501104616, - 0.0650523596007536, - -0.21354822443832425, - -0.0320868985409114, - -0.14109538478541814, - 0.04897347440089205, - -0.09756066237138894, - -0.11131755801137846, - -0.1692818627588863, - -0.03139556313656107, - -0.07986160039320207, - 0.0658157915647664, - -0.18656027558078656, - 0.127354243477162, - 0.06713244502617206, - 0.15333795260619543, - 0.12515880492477272, - -0.027641477785758154, - 0.022689253191751208, - 0.09677069988850706, - 0.12547787882702735, - 0.028235299156442625, - 0.10494176166265137, - 0.17399881253924027, - -0.0012582481464238294 - ] - ] - }, - { - "layer": 1, - "rows": 24, - "ridge": 0.018549247334400814, - "mean": [ - -1.1489043235778809, - 0.6633487343788147, - -0.33107098937034607, - 1.440550446510315, - 0.753727912902832, - 1.2764240503311157, - 0.08712496608495712, - 0.2678806483745575, - -0.5330119132995605, - -0.7228863835334778, - 0.6753228306770325, - -1.935529351234436, - -0.11008074134588242, - 0.206154927611351, - 1.5101553201675415, - -0.20731449127197266, - 0.3162889778614044, - 1.8702863454818726, - -0.24037301540374756, - -0.34410205483436584, - 0.4802817106246948, - 0.22172844409942627, - -0.9607250094413757, - 0.5064640641212463, - -1.4034104347229004, - 0.4384218454360962, - -0.5915393233299255, - -0.02437714673578739, - -1.1723614931106567, - -0.03587258607149124, - 0.8888337016105652, - -0.16504190862178802, - -0.20525789260864258, - 0.9123387932777405, - 0.9835430979728699, - -0.0735071673989296, - 0.6846955418586731, - -0.2978948652744293, - -1.7445226907730103, - 0.1690688580274582, - 1.1819684505462646, - -0.22134970128536224, - 2.1560161113739014, - -0.07718279212713242, - -0.3251950740814209, - -0.9837756156921387, - 0.06553345173597336, - -0.5456608533859253, - 1.0326621532440186, - -0.5658420920372009, - 0.509735107421875, - -0.893397867679596, - -0.8804607391357422, - 1.460649847984314, - 0.7556697726249695, - 1.0270441770553589, - -1.192921757698059, - -0.06827763468027115, - -0.727931559085846, - -0.11067074537277222, - 0.4353121519088745, - 0.8252081871032715, - -0.29633963108062744, - 1.8864964246749878 - ], - "eigenvalues": [ - 0.26441547957025074, - 0.22348730665157338, - 0.20939793353643146, - 0.12837732664024984, - 0.0635406425101274, - 0.058816308081155906, - 0.05656547595030934, - 0.03791589765395543, - 0.03252796590602906, - 0.021604339948939722, - 0.016947496490150118, - 0.01313122346877728, - 0.01134353690601394, - 0.010148353901092777, - 0.00873542308790711, - 0.0074263180241002, - 0.006492017912821529, - 0.004637854943728049, - 0.003531743727887489, - 0.0029131056554900212, - 0.0022173369551304035, - 0.0016464337529068084, - 0.0013322977518218932 - ], - "basis": [ - [ - 0.18561854146378676, - -0.1244903821396661, - -0.052689490395209974, - 0.08728901907511992, - 0.03635921792111065, - -0.036595019018094685, - -0.04496815621269199, - 0.09586997046824297, - 0.15038549073003427, - 0.08218159616370074, - 0.08752228739289437, - -0.030992573670386592, - 0.047220388013318855, - -0.056041587815500477, - -0.11380584558064982, - 0.05389520154923095, - -0.10469900130683668, - -0.1363684322065957, - -0.1251847738882707, - -0.011155022126243046, - -0.12365331170225545, - -0.05440203242013426, - 0.20228150395188355, - -0.09248984043805178, - -0.2971911423535028, - -0.07290762268562381, - -0.0141833215707949, - 0.0023822237829105243, - 0.21649599718927084, - 0.07460220522764387, - 0.023067035830142062, - 0.005953292770421418, - -0.2007389705613163, - 0.14605995986614995, - 0.12495752442743076, - -0.2553326926057036, - -0.014568948827843887, - -0.10461635085555453, - 0.07623081017798083, - -0.1990537821272413, - 0.01074636210944023, - 0.045746127703386506, - 0.07015854386550752, - 0.055648505404001715, - 0.07141508174761262, - -0.04266363886893779, - 0.011618178145029568, - 0.08239622283201987, - -0.4051027854170284, - 0.02125626092091645, - -0.06580852940359058, - -0.02781425284619477, - 0.21364760941542904, - -0.10243047528798306, - 0.08753405048253098, - -0.08430797856448849, - -0.03959053314885185, - 0.1596658434981343, - -0.23777439375156117, - 0.21142110612369716, - 0.02832322599428069, - 0.10983479582867131, - 0.011332428329760108, - 0.04090777427869463 - ], - [ - 0.17246755413658924, - -0.15189638323953522, - 0.034642540573135865, - 0.0741362858768735, - 0.042930698835329385, - -0.07550922874350458, - 0.018298806985419774, - 0.12539640149272116, - -0.13443101907063867, - -0.0546978965132004, - 0.014916518036583476, - -0.07372402452104929, - -0.10345991670807833, - 0.2673279488330679, - -0.12261860325895266, - -0.16397087194179882, - -0.21197792486282663, - -0.0484093091321321, - -0.05269136785615713, - -0.0354360274983483, - 0.05560250945780912, - -0.008664696644671274, - -0.20356261996089942, - -0.07722507377340233, - -0.10064069534568958, - -0.021899106104470583, - 0.15948703911025394, - 0.1908391494794438, - 0.056423023749795354, - 0.04180539439709702, - -0.030397280825600906, - -0.05755255957509028, - -0.045741533879895324, - -0.02797354784720655, - -0.09397273207549513, - 0.010197244087822754, - -0.30477037624171177, - 0.06465629306767987, - -0.23383782987834803, - 0.024215647167897075, - 0.05905479754111552, - -0.07201614964682511, - 0.11145842631651719, - 0.1062990170017784, - 0.20664638253660655, - -0.2034141358406895, - -0.022572385827865735, - 0.03136278603144636, - 0.1148442619730067, - 0.05631725955187785, - -0.03650209171266956, - -0.24567312682641337, - -0.13824656120599518, - -0.11470395120261886, - 0.0708514680591638, - -0.05463051673925628, - -0.13321079339619907, - 0.08348916951230725, - 0.11828094810619402, - -0.20689758242426817, - -0.18614473700330184, - 0.14107649051507612, - 0.016145936958875076, - 0.21401540726781407 - ], - [ - 0.08557721442443394, - 0.03528609075344685, - 0.10893420492316161, - -0.1342806773761938, - 0.05537380960284429, - 0.06391054595797271, - 0.1188959965477664, - 0.014588687887791163, - -0.009105770928494348, - 0.05160408491435999, - -0.052942626035554406, - -0.21162216030543568, - 0.15507684406067762, - 0.16814127042103988, - -0.015512920591392435, - -0.18257517662157965, - -0.031325325537037985, - -0.12449290297958177, - 0.06564439915485767, - -0.005492674583834535, - -0.04652589318957427, - -0.0012744798079015495, - 0.1215387780133081, - 0.10489794007045802, - 0.06155597980190811, - -0.11644844062027962, - -0.14701935423216136, - 0.19475369947345983, - -0.08316451726810328, - -0.0806696642539961, - 0.13823070386790537, - -0.07722204564823655, - -0.2732936537696393, - -0.11640368406815987, - -0.06786308464803625, - -0.3150750899463616, - 0.2124324546429359, - 0.07476832336790504, - 0.10654880986664099, - -0.19824373444048105, - -0.15815423847310317, - 0.19773149030268902, - 0.14512878879666838, - -0.12905817148709692, - -0.09172901121327376, - -0.023798893956206907, - -0.19550034549874426, - 0.03832308429154702, - 0.18756199868242387, - 0.12264381774083946, - -0.01805625422460545, - -0.09374443536155654, - -0.029863556891285087, - -0.03917939883872907, - 0.03812115971085147, - -0.007655864357519177, - -0.11882320344535455, - 0.04557712031166979, - 0.19462922601904503, - -0.07785088795823858, - 0.07191817221818542, - -0.13526534069272286, - -0.08756112840114642, - -0.20279006589314255 - ], - [ - -0.2761914197038829, - -0.040821232587694545, - -0.06283352538633095, - -0.01076055674288171, - -0.044116718519021714, - 0.2098873092408958, - -0.0435567514579201, - -0.01741798759153005, - -0.14349349577664944, - -0.14978956340235453, - 0.22686529304870676, - 0.037747550809636, - -0.08093406815095788, - 0.22949266953642822, - 0.35600830176398846, - -0.0392640578319909, - 0.11035837185278244, - -0.06816584853090121, - 0.0440578756036902, - -0.18775785355189414, - -0.04956726590117212, - 0.09200146070851166, - -0.19696048960018203, - -0.10514238284248151, - -0.008338754824415899, - -0.005227462462315418, - 0.08613989417773706, - -0.024745403069105425, - 0.13168550850121366, - 0.10682666754838753, - -0.022982876119631762, - 0.15619899887971858, - -0.10258401080863357, - 0.004611362670950657, - 0.05608598185161964, - -0.06800232825480924, - 0.18217792516420905, - -0.11542117689597871, - 0.18325996615116175, - -0.14108666208530274, - -0.19809359820288458, - 0.04962974873030317, - 0.06148025982233224, - 0.19742250397638808, - -0.04492235226616992, - -0.07653183474856338, - 0.14812203032711208, - -0.10122031876165172, - -0.065454950256793, - 0.14244945742474346, - -0.19611597836290193, - -0.1319376340977306, - -0.07062330741066494, - -0.0009747119924189124, - -0.04711075175939683, - 0.055706201774012455, - 0.024588134663947242, - -0.14433620246683113, - -0.09955737874269356, - -0.10293788294612374, - -0.028704757999913445, - 0.17640261942204044, - 0.02939857843146983, - -0.03776597796596056 - ], - [ - -0.0018091625983460895, - -0.34494257681388824, - -0.027114350222101437, - 0.1041015490985989, - -0.20936678919991603, - -0.12351366953321048, - -0.09167775490177037, - -0.09704958020492989, - -0.03729742498393279, - -0.054697804464628866, - -0.09682293628110991, - 0.20287472542374319, - 0.031069273422238333, - 0.060703969950183886, - -0.15839589476557847, - -0.1577775066491867, - 0.07614501931451036, - 0.010048465815907083, - -0.012512510848633578, - -0.10813902580286336, - 0.07916519313334895, - -0.12679617628876058, - 0.03719817871038231, - -0.23649098588644274, - -0.07234738724836481, - -0.06547095883462334, - -0.009041633871907163, - 0.06608835107922019, - 0.23125030254666543, - 0.1527203919719078, - 0.08436500441329263, - 0.051460580842629985, - 0.10757769215376833, - 0.10034605696253418, - -0.1391978496426413, - -0.03333403805061485, - 0.020260652717491837, - -0.14019714758634022, - -0.132633932538606, - 0.09112303857653752, - -0.2793089635871158, - -0.03470081797359518, - -0.033410031212089145, - -0.027343926982861262, - -0.04484923338140393, - -0.08763982593013399, - -0.036116313514696005, - 0.02077334170514036, - 0.1703905956572415, - -0.14791101942383023, - 0.09475693265955297, - 0.05045844835213525, - -0.07351839443917872, - 0.025374805168957546, - 0.18244909173829973, - 0.11692752477713263, - -0.015109874595412588, - -0.10111671122018102, - -0.046615091089392865, - 0.09203777792816421, - 0.1568412003051731, - -0.12776743244478028, - -0.028667597036041916, - -0.3551736743323275 - ], - [ - -0.231087516439437, - 0.01256190459895877, - 0.06247154775502521, - -0.09433737892162933, - -0.17283995734792423, - 0.1439710266701546, - -0.13254616194770402, - 0.08649446799775848, - -0.01495339056729157, - 0.13793335732949957, - -0.21403205286148347, - 0.02641981599604341, - 0.01037238113040618, - -0.2904888134070498, - -0.1470768868462738, - -0.0032097525220365908, - -0.1905176655159088, - -0.04331685727580702, - 0.008880234527809897, - 0.13732764990646312, - -0.011720803728292855, - -0.07348699731049153, - 0.11178856452404913, - -0.18253766122403606, - 0.17625255632440925, - 0.08270401504800977, - -0.04774146660663766, - 0.20201959358519958, - 0.17039656956889562, - -0.02584064900454661, - -0.1311178814734365, - -0.12576019049382559, - -0.05758938823143225, - -0.011625457515828802, - -0.04844210986471822, - -0.004708199608734007, - 0.024731069308584132, - -0.008239828543490488, - 0.21127704153436416, - 0.08845467159682045, - 0.0624267446626761, - -0.038805915279079714, - 0.01606281172057577, - -0.14386694682456955, - 0.0249311945329919, - -0.0028422361078653856, - 0.3170846225139061, - -0.037442336425141505, - -0.14491329146842533, - 0.10147657743120739, - -0.12864130874199567, - -0.1765633815735491, - -0.19294014576260696, - -0.14791402370556903, - 0.13225239847247502, - 0.19540117234945614, - 0.0055967915512033254, - 0.020972807616123763, - 0.07369882651582546, - -0.19688108497053133, - 0.04880051518875064, - -0.002893349712947497, - 0.06996256660380362, - 0.01683568806583281 - ], - [ - 0.05906723192313716, - 0.14085508085468543, - -0.12487455571707248, - -0.06994319731141642, - 0.12948799256500487, - 0.3448141716096929, - 0.07298865188162276, - -0.06372432972111607, - 0.03188299059891601, - -0.0020067979986361697, - -0.15243768579037464, - -0.058709522443374296, - -0.09251109077199676, - -0.2101417646372229, - 0.046127095826705, - -0.032243050324681485, - 0.0660750856972944, - -0.047931105354538296, - -0.12918877375229845, - -0.2038852895829952, - 0.07171149863357504, - -0.1701066432178085, - 0.012213677727804201, - 0.1776158331964867, - 0.05699445609171152, - 0.010104919341109856, - -0.05679815256423945, - -0.30026430797845943, - 0.22020002562746388, - -0.04996438184465507, - 0.27995821449073355, - 0.030467156974313007, - 0.045015892852466786, - 0.1470140213164601, - -0.20353297409348148, - -0.14912839207326584, - 0.045600045024497216, - -0.02845432724186177, - -0.12960046039930279, - 0.025845926556098724, - -0.09583527769183961, - -0.12416571205605047, - -0.012822132235177931, - 0.0510744880994781, - 0.062266855870335584, - 0.016758862736393827, - 0.1195838441180438, - 0.05409359174428171, - 0.1076267529250293, - -0.056216347974728895, - 0.13007090604346125, - -0.1363883820898243, - -0.1766963939756545, - -0.19000539920452034, - 0.03151670189118376, - -0.18083538211559214, - -0.1440507407958139, - -0.012867521746437518, - -0.06963320889638619, - -0.016164194597639858, - 0.05161415908162834, - 0.008167422360469767, - -0.07731839453606773, - 0.16548978909056722 - ], - [ - 0.058476802243240186, - -0.10523476847672426, - 0.13517043773402393, - 0.04245611827991708, - -0.09642864454272913, - -0.08705357197140516, - -0.059071063548343225, - 0.04730265591702142, - 0.11702717132086755, - -0.12519181639776747, - -0.2219915151145793, - -0.0927772761562695, - 0.1267819420821718, - -0.11332025421738755, - 0.0006258310694300573, - -0.17176384246921017, - -0.09802965514527107, - 0.15182390201139676, - -0.08471808073074867, - 0.01676709190997864, - 0.1086417059357896, - 0.30110987113760107, - -0.0641372506416219, - -0.06716376657127611, - -0.09600231373185593, - -0.035596383550975004, - 0.13427143666399993, - -0.12208471738126148, - -0.2902320536226415, - 0.11931097182055882, - 0.00934031170922533, - 0.33896450082620927, - -0.050198730625774755, - 0.1238627593481677, - -0.1074211938867818, - -0.0351761977565449, - 0.2741416937175946, - 0.10263372821718118, - 0.0723449406035698, - 0.12933784038997986, - -0.042240401176843745, - -0.1941823490472717, - -0.022552974683355743, - -0.05349379355361445, - -0.15948976949042548, - -0.13726823840737615, - -0.041986473058130094, - -0.10841549288451612, - -0.18334845354194135, - 0.029039285665123527, - 0.025349612316338147, - -0.09924884110547945, - 0.08434991791055443, - -0.08858715245825877, - -0.050937479196719745, - -0.08456787887091292, - -0.13088694162570585, - -0.04005610104610097, - -0.027286586972833735, - -0.15041711053197623, - 0.0845186700578376, - -0.08068318297451475, - -0.05030587125363253, - 0.1489057572459153 - ], - [ - -0.11881562189297139, - 0.07695265381923075, - 0.19392678778921016, - 0.01531005982328198, - -0.13332299909555378, - -0.1500164472558404, - 0.0020441133084808543, - -0.028950267932879043, - 0.07545822012242298, - -0.023431347058652272, - 0.05333495347259421, - -0.13494966149413606, - 0.03004504936029312, - -0.09367852015462777, - 0.14160475323881555, - -0.07444734946810339, - 0.0002707849375070147, - 0.057570654002777846, - 0.17043108831800835, - -0.02578365236341236, - 0.06710188933308868, - -0.3488137903068996, - 0.0834243539352258, - 0.17229302347260636, - -0.19282639456832268, - -0.020447374442166523, - -0.22051232731551168, - -0.02542293486467567, - -0.07070338744748372, - 0.12098147513386386, - -0.0006817031634018828, - -0.004456073221073512, - 0.17165803942306415, - 0.15691504570266362, - 0.187859049932473, - 0.11620054723283442, - -0.12161831786166022, - -0.014581945484856657, - -0.12871787082756708, - -0.06351434179635698, - -0.08286474956815003, - 0.20438855938730086, - 0.0062622351406010765, - -0.08413628938716593, - 0.08957405249001926, - -0.19754119048590746, - 0.1225407039533092, - -0.024269193493718623, - -0.10414358349072128, - -0.011664034216517783, - -0.1524204852557195, - -0.11185810487113806, - 0.028878056127646518, - 0.06912413240023219, - -0.15370006456297347, - 0.07774250246202592, - -0.38194591670245126, - -0.17195718413421124, - 0.0461525316738253, - -0.061220081138170325, - 0.019640981234419506, - -0.056298488822644994, - -0.10251276419923377, - 0.04188138344884852 - ], - [ - -0.2633740431981046, - -0.016726049268449467, - 0.1603431826686986, - -0.09518111584517891, - 0.17642511627307794, - -0.18019749693588716, - 0.11205286048007009, - 0.017300378416075877, - -0.07563634276092152, - -0.2744494450012607, - 0.058066802415576525, - 0.033885883249088464, - -0.32921485587159477, - -0.2253544363195603, - -0.06417817005553397, - 0.09615908168721403, - 0.01598028418662105, - 0.013887260197308309, - -0.1857068992284867, - -0.09152775750952223, - -0.02330201967300897, - -0.0018591504102516707, - 0.08118755660160194, - 0.2541537519423217, - 0.04107597590585483, - -0.06549990619086062, - 0.08797408443080562, - 0.2285393924584214, - 0.11302926607998912, - 0.21332604692105056, - 0.1474784646723322, - -0.0058424045263395135, - -0.04004357081028818, - -0.0956126227142363, - 0.003573568126856145, - -0.07933122317317969, - -0.09421220376325198, - 0.09028617000290393, - 0.17056035399234992, - 0.04975491655047963, - -0.008977492038489646, - -0.19938555456506007, - -0.0017525871349685232, - -0.024053463032416653, - 0.06104718718433104, - -0.23345324760319736, - -0.188377135302403, - 0.014226250509216866, - -0.1403074331832285, - 0.09890935110509415, - 0.04043969571616859, - 0.14911398660167904, - -0.10504309431424523, - 0.0211760654070414, - -0.09123866045905281, - -0.06442582180773151, - 0.014533407731437216, - -0.0013502537142724151, - 0.02232241108809075, - 0.0195240547127977, - 0.018588659968238826, - -0.08458129544371246, - 0.017158180273193876, - -0.11754234560704407 - ], - [ - -0.133753939644675, - 0.16450243787735638, - -0.09083167135964791, - -0.04873038902931792, - -0.07815398932816793, - -0.15277435445100837, - 0.018148780175351813, - -0.13475255639521178, - -0.14376448215855006, - 0.1760105860573163, - -0.25884254339739937, - -0.08372696892740013, - -0.1546696767437112, - 0.04765364018446176, - 0.18873346854799783, - -0.047444890661496146, - -0.0348551263104836, - -0.10952802418527068, - -0.2659216713287821, - -0.13367009666971516, - 0.013176711929669866, - 0.17390671188895224, - -0.06981951010037006, - -0.0847903551628021, - -0.08146246221550851, - -0.17415298027972595, - 0.00668887367925656, - 0.03424981422050166, - -0.051682958781255235, - -0.2541748338617599, - 0.10472331191437145, - -0.08848930331453908, - -0.2174311149489526, - 0.05006245470069982, - -0.08915054034709384, - 0.09956022177347043, - -0.015119956655015053, - -0.08164211741812005, - -0.29369301076626253, - -0.03545596152532241, - 0.1328343405404987, - 0.034759902792810535, - -0.11775991669689298, - -0.0698252353841103, - -0.07168407880362264, - -0.09190631029029535, - 0.14372867231281306, - 0.1799810904307277, - -0.2301409787601561, - -0.042911676737466604, - -0.051799221410518174, - 0.06093284350893769, - 0.06206434790336867, - 0.0663136065020051, - -0.03241286650080662, - -0.036639257442828976, - -0.04770166696058881, - -0.12643518009147942, - 0.05451883176944516, - 0.015905896975120723, - -0.07396421338892724, - -0.0437478629880258, - 0.14311523692045988, - -0.2252875983697501 - ], - [ - -0.0934120771055082, - -0.01943913424783601, - -0.3392277813430225, - 0.05255124981135854, - -0.0777590204174273, - 0.0709496772237848, - 0.04842332667011626, - -0.032834386001719514, - -0.022992468188851554, - 0.1595505989595102, - 0.09457762591019299, - 0.04216507435325362, - -0.0822682335073145, - 0.05921586738557694, - 0.06342278736655561, - 0.07896557708836549, - -0.033504921853828425, - 0.013563286372099729, - 0.16302110237636339, - 0.1859637628154692, - 0.21711567960617442, - 0.0946595763669909, - 0.039158325892866545, - -0.01694475158707745, - 0.02989938430964144, - -0.07380063558083604, - -0.1115404853116929, - -0.06013318819554964, - -0.047159282222949045, - 0.15649599289535468, - 0.20510246834965687, - 0.04357224969726097, - -0.15222545639605173, - 0.059569824668188526, - -0.044889680394005406, - -0.0628069691457372, - -0.008101980672800515, - 0.34174422827824347, - -0.10169086688661254, - -0.0919838163611315, - 0.026616057035584017, - -0.15249691568140764, - 0.18190729075097764, - 0.042379402254142426, - 0.3031045670768988, - -0.03972708631839641, - -0.018857089335029366, - -0.04920483952947015, - -0.14216102379477252, - -0.05567120535052656, - 0.16920589434909195, - 0.12029583108093937, - 0.0878276813296404, - -0.061119632220889446, - -0.04726814438172233, - 0.39374609520539905, - 0.011559278458105835, - -0.029697051507928587, - 0.08004368184167668, - -0.07390482859666499, - 0.05461405671218271, - -0.05787019783331508, - -0.10029206946286322, - -0.005657902051914587 - ], - [ - 0.09972225510326602, - -0.09400410034785436, - 0.06421857941633388, - 0.07060186240055907, - -0.04916535955143286, - -0.12135504060315824, - 0.20846682407828715, - -0.019956025144828055, - -0.31096954696747764, - 0.23675845613081287, - -0.10515361565158308, - 0.027082488741822362, - -0.09340121107482391, - -0.03847051126204401, - -0.028604051581247174, - -0.08096960877914806, - 0.051681189579698965, - -0.0992240133181202, - -0.06469686726927938, - -0.05554168803694849, - 0.0028145875613645984, - 0.1559071260909351, - 0.16471121282281515, - -0.0663771247187874, - 0.2536974357910177, - -0.13421125604551054, - -0.12438024499381929, - 0.014417183411528412, - 0.02533846882574442, - 0.14772556246700022, - -0.03625135926858352, - 0.2066456778603282, - 0.19585657998210768, - 0.11334444593586439, - 0.14467677608680446, - 0.020164663822295422, - -0.014594824450268417, - 0.10622367538211, - 0.09216113870595424, - -0.20188971079038553, - 0.1171845909549993, - 0.052947483045384006, - 0.02781513095968739, - 0.10986343581320485, - 0.10934287689696043, - 0.08730686126156349, - 0.16557318332690985, - -0.28386042054688215, - 0.024995146576116904, - -0.10669665264850615, - -0.025221128362143096, - -0.15345901619925933, - -0.05754369212526968, - 0.035892351537300624, - -0.1399320895353267, - -0.29210374771506953, - 0.046674693402321124, - 0.0744025535104595, - 0.12250854851310482, - 0.11962813106638158, - 0.025880693296790287, - 0.021284776956441556, - -0.09269286607710231, - -0.07822982424363707 - ], - [ - 0.10317462817559042, - -0.05768782339001765, - 0.14218515966629836, - -0.19759990017182524, - 0.0037690501961843066, - 0.044580093851318524, - -0.11999745870327154, - 0.19381891206816063, - -0.2240090158407062, - 0.015004663628581523, - -0.05832029458586678, - -0.2523625997121961, - -0.013241255866047592, - -0.029791301106564836, - -0.07333868448584407, - -0.06566259989394804, - 0.17223037115297263, - -0.13482781426823637, - -0.10478838602165562, - 0.03203257491444246, - 0.2967022347377036, - 0.16670925561506564, - 0.18354551886017043, - 0.022060223880240412, - -0.10091800128066158, - 0.17070549143178976, - -0.056655657921037404, - 0.03997564487763238, - -0.16801935532472947, - 0.14135358088047545, - 0.17179414154277545, - -0.0989535697580435, - 0.05709684513084334, - -0.08989022264565855, - -0.05139228516616358, - -0.032319930621401864, - -0.0967430727648608, - -0.21679920656065926, - 0.12146017773886524, - -0.03218528975849047, - 0.0250324084056984, - -0.021118778558912286, - -0.04191750193155279, - 0.16462572047356205, - -0.04963798435789465, - 0.10925424856332396, - 0.04597379782653194, - 0.09976767750581271, - 0.015278640083500591, - -0.13053777244192735, - 0.06786069393413678, - 0.08017546638484872, - -0.01856464715582818, - 0.16791600158380768, - 0.001610790324957948, - 0.2386601520313936, - -0.05210331619609044, - -0.163661723419408, - -0.0931492757992408, - -0.003146440966004867, - 0.031531306991557186, - 0.3191249059575137, - -0.04117503906303856, - 0.054354218529937146 - ], - [ - 0.018260779386174528, - 0.08565073568326168, - 0.1795133891786318, - 0.09038873047643463, - -0.03929780146424896, - -0.023888857514270525, - 0.22922337694770573, - 0.06582349700249772, - 0.2248256613406198, - 0.0047332986885326375, - -0.15980772730506462, - 0.03878563163400457, - -0.014451191808894056, - 0.027971709022582794, - 0.2276239736877064, - 0.2114900798281658, - -0.12822003499124343, - -0.13016987830202928, - 0.06808660548001307, - -0.1377480069917501, - 0.2981553622329007, - -0.015150566669040957, - 0.07344855619074091, - 0.06072118071075531, - -0.18225782968280357, - 0.02140508336174068, - 0.10935954519434839, - -0.06657332287115814, - 0.06472679722667136, - 0.05825015662629415, - 0.002942151939933558, - -0.09389344226476147, - 0.06988270379258336, - -0.047824741093431634, - -0.10045788015239676, - 0.038231994678942574, - -0.07364769045140443, - 0.04498473778214195, - 0.05061308511193058, - 0.026848856705083995, - 0.08569164340381694, - 0.19358126412427465, - -0.007140214884876833, - 0.08354090110649161, - -0.12268759715817236, - -0.03749817799910906, - 0.007462624683519681, - -0.3278186921741745, - 0.013405516302536417, - 0.09464119879265478, - 0.28332330756498225, - -0.11299801122140625, - 0.08543142884624987, - -0.07760685459134468, - 0.15505333618732245, - 0.053514814865079544, - 0.13554037011354902, - 0.12032142833175334, - -0.045511485679665835, - -0.13781699257700733, - -0.046709375630042155, - 0.11629950787065517, - 0.09535589101023566, - -0.26405488913457564 - ], - [ - 0.15882174374790003, - -0.06453376949847256, - 0.015040785067286124, - -0.22016780692868293, - -0.06179423029703475, - 0.06202318968201503, - -0.1322024257158808, - 0.11406572018516796, - 0.051615882136467076, - 0.08857149410504285, - 0.2347870007158244, - -0.03825858440245556, - 0.019711671918031314, - -0.12663606820209053, - 0.2270677067808898, - -0.07063414260225118, - -0.3166248722713296, - -0.11431671557117802, - -0.009224357208146423, - -0.17295647767669411, - -0.018024612103554594, - -0.09457217037896516, - 0.04490256185238353, - -0.019582473617462955, - 0.23108893728306548, - -0.10231361934124285, - -0.06060721549355099, - 0.023527952714828704, - 0.060843244732449876, - 0.11603855781558066, - -0.06045467922032963, - 0.226246693209622, - -0.006944265836496312, - 0.2383843374443002, - -0.2507424206384857, - 0.008124129687281881, - -0.12369079093450122, - 0.0077709878548989485, - 0.02405719479264199, - 0.007097791039118544, - 0.1910885453073841, - 0.0065926161569009436, - -0.20357150924177536, - -0.16633527975714596, - 0.050054442793029015, - -0.013308284979173532, - -0.21128464813219705, - 0.04780769847533206, - 0.1546823093246861, - 0.09696334439337712, - -0.05588606478363467, - 0.0786067530887363, - 0.18397016342965564, - 0.059176206690191364, - -0.037403243328622555, - 0.03970838039997078, - 0.1301325973975027, - -0.20499919225940413, - -0.004521892150389181, - -0.020111777530537903, - -0.02121302720227433, - 0.08154638151154231, - 0.08622024858091654, - -0.025341968236836637 - ], - [ - -0.004552593168143245, - -0.15847409663843828, - 0.03190452616919567, - 0.09208983180951671, - 0.14085696899566202, - 0.2893687619180082, - -0.008743632627082342, - -0.03347621582488191, - 0.07328266261263922, - 0.16328146942528518, - -0.09651897023027874, - 0.004192451297811964, - -0.06835944506069662, - -0.062449144781166706, - -0.08935981739192307, - 0.22986097988743295, - 0.06761591810716044, - 0.19358831342508895, - -0.16278708206496673, - -0.08184265196742618, - -0.038920596782189135, - 0.18692563475195895, - -0.16986611861033768, - -0.031598422903842474, - 0.02765177690393123, - -0.005089318969592217, - -0.20323171312042462, - 0.05169919710635433, - 0.06350838890825135, - 0.06204031448527376, - -0.07353381027928338, - 0.0017469377913494966, - -0.08686475148551157, - 0.0037689016844042428, - 0.02010753189385071, - 0.19422370963880686, - -0.040999072607673506, - -0.20296246664783016, - -0.0373744540199529, - -0.06905447613079196, - 0.12585818423937178, - 0.0905814666754486, - 0.3242726668448106, - -0.17749127185207136, - 0.04693593714482103, - -0.03988899386813372, - -0.24388792551309685, - -0.17204476202847202, - 0.04966652719083631, - 0.08731336623592006, - 0.06925569999320456, - -0.0696663931976126, - 0.020194576542839366, - 0.24888381364706266, - 0.0247615825817797, - 0.017877029149248783, - -0.2580696042751331, - -0.10714785293284455, - -0.12315854998482084, - -0.059163316899602476, - 0.11859447346772753, - -0.012729558116450239, - 0.08898927682779718, - -0.00044949680655604067 - ], - [ - -0.020713632284984188, - -0.044044690839757025, - -0.07044746907571799, - -0.15507420432063757, - 0.11860378685412168, - 0.1302497047667436, - -0.03748619433995162, - -0.13864245956899723, - 0.07423477520525176, - -0.13729635738048085, - -0.04995577628643293, - -0.013461220523311501, - 0.0744994163900226, - 0.07810692854840232, - -0.08976896351728446, - -0.01689473608095276, - -0.037995008583086146, - 0.1269869047818272, - 0.0006642806393155561, - 0.08193939935349152, - 0.23614583662594615, - -0.02792097079040446, - 0.006667184840406423, - -0.1391274461990727, - -0.1419296247178083, - -0.13483541474187052, - 0.20122240933831606, - 0.16306421646666835, - 0.15998149992659913, - -0.28447614363240076, - -0.04053549103716261, - 0.07760178729158372, - 0.01052685013753647, - 0.0006359307601249729, - 0.07078636918435055, - -0.2577246670523249, - -0.0272208700032085, - 0.13745755255566275, - 0.08578078016531471, - 0.06541088587652999, - 0.23931599175238738, - 0.24963484859382643, - -0.11563140415068796, - -0.008438547614206047, - 0.10062367337110618, - -0.1450878478858462, - 0.15255127493464934, - -0.19684366340197265, - 0.08686039418116911, - -0.049845056471271014, - 0.06419141075701823, - 0.18035465509410248, - -0.06991816707365202, - 0.13187903814295843, - -0.21569948207112988, - -0.07618414745220672, - -0.051066416632851164, - -0.19549426568472125, - -0.015656263516770765, - 0.10284026813613803, - 0.19002692584675074, - 0.06061987970395083, - -0.04435345424272213, - 0.07986255586997415 - ], - [ - 0.21052305941407762, - 0.16956570266745175, - -0.17347681566561776, - -0.006927646301849815, - -0.05207789195071379, - -0.075280011560141, - -0.26457013134088864, - -0.006211339078304553, - -0.12819046184079766, - -0.023166638753785933, - -0.06024348194353001, - 0.0811651977438542, - -0.10367607725778845, - -0.12927736685459823, - 0.059235249956104435, - 0.21272916923790197, - 0.09382652848370335, - 0.020229615090704596, - -0.03069494057563773, - -0.17713581469868664, - -0.1754268372481705, - -0.10333601376567972, - 0.06281538989527048, - -0.1617471865636762, - -0.03321571092587665, - 0.18306393601761514, - 0.07692600876785108, - 0.08927706120126791, - -0.03623321990621002, - -0.07578594887237125, - -0.06596139058102346, - 0.06281796063669283, - 0.10207746735306361, - 0.06599586802789029, - 0.14399723563326747, - -0.1409452856957908, - 0.049412582874386934, - -0.02538051688318111, - -0.07296838302820248, - -0.1888893087380574, - 0.08125523153770663, - -0.0025317342201609215, - -0.10071895302538134, - 0.19594218032877353, - -0.17343275859815627, - -0.14902218760703279, - -0.21833970005702932, - -0.01407543540545711, - -0.016883242792200718, - 0.0728899609787853, - 0.1815610702697295, - -0.08574025560007856, - -0.043823259778919106, - 0.00824564782847198, - -0.08448017882548674, - 0.1694481800208763, - -0.07420195620447297, - 0.10726117669696196, - 0.3040469239325118, - -0.1921202644813693, - 0.22457179677744313, - 0.010453457960284844, - -0.04512652909963739, - 0.02335769478663135 - ], - [ - -0.045347048232780005, - -0.09195646699155902, - -0.020239079969375393, - -0.09312960474175988, - 0.12610268813697698, - 0.13903771910824014, - -0.11447451301613808, - 0.2241965567763764, - 0.0886446702986254, - -0.07286281556311125, - -0.2992655146981084, - -0.09224136971084582, - 0.021002810283460675, - 0.15557451949296824, - 0.14108495220514458, - 0.29950890471476704, - -0.023420516482597624, - -0.3106480422310301, - 0.12142350219896647, - 0.09395805380598635, - -0.15508343239368055, - 0.07375876220938879, - 0.15038968146320378, - -0.08425517334215568, - 0.02365764210881004, - 0.0019572583451003046, - 0.17058662516116105, - 0.09956983180322401, - -0.05506552557743079, - -0.010048701281615433, - -0.024363006764807443, - 0.0899904322374222, - 0.15587087299991265, - 0.024793558799227768, - -0.0731513383020278, - 0.12181230443246904, - -0.10552686649608957, - 0.006878436775935459, - 0.0034244169164310222, - -0.029812939559155316, - -0.21991673938425754, - 0.0033853444591114804, - -0.042330472918252336, - 0.1414338309733141, - 0.20569748389126508, - 0.09190286213858781, - -0.06711391324737531, - -0.02725804963129182, - -0.032425147728346836, - -0.08804434150706843, - -0.06308737043125877, - 0.10322034857779865, - 0.00031514943850256724, - -0.09883869989722568, - -0.0555458730843416, - -0.08433418183191309, - -0.21101865555776725, - -0.11021535545636335, - 0.015088676889076297, - 0.06881417665834702, - -0.027488300667568615, - -0.3179856483322248, - 0.12149849294270716, - -0.006759832979587448 - ], - [ - -0.05142431772926939, - -0.1488459911337232, - 0.03758711537855182, - 0.0739557035231855, - 0.04216474407951226, - 0.12259163644541078, - 0.041863597338565005, - 0.04968934704232, - -0.0057529053323595565, - 0.023936755699619488, - 0.18473015177050223, - -0.11946027617843823, - 0.2757613437351149, - 0.2476423279463075, - -0.1078297477039683, - 0.2164791650649615, - 0.3062612825831113, - 0.06860471030672696, - -0.12633389830589456, - -0.0740964451222276, - 0.04613304434427913, - -0.14853912830905516, - 0.004961749416074886, - 0.15415257648592606, - 0.12251741500499772, - 0.03192934542875777, - -0.07146237701870695, - 0.1109447139393473, - -0.13871990766154346, - -0.07848268488484603, - -0.06296752015697682, - 0.023092146167531646, - 0.08405026442188625, - 0.16832890051122973, - -0.2863819128637091, - -0.06828464587906621, - 0.014552584813609435, - -0.04242461377056174, - -0.03934358013558233, - 0.062191550815200856, - 0.08287328778170391, - -0.06328278315565082, - -0.13604999315146923, - -0.043114483932022725, - 0.015959919263233157, - -0.1490503827498776, - 0.06324457926846293, - -0.08646476247065243, - -0.36875917591383567, - -0.009968683102860941, - 0.049374311683510363, - -0.12482371552547095, - -0.06682151844815482, - 0.0024546236776833556, - 0.11005413215336424, - -0.005140561483958218, - 0.12650933543062637, - -0.040092316375158955, - 0.2714481563436287, - 0.10186901766376445, - -0.04428786529623539, - -0.008086211103056797, - 0.033354414083676356, - -0.030522924663160967 - ], - [ - -0.2489178798324397, - -0.14000797630051323, - 0.01677543509016992, - -0.02957670554585348, - -0.05102820462093573, - -0.1939867803222319, - 0.20368051941944748, - -0.0408623495473143, - 0.13566980347495855, - 0.06442538821346788, - -0.05350869140411388, - 0.13360424158680329, - -0.07074662754747031, - 0.1638188807042922, - -9.579237720866767e-05, - 0.049704586212383266, - 0.07247513842438912, - 0.06826378809773055, - 0.11583960351738591, - -0.0369796857169066, - -0.07611305408377418, - 0.04442028949139412, - 0.25605706763593344, - 0.13551786255622317, - 0.06232090224704711, - -0.0095402799929396, - 0.22167963210494532, - -0.016147821860509625, - -0.024450386393310673, - -0.18271810281881595, - -0.05338567445012451, - 0.10541586527173417, - -0.05612356990654734, - 0.24635275176008056, - 0.13310708304975838, - -0.08301846881304754, - -0.0524061064399652, - -0.07256422292305902, - 0.019836192012791548, - -0.03148182845379764, - 0.1036377043067739, - -0.09144344065242979, - 0.04109742594477234, - -0.09699148159414765, - 0.025425167332318404, - 0.28826635747730966, - -0.13786584152404924, - 0.18706888124227578, - 0.04261967345950507, - -0.03574975268370387, - 0.06046483392956596, - -0.06412897755971239, - -0.06488077812980621, - -0.09229468800565829, - 0.1887432476783527, - -0.022459216670536273, - -0.14545827938897424, - -0.20846031110930557, - 0.03515839148275562, - -0.1799095223875974, - 0.11675687320842418, - 0.3096082568722649, - -0.03721486883882454, - 0.06315095032388196 - ], - [ - -0.08071808717792091, - 0.032530345375056884, - 0.048276772477567995, - 0.01971771477558885, - 0.2690323400486781, - -0.05396651120408271, - -0.08279127826617243, - -0.20336294185337886, - -0.12314774604101045, - 0.02413794945477012, - 0.034620364676255545, - -0.10619049641471287, - -0.009381263366890786, - 0.06455412484678946, - 0.008180727991743507, - -0.042553389200524906, - -0.13144065414392828, - -0.1290349045977483, - 0.11715995965672826, - 0.009322777799716592, - -0.01877918955423276, - -0.017479647314930267, - 0.21099825390222535, - -0.05040785490860799, - -0.027037151986143686, - 0.11776888069869051, - -0.003576266833018248, - -0.07459270552206147, - -0.07592256048904432, - 0.1378390804860965, - -0.014749333774253567, - 0.04381110207901955, - -0.1255279437522668, - 0.4132169895045603, - -0.022890823924205304, - 0.08972452078426359, - 0.11266603636443165, - -0.04757380071112512, - -0.06052212117835889, - 0.2200021513351258, - 0.11356433128640814, - 0.2020212965971872, - 0.2650806019029492, - 0.13035695152100593, - -0.13431378721603093, - -0.10842242025400001, - -0.0005038649128141699, - -0.009753355919460891, - 0.010774793516328134, - 0.013953658349337112, - 0.0011775501486861167, - 0.2488244877526759, - -0.32580950301385053, - 0.09719654752251138, - 0.14052694347724423, - -0.0023983549442779693, - 0.1118218550938098, - 0.14643925109328446, - -0.0045257103760680175, - -0.006813543850201141, - -0.014793443282436074, - -0.08636318716944667, - 0.0723811435803278, - 0.10880911095501625 - ] - ] - }, - { - "layer": 2, - "rows": 24, - "ridge": 0.0343712717294693, - "mean": [ - -1.1361581087112427, - 1.0497184991836548, - 0.15657716989517212, - 1.0506705045700073, - 1.0729295015335083, - 1.2391597032546997, - 0.1344860941171646, - -0.13217882812023163, - -0.8580735325813293, - -0.26820001006126404, - 0.47560444474220276, - -1.960870623588562, - -0.019228162243962288, - 0.7597949504852295, - 1.8830032348632812, - -0.17108698189258575, - 1.1172285079956055, - 1.045040488243103, - 0.49296119809150696, - -1.0516003370285034, - 0.4499054253101349, - 0.313809335231781, - -0.3049377202987671, - 0.28736281394958496, - -0.9285039901733398, - -0.8964965343475342, - -0.738171398639679, - -0.25477078557014465, - -0.4410940110683441, - -0.3950026333332062, - 1.0224733352661133, - 0.43456801772117615, - -0.0002316435129614547, - 1.1087088584899902, - 1.0855498313903809, - 0.2119826078414917, - 0.7086305022239685, - -0.10458102077245712, - -1.440147876739502, - 0.3865603506565094, - 0.9631733298301697, - 0.5327298641204834, - 2.3079001903533936, - -1.351157307624817, - 0.507755696773529, - -1.0545552968978882, - -0.9975010752677917, - 0.04781806468963623, - 0.8516592979431152, - 0.1026468351483345, - 0.12864351272583008, - -0.8022353649139404, - -1.0394779443740845, - 0.9660735726356506, - 0.6907410025596619, - 1.6428762674331665, - -1.2846468687057495, - -0.6637190580368042, - -0.022738197818398476, - -0.8345139026641846, - 0.3874208927154541, - 0.21338553726673126, - -0.8968024253845215, - 1.8283790349960327 - ], - "eigenvalues": [ - 0.6159790919401288, - 0.4080878402622932, - 0.3308281360914219, - 0.20273327881995942, - 0.1687627599645152, - 0.09166073007569338, - 0.0862253737429995, - 0.05227535954489049, - 0.047114751462291514, - 0.03874054999755907, - 0.02756583712051465, - 0.025000360316712, - 0.019009281146965942, - 0.017167149396733607, - 0.01572816042578733, - 0.014214839560706655, - 0.01084396331253538, - 0.006978935385234202, - 0.006570289869270003, - 0.004843670925435311, - 0.0036491919570969065, - 0.0032467271235956997, - 0.002535064899380923 - ], - "basis": [ - [ - 0.23355241774163285, - -0.1147071301092464, - -0.028586959663731492, - 0.045903459429727955, - -0.10149874367528751, - -0.009718872155936373, - 0.005467811184489943, - 0.16237735031438066, - -0.12699168497476085, - 0.024989341589323342, - 0.13614675693016381, - 0.05018946250330202, - -0.2993783428018391, - -0.05569494379197341, - -0.18689056285992292, - 0.09982000423410231, - -0.21002241608185362, - 0.07100813173033867, - -0.1694323127571077, - 0.056443683869101535, - 0.0176496936166069, - 0.06315233903407251, - 0.08850110892186748, - -0.059057137515497134, - -0.26268921888595553, - 0.048406181290291936, - 0.0737181994850417, - 0.1674221167400599, - 0.15568041338249589, - 0.22405571730942386, - -0.023944664633051137, - -0.02127171034640306, - -0.00953449360257571, - 0.10461188238946854, - 0.05258634672312253, - 0.12606153853112695, - -0.11915205102210027, - -0.10512321216790817, - -0.15434939341404932, - 0.03455375894984839, - 0.12929016660831397, - -0.16944748396288348, - -0.05565615461993274, - 0.047021587066932186, - 0.133258183865252, - 0.002531501835013374, - 0.09392540838898844, - 0.20599578869637222, - -0.14626140207856356, - -0.04290150708685797, - 0.03436073198117985, - -0.17296192507213487, - 0.07857882183099724, - -0.07853404735967245, - 0.039265234606552034, - -0.0547569176686108, - -0.1288331574299431, - 0.07631063683931953, - -0.23931426721944887, - -0.05073785453930074, - -0.0854411315375493, - 0.18402862707146456, - -0.04623391541900516, - 0.2090740167118095 - ], - [ - -0.07206088192817393, - 0.006713298202640573, - 0.04081457862169584, - 0.0530078359088327, - -0.003502069393803677, - -0.079025091399722, - 0.03548330669361094, - -0.003838766784010905, - -0.14770738175089146, - -0.1285720962206566, - -0.09147436840769176, - -0.022545554931831538, - -0.023771123891551556, - 0.14474497916791457, - 0.007158173296394367, - -0.0345406437705972, - -0.047240788422231415, - 0.1864625235875833, - 0.03039756213062813, - 0.024595592406701883, - 0.1764182266976704, - 0.10789210421723269, - -0.24286654808091304, - 0.08156398544377243, - 0.17527612534968473, - 0.044162202193978435, - 0.282097108400186, - 0.15082473406055813, - -0.06822431289922086, - 0.06712895284627127, - -0.059030759495569324, - -0.03350453498969254, - 0.18805775122794288, - -0.14545109678006155, - -0.2843214735930567, - 0.1514196013020296, - -0.07283211993929888, - 0.050628845947446675, - -0.11607383222469088, - 0.15200539714788408, - 0.010285771357295909, - -0.17403206102359767, - -0.07460866401619425, - 0.06710599310099738, - -0.03173632623159517, - -0.026412622544512487, - 0.08604669010768076, - -0.12480741030134566, - 0.2521787791812624, - 0.019320367885032694, - 0.04780577734230511, - -0.13854259342292038, - -0.31458544697291146, - 0.03194188532100413, - 0.020632146836694083, - -0.012488808374184191, - -0.08690801858776111, - -0.11013858083571929, - 0.18135096077642526, - -0.28328117375353784, - -0.10734874692073239, - 0.07323172396051313, - 0.03718931821860089, - 0.10044113722982438 - ], - [ - 0.08710650269658539, - -0.1391692949331972, - -0.005833261887905802, - 0.04496523588649766, - 0.06709810622361369, - 0.031737684379227644, - 0.021476417052481184, - 0.24083804761876773, - -0.1370420794842188, - 0.04528915356243894, - -0.005678036655119899, - -0.16243926370662456, - -0.1350725456865944, - 0.31971462881842516, - -0.13222674759636902, - -0.31741581336193303, - -0.17357442247464047, - -0.056524112798607376, - -0.06828785956140769, - 0.006966362349149677, - 0.05260844940568902, - 0.010238618114504676, - 0.009737124882867725, - 0.007753297355442069, - -0.08588787353690483, - -0.0712038782485666, - -0.060083973533870315, - 0.31797704524444376, - 0.059737608118596804, - -0.03511613687865976, - 0.14650847276282988, - -0.08291932779250585, - -0.2702456000108061, - -0.260251846513335, - -0.0222110851413327, - -0.18748284960437656, - 0.040544175598875284, - 0.06970373686429608, - 0.07975817949152547, - -0.18450387705087581, - -0.08341778114383583, - 0.061540701120679026, - 0.06319919833276459, - -0.029254204659094684, - 0.10866072608231746, - 0.03368342239458321, - -0.09232962336648765, - 0.008831102870627517, - 0.09731891053615611, - 0.09473154180273112, - 0.004058723147790674, - -0.05645624693074633, - 0.03567124879128211, - 0.08350921158419042, - 0.13445855173815474, - -0.1353825592657786, - 0.05354594877388141, - -0.20375350472575135, - 0.13364375578776644, - 0.06775022377222778, - 0.06308153216694624, - -0.08377303003078262, - 0.06767538276300925, - -0.14328115403316158 - ], - [ - -0.1462678581164739, - -0.00539639619650837, - -0.042650232917878395, - -0.11690230657304618, - -0.0963378297398707, - 0.002745752793260117, - 0.003930973266877074, - 0.08759652885569255, - -0.012113319920302373, - -0.1932691407687569, - 0.10952787827526131, - 0.05349059905441103, - -0.15532227301249635, - 0.31487332716055977, - 0.1556570407045001, - 0.020719689856987574, - 0.04521598055615737, - -0.2419023010223659, - 0.03295380648788277, - -0.09082587856929442, - 0.060252165208713515, - -0.038889833278485816, - -0.14786470787600828, - -0.12177542378243736, - -0.09848281678719105, - -0.12892506415986385, - 0.057824603763580916, - -0.06114095463216952, - 0.18359549372023262, - -0.08529514672907913, - -0.0640783919637105, - 0.1602371358346215, - -0.07237118240215999, - 0.12719863193678463, - 0.010251393201592063, - 0.017067754430957944, - -0.02629303539405123, - -0.1583165633553406, - 0.12374320598200947, - -0.08631522342698368, - 0.028155877863133942, - 0.18120204347454094, - 0.21213004670760183, - 0.14665111877747414, - -0.07651336019217479, - -0.08898656121282685, - 0.17012203636927334, - -0.1406827852165147, - -0.23598324028952725, - 0.11881588263788509, - -0.16620002967379421, - -0.03144838250477578, - -0.010134779170926997, - -0.13526940389459127, - -0.016536594265266085, - 0.08104511207826239, - 0.10498521572662033, - -0.03653101960745558, - 0.0916070645788364, - -0.1764482105903468, - -0.2774085169640962, - 0.13882997402026973, - 0.142484403155905, - 0.06990150004842316 - ], - [ - 0.11461412012880257, - -0.14751868656540973, - -0.14030988589753213, - 0.1914344959145099, - -0.12737041282553813, - 0.07303813855999279, - 0.014799553708892722, - -0.1765940415460281, - -0.005819555740015155, - 0.054425789429931815, - -0.02182166316253894, - 0.14826276804605082, - -0.008834142484979456, - 0.2013853048685568, - 0.04671949098700215, - -0.03813167953749404, - 0.09218724226620979, - -0.04895208086406655, - -0.03398467713816755, - -0.039008038884244874, - 0.28788952991324684, - 0.08673207814562967, - 0.11873168134093058, - -0.1715018379092752, - -0.10331601677975626, - 0.04387482866458349, - 0.05498168200477401, - -0.27957462097351926, - 0.09635892908213381, - -0.005273728335533381, - 0.2580111707809726, - 0.25598073237657204, - 0.14008281555976868, - 0.04481995619550863, - -0.12054795478994056, - -0.0648979457258535, - 0.15028206775440897, - -0.10628996918652549, - -0.21934660100312497, - 0.03640105288063261, - -0.21071449562242925, - -0.050476958071390354, - -0.11055390789558178, - 0.13946226951644822, - -0.08246619790413248, - 0.05468474108391722, - 0.08442807223506497, - -0.05781991814534721, - 0.08172230705003049, - -0.04032407750150974, - -0.04064416628109527, - -0.04744092566646907, - 0.03004079796290532, - 0.016964506534547095, - 0.05419782791313861, - -0.12323835100107572, - -0.1653130188763264, - -0.18208700995410532, - -0.1441675573147, - 0.13281788332853578, - 0.026333925614962308, - -0.1419976872680162, - -0.001322033371814422, - -0.17185712576656684 - ], - [ - -0.11209220890901538, - 0.08340716156560202, - -0.03502396477195618, - -0.12275475283702046, - 0.004783779400002273, - 0.22947774779699487, - 0.099128395216075, - 0.034024247545459886, - -0.027772994316084928, - -0.16934947742186357, - -0.1649426401479442, - -0.01894391157241131, - -0.08126708723534551, - -0.2409846967965368, - -0.09039795036739579, - 0.10010337664715557, - -0.08007353314268525, - -0.1172997557331125, - -0.2504771154742991, - 0.07622212804004606, - 0.01691678464859973, - -0.07502523069962194, - -0.11599579061343832, - 0.0008481931932201434, - 0.21559703413478523, - 0.07008624318712015, - -0.062143540691831534, - -0.02876873788766815, - 0.14200630737341488, - -0.021766924021742958, - 0.13378147353518666, - -0.05630226852184723, - -0.09924097999111697, - 0.13796363551868715, - -0.08910712307813118, - -0.33699338308866594, - 0.02646322102663271, - 0.004404282089484845, - -0.04376785922234326, - 0.009268290983440003, - -0.13424428499685148, - -0.20699430005721559, - 0.04724528410286661, - 0.07470827797468106, - 0.09063826311775094, - -0.027788948105056492, - 0.23073370923968026, - 0.004918963863892578, - 0.0797326275213062, - 0.21798897058852224, - 0.07570060507269144, - 0.030565966559475875, - -0.2083429071751959, - -0.14912683009780797, - 0.118544248749277, - -0.029141232235549153, - 0.08371108360406108, - 0.15969857838652332, - -0.1466433162822989, - 0.012245802750783795, - 0.08411064973837466, - 0.11120347618315023, - 0.1150121659463041, - -0.2068487436981141 - ], - [ - -0.062496809813825285, - -0.14710456328781402, - -0.07505183640691734, - -0.0027409200304153642, - -0.3237905639763246, - -0.1963366102219492, - -0.10397493191875748, - 0.014834162077538252, - -0.050829486226572226, - 0.20900356910516688, - -0.16911133096093922, - 0.11732814243774672, - 0.03681790002296556, - -0.023259436731224804, - -0.07142195980449235, - -0.03532098634584136, - -0.09508489046313115, - 0.07269355769689315, - 0.04513347165126337, - 0.10911985855041913, - -0.05885669451758983, - 0.07077694299567382, - -0.011639349015499532, - -0.3153104272627357, - 0.23137626198266215, - -0.05015745757644189, - -0.03303293085595862, - 0.2164342300114239, - 0.06383832244305086, - -0.11531740694015939, - -0.179204492698279, - 0.024949172871149804, - 0.0817375724046263, - -0.11295130051924346, - 0.10856811870032217, - 0.05289008008432993, - 0.0626879567619689, - -0.12297129718383744, - 0.042946442439975925, - 0.030930200734415568, - -0.09272515430886585, - 0.11229139853728126, - -0.11814535330929289, - 0.0036675985076110654, - -0.014642234934626457, - 0.04318969208856356, - 0.3571431529714119, - 0.14700211629129906, - -0.09623335870171862, - -0.11409236876496685, - -0.0364507795910481, - 0.0611333111061325, - -0.0444842533516814, - 0.07555734398317507, - 0.1258155405605, - 0.2216470640686886, - 0.09276627662595316, - 0.06920492530954678, - 0.04251668762039739, - 0.01565654463075537, - 0.1768999880467401, - -0.05672363528585868, - 0.17150239393710767, - -0.07394183722595829 - ], - [ - 0.10041471166342023, - -0.1014687258858263, - 0.20092795995156817, - 0.01619819905403276, - -0.1626298121600464, - -0.084419148274565, - -0.0380792329533062, - -0.0033538430758611637, - -0.08645150511408338, - 0.010054048484182116, - -0.12130499923587199, - -0.014374235340587743, - 0.04558517737634822, - -0.020422942874049752, - 0.007539526335417084, - -0.08609364365961054, - -0.1488650868969918, - 0.05150749447574242, - -0.20177409799319396, - 0.05997500996473998, - -0.16234652599611554, - 0.2080392853611987, - -0.07917489073652427, - -0.14416965059173184, - -0.02069523296530835, - -0.01286519537549146, - 0.27467652873804993, - -0.10064196974392742, - -0.11511995435003396, - 0.09285507466565014, - -0.014561497541426553, - 0.2971036991433277, - -0.1001439370431565, - -0.008587648123827986, - -0.00851825261269172, - -0.13660884038183632, - 0.3066748903281978, - 0.257836137919808, - 0.1823464685969624, - 0.12772287581521796, - 0.05011328254746224, - -0.07913213183969217, - 0.0735829443925953, - -0.20198507163812476, - -0.06061818248979136, - -0.1141796560879036, - -0.1612510809150557, - -0.14901479722825597, - -0.17852966956211153, - 0.0515308621443672, - -0.035737992695476326, - 0.02959408810847658, - 0.011300495925251113, - -0.23592900110953097, - -0.13032691309634814, - -0.068178366741642, - 0.00964470417064367, - 0.06686504153158318, - -0.07508014541887452, - -0.1144630591669923, - 0.06996124216677209, - -0.08591613127621381, - 0.012806269610294255, - 0.021607881520632408 - ], - [ - -0.18488283482041346, - 0.13389446564452517, - 0.12156539244219801, - -0.169103471737255, - -0.08448517395826753, - 0.004296504051166697, - 0.11790078313063254, - -0.03312657883481135, - 0.06623382946266385, - 0.07945805490446958, - 0.0216870161939784, - -0.12569073230640682, - -0.11648633252404142, - -0.19803338834326803, - 0.093211628282853, - -0.21421639370524972, - -0.03279856155713221, - 0.0970408013547789, - 0.024988470466967047, - -0.19160830196099504, - 0.09539652287209453, - -0.16489864929795595, - 0.18677238148548356, - 0.09652062642524391, - 0.023735059683921114, - -0.19859021566948162, - -0.08938923140327887, - 0.090149910290244, - -0.02708779429468662, - 0.037060844709154335, - 0.2076828447005082, - 0.0784854279559382, - -0.009545913195718818, - 0.05768209461418512, - 0.023535522484700023, - 0.02722367535527677, - 0.19323613905808346, - 0.04417401621362755, - -0.11897119475934373, - -0.05446612562889445, - 0.03898404917892721, - 0.10937366801523495, - 0.012499001684723324, - -0.12072960829189804, - 0.08789726457168401, - -0.02793049937244835, - 0.3092085560482944, - 0.08365359980644808, - -0.08811537634076523, - 0.024089346646177394, - -0.09995686599991029, - -0.11374855690613836, - -0.05964567245963646, - -0.0902958505422417, - -0.1570469901488963, - -0.02133537117746954, - -0.35365096783807487, - -0.13740979006011703, - 0.08190044100628364, - -0.21054837253148467, - 0.1503478124038856, - -0.11417641207490484, - -0.06809863728381932, - 0.09145149741312485 - ], - [ - 0.1421314465258811, - 0.07960795302960677, - -0.15902571272093935, - 0.11669439544598552, - -0.05321649244111727, - 0.24824034851564514, - -0.1982183385715376, - 0.017183583968092195, - 0.013014977462912556, - 0.2080596504441032, - -0.09438980176007203, - -0.16280715309605842, - 0.15539080195629332, - 0.1567562845707528, - 0.0010158106727429044, - -0.13791612943859863, - -0.04757388210621165, - 0.0093373380519308, - -0.043109868412954604, - 0.0741133167574333, - -0.10138120545058321, - 0.1304534595062839, - -0.016165265381569257, - 0.03891778709355692, - 0.10644950619023413, - 0.12152790870723099, - -0.1603574328149586, - -0.22906376442269472, - 0.011846082462831838, - -0.352521144557297, - 0.014216695492003422, - -0.0888106080550686, - -0.13876288218664393, - 0.18148510259273953, - -0.018498744717886595, - 0.004266919148266002, - -0.0019914227752570015, - -0.0170886631757827, - 0.12837062573673597, - -0.08596020967878003, - 0.0775952813212015, - -0.06312354645552237, - -0.005829343732232701, - -0.00607544148958489, - 0.013030638446356105, - -0.09285116889955028, - 0.044047114552390555, - 0.09370828558218633, - 0.14334703420297823, - -0.0937626995012505, - -0.14265837765755943, - -0.1680992934580924, - -0.0683044480219474, - -0.0784858411308153, - 0.1310635721411467, - 0.05946539704470338, - -0.09181967572926183, - -0.019205095925603995, - -0.08812229826819756, - -0.2562132636873763, - -0.0003361159192586166, - 0.0035550721748466674, - -0.06947220485499955, - 0.3248010688647647 - ], - [ - 0.06934643351658105, - 0.0029846269592181157, - 0.21241522423471787, - -0.03505716459143244, - -0.10713976070714995, - 0.014092433032404003, - -0.05100832936278434, - -0.0015589749289785777, - 0.24756148758124327, - -0.05234232558134178, - 0.13749321836614223, - -0.024829069847617857, - 0.012632909321394074, - 0.10814804929782287, - -0.23332185706787495, - 0.08126695901476497, - -0.0725473433186588, - -0.03637453002203785, - 0.2189817693204098, - 0.05261222922509919, - 0.09334256906584573, - 0.012515109586430468, - 0.3002887290314165, - 0.06702966012375654, - -0.07805796889713557, - 0.2733654303653686, - -0.01435716661698128, - 0.14841336282479278, - -0.20479960726605476, - 0.10346754661427332, - -0.06617186117626409, - -0.022362230544346898, - 0.029709254102111816, - 0.012555065059915986, - -0.07935365846025166, - -0.24890625622191304, - 0.2034613218745859, - -0.1048748431827762, - 0.1656427328783829, - -0.00566643211359686, - -0.19758193360822068, - -0.014710191353096742, - 0.06567573415345994, - 0.0848463328828748, - -0.12126105381543863, - 0.03828209843652678, - 0.15589977725267057, - -0.1384849935714474, - 0.13148684966589755, - 0.07836713660833389, - 0.03971788598759569, - 0.04994674958253122, - 0.09193919583964948, - 0.00903879787218863, - 0.10461419019315983, - 0.11501098478730032, - -0.12026931048695648, - 0.2593322902596855, - 0.06841175571565006, - -0.1260918826756462, - -0.13869699842916708, - -0.045877855445860455, - -0.05752218744345248, - 0.09973819622192212 - ], - [ - 0.1077461861029259, - -0.12324297105760389, - -0.16801699028937336, - 0.10619929350613173, - 0.08913726865986586, - 0.15227149679985746, - -0.11959520337230375, - -0.08709818478808504, - 0.04880674106013147, - -0.15463174281924755, - 0.09684192479485577, - 0.27951010654579084, - 0.031047731521796372, - -0.025563988804579697, - 0.010531978916498128, - 0.04889859567408308, - 0.0665208837668002, - 0.12948712205736057, - 0.2770062138749127, - -0.032919538192236655, - -0.25715300334987373, - -0.16224949706547248, - -0.1621206569478613, - -0.11063120628950365, - 0.022940211575802196, - -0.012825615320726793, - -0.07118631997554652, - 0.15019770795787432, - 0.2500685483804933, - 0.1958811222163837, - 0.09726869881829037, - 0.16022765942479414, - 0.0016527345686866302, - -0.05021804199759924, - 0.05033375416321116, - -0.04251682593380129, - 0.06834590277729463, - 0.03358862439342188, - -0.033717800155638813, - 0.011229994071792818, - -0.16440150491903396, - -0.03721247471094196, - 0.1868697413313219, - -0.20087180038716848, - 0.19166197639952398, - -0.21645987670540562, - -0.06271298894906373, - 0.019502326694013784, - 0.102302924078208, - 0.07460960255895974, - -0.08607959083456689, - -0.16146001533005352, - -0.12676667901663366, - 0.006337090537247551, - 0.06242675902968566, - 0.14121273793492786, - -0.020125732396077033, - 0.06688132549563607, - 0.08480582659413073, - -0.02082037275057541, - 0.033020777662285165, - -0.152719133216357, - -0.167070977343918, - 0.09281751840644058 - ], - [ - -0.16219314033718815, - -0.056204257009875865, - -0.25443213553009947, - -0.0043201936517717945, - -0.15428937618159388, - 0.0012484544026337067, - 0.005174842520112206, - 0.08509978422515804, - -0.1582257971418354, - 0.11697587305781115, - 0.24033850073276997, - 0.0039216343248833566, - -0.06687532145289707, - 0.07288134629503296, - 0.0300709027492998, - 0.013201599189900142, - 0.08607028976439318, - -0.15790488066740244, - 0.1557464645852586, - 0.10109741222814654, - 0.064836205093647, - -0.006100511723785768, - -0.15562595681970823, - 0.11725578167389067, - 0.042261740680425285, - -0.0253112302510641, - -0.03277599356951905, - 0.03234466763322597, - -0.25424616068238187, - 0.11270965216748084, - 0.1881686847483611, - 0.0006142243850474381, - 0.0032991489067422473, - 0.03641048833747705, - -0.051673032837633914, - 0.01629629191219487, - 0.2749775804368913, - 0.17311336162740806, - 0.028377002044317798, - 0.03259099973479209, - 0.082879619976367, - -0.13123085544805888, - -0.013977216798444249, - 0.23367373635931268, - 0.3290532199268392, - 0.12673821632034546, - -0.07300579377707322, - 0.07802279816272824, - -0.05394169957121078, - -0.1424281227802907, - -0.09150002384157904, - 0.2871601217857947, - -0.03367054685969475, - 0.024440965749508006, - -0.007378356191396106, - 0.11441936805214038, - 0.1186172022349001, - 0.07516123052024444, - -0.10532481293918569, - -0.13834396854612965, - 0.037075463583710125, - 0.03670571402863083, - -0.1793623356443517, - -0.030007319484711904 - ], - [ - 0.07925988702623353, - -0.16305715165633786, - -0.023162127709015632, - -0.061417740589198994, - -0.04218937369161141, - 0.10709976141897812, - 0.040433318923325516, - 0.009687782509183672, - -0.057479030472526366, - 0.15021354647067545, - -0.0010111709345633861, - -0.0951122287430226, - 0.12854770343172633, - -0.13468160870251544, - 0.14893103060909763, - 0.011254146204266487, - 0.15045381079428546, - 0.029727962255578062, - 0.027424558375222268, - -0.1538393029414171, - 0.013796454830397733, - 0.2042453303507667, - 0.1267449496953358, - 0.01959003329882824, - 0.2057782613095865, - -0.027519479399038982, - -0.0635754751023325, - 0.14932843525312361, - 0.13346810909617074, - 0.24193756017622478, - 0.040019857672200024, - 0.18742173838027112, - 0.062413845081870964, - 0.12482694575057644, - 0.05166575536922778, - -0.12747181066417324, - -0.007710356553838557, - -0.0033573519972150906, - 0.1708663157890687, - -0.2000235888569822, - 0.0911502528170537, - -0.032856553141182715, - 0.08125517631609953, - 0.09864650217633142, - 0.0069825690119156535, - 0.05469922647459429, - -0.04146110056206948, - -0.2549543724072367, - 0.09391880987713379, - -0.15350303178927763, - 0.2656699345271049, - -0.2182588501566468, - 0.11905643924939355, - 0.12401388250822572, - -0.06457246176746467, - 0.13875841766007027, - 0.058202137739421615, - -0.14091413537285882, - -0.021259828734667186, - -0.0877689773250441, - 0.054971505540315255, - 0.3451624271030207, - 0.07013348714021862, - -0.04397989254155177 - ], - [ - -0.03494012172931553, - -0.0602877931929719, - 0.06620141380438141, - -0.04865740025646352, - 0.025570088287763214, - 0.018332187797626583, - 0.07674028424773194, - 0.04765669153952179, - -0.11418592613646915, - -0.16313584752601842, - 0.18676155847343873, - 0.04480458438827468, - -0.06402963813733893, - -0.10388585912185344, - -0.24975594618272226, - -0.18132439926848548, - 0.07321441959548132, - 0.05916642594909687, - -0.09147637177036007, - -0.18418832566304416, - -0.15751625177321052, - 0.12258434558856238, - -0.027609553376057562, - 0.09162933909584256, - 0.1254582343022388, - -0.10791354310354496, - -0.1215951298643287, - -0.07279244836635979, - 0.02463698468603221, - -0.0027815455288277917, - -0.24822061938615714, - 0.1644232837917987, - 0.19189360441504905, - 0.04132115242910462, - 0.08371058843434376, - 0.08295489804914052, - 0.06964560893276264, - -0.16958246581930783, - 0.32979676025436183, - -0.09210671555543536, - -0.15001438305304451, - -0.03137004392323737, - -0.10378119369867304, - 0.11045961728795871, - 0.046921528348436645, - 0.08068230657977858, - 0.01131279165228097, - 0.015139399588439734, - 0.1335019357447358, - -0.08248062262545179, - -0.24306093944312154, - 0.02447663193215639, - -0.15185785188668363, - 0.1019593687841871, - -0.012106669540759002, - -0.39450121376997893, - -0.004026193729158122, - 0.03226137199273694, - -0.09407954757918872, - 0.03671741272462254, - -0.0477287374274311, - -0.07038024646376911, - -0.06957911627142713, - 0.0003920457380000235 - ], - [ - 0.05202867979321444, - 0.11455483595176329, - -0.08057708958060214, - 0.10175028887865438, - 0.10378180773451422, - 0.001747853018683683, - 0.153755972354709, - -0.10198367439828221, - 0.041205249741223526, - 0.09059262231814331, - -0.1621184943207254, - 0.10398408431428542, - -0.05286789341851919, - -0.04318177819538583, - 0.1838514210776344, - 0.14661918563564372, - -0.18458661169618099, - -0.0178401902743229, - -0.054188516214166156, - 0.02694103672105889, - -0.019113881554851973, - 0.10143814812050718, - 0.11638439787733248, - -0.03202402992598221, - 0.007008976991019742, - -0.11895682268442592, - 0.162528104998032, - 0.04809773489848416, - -0.006343238392956938, - -0.13063141296560513, - -0.13889056515566375, - 0.04901859161887692, - -0.013036134524500672, - -0.05405878204733442, - 0.12992518582100399, - 0.2064048667854352, - -0.027196624236870102, - 0.10186498237919335, - -0.07218966920213468, - -0.19613526144736151, - -0.11934552344329225, - 0.12388600930882576, - 0.30993144411844553, - 0.15758134405582427, - 0.3057019288959266, - 0.24155695383269754, - 0.04736770684575071, - -0.17945788433880122, - 0.18161021137708963, - -0.010563816103179361, - 0.08064914116416078, - 0.024388766942760726, - 0.1217621567945871, - -0.10815800738253, - 0.11167305764331412, - -0.17260176445216946, - -0.019069645794565455, - 0.20484443491693083, - -0.013828179922783587, - -0.18006875079613335, - -0.016291116650364628, - -0.1611696153737834, - -0.07362885589903702, - -0.02928994013149871 - ], - [ - -0.1865990221870819, - 0.13059479855413494, - -0.1319938898623769, - -0.1182843451381498, - 0.114460930189489, - -0.05899547016344177, - -0.24716921903668262, - 0.08703500894586802, - 0.2026523812189681, - -0.14672748153414386, - 0.03403757109132916, - -0.10976803558428336, - 0.2389232575958318, - -0.08988352211653676, - 0.07299995150692444, - 0.04495460235863738, - -0.2348089493283544, - 0.23140745240148264, - 0.032893413605508105, - 0.09361619843259307, - 0.05060437005442679, - 0.0269986093568103, - -0.11035351716386005, - -0.10076358518681501, - -0.21660286655257832, - -0.06813447075547517, - 0.1458685934249413, - 0.04152638286553238, - 0.2033684591539121, - -0.033235368605204485, - 0.005071083171428706, - 0.16567482246896864, - 0.04812376393053567, - -0.0667451679089557, - -0.07166009538329929, - -0.23614093023826124, - -0.0948425248445244, - 0.0036885846884850324, - 0.12117422806723387, - -0.06301500949606124, - -0.00013924532622255266, - -0.09110226343749242, - -0.20246388492571102, - 0.08426619230654264, - 0.16829801254049975, - 0.11185935741487764, - 0.09479189895958089, - -0.05306100494478102, - 0.08322859615683856, - -0.04575842385736969, - -0.10853783852014358, - 0.21803925702263527, - 0.22078379679656268, - 0.0016868403392857028, - -0.03396855920284696, - -0.025681303850728664, - -0.06573745369727924, - -0.18869507700537613, - -0.05140465367853293, - 0.046849136130889875, - 0.04003817970691232, - 0.055376684556948164, - -0.0421180416882704, - 0.14149809891719328 - ], - [ - -0.13055512100354424, - -0.016091595125316726, - -0.0658246144259377, - -0.030049991676979942, - 0.10675297684920262, - 0.157115129314659, - -0.13780049814381834, - -0.2638212659083549, - -0.12392397911880984, - -0.07208576592848907, - 0.03498219823192546, - -0.185780334053304, - -0.1495996918660806, - 0.09130877074208951, - -0.22048871433618847, - 0.33515114362198783, - 0.15388159612134608, - 0.19673307304160143, - -0.24608372070404744, - 0.10763792230389797, - 0.1374968274033966, - 0.1570875117459229, - 0.03457493214524266, - -0.0757593393756678, - 0.10004974239216918, - -0.012369349333449043, - -0.13870151340109776, - 0.17564875910280636, - 0.03671766825086059, - -0.07808728786098888, - -0.06004229565255291, - -0.008130141123021057, - -0.04496737123904235, - -0.08246095323961372, - 0.06401392299242994, - 0.051401642228452095, - 0.17835910643736055, - -0.0875842865494567, - -0.030858004884941587, - 0.07953212694318766, - 0.20309349277124641, - 0.13841361689995962, - 0.17234288377106224, - 0.07959543533740009, - 0.0013546360625352003, - -0.18311049119307382, - -0.05389614704287298, - -0.180179602736165, - -0.04687821216366469, - 0.07487480646491716, - -0.02199119034137535, - 0.1576344108429571, - 0.030381561985524694, - 0.11155884090208384, - -0.05059148938736868, - 0.02684785420102916, - -0.14229943717613525, - -0.09544509103763155, - -0.04454469620314733, - 0.06684617360306272, - 0.11241524582156602, - -0.10551296700773422, - -0.04665372758027808, - 0.0959959253090021 - ], - [ - -0.0515705811419872, - -0.1802642167650813, - -0.10108460904299281, - -0.03390497652148994, - -0.086090765675042, - 0.11204402423045391, - 0.11588371363931217, - 0.07858325749954084, - 0.10654287584343386, - 0.1308655931449642, - 0.10180949232135125, - 0.06274212711867169, - -0.0013103434050797795, - 0.006579545118075467, - -0.05466803619597753, - -0.10335556936412371, - -0.207876466038561, - 0.040159490933988067, - 0.039989301564373386, - 0.15850622412521465, - 0.08875979403783157, - -0.11621373845231703, - 0.09219969994245002, - -0.05424335499176003, - 0.24193845290726584, - -0.04830293399298303, - -0.09308751134374328, - -0.00557839672514428, - -0.10492663489467155, - 0.14189794754358512, - -0.16235330782514393, - 0.06416916711373608, - -0.07676701552282993, - 0.30040955428519106, - -0.1500263265530513, - 0.045040682158297436, - -0.3143486103023431, - 0.09564314672860592, - 0.09118515106627213, - 0.1922567182274428, - 0.0005718779141161252, - 0.04332026138841725, - 0.16880170434626046, - -0.035179369504143104, - 0.049692344686415195, - 0.04498463378011832, - -0.01669230990283563, - -0.12280009483079916, - 0.02955056757648907, - 0.041931502869269416, - 0.10813223601654212, - 0.15049850505690163, - -0.08685153015234706, - -0.12859316809806604, - -0.06668337384095827, - 0.00651218271021426, - -0.04702691289266179, - -0.2705417517352985, - -0.053087659874228796, - 0.23371316894251487, - -0.13760828459872246, - -0.24149279068734453, - 0.042831216834111306, - 0.1378422364988936 - ], - [ - 0.08676424467631025, - -0.0922304564246185, - -0.09652912077750452, - -0.03637027699399378, - 0.04448745394177293, - 0.04117675960846198, - 0.04765795582667189, - 0.1023697367937818, - 0.024400087478377883, - 0.06385939942147606, - -0.11775562201001023, - -0.151778083167507, - 0.13448177217923796, - 0.24904148340318966, - -0.15004720775155322, - 0.31405104510443527, - 0.12952912302330777, - -0.005648197482712468, - 0.12748137719846586, - -0.09622339085347482, - -0.16533143067976497, - -0.04243156198523083, - 0.1307181393298476, - -0.009313223390954901, - 0.09234541288705547, - -0.025973233661042972, - 0.10017608202182197, - 0.14256023418970154, - -0.07259823342317191, - -0.13304898312979319, - -0.04435516878805133, - 0.14717981581833675, - 0.151502064485612, - 0.22161212983822415, - -0.0469005460300688, - -0.16776116798345345, - -0.08783259036545343, - 0.22642314489227744, - -0.14701232850571755, - -0.053896542717052784, - 0.11420281823305486, - -0.07703454709410511, - -0.12133105227372111, - 0.06196198005409638, - 0.09865186580731533, - 0.06488472977084668, - 0.06723240742031855, - 0.061078074880469534, - -0.23758366339351736, - 0.05681988793041724, - -0.1310234034435964, - -0.1055897431977925, - -0.06609427089397082, - -0.05430656380370657, - -0.0602164066672669, - -0.2698848815224717, - -0.0463112359838351, - 0.09533549244820129, - 0.2982377040691853, - 0.13345617682955294, - 0.057299591891649265, - 0.011415871450485325, - -0.009555560086367331, - -0.019418005751958185 - ], - [ - 0.039624344188747704, - 0.08127603777176333, - -0.1683513226751274, - 0.08799935608680239, - 0.1279917411835233, - -0.058688895586676275, - -0.013376454760121203, - 0.06743682435344918, - -0.11898503774579931, - -0.00809624383408451, - 0.028695641764273097, - -0.10222964612716469, - 0.03768334984243678, - -0.08720452788215884, - 0.22029989658337254, - 0.009249931270677319, - 0.07455815373620078, - -0.07874303805327651, - -0.2531107275375493, - 0.15778641212484973, - -0.11845220387936964, - 0.03501679642405525, - 0.10953146546893285, - 0.0613540238407299, - 0.0833837019057621, - 0.053507224235195494, - -0.11795375231777475, - -0.01079022472512948, - -0.2272683746345602, - 0.13746691160300273, - 0.05393018883497473, - 0.04522983325342475, - 0.04905747838252068, - -0.3379168987852184, - -0.1935746812286669, - -0.056453274362010156, - -0.06372591288939787, - -0.11225445049293548, - 0.02962637434247891, - -0.032829316402639946, - -0.3260711285651581, - 0.02966303271534327, - -0.01778536171784018, - 0.08289932101783107, - 0.07693895617218456, - -0.13453154359154185, - 0.18424763560188867, - -0.1004636330139747, - -0.2899658846649391, - -0.12825583238118232, - -0.002803287641844678, - -0.1564739056776209, - -0.00114597429308773, - -0.09914323483295309, - -0.07226301999740958, - 0.0024649372000324133, - 0.0448228218420806, - 0.021374187359331113, - 0.08879991957622785, - 0.18234107653656256, - -0.10068825878449887, - -0.03611585693837921, - -0.05930887794197523, - 0.24494644848547983 - ], - [ - 0.02123288561154513, - 0.14313331455622327, - -0.12585091582840993, - 0.11643790555061934, - 0.08036904442342419, - -0.1599359029602018, - 0.4661030736778162, - -0.18864725206316885, - -0.06769683886891786, - -0.034683775040536706, - 0.1031911457474731, - -0.18180698704723294, - 0.2344928522409699, - 0.03601741050357881, - -0.25055422746877865, - -0.11793212654126231, - 0.03148333410738535, - 0.04435910301838099, - 0.07025033436329367, - 0.1489870265496878, - 0.07995537582892179, - 0.03291595163660257, - 0.1619229280371017, - 0.06846833413239377, - -0.01607776287172025, - -0.12369414327602113, - 0.11680722371186206, - -0.04632148536071062, - 0.21948479328894602, - 0.09504831285426313, - -0.012265148444469699, - 0.029855956632645047, - 0.04909544935752943, - -0.02208622318351633, - 0.07205934658484218, - -0.1293769524489027, - -0.03595989199345866, - 0.0712123037239018, - 0.034399402239462494, - 0.1874893948353104, - 0.053427886717755564, - 0.17735856831964, - 0.042381288858942184, - 0.06344374623205477, - -0.052720392937315036, - -0.15557071416536486, - 0.06608501193093326, - 0.10868029386042359, - 0.006724468201275521, - -0.04082993473059128, - -0.07683352320098503, - -0.04185759212478087, - 0.019576398028409527, - -0.16682068779853165, - 0.18677266485509061, - 0.08195336467122549, - 0.24958563060247838, - -0.021982956970677335, - -0.04977026667184539, - -0.07512345308727796, - 0.06577298416614538, - 0.0445244251683026, - -0.12722825493083198, - 0.029380227797437226 - ], - [ - -0.329933124457535, - -0.03811365248610126, - -0.026546136787007873, - 0.1057754187703028, - -0.06093311842877739, - -0.001561101155637102, - 0.20855337514204902, - 0.08410959782151181, - 0.12996151444059956, - 0.16246546938980624, - -0.12499066749313031, - 0.21455168101392036, - -0.061191407610021384, - 0.10365927231615603, - -0.07866003827988433, - 0.07005874799169096, - 0.2121813328407976, - 0.23999633026877146, - 0.06398478065224181, - -0.025635001880277633, - -0.1116370798485355, - 0.008642999197746536, - -0.05947708951194535, - 0.13744641417873166, - -0.013082271384462016, - -0.10395072765214096, - -0.078195077381021, - -0.017898202178381336, - -0.12713598309291965, - -0.043545744923062915, - -0.015079940080292904, - 0.0878316220744752, - -0.19958669582635333, - -0.2697854207627697, - 0.0787797233947352, - -0.19742665690502612, - -0.13740686145306746, - -0.16722114792900822, - -0.016213364335428436, - 0.017209418287377685, - 0.12431811747203367, - -0.1933051478994039, - -0.0035689504117802874, - -0.13419617387642802, - -0.06783731262563489, - 0.105194097894492, - -0.02346806919528982, - -0.15782137325511755, - -0.10602673108010105, - -0.07627463429743775, - -0.022963426596530053, - -0.054272893777097604, - 0.038851713562045684, - -0.14948193619287956, - 0.23989576597720869, - -0.029885700308917844, - -0.16984804704674575, - -0.007876344317376186, - -0.18107866043372736, - -0.03492404143751271, - -0.11570809185033462, - 0.07683771747031937, - -0.05660096365425011, - -0.04264591618570023 - ] - ] - }, - { - "layer": 3, - "rows": 24, - "ridge": 0.05008074144522349, - "mean": [ - -1.1672000885009766, - 1.8900855779647827, - 0.20041881501674652, - 1.5460702180862427, - 1.3023158311843872, - 1.0329928398132324, - -0.15213178098201752, - 0.5809727311134338, - -0.5897409915924072, - 0.1667138785123825, - 0.4618253707885742, - -1.473828911781311, - -0.4177567958831787, - 0.9149282574653625, - 1.9613069295883179, - -0.43115416169166565, - 1.7171239852905273, - 1.0439878702163696, - -0.12038538604974747, - -0.5460716485977173, - 0.6451572775840759, - 0.9891571998596191, - -1.584525465965271, - -0.6002110838890076, - -0.8275081515312195, - -1.0818735361099243, - -0.37593233585357666, - -0.33816584944725037, - 0.5149696469306946, - -0.5435014367103577, - 0.8571256995201111, - 1.3441582918167114, - -0.4352305829524994, - 1.129738688468933, - 1.0840258598327637, - 0.8417221903800964, - 1.039987564086914, - -0.4174279272556305, - -1.0249570608139038, - -0.033091951161623, - 0.5284595489501953, - 0.04981664940714836, - 3.0846269130706787, - -1.1295896768569946, - 0.8584709167480469, - -0.5597923398017883, - -1.637886643409729, - -1.0323357582092285, - 0.7547407150268555, - -0.21722553670406342, - -0.31369492411613464, - -1.566554069519043, - -0.9227381348609924, - 0.7176042199134827, - 0.24865858256816864, - 1.7140487432479858, - -1.119145393371582, - -0.43076658248901367, - -0.2690255641937256, - -1.5103297233581543, - -0.07304813712835312, - -0.29888293147087097, - -0.28257980942726135, - 1.1756495237350464 - ], - "eigenvalues": [ - 0.7490720886850509, - 0.6316509453099468, - 0.4585923085505545, - 0.3475329997263063, - 0.2161108306366524, - 0.1665202636764104, - 0.14791515595873395, - 0.09912042818731676, - 0.07086808480495167, - 0.06154383145169426, - 0.05073547766451338, - 0.03758837988965108, - 0.029888400094717923, - 0.02610330381227562, - 0.022990354651143286, - 0.021780935338887416, - 0.017853200575921904, - 0.015503800914777278, - 0.010734117975250217, - 0.008601174346270965, - 0.005823793430828775, - 0.004907902864830351, - 0.0037298141291732326 - ], - "basis": [ - [ - 0.24637576168611758, - -0.15174533991733646, - 0.07290538132228852, - 0.006907969873953733, - -0.15070542465304385, - -0.019933154042150465, - -0.04716639692083749, - 0.2110916027815368, - -0.06885380515833996, - 0.0476049798981332, - 0.0838160308263415, - 0.13734332316190703, - -0.25588131449926776, - -0.023156050934600513, - -0.20404488742148225, - -0.030752342938441948, - -0.16458922398026662, - 0.004207491623480971, - -0.0852318415889473, - -0.09894710262192993, - -0.03394572827740558, - -0.042556465354128735, - -0.05123416703448945, - -0.002620777494241662, - -0.30500086994371844, - 0.003866441131339479, - 0.008884726104958223, - 0.12393848884380286, - 0.061381009882059086, - 0.18483163006637723, - 0.09285377880720923, - 0.023215881011477122, - -0.0833068579817238, - 0.0015963946983369223, - -0.04307654703764072, - 0.20023945183310343, - -0.14820518833815888, - -0.13710208825165807, - -0.26246535552156813, - 0.022358084942905622, - 0.21272172824079655, - -0.10088752150959536, - 0.06603746210146927, - -0.04383449733691863, - 0.12918642589213097, - 0.059260126018516934, - 0.14832574728419484, - 0.16916989992602738, - 0.01555514108968245, - -0.14423338727392754, - 0.05780027484414703, - -0.18755357954472898, - 0.00945700336268329, - -0.03874314262050202, - -0.0584332656664044, - -0.07175083065209363, - -0.07569250109174772, - 0.09433425331405168, - -0.09776170643240825, - 0.07385760331137295, - -0.018798156489442032, - 0.1534810572217529, - -0.009481615693015722, - 0.28154798576955864 - ], - [ - -0.10014919520674195, - 0.21406615166987952, - 0.14456898518575992, - 0.04682357882683255, - 0.12231740645364063, - -0.018996750200685985, - -0.0156470673589403, - -0.23739935977500007, - -0.03129544146774327, - -0.01855097233978271, - 0.04248877575914525, - 0.17311654830191076, - 0.09956057910580922, - 0.00892893352021313, - 0.008443897664447782, - 0.1251476830926104, - 0.11125944534194093, - 0.11585883187349709, - 0.13004605608402295, - -0.09584089340125806, - -0.05772120948947243, - -0.1353068318800249, - -0.12289495885033129, - -0.009812980307465233, - 0.11332117486684648, - 0.08874931310854196, - 0.23331121973412394, - -0.20206881277451866, - -0.1646837750567822, - -0.00490236167581328, - 0.027528242291125507, - -0.08335652421383218, - 0.1504403995339693, - -0.04257382659555557, - 0.015920220663420727, - 0.15764334700403748, - -0.08140274806460163, - 0.023933746693411872, - -0.1168287652761491, - 0.20977307375907822, - 0.22700266401723493, - -0.17388682565380176, - -0.1839466743107522, - 0.13118678194480998, - 0.08121334212983503, - 0.007078645200428273, - 0.13306494324351828, - -0.1209303716060504, - 0.25888332447575585, - -0.11069506959941494, - 0.1405119638978321, - -0.027202974555763336, - -0.24256193386872976, - -0.11314556167008251, - -0.10510423687106538, - 0.08220481858962261, - -0.14929687929495625, - -0.006817872972329861, - -0.025209515952781106, - -0.18338155803349007, - -0.043593275543750365, - 0.03532691754296376, - 0.07483209888447263, - 0.09994821132011841 - ], - [ - 0.07626761450691791, - -0.11800048445055714, - 0.10134323112974575, - 0.13381586737466314, - -0.03718738924581856, - 0.017929747084068876, - 0.08668712295497401, - 0.0031598949787197315, - -0.04549541059821671, - 0.02033704056159982, - -0.09651008376422462, - -0.25506186240265355, - 0.08405816976774856, - -0.06889628647476616, - -0.14372267870083696, - -0.24837733062083917, - -0.04902441867772961, - 0.22434914836168018, - -0.03915142342416373, - -0.05186391098131169, - 0.1153689041905485, - -0.08219144126328258, - 0.0851367932886609, - 0.1853988820710714, - 0.057364930945142896, - 0.0047135858876327374, - -0.08898652964476234, - 0.2452006881179063, - -0.13245739862599396, - 0.009386285021665391, - 0.06809940303840914, - -0.23168031291045346, - 0.08144510567983217, - -0.25173998638113065, - -0.08393031576758106, - -0.047987834857577974, - -0.08291091298949203, - 0.23198771947643185, - -0.015105402629796249, - 0.12076019801473321, - 0.12999108973426643, - 0.08899024715546452, - -0.1475179188614747, - -0.04712415010890451, - 0.046407993797786935, - 0.08577124795808529, - 0.09183797945986433, - 0.07905789193327412, - 0.2248831301585814, - 0.049431595577940246, - 0.108003002859987, - -0.12161387049255232, - 0.040069167255687425, - 0.06857969769223608, - 0.05529151400446791, - -0.0210720430371428, - -0.0351858246913795, - -0.1514499593938168, - 0.29533201590013014, - 0.0926497798890197, - 0.20942756103035343, - -0.07415689475479789, - 0.00893790524081761, - -0.139074828180109 - ], - [ - 0.03484891170297884, - -0.06609440608869742, - 0.08360645740133796, - -0.05937661897569461, - 0.0025213849987588827, - 0.000339183969862411, - -0.06559380321959855, - -0.09900269644558148, - 0.17371501153781227, - 0.18009089052296293, - 0.06618674521479839, - -0.008479767148724324, - 0.18714864648291263, - -0.2696675789910105, - 0.012499207103940492, - -0.01002568122629177, - 0.08678849340273184, - -0.034992456982596266, - 0.15346879181260129, - 0.009232600464610946, - -0.24553065681434746, - -0.15910510951247775, - 0.2395456951702668, - -0.0885006873973483, - -0.048835197137328465, - 0.029716822460845026, - -0.15253367276709118, - -0.19945263033879862, - -0.0961080062424324, - -0.05133414074470845, - 0.03686366872648009, - 0.004430426015180754, - 0.0021236011573876785, - 0.024997845751816326, - 0.24828108776874955, - -0.05102408759237453, - -0.05255083065654022, - -0.01397855669073212, - -0.04779069215714819, - 0.07109844585497724, - 0.018826547735627017, - 0.059648179209421476, - -0.134404030831347, - -0.030319394582005804, - 0.06847085356141276, - 0.03568905825682747, - 0.04141750978706364, - 0.1961384244676285, - -0.0931716643973848, - -0.22464818375327136, - 0.13629124008846424, - 0.16256229318288087, - 0.2045626156267531, - 0.018026440606824873, - -0.021172246936087134, - 0.07752155845805161, - -0.016509865626994052, - 0.18257141839598012, - -0.15491111056076784, - 0.24056023975177795, - 0.2831402424082864, - -0.05110820843757765, - -0.19112850671822956, - -0.013233696526933684 - ], - [ - 0.03229665864469477, - -0.21947711509576645, - 0.0415064225047315, - 0.19666173635819761, - -0.09386640587470535, - -0.05805385117440641, - 0.033134766746324706, - -0.2105298986606732, - -0.08260006067847457, - -0.024948169333111083, - 0.11828300190256723, - 0.22234390907520943, - 0.016217136675881694, - 0.2900577313293458, - -0.13118026695053664, - 0.03416976968401812, - 0.06976960805061178, - -0.011411565471809182, - 0.053798805232249405, - -0.06656114023304428, - 0.2356594341708527, - 0.1330381761331146, - 0.10339970116574394, - -0.23696579300799409, - 0.0495104396485958, - -0.07259943206230667, - 0.025910434762992467, - -0.10639120849984346, - 0.18502065785212715, - -0.0641834411450115, - -0.029121615609058682, - 0.16571517220096613, - 0.020921478334113792, - -0.243239495200158, - 0.2039748692020426, - -0.11904832191078919, - 0.06603420730869276, - -0.10844162571929156, - -0.13725703937378583, - 0.012627129790409121, - -0.013483253435333591, - -0.017216374859669252, - -0.07995611164137958, - 0.12083197696577395, - -0.013379008373290277, - 0.11037710586989906, - 0.053995820866445526, - -0.03647468261631188, - 0.11556653490144637, - -0.10924553435631428, - -0.07704155739808026, - -0.0968109388588681, - 0.23127884520472394, - 0.03567357060295224, - 0.1966570521752951, - -0.08162708472412943, - -0.054060344004366996, - -0.10384372369361486, - -0.04440133926916189, - 0.11171071035239508, - -0.018877523248252467, - -0.2546500426266644, - 0.1232649322395694, - -0.05033666183819555 - ], - [ - -0.06493178012921545, - 0.15280828834206814, - -0.05176516357855219, - -0.043335552392472956, - 0.08738970897792202, - 0.27520740884863387, - 0.09268974365771737, - -0.08262605428704836, - 0.05161945058647368, - -0.12862846828948987, - -0.040535414653398334, - 0.033983071514519264, - -0.06521268343703199, - -0.19736357865506332, - -0.19828872657967528, - -0.006526773152949151, - 0.0256466263633392, - -0.12061257431139724, - -0.22209485793302333, - 0.09019872709746608, - 0.05178578643397225, - -0.03312013035866209, - -0.01568599240139001, - -0.08056201105340627, - 0.13765679239677395, - 0.04074722622386274, - 0.054936674209204055, - 0.005299159724785043, - 0.16952020610858637, - 0.0896793536731852, - 0.20004269355695803, - 0.0922261719958474, - -0.08490109471800134, - -0.07664130202550344, - -0.265863627970085, - -0.15162864936990764, - -0.015134846454230981, - -0.007892807436227832, - -0.04475426296157467, - 0.08716919955732219, - -0.1754181534997638, - -0.28246085361491363, - 0.037919374672816746, - -0.03491925715468473, - 0.15138005287699177, - 0.044950883430488024, - 0.010921529882136452, - -0.072648323996452, - 0.05857405974478182, - -0.0052569227016129585, - 0.1179946768968785, - 0.07685576232410046, - -0.12105778345551486, - -0.08501006706027545, - 0.11521266396475814, - -0.32091322099502995, - -0.07551058285056907, - 0.23002649607137857, - -0.06828918783132745, - 0.15489468739467596, - 0.19686334840808606, - -0.10421837828803021, - -0.010265995339134143, - -0.11726184242126435 - ], - [ - -0.3133638042802869, - -0.12576395051637063, - -0.0257296651489721, - -0.11155202308853379, - 0.04303579521717299, - 0.006432499120610673, - -0.12356897033070907, - -0.014949766784474164, - -0.026522912927788037, - -0.092923483875632, - -0.042129734225418165, - 0.22232835113356042, - -0.11424050164336742, - -0.04716248650313244, - -0.01870868968091875, - -0.10753880542597549, - -0.04257520182764234, - -0.17252523720409768, - -0.0762559044573318, - -0.036468262799005606, - -0.14454973560869733, - -0.06002596479265245, - 0.014947075410055759, - -0.14212102009500518, - 0.1588063159357275, - -0.09383278046126006, - -0.04766192947635623, - 0.19758465652790386, - 0.007489657183285387, - -0.19277518096364213, - -0.11585570773341893, - -0.10801395749135034, - 0.04042606931063334, - -0.12183241673794884, - 0.051923151137031706, - -0.007795548072363665, - -0.08743778864229823, - -0.1485444510760658, - 0.07466624837819014, - -0.055747172413423425, - 0.08195889754687626, - 0.1086928695246847, - 0.10710691564348536, - 0.09207384615990799, - 0.010096949243863942, - -0.02266123527575032, - 0.379557921045677, - 0.26128956583625224, - -0.019028434628708502, - 0.0345367151999763, - -0.08374043180727658, - 0.024779257167101405, - -0.20125147857996398, - -0.09707112107630173, - 0.14367977715129787, - 0.1525330528970675, - 0.16683093471311403, - 0.12609075762532387, - 0.09955815773803346, - -0.06605296029731811, - 0.15382282573361714, - 0.0380679096898543, - 0.2193915714071009, - -0.056120833093869775 - ], - [ - 0.05340300575157047, - 0.035828398088086626, - 0.10084278783509146, - 0.20001262758387386, - -0.1016656843919245, - 0.09352739944001547, - -0.1870926783982665, - -0.06706383240218211, - -0.07858430960956415, - 0.05353742471714134, - -0.32692256792321633, - -0.04078757275271229, - 0.10972060974701814, - -0.247910278020381, - 0.013918054845057008, - 0.12459381417198268, - -0.1831042860078757, - 0.17740764155227928, - -0.3040218188620323, - -0.072937205756485, - 0.07717213614686569, - 0.3016989883540223, - -0.013355768503242474, - -0.2573471624991598, - 0.17283433653934432, - 0.07061341151831989, - -0.014993269448981085, - -0.09395044809921518, - 0.015131370770654361, - -0.05821589322342021, - -0.2176565762051844, - -0.12418236373839028, - -0.019447388558913457, - 0.12716128718380745, - 0.15405702219702194, - 0.015275726033079353, - -0.02605119905504912, - 0.06385330217391767, - -0.05943118198006547, - 0.0024541510734195616, - 0.14062258512518716, - -0.10104499962645708, - 0.00674430389669494, - -0.17514439902742676, - -0.0482213877384802, - -0.02907000779503163, - -0.0650534915514083, - 0.05212207830115152, - -0.07688910768213036, - 0.08992490624433895, - -0.06711533807278675, - -0.09555450827832636, - -0.11144242835162776, - -0.005771291853631201, - -0.02833676515006708, - -0.01894384351535339, - 0.10289399883322817, - -0.08599566648529328, - -0.18754993283467036, - 0.051252032546830334, - 0.09594979152326319, - -0.06377167683020303, - 0.03307449733585436, - 0.11320941795046051 - ], - [ - 0.006975338470967777, - -0.04251738973232503, - 0.17860337231689757, - 0.013717038996509293, - -0.08086089547609585, - -0.06925027804650646, - -0.07168151952039249, - -0.010863102850189052, - 0.057239140096361434, - 0.029262007882250855, - 0.07058757183660126, - 0.04152640204071237, - 0.06290313199655205, - 2.530541419061616e-05, - -0.1459685267620152, - -0.08813412329432511, - -0.06708003035273438, - 0.005459566607108741, - 0.01443278582100966, - -0.23672849974431043, - 0.12709498094245922, - 0.06579113082876938, - 0.10361189295313472, - -0.04694907851176051, - 0.038727803244469436, - -0.021043673855297595, - 0.11605374610389846, - 0.08333065527784989, - -0.28232527416592296, - 0.15157428451934668, - 0.0675912167096172, - 0.25110236604730113, - -0.07005079694027491, - 0.14737755390969623, - -0.01327889316374873, - -0.2624629883698325, - 0.25236400568217005, - 0.1267402303461054, - 0.2383269198558816, - -0.16172331667400547, - 0.09360469500343578, - 0.025509343590177952, - 0.18260983606839867, - -0.013235486596345753, - 0.07528079365169295, - -0.017196553969712727, - 0.22875323738002987, - -0.1793504225729639, - -0.11528307018419773, - -0.052818364635146026, - 0.09982725411047493, - -0.09695024830550236, - 0.024962336832625328, - -0.047019686451585746, - -0.27292430286470004, - 0.006139541023944741, - -0.0864382261659241, - 0.07702677645359329, - -0.10266096213982519, - -0.17095377303845088, - 0.16259692669251485, - 0.03813311170637195, - 0.11207403532585683, - -0.14326384347348511 - ], - [ - -0.020234360753209942, - -0.010152996880833804, - 0.14113862729808896, - 0.16116858055567246, - -0.10368112639220413, - -0.10602632313990981, - 0.024157883315836747, - 0.027718292077255086, - -0.11960819825543627, - -0.07441661283606671, - 0.062051859121477586, - 0.13243459841607247, - -0.0384455660128962, - -0.14317125143538603, - -0.17166762073726863, - 0.3238790235423948, - -0.03099405268524214, - 0.025226844997997728, - 0.0908023370377416, - 0.13181998392946956, - -0.13987018877635646, - -0.00013495584037855944, - -0.027724202742982824, - -0.05028160950032238, - -0.10281586220794413, - 0.08722504753313562, - 0.14375783432394137, - 0.2900714027402754, - -0.18134624404178531, - 0.18562851580336953, - -0.28288874063431313, - 0.04996817461217232, - 0.06005596989060309, - -0.22114031646543852, - 0.050135579784950736, - -0.012003619267381402, - 0.018558725098732055, - 0.08737584332402432, - -0.07213419274788624, - -0.0020305923400828416, - -0.07374248459245102, - -0.04487571249915528, - -0.0014161560859129244, - -0.037486776927052295, - -0.04644102213689445, - 0.009095689930133087, - -0.13399604169110774, - -0.18676421472073096, - -0.04145682572586189, - 0.010076945798165053, - 0.10184322125694568, - 0.20578415482637152, - -0.035796194889646894, - 0.10173624892540775, - 0.018999569034751244, - 0.10384263806950261, - 0.25219966798426574, - 0.18873835496515554, - 0.10411378207200757, - 0.20593409811053978, - -0.10469835293357366, - 0.06453650796629358, - 0.035864822243798604, - -0.17676737920363436 - ], - [ - -0.304064971754362, - -0.13310828495825053, - 0.07245087238624925, - -0.04488087964265041, - 0.22098019322025905, - -0.15382265504510112, - 0.09959200829733424, - 0.028468363205901515, - 0.03380822391213274, - 0.06838550299871987, - 0.14655377145327045, - -0.0715730134114822, - -0.18443856980638712, - -0.13512855426643738, - 0.12808403647517747, - -0.016862211915839427, - -0.13045712383480076, - 0.15487648569208765, - -0.026406639001762627, - -0.09307414957273884, - 0.19246688566696932, - -0.009278559429204027, - -0.08589190658606714, - -0.04943948598583218, - -0.07298364749602124, - -0.27401448535343276, - 0.1737636801680142, - -0.017362562137060243, - -0.10304821398643985, - 0.0959904033293338, - -0.06876033943918046, - 0.0885981629589672, - 0.10520574951635933, - -0.04551957044576904, - 0.15344615637914866, - 0.08896314200248523, - -0.1730459206787742, - 0.10008106575241155, - -0.1182306262765487, - 0.09379192707687102, - -0.06785618056389639, - 0.006841932898527119, - 0.0762725335511324, - -0.004208408519086435, - -0.03672003913821707, - -0.0943022707937872, - -0.020372293391280095, - 0.07896475804810464, - -0.278033918027091, - -0.05125529445372451, - -0.1000147440039146, - 0.09660944365888685, - -0.15168190833170397, - -0.0809340016560505, - -0.009708408855161294, - -0.2328031939544511, - -0.22094292355761178, - -0.17035280726233534, - 0.001416017501529008, - 0.09576266281147917, - 0.026448641905083822, - -0.07978792627703271, - -0.15540266367722452, - -0.14582411752290925 - ], - [ - 0.10063394193621032, - 0.00776753313936549, - -0.24027455709608178, - 0.09911580808619246, - -0.06433712265783656, - 0.038607384022612226, - -0.05391284571715087, - -0.08787584997558386, - -0.10144114939845429, - 0.03280344405848499, - -0.06712447366923416, - 0.15418279710750998, - 0.08438445872576535, - -0.0401549325325791, - 0.16883772503628133, - -0.09607709617248276, - -0.04378866828050629, - 0.12905894997447528, - 0.1100820377874031, - 0.0611303476161838, - -0.12979109805962086, - -0.1777437121007127, - -0.1832015132717761, - -0.1165926992975546, - -0.012799161457556626, - -0.09072982922283045, - -0.014420874666719825, - -0.0015803090338914992, - 0.1291649719658745, - 0.20444614848915066, - 0.23101718959948675, - 0.13599645734544996, - -0.0810717787431851, - -0.2785413644425352, - 0.008137892659381418, - 0.04605760275162815, - 0.1896199546035091, - 0.2315645964547797, - -0.1578612582319236, - -0.07548388354834495, - -0.08286730588539744, - 0.1345822533801996, - 0.06855420856471987, - -0.24834592734412314, - 0.11121992490816082, - -0.17168205934770367, - -0.011667258483127486, - 0.026804880984920145, - -0.029009722923049288, - -0.06936264462957098, - -0.1811799240558326, - -0.02783449818517415, - -0.18487608041332027, - -0.0340790315277463, - -0.1290391417724228, - 0.19614854769472503, - 0.053598112398717264, - 0.00671456711251259, - 0.029270784738985645, - -0.09805076308647075, - 0.09902883651033385, - -0.23693851871700536, - -0.01675927644515674, - 0.03125464145500804 - ], - [ - 0.05878862354815508, - 0.10984078022511051, - 0.019477559679315578, - 0.21232210920723532, - 0.06754318026802313, - 0.019988449141281818, - 0.01011545408746658, - 0.06981270010020471, - 0.10954744920592487, - 0.0023917521376227544, - 0.07082447558880657, - 0.09500001801465795, - -0.06483055627125094, - 0.13896566233277585, - -0.053337292097562584, - -0.1363077856462482, - -0.1454148646100898, - 0.1330501270282438, - -0.06490567110526176, - 0.09316755035655977, - -0.3141235001132156, - 0.0250664860915431, - -0.042898906322813256, - -0.09372384347662102, - -0.10071623034462077, - 0.04599155792749588, - 0.04703292032056863, - -0.03578399817384391, - -0.1762113307332753, - -0.11257836303700534, - -0.16031451317089057, - -0.13411551439291303, - -0.0955803422336675, - 0.03654404581258116, - 0.1882120239612718, - -0.0291320594193908, - -0.03330536156111472, - 0.12214913846133023, - 0.25829895901289673, - -0.04019405861572647, - -0.1271714837115375, - 0.04820218615651124, - 0.1592350238508846, - 0.1081001696051158, - 0.09815227964881165, - 0.026895685413825927, - -0.02477049057233294, - -0.03410604493038002, - 0.21504381130082517, - -0.07822965355038296, - -0.16735079602663766, - -0.100320448906678, - 0.03433715307314242, - -0.1866398401630261, - 0.03896270253138573, - -0.28828526096524687, - -0.035130920520614756, - 0.2010396208038843, - 0.16829688975217283, - -0.060522390619984365, - -0.05138351453181182, - -0.21339140272728566, - -0.2196893430043179, - 0.11547077084698879 - ], - [ - -0.06383167986510159, - -0.038366641689547655, - -0.18419276105216487, - 0.07407117069662611, - 0.15146119148349724, - -0.028128347250380648, - 0.05637986715870276, - -0.01764914001432947, - -0.25666882052816187, - 0.015515627786565662, - -0.05775288282020402, - 0.0656813917414808, - 0.10753377947496759, - -0.06238374615981097, - 0.017982517187085014, - -0.13793996024669894, - 0.27307751156938903, - 0.009840978847311268, - -0.2628049448398271, - -0.11705658392704812, - -0.2524573118087912, - 0.2183025819637376, - 0.015420391192491516, - 0.23078549241459656, - -0.10176830388776044, - -0.0938006286159045, - 0.09193017148205215, - 0.04137571828483558, - -0.02293748626267047, - 0.09096753389876226, - 0.022651675803626287, - 0.14223490428722657, - 0.11779181941265013, - -0.0660362667988297, - 0.0668845808571697, - 0.24784671517370205, - -0.0003745980742231077, - -0.021447224222163573, - 0.06753698273574306, - -0.014724870540922997, - 0.05051558511907277, - 0.07516377128107402, - 0.08031395283551238, - 0.21752480130639196, - 0.12829191739929943, - 0.07336641233121344, - -0.08283785981218632, - -0.0044546289032774645, - 0.16223393904454067, - 0.049186483872743, - -0.06356669107515331, - 0.06308336222782714, - 0.10698723466011675, - 0.1367016520941554, - -0.14481591877317027, - -0.14059470589709214, - 0.15874351632197586, - -0.06115497340044626, - -0.2863003136076101, - 0.017524526202871624, - 0.15893188521096102, - 0.048544874441100345, - 0.03670163249514876, - -0.10087448623580766 - ], - [ - -0.04129568073155474, - 0.2628801662093118, - 0.14076526543247347, - -0.032536528768420364, - 0.015489576687115715, - -0.05249939515889562, - 0.08354391828162323, - -0.005870334972907053, - 0.10495607057415239, - -0.14434041601551598, - -0.06440228803741638, - -0.10759560865273449, - 0.15083787009908073, - -0.017088897067033485, - 0.20139143496996545, - -0.012824325835696891, - -0.1324849935340437, - 0.051059548613475406, - -0.04699682691717832, - 0.03442842975733222, - -0.06471050341254636, - 0.11373144246259288, - 0.18204182306135475, - -0.14213060175330008, - -0.10897146982657731, - -0.13706896640444458, - 0.258710357219854, - 0.10864531747851168, - 0.2718562400942613, - -0.09858745623743763, - 0.16865396952011694, - 0.057999259256535735, - -0.10082498638821176, - -0.1396009405428101, - 0.10540754285374233, - 0.08232337380433066, - -0.1616569086968562, - 0.13469319673825322, - -0.10033432696735581, - -0.1506573345489256, - 0.18007681299487113, - 0.11241671126448358, - 0.13674143643669048, - -0.07783089283716862, - 0.0806840834892643, - 0.043908234540304895, - 0.021505333307199326, - -0.055993834396484886, - -0.0008798052491169755, - 0.011744647697020435, - 0.24982975701697455, - 0.13505579645436866, - 0.2837805738882371, - -0.157473681277628, - 0.12676960246015986, - -0.0031255199227933758, - 0.02595488550184108, - 0.02598130675739474, - 0.06074860299150271, - -0.1531152314749652, - -0.08525266771184097, - 0.12504364579498667, - 0.08958727148805576, - -0.007851177387479338 - ], - [ - -0.12610459068947252, - 0.07986952705817317, - -0.03116368615837597, - -0.07146576919776132, - -0.01597608990539793, - -0.10913704289503696, - -0.11385212107775257, - 0.020204438690515598, - -0.1955564850923867, - -0.07030811932404737, - -0.06908655683764069, - -0.0875994691139194, - 0.1119812021695116, - 0.3017642199462576, - -0.20026024714470722, - -0.003661858986877471, - -0.13820411508617717, - 0.04079283018301679, - -0.0037265065726463345, - 0.15252298051931934, - -0.014117389337236358, - -0.047128426567115224, - -0.029990700516052196, - -0.05951031663041619, - -0.24964524165176152, - -0.006178718914092714, - 0.19784547363847574, - -0.07455684136333951, - -0.08006760187568153, - 0.0071176649538351785, - -0.02383499175920355, - -0.15785098511706286, - -0.14550077341343276, - 0.035363600658471946, - -0.19754611987097104, - -0.20506693474447432, - 0.16422239868866154, - 0.03631619156065768, - -0.0412909599977967, - 0.2010702100876493, - 0.19200980339328624, - -0.017706444560168056, - -0.13555058760726368, - -0.008425476371167284, - 0.05278498562097061, - -0.042409890177035434, - -0.02097210693181139, - 0.21843138018734193, - -0.07636553270100183, - 0.002545897464846247, - -0.23762309652767508, - 0.3844641197066561, - 0.10723173181320468, - 0.009925610767399402, - 0.016127028174528126, - -0.07463109428120072, - 0.0002436141403556218, - -0.04097098148190769, - -0.11875717205588408, - -0.06348761342533144, - 0.1560238828351676, - 0.004331548634705816, - 0.047451621604058886, - 0.02424692219235471 - ], - [ - 0.053480902948828235, - 0.07992304285025824, - -0.02110322933759759, - 0.048740263764554426, - -0.06922965248411905, - -0.036357343476017503, - 0.2199696951132687, - -0.1270295300283577, - -0.09554679114635424, - 0.31619025706097414, - -0.09610209505803691, - 0.09677247453338578, - -0.13644976880703827, - 0.051413215306013144, - -0.05710454303999586, - 0.057153417009612524, - 0.0992303988514561, - -0.2513702884874773, - -0.028945105510026246, - -0.012059927318719015, - 0.03655344462324919, - 0.03040429495956469, - 0.10135506527255285, - 0.14157715557641812, - 0.12137583855765141, - -0.03341777082158279, - 0.14698107410172173, - -0.03792636680375602, - -0.23498372816810767, - -0.24384248656767982, - 0.027493945619497733, - -0.1314319883047699, - -0.2385574791936321, - 0.026532253328701936, - -0.11459670916742012, - 0.24595524766220336, - 0.1493041380994081, - 0.06019189818638656, - -0.2128264941325306, - 0.03491638023841281, - 0.1167851499117286, - 0.07349187873333524, - 0.1906403797745543, - -0.07491765557303033, - -0.043035011293844176, - 0.16968746825357278, - -0.17057877650674388, - 0.06702248807142819, - -0.22851745152193306, - -0.09117212923204142, - 0.03013675452422943, - -0.093084773397394, - -0.0030691897183169306, - -0.08931646336664825, - 0.08284991015962417, - 0.01356358481252498, - 0.013701122940358124, - 0.09532769887195326, - 0.09334425610989962, - -0.07590466573119417, - 0.04382645826229195, - -0.13898046567353248, - -0.019425909033042667, - -0.15556947260152418 - ], - [ - -0.02312578290240023, - 0.32665127579173386, - 0.26034547997202423, - -0.10097380155444474, - 0.06285587438698872, - -0.06893160181778336, - -0.07905845093678109, - -0.13131366220406412, - 0.16751310749926626, - -0.13669255341275174, - 0.015495020506160357, - -0.09559020860167267, - -0.11122088354853708, - -0.03521726089543546, - -0.04314522192316998, - -0.012998256516495381, - -0.0008342450532671189, - 0.030746985897694083, - -0.02893629759091547, - -0.060068126556998655, - 0.009832024280760323, - 0.10647945735608319, - 0.06687620924323107, - 0.09888045943342026, - -0.17063225995906528, - 0.08812495225588188, - -0.08577043738806772, - -0.07994547914569164, - -0.055676691981454, - -0.04493444732326734, - 0.12539168511974208, - -0.0946610950934217, - 0.0024538950815003774, - -0.2937596004885412, - 0.05392458172920837, - 0.05992786495677363, - 0.20550027620766426, - -0.30386140546865015, - -0.11453987638322811, - 0.04865162114703623, - -0.050888741319493634, - 0.24739540285253836, - 0.10117373811737786, - -0.11938621315260863, - -0.26286727111342856, - -0.1430055688718369, - 0.045928395754768064, - -0.0604438698342671, - 0.04133963822339442, - -0.014666615414797923, - -0.17104529136044871, - -0.10105059490569818, - -0.07566341902310085, - 0.19236136809144408, - -0.15341779236660313, - -0.16997544636483203, - 0.033297336122743576, - 0.08126343103050676, - -0.008662309572473667, - 0.10229201541007239, - 0.05306933698019438, - -0.030710939492853733, - 0.1164785677538057, - 0.027391158118899344 - ], - [ - -0.0616292529358815, - 0.09176296453936528, - 0.07916224436571424, - -0.017985543729074023, - -0.15292403533510385, - 0.04710656584085074, - 0.34077229195447506, - -0.02541883767100876, - 0.012654583240455871, - -0.034426628847182034, - 0.1360111246111357, - -0.07836430869174266, - 0.1596533649472611, - 0.04215265739957639, - -0.12155701392915917, - -0.17314029866534533, - -0.10690741216427806, - -0.042281119462512576, - -0.010057075261824219, - 0.049573577473517615, - 0.14004509507540733, - 0.022624826230226734, - 0.06658224397218455, - 0.1411078036516843, - 0.11677175571535275, - -0.042879209434123974, - -0.14082170991255208, - -0.18807838925480314, - -0.08546989509985795, - 0.27767211473561765, - -0.1754774603490127, - 0.14097948677894404, - -0.003628400698777742, - -0.12495376608669737, - -0.031332266891001465, - 0.06981192649804033, - -0.03041593688801222, - 0.01907947158534997, - 0.08440892768989568, - 0.15748840306406334, - 0.03254011678163731, - 0.04058643643389781, - 0.19432400809660916, - 0.05546074780155821, - -0.1000182281475824, - -0.16070340355357093, - 0.03506433889402353, - 0.13521380487008408, - 0.015674690268050313, - 0.00017806384534635404, - 0.11939407822957519, - 0.06906058563084033, - -0.06381124123436775, - -0.2179245750185475, - 0.13511669875380802, - 0.08831989144674542, - 0.31697328408467434, - -0.021390717109770082, - -0.17261715496161675, - -0.019664789371025344, - -0.07347534844935687, - -0.09572554943930812, - -0.04536016197514561, - 0.27677678519854376 - ], - [ - -0.26053176103461934, - 0.13608002783963224, - -0.05096026565724869, - 0.017858977824970316, - -0.0640762982222237, - 0.1806740211254762, - -0.07348932353396544, - 0.115352013593277, - 0.0017074267212727145, - -0.00037769896999972674, - 0.051133746972279, - 0.03446826467249106, - -0.03844959861759199, - 0.09110421016798474, - -0.0939615053310095, - 0.36353349704395993, - 0.20191786177559248, - 0.16914820298579228, - -0.15211529653749506, - 0.11784381855143912, - -0.004897604349451921, - -0.0796162763633159, - 0.21726655083526342, - 0.1609228074916334, - 0.12512907287888989, - 0.06629960457841655, - -0.1936502585542167, - 0.09133454434027978, - 0.03200329546689164, - 0.08538333881880288, - 0.09841587583607793, - 0.07801328029135823, - -0.07973736119972663, - 0.07407568922642747, - 0.11296172184819907, - 0.037430323040364276, - -0.004889347833340029, - 0.09060475905030854, - 0.015156117258630008, - -0.06057633445163368, - 0.21880991107136744, - 0.026185514200245983, - 0.19521544666417717, - 0.08114064996420926, - 0.050865176060839686, - -0.06480128277896868, - 0.014893959761754989, - 0.00769058360258812, - -0.029571270277091957, - -0.0700480858429794, - -0.1407632725093592, - 0.08443755407664565, - 0.07776613571288764, - -0.11637159583548948, - -0.13621771295784937, - 0.06476463963397325, - -0.20118867948067312, - -0.16316238958398196, - 0.1976844641732369, - 0.24328353017955917, - -0.006977790279383505, - -0.10789406241260217, - 0.11079965229493395, - 0.1481625016826724 - ], - [ - 0.18713375994409903, - 0.005234371766130407, - 0.05165779081111304, - 0.010896418169803055, - 0.03659563850013869, - 0.032221295625081574, - 0.05771677787802466, - -0.013147617316384917, - -0.07745863144692253, - -0.19965339648954342, - 0.14475769896041282, - 0.09022183005297539, - 0.013637087986661618, - -0.05793533156662455, - -0.09584036757972951, - 0.09638578367396747, - -0.11298817541853888, - -0.09505652923565386, - 0.08594891763139265, - -0.14011606902881563, - 0.05168060307423952, - -0.14134759491610227, - 0.22854949966071386, - -0.041130612523413726, - 0.0008924770498533542, - 0.020968518893708536, - 0.07273211951095314, - -0.11907333793492586, - 0.2116015487752247, - 0.0657762262143122, - 0.005553405548746986, - 0.05812215841799067, - 0.1233479173223669, - 0.34575515880068836, - -0.011314461876763365, - 0.260894338815378, - -0.023503209140328746, - 0.2276388292591083, - 0.11860459963505099, - 0.01963374510247278, - 0.07169153388333288, - 0.18873034498616345, - -0.1065430430855264, - -0.08308180640414664, - -0.12119571678526368, - -0.038516288560585435, - -0.02794244593832044, - 0.27360818684555227, - 0.12342821465005875, - 0.16035472852857788, - -0.10017712601977556, - 0.04500429041407049, - -0.08733253352828081, - 0.06250285083437203, - -0.1014609385548908, - -0.16309804295612526, - 0.05067096018085278, - 0.14738351903906285, - 0.0980224315768047, - 0.024498471823776874, - -0.06910206247524907, - -0.158514397613343, - 0.1694500446943089, - -0.21525534476913785 - ], - [ - -0.13947311748621868, - 0.0437739654440528, - 0.13228217184866287, - -0.1350474669127765, - -0.23141761308840766, - -0.04158192821207036, - -0.2516105220994294, - -0.0498715268601334, - -0.16493956978772015, - -0.11233767270733863, - 0.17331351332902797, - -0.025477184360352047, - 0.02637304185730431, - -0.14476447607069398, - -0.011799702430189171, - -0.024171310922800338, - -0.2148747124801453, - -0.04975770499615326, - -0.02200592465081963, - 0.008076242439433794, - 0.09326249504211948, - -0.030676481424904208, - -0.2611232241106388, - 0.04531975754838454, - 0.0827709155555637, - -0.061490083318184445, - -0.19086793767538565, - -0.07483037836939357, - 0.08887769801641625, - -0.05649402435810736, - -0.07705654836762621, - -0.13896254387331144, - -0.055517593395639823, - 0.027150004871689587, - -5.349216119275476e-05, - 0.2786001259154094, - 0.2531928202259057, - 0.11780822026390401, - 0.0602904441525028, - -0.025546410114100443, - -0.12973469767995505, - 0.05806226353010686, - 0.21444875869125296, - 0.07004312252993251, - 0.17571592357752697, - 0.20688155586332127, - -0.014933771975990155, - -0.01897205488504897, - 0.16711706199227935, - -0.18464879221765945, - 0.14343170626695073, - 0.14424728075885002, - 0.07808357931618659, - 0.18291744930273462, - 0.08396205583973979, - 0.024100912608128907, - -0.17045427599140908, - -0.08097465402723258, - -0.06045258468926889, - 0.0022254020937146524, - -0.04803710042927474, - -0.016914444546294982, - -0.05400925320886357, - -0.08010081311283498 - ], - [ - -0.2313082849912339, - -0.12538329558733277, - -0.003972992781784823, - -0.11642476277070964, - 0.029888702592623103, - 0.13626516744367687, - -0.008260952857934534, - 0.17756574388380755, - -0.011079152429662786, - 0.040671620961932366, - -0.038646588837294694, - 0.17976732202773565, - 0.1105046436180642, - -0.09721498212523101, - -0.12322259152755342, - -0.005357971961392657, - 0.04553332395694619, - 0.06776228014688622, - 0.14709351056990774, - -0.12913526828114685, - -0.1622679492386197, - 0.010853252291867099, - -0.10702408071397124, - 0.05875117993081506, - -0.07735872132577606, - 0.02566910169736706, - 0.04073634267251954, - 0.006284272873653366, - 0.041354633461587964, - 0.07902798465441212, - -0.004529344446289432, - -0.007787148617631518, - -0.31714405182724476, - 0.00307669616370939, - 0.11753535951982519, - -0.11501744131496083, - -0.02901691762134572, - -0.07263734667512811, - 0.07003975651117786, - 0.13361234738970829, - 0.08491299026407917, - -0.029966255246319923, - 0.11234883391704374, - -0.2328287369383309, - -0.3240007706565678, - -0.1469949192525189, - -0.26061203498582325, - 0.08689292519426908, - 0.26454234384806546, - 0.01397375190138643, - 0.13849439246969067, - -0.16654594524246646, - 0.055416117290914654, - -0.014420845257911924, - 0.17722306291850068, - 0.016694505037225638, - -0.17131232213385347, - -0.08378178447128264, - -0.09799683219714099, - -0.10753196132303076, - -0.029817558789986678, - -0.006479444512317684, - 0.0706966441585111, - -0.20480867175570514 - ] - ] - } - ] - } -} diff --git a/browser-runtime/forks/apply-fork-overlay.mjs b/browser-runtime/forks/apply-fork-overlay.mjs index e13c86b..f76db91 100644 --- a/browser-runtime/forks/apply-fork-overlay.mjs +++ b/browser-runtime/forks/apply-fork-overlay.mjs @@ -38,10 +38,10 @@ export function validateManifest(manifest) { if (manifest?.schemaVersion !== 1 || manifest.status !== "feasibility-overlay") { throw new Error("unsupported fork overlay manifest"); } - if (manifest.hookAbi !== "block-sites-v5") { + if (manifest.hookAbi !== "block-sites-v6") { throw new Error("unexpected fork overlay hook ABI"); } - if (manifest.structuredHookProfile !== "standard-v4") { + if (manifest.structuredHookProfile !== "standard-v5") { throw new Error("unexpected fork overlay structured-hook profile"); } if (manifest.exactReadoutAbi !== "exact-readout-v2") { diff --git a/browser-runtime/forks/base_model_adapters.py b/browser-runtime/forks/base_model_adapters.py index 6d40035..b33b753 100644 --- a/browser-runtime/forks/base_model_adapters.py +++ b/browser-runtime/forks/base_model_adapters.py @@ -233,7 +233,7 @@ def get_default_spec(self): _name.startswith(("drowse_", "_drowse_")) or _name == "_get_logits" ): setattr(_head, _name, _method) - # Fused q/k/v and LayerNorm: no unit sites, the residual descriptor (`standard-v4-residual`). + # Fused q/k/v and LayerNorm: no unit sites, the residual descriptor (`standard-v5-residual`). _head._drowse_block_spec = lambda self: None diff --git a/browser-runtime/forks/build-mixed-affine.py b/browser-runtime/forks/build-mixed-affine.py deleted file mode 100644 index accc4d5..0000000 --- a/browser-runtime/forks/build-mixed-affine.py +++ /dev/null @@ -1,81 +0,0 @@ -#!/usr/bin/env python3 -"""Record the affine lowering of the unit-ablation `mixed` case's push. - -The `mixed` golden (`0.4 deceptive_fixture + !neuron/L1n5`) records the forwards but not how its -push of the session-registered fixture direction lowers to affine groups: that lowering runs -through the fixture session's whitener. This script runs drowse's own lowering -(`tests.support.browser_units.lowered_pushes`, the one `neuron-push` records) on each fixture -session and writes it in neuron-push's case shape, bound to the model file's digest, so the C VM -and WebGPU harnesses can run `mixed` from its recorded tables plus these groups. - -Usage (from the drowse.ai root, CPU only): - - python browser-runtime/forks/build-mixed-affine.py [--check] - -`--check` regenerates in memory and fails if the committed file differs beyond 1e-6. -""" - -from __future__ import annotations - -import argparse -import json -import os -import sys -from pathlib import Path - -ROOT = Path(__file__).resolve().parents[2] -OUT = ROOT / "browser-runtime" / "fixtures" / "unit-ablation-mixed-affine-v1.json" -EXPRESSION = "0.4 deceptive_fixture" -ARCHES = ("qwen3", "gemma3") - - -def build() -> dict: - os.environ.setdefault("CUDA_VISIBLE_DEVICES", "") - sys.path.insert(0, str(ROOT / "drowse")) - from tests.support import browser_units as bu - - if f"0.4 {bu.FIXTURE_DIRECTION} + !neuron/L1n5" not in [s for _n, s, _k in bu.ABLATION_CASES]: - raise SystemExit("the unit-ablation `mixed` case no longer pushes " + EXPRESSION) - arches = {} - for arch in ARCHES: - with bu.fixture(arch, lenses=False) as fx: - bu._register_fixture_direction(fx) - arches[arch] = {"cases": bu.lowered_pushes(fx, bu.FIXTURE_DIRECTION, [EXPRESSION])} - return { - "schemaVersion": 1, - "about": "The unit-ablation `mixed` case's push lowered to affine groups by drowse's " - "lowered_pushes on each fixture session (neuron-push's case shape). Regenerate " - "with python browser-runtime/forks/build-mixed-affine.py.", - "golden": "unit-ablation", - "case": "mixed", - "fixtureModels": {"sha256": bu.model_file_sha256()}, - "arches": arches, - } - - -def _close(a, b) -> bool: - if isinstance(a, dict) and isinstance(b, dict): - return a.keys() == b.keys() and all(_close(a[k], b[k]) for k in a) - if isinstance(a, list) and isinstance(b, list): - return len(a) == len(b) and all(_close(x, y) for x, y in zip(a, b)) - if isinstance(a, float) or isinstance(b, float): - return abs(float(a) - float(b)) <= 1e-6 - return a == b - - -def main() -> None: - parser = argparse.ArgumentParser() - parser.add_argument("--check", action="store_true") - args = parser.parse_args() - doc = build() - if args.check: - if not _close(json.loads(OUT.read_text()), doc): - raise SystemExit(f"{OUT.name} is stale: regenerate it") - print(f"{OUT.name} matches") - return - OUT.write_text(json.dumps(doc, indent=1) + "\n") - print(f"wrote {OUT}") - - -if __name__ == "__main__": - main() diff --git a/browser-runtime/forks/build-production-webgpu.py b/browser-runtime/forks/build-production-webgpu.py index 97fef0c..98eb023 100644 --- a/browser-runtime/forks/build-production-webgpu.py +++ b/browser-runtime/forks/build-production-webgpu.py @@ -43,11 +43,11 @@ ] OPTIONAL_SOURCE_FILES = ["generation_config.json", "LICENSE", "README.md"] #: Hook ABI v5 (HOOK_ABI.md §1, §7): dense gated-MLP blocks compile the unit sites -#: (`standard-v4`); every other architecture attests the residual descriptor. +#: (`standard-v5`); every other architecture attests the residual descriptor. UNIT_ARCHITECTURES = frozenset({"qwen3", "gemma3_text", "gemma3"}) -STRUCTURED_HOOK_PROFILES = ("standard-v4", "standard-v4-residual") -RUNTIME_ABI = "drowse-web-runtime-v2" -HOOK_ABI = "block-sites-v5" +STRUCTURED_HOOK_PROFILES = ("standard-v5", "standard-v5-residual") +RUNTIME_ABI = "drowse-web-runtime-v3" +HOOK_ABI = "block-sites-v6" #: The bridge's conversation rules each MLC template takes, so a chat prompt prefills what the #: model's own chat template (and drowse's scene grammar) renders: Qwen3 renders no system block #: without a system message (MLC's template defaults one); Gemma 3 folds the system message into @@ -59,16 +59,16 @@ def structured_hook_profile_for(architecture: str) -> str: - return "standard-v4" if architecture in UNIT_ARCHITECTURES else "standard-v4-residual" + return "standard-v5" if architecture in UNIT_ARCHITECTURES else "standard-v5-residual" THINKING_DELIMITERS = ("", "") PRODUCTION_QUANTIZATIONS = ("q4f16_1", "q4f32_1", "q0f32") PRODUCTION_ARCHITECTURES = ("qwen3", "llama", "gemma3_text", "gpt2", "gpt_neox", "qwen3_5") BASE_ADAPTER_DIGESTS = { - "base_model_adapters.py": "92606e6406f81221e76a30f41f3aa0a08e4acb830fdcdd4b5ec5b4034b974c1c", + "base_model_adapters.py": "c7d72ca6fb9fadb5ad38a5f0d34dadba4e718d0c44d55cb53622879e2e779d0a", } HYBRID_ADAPTER_DIGESTS = { **BASE_ADAPTER_DIGESTS, - "qwen35_adapter.py": "77865be561dfebca0a888d5f0cb8a060206a28ef0c18ff8300bf759d8df73514", + "qwen35_adapter.py": "be3e54d32d7cf48902ab0222d847fc397b9a8808f1bdb935e8602d697d7009dd", "hybrid_state_kernels.py": "7075a4b80b11093503ca5048074095eb41c39cade72edf4fa6a0f69b2fdfb8a3", } BASE_MODEL_SOURCE_DIGESTS = { diff --git a/browser-runtime/forks/build-units-fixtures.py b/browser-runtime/forks/build-units-fixtures.py deleted file mode 100644 index e6e97f8..0000000 --- a/browser-runtime/forks/build-units-fixtures.py +++ /dev/null @@ -1,316 +0,0 @@ -#!/usr/bin/env python3 -"""Build an MLC model directory from one of drowse's hook ABI v5 fixture checkpoints. - -The checkpoint is `write_checkpoint(arch, path)` from drowse's `tests/support/browser_units.py` -(the generator behind every `*-v1.json` units golden). This script binds it to the goldens' -model file (`units-tiny-models-v1.json`: every tensor's fp32 sha256), maps the recorded HF -config to MLC's config (names and the Gemma sliding pattern MLC cannot read from `layer_types`), -converts the weights with MLC's own converter, and proves the result exact: q0f32 tensors equal -the source bit for bit, and every q4f32_1 tensor dequantizes to the source bit for bit (the -fixture weights are q4-exact, so MLC's `scale = max|w| / 7` must reproduce them). Libraries are -compiled from the written config with `compile-tiny-webgpu.py --model-config`. -""" - -from __future__ import annotations - -import argparse -import hashlib -import importlib.util -import json -import os -import shutil -import sys -import tempfile -from pathlib import Path - -import numpy as np - -sys.path.insert(0, str(Path(__file__).resolve().parent)) -from overlay_checks import ( # noqa: E402 - bootstrap_mlc_package, - ensure_import_roots, - require_llvm, - verify_sources, -) - -FIXTURE_MODELS = "units-tiny-models-v1" -ARCHES = {"qwen3": "qwen3", "gemma3_text": "gemma3"} -QUANTIZATIONS = ("q0f32", "q4f32_1") - - -def main() -> None: - args = parse_args() - mlc_repository = args.mlc_repository.resolve(strict=True) - tvm_repository = args.tvm_repository.resolve(strict=True) - checkpoint = args.checkpoint.resolve(strict=True) - output = args.output.resolve() - if output.exists(): - raise SystemExit(f"output already exists: {output}") - verify_sources(mlc_repository, tvm_repository) - ensure_import_roots(mlc_repository, tvm_repository) - os.environ.setdefault("SKIP_LOADING_MLCLLM_SO", "1") - - model_file = json.loads(args.model_file.read_text(encoding="utf-8")) - if ( - model_file.get("golden") != "units-tiny-models" - or model_file.get("fixtureModels", {}).get("name") != FIXTURE_MODELS - or model_file.get("hookAbi") != "block-sites-v5" - ): - raise SystemExit(f"{args.model_file} is not the {FIXTURE_MODELS} model file") - entry = model_file["arches"][ARCHES[args.architecture]] - if entry["family"] != args.architecture: - raise SystemExit(f"model file family {entry['family']} is not {args.architecture}") - source = verify_checkpoint(checkpoint, entry) - - import tvm - from safetensors.numpy import load_file - - bootstrap_mlc_package(mlc_repository, "fixture", model_registry=True) - from mlc_llm.interface.convert_weight import convert_weight - from mlc_llm.model import MODELS - from mlc_llm.quantization import QUANTIZATION - - require_llvm(tvm) - production = load_production_tool() - model = MODELS[args.architecture] - if args.architecture == "gemma3_text": - model = production.gemma_conversion_model(model) - quantization = QUANTIZATION[args.quantization] - mlc_config = mlc_source_config(args.architecture, entry, args.context_window_size) - - stage = Path(tempfile.mkdtemp(prefix=f"{output.name}.partial-", dir=output.parent)) - try: - config_path = stage / "source-config.json" - config_path.write_text(json.dumps(mlc_config, indent=2, sort_keys=True) + "\n") - convert_weight( - config=config_path, - quantization=quantization, - model=model, - device=tvm.runtime.cpu(), - source=checkpoint / "model.safetensors", - source_format="huggingface-safetensor", - output=stage, - encode_format="raw", - ) - config_path.unlink() - model_config = model.config.from_dict(mlc_config) - mapping = model.source["huggingface-safetensor"](model_config, quantization) - report = verify_conversion(stage, load_file(str(checkpoint / "model.safetensors")), mapping, - args.quantization) - write_chat_config(stage, checkpoint, args, entry, production.browser_model_config( - args.architecture, model_config)) - shutil.copyfile(checkpoint / "tokenizer.json", stage / "tokenizer.json") - (stage / "drowse-units-fixture.json").write_text(json.dumps({ - "fixtureModels": FIXTURE_MODELS, - "fixtureModelsSha256": hashlib.sha256(args.model_file.read_bytes()).hexdigest(), - "arch": ARCHES[args.architecture], - "architecture": args.architecture, - "quantization": args.quantization, - "contextWindowSize": args.context_window_size, - "sourceTensors": source, - "conversion": report, - }, indent=2, sort_keys=True) + "\n") - stage.rename(output) - except BaseException: - shutil.rmtree(stage, ignore_errors=True) - raise - print(json.dumps({"output": str(output), "architecture": args.architecture, - "quantization": args.quantization, **report}, sort_keys=True)) - - -def parse_args() -> argparse.Namespace: - parser = argparse.ArgumentParser() - parser.add_argument("--mlc-repository", required=True, type=Path) - parser.add_argument("--tvm-repository", required=True, type=Path) - parser.add_argument("--checkpoint", required=True, type=Path) - parser.add_argument("--model-file", required=True, type=Path) - parser.add_argument("--architecture", required=True, choices=sorted(ARCHES)) - parser.add_argument("--quantization", required=True, choices=QUANTIZATIONS) - parser.add_argument("--context-window-size", type=int, default=128) - parser.add_argument("--output", required=True, type=Path) - return parser.parse_args() - - -def load_production_tool(): - path = Path(__file__).resolve().with_name("build-production-webgpu.py") - spec = importlib.util.spec_from_file_location("drowse_build_production_webgpu", path) - module = importlib.util.module_from_spec(spec) - spec.loader.exec_module(module) - return module - - -def verify_checkpoint(checkpoint: Path, entry: dict) -> int: - """Every tensor the model file lists, with its recorded fp32 digest; nothing else but the - tied head.""" - from safetensors.numpy import load_file - - tensors = load_file(str(checkpoint / "model.safetensors")) - listed = {row["name"]: row for row in entry["tensors"]} - extra = sorted(set(tensors) - set(listed) - {"lm_head.weight"}) - if extra: - raise SystemExit(f"checkpoint has tensors the model file does not list: {extra[:4]}") - for name, row in listed.items(): - value = tensors.get(name) - if value is None: - raise SystemExit(f"checkpoint lacks {name}") - if value.dtype != np.float32 or list(value.shape) != row["shape"]: - raise SystemExit(f"checkpoint tensor {name} is not fp32 {row['shape']}") - digest = hashlib.sha256(value.astype(" int: - """MLC's Gemma3 rule is `local = (L + 1) % pattern != 0`; find the pattern that reproduces - the HF `layer_types` exactly.""" - count = len(layer_types) - for pattern in range(1, count + 1): - if all((layer_types[i] == "sliding_attention") == ((i + 1) % pattern != 0) - for i in range(count)): - return pattern - raise SystemExit(f"layer_types {layer_types} has no MLC sliding pattern") - - -def mlc_source_config(architecture: str, entry: dict, context_window_size: int) -> dict: - hf = entry["config"] - common = { - "hidden_size": hf["hidden_size"], - "intermediate_size": hf["intermediate_size"], - "num_hidden_layers": hf["num_hidden_layers"], - "num_attention_heads": hf["num_attention_heads"], - "num_key_value_heads": hf["num_key_value_heads"], - "head_dim": hf["head_dim"], - "rms_norm_eps": hf["rms_norm_eps"], - "vocab_size": hf["vocab_size"], - "context_window_size": context_window_size, - "prefill_chunk_size": context_window_size, - "max_batch_size": 1, - } - if architecture == "qwen3": - rope = hf["rope_parameters"] - if rope.get("rope_type") != "default" or hf["sliding_window"] is not None: - raise SystemExit("the qwen3 fixture must use default RoPE and no sliding window") - return {**common, "model_type": "qwen3", "hidden_act": hf["hidden_act"], - "attention_bias": False, "rope_theta": rope["rope_theta"], - "tie_word_embeddings": hf["tie_word_embeddings"]} - rope = hf["rope_parameters"] - if any(rope[kind].get("rope_type") != "default" for kind in rope): - raise SystemExit("the gemma3 fixture must use default RoPE") - if hf["attn_logit_softcapping"] is not None or hf["final_logit_softcapping"] is not None: - raise SystemExit("the gemma3 fixture must not soft-cap logits") - text = {**common, "hidden_activation": hf["hidden_activation"], - "query_pre_attn_scalar": hf["query_pre_attn_scalar"], - "position_embedding_base": rope["full_attention"]["rope_theta"], - "rope_local_base_freq": rope["sliding_attention"]["rope_theta"], - "sliding_window_size": hf["sliding_window"], - "sliding_window_pattern": sliding_pattern(hf["layer_types"])} - return {"model_type": "gemma3_text", "text_config": text, "vocab_size": hf["vocab_size"], - "context_window_size": context_window_size, "prefill_chunk_size": context_window_size, - "sliding_window_size": -1, "max_batch_size": 1, "is_text_model": True} - - -def load_tensor_cache(directory: Path) -> dict[str, np.ndarray]: - cache = json.loads((directory / "tensor-cache.json").read_text(encoding="utf-8")) - tensors = {} - for shard in cache["records"]: - data = (directory / shard["dataPath"]).read_bytes() - for record in shard["records"]: - if record.get("format") != "raw": - raise SystemExit(f"{record['name']} is not stored raw ({record.get('format')})") - chunk = data[record["byteOffset"]: record["byteOffset"] + record["nbytes"]] - tensors[record["name"]] = np.frombuffer(chunk, dtype=record["dtype"]).reshape( - record["shape"]) - return tensors - - -def dequantize_q4(weight: np.ndarray, scale: np.ndarray) -> np.ndarray: - """MLC group quantization (q4f32_1): eight 4-bit codes per uint32, low nibble first, groups of - 32 along the last axis, value = (code − 7) · scale.""" - rows = weight.shape[0] - shifts = np.arange(8, dtype=np.uint32) * 4 - codes = (weight[:, :, None] >> shifts) & np.uint32(0xF) - codes = codes.reshape(rows, -1).astype(np.float32) - columns = codes.shape[1] - if scale.shape != (rows, columns // 32): - raise SystemExit(f"q4 scale shape {scale.shape} does not match codes {codes.shape}") - return (codes - np.float32(7)) * np.repeat(scale.astype(np.float32), 32, axis=1) - - -def verify_conversion(directory: Path, source: dict, mapping, quantization: str) -> dict: - converted = load_tensor_cache(directory) - exact = q4 = 0 - for mlc_name, hf_names in mapping.param_map.items(): - arrays = [source[name] for name in hf_names] - expected = np.asarray(mapping.map_func[mlc_name](*arrays), dtype=np.float32) - base = mlc_name[: -len(".weight")] if mlc_name.endswith(".weight") else mlc_name - if quantization == "q4f32_1" and f"{base}.q_weight" in converted: - weight, scale = converted[f"{base}.q_weight"], converted[f"{base}.q_scale"] - if scale.dtype != np.float32: - raise SystemExit(f"{base}.q_scale is {scale.dtype}, not float32") - actual = dequantize_q4(weight, scale)[:, : expected.shape[-1]] - grouped = np.abs(expected.astype(np.float64)).reshape(expected.shape[0], -1, 32) - if not np.array_equal(scale, (grouped.max(-1) / 7).astype(np.float32)): - raise SystemExit(f"{base}.q_scale is not max|w| / 7 of the source") - q4 += 1 - else: - actual = converted.get(mlc_name) - if actual is None: - raise SystemExit(f"converted cache lacks {mlc_name}") - if actual.shape != expected.shape or not np.array_equal( - actual.astype(np.float32).view(np.uint32), expected.view(np.uint32) - ): - worst = float(np.max(np.abs(actual.astype(np.float64) - expected))) \ - if actual.shape == expected.shape else float("inf") - raise SystemExit(f"{mlc_name} is not exact after conversion (max |Δ| {worst:g})") - exact += 1 - return {"exactTensors": exact, "q4Tensors": q4} - - -def write_chat_config(directory: Path, checkpoint: Path, args, entry: dict, model_config: dict): - tokenizer = entry["tokenizer"] - vocab = json.loads((checkpoint / "tokenizer.json").read_text(encoding="utf-8")) - eos = tokenizer["eos"] - config = { - "model_type": args.architecture, - "quantization": args.quantization, - "model_config": model_config, - "vocab_size": entry["config"]["vocab_size"], - "active_vocab_size": tokenizer["size"], - "context_window_size": args.context_window_size, - "sliding_window_size": -1, - "prefill_chunk_size": args.context_window_size, - "attention_sink_size": -1, - "tensor_parallel_shards": 1, - "pipeline_parallel_stages": 1, - "tokenizer_files": ["tokenizer.json"], - "tokenizer_info": {"token_postproc_method": "byte_level", "prepend_space_in_encode": False, - "strip_space_in_decode": False}, - "conv_template": { - "name": "drowse-units-fixture", "system_template": "", "system_message": "", - "roles": {"user": "", "assistant": ""}, "seps": [""], "role_content_sep": "", - "role_empty_sep": "", "stop_str": [], "stop_token_ids": [eos], - }, - "bos_token_id": tokenizer["bos"] if tokenizer["bos"] is not None else eos, - "eos_token_id": eos, - "pad_token_id": tokenizer["pad"], - # Raw completions start at the family's BOS, as the goldens' short prompt does. - "drowse_completion_prefix_token_ids": [] if tokenizer["bos"] is None else [tokenizer["bos"]], - "drowse_capture_special_token_ids": sorted( - vocab["model"]["vocab"][token] if token in vocab["model"]["vocab"] else - next(item["id"] for item in vocab["added_tokens"] if item["content"] == token) - for token in tokenizer["specials"] - ), - "repetition_penalty": 1.0, "frequency_penalty": 0.0, "presence_penalty": 0.0, - "top_p": 1.0, "temperature": 0.0, - } - (directory / "mlc-chat-config.json").write_text(json.dumps(config, indent=2, sort_keys=True) - + "\n") - - -if __name__ == "__main__": - main() diff --git a/browser-runtime/forks/compile-tiny-webgpu.py b/browser-runtime/forks/compile-tiny-webgpu.py index 4cb5a90..bed66f0 100644 --- a/browser-runtime/forks/compile-tiny-webgpu.py +++ b/browser-runtime/forks/compile-tiny-webgpu.py @@ -28,11 +28,6 @@ def main() -> None: tvm_repository = args.tvm_repository.resolve(strict=True) output = args.output.resolve() validate_output(output) - fixture_config = ( - json.loads(args.model_config.read_text(encoding="utf-8")) - if args.model_config is not None - else None - ) verify_sources(mlc_repository, tvm_repository) emcc = verify_emcc() verify_wasm_runtime(mlc_repository) @@ -91,7 +86,6 @@ def main() -> None: QUANTIZATION, make_quantization_functions, args.context_window_size, - fixture_config, ) module, named_params, ext_mods = model.export_tvm( spec=model.get_default_spec(), @@ -195,12 +189,6 @@ def parse_args() -> argparse.Namespace: ) parser.add_argument("--context-window-size", type=int, choices=[16, 2048, 4096], default=16) parser.add_argument("--output", required=True, type=Path) - parser.add_argument( - "--model-config", - type=Path, - help="mlc-chat-config.json of a build-units-fixtures.py model to compile instead of the " - "synthetic tiny config (its context window replaces --context-window-size)", - ) parser.add_argument("--ir-stats-only", action="store_true") return parser.parse_args() @@ -273,26 +261,7 @@ def create_model( quantization_registry, make_quantization_functions, context_window_size, - fixture_config=None, ): - if fixture_config is not None: - # A converted fixture model (build-units-fixtures.py): compile exactly its config. - if ( - fixture_config["model_type"] != architecture - or fixture_config["quantization"] != quantization_name - or architecture not in ("qwen3", "gemma3_text") - ): - raise SystemExit("--model-config does not describe this architecture and quantization") - config_class, model_class = ( - (qwen_config_class, qwen_model_class) - if architecture == "qwen3" - else (gemma_config_class, gemma_model_class) - ) - config = config_class.from_dict(fixture_config["model_config"]) - quantization = quantization_registry[quantization_name] - quantize = make_quantization_functions(model_class)[quantization.kind] - model, _ = quantize(config, quantization) - return model, architecture, config common = { "hidden_size": 64, "intermediate_size": 128, diff --git a/browser-runtime/forks/export-webgpu-kernel-goldens.py b/browser-runtime/forks/export-webgpu-kernel-goldens.py index 300fa2c..306816a 100644 --- a/browser-runtime/forks/export-webgpu-kernel-goldens.py +++ b/browser-runtime/forks/export-webgpu-kernel-goldens.py @@ -54,9 +54,9 @@ def emit(module, label, metadata_fields): class Affine(nn.Module): - def forward(self, residual, active, basis, neutral, target, along, kappa, kind, direction, bias, threshold): + def forward(self, residual, active, basis, read, neutral, target, along, kappa, kind, direction, bias, threshold): return apply_structured_affine_hook( - residual, 0, active, basis, neutral, target, along, kappa, kind, direction, bias, threshold + residual, 0, active, basis, read, neutral, target, along, kappa, kind, direction, bias, threshold ) @@ -65,6 +65,7 @@ def forward(self, residual, active, basis, neutral, target, along, kappa, kind, "residual": [b, t, h], "active": [1, 4], "basis": [1, 4, 8, h], + "read": [1, 4, 8, h], "neutral": [1, 4, h], "target": [1, 4, 8], "along": [1, 4], diff --git a/browser-runtime/forks/manifest.json b/browser-runtime/forks/manifest.json index 27fde87..9a77edb 100644 --- a/browser-runtime/forks/manifest.json +++ b/browser-runtime/forks/manifest.json @@ -1,8 +1,8 @@ { "schemaVersion": 1, "status": "feasibility-overlay", - "hookAbi": "block-sites-v5", - "structuredHookProfile": "standard-v4", + "hookAbi": "block-sites-v6", + "structuredHookProfile": "standard-v5", "exactReadoutAbi": "exact-readout-v2", "tvmRepository": "https://github.com/apache/tvm.git", "tvmCommit": "68ba2b31c2a6d202fcd44e5780ef10ce08721dd5", @@ -58,17 +58,17 @@ "baseCommit": "9fa644f54b04983adea4d0168f49fc6af4a893ba", "baseTree": "3ecd325c3ab1f631e4c1390917ae48bbf07bf965", "patch": "mlc-llm-drowse.patch", - "patchBytes": 449691, - "patchSha256": "835ec7626b9e929fb0b4aca54b09d8b2ec45489dc8a6467f1ac60341791db0c3", + "patchBytes": 452632, + "patchSha256": "6a9a9409427d634d763f7402db400bd0635d7e748662dc93d0e2f2bb1f998f29", "resultFiles": { "python/mlc_llm/interface/compile.py": "435876d96e9ba6fbc3f02dd6f5ed858df559ebded169ce91c5cdd8151e610d32", "python/mlc_llm/interface/convert_weight.py": "dffc4af8487f54087bc27f9a35f959df318a70c4c33326b65d4a6d9f6479a1b5", - "python/mlc_llm/model/drowse_hooks.py": "dd2d9779692360bdddd214553804e90c82942f47011fa947f830321bd3c67cd6", + "python/mlc_llm/model/drowse_hooks.py": "649787ef8db81cca6502a1c27c3c1a6d6ccf9ef65900f3d5a9e106d57bad9417", "python/mlc_llm/model/drowse_reads.py": "f6ef0f42e2b49d0e6c8729cdc8aa93dd6cdbd4d614045173e28deba4d129d4b2", - "python/mlc_llm/model/drowse_units.py": "70c890ea5362763dac19b6c6eeae03a10aef3fcfc48879eadbda20f68db1afe2", + "python/mlc_llm/model/drowse_units.py": "101c80257d844bcf7ea4ce905b3856a1de7f6cffbc48e8fb7f7174fce66b43e2", "python/mlc_llm/model/gemma3/gemma3_model.py": "8a8f423b8ef28c43bbca065857b8a344118f30319c80550c58ee50bf7b777867", - "python/mlc_llm/model/llama/llama_model.py": "43898289270c720e1a255ca458ce85ea7e3ab4e3798c234caa422e419ae80825", - "python/mlc_llm/model/qwen3/qwen3_model.py": "98312ccb7ecd9452b0cc77a7a5ddfb71a7fcda6e4a4c33815b9e05eeec8c8574", + "python/mlc_llm/model/llama/llama_model.py": "441c3f5f99f6dc261249dd357d882beb39e75c1cd573010ed8fffdb144f453a9", + "python/mlc_llm/model/qwen3/qwen3_model.py": "42b5b4a694e42cdba78b72ee52d7586757088479bae028ca2d3ff202dead8e20", "python/mlc_llm/op/moe_misc.py": "4141be404d6d31b1ee152ef495fd5bdfc75b16af968ad01e07c3d1d26637ef92" } }, @@ -79,32 +79,32 @@ "baseCommit": "90f67096b68d3b77509c938f2221e4cef03b7d76", "baseTree": "ac223f95dc7ea27acaba299fe6b780ccb5d67b6f", "patch": "web-llm-drowse.patch", - "patchBytes": 529085, - "patchSha256": "84e6efdde332516132cf46926c212c7168b0bec5e9d4c492cd0a8f0427686827", + "patchBytes": 530342, + "patchSha256": "b5ae425313a84366238c67a74bccdf11a7670d8be7595f17a2898b3c5a8276e9", "resultFiles": { - "package-lock.json": "158f6ef9f096ad78bedc5afff5a9a36fd4693a69eb81dac210ccf1a588513340", - "package.json": "c393c1981c58fd6461580876256d501c5572da9f93281d6f8eefba051a128538", + "package-lock.json": "a91180a119ccf654a16af346f1d91cd83416de8832c88c802763846364d0b3c9", + "package.json": "120118f9c122c3ef7a9314d5d1f3995795873546f561ef0baebaaeb982d8c6fc", "rollup.config.js": "509d7ae65c5f1d3a9844f317854c191c2e4ea0978880b1e9cb4abb9216209273", "src/cache_util.ts": "22068a3108e0df16d9bd6c1397283cdb0f33aafa5f22eb2c26678cc30342ec08", "src/config.ts": "ee61e5876d51038eb7d6235fd1de1ea066e5f1f103242ffb7e69dba7f6ac86bd", "src/conversation.ts": "f76b93d1306a8eef8735236f7e7b37fdc0c6df0bc85448e5ed4b73eaf8f768c1", - "src/drowse.ts": "e17e329c5af01bf3cf75725c8a2988ec6e8a51e215c8ac6faa3f7f02f809ffc3", + "src/drowse.ts": "53f9dbcaa930d5d6263254bf8fbe60630a0655ca3e8ed12b13f8fb578eb88de8", "src/drowse_gpu_controls.ts": "31415bce2481fa0df2ef59d0c5d937001f688ef84ab30ee43dc098df03e34c08", "src/drowse_gpu_topk.ts": "b6267e699827327913e6513eb46868a769de5535fe8e042608821509cc93850b", - "src/engine.ts": "edbdb0df747b32c90c2b83f7b7c83c300b28e57fe1e001c2fa7efed67a93540d", + "src/engine.ts": "8e805030c20d957a421c04728657c914d70a139802f2391cc28e13e1e95dfc15", "src/gpu.ts": "7680a9f6742b36174b0175085fd5148da70ea599a70b5daf246f35c678a4a2d5", "src/index.ts": "bf7caa4dae80f8c15ee2f11dbadc1d82adf4ed041c24c182b6e92aa02c02bf17", - "src/llm_chat.ts": "d4417c658bc20bcb4b5c7ad3f313c74119d2562391ef20fd566e5427403cddf0", + "src/llm_chat.ts": "74e3b5441c17ce27e9fd7ab57f4b14b85d6eb1852f67fa04f1388360e5e76fb3", "src/message.ts": "9425730f4136fc688c100a3761465b7bd972e3daf265e79b82b30ddd70f572c5", "src/openai_api_protocols/chat_completion.ts": "c58e06d58841e18b6e6a9a0e08fa789663999224f308846fad835f25bc42ade7", "src/openai_api_protocols/completion.ts": "4dd7e554b4467630f1f53882b2c2d196b35df7c0f392d0a8d253e09a9741e0b4", "src/openai_api_protocols/index.ts": "13b993b69d41bdfc8d7118dd2dbc5dd45021b87853cf7fe396000ba9e3c85cbe", - "src/types.ts": "726726eacd2ff3768d5fad22a05bf11cd452977d2807aeab55b7a41d8cbcdbad", + "src/types.ts": "5ddc3a3e82f1e5b96461a913a86fdd47a3c353e306bc399abe64eb80ebfe7bd5", "src/utils.ts": "d462c6a68a159c863ce382dd3ea367da649f5801b877265d3080d9436ae8fef4", "src/web_worker.ts": "a9ffcabfdbfe44df51f13743ea50f22bb2ef6c06563a54f6d987e28d95e3acc9", "tests/cache_util.test.ts": "7ea1dd54414e9a9b8cff3c82bf3bedcf5d7d4e44bc7f1aae57d54ef2cebf2a94", "tests/conversation.test.ts": "a71ec20e05dc616cefab552bb16dc51efd6cb47e56ec8553b917240d2a8e65fa", - "tests/drowse.test.ts": "dc3f490542af4af9f9c1f50e8a817187d673d1d58273d2c7dd66ecc1aae39c1e", + "tests/drowse.test.ts": "7999e18c3bfdc07f3499ff37622a7e30f6005045f4a6dbf2a6bd5f634e6a8e86", "tests/drowse_pipeline.test.ts": "7d2576a9f6684f9c438fcd4768574bacf5b86cc1f894f3eff3c3335a3c5342cb", "tests/drowse_positions.test.ts": "5c44a8c5d73dcfabc19b9ecefbfefebcdcace1de20a16185bf4e1e9fc0f20823", "tests/engine_integration.test.ts": "7e10bc6daaf25f3d09e6a30d3cc8a61cc699154c65efc39d14dddac61c2b9227", @@ -120,7 +120,7 @@ "baseModels": { "gpt2": { "modelAdapterFiles": { - "base_model_adapters.py": "92606e6406f81221e76a30f41f3aa0a08e4acb830fdcdd4b5ec5b4034b974c1c" + "base_model_adapters.py": "c7d72ca6fb9fadb5ad38a5f0d34dadba4e718d0c44d55cb53622879e2e779d0a" }, "modelSourceFiles": { "python/mlc_llm/model/gpt2/gpt2_loader.py": "d9e91af06a275b8b4e6b2419e51c9670702fddfb3ad9e3fecdf63901310e4c36", @@ -129,7 +129,7 @@ }, "gpt_neox": { "modelAdapterFiles": { - "base_model_adapters.py": "92606e6406f81221e76a30f41f3aa0a08e4acb830fdcdd4b5ec5b4034b974c1c" + "base_model_adapters.py": "c7d72ca6fb9fadb5ad38a5f0d34dadba4e718d0c44d55cb53622879e2e779d0a" }, "modelSourceFiles": { "python/mlc_llm/model/gpt_neox/gpt_neox_loader.py": "0440155050e86cba299b8b6ce18cc016dfcc25e790e3cfdc3b209f86b99cd3c9", @@ -138,8 +138,8 @@ }, "qwen3_5": { "modelAdapterFiles": { - "base_model_adapters.py": "92606e6406f81221e76a30f41f3aa0a08e4acb830fdcdd4b5ec5b4034b974c1c", - "qwen35_adapter.py": "77865be561dfebca0a888d5f0cb8a060206a28ef0c18ff8300bf759d8df73514", + "base_model_adapters.py": "c7d72ca6fb9fadb5ad38a5f0d34dadba4e718d0c44d55cb53622879e2e779d0a", + "qwen35_adapter.py": "be3e54d32d7cf48902ab0222d847fc397b9a8808f1bdb935e8602d697d7009dd", "hybrid_state_kernels.py": "7075a4b80b11093503ca5048074095eb41c39cade72edf4fa6a0f69b2fdfb8a3" }, "modelSourceFiles": { diff --git a/browser-runtime/forks/mlc-llm-drowse.patch b/browser-runtime/forks/mlc-llm-drowse.patch index 6f8255e..ddbf483 100644 --- a/browser-runtime/forks/mlc-llm-drowse.patch +++ b/browser-runtime/forks/mlc-llm-drowse.patch @@ -66,10 +66,10 @@ index c5f33250..5f8096e5 100644 allowed_lora_source_formats = {"huggingface-safetensor", "huggingface-torch"} diff --git a/python/mlc_llm/model/drowse_hooks.py b/python/mlc_llm/model/drowse_hooks.py new file mode 100644 -index 00000000..e1462573 +index 00000000..33f25e63 --- /dev/null +++ b/python/mlc_llm/model/drowse_hooks.py -@@ -0,0 +1,4474 @@ +@@ -0,0 +1,4518 @@ +"""Drowse post-block residual hooks for browser model libraries.""" + +from tvm import te @@ -103,9 +103,9 @@ index 00000000..e1462573 +STRUCTURED_REQUIRED_MAX_STORAGE_BUFFERS_PER_SHADER_STAGE = 8 +STRUCTURED_HOOK_PROFILE_MAGIC = 0x53414B4C +STRUCTURED_HOOK_PROFILE_SCHEMA_VERSION = 4 -+STRUCTURED_HOOK_PROFILE_ID = 4 -+STRUCTURED_HOOK_ABI_VERSION = 5 -+STRUCTURED_HOOK_FORMAT_VERSION = 4 ++STRUCTURED_HOOK_PROFILE_ID = 5 ++STRUCTURED_HOOK_ABI_VERSION = 6 ++STRUCTURED_HOOK_FORMAT_VERSION = 5 +STRUCTURED_MIN_COMPUTE_WORKGROUP_STORAGE_SIZE = 32 * 1024 +EXACT_READOUT_ABI_VERSION = 2 +READOUT_TOP_K = 8 @@ -439,9 +439,9 @@ index 00000000..e1462573 + context_tokens: int, + prefill_chunk_size: int, +) -> Tensor: -+ """Descriptor schema 4 (hook ABI `block-sites-v5`): v3's 31 fields, then the block spec and ++ """Descriptor schema 4 (hook ABI `block-sites-v6`): v3's 31 fields, then the block spec and + the unit capacities (`drowse_units.hook_profile_values`). `block` is None for a residual -+ (`standard-v4-residual`) library.""" ++ (`standard-v5-residual`) library.""" + base = ( + STRUCTURED_HOOK_PROFILE_MAGIC, + STRUCTURED_HOOK_PROFILE_SCHEMA_VERSION, @@ -500,6 +500,15 @@ index 00000000..e1462573 + ], + "float32", + ), ++ "affine_read": nn.spec.Tensor( ++ [ ++ num_layers, ++ STRUCTURED_MAX_AFFINE_GROUPS, ++ STRUCTURED_MAX_RANK, ++ hidden_size, ++ ], ++ "float32", ++ ), + "affine_neutral": nn.spec.Tensor( + [num_layers, STRUCTURED_MAX_AFFINE_GROUPS, hidden_size], "float32" + ), @@ -558,6 +567,15 @@ index 00000000..e1462573 + ], + "float32", + ), ++ "curve_read": nn.spec.Tensor( ++ [ ++ num_layers, ++ STRUCTURED_MAX_CURVES, ++ STRUCTURED_MAX_RANK, ++ hidden_size, ++ ], ++ "float32", ++ ), + "curve_neutral": nn.spec.Tensor( + [num_layers, STRUCTURED_MAX_CURVES, hidden_size], "float32" + ), @@ -664,6 +682,15 @@ index 00000000..e1462573 + ], + "float32", + ), ++ "curve_read": nn.spec.Tensor( ++ [ ++ num_layers, ++ STRUCTURED_MAX_CURVES, ++ STRUCTURED_MAX_RANK, ++ hidden_size, ++ ], ++ "float32", ++ ), + "curve_neutral": nn.spec.Tensor( + [num_layers, STRUCTURED_MAX_CURVES, hidden_size], "float32" + ), @@ -923,6 +950,7 @@ index 00000000..e1462573 + layer_id: int, + affine_active: Tensor, + affine_basis: Tensor, ++ affine_read: Tensor, + affine_neutral: Tensor, + affine_target: Tensor, + affine_along: Tensor, @@ -941,12 +969,14 @@ index 00000000..e1462573 + var_residual: T.handle, + var_active: T.handle, + var_basis: T.handle, ++ var_read: T.handle, + var_neutral: T.handle, + var_target: T.handle, + var_along: T.handle, + var_kappa: T.handle, -+ var_output: T.handle, + ): ++ # In place on the residual: with the read rows the kernel binds 8 storage buffers, the ++ # most a drowse kernel may (HOOK_ABI.md §10). Each workgroup reads and writes one row. + T.func_attr({"op_pattern": 8, "tirx.is_scheduled": 1, "tirx.noalias": True}) + residual = T.match_buffer( + var_residual, @@ -968,6 +998,16 @@ index 00000000..e1462573 + ), + "float32", + ) ++ read_rows = T.match_buffer( ++ var_read, ++ ( ++ num_layers, ++ STRUCTURED_MAX_AFFINE_GROUPS, ++ STRUCTURED_MAX_RANK, ++ hidden_size, ++ ), ++ "float32", ++ ) + neutral = T.match_buffer( + var_neutral, + (num_layers, STRUCTURED_MAX_AFFINE_GROUPS, hidden_size), @@ -996,11 +1036,6 @@ index 00000000..e1462573 + ), + "float32", + ) -+ output = T.match_buffer( -+ var_output, -+ (batch_size, sequence_length, hidden_size), -+ residual_dtype, -+ ) + current = T.sblock_alloc_buffer((T.ceildiv(hidden_size, 64),), "float32", scope="local") + partial = T.sblock_alloc_buffer((64,), "float32", scope="shared") + delta = T.sblock_alloc_buffer((STRUCTURED_MAX_RANK,), "float32", scope="shared") @@ -1025,7 +1060,7 @@ index 00000000..e1462573 + if hidden < hidden_size: + partial[lane] = partial[lane] + ( + current[chunk] - neutral[layer_id, group, hidden] -+ ) * basis[layer_id, group, row, hidden] ++ ) * read_rows[layer_id, group, row, hidden] + T.tvm_storage_sync("shared") + for stage in T.unroll(6): + offset = T.meta_var(32 >> stage) @@ -1050,20 +1085,22 @@ index 00000000..e1462573 + for chunk in T.serial(T.ceildiv(hidden_size, 64)): + hidden = T.meta_var(chunk * 64 + lane) + if hidden < hidden_size: -+ output[batch, sequence, hidden] = T.cast(current[chunk], residual_dtype) ++ residual[batch, sequence, hidden] = T.cast(current[chunk], residual_dtype) + -+ steered = op.tensor_ir_op( ++ steered = op.tensor_ir_inplace_op( + _affine, + f"drowse_structured_affine_{layer_id}", + args=[ + hidden_states, + affine_active, + affine_basis, ++ affine_read, + affine_neutral, + affine_target, + affine_along, + affine_kappa, + ], ++ inplace_indices=[0], + out=Tensor.placeholder(hidden_states.shape, residual_dtype), + ) + measurements = measure_structured_probes( @@ -1083,6 +1120,7 @@ index 00000000..e1462573 + decode: bool, + affine_active: Tensor, + affine_basis: Tensor, ++ affine_read: Tensor, + affine_neutral: Tensor, + affine_target: Tensor, + affine_along: Tensor, @@ -1092,6 +1130,7 @@ index 00000000..e1462573 + probe_bias: Tensor, + probe_threshold: Tensor, + curve_basis: Tensor, ++ curve_read: Tensor, + curve_neutral: Tensor, + curve_domain_kind: Tensor, + curve_parameters: Tensor, @@ -1102,6 +1141,7 @@ index 00000000..e1462573 + layer_id, + affine_active, + affine_basis, ++ affine_read, + affine_neutral, + affine_target, + affine_along, @@ -1121,6 +1161,7 @@ index 00000000..e1462573 + curve_id, + decode, + curve_basis, ++ curve_read, + curve_neutral, + curve_domain_kind, + curve_parameters, @@ -2413,15 +2454,18 @@ index 00000000..e1462573 + curve_id: int, + decode: bool, + curve_basis: Tensor, ++ curve_read: Tensor, + curve_neutral: Tensor, + curve_domain_kind: Tensor, + curve_parameters: Tensor, + curve_feet: Tensor, +): -+ basis = _layer_group_matrix(curve_basis, layer_id, curve_id, "drowse_curve_basis") ++ # Typed frame (hook ABI v6): coordinates through the read rows, the write along the basis rows ++ # (`_reconstruct_curve_tir`), so a full `onto` ablation is LEACE against the neutral. ++ read = _layer_group_matrix(curve_read, layer_id, curve_id, "drowse_curve_read") + neutral = _layer_group_vector(curve_neutral, layer_id, curve_id, "drowse_curve_neutral") + centered = residual - neutral -+ q = _project_onto_rows(centered, basis) ++ q = _project_onto_rows(centered, read) + coordinates, feet = _curve_coordinates_tir( + q, + curve_parameters, @@ -5892,11 +5936,11 @@ index 00000000..29d20f3b + setattr(cls, name, _method(function, with_model)) diff --git a/python/mlc_llm/model/drowse_units.py b/python/mlc_llm/model/drowse_units.py new file mode 100644 -index 00000000..523e7baf +index 00000000..31278720 --- /dev/null +++ b/python/mlc_llm/model/drowse_units.py @@ -0,0 +1,1342 @@ -+"""Drowse hook ABI v5 (`block-sites-v5`): in-block unit sites for dense blocks. ++"""Drowse hook ABI v6 (`block-sites-v6`): in-block unit sites for dense blocks. + +Every eligible model's decoder layer runs `drowse_block(hidden, cache, layer_id, sites)`. With +`NO_SITES` the block is op for op the upstream layer (the v4 graph); `UnitSites` inserts, per @@ -5930,9 +5974,9 @@ index 00000000..523e7baf +DROWSE_KERNEL_STORAGE_BINDINGS = 8 + +HOOK_PROFILE_SCHEMA_VERSION = 4 -+HOOK_PROFILE_ID = 4 -+BLOCK_SITES_HOOK_ABI_VERSION = 5 -+STRUCTURED_HOOK_FORMAT_VERSION = 4 ++HOOK_PROFILE_ID = 5 ++BLOCK_SITES_HOOK_ABI_VERSION = 6 ++STRUCTURED_HOOK_FORMAT_VERSION = 5 +BLOCK_SITES_EXACT_READOUT_ABI_VERSION = 2 + +ACTIVATION_SILU = 1 @@ -5995,7 +6039,7 @@ index 00000000..523e7baf + +def hook_profile_values(base: tuple, block: dict | None, context_tokens: int, + prefill_chunk_size: int, hidden_size: int) -> tuple: -+ """Descriptor schema 4: v3's 31 fields (ABI 5, format 4, readout 2 in `base`), then the block ++ """Descriptor schema 4: v3's 31 fields (ABI 6, format 5, readout 2 in `base`), then the block + and unit fields. A residual library (`block is None`) reports 0 in every block field, unit + capacity, `ANATOMY_STRIDE`, `UNIT_POSITIONS_FROM` and `MAX_ANATOMY_UNITS`.""" + units = block is not None @@ -7527,7 +7571,7 @@ index b022bab9..95fd8a20 100644 + +_install_drowse_reads() diff --git a/python/mlc_llm/model/llama/llama_model.py b/python/mlc_llm/model/llama/llama_model.py -index 4659a249..e52174c2 100644 +index 4659a249..cdbe42ed 100644 --- a/python/mlc_llm/model/llama/llama_model.py +++ b/python/mlc_llm/model/llama/llama_model.py @@ -11,6 +11,31 @@ from tvm.relax.frontend.nn import Tensor, op @@ -7571,7 +7615,7 @@ index 4659a249..e52174c2 100644 self.layers = nn.ModuleList( [LlamaDecoderLayer(config) for _ in range(config.num_hidden_layers)] ) -@@ -244,16 +269,137 @@ class LlamaModel(nn.Module): +@@ -244,16 +269,143 @@ class LlamaModel(nn.Module): return hidden_states @@ -7601,6 +7645,7 @@ index 4659a249..e52174c2 100644 + paged_kv_cache: PagedKVCache, + affine_active: Tensor, + affine_basis: Tensor, ++ affine_read: Tensor, + affine_neutral: Tensor, + affine_target: Tensor, + affine_along: Tensor, @@ -7622,6 +7667,7 @@ index 4659a249..e52174c2 100644 + layer_id, + affine_active, + affine_basis, ++ affine_read, + affine_neutral, + affine_target, + affine_along, @@ -7644,6 +7690,7 @@ index 4659a249..e52174c2 100644 + decode: bool, + affine_active: Tensor, + affine_basis: Tensor, ++ affine_read: Tensor, + affine_neutral: Tensor, + affine_target: Tensor, + affine_along: Tensor, @@ -7653,6 +7700,7 @@ index 4659a249..e52174c2 100644 + probe_bias: Tensor, + probe_threshold: Tensor, + curve_basis: Tensor, ++ curve_read: Tensor, + curve_neutral: Tensor, + curve_domain_kind: Tensor, + curve_parameters: Tensor, @@ -7672,6 +7720,7 @@ index 4659a249..e52174c2 100644 + decode, + affine_active, + affine_basis, ++ affine_read, + affine_neutral, + affine_target, + affine_along, @@ -7681,6 +7730,7 @@ index 4659a249..e52174c2 100644 + probe_bias, + probe_threshold, + curve_basis, ++ curve_read, + curve_neutral, + curve_domain_kind, + curve_parameters, @@ -7710,7 +7760,7 @@ index 4659a249..e52174c2 100644 self.hidden_size = config.hidden_size self.vocab_size = config.vocab_size self.rope_scaling = config.rope_scaling -@@ -346,6 +492,429 @@ class LlamaForCausalLM(nn.Module): +@@ -346,6 +498,441 @@ class LlamaForCausalLM(nn.Module): logits = self.get_logits(hidden_states) return logits, paged_kv_cache @@ -7770,6 +7820,7 @@ index 4659a249..e52174c2 100644 + paged_kv_cache: PagedKVCache, + affine_active: Tensor, + affine_basis: Tensor, ++ affine_read: Tensor, + affine_neutral: Tensor, + affine_target: Tensor, + affine_along: Tensor, @@ -7784,6 +7835,7 @@ index 4659a249..e52174c2 100644 + paged_kv_cache, + affine_active, + affine_basis, ++ affine_read, + affine_neutral, + affine_target, + affine_along, @@ -7802,6 +7854,7 @@ index 4659a249..e52174c2 100644 + paged_kv_cache: PagedKVCache, + affine_active: Tensor, + affine_basis: Tensor, ++ affine_read: Tensor, + affine_neutral: Tensor, + affine_target: Tensor, + affine_along: Tensor, @@ -7816,6 +7869,7 @@ index 4659a249..e52174c2 100644 + paged_kv_cache, + affine_active, + affine_basis, ++ affine_read, + affine_neutral, + affine_target, + affine_along, @@ -7880,6 +7934,7 @@ index 4659a249..e52174c2 100644 + paged_kv_cache: PagedKVCache, + affine_active: Tensor, + affine_basis: Tensor, ++ affine_read: Tensor, + affine_neutral: Tensor, + affine_target: Tensor, + affine_along: Tensor, @@ -7889,6 +7944,7 @@ index 4659a249..e52174c2 100644 + probe_bias: Tensor, + probe_threshold: Tensor, + curve_basis: Tensor, ++ curve_read: Tensor, + curve_neutral: Tensor, + curve_domain_kind: Tensor, + curve_parameters: Tensor, @@ -7900,6 +7956,7 @@ index 4659a249..e52174c2 100644 + False, + affine_active, + affine_basis, ++ affine_read, + affine_neutral, + affine_target, + affine_along, @@ -7909,6 +7966,7 @@ index 4659a249..e52174c2 100644 + probe_bias, + probe_threshold, + curve_basis, ++ curve_read, + curve_neutral, + curve_domain_kind, + curve_parameters, @@ -7923,6 +7981,7 @@ index 4659a249..e52174c2 100644 + paged_kv_cache: PagedKVCache, + affine_active: Tensor, + affine_basis: Tensor, ++ affine_read: Tensor, + affine_neutral: Tensor, + affine_target: Tensor, + affine_along: Tensor, @@ -7932,6 +7991,7 @@ index 4659a249..e52174c2 100644 + probe_bias: Tensor, + probe_threshold: Tensor, + curve_basis: Tensor, ++ curve_read: Tensor, + curve_neutral: Tensor, + curve_domain_kind: Tensor, + curve_parameters: Tensor, @@ -7943,6 +8003,7 @@ index 4659a249..e52174c2 100644 + True, + affine_active, + affine_basis, ++ affine_read, + affine_neutral, + affine_target, + affine_along, @@ -7952,6 +8013,7 @@ index 4659a249..e52174c2 100644 + probe_bias, + probe_threshold, + curve_basis, ++ curve_read, + curve_neutral, + curve_domain_kind, + curve_parameters, @@ -8140,12 +8202,12 @@ index 4659a249..e52174c2 100644 def prefill_to_last_hidden_states(self, input_embed: Tensor, paged_kv_cache: PagedKVCache): op_ext.configure() -@@ -422,8 +991,127 @@ class LlamaForCausalLM(nn.Module): +@@ -422,8 +1009,127 @@ class LlamaForCausalLM(nn.Module): dtype=self.dtype, ) + def _drowse_block_spec(self): -+ """Llama has no unit sites in hook ABI v5: the residual profile.""" ++ """Llama has no unit sites in hook ABI v6: the residual profile.""" + return None + + def drowse_hook_profile(self): @@ -8268,7 +8330,7 @@ index 4659a249..e52174c2 100644 "embed": { "input_ids": nn.spec.Tensor(["seq_len"], "int32"), "$": { -@@ -462,6 +1150,24 @@ class LlamaForCausalLM(nn.Module): +@@ -462,6 +1168,24 @@ class LlamaForCausalLM(nn.Module): "effect_mode": "none", }, }, @@ -8293,7 +8355,7 @@ index 4659a249..e52174c2 100644 "prefill_to_last_hidden_states": { "input_embed": nn.spec.Tensor([1, "seq_len", self.hidden_size], self.dtype), "paged_kv_cache": nn.spec.Object(object_type=PagedKVCache), -@@ -495,6 +1201,83 @@ class LlamaForCausalLM(nn.Module): +@@ -495,6 +1219,83 @@ class LlamaForCausalLM(nn.Module): "effect_mode": "none", }, }, @@ -8377,7 +8439,7 @@ index 4659a249..e52174c2 100644 "batch_verify": { "input_embeds": nn.spec.Tensor([1, "seq_len", self.hidden_size], self.dtype), "paged_kv_cache": nn.spec.Object(object_type=PagedKVCache), -@@ -539,4 +1322,8 @@ class LlamaForCausalLM(nn.Module): +@@ -539,4 +1340,8 @@ class LlamaForCausalLM(nn.Module): }, }, } @@ -8387,7 +8449,7 @@ index 4659a249..e52174c2 100644 + +drowse_reads.install(LlamaForCausalLM) diff --git a/python/mlc_llm/model/qwen3/qwen3_model.py b/python/mlc_llm/model/qwen3/qwen3_model.py -index f3bdfec1..7fd6a4ed 100644 +index f3bdfec1..36bba279 100644 --- a/python/mlc_llm/model/qwen3/qwen3_model.py +++ b/python/mlc_llm/model/qwen3/qwen3_model.py @@ -12,6 +12,42 @@ from tvm.relax.frontend.nn import Tensor, op @@ -8503,7 +8565,7 @@ index f3bdfec1..7fd6a4ed 100644 hidden_states = self._apply_residual(out, residual=hidden_states) return hidden_states -@@ -255,6 +311,181 @@ class Qwen3Model(nn.Module): +@@ -255,6 +311,191 @@ class Qwen3Model(nn.Module): hidden_states = self.norm(hidden_states) return hidden_states @@ -8535,6 +8597,7 @@ index f3bdfec1..7fd6a4ed 100644 + paged_kv_cache: PagedKVCache, + affine_active: Tensor, + affine_basis: Tensor, ++ affine_read: Tensor, + affine_neutral: Tensor, + affine_target: Tensor, + affine_along: Tensor, @@ -8554,6 +8617,7 @@ index f3bdfec1..7fd6a4ed 100644 + layer_id, + affine_active, + affine_basis, ++ affine_read, + affine_neutral, + affine_target, + affine_along, @@ -8576,6 +8640,7 @@ index f3bdfec1..7fd6a4ed 100644 + decode: bool, + affine_active: Tensor, + affine_basis: Tensor, ++ affine_read: Tensor, + affine_neutral: Tensor, + affine_target: Tensor, + affine_along: Tensor, @@ -8585,6 +8650,7 @@ index f3bdfec1..7fd6a4ed 100644 + probe_bias: Tensor, + probe_threshold: Tensor, + curve_basis: Tensor, ++ curve_read: Tensor, + curve_neutral: Tensor, + curve_domain_kind: Tensor, + curve_parameters: Tensor, @@ -8602,6 +8668,7 @@ index f3bdfec1..7fd6a4ed 100644 + decode, + affine_active, + affine_basis, ++ affine_read, + affine_neutral, + affine_target, + affine_along, @@ -8611,6 +8678,7 @@ index f3bdfec1..7fd6a4ed 100644 + probe_bias, + probe_threshold, + curve_basis, ++ curve_read, + curve_neutral, + curve_domain_kind, + curve_parameters, @@ -8631,6 +8699,7 @@ index f3bdfec1..7fd6a4ed 100644 + sites, + affine_active: Tensor, + affine_basis: Tensor, ++ affine_read: Tensor, + affine_neutral: Tensor, + affine_target: Tensor, + affine_along: Tensor, @@ -8640,6 +8709,7 @@ index f3bdfec1..7fd6a4ed 100644 + probe_bias: Tensor, + probe_threshold: Tensor, + curve_basis: Tensor, ++ curve_read: Tensor, + curve_neutral: Tensor, + curve_domain_kind: Tensor, + curve_parameters: Tensor, @@ -8660,6 +8730,7 @@ index f3bdfec1..7fd6a4ed 100644 + decode, + affine_active, + affine_basis, ++ affine_read, + affine_neutral, + affine_target, + affine_along, @@ -8669,6 +8740,7 @@ index f3bdfec1..7fd6a4ed 100644 + probe_bias, + probe_threshold, + curve_basis, ++ curve_read, + curve_neutral, + curve_domain_kind, + curve_parameters, @@ -8685,7 +8757,7 @@ index f3bdfec1..7fd6a4ed 100644 class Qwen3LMHeadModel(nn.Module): def __init__(self, config: Qwen3Config): -@@ -274,6 +505,8 @@ class Qwen3LMHeadModel(nn.Module): +@@ -274,6 +515,8 @@ class Qwen3LMHeadModel(nn.Module): self.tensor_parallel_shards = config.tensor_parallel_shards self.head_dim = config.head_dim self.weight_block_size = config.weight_block_size @@ -8694,7 +8766,7 @@ index f3bdfec1..7fd6a4ed 100644 def to(self, dtype: Optional[str] = None): super().to(dtype=dtype) -@@ -330,6 +563,680 @@ class Qwen3LMHeadModel(nn.Module): +@@ -330,6 +573,704 @@ class Qwen3LMHeadModel(nn.Module): logits = logits.astype("float32") return logits, paged_kv_cache @@ -8752,6 +8824,7 @@ index f3bdfec1..7fd6a4ed 100644 + paged_kv_cache: PagedKVCache, + affine_active: Tensor, + affine_basis: Tensor, ++ affine_read: Tensor, + affine_neutral: Tensor, + affine_target: Tensor, + affine_along: Tensor, @@ -8766,6 +8839,7 @@ index f3bdfec1..7fd6a4ed 100644 + paged_kv_cache, + affine_active, + affine_basis, ++ affine_read, + affine_neutral, + affine_target, + affine_along, @@ -8784,6 +8858,7 @@ index f3bdfec1..7fd6a4ed 100644 + paged_kv_cache: PagedKVCache, + affine_active: Tensor, + affine_basis: Tensor, ++ affine_read: Tensor, + affine_neutral: Tensor, + affine_target: Tensor, + affine_along: Tensor, @@ -8798,6 +8873,7 @@ index f3bdfec1..7fd6a4ed 100644 + paged_kv_cache, + affine_active, + affine_basis, ++ affine_read, + affine_neutral, + affine_target, + affine_along, @@ -8862,6 +8938,7 @@ index f3bdfec1..7fd6a4ed 100644 + paged_kv_cache: PagedKVCache, + affine_active: Tensor, + affine_basis: Tensor, ++ affine_read: Tensor, + affine_neutral: Tensor, + affine_target: Tensor, + affine_along: Tensor, @@ -8871,6 +8948,7 @@ index f3bdfec1..7fd6a4ed 100644 + probe_bias: Tensor, + probe_threshold: Tensor, + curve_basis: Tensor, ++ curve_read: Tensor, + curve_neutral: Tensor, + curve_domain_kind: Tensor, + curve_parameters: Tensor, @@ -8882,6 +8960,7 @@ index f3bdfec1..7fd6a4ed 100644 + False, + affine_active, + affine_basis, ++ affine_read, + affine_neutral, + affine_target, + affine_along, @@ -8891,6 +8970,7 @@ index f3bdfec1..7fd6a4ed 100644 + probe_bias, + probe_threshold, + curve_basis, ++ curve_read, + curve_neutral, + curve_domain_kind, + curve_parameters, @@ -8905,6 +8985,7 @@ index f3bdfec1..7fd6a4ed 100644 + paged_kv_cache: PagedKVCache, + affine_active: Tensor, + affine_basis: Tensor, ++ affine_read: Tensor, + affine_neutral: Tensor, + affine_target: Tensor, + affine_along: Tensor, @@ -8914,6 +8995,7 @@ index f3bdfec1..7fd6a4ed 100644 + probe_bias: Tensor, + probe_threshold: Tensor, + curve_basis: Tensor, ++ curve_read: Tensor, + curve_neutral: Tensor, + curve_domain_kind: Tensor, + curve_parameters: Tensor, @@ -8925,6 +9007,7 @@ index f3bdfec1..7fd6a4ed 100644 + True, + affine_active, + affine_basis, ++ affine_read, + affine_neutral, + affine_target, + affine_along, @@ -8934,6 +9017,7 @@ index f3bdfec1..7fd6a4ed 100644 + probe_bias, + probe_threshold, + curve_basis, ++ curve_read, + curve_neutral, + curve_domain_kind, + curve_parameters, @@ -8971,6 +9055,7 @@ index f3bdfec1..7fd6a4ed 100644 + paged_kv_cache: PagedKVCache, + affine_active: Tensor, + affine_basis: Tensor, ++ affine_read: Tensor, + affine_neutral: Tensor, + affine_target: Tensor, + affine_along: Tensor, @@ -8980,6 +9065,7 @@ index f3bdfec1..7fd6a4ed 100644 + probe_bias: Tensor, + probe_threshold: Tensor, + curve_basis: Tensor, ++ curve_read: Tensor, + curve_neutral: Tensor, + curve_domain_kind: Tensor, + curve_parameters: Tensor, @@ -9000,6 +9086,7 @@ index f3bdfec1..7fd6a4ed 100644 + sites, + affine_active, + affine_basis, ++ affine_read, + affine_neutral, + affine_target, + affine_along, @@ -9009,6 +9096,7 @@ index f3bdfec1..7fd6a4ed 100644 + probe_bias, + probe_threshold, + curve_basis, ++ curve_read, + curve_neutral, + curve_domain_kind, + curve_parameters, @@ -9031,6 +9119,7 @@ index f3bdfec1..7fd6a4ed 100644 + paged_kv_cache: PagedKVCache, + affine_active: Tensor, + affine_basis: Tensor, ++ affine_read: Tensor, + affine_neutral: Tensor, + affine_target: Tensor, + affine_along: Tensor, @@ -9040,6 +9129,7 @@ index f3bdfec1..7fd6a4ed 100644 + probe_bias: Tensor, + probe_threshold: Tensor, + curve_basis: Tensor, ++ curve_read: Tensor, + curve_neutral: Tensor, + curve_domain_kind: Tensor, + curve_parameters: Tensor, @@ -9060,6 +9150,7 @@ index f3bdfec1..7fd6a4ed 100644 + sites, + affine_active, + affine_basis, ++ affine_read, + affine_neutral, + affine_target, + affine_along, @@ -9069,6 +9160,7 @@ index f3bdfec1..7fd6a4ed 100644 + probe_bias, + probe_threshold, + curve_basis, ++ curve_read, + curve_neutral, + curve_domain_kind, + curve_parameters, @@ -9091,6 +9183,7 @@ index f3bdfec1..7fd6a4ed 100644 + paged_kv_cache: PagedKVCache, + affine_active: Tensor, + affine_basis: Tensor, ++ affine_read: Tensor, + affine_neutral: Tensor, + affine_target: Tensor, + affine_along: Tensor, @@ -9100,6 +9193,7 @@ index f3bdfec1..7fd6a4ed 100644 + probe_bias: Tensor, + probe_threshold: Tensor, + curve_basis: Tensor, ++ curve_read: Tensor, + curve_neutral: Tensor, + curve_domain_kind: Tensor, + curve_parameters: Tensor, @@ -9146,6 +9240,7 @@ index f3bdfec1..7fd6a4ed 100644 + sites, + affine_active, + affine_basis, ++ affine_read, + affine_neutral, + affine_target, + affine_along, @@ -9155,6 +9250,7 @@ index f3bdfec1..7fd6a4ed 100644 + probe_bias, + probe_threshold, + curve_basis, ++ curve_read, + curve_neutral, + curve_domain_kind, + curve_parameters, @@ -9375,7 +9471,7 @@ index f3bdfec1..7fd6a4ed 100644 def batch_prefill( self, input_embeds: Tensor, -@@ -375,8 +1282,147 @@ class Qwen3LMHeadModel(nn.Module): +@@ -375,8 +1316,147 @@ class Qwen3LMHeadModel(nn.Module): dtype=self.dtype, ) @@ -9523,7 +9619,7 @@ index f3bdfec1..7fd6a4ed 100644 "embed": { "input_ids": nn.spec.Tensor(["seq_len"], "int32"), "$": { -@@ -400,6 +1446,24 @@ class Qwen3LMHeadModel(nn.Module): +@@ -400,6 +1480,24 @@ class Qwen3LMHeadModel(nn.Module): "effect_mode": "none", }, }, @@ -9548,7 +9644,7 @@ index f3bdfec1..7fd6a4ed 100644 "batch_prefill": { "input_embeds": nn.spec.Tensor([1, "seq_len", self.hidden_size], self.dtype), "logit_positions": nn.spec.Tensor(["batch_size"], "int32"), -@@ -417,6 +1481,83 @@ class Qwen3LMHeadModel(nn.Module): +@@ -417,6 +1515,83 @@ class Qwen3LMHeadModel(nn.Module): "effect_mode": "none", }, }, @@ -9632,7 +9728,7 @@ index f3bdfec1..7fd6a4ed 100644 "batch_verify": { "input_embeds": nn.spec.Tensor([1, "seq_len", self.hidden_size], self.dtype), "paged_kv_cache": nn.spec.Object(object_type=PagedKVCache), -@@ -437,8 +1578,71 @@ class Qwen3LMHeadModel(nn.Module): +@@ -437,8 +1612,71 @@ class Qwen3LMHeadModel(nn.Module): }, }, } diff --git a/browser-runtime/forks/qwen35_adapter.py b/browser-runtime/forks/qwen35_adapter.py index 3f5c460..2dc775a 100644 --- a/browser-runtime/forks/qwen35_adapter.py +++ b/browser-runtime/forks/qwen35_adapter.py @@ -107,5 +107,5 @@ def get_default_spec(self): setattr(InstrumentedQwen35LMHeadModel, _name, _hybrid_forward(_method) if "paged_kv_cache" in inspect.signature(_method).parameters else _method) -# Linear attention layers: no unit sites, the residual descriptor (`standard-v4-residual`). +# Linear attention layers: no unit sites, the residual descriptor (`standard-v5-residual`). InstrumentedQwen35LMHeadModel._drowse_block_spec = lambda self: None diff --git a/browser-runtime/forks/static_reads.py b/browser-runtime/forks/static_reads.py deleted file mode 100644 index 1a06bae..0000000 --- a/browser-runtime/forks/static_reads.py +++ /dev/null @@ -1,570 +0,0 @@ -"""C TVM VM checks of the static reads and `exact-readout-v2` (hook ABI v5, B1 §4.1, §4.3). - -Run by `units_goldens.verify_arch` on each fixture library. Two layers: - -- every primitive against its formula, in fp64 numpy over the converted (dequantized) tensors, - on seeded inputs (`formula:` in the worst-|Δ| record); -- the goldens wherever a device primitive is involved, composed the way the host composes them: - `neuron-push` (the registered direction is the neuron write), `unit-reads` (each neuron read's - `w_norm` and `cos_ab`), `unit-artifacts` (every population scalar and contrast statistic of - every lens layer that the device reads produce: R writes and fires± `ρ`, `lse`, `lse_neg`, mean, - std; S writes and fires± `‖u‖`, `sqrt(uᵀΣ_E u)`, mean, std, S fires pooled), `slens` (the atom - directions `K_L ẽ_v` and the footprint z top-k), `lens-reads` (every present R and S half). - -The fixture lenses come from the goldens' portable generator (`units-tiny-models-v1.json`). -""" - -from __future__ import annotations - -import json -import os -from pathlib import Path - -import numpy as np - -SEED = 0x5EED0005 -LENS_ORDINAL = 1000 -LENS_LAYERS = {("R", "out"): (0, 1), ("R", "mid"): (1, 3), ("S", "out"): (0, 1), ("S", "mid"): (0, 2)} -R_STD_FLOOR, S_STD_FLOOR = 1e-4, 1e-6 -LOWEST = np.float32(-3.4028234663852886e38) -_MASK = 0xFFFFFFFF - - -def _h(x): - x = x & _MASK - x ^= x >> 16 - x = (x * 0x7FEB352D) & _MASK - x ^= x >> 15 - x = (x * 0x846CA68B) & _MASK - x ^= x >> 16 - return x - - -def _u(ordinal: int, count: int): - seed = int(_h(np.array([(SEED + 0x9E3779B9 * ordinal) & _MASK], dtype=np.uint64))[0]) - return _h(np.arange(count, dtype=np.uint64) ^ np.uint64(seed)) - - -def fixture_lenses(d: int) -> dict: - """`(family, site, layer) → [d, d]` fp32, as `browser_units.fixture_lens` builds them.""" - lenses = {} - for i, ((family, site), layers) in enumerate(sorted(LENS_LAYERS.items())): - for layer in layers: - u = _u(LENS_ORDINAL + 16 * i + layer, d * d) - noise = (((u >> 16) % 256).astype(np.float64) - 128.0) * 2.0**-10 - lenses[(family, site, layer)] = (0.75 * np.eye(d) + noise.reshape(d, d)).astype(np.float32) - return lenses - - -class Weights: - """The fixture library's weights in fp64, dequantized from the tensor cache.""" - - def __init__(self, tensors: dict, block: dict, num_layers: int): - self.tensors, self.block, self.num_layers = tensors, block, num_layers - self.prefix = "language_model.model." if any( - n.startswith("language_model.") for n in tensors) else "model." - - def get(self, name: str) -> np.ndarray: - name = self.prefix + name - if name + ".weight" in self.tensors: - return self.tensors[name + ".weight"].astype(np.float64) - weight, scale = self.tensors[name + ".q_weight"], self.tensors[name + ".q_scale"] - shifts = np.arange(8, dtype=np.uint32) * 4 - codes = ((weight[:, :, None] >> shifts) & 0xF).reshape(weight.shape[0], -1).astype(np.float64) - return (codes - 7) * np.repeat(scale.astype(np.float64), 32, axis=1) - - def gain(self, layer: int, which: str) -> np.ndarray: - sandwich = self.block["sandwich"] - names = {"ai": "input_layernorm", - "ao": "post_attention_layernorm" if sandwich else None, - "mi": "pre_feedforward_layernorm" if sandwich else "post_attention_layernorm", - "mo": "post_feedforward_layernorm" if sandwich else None} - if names[which] is None: - return np.ones(self.get("embed_tokens").shape[1]) - return self.get(f"layers.{layer}.{names[which]}") - - def layer(self, layer: int) -> dict: - b, p = self.block, f"layers.{layer}." - hd, heads, kv, d_ff = b["head_dim"], b["n_heads"], b["n_kv_heads"], b["d_ff"] - if self.prefix + p + "self_attn.c_attn.weight" in self.tensors or \ - self.prefix + p + "self_attn.c_attn.q_weight" in self.tensors: - qkv = self.get(p + "self_attn.c_attn") - q, k, v = qkv[: heads * hd], qkv[heads * hd: (heads + kv) * hd], qkv[(heads + kv) * hd:] - else: - q, k, v = (self.get(p + f"self_attn.{r}_proj") for r in "qkv") - gate_up = self.get(p + "mlp.gate_up_proj") - return {"q": q, "k": k, "v": v, "o": self.get(p + "self_attn.o_proj"), - "gate": gate_up[:d_ff], "up": gate_up[d_ff:], "down": self.get(p + "mlp.down_proj")} - - def writes(self, layer: int) -> np.ndarray: - """`[d_ff, d]`: `s·γ_mo ⊙ W_down[:, n]` per neuron.""" - scale = float(self.block.get("residual_scale", 1.0)) - return (scale * self.gain(layer, "mo")[:, None] * self.layer(layer)["down"]).T - - def reads(self, layer: int): - gain = self.gain(layer, "mi") - w = self.layer(layer) - a, b = w["gate"] * gain, w["up"] * gain - return (a / np.maximum(np.linalg.norm(a, axis=1, keepdims=True), 1e-12), - b / np.maximum(np.linalg.norm(b, axis=1, keepdims=True), 1e-12)) - - def head_write(self, layer: int, head: int) -> np.ndarray: - hd = self.block["head_dim"] - return self.gain(layer, "ao")[:, None] * self.layer(layer)["o"][:, head * hd:(head + 1) * hd] - - @property - def embedding(self) -> np.ndarray: - return self.get("embed_tokens") - - @property - def final_gain(self) -> np.ndarray: - return self.get("norm") - - -class Device: - """Calls into the fixture library's static reads (fp32 in, numpy out).""" - - def __init__(self, vm): - self.vm, self.tvm = vm, vm.env.tvm - - def __call__(self, name: str, *args, packed: bool = True): - arrays = [self.tvm.runtime.tensor(np.ascontiguousarray(a)) for a in args] - out = self.vm.vm[name](*arrays, self.vm.params) if packed else self.vm.vm[name](*arrays) - if hasattr(out, "numpy"): - return out.numpy() - return [o.numpy() for o in out] - - def topk(self, x: np.ndarray, k: int): - n = x.shape[0] - values, indices = self("drowse_topk", x.astype(np.float32), np.zeros((n, k), np.float32), - np.zeros((n, k), np.int32), packed=False) - return values, indices - - def chan(self, rows: np.ndarray, chunk: int = 37): - """Mean and centred sum of squares of `rows` through repeated merges (chunked, so the - merge rule itself is exercised).""" - width = rows.shape[1] - count, mean, m2 = 0, np.zeros(width, np.float32), np.zeros(width, np.float32) - for start in range(0, rows.shape[0], chunk): - part = rows[start:start + chunk].astype(np.float32) - mean, m2 = self("drowse_chan_merge", np.array([count], np.float32), mean, m2, part, - packed=False) - count += part.shape[0] - return count, mean, m2 - - -def mask_words(kept, vocab: int) -> np.ndarray: - words = np.zeros((vocab + 31) // 32, np.uint32) - for v in kept: - words[v >> 5] |= np.uint32(1) << np.uint32(v & 31) - return words - - -def exact_topk(x: np.ndarray, k: int): - """Value desc, index asc.""" - order = np.lexsort((np.arange(x.shape[-1])[None, :].repeat(x.shape[0], 0), -x), axis=-1)[:, :k] - return np.take_along_axis(x, order, -1), order - - -def _rms(x: np.ndarray, eps: float) -> np.ndarray: - return 1.0 / np.sqrt(np.mean(np.asarray(x, np.float64) ** 2, axis=-1) + eps) - - -def verify_formulas(dev: Device, w: Weights, check, statistics) -> None: - """Every primitive against its formula on seeded inputs.""" - block, L = w.block, w.num_layers - d, d_ff = w.embedding.shape[1], block["d_ff"] - heads, hd, kv = block["n_heads"], block["head_dim"], block["n_kv_heads"] - vocab = w.embedding.shape[0] - eps, scale_e = block["rms_eps"], float(block["embed_scale"]) - rng = np.random.default_rng(0xB4C) - f32 = lambda *shape: rng.standard_normal(shape).astype(np.float32) # noqa: E731 - - units = np.array([[l, n] for l in range(L) for n in (0, 5, d_ff - 1)] + [[L - 1, 7], [0, 40]], - np.int32) - rows = dev("drowse_neuron_rows", units) - for i, (layer, n) in enumerate(units): - a, b = w.reads(layer) - check("formula:neuron_rows", np.stack([w.writes(layer)[n], a[n], b[n]]), rows[i]) - head_units = np.array([[l, h] for l in range(L) for h in range(heads)], np.int32) - head = dev("drowse_head_rows", head_units) - group = heads // kv - for i, (layer, h) in enumerate(head_units): - p, ai = w.layer(layer), w.gain(layer, "ai") - g = h // group - expect = np.stack([w.head_write(layer, h).T, ai * p["q"][h * hd:(h + 1) * hd], - ai * p["k"][g * hd:(g + 1) * hd], ai * p["v"][g * hd:(g + 1) * hd]]) - check("formula:head_rows", expect, head[i]) - - layers = np.array([L - 1, 0, 2 % L, 0], np.int32) - x = f32(len(layers), 3, d) - got = dev("drowse_layer_write_scores", x, layers) - reads = dev("drowse_layer_read_scores", x, layers) - for j, layer in enumerate(layers): - a, b = w.reads(layer) - check("formula:layer_write_scores", x[j] @ w.writes(layer).T, got[j]) - check("formula:layer_read_scores", np.stack([x[j] @ a.T, x[j] @ b.T]), reads[j]) - - g, act, mlp_o, z, attn_o = f32(4, d), f32(4, d_ff), f32(4, d), f32(4, heads * hd), f32(4, d) - contributions = dev("drowse_neuron_contributions", g, act, mlp_o, layers) - head_c = dev("drowse_head_contributions", g, z, attn_o, layers) - grams = dev("drowse_head_write_grams") - norms = dev("drowse_head_write_norms", z, attn_o, layers, grams, packed=False) - for j, layer in enumerate(layers): - r_mo = _rms(mlp_o[j], eps) if block["sandwich"] else 1.0 - r_ao = _rms(attn_o[j], eps) if block["sandwich"] else 1.0 - check("formula:neuron_contributions", act[j] * (w.writes(layer) @ g[j]) * r_mo, - contributions[j]) - per_head = [] - norm = [] - for h in range(heads): - bh = w.head_write(layer, h) - zh = z[j, h * hd:(h + 1) * hd].astype(np.float64) - per_head.append(r_ao * float((g[j] @ bh) @ zh)) - norm.append(r_ao * np.sqrt(max(0.0, float(zh @ (bh.T @ bh) @ zh)))) - check("formula:head_contributions", per_head, head_c[j]) - check("formula:head_write_norms", norm, norms[j]) - pairs = np.array([[0, 0], [L - 1, heads - 1], [1 % L, 2 % heads]], np.int32) - gathered = dev("drowse_gather_head_grams", grams, pairs, packed=False) - check("formula:gather_head_grams", grams[pairs[:, 0], pairs[:, 1]], gathered) - - ids = np.array([0, 3, 71, vocab - 1, 17], np.int32) - mean_e = f32(d) * np.float32(0.1) - E, gamma_f = w.embedding, w.final_gain - check("formula:embedding_rows", scale_e * E[ids] - mean_e, - dev("drowse_embedding_rows", ids, mean_e)) - unemb = dev("drowse_unembedding_rows", ids) - check("formula:unembedding_rows", gamma_f * E[ids], unemb) - h_final = f32(len(ids), d) - check("formula:unembed_cotangent", _rms(h_final, eps)[:, None] * gamma_f * E[ids], - dev("drowse_unembed_cotangent", h_final, ids)) - rows_x = f32(3, d) - logits = dev("drowse_vocab_logits", rows_x) - normed = rows_x * _rms(rows_x, eps)[:, None] * gamma_f - check("formula:vocab_logits", normed @ E.T, logits) - mean_s, sigma, words = statistics - u = f32(3, d) - scores = dev("drowse_footprint_scores", u, mean_s, sigma, words) - kept = np.array([(words[v >> 5] >> (v & 31)) & 1 for v in range(vocab)], bool) - raw = (scale_e * u.astype(np.float64) @ E.T - (u @ mean_s)[:, None]) / np.sqrt( - np.maximum(np.einsum("ni,ij,nj->n", u, sigma.astype(np.float64), u), 1e-30))[:, None] - check("formula:footprint_scores", raw[:, kept], scores[:, kept]) - if not np.all(scores[:, ~kept] == LOWEST): - raise SystemExit("formula:footprint_scores: a masked id is not LOWEST") - for flag in (0, 1): - moments = dev("drowse_logit_moments", logits, words, np.array([flag], np.int32), packed=False) - sel = logits[:, kept] if flag else logits - c = sel.astype(np.float64) - sel.mean(-1, keepdims=True) - var = np.maximum((c**2).mean(-1), 1e-30) - check("formula:logit_moments", np.stack([(c**3).mean(-1) / var**1.5, - (c**4).mean(-1) / var**2], -1), moments) - big = f32(3, 1500) * np.float32(4) - big[1, 7:11] = big[1, 3] - lse = dev("drowse_log_sum_exp", big, packed=False) - check("formula:log_sum_exp", np.log(np.exp(big.astype(np.float64)).sum(-1)), lse) - for k in (1, 5, 64, 300): - values, indices = dev.topk(big, k) - ev, ei = exact_topk(big, k) - if not np.array_equal(indices, ei): - raise SystemExit(f"formula:topk k={k}: indices differ from value desc, index asc") - check("formula:topk", ev, values) - masked = np.where(kept[None, :], logits, LOWEST) - values, indices = dev.topk(masked, int(kept.sum()) + 3) - if not (np.all(indices[:, -3:] >= 0) and np.all(values[:, -3:] == LOWEST)): - raise SystemExit("formula:topk past the kept ids must return the LOWEST entries in id order") - a, wb = f32(2, 3, 5), f32(2, 5, 4) - check("formula:batched_matmul", a @ wb, dev("drowse_batched_matmul", a, wb, packed=False)) - check("formula:batched_matmul", a @ wb[:1], dev("drowse_batched_matmul", a, wb[:1], packed=False)) - wt = f32(1, 4, 5) - check("formula:batched_matmul_nt", a @ wt.transpose(0, 2, 1), - dev("drowse_batched_matmul_nt", a, wt, packed=False)) - xq, mq = f32(3, d), f32(3, d, d) - check("formula:quadratic_form", np.einsum("bi,bij,bj->b", xq, mq, xq), - dev("drowse_quadratic_form", xq, mq, packed=False)) - check("formula:quadratic_form", np.einsum("bi,ij,bj->b", xq, mq[0], xq), - dev("drowse_quadratic_form", xq, mq[:1], packed=False)) - xg = f32(3, 4, 7) - check("formula:grouped_row_norms", np.linalg.norm(xg, axis=-1), - dev("drowse_grouped_row_norms", xg, packed=False)) - data = f32(100, 9) + np.float32(3) - count, mean, m2 = dev.chan(data) - check("formula:chan_merge", data.mean(0), mean) - check("formula:chan_merge", ((data - data.mean(0)) ** 2).sum(0), m2) - - -class Reader: - """The host's compositions of the device reads, as B5 composes them (fixture lenses).""" - - def __init__(self, dev: Device, w: Weights, lenses: dict, statistics): - self.dev, self.w, self.lenses = dev, w, lenses - self.mean_e, self.sigma, self.words = statistics - self.L = w.num_layers - self.eps_f = w.block["rms_eps"] - - def r_matrix(self, layer: int, site: str): - if ("R", site, layer) in self.lenses: - return self.lenses[("R", site, layer)] - if site == "out" and layer == self.L - 1: - return None # the logit lens - return False - - def transport_r(self, rows: np.ndarray, matrix) -> np.ndarray: - rows = rows.astype(np.float32) - if matrix is None: - return rows - return self.dev("drowse_batched_matmul_nt", rows[None], matrix[None], packed=False)[0] - - def pull_s(self, rows: np.ndarray, matrix) -> np.ndarray: - return self.dev("drowse_batched_matmul", rows.astype(np.float32)[None], matrix[None], - packed=False)[0] - - def r_read(self, rows, matrix, k: int): - logits = self.dev("drowse_vocab_logits", self.transport_r(rows, matrix)) - lse = self.dev("drowse_log_sum_exp", logits, packed=False) - values, ids = self.dev.topk(logits, k) - return ids, np.exp(values.astype(np.float64) - lse[:, None]) - - def place(self, rows, layer: int, site: str, k: int, of: str, means: dict): - """lens.read's two halves of `rows` at (layer, site): (ids, values) per half, or None - where the fixture has no lens there.""" - r = s = None - matrix = self.r_matrix(layer, site) - if matrix is not False: - r = self.r_read(rows, matrix, k) - if ("S", site, layer) in self.lenses: - centred = rows - means[site][layer] if of == "residual" else rows - s = self.s_read(self.pull_s(centred, self.lenses[("S", site, layer)]), k) - return {"r": r, "s": s} - - def s_read(self, u, k: int): - scores = self.dev("drowse_footprint_scores", u.astype(np.float32), self.mean_e, self.sigma, - self.words) - values, ids = self.dev.topk(scores, k) - return ids, values - - -def declared_groups(doc: dict, path: str) -> list: - """The golden's declared tie groups (positions) for the token list at `path`.""" - return [g for tie in doc.get("declared_ties", []) if tie["path"] == path for g in tie["groups"]] - - -def _tie_blocks(values: list, window: float, groups: list) -> list: - """Positions whose order may differ: runs of golden values within `window` of each other, - joined with the declared tie groups.""" - parent = list(range(len(values))) - - def find(i: int) -> int: - while parent[i] != i: - parent[i] = parent[parent[i]] - i = parent[i] - return i - - for i in range(len(values) - 1): - if abs(values[i] - values[i + 1]) <= window: - parent[find(i + 1)] = find(i) - for group in groups: - for p in group[1:]: - parent[find(p)] = find(group[0]) - blocks: dict = {} - for i in range(len(values)): - blocks.setdefault(find(i), []).append(i) - return list(blocks.values()) - - -def _check_tokens(check, label: str, tokens: list, ids, values, atol: float, - groups: list = ()) -> None: - """A golden token list against the device's: the same ids, each id's value within `atol` - (+ the 6-decimal rounding), the device's values non-increasing, and each position holding the - golden's id except inside a tie (a declared group, or golden values within the tolerance).""" - golden = {int(t["token_id"]): float(t["value"]) for t in tokens} - got = {int(i): float(v) for i, v in zip(ids, values)} - if set(golden) != set(got): - raise SystemExit(f"{label}: ids {sorted(got)} are not the golden's {sorted(golden)}") - order = [golden[int(t["token_id"])] for t in tokens] - check(label, order, [got[int(t["token_id"])] for t in tokens], atol=atol + 2e-6, rtol=0.0) - device = [float(v) for v in values] - if any(device[i] < device[i + 1] for i in range(len(device) - 1)): - raise SystemExit(f"{label}: the device's values are not non-increasing: {device}") - golden_ids = [int(t["token_id"]) for t in tokens] - for block in _tie_blocks(order, 2 * (atol + 2e-6), list(groups)): - if {golden_ids[p] for p in block} != {int(ids[p]) for p in block}: - raise SystemExit(f"{label}: positions {block} hold {[int(ids[p]) for p in block]}, " - f"the golden {[golden_ids[p] for p in block]}") - - -def _check_place(check, tol: dict, label: str, golden: dict, got: dict, row: int, doc: dict, - path: str, where: str) -> None: - """One row's present R and S halves against a place read's (R probabilities, S z).""" - for half, atol in (("r", tol["probability_atol"]), ("s", tol["z_atol"])): - want = golden[half] - if want is None or want.get("absent") is not None or want.get("unit") == "layer_z": - continue - if got[half] is None: - raise SystemExit(f"{label}: a present {half} half at {where} has no fixture lens") - ids, values = got[half] - m = len(want["tokens"]) - _check_tokens(check, f"{label}:{half}", want["tokens"], ids[row][:m], values[row][:m], atol, - declared_groups(doc, f"{path}.{half}.tokens")) - - -def verify_goldens(dev: Device, w: Weights, check, goldens: Path, arch: str, statistics) -> None: - block = w.block - d, d_ff = w.embedding.shape[1], block["d_ff"] - lenses = fixture_lenses(d) - reader = Reader(dev, w, lenses, statistics) - stats = json.loads((goldens / f"unit-stats-{arch}-v1.json").read_text()) - from units_goldens import decode - - means = {"out": decode(stats["out_mean"]), "mid": decode(stats["mid_mean"])} - tol = json.loads((goldens / f"lens-reads-{arch}-v1.json").read_text())["tolerance"]["library"] - - # neuron-push: the registered profile is the neuron's write. - push = json.loads((goldens / f"neuron-push-{arch}-v1.json").read_text()) - for layer, vector in push["profile"].items(): - unit = next(c for c in push["cases"] if "neuron/L" in json.dumps(c)) - index = int(json.dumps(unit).split("neuron/L")[1].split("n")[1].split('"')[0].split("@")[0]) - row = dev("drowse_neuron_rows", np.array([[int(layer), index]], np.int32))[0, 0] - check("neuron-push:profile", decode(vector), row) - - # unit-reads: each neuron read's write norm and cos(â, b̂). - reads = json.loads((goldens / f"unit-reads-{arch}-v1.json").read_text()) - for case in reads["reads"]: - read = case["read"] - if read["kind"] != "neuron": - continue - rows = dev("drowse_neuron_rows", np.array([[read["layer"], read["index"]]], np.int32))[0] - check("unit-reads:w_norm", read["scalars"]["w_norm"], np.linalg.norm(rows[0]), - atol=2e-6 + tol["atol"]) - check("unit-reads:cos_ab", read["scalars"]["cos_ab"], float(rows[1] @ rows[2]), - atol=2e-6 + tol["atol"]) - - # unit-artifacts: the population scalars and contrast statistics the device reads produce. - artifacts = json.loads((goldens / f"unit-artifacts-{arch}-v1.json").read_text()) - embedded = dev("drowse_embedding_rows", np.arange(w.embedding.shape[0], dtype=np.int32), - reader.mean_e) - for entry in artifacts["layers"]: - layer, t = entry["layer"], entry["tensors"] - rows = dev("drowse_neuron_rows", np.array([[layer, n] for n in range(d_ff)], np.int32)) - populations = {"writes": rows[:, 0], "fires+": rows[:, 1] + rows[:, 2], - "fires-": rows[:, 1] - rows[:, 2]} - site_of = {"writes": "out", "fires+": "mid", "fires-": "mid"} - for name, population in populations.items(): - key = f"R.{name}" - if f"{key}.rho" not in t: - continue - matrix = reader.r_matrix(layer, site_of[name]) - x = reader.transport_r(population, matrix) - logits = dev("drowse_vocab_logits", x) - check(f"unit-artifacts:{key}.rho", decode(t[f"{key}.rho"]), _rms(x, reader.eps_f)) - check(f"unit-artifacts:{key}.lse", decode(t[f"{key}.lse"]), - dev("drowse_log_sum_exp", logits, packed=False)) - if f"{key}.lse_neg" in t: - check(f"unit-artifacts:{key}.lse_neg", decode(t[f"{key}.lse_neg"]), - dev("drowse_log_sum_exp", -logits, packed=False)) - count, mean, m2 = dev.chan(logits) - check(f"unit-artifacts:{key}.mean", decode(t[f"{key}.mean"]), mean) - check(f"unit-artifacts:{key}.std", decode(t[f"{key}.std"]), - np.sqrt(np.maximum(m2 / count, R_STD_FLOOR**2))) - pooled = [] - for name, population in populations.items(): - key = f"S.{name}" - if f"{key}.norm" not in t: - continue - u = reader.pull_s(population, lenses[("S", site_of[name], layer)]) - norm = dev("drowse_grouped_row_norms", u[:, None, :], packed=False)[:, 0] - check(f"unit-artifacts:{key}.norm", decode(t[f"{key}.norm"]), norm) - root = np.sqrt(np.maximum(dev("drowse_quadratic_form", u, reader.sigma[None], - packed=False), 1e-30)) - check(f"unit-artifacts:{key}.footprint_std", decode(t[f"{key}.footprint_std"]), root) - unit_u = (u / np.maximum(norm, 1e-12)[:, None]).astype(np.float32) - raw = dev("drowse_batched_matmul_nt", unit_u[None], embedded[None], packed=False)[0] - if name == "writes": - count, mean, m2 = dev.chan(raw) - check(f"unit-artifacts:{key}.mean", decode(t[f"{key}.mean"]), mean) - check(f"unit-artifacts:{key}.std", decode(t[f"{key}.std"]), - np.sqrt(np.maximum(m2 / count, S_STD_FLOOR**2))) - else: - pooled.append(raw) - if pooled: - count, mean, m2 = dev.chan(np.concatenate(pooled)) - check("unit-artifacts:S.fires.mean", decode(t["S.fires.mean"]), mean) - check("unit-artifacts:S.fires.std", decode(t["S.fires.std"]), - np.sqrt(np.maximum(m2 / count, S_STD_FLOOR**2))) - - # slens: the atom directions `K_L ẽ_v` and the footprint z top-k. - slens = json.loads((goldens / f"slens-{arch}-v1.json").read_text()) - words = dict(zip(slens["probe_words"], slens["probe_word_ids"])) - for atom in slens["atoms"]: - name = atom["atom"].split("/", 1)[1] - token = int(name[1:]) if name.startswith("#") else words[name] - e = dev("drowse_embedding_rows", np.array([token], np.int32), reader.mean_e) - for layer, vector in atom["layers"].items(): - got = dev("drowse_batched_matmul_nt", e[None], lenses[("S", "out", int(layer))][None], - packed=False)[0, 0] - check("slens:atom", decode(vector), got) - for f, footprint in enumerate(slens["footprints"]): - ids, z = reader.s_read(decode(footprint["u"]), footprint["k"]) - for row, top in enumerate(footprint["top"]): - _check_tokens(check, "slens:footprint", [{"token_id": t["token_id"], "value": t["z"]} - for t in top], ids[row], z[row], tol["z_atol"], - declared_groups(slens, f"footprints[{f}].top[{row}]")) - - # lens-reads: every present half. - lens_reads = json.loads((goldens / f"lens-reads-{arch}-v1.json").read_text()) - for q, request in enumerate(lens_reads["requests"]): - if request.get("lens") is not None: - continue # a session with no S lens prepared: the absent text only - layer, site = request["layer"], request["site"] - got = reader.place(decode(request["rows"]), layer, site, request["k"], request["of"], means) - for i, read in enumerate(request["reads"]): - _check_place(check, tol, "lens-reads", read, got, i, lens_reads, - f"requests[{q}].reads[{i}]", f"L{layer} {site}") - - # unit-reads poles: a neuron's writes (w, −w at its out) and firing directions (â ± b̂ at its - # mid) read through lens.read, and each pole's logit-lens skew and kurtosis over the kept - # tokens. Hub-hidden halves (unit layer_z) rank by contrast statistics, B5's host composition - # rather than a device read; every raw half is checked, hub-hidden read or not. - for c, case in enumerate(reads["reads"]): - read = case["read"] - if read["kind"] != "neuron": - continue - rows = dev("drowse_neuron_rows", np.array([[read["layer"], read["index"]]], np.int32))[0] - w, a, b = rows[0], rows[1], rows[2] - moments = dev("drowse_logit_moments", dev("drowse_vocab_logits", w[None]), - reader.words, np.array([1], np.int32), packed=False)[0] - places = {"writes": reader.place(np.stack([w, -w]), read["layer"], "out", case["k"], - "direction", means), - "fires_on": reader.place(np.stack([a + b, a - b]), read["layer"], "mid", - case["k"], "direction", means)} - for p, pole in enumerate(read["poles"]): - sign = 1.0 if pole["pole"] == "+" else -1.0 - check("unit-reads:vocab_moments", [pole["vocab_skew"], pole["vocab_kurt"]], - [sign * float(moments[0]), float(moments[1])], atol=2e-6 + tol["atol"]) - for where in ("writes", "fires_on"): - _check_place(check, tol, f"unit-reads:{where}", pole[where], places[where], p, - reads, f"reads[{c}].read.poles[{p}].{where}", - f"L{read['layer']} {pole[where]['site']}") - - -def verify(env, vm, tensors: dict, goldens: Path, arch: str, check) -> None: - if os.environ.get("DROWSE_READS_CONTINUE"): - strict, failures = check, [] - - def check(label, golden, actual, **kwargs): # noqa: F811 - try: - strict(label, golden, actual, **kwargs) - except SystemExit as error: - failures.append(str(error)) - print("FAIL", error, flush=True) - w = Weights(tensors, vm.block, vm.num_layers) - dev = Device(vm) - slens = json.loads((goldens / f"slens-{arch}-v1.json").read_text()) - from units_goldens import decode - - statistics = (decode(slens["mean_E"]).astype(np.float32), - decode(slens["sigma_E"]).astype(np.float32), - mask_words(slens["mask"]["kept"], w.embedding.shape[0])) - verify_formulas(dev, w, check, statistics) - verify_goldens(dev, w, check, goldens, arch, statistics) - if os.environ.get("DROWSE_READS_CONTINUE") and failures: - raise SystemExit(f"{len(failures)} static-read checks failed") diff --git a/browser-runtime/forks/units_goldens.py b/browser-runtime/forks/units_goldens.py deleted file mode 100644 index ddcfa00..0000000 --- a/browser-runtime/forks/units_goldens.py +++ /dev/null @@ -1,1122 +0,0 @@ -"""C TVM VM checks of hook ABI v5 (`block-sites-v5`) against drowse's units goldens. - -`verify-mlc-hook.py --units-fixtures DIR` runs these over the MLC fixture models that -`build-units-fixtures.py` writes (`DIR/units--`). Each model is compiled for -`llvm` through MLC's own pipeline (GPU-scheduled drowse kernels run serially, lane by lane, after -`strip_gpu_thread_bindings`), driven through MLC's paged KV cache exactly as WebLLM drives it, and -compared with the goldens' `library` tolerance: - -- `block-sites`: every site (`block_in`, `z`, `attn_o`, `mid`, `act`, `mlp_o`, `out`) at every - position of the short prompt, captured from `drowse_block` itself, and the last logits; -- `unit-ablation`: every case's prefill and decode forwards through `drowse_units_batch_*` from - the case's own lowered tables (logits, the last row's `out` at every layer), and the site-level - forward for the sink rows and `out_last_layer`; -- `unit-probes`: the unit tap's raw value per forward (neuron `act`, head write norm through the - tap grams), its reading over the neutral scale, and the gate the decode loop saw; -- replay (`drowse_replay_batch_prefill`, fed in forwards of at most 16 rows on one KV sequence): - `attention-patterns` (every head's row at positions 2, 5, 8 through `drowse_attention_rows`), - `token-anatomy` (the taps at the producing position, every head's write norm from the captured - `z` and `attn_o`, the MLP write, the chosen heads' rows) and `unit-activity` (every unit's device - peak, row and rank against the diagnostics, the host ranking, traces, the float16 population), - with `head_grams` built by `drowse_head_write_grams`. - -Returns the worst |Δ| per golden so the caller can record it. -""" - -from __future__ import annotations - -import base64 -import json -import os -import re -from pathlib import Path - -import numpy as np - -ARCH_FAMILY = {"gemma3": "gemma3_text", "qwen3": "qwen3"} -TERM = re.compile( - r"^(?:(?P[-+]?[0-9.]+)\s+)?!(?Pneuron|head)/L(?P\d+)[nh](?P\d+)" - r"(?:@(?P.+))?$" -) - - -def decode(value) -> np.ndarray: - if isinstance(value, dict) and value.get("encoding") == "float32-le-base64": - return np.frombuffer(base64.b64decode(value["data"]), " None: - golden = np.asarray(golden, np.float64) - actual = np.asarray(actual, np.float64) - if golden.shape != actual.shape: - raise SystemExit(f"{label}: shape {actual.shape} is not the golden's {golden.shape}") - a = self.atol if atol is None else atol - r = self.rtol if rtol is None else rtol - error = np.abs(actual - golden) - bound = a + r * np.abs(golden) - if os.environ.get("DROWSE_UNITS_DEBUG") and error.ndim == 3: - for layer in range(error.shape[0]): - print(f" {label} L{layer}: max |Δ| {float(error[layer].max()):.3g} rows " - f"{[int(r) for r in np.nonzero((error[layer] > bound[layer]).any(-1))[0]]}") - if (not np.all(np.isfinite(actual)) or np.any(error > bound)) and not os.environ.get( - "DROWSE_UNITS_DEBUG" - ): - index = np.unravel_index(int(np.argmax(error - bound)), error.shape) - raise SystemExit( - f"{label}: |Δ| {float(error[index]):.3g} at {index} exceeds {float(bound[index]):.3g} " - f"(golden {float(golden[index]):.6g}, library {float(actual[index]):.6g})" - ) - key = label.split(":")[0] - self.worst[key] = max(self.worst.get(key, 0.0), float(error.max(initial=0.0))) - - -class UnitProgram: - """`unit_meta`/`unit_coeff`/`unit_active`/`tap_grams` in the HOOK_ABI.md §4 layout.""" - - def __init__(self, layout_meta, layout_coeff, num_layers: int, head_dim: int, caps: dict): - self.meta_layout, self.coeff_layout = layout_meta, layout_coeff - self.num_layers, self.head_dim, self.caps = num_layers, head_dim, caps - self.neurons, self.heads, self.neuron_taps, self.head_taps = [], [], [], [] - self.triggers = [] - - def group(self, trigger) -> int: - key = json.dumps(trigger, sort_keys=True) - keys = [json.dumps(t, sort_keys=True) for t in self.triggers] - if key not in keys: - if len(self.triggers) >= self.caps["groups"]: - raise SystemExit("unit program has more trigger groups than capacity") - self.triggers.append(trigger) - keys.append(key) - return keys.index(key) - - def ablate(self, kind: str, layer: int, index: int, keep: float, bias, trigger) -> None: - group = self.group(trigger) - entry = (layer, index, group, np.float32(keep), np.asarray(bias, np.float32)) - (self.neurons if kind == "neuron" else self.heads).append(entry) - - def tap(self, kind: str, layer: int, index: int, gram=None) -> int: - slot = len(self.neuron_taps) + len(self.head_taps) - if kind == "neuron": - self.neuron_taps.append((layer, index, slot)) - else: - self.head_taps.append((layer, index, slot, gram)) - return slot - - def buffers(self, active: list[bool]): - meta = np.zeros(self.meta_layout["__length__"][0], np.uint32) - coeff = np.zeros(self.coeff_layout["__length__"][0], np.float32) - grams = np.zeros((self.caps["head_taps"], self.head_dim, self.head_dim), np.float32) - - def csr(name, entries, columns): - offsets = self.meta_layout[name + "_offsets"][0] - ordered = sorted(enumerate(entries), key=lambda item: (item[1][0], item[0])) - for layer in range(self.num_layers + 1): - meta[offsets + layer] = sum(1 for _, e in ordered if e[0] < layer) - return [e for _, e in ordered], columns - - neurons, _ = csr("neuron", self.neurons, None) - for i, (layer, index, group, keep, bias) in enumerate(neurons): - meta[self.meta_layout["neuron_index"][0] + i] = index - meta[self.meta_layout["neuron_group"][0] + i] = group - coeff[self.coeff_layout["neuron_keep"][0] + i] = keep - coeff[self.coeff_layout["neuron_bias"][0] + i] = bias - heads, _ = csr("head", self.heads, None) - for i, (layer, index, group, keep, bias) in enumerate(heads): - meta[self.meta_layout["head_index"][0] + i] = index - meta[self.meta_layout["head_group"][0] + i] = group - coeff[self.coeff_layout["head_keep"][0] + i] = keep - start = self.coeff_layout["head_bias"][0] + i * self.head_dim - coeff[start : start + self.head_dim] = bias - taps, _ = csr("tap_neuron", self.neuron_taps, None) - for i, (layer, index, slot) in enumerate(taps): - meta[self.meta_layout["tap_neuron_index"][0] + i] = index - meta[self.meta_layout["tap_neuron_slot"][0] + i] = slot - taps, _ = csr("tap_head", self.head_taps, None) - for i, (layer, index, slot, gram) in enumerate(taps): - meta[self.meta_layout["tap_head_index"][0] + i] = index - meta[self.meta_layout["tap_head_slot"][0] + i] = slot - grams[i] = gram - unit_active = np.asarray([1.0 if flag else 0.0 for flag in active] - + [0.0] * (self.caps["groups"] - len(active)), np.float32) - return meta, coeff, unit_active, grams - - -def trigger_active(trigger: dict | None, forward: int, gate_score) -> bool: - """Native `Trigger.active` (drowse/steering/triggers.py) for a raw generation: forward 0 is the - prefill, forward k ≥ 1 is a decode forward with `gen_step = k` (drowse/loom/replay.py: the - forward that reads the first generated token is step 1) in the response region.""" - if trigger is None: - return True - if forward == 0: - return trigger.get("gate") is None and trigger.get("prompt", True) - if not trigger.get("generated", True) or not trigger.get("response", True): - return False - gen_step = forward - if trigger.get("first_n") is not None and gen_step >= trigger["first_n"]: - return False - if trigger.get("after_n") is not None and gen_step < trigger["after_n"]: - return False - gate = trigger.get("gate") - if gate is not None: - if gate_score is None: - return False - op, threshold = gate["op"], gate["threshold"] - return {">": gate_score > threshold, ">=": gate_score >= threshold, - "<": gate_score < threshold, "<=": gate_score <= threshold}[op] - return True - - -def parse_trigger(text: str | None) -> dict | None: - """The browser-relevant subset of native triggers used by the units goldens.""" - if text is None: - return None - if text in ("prompt", "before"): - return {"prompt": True, "generated": False} - if text == "response": - return {"prompt": False, "generated": True, "response": True} - if text.startswith("first:"): - return {"prompt": False, "first_n": int(text.split(":")[1])} - match = re.match(r"^when:(\S+)\s*(>=|<=|>|<)\s*(\S+)$", text) - if match: - return {"gate": {"probe": match.group(1), "op": match.group(2), - "threshold": float(match.group(3))}} - raise SystemExit(f"unsupported trigger in a units golden: {text}") - - -class FixtureVM: - """One units model (a build-units-fixtures.py fixture or a converted production model) - compiled for llvm, its parameters, and a paged KV cache.""" - - def __init__(self, env, model_dir: Path): - self.env = env - tvm, relax, nn = env.tvm, env.relax, env.nn - chat = json.loads((model_dir / "mlc-chat-config.json").read_text()) - fixture_path = model_dir / "drowse-units-fixture.json" - fixture = (json.loads(fixture_path.read_text()) if fixture_path.is_file() - else {"arch": chat["model_type"], "quantization": chat["quantization"]}) - self.arch, self.quantization = fixture["arch"], fixture["quantization"] - config_class, model_class = env.models[chat["model_type"]] - config = config_class.from_dict(chat["model_config"]) - quantization = env.QUANTIZATION[self.quantization] - target = tvm.target.Target({"kind": "llvm"}) - with target: - model, _ = env.make_quantization_functions(model_class)[quantization.kind]( - config, quantization - ) - spec = self._spec(model, nn) - module, named_params, ext_mods = model.export_tvm(spec=spec, allow_extern=True) - module = strip_scheduled_kernels(module, tvm, env.strip_gpu_thread_bindings) - self.block = model._drowse_block_spec() - self.num_layers = model.num_hidden_layers - self.hidden_size = model.hidden_size - self.vocab = chat["vocab_size"] - env.prepare_parameters(named_params) - metadata = env.create_metadata(chat["model_type"], config, named_params, self.quantization) - pipeline = relax.get_pipeline( - "mlc_llm", target=target, flashinfer=False, cublas_gemm=False, - faster_transformer=False, allreduce_strategy=env.IPCAllReduceStrategyType.NONE, - variable_bounds={"total_seq_len": config.context_window_size, - "seq_len": config.prefill_chunk_size, "batch_size": 1, - "jlens_layers": self.num_layers, "sae_features": 16384}, - cuda_graph_symbolic_capture_hints={}, additional_tirs={}, ext_mods=ext_mods, - metadata=metadata, debug_dump=None, - ) - with tvm.transform.PassContext(config={"tirx.disable_cse_tir": True}): - executable = relax.build(module, target=target, relax_pipeline=pipeline) - self.vm = relax.VirtualMachine(executable, tvm.cpu()) - tensors = load_tensor_cache(model_dir) - self.params = [tvm.runtime.tensor(tensors[name], device=tvm.cpu()) for name, _ in named_params] - self.curve_zeros = { - name: np.zeros([int(d) for d in t.shape], t.dtype) - for name, t in env.structured_curve_program_spec(self.num_layers, self.hidden_size).items() - } - self.context = config.context_window_size - self.add_sequence = tvm.get_global_func("vm.builtin.kv_state_add_sequence") - self.begin_forward = tvm.get_global_func("vm.builtin.kv_state_begin_forward") - self.end_forward = tvm.get_global_func("vm.builtin.kv_state_end_forward") - - def _spec(self, model, nn): - env = self.env - from mlc_llm.nn import PagedKVCache - - d = model.hidden_size - head_dim = model._drowse_block_spec()["head_dim"] - curved = env.structured_curve_program_spec(model.num_hidden_layers, d) - units = env.unit_program_spec(model.num_hidden_layers, head_dim) - block = model._drowse_block_spec() - replay = env.drowse_units.replay_program_spec(model.num_hidden_layers, block) - rows = env.drowse_units.attention_rows_spec(block) - packed = {"param_mode": "packed", "effect_mode": "none"} - install_block_sites_forward(type(model), env) - raw = { - "embed": {"input_ids": nn.spec.Tensor(["seq_len"], "int32"), "$": packed}, - "create_paged_kv_cache": { - "max_batch_size": int, "max_total_seq_len": int, "prefill_chunk_size": int, - "page_size": int, "support_sliding_window": int, - "$": {"param_mode": "none", "effect_mode": "none"}, - }, - "drowse_units_batch_prefill": { - "input_embeds": nn.spec.Tensor([1, "seq_len", d], "float32"), - "logit_positions": nn.spec.Tensor(["batch_size"], "int32"), - "paged_kv_cache": nn.spec.Object(object_type=PagedKVCache), - **curved, **units, "$": packed, - }, - "drowse_units_batch_decode": { - "input_embeds": nn.spec.Tensor(["batch_size", 1, d], "float32"), - "paged_kv_cache": nn.spec.Object(object_type=PagedKVCache), - **curved, **units, "$": packed, - }, - "drowse_replay_batch_prefill": { - "input_embeds": nn.spec.Tensor([1, "seq_len", d], "float32"), - "logit_positions": nn.spec.Tensor(["batch_size"], "int32"), - "paged_kv_cache": nn.spec.Object(object_type=PagedKVCache), - **curved, **units, **replay, "$": packed, - }, - "drowse_attention_rows": {**rows, "$": {"param_mode": "none", "effect_mode": "none"}}, - "drowse_head_write_grams": {"$": packed}, - "drowse_verify_block_sites": { - "input_embeds": nn.spec.Tensor([1, "seq_len", d], "float32"), - "logit_positions": nn.spec.Tensor(["batch_size"], "int32"), - "paged_kv_cache": nn.spec.Object(object_type=PagedKVCache), - **units, "$": packed, - }, - **env.drowse_reads.readout_spec(model), - **env.drowse_reads.unit_read_spec(model), - } - return nn.spec.ModuleSpec.from_raw(raw, model) - - def new_cache(self): - shape = self.env.tvm.runtime.ShapeTuple - cache = self.vm["create_tir_paged_kv_cache"]( - shape([1]), shape([self.context]), shape([self.context]), shape([16]), shape([0]) - ) - self.add_sequence(cache, 0) - return cache - - def embed(self, ids): - tvm = self.env.tvm - rows = self.vm["embed"](tvm.runtime.tensor(np.asarray(ids, np.int32)), self.params) - return rows.numpy().reshape(1, len(ids), self.hidden_size).astype(np.float32) - - def forward_units(self, cache, ids, program_buffers, *, prefill: bool, affine=None): - tvm = self.env.tvm - meta, coeff, active, grams = program_buffers - embeds = self.embed(ids) - self.begin_forward(cache, tvm.runtime.ShapeTuple([0]), tvm.runtime.ShapeTuple([len(ids)])) - curve = [tvm.runtime.tensor((affine or {}).get(name, value)) - for name, value in self.curve_zeros.items()] - units = [tvm.runtime.tensor(v) for v in (meta, coeff, active, grams)] - if prefill: - out = self.vm["drowse_units_batch_prefill"]( - tvm.runtime.tensor(embeds), tvm.runtime.tensor(np.asarray([len(ids) - 1], np.int32)), - cache, *curve, *units, self.params, - ) - else: - out = self.vm["drowse_units_batch_decode"]( - tvm.runtime.tensor(embeds), cache, *curve, *units, self.params - ) - self.end_forward(cache) - logits = out[0].numpy().reshape(-1)[: self.vocab] - return logits, out[4].numpy(), out[5].numpy() - - def forward_sites(self, cache, ids, program_buffers): - tvm = self.env.tvm - meta, coeff, active, grams = program_buffers - embeds = self.embed(ids) - self.begin_forward(cache, tvm.runtime.ShapeTuple([0]), tvm.runtime.ShapeTuple([len(ids)])) - out = self.vm["drowse_verify_block_sites"]( - tvm.runtime.tensor(embeds), tvm.runtime.tensor(np.asarray([len(ids) - 1], np.int32)), cache, - *[tvm.runtime.tensor(v) for v in (meta, coeff, active, grams)], self.params, - ) - self.end_forward(cache) - names = ("block_in", "z", "attn_o", "mid", "act", "mlp_o", "out") - sites = {name: np.stack([out[1 + layer * 7 + k].numpy()[0] for layer in range(self.num_layers)]) - for k, name in enumerate(names)} - return out[0].numpy().reshape(-1)[: self.vocab], sites - - - # ------------------------------------------------------------------ replay (B1 §2.3, §6) --- - - def head_grams(self) -> np.ndarray: - return self.vm["drowse_head_write_grams"](self.params).numpy() - - def replay_carry(self, rows: int, tokens: int) -> dict: - """A fresh replay's threaded buffers: activity state (value 0, row −1, rank −1), traces - `[32, rows]`, population and pattern keys `[8, KV, tokens, hd]` (sized to the replay, as - the bridge sizes them).""" - tvm, du = self.env.tvm, self.env.drowse_units - block, L = self.block, self.num_layers - f, h = block["d_ff"], block["n_heads"] - state = np.zeros((L, 3 * f + 3 * h), np.float32) - state[:, f: 3 * f] = -1 - state[:, 3 * f + h:] = -1 - arrays = { - "state": state, - "traces": np.zeros((du.UNIT_MAX_ACTIVITY_TRACES, rows), np.float32), - "population": np.zeros((L, f + h), np.float32), - "keys": np.zeros((du.UNIT_MAX_PATTERN_LAYERS, block["n_kv_heads"], tokens, - block["head_dim"]), np.float32), - } - return {name: tvm.runtime.tensor(value) for name, value in arrays.items()} - - def replay_forward(self, cache, ids, program_buffers, meta, scales, grams, carry, affine=None): - """One `drowse_replay_batch_prefill` forward continuing `cache` (positions follow the - cache's length); the threaded buffers come back in `carry`.""" - tvm = self.env.tvm - embeds = self.embed(ids) - self.begin_forward(cache, tvm.runtime.ShapeTuple([0]), tvm.runtime.ShapeTuple([len(ids)])) - curve = [tvm.runtime.tensor((affine or {}).get(name, value)) - for name, value in self.curve_zeros.items()] - units = [tvm.runtime.tensor(v) for v in program_buffers] - out = self.vm["drowse_replay_batch_prefill"]( - tvm.runtime.tensor(embeds), tvm.runtime.tensor(np.asarray([len(ids) - 1], np.int32)), - cache, *curve, *units, tvm.runtime.tensor(meta), scales, grams, - carry["state"], carry["traces"], carry["population"], carry["keys"], self.params, - ) - self.end_forward(cache) - return { - "logits": out[0].numpy().reshape(-1)[: self.vocab], - "measurements": out[2].numpy(), - "jlens": out[4].numpy(), - "taps": out[5].numpy(), - "anatomy": out[6].numpy(), - "pattern_q": out[11], - "carry": {"state": out[7], "traces": out[8], "population": out[9], "keys": out[10]}, - } - - def attention_rows(self, keys, queries, rows_meta: np.ndarray) -> np.ndarray: - tvm = self.env.tvm - return self.vm["drowse_attention_rows"](keys, queries, tvm.runtime.tensor(rows_meta)).numpy() - - -def strip_scheduled_kernels(module, tvm, strip): - """Serialize only the kernels that carry GPU thread bindings (the drowse kernels); the - upstream graph's unscheduled kernels go through MLC's llvm pipeline untouched.""" - tir = tvm.tirx - for var in list(module.get_global_vars()): - function = module[var] - if not isinstance(function, tir.PrimFunc): - continue - bound = [] - tir.stmt_functor.post_order_visit( - function.body, - lambda node: bound.append(node) - if isinstance(node, tir.For) and node.kind == tir.ForKind.THREAD_BINDING else None, - ) - if bound: - module.update_func(var, strip(tvm.IRModule({var: function}), tvm)[var]) - return module - - -def install_block_sites_forward(model_class, env) -> None: - """A verification-only entry point: one forward through `drowse_block` with unit sites that - also capture every site tensor (never compiled into a library).""" - if getattr(model_class, "drowse_verify_block_sites", None) is not None: - return - UnitSites, op = env.UnitSites, env.op - - class CaptureSites(UnitSites): - def __init__(self, *args): - super().__init__(*args) - self.rows = {} - - def head(self, z, layer_id): - z = super().head(z, layer_id) - self.rows[(layer_id, "z")] = z - return z - - def mid(self, h_mid, layer_id): - self.rows[(layer_id, "mid")] = h_mid - - def neuron(self, act, layer_id): - act = super().neuron(act, layer_id) - self.rows[(layer_id, "act")] = act - return act - - def tap(self, z, attn_o, act, layer_id): - super().tap(z, attn_o, act, layer_id) - self.rows[(layer_id, "attn_o")] = attn_o - - def mlp(self, mlp_o, layer_id): - self.rows[(layer_id, "mlp_o")] = mlp_o - - def drowse_verify_block_sites(self, input_embeds, logit_positions, paged_kv_cache, unit_meta, - unit_coeff, unit_active, tap_grams): - spec = self._drowse_block_spec() - b, s, _ = input_embeds.shape - sites = CaptureSites(self.num_hidden_layers, spec["head_dim"], - paged_kv_cache.get_query_positions(b * s), unit_meta, unit_coeff, - unit_active, tap_grams, spec["sandwich"], spec["rms_eps"]) - hidden = self.model._drowse_prepare_inputs(input_embeds) - captured = [] - for layer_id, layer in enumerate(self.model.layers): - block_in = hidden - hidden = layer.drowse_block(hidden, paged_kv_cache, layer_id, sites) - captured += [block_in, sites.rows[(layer_id, "z")], sites.rows[(layer_id, "attn_o")], - sites.rows[(layer_id, "mid")], sites.rows[(layer_id, "act")], - sites.rows[(layer_id, "mlp_o")], hidden] - last = op.take(self.model.norm(hidden), logit_positions, axis=1) - return (self._get_logits(last), *captured) - - model_class.drowse_verify_block_sites = drowse_verify_block_sites - - -def load_tensor_cache(directory: Path) -> dict[str, np.ndarray]: - """Every tensor as the runtime decodes it: `f32-to-bf16` records (production q4f32_1 scales - and norms) widen their stored bf16 bits to float32.""" - cache = json.loads((directory / "tensor-cache.json").read_text()) - tensors = {} - for shard in cache["records"]: - data = (directory / shard["dataPath"]).read_bytes() - for record in shard["records"]: - chunk = data[record["byteOffset"]: record["byteOffset"] + record["nbytes"]] - encoding = record.get("format", "raw") - if encoding not in ("raw", "f32-to-bf16"): - raise SystemExit(f"{record['name']}: unsupported tensor encoding {encoding}") - if encoding == "f32-to-bf16" and record["dtype"] == "float32": - bits = np.frombuffer(chunk, dtype=" np.ndarray: - """`G_h = (γ_ao ⊙ W_O^h)ᵀ (γ_ao ⊙ W_O^h)` from the converted (dequantized) tensors, fp64.""" - hd = block["head_dim"] - suffix = f"layers.{layer}.self_attn.o_proj.weight" - prefix = next(name for name in tensors if name.endswith(suffix) or name.endswith( - suffix.replace(".weight", ".q_weight"))) - prefix = prefix.rsplit(".", 1)[0] - if prefix + ".weight" in tensors: - w = tensors[prefix + ".weight"].astype(np.float64) - else: - weight, scale = tensors[prefix + ".q_weight"], tensors[prefix + ".q_scale"] - shifts = np.arange(8, dtype=np.uint32) * 4 - codes = ((weight[:, :, None] >> shifts) & 0xF).reshape(weight.shape[0], -1).astype(np.float64) - w = (codes - 7) * np.repeat(scale.astype(np.float64), 32, axis=1) - columns = w[:, head * hd: (head + 1) * hd] - if block["sandwich"]: - gamma = tensors[prefix.replace("self_attn.o_proj", "post_attention_layernorm") - + ".weight"].astype(np.float64) - columns = gamma[:, None] * columns - return (columns.T @ columns).astype(np.float32) - - -def unit_stats(goldens: Path, arch: str) -> dict: - stats = json.loads((goldens / f"unit-stats-{arch}-v1.json").read_text()) - return { - "neuron_mean": decode(stats["neuron_mean"]), - "head_mean": decode(stats["head_mean"]), - "neuron_scale": decode(stats["scales"]["neuron"]), - "head_scale": decode(stats["scales"]["head"]), - } - - -def reading(kind: str, layer: int, index: int, raw: float, stats: dict) -> float: - if kind == "neuron": - scale = stats["neuron_scale"][layer, 0 if raw >= 0 else 1, index] - else: - scale = stats["head_scale"][layer, index] - return float(np.float32(raw) / np.float32(scale)) - - -def verify_arch(env, fixtures: Path, goldens: Path, arch: str, quantization: str) -> dict: - model_dir = fixtures / f"units-{arch}-{quantization}" - vm = FixtureVM(env, model_dir) - tensors = load_tensor_cache(model_dir) - stats = unit_stats(goldens, arch) - block = vm.block - caps = {"groups": env.UNIT_MAX_GROUPS, "head_taps": env.UNIT_MAX_HEAD_TAPS} - - def program(): - return UnitProgram(env.unit_meta_layout(vm.num_layers), env.unit_coeff_layout(block["head_dim"]), - vm.num_layers, block["head_dim"], caps) - - # block-sites: the unablated forward, every site at every position. - sites_golden = json.loads((goldens / f"block-sites-{arch}-v1.json").read_text()) - tolerance = Tolerance(sites_golden["tolerance"]) - empty = program().buffers([]) - logits, sites = vm.forward_sites(vm.new_cache(), sites_golden["ids"], empty) - for name, value in sites_golden["sites"].items(): - tolerance.check(f"block-sites:{name}", decode(value), sites[name]) - tolerance.check("block-sites:logits", decode(sites_golden["logits_last"]), logits) - - # The units entry points with an empty program agree with the site forward. - unit_logits, jlens, taps = vm.forward_units(vm.new_cache(), sites_golden["ids"], empty, prefill=True) - tolerance.check("block-sites:units-prefill-logits", decode(sites_golden["logits_last"]), unit_logits) - tolerance.check("block-sites:units-prefill-out", decode(sites_golden["sites"]["out"])[:, -1], jlens) - - # unit-ablation: every case from its own lowered tables. - ablation = json.loads((goldens / f"unit-ablation-{arch}-v1.json").read_text()) - push = json.loads((goldens / f"neuron-push-{arch}-v1.json").read_text()) - mixed = mixed_affine(ablation, arch) - for case in ablation["cases"]: - affine = None - if case["name"] == "mixed": - affine = push_affine(vm, mixed, case["steering"].split(" + ")[0]) - if case["name"] == "push-and-ablate": - affine = push_affine(vm, push, "0.3 neuron/L2n7") - unit = program() - for table in case["tables"]: - trigger = dict(table["trigger"]) - entries = list(table["entries"]) - if table["site"] == "act": - for coordinate, keep, bias in zip(entries, table["keep"], table["bias"]): - unit.ablate("neuron", table["layer"], coordinate, keep, bias, trigger) - else: - hd = block["head_dim"] - for start in range(0, len(entries), hd): - span = entries[start: start + hd] - head = span[0] // hd - if span != list(range(head * hd, (head + 1) * hd)): - raise SystemExit(f"{case['name']}: a z table is not whole heads") - keeps = set(table["keep"][start: start + hd]) - if len(keeps) != 1: - raise SystemExit(f"{case['name']}: a head's keep is not uniform") - unit.ablate("head", table["layer"], head, keeps.pop(), - table["bias"][start: start + hd], trigger) - gates = {t["gate"]["probe"] for t in unit.triggers if t.get("gate")} - gate_slots = {} - for probe in sorted(gates): - kind, layer, index = parse_unit(probe) - gram = head_gram(tensors, block, layer, index) if kind == "head" else None - gate_slots[probe] = (kind, layer, index, unit.tap(kind, layer, index, gram)) - cache = vm.new_cache() - scores = {} - for number, forward in enumerate(case["forwards"]): - active = [trigger_active(t, number, scores.get(((t or {}).get("gate") or {}).get("probe"))) - for t in unit.triggers] - buffers = unit.buffers(active) - label = f"unit-ablation:{case['name']}[{number}]" - if number == 0 and affine is None: - site_logits, site = vm.forward_sites(vm.new_cache(), forward["ids"], buffers) - tolerance.check(label + ".logits(sites)", decode(forward["logits"]), site_logits) - golden_out = decode(forward["out"]) - tolerance.check(label + ".out", golden_out, site["out"][:, forward["out_rows"]]) - tolerance.check(label + ".out_last_layer", decode(case["out_last_layer"]), - site["out"][-1]) - logits, jlens, taps = vm.forward_units(cache, forward["ids"], buffers, - prefill=number == 0, affine=affine) - tolerance.check(label + ".logits", decode(forward["logits"]), logits) - last_row = forward["out_rows"].index(len(forward["ids"]) - 1) - expected = decode(forward["out"])[:, last_row].astype(np.float32) - if affine is not None: - # `out` is the block output; the units pair returns the residual after the - # post-block hook, which adds the push's delta at the layers it names. - active = affine["affine_active"][:, 0] != 0 - expected = expected + np.where(active[:, None], affine["affine_along"][:, 0, None] - * affine["affine_target"][:, 0, 0, None] - * affine["affine_basis"][:, 0, 0], 0).astype(np.float32) - tolerance.check(label + ".out_last", expected, jlens) - scores = {probe: reading(kind, layer, index, float(taps[slot]), stats) - for probe, (kind, layer, index, slot) in gate_slots.items()} - - # unit-probes: the live tap through the units pair. - probes = json.loads((goldens / f"unit-probes-{arch}-v1.json").read_text()) - for case in probes["cases"]: - unit = program() - for term in split_terms(case["steering"]): - kind, layer, index, alpha, trigger = term - mean = (stats["neuron_mean"][layer, index] if kind == "neuron" - else stats["head_mean"][layer, index]) - unit.ablate(kind, layer, index, np.float32(1 - alpha), - (np.float32(alpha) * np.asarray(mean, np.float32)), trigger) - names = list(probes["probes"]) + ([probes["gate_unit"]] if case["gate_scalars"] else []) - slots = {} - for name in names: - kind, layer, index = parse_unit(name) - gram = head_gram(tensors, block, layer, index) if kind == "head" else None - slots[name] = (kind, layer, index, unit.tap(kind, layer, index, gram)) - cache = vm.new_cache() - ids = list(probes["ids"]) - scores = {} - for number, forward in enumerate(case["forwards"]): - active = [trigger_active(t, number, scores.get(((t or {}).get("gate") or {}).get("probe"))) - for t in unit.triggers] - step_ids = ids if number == 0 else [case["tokens"][number - 1]] - logits, _, taps = vm.forward_units(cache, step_ids, unit.buffers(active), - prefill=number == 0) - if int(np.argmax(logits)) != case["tokens"][number]: - raise SystemExit(f"unit-probes:{case['name']}[{number}] greedy token differs") - label = f"unit-probes:{case['name']}[{number}]" - scores = {} - for name, (kind, layer, index, slot) in slots.items(): - raw = float(taps[slot]) - golden = forward["units"][name] - tolerance.check(label + f".{name}.raw", golden["raw"], raw) - value = reading(kind, layer, index, raw, stats) - tolerance.check(label + f".{name}.value", golden["value"], value, - atol=tolerance.z_atol, rtol=0.0) - scores[name] = value - if case["gate_scalars"]: - gate = probes["gate_unit"] - tolerance.check(label + ".gate", case["gate_scalars"][number][gate], scores[gate], - atol=tolerance.z_atol, rtol=0.0) - verify_replay(env, vm, tensors, stats, goldens, arch, program, tolerance.worst) - if not os.environ.get("DROWSE_UNITS_SKIP_READS"): - import static_reads - - static_reads.verify(env, vm, tensors, goldens, arch, tolerance.check) - return tolerance.worst - - -MIXED_AFFINE = Path(__file__).resolve().parents[1] / "fixtures" / "unit-ablation-mixed-affine-v1.json" - - -def mixed_affine(ablation: dict, arch: str) -> dict: - """The `mixed` case's push lowered to affine groups (browser-runtime/fixtures, recorded by - build-mixed-affine.py from drowse's own lowering), bound to the goldens' model file.""" - doc = json.loads(MIXED_AFFINE.read_text()) - if doc["fixtureModels"]["sha256"] != ablation["fixtureModels"]["sha256"]: - raise SystemExit(f"{MIXED_AFFINE.name} names another fixture model file: regenerate it") - return doc["arches"][arch] - - -def push_affine(vm, push: dict, expression: str) -> dict: - """The structured affine buffers of a neuron push from neuron-push's recorded lowering - (`delta = along · target · basis`, collapse 0), in group 0 at every layer it names.""" - case = next(c for c in push["cases"] if c["expression"] == expression) - if case["trigger"]["gate"] is not None or not case["trigger"]["prompt"]: - raise SystemExit("push_affine handles always-on pushes only") - affine = {name: value.copy() for name, value in vm.curve_zeros.items()} - for layer in case["layers"]: - index = layer["layer"] - affine["affine_active"][index, 0] = 1.0 - affine["affine_basis"][index, 0, 0] = np.asarray(layer["basis"], np.float32) - affine["affine_neutral"][index, 0] = np.asarray(layer["neutral"], np.float32) - affine["affine_target"][index, 0, 0] = np.float32(layer["target"]) - affine["affine_along"][index, 0] = np.float32(layer["along"]) - return affine - - -def parse_unit(name: str): - match = re.match(r"^(neuron|head)/L(\d+)[nh](\d+)$", name) - if not match: - raise SystemExit(f"not a unit name: {name}") - return match.group(1), int(match.group(2)), int(match.group(3)) - - -def split_terms(steering: str | None): - if steering is None: - return [] - terms = [] - for text in steering.split(" + "): - match = TERM.match(text.strip()) - if not match: - raise SystemExit(f"unsupported steering term in a units golden: {text}") - alpha = float(match.group("alpha")) if match.group("alpha") else 1.0 - terms.append((match.group("kind"), int(match.group("layer")), int(match.group("index")), - alpha, parse_trigger(match.group("trigger")))) - return terms - - -def verify(env, fixtures: Path, goldens: Path) -> dict: - results = {} - only = os.environ.get("DROWSE_UNITS_ONLY") - for arch in ("qwen3", "gemma3"): - for quantization in ("q0f32", "q4f32_1"): - if only and f"{arch}-{quantization}" not in only.split(","): - continue - if not (fixtures / f"units-{arch}-{quantization}").is_dir(): - raise SystemExit(f"missing fixture model units-{arch}-{quantization} in {fixtures}") - results[f"{arch}-{quantization}"] = verify_arch(env, fixtures, goldens, arch, quantization) - worst = results[f"{arch}-{quantization}"] - print(f"units goldens {arch} {quantization}: " - + ", ".join(f"{k} {v:.2e}" for k, v in sorted(worst.items())), flush=True) - return results - - -# ---------------------------------------------------------------------- replay (stage 2) --- - -#: Replay forwards carry at most this many rows here, so every case also exercises the -#: KV-continuing chunk path (the bridge chunks at the library's `prefill_chunk_size`). -REPLAY_CHUNK = 16 -#: Native `UnitScales` floor (drowse/units/capture.py `SCALE_FLOOR`). -SCALE_FLOOR = 1e-6 -#: The raw first turn's one-token prompt (`browser_units.RAW_FIRST` through the fixture -#: tokenizer: "K" on qwen3, "=" on gemma3; no BOS, so its first row is produced at the sink). -RAW_FIRST_IDS = {"qwen3": [45], "gemma3": [32]} - - -def replay_meta(du, *, anatomy=None, spans=None, population_row=None, traces=(), - pattern_layers=()) -> np.ndarray: - """`replay_meta` as drowse.ai's `encodeReplayMeta` packs it (HOOK_ABI.md §7).""" - lay = du.replay_meta_layout() - meta = np.full(lay["length"], -1, np.int32) - flags = 0 - if anatomy is not None: - meta[lay["anatomy_position"]] = anatomy - flags |= du.REPLAY_FLAG_ANATOMY - meta[lay["span_count"]] = 0 - meta[lay["trace_count"]] = 0 - if spans is not None: - meta[lay["span_count"]] = len(spans) - for i, (first_row, rows, first_position) in enumerate(spans): - meta[lay["spans"] + 4 * i: lay["spans"] + 4 * i + 4] = [ - first_row, rows, first_position, 1 if first_position < 0 else 0] - meta[lay["population_row"]] = -1 if population_row is None else population_row - meta[lay["trace_count"]] = len(traces) - for i, (kind, layer, index) in enumerate(traces): - meta[lay["traces"] + 3 * i: lay["traces"] + 3 * i + 3] = [ - layer, 0 if kind == "neuron" else 1, index] - flags |= du.REPLAY_FLAG_ACTIVITY - meta[lay["pattern_layer_count"]] = len(pattern_layers) - if pattern_layers: - meta[lay["pattern_layers"]: lay["pattern_layers"] + len(pattern_layers)] = sorted(pattern_layers) - flags |= du.REPLAY_FLAG_PATTERNS - meta[lay["flags"]] = flags - return meta - - -def unit_scales(stats: dict) -> np.ndarray: - """`[L, 2·d_ff + H]`: `S+ | S− | S_head`, floored as native's activity reads them.""" - neuron, head = stats["neuron_scale"], stats["head_scale"] - return np.maximum(np.concatenate([neuron[:, 0], neuron[:, 1], head], axis=1), - SCALE_FLOOR).astype(np.float32) - - -def run_replay(vm, segments, *, program, meta, scales, grams, affine=None, anatomy=None, rows=1): - """Feed `segments` (`(ids, active)` each: one control state) on one fresh sequence in - forwards of at most `REPLAY_CHUNK` rows, threading the carried buffers. Returns the carry, - every forward's output, and the forward holding the anatomy position (its taps and - queries).""" - tokens = sum(len(ids) for ids, _ in segments) - cache, carry = vm.new_cache(), vm.replay_carry(max(1, rows), tokens) - meta_t = meta - position, outputs, at = 0, [], None - for ids, active in segments: - buffers = program.buffers(active) - for start in range(0, len(ids), REPLAY_CHUNK): - chunk = list(ids[start: start + REPLAY_CHUNK]) - out = vm.replay_forward(cache, chunk, buffers, meta_t, scales, grams, carry, affine) - carry = out["carry"] - if anatomy is not None and position <= anatomy < position + len(chunk): - at = out - outputs.append((position, chunk, out)) - position += len(chunk) - return carry, outputs, at - - -def check_next_tokens(label: str, outputs, tokens: dict[int, int], *, distinct: bool = False) -> None: - """Each forward's last logits pick the token the golden says was produced there (greedy, or - `distinct` greedy over the tokens not yet generated, as the goldens' generated nodes ran).""" - order = sorted(tokens) - for position, chunk, out in outputs: - last = position + len(chunk) - 1 - if last not in tokens: - continue - logits = out["logits"].astype(np.float64).copy() - if distinct: - logits[[tokens[p] for p in order if p < last]] = -np.inf - if int(np.argmax(logits)) != tokens[last]: - raise SystemExit(f"{label}: the replay at position {last} does not pick token {tokens[last]}") - - -def program_for(make_program, steering, stats, vm, push, affine_fn): - """A unit program (and push buffers) for one golden's steering string.""" - unit, affine = make_program(), None - if steering is None: - return unit, affine - terms = [] - for text in steering.split(" + "): - text = text.strip() - if text.startswith("0.3 neuron/"): - affine = affine_fn(vm, push, text) - else: - terms.append(text) - for kind, layer, index, alpha, trigger in split_terms(" + ".join(terms) if terms else None): - mean = stats["neuron_mean"][layer, index] if kind == "neuron" else stats["head_mean"][layer, index] - unit.ablate(kind, layer, index, np.float32(1 - alpha), - np.float32(alpha) * np.asarray(mean, np.float32), trigger) - return unit, affine - - -def head_write_norms(anatomy, layout, block, grams, hidden_size): - L = anatomy.shape[0] - hd, H = block["head_dim"], block["n_heads"] - out = np.zeros((L, H), np.float64) - for layer in range(L): - z = anatomy[layer, layout["z"]: layout["z"] + H * hd].astype(np.float64).reshape(H, hd) - o = anatomy[layer, layout["attn_o"]: layout["attn_o"] + hidden_size].astype(np.float64) - q = np.einsum("hi,hij,hj->h", z, grams[layer].astype(np.float64), z) - norm = np.sqrt(np.maximum(q, 0)) - if block["sandwich"]: - norm = norm / np.sqrt(np.mean(o * o) + block["rms_eps"]) - out[layer] = norm - return out - - -def pattern_rows(vm, carry, queries, heads, slots, position): - """`drowse_attention_rows` for `(layer, head)` pairs, in batches of `MAX_PATTERN_HEADS`.""" - du = vm.env.drowse_units - rows = [] - for start in range(0, len(heads), du.UNIT_MAX_PATTERN_HEADS): - batch = heads[start: start + du.UNIT_MAX_PATTERN_HEADS] - meta = np.full((du.UNIT_MAX_PATTERN_HEADS, 4), -1, np.int32) - for i, (layer, head) in enumerate(batch): - meta[i] = [slots[layer], layer, head, position] - out = vm.attention_rows(carry["keys"], queries, meta) - rows.extend(out[: len(batch)]) - if np.any(out[len(batch):] != 0): - raise SystemExit("attention rows: an unused row is not zero") - return np.asarray(rows) - - -def verify_replay(env, vm, tensors, stats, goldens: Path, arch: str, make_program, worst: dict): - du = vm.env.drowse_units - block, L, d = vm.block, vm.num_layers, vm.hidden_size - layout = du.anatomy_layout(d, block) - scales_np = unit_scales(stats) - grams_np = vm.head_grams() - host_grams = np.stack([np.stack([head_gram(tensors, block, layer, h) for h in range(block["n_heads"])]) - for layer in range(L)]) - if not np.allclose(grams_np, host_grams, rtol=1e-4, atol=1e-5): - raise SystemExit(f"drowse_head_write_grams differs from the converted tensors' grams " - f"(max |Δ| {float(np.abs(grams_np - host_grams).max()):.3g})") - tvm = env.tvm - scales, grams = tvm.runtime.tensor(scales_np), tvm.runtime.tensor(grams_np) - push = json.loads((goldens / f"neuron-push-{arch}-v1.json").read_text()) - all_layers = list(range(L)) - slots = {layer: i for i, layer in enumerate(all_layers)} - - # attention-patterns: every head at positions 2, 5, 8 of the short prompt, every layer. - golden = json.loads((goldens / f"attention-patterns-{arch}-v1.json").read_text()) - tol = Tolerance(golden["tolerance"]) - prob = golden["tolerance"]["library"]["probability_atol"] - heads = [(layer, h) for layer in all_layers for h in range(block["n_heads"])] - for case in golden["cases"]: - unit, affine = program_for(make_program, case["steering"], stats, vm, push, push_affine) - for row in case["rows"]: - p = row["position"] - meta = replay_meta(du, anatomy=p, pattern_layers=all_layers) - carry, outputs, at = run_replay(vm, [(golden["ids"], [True] * len(unit.triggers))], - program=unit, meta=meta, scales=scales, grams=grams, - affine=affine, anatomy=p) - got = pattern_rows(vm, carry, at["pattern_q"], heads, slots, p) - for layer in all_layers: - expected = decode(row["layers"][layer]) - block_rows = got[layer * block["n_heads"]: (layer + 1) * block["n_heads"]] - tol.check(f"attention-patterns:{case['name']}@{p}.L{layer}", expected, - block_rows[:, : p + 1], atol=prob, rtol=0.0) - if np.any(block_rows[:, p + 1:] != 0): - raise SystemExit(f"attention-patterns:{case['name']}@{p}: weight past p") - worst.update(tol.worst) - - # token-anatomy: the taps at the producing position, write norms, chosen heads' rows. - golden = json.loads((goldens / f"token-anatomy-{arch}-v1.json").read_text()) - tol = Tolerance(golden["tolerance"]) - prob = golden["tolerance"]["library"]["probability_atol"] - rounded = golden["tolerance"]["rounded"]["atol"] - for case in golden["cases"]: - inter = case["intermediates"] - ids = inter["ids"] - p = len(ids) - 1 - unit, affine = program_for(make_program, case["steering"], stats, vm, push, push_affine) - meta = replay_meta(du, anatomy=p, pattern_layers=all_layers) - carry, outputs, at = run_replay(vm, [(ids, [True] * len(unit.triggers))], program=unit, - meta=meta, scales=scales, grams=grams, affine=affine, - anatomy=p) - anatomy = at["anatomy"] - label = f"token-anatomy:{case['name']}" - for name in ("block_in", "mid", "out", "act", "z"): - expected = decode(inter["taps"][name]) - tol.check(f"{label}.{name}", expected, - anatomy[:, layout[name]: layout[name] + expected.shape[1]]) - tol.check(f"{label}.head_write_norms", decode(inter["head_write_norms"]), - head_write_norms(anatomy, layout, block, host_grams, d)) - # block_in[L+1] is out[L]; out_pre − mid is the MLP's write (after the post-norm on Gemma). - tol.check(f"{label}.block_in=out", anatomy[1:, layout["block_in"]: layout["block_in"] + d], - anatomy[:-1, layout["out"]: layout["out"] + d]) - mlp = anatomy[:, layout["mlp_o"]: layout["mlp_o"] + d].astype(np.float64) - if block["sandwich"]: - gamma = np.stack([tensors[next(n for n in tensors if n.endswith( - f"layers.{layer}.post_feedforward_layernorm.weight"))] for layer in all_layers]) - mlp = gamma * mlp / np.sqrt(np.mean(mlp * mlp, axis=1, keepdims=True) + block["rms_eps"]) - tol.check(f"{label}.mlp_write", mlp, - anatomy[:, layout["out_pre"]: layout["out_pre"] + d] - - anatomy[:, layout["mid"]: layout["mid"] + d]) - record = case["envelope"]["measurements"]["anatomy"] - if record.get("patterns"): - chosen = [(item["layer"], item["head"]) for item in record["patterns"]] - got = pattern_rows(vm, carry, at["pattern_q"], chosen, slots, p) - for item, row in zip(record["patterns"], got): - tol.check(f"{label}.pattern.{item['unit']}", item["weights"], row[: p + 1], - atol=prob + rounded, rtol=0.0) - worst.update(tol.worst) - - # unit-activity: device peaks against every unit's diagnostics, the host ranking, traces and - # the population (B1-goldens §2.5). - verify_activity(env, vm, goldens, arch, make_program, stats, scales, grams, worst) - - -def spans_from_runs(runs, rows: int): - """Native `ReplayForward.spans()`: `(first_row, rows, producing position of the first row)`.""" - stops = [first for first, _ in runs[1:]] + [rows] - return [(int(first), int(stop) - int(first), int(at) - 1) for (first, at), stop in zip(runs, stops)] - - -def rank_activity(state: np.ndarray, block: dict, top: int): - """The host's ranking of the device state (native `_activity`): each kind's top `top` by rank - over the flat order `[(neuron, 0), (head, 0), (neuron, 1), …]`, rank descending, flat index - ascending on ties, rank −1 dropped.""" - f, h = block["d_ff"], block["n_heads"] - flat = [] - for layer in range(state.shape[0]): - row = state[layer] - for n in range(f): - flat.append(("neuron", layer, n, row[n], row[f + n], row[2 * f + n])) - for k in range(h): - flat.append(("head", layer, k, row[3 * f + k], row[3 * f + h + k], row[3 * f + 2 * h + k])) - out = [] - for kind in ("neuron", "head"): - items = sorted(((i, e) for i, e in enumerate(flat) if e[0] == kind), - key=lambda item: (-float(item[1][5]), item[0])) - out += [e for _, e in items[:top] if e[5] >= 0] - return out - - -def unit_name(kind: str, layer: int, index: int) -> str: - return f"{kind}/L{layer}{'n' if kind == 'neuron' else 'h'}{index}" - - -def f16_close(golden_text: str, actual: np.ndarray) -> bool: - golden = np.frombuffer(base64.b64decode(golden_text), "= 1e-3 * max(1.0, abs(float(peak[i]))) and at != int(row[i]): - raise SystemExit(f"{unit_label}: peak row {at}, golden {int(row[i])}") - # the host ranking of the device state - ranked = rank_activity(state, block, int(args["top"])) - listed = result["top"] - if len(ranked) != len(listed): - raise SystemExit(f"{label}: {len(ranked)} ranked units, golden {len(listed)}") - groups = ties.get(f"cases[{number}].result.top", {"groups": []})["groups"] - grouped = {i: tuple(g) for g in groups for i in g} - for i, (entry, (kind, layer, index, value, at, _rank)) in enumerate(zip(listed, ranked)): - name_i = unit_name(kind, layer, index) - if i in grouped: - members = {listed[j]["unit"] for j in grouped[i]} - if name_i not in members: - raise SystemExit(f"{label}: tie group {grouped[i]} lacks {name_i}") - entry = next(e for e in listed if e["unit"] == name_i) - elif entry["unit"] != name_i: - raise SystemExit(f"{label}: top[{i}] is {name_i}, golden {entry['unit']}") - tol.check(f"{label}.top", [entry["peak"]], [value], atol=z_atol, rtol=0.0) - if name_i not in case["tied_peak_rows"] and int(at) != entry["raw_index"]: - raise SystemExit(f"{label}: {name_i} peaks at row {int(at)}, golden {entry['raw_index']}") - # traces (unproduced rows were never written: 0) and the population - trace_values = carry["traces"].numpy() - for slot, unit_text in enumerate(args.get("units", [])): - expected = result["traces"][unit_text] - tol.check(f"{label}.trace", expected, trace_values[slot, : len(expected)], - atol=z_atol, rtol=0.0) - if population_row is not None: - population = carry["population"].numpy() - for entry in result["population"]["layers"]: - layer = entry["layer"] - if not f16_close(entry["neurons"], population[layer, :f]) or not f16_close( - entry["heads"], population[layer, f:]): - raise SystemExit(f"{label}: population at layer {layer} is not within one f16 ulp") - worst.update(tol.worst) diff --git a/browser-runtime/forks/units_vm.py b/browser-runtime/forks/units_vm.py new file mode 100644 index 0000000..97fe76a --- /dev/null +++ b/browser-runtime/forks/units_vm.py @@ -0,0 +1,478 @@ +"""A units model (hook ABI v6, `block-sites-v6`) on the C TVM VM, for verify-production-library.py. + +`UnitsVM` compiles a converted MLC model for `llvm` through MLC's own pipeline (GPU-scheduled +drowse kernels run serially, lane by lane, after `strip_gpu_thread_bindings`) and drives it +through MLC's paged KV cache exactly as WebLLM drives it. `UnitProgram` packs `unit_meta`, +`unit_coeff`, `unit_active` and `tap_grams` in the HOOK_ABI.md §4 layout. `Weights` dequantizes +the tensor cache to fp64 and `Device` calls the library's static reads. +""" + +from __future__ import annotations + +import json +from pathlib import Path + +import numpy as np + + +class UnitProgram: + """`unit_meta`/`unit_coeff`/`unit_active`/`tap_grams` in the HOOK_ABI.md §4 layout.""" + + def __init__(self, layout_meta, layout_coeff, num_layers: int, head_dim: int, caps: dict): + self.meta_layout, self.coeff_layout = layout_meta, layout_coeff + self.num_layers, self.head_dim, self.caps = num_layers, head_dim, caps + self.neurons, self.heads, self.neuron_taps, self.head_taps = [], [], [], [] + self.triggers = [] + + def group(self, trigger) -> int: + key = json.dumps(trigger, sort_keys=True) + keys = [json.dumps(t, sort_keys=True) for t in self.triggers] + if key not in keys: + if len(self.triggers) >= self.caps["groups"]: + raise SystemExit("unit program has more trigger groups than capacity") + self.triggers.append(trigger) + keys.append(key) + return keys.index(key) + + def ablate(self, kind: str, layer: int, index: int, keep: float, bias, trigger) -> None: + group = self.group(trigger) + entry = (layer, index, group, np.float32(keep), np.asarray(bias, np.float32)) + (self.neurons if kind == "neuron" else self.heads).append(entry) + + def tap(self, kind: str, layer: int, index: int, gram=None) -> int: + slot = len(self.neuron_taps) + len(self.head_taps) + if kind == "neuron": + self.neuron_taps.append((layer, index, slot)) + else: + self.head_taps.append((layer, index, slot, gram)) + return slot + + def buffers(self, active: list[bool]): + meta = np.zeros(self.meta_layout["__length__"][0], np.uint32) + coeff = np.zeros(self.coeff_layout["__length__"][0], np.float32) + grams = np.zeros((self.caps["head_taps"], self.head_dim, self.head_dim), np.float32) + + def csr(name, entries, columns): + offsets = self.meta_layout[name + "_offsets"][0] + ordered = sorted(enumerate(entries), key=lambda item: (item[1][0], item[0])) + for layer in range(self.num_layers + 1): + meta[offsets + layer] = sum(1 for _, e in ordered if e[0] < layer) + return [e for _, e in ordered], columns + + neurons, _ = csr("neuron", self.neurons, None) + for i, (layer, index, group, keep, bias) in enumerate(neurons): + meta[self.meta_layout["neuron_index"][0] + i] = index + meta[self.meta_layout["neuron_group"][0] + i] = group + coeff[self.coeff_layout["neuron_keep"][0] + i] = keep + coeff[self.coeff_layout["neuron_bias"][0] + i] = bias + heads, _ = csr("head", self.heads, None) + for i, (layer, index, group, keep, bias) in enumerate(heads): + meta[self.meta_layout["head_index"][0] + i] = index + meta[self.meta_layout["head_group"][0] + i] = group + coeff[self.coeff_layout["head_keep"][0] + i] = keep + start = self.coeff_layout["head_bias"][0] + i * self.head_dim + coeff[start : start + self.head_dim] = bias + taps, _ = csr("tap_neuron", self.neuron_taps, None) + for i, (layer, index, slot) in enumerate(taps): + meta[self.meta_layout["tap_neuron_index"][0] + i] = index + meta[self.meta_layout["tap_neuron_slot"][0] + i] = slot + taps, _ = csr("tap_head", self.head_taps, None) + for i, (layer, index, slot, gram) in enumerate(taps): + meta[self.meta_layout["tap_head_index"][0] + i] = index + meta[self.meta_layout["tap_head_slot"][0] + i] = slot + grams[i] = gram + unit_active = np.asarray([1.0 if flag else 0.0 for flag in active] + + [0.0] * (self.caps["groups"] - len(active)), np.float32) + return meta, coeff, unit_active, grams + + +class UnitsVM: + """One converted units model compiled for llvm, its parameters, and a paged KV cache.""" + + def __init__(self, env, model_dir: Path): + self.env = env + tvm, relax, nn = env.tvm, env.relax, env.nn + chat = json.loads((model_dir / "mlc-chat-config.json").read_text()) + self.arch, self.quantization = chat["model_type"], chat["quantization"] + config_class, model_class = env.models[chat["model_type"]] + config = config_class.from_dict(chat["model_config"]) + quantization = env.QUANTIZATION[self.quantization] + target = tvm.target.Target({"kind": "llvm"}) + with target: + model, _ = env.make_quantization_functions(model_class)[quantization.kind]( + config, quantization + ) + spec = self._spec(model, nn) + module, named_params, ext_mods = model.export_tvm(spec=spec, allow_extern=True) + module = strip_scheduled_kernels(module, tvm, env.strip_gpu_thread_bindings) + self.block = model._drowse_block_spec() + self.num_layers = model.num_hidden_layers + self.hidden_size = model.hidden_size + self.vocab = chat["vocab_size"] + env.prepare_parameters(named_params) + metadata = env.create_metadata(chat["model_type"], config, named_params, self.quantization) + pipeline = relax.get_pipeline( + "mlc_llm", target=target, flashinfer=False, cublas_gemm=False, + faster_transformer=False, allreduce_strategy=env.IPCAllReduceStrategyType.NONE, + variable_bounds={"total_seq_len": config.context_window_size, + "seq_len": config.prefill_chunk_size, "batch_size": 1, + "jlens_layers": self.num_layers, "sae_features": 16384}, + cuda_graph_symbolic_capture_hints={}, additional_tirs={}, ext_mods=ext_mods, + metadata=metadata, debug_dump=None, + ) + with tvm.transform.PassContext(config={"tirx.disable_cse_tir": True}): + executable = relax.build(module, target=target, relax_pipeline=pipeline) + self.vm = relax.VirtualMachine(executable, tvm.cpu()) + tensors = load_tensor_cache(model_dir) + self.params = [tvm.runtime.tensor(tensors[name], device=tvm.cpu()) for name, _ in named_params] + self.curve_zeros = { + name: np.zeros([int(d) for d in t.shape], t.dtype) + for name, t in env.structured_curve_program_spec(self.num_layers, self.hidden_size).items() + } + self.context = config.context_window_size + self.add_sequence = tvm.get_global_func("vm.builtin.kv_state_add_sequence") + self.begin_forward = tvm.get_global_func("vm.builtin.kv_state_begin_forward") + self.end_forward = tvm.get_global_func("vm.builtin.kv_state_end_forward") + + def _spec(self, model, nn): + env = self.env + from mlc_llm.nn import PagedKVCache + + d = model.hidden_size + head_dim = model._drowse_block_spec()["head_dim"] + curved = env.structured_curve_program_spec(model.num_hidden_layers, d) + units = env.unit_program_spec(model.num_hidden_layers, head_dim) + block = model._drowse_block_spec() + replay = env.drowse_units.replay_program_spec(model.num_hidden_layers, block) + rows = env.drowse_units.attention_rows_spec(block) + packed = {"param_mode": "packed", "effect_mode": "none"} + install_block_sites_forward(type(model), env) + raw = { + "embed": {"input_ids": nn.spec.Tensor(["seq_len"], "int32"), "$": packed}, + "create_paged_kv_cache": { + "max_batch_size": int, "max_total_seq_len": int, "prefill_chunk_size": int, + "page_size": int, "support_sliding_window": int, + "$": {"param_mode": "none", "effect_mode": "none"}, + }, + "drowse_units_batch_prefill": { + "input_embeds": nn.spec.Tensor([1, "seq_len", d], "float32"), + "logit_positions": nn.spec.Tensor(["batch_size"], "int32"), + "paged_kv_cache": nn.spec.Object(object_type=PagedKVCache), + **curved, **units, "$": packed, + }, + "drowse_units_batch_decode": { + "input_embeds": nn.spec.Tensor(["batch_size", 1, d], "float32"), + "paged_kv_cache": nn.spec.Object(object_type=PagedKVCache), + **curved, **units, "$": packed, + }, + "drowse_replay_batch_prefill": { + "input_embeds": nn.spec.Tensor([1, "seq_len", d], "float32"), + "logit_positions": nn.spec.Tensor(["batch_size"], "int32"), + "paged_kv_cache": nn.spec.Object(object_type=PagedKVCache), + **curved, **units, **replay, "$": packed, + }, + "drowse_attention_rows": {**rows, "$": {"param_mode": "none", "effect_mode": "none"}}, + "drowse_head_write_grams": {"$": packed}, + "drowse_verify_block_sites": { + "input_embeds": nn.spec.Tensor([1, "seq_len", d], "float32"), + "logit_positions": nn.spec.Tensor(["batch_size"], "int32"), + "paged_kv_cache": nn.spec.Object(object_type=PagedKVCache), + **units, "$": packed, + }, + **env.drowse_reads.readout_spec(model), + **env.drowse_reads.unit_read_spec(model), + } + return nn.spec.ModuleSpec.from_raw(raw, model) + + def new_cache(self): + shape = self.env.tvm.runtime.ShapeTuple + cache = self.vm["create_tir_paged_kv_cache"]( + shape([1]), shape([self.context]), shape([self.context]), shape([16]), shape([0]) + ) + self.add_sequence(cache, 0) + return cache + + def embed(self, ids): + tvm = self.env.tvm + rows = self.vm["embed"](tvm.runtime.tensor(np.asarray(ids, np.int32)), self.params) + return rows.numpy().reshape(1, len(ids), self.hidden_size).astype(np.float32) + + def forward_units(self, cache, ids, program_buffers, *, prefill: bool, affine=None): + tvm = self.env.tvm + meta, coeff, active, grams = program_buffers + embeds = self.embed(ids) + self.begin_forward(cache, tvm.runtime.ShapeTuple([0]), tvm.runtime.ShapeTuple([len(ids)])) + curve = [tvm.runtime.tensor((affine or {}).get(name, value)) + for name, value in self.curve_zeros.items()] + units = [tvm.runtime.tensor(v) for v in (meta, coeff, active, grams)] + if prefill: + out = self.vm["drowse_units_batch_prefill"]( + tvm.runtime.tensor(embeds), tvm.runtime.tensor(np.asarray([len(ids) - 1], np.int32)), + cache, *curve, *units, self.params, + ) + else: + out = self.vm["drowse_units_batch_decode"]( + tvm.runtime.tensor(embeds), cache, *curve, *units, self.params + ) + self.end_forward(cache) + logits = out[0].numpy().reshape(-1)[: self.vocab] + return logits, out[4].numpy(), out[5].numpy() + + def forward_sites(self, cache, ids, program_buffers): + tvm = self.env.tvm + meta, coeff, active, grams = program_buffers + embeds = self.embed(ids) + self.begin_forward(cache, tvm.runtime.ShapeTuple([0]), tvm.runtime.ShapeTuple([len(ids)])) + out = self.vm["drowse_verify_block_sites"]( + tvm.runtime.tensor(embeds), tvm.runtime.tensor(np.asarray([len(ids) - 1], np.int32)), cache, + *[tvm.runtime.tensor(v) for v in (meta, coeff, active, grams)], self.params, + ) + self.end_forward(cache) + names = ("block_in", "z", "attn_o", "mid", "act", "mlp_o", "out") + sites = {name: np.stack([out[1 + layer * 7 + k].numpy()[0] for layer in range(self.num_layers)]) + for k, name in enumerate(names)} + return out[0].numpy().reshape(-1)[: self.vocab], sites + + + # ------------------------------------------------------------------ replay (B1 §2.3, §6) --- + + def head_grams(self) -> np.ndarray: + return self.vm["drowse_head_write_grams"](self.params).numpy() + + def replay_carry(self, rows: int, tokens: int) -> dict: + """A fresh replay's threaded buffers: activity state (value 0, row −1, rank −1), traces + `[32, rows]`, population and pattern keys `[8, KV, tokens, hd]` (sized to the replay, as + the bridge sizes them).""" + tvm, du = self.env.tvm, self.env.drowse_units + block, L = self.block, self.num_layers + f, h = block["d_ff"], block["n_heads"] + state = np.zeros((L, 3 * f + 3 * h), np.float32) + state[:, f: 3 * f] = -1 + state[:, 3 * f + h:] = -1 + arrays = { + "state": state, + "traces": np.zeros((du.UNIT_MAX_ACTIVITY_TRACES, rows), np.float32), + "population": np.zeros((L, f + h), np.float32), + "keys": np.zeros((du.UNIT_MAX_PATTERN_LAYERS, block["n_kv_heads"], tokens, + block["head_dim"]), np.float32), + } + return {name: tvm.runtime.tensor(value) for name, value in arrays.items()} + + def replay_forward(self, cache, ids, program_buffers, meta, scales, grams, carry, affine=None): + """One `drowse_replay_batch_prefill` forward continuing `cache` (positions follow the + cache's length); the threaded buffers come back in `carry`.""" + tvm = self.env.tvm + embeds = self.embed(ids) + self.begin_forward(cache, tvm.runtime.ShapeTuple([0]), tvm.runtime.ShapeTuple([len(ids)])) + curve = [tvm.runtime.tensor((affine or {}).get(name, value)) + for name, value in self.curve_zeros.items()] + units = [tvm.runtime.tensor(v) for v in program_buffers] + out = self.vm["drowse_replay_batch_prefill"]( + tvm.runtime.tensor(embeds), tvm.runtime.tensor(np.asarray([len(ids) - 1], np.int32)), + cache, *curve, *units, tvm.runtime.tensor(meta), scales, grams, + carry["state"], carry["traces"], carry["population"], carry["keys"], self.params, + ) + self.end_forward(cache) + return { + "logits": out[0].numpy().reshape(-1)[: self.vocab], + "measurements": out[2].numpy(), + "jlens": out[4].numpy(), + "taps": out[5].numpy(), + "anatomy": out[6].numpy(), + "pattern_q": out[11], + "carry": {"state": out[7], "traces": out[8], "population": out[9], "keys": out[10]}, + } + + def attention_rows(self, keys, queries, rows_meta: np.ndarray) -> np.ndarray: + tvm = self.env.tvm + return self.vm["drowse_attention_rows"](keys, queries, tvm.runtime.tensor(rows_meta)).numpy() + + +def strip_scheduled_kernels(module, tvm, strip): + """Serialize only the kernels that carry GPU thread bindings (the drowse kernels); the + upstream graph's unscheduled kernels go through MLC's llvm pipeline untouched.""" + tir = tvm.tirx + for var in list(module.get_global_vars()): + function = module[var] + if not isinstance(function, tir.PrimFunc): + continue + bound = [] + tir.stmt_functor.post_order_visit( + function.body, + lambda node: bound.append(node) + if isinstance(node, tir.For) and node.kind == tir.ForKind.THREAD_BINDING else None, + ) + if bound: + module.update_func(var, strip(tvm.IRModule({var: function}), tvm)[var]) + return module + + +def install_block_sites_forward(model_class, env) -> None: + """A verification-only entry point: one forward through `drowse_block` with unit sites that + also capture every site tensor (never compiled into a library).""" + if getattr(model_class, "drowse_verify_block_sites", None) is not None: + return + UnitSites, op = env.UnitSites, env.op + + class CaptureSites(UnitSites): + def __init__(self, *args): + super().__init__(*args) + self.rows = {} + + def head(self, z, layer_id): + z = super().head(z, layer_id) + self.rows[(layer_id, "z")] = z + return z + + def mid(self, h_mid, layer_id): + self.rows[(layer_id, "mid")] = h_mid + + def neuron(self, act, layer_id): + act = super().neuron(act, layer_id) + self.rows[(layer_id, "act")] = act + return act + + def tap(self, z, attn_o, act, layer_id): + super().tap(z, attn_o, act, layer_id) + self.rows[(layer_id, "attn_o")] = attn_o + + def mlp(self, mlp_o, layer_id): + self.rows[(layer_id, "mlp_o")] = mlp_o + + def drowse_verify_block_sites(self, input_embeds, logit_positions, paged_kv_cache, unit_meta, + unit_coeff, unit_active, tap_grams): + spec = self._drowse_block_spec() + b, s, _ = input_embeds.shape + sites = CaptureSites(self.num_hidden_layers, spec["head_dim"], + paged_kv_cache.get_query_positions(b * s), unit_meta, unit_coeff, + unit_active, tap_grams, spec["sandwich"], spec["rms_eps"]) + hidden = self.model._drowse_prepare_inputs(input_embeds) + captured = [] + for layer_id, layer in enumerate(self.model.layers): + block_in = hidden + hidden = layer.drowse_block(hidden, paged_kv_cache, layer_id, sites) + captured += [block_in, sites.rows[(layer_id, "z")], sites.rows[(layer_id, "attn_o")], + sites.rows[(layer_id, "mid")], sites.rows[(layer_id, "act")], + sites.rows[(layer_id, "mlp_o")], hidden] + last = op.take(self.model.norm(hidden), logit_positions, axis=1) + return (self._get_logits(last), *captured) + + model_class.drowse_verify_block_sites = drowse_verify_block_sites + + +def load_tensor_cache(directory: Path) -> dict[str, np.ndarray]: + """Every tensor as the runtime decodes it: `f32-to-bf16` records (production q4f32_1 scales + and norms) widen their stored bf16 bits to float32.""" + cache = json.loads((directory / "tensor-cache.json").read_text()) + tensors = {} + for shard in cache["records"]: + data = (directory / shard["dataPath"]).read_bytes() + for record in shard["records"]: + chunk = data[record["byteOffset"]: record["byteOffset"] + record["nbytes"]] + encoding = record.get("format", "raw") + if encoding not in ("raw", "f32-to-bf16"): + raise SystemExit(f"{record['name']}: unsupported tensor encoding {encoding}") + if encoding == "f32-to-bf16" and record["dtype"] == "float32": + bits = np.frombuffer(chunk, dtype=" np.ndarray: + name = self.prefix + name + if name + ".weight" in self.tensors: + return self.tensors[name + ".weight"].astype(np.float64) + weight, scale = self.tensors[name + ".q_weight"], self.tensors[name + ".q_scale"] + shifts = np.arange(8, dtype=np.uint32) * 4 + codes = ((weight[:, :, None] >> shifts) & 0xF).reshape(weight.shape[0], -1).astype(np.float64) + return (codes - 7) * np.repeat(scale.astype(np.float64), 32, axis=1) + + def gain(self, layer: int, which: str) -> np.ndarray: + sandwich = self.block["sandwich"] + names = {"ai": "input_layernorm", + "ao": "post_attention_layernorm" if sandwich else None, + "mi": "pre_feedforward_layernorm" if sandwich else "post_attention_layernorm", + "mo": "post_feedforward_layernorm" if sandwich else None} + if names[which] is None: + return np.ones(self.get("embed_tokens").shape[1]) + return self.get(f"layers.{layer}.{names[which]}") + + def layer(self, layer: int) -> dict: + b, p = self.block, f"layers.{layer}." + hd, heads, kv, d_ff = b["head_dim"], b["n_heads"], b["n_kv_heads"], b["d_ff"] + if self.prefix + p + "self_attn.c_attn.weight" in self.tensors or \ + self.prefix + p + "self_attn.c_attn.q_weight" in self.tensors: + qkv = self.get(p + "self_attn.c_attn") + q, k, v = qkv[: heads * hd], qkv[heads * hd: (heads + kv) * hd], qkv[(heads + kv) * hd:] + else: + q, k, v = (self.get(p + f"self_attn.{r}_proj") for r in "qkv") + gate_up = self.get(p + "mlp.gate_up_proj") + return {"q": q, "k": k, "v": v, "o": self.get(p + "self_attn.o_proj"), + "gate": gate_up[:d_ff], "up": gate_up[d_ff:], "down": self.get(p + "mlp.down_proj")} + + def writes(self, layer: int) -> np.ndarray: + """`[d_ff, d]`: `s·γ_mo ⊙ W_down[:, n]` per neuron.""" + scale = float(self.block.get("residual_scale", 1.0)) + return (scale * self.gain(layer, "mo")[:, None] * self.layer(layer)["down"]).T + + def reads(self, layer: int): + gain = self.gain(layer, "mi") + w = self.layer(layer) + a, b = w["gate"] * gain, w["up"] * gain + return (a / np.maximum(np.linalg.norm(a, axis=1, keepdims=True), 1e-12), + b / np.maximum(np.linalg.norm(b, axis=1, keepdims=True), 1e-12)) + + def head_write(self, layer: int, head: int) -> np.ndarray: + hd = self.block["head_dim"] + return self.gain(layer, "ao")[:, None] * self.layer(layer)["o"][:, head * hd:(head + 1) * hd] + + @property + def embedding(self) -> np.ndarray: + return self.get("embed_tokens") + + @property + def final_gain(self) -> np.ndarray: + return self.get("norm") + + +class Device: + """Calls into a units library's static reads (fp32 in, numpy out).""" + + def __init__(self, vm): + self.vm, self.tvm = vm, vm.env.tvm + + def __call__(self, name: str, *args, packed: bool = True): + arrays = [self.tvm.runtime.tensor(np.ascontiguousarray(a)) for a in args] + out = self.vm.vm[name](*arrays, self.vm.params) if packed else self.vm.vm[name](*arrays) + if hasattr(out, "numpy"): + return out.numpy() + return [o.numpy() for o in out] + + def topk(self, x: np.ndarray, k: int): + n = x.shape[0] + values, indices = self("drowse_topk", x.astype(np.float32), np.zeros((n, k), np.float32), + np.zeros((n, k), np.int32), packed=False) + return values, indices + + def chan(self, rows: np.ndarray, chunk: int = 37): + """Mean and centred sum of squares of `rows` through repeated merges (chunked, so the + merge rule itself is exercised).""" + width = rows.shape[1] + count, mean, m2 = 0, np.zeros(width, np.float32), np.zeros(width, np.float32) + for start in range(0, rows.shape[0], chunk): + part = rows[start:start + chunk].astype(np.float32) + mean, m2 = self("drowse_chan_merge", np.array([count], np.float32), mean, m2, part, + packed=False) + count += part.shape[0] + return count, mean, m2 diff --git a/browser-runtime/forks/verify-mlc-hook.py b/browser-runtime/forks/verify-mlc-hook.py index 61bfd2a..c513a06 100644 --- a/browser-runtime/forks/verify-mlc-hook.py +++ b/browser-runtime/forks/verify-mlc-hook.py @@ -1,7 +1,6 @@ #!/usr/bin/env python3 import argparse -import json import os import subprocess import sys @@ -60,11 +59,6 @@ def main() -> None: raise SystemExit(f"exact MLC/TVM toolchain is unavailable: {error}") from error require_llvm(tvm) - if args.units_fixtures is not None: - verify_units_fixtures(args, tvm, relax, nn, op) - sys.stdout.flush() - os._exit(0) - if args.export_only is not None: model, label = create_tiny_model( args.export_only, @@ -508,7 +502,7 @@ def forward(self): descriptor = vm["forward"]().numpy() if descriptor.shape != (67,): raise SystemExit("Drowse hook profile descriptor (schema 4) has the wrong length") - np.testing.assert_array_equal(descriptor[:7], [0x53414B4C, 4, 4, 5, 4, 2, 4]) + np.testing.assert_array_equal(descriptor[:7], [0x53414B4C, 4, 5, 6, 5, 2, 4]) np.testing.assert_array_equal(descriptor[28:32], [2, 8, 16384, 0]) np.testing.assert_array_equal(descriptor[-4:], [256, 0, 8, 16]) @@ -539,6 +533,7 @@ def forward( residual, affine_active, affine_basis, + affine_read, affine_neutral, affine_target, affine_along, @@ -553,6 +548,7 @@ def forward( 0, affine_active, affine_basis, + affine_read, affine_neutral, affine_target, affine_along, @@ -569,6 +565,7 @@ def forward( "residual": spec.Tensor([1, 1, hidden_size], "float32"), "affine_active": spec.Tensor([1, groups], "float32"), "affine_basis": spec.Tensor([1, groups, rank, hidden_size], "float32"), + "affine_read": spec.Tensor([1, groups, rank, hidden_size], "float32"), "affine_neutral": spec.Tensor([1, groups, hidden_size], "float32"), "affine_target": spec.Tensor([1, groups, rank], "float32"), "affine_along": spec.Tensor([1, groups], "float32"), @@ -622,7 +619,7 @@ def forward( probe_threshold, ] residual, measurements = structured_vm["forward"]( - *(tvm_tensor(value, device=tvm.cpu()) for value in values) + *(tvm_tensor(value, device=tvm.cpu()) for value in with_reads(values)) ) np.testing.assert_allclose( residual.numpy().reshape(hidden_size), [0.6, 1.2], rtol=1e-6, atol=1e-7 @@ -637,13 +634,13 @@ def forward( blocked_threshold[0, 3] = 1.3 blocked_values[10] = blocked_threshold _, blocked_measurements = structured_vm["forward"]( - *(tvm_tensor(value, device=tvm.cpu()) for value in blocked_values) + *(tvm_tensor(value, device=tvm.cpu()) for value in with_reads(blocked_values)) ) np.testing.assert_array_equal(blocked_measurements.numpy()[3:4], [0.0]) inactive_values = list(values) inactive_values[1] = np.zeros((1, groups), dtype="float32") inactive_residual, _ = structured_vm["forward"]( - *(tvm_tensor(value, device=tvm.cpu()) for value in inactive_values) + *(tvm_tensor(value, device=tvm.cpu()) for value in with_reads(inactive_values)) ) np.testing.assert_allclose( inactive_residual.numpy().reshape(hidden_size), @@ -651,6 +648,37 @@ def forward( rtol=1e-6, atol=1e-7, ) + # Hook ABI v6: a typed frame reads with its read rows and writes along its basis rows. The + # TS CPU reference's case (structured-hook-program.test.mjs): basis [1, 1], read [0.5, 0.5], + # a full ablation of [3, 1] is [1, -1]; a shared row would give [-1, -3]. + typed_basis = np.zeros_like(affine_basis) + typed_basis[0, 0, 0] = [1, 1] + typed_read = np.zeros_like(affine_basis) + typed_read[0, 0, 0] = [0.5, 0.5] + typed_along = np.zeros_like(affine_along) + typed_along[0, 0] = 1 + typed_kappa = np.zeros_like(affine_kappa) + typed_kappa[0, 0, 0] = 1 + typed_values = [ + np.asarray([[[3.0, 1.0]]], dtype="float32"), + affine_active, + typed_basis, + typed_read, + affine_neutral, + np.zeros_like(affine_target), + typed_along, + typed_kappa, + probe_kind, + probe_direction, + probe_bias, + probe_threshold, + ] + typed_residual, _ = structured_vm["forward"]( + *(tvm_tensor(value, device=tvm.cpu()) for value in typed_values) + ) + np.testing.assert_allclose( + typed_residual.numpy().reshape(hidden_size), [1.0, -1.0], rtol=1e-6, atol=1e-6 + ) class CurvedModule(nn.Module): def __init__(self, decode=False): @@ -662,6 +690,7 @@ def forward( residual, affine_active, affine_basis, + affine_read, affine_neutral, affine_target, affine_along, @@ -676,6 +705,7 @@ def forward( curve_embed_dim, curve_node_count, curve_basis, + curve_read, curve_neutral, curve_domain_kind, curve_node_parameters, @@ -722,6 +752,7 @@ def forward( self.decode, affine_active, affine_basis, + affine_read, affine_neutral, affine_target, affine_along, @@ -731,6 +762,7 @@ def forward( probe_bias, probe_threshold, curve_basis, + curve_read, curve_neutral, curve_domain_kind, curve_parameters, @@ -741,6 +773,7 @@ def forward( "residual": spec.Tensor([1, 1, hidden_size], "float32"), "affine_active": spec.Tensor([1, groups], "float32"), "affine_basis": spec.Tensor([1, groups, rank, hidden_size], "float32"), + "affine_read": spec.Tensor([1, groups, rank, hidden_size], "float32"), "affine_neutral": spec.Tensor([1, groups, hidden_size], "float32"), "affine_target": spec.Tensor([1, groups, rank], "float32"), "affine_along": spec.Tensor([1, groups], "float32"), @@ -755,6 +788,7 @@ def forward( "curve_embed_dim": spec.Tensor([1, curves], "uint32"), "curve_node_count": spec.Tensor([1, curves], "uint32"), "curve_basis": spec.Tensor([1, curves, rank, hidden_size], "float32"), + "curve_read": spec.Tensor([1, curves, rank, hidden_size], "float32"), "curve_neutral": spec.Tensor([1, curves, hidden_size], "float32"), "curve_domain_kind": spec.Tensor([1, curves], "uint32"), "curve_node_parameters": spec.Tensor([1, curves, nodes, embed], "float32"), @@ -850,11 +884,29 @@ def forward( curve_feet, ] curved, curve_measurements, next_foot = curved_vm["forward"]( - *(tvm_tensor(value, device=tvm.cpu()) for value in curve_values) + *(tvm_tensor(value, device=tvm.cpu()) for value in with_reads(curve_values)) ) np.testing.assert_allclose( curved.numpy().reshape(hidden_size), [0.6, 0.2], rtol=3e-3, atol=3e-4 ) + # Hook ABI v6, typed curves: map the hidden space by A (write rows b -> A b, read rows + # r -> A^-T r, residual h -> A h). The coordinates are unchanged, so the curved residual is + # A times the one above (the norm cap does not bind here) and the foot is the same. + shear = np.asarray([[1.0, 1.0], [0.0, 1.0]], dtype="float32") + typed_curve_values = with_reads(curve_values) + typed_curve_values[0] = curve_values[0] @ shear.T + typed_curve_values[17] = curve_basis @ shear.T + typed_curve_values[18] = curve_basis @ np.linalg.inv(shear) + typed_curved, _, typed_foot = curved_vm["forward"]( + *(tvm_tensor(value, device=tvm.cpu()) for value in typed_curve_values) + ) + np.testing.assert_allclose( + typed_curved.numpy().reshape(hidden_size), + curved.numpy().reshape(hidden_size) @ shear.T, + rtol=1e-4, + atol=1e-5, + ) + np.testing.assert_allclose(typed_foot.numpy(), next_foot.numpy(), rtol=1e-4, atol=1e-5) np.testing.assert_allclose( curve_measurements.numpy()[:2], [0.6, 0.0], rtol=3e-3, atol=3e-4 ) @@ -890,7 +942,7 @@ def forward( periodic_values[28] = periodic_bounds periodic_values[29] = periodic_axes periodic, _, periodic_foot = curved_vm["forward"]( - *(tvm_tensor(value, device=tvm.cpu()) for value in periodic_values) + *(tvm_tensor(value, device=tvm.cpu()) for value in with_reads(periodic_values)) ) np.testing.assert_allclose( periodic.numpy().reshape(hidden_size), [0.0, 1.0], rtol=3e-3, atol=3e-4 @@ -943,7 +995,7 @@ def forward( sphere_values[29] = sphere_axis_periodic sphere_values[30] = sphere_periods sphere, _, sphere_foot = curved_vm["forward"]( - *(tvm_tensor(value, device=tvm.cpu()) for value in sphere_values) + *(tvm_tensor(value, device=tvm.cpu()) for value in with_reads(sphere_values)) ) np.testing.assert_allclose( sphere.numpy().reshape(hidden_size), [0.0, 1.0], rtol=3e-3, atol=3e-4 @@ -961,7 +1013,7 @@ def forward( curve_values[11] = np.zeros((1, curves), dtype="float32") curve_values[-1] = np.full((1, curves, intrinsic), 0.4, dtype="float32") inactive, _, inactive_foot = decode_vm["forward"]( - *(tvm_tensor(value, device=tvm.cpu()) for value in curve_values) + *(tvm_tensor(value, device=tvm.cpu()) for value in with_reads(curve_values)) ) np.testing.assert_allclose( inactive.numpy().reshape(hidden_size), [0.2, 0.3], rtol=1e-6, atol=1e-7 @@ -1296,53 +1348,6 @@ def create_tiny_model( ) -def verify_units_fixtures(args, tvm, relax, nn, op) -> None: - """Hook ABI v5 on the C TVM VM: the units goldens over build-units-fixtures.py models.""" - import importlib.util - import types as pytypes - - from mlc_llm import compiler_pass as _compiler_pass # noqa: F401 (registers the pipeline) - from mlc_llm import op as op_ext - from mlc_llm.interface.compiler_flags import IPCAllReduceStrategyType - from mlc_llm.model import drowse_reads, drowse_units - from mlc_llm.model.drowse_hooks import structured_curve_program_spec - from mlc_llm.model.gemma3.gemma3_model import Gemma3Config, Gemma3ForCausalLM - from mlc_llm.model.qwen3.qwen3_model import Qwen3Config, Qwen3LMHeadModel - from mlc_llm.quantization import QUANTIZATION, make_quantization_functions - - import units_goldens - - compiler_path = Path(__file__).resolve().with_name("compile-tiny-webgpu.py") - compiler_spec = importlib.util.spec_from_file_location("drowse_compile_tiny", compiler_path) - compiler = importlib.util.module_from_spec(compiler_spec) - compiler_spec.loader.exec_module(compiler) - env = pytypes.SimpleNamespace( - tvm=tvm, relax=relax, nn=nn, op=op, - models={"qwen3": (Qwen3Config, Qwen3LMHeadModel), - "gemma3_text": (Gemma3Config, Gemma3ForCausalLM)}, - QUANTIZATION=QUANTIZATION, make_quantization_functions=make_quantization_functions, - strip_gpu_thread_bindings=strip_gpu_thread_bindings, - prepare_parameters=compiler.prepare_parameters, create_metadata=compiler.create_metadata, - IPCAllReduceStrategyType=IPCAllReduceStrategyType, - structured_curve_program_spec=structured_curve_program_spec, - unit_program_spec=drowse_units.unit_program_spec, - unit_meta_layout=drowse_units.unit_meta_layout, - unit_coeff_layout=drowse_units.unit_coeff_layout, - UnitSites=drowse_units.UnitSites, - drowse_units=drowse_units, - drowse_reads=drowse_reads, - UNIT_MAX_GROUPS=drowse_units.UNIT_MAX_GROUPS, - UNIT_MAX_HEAD_TAPS=drowse_units.UNIT_MAX_HEAD_TAPS, - ) - op_ext.enable(target=tvm.target.Target("llvm"), flashinfer=False, faster_transformer=False, - cutlass=False) - results = units_goldens.verify(env, args.units_fixtures.resolve(strict=True), - args.goldens.resolve(strict=True)) - print("units goldens (block-sites, unit-ablation, unit-probes, attention-patterns, " - "token-anatomy, unit-activity) passed on the C TVM VM: " - + json.dumps(results, sort_keys=True)) - - def verify_isolated_model_exports(args) -> None: for architecture in ("qwen3", "llama", "gemma3_text"): subprocess.run( @@ -1376,26 +1381,24 @@ def verify_isolated_readout_goldens(args) -> None: def parse_args() -> argparse.Namespace: - repository_root = Path(__file__).resolve().parents[2] parser = argparse.ArgumentParser() parser.add_argument("--mlc-repository", required=True, type=Path) parser.add_argument("--tvm-repository", required=True, type=Path) parser.add_argument("--export-only", choices=["qwen3", "llama", "gemma3_text"]) parser.add_argument("--readout-only", action="store_true") - parser.add_argument( - "--units-fixtures", - type=Path, - help="directory of build-units-fixtures.py models (units--): check them " - "against the block-sites, unit-ablation and unit-probes goldens on the C TVM VM", - ) - parser.add_argument( - "--goldens", - type=Path, - default=repository_root / "drowse/tests/fixtures/browser", - ) return parser.parse_args() +def with_reads(values: list) -> list: + """Hook ABI v6 inputs from a v5-ordered case list: each read input copies its basis + (these cases' rows are orthonormal, so they are their own duals).""" + result = list(values) + result.insert(3, values[2]) + if len(values) > 11: + result.insert(18, values[16]) + return result + + def strip_gpu_thread_bindings(module, tvm): """Execute workgroup phases serially on CPU, retaining per-lane local state.""" tir = tvm.tirx diff --git a/browser-runtime/forks/verify-production-library.py b/browser-runtime/forks/verify-production-library.py index 9e326a0..549c0a7 100644 --- a/browser-runtime/forks/verify-production-library.py +++ b/browser-runtime/forks/verify-production-library.py @@ -6,7 +6,7 @@ - The descriptor (schema 4) the model's `drowse_hook_profile` returns, built for the C TVM VM and written to the report, for `expectedHookProfileDescriptor` (C0) to check against the lock's block spec. -- Units models (`standard-v4`), with `--parity`: one forward of the parity input through +- Units models (`standard-v5`), with `--parity`: one forward of the parity input through `drowse_block` on the C TVM VM against PyTorch on the dequantized MLC tensors (`mlc_q4_torch`): the per-layer relative error of `act`, `z`, `mid` and `out` and of the last position's logits at most 1% (B1 §4.3, the q4 parity gate's measure); greedy tokens through the units pair equal @@ -105,7 +105,7 @@ def main() -> None: failures: list[str] = [] if args.parity: if arch not in UNIT_ARCHITECTURES: - raise SystemExit(f"{arch} attests standard-v4-residual: no block sites to compare") + raise SystemExit(f"{arch} attests standard-v5-residual: no block sites to compare") parity_input = json.loads(args.input.read_text()) report["checks"].update(parity(env, model_dir, args.input, parity_input, args.greedy_tokens, args.reference_python, failures)) @@ -141,7 +141,7 @@ def parse_args() -> argparse.Namespace: def environment(tvm, relax, nn, op): - """What `units_goldens.FixtureVM` needs (the same namespace verify-mlc-hook.py builds).""" + """What `units_vm.UnitsVM` needs.""" from mlc_llm import compiler_pass as _compiler_pass # noqa: F401 (registers the pipeline) from mlc_llm import op as op_ext from mlc_llm.interface.compiler_flags import IPCAllReduceStrategyType @@ -203,18 +203,17 @@ def parity(env, model_dir: Path, input_path: Path, parity_input: dict, greedy_to import subprocess import tempfile - import units_goldens as ug - from static_reads import Device + from units_vm import Device, UnitProgram, UnitsVM, load_tensor_cache ids = [int(value) for value in parity_input["inputIds"]] checks: dict = {} timer = time.time() - vm = ug.FixtureVM(env, model_dir) + vm = UnitsVM(env, model_dir) checks["cvmBuildSeconds"] = round(time.time() - timer, 1) block, layers = vm.block, vm.num_layers caps = {"groups": env.UNIT_MAX_GROUPS, "head_taps": env.UNIT_MAX_HEAD_TAPS} - empty = ug.UnitProgram(env.unit_meta_layout(layers), env.unit_coeff_layout(block["head_dim"]), + empty = UnitProgram(env.unit_meta_layout(layers), env.unit_coeff_layout(block["head_dim"]), layers, block["head_dim"], caps).buffers([]) timer = time.time() vm_logits, sites = vm.forward_sites(vm.new_cache(), ids, empty) @@ -256,7 +255,7 @@ def parity(env, model_dir: Path, input_path: Path, parity_input: dict, greedy_to failures.append(f"greedy tokens differ: cvm {vm_greedy}, torch {torch_greedy}") timer = time.time() - tensors = ug.load_tensor_cache(model_dir) + tensors = load_tensor_cache(model_dir) weights = ProductionWeights(tensors, block, layers) checks["staticReads"] = static_reads(Device(vm), weights, sites, failures) checks["staticReads"]["seconds"] = round(time.time() - timer, 1) @@ -338,13 +337,13 @@ def cvm_greedy(vm, ids: list[int], empty, count: int, eos_ids: set) -> list[int] # ------------------------------------------------------------------------- static reads --- class ProductionWeights: - """`static_reads.Weights` over a production tensor cache, one layer resident at a time and the + """`units_vm.Weights` over a production tensor cache, one layer resident at a time and the vocabulary dequantized in chunks (a 4B model's embedding is 5.4 GB in fp64).""" CHUNK = 16384 def __init__(self, tensors: dict, block: dict, num_layers: int): - from static_reads import Weights + from units_vm import Weights self.inner = Weights(tensors, block, num_layers) self.tensors, self.block, self.prefix = tensors, block, self.inner.prefix diff --git a/browser-runtime/forks/verify-webgpu-kernel-goldens.mjs b/browser-runtime/forks/verify-webgpu-kernel-goldens.mjs index f0c28d4..d0b4fe5 100644 --- a/browser-runtime/forks/verify-webgpu-kernel-goldens.mjs +++ b/browser-runtime/forks/verify-webgpu-kernel-goldens.mjs @@ -190,6 +190,8 @@ try { active = data(4, (i) => (mode === "inactive" ? 0 : i === 2 ? 0 : 1)), along = data(4, (i) => (i - 1.5) * 0.1), basis = data(4 * 8 * h, (i) => Math.sin(i * 0.27) / Math.sqrt(h)), + // Hook ABI v6: coordinates through the read rows, distinct from the write rows. + read = data(4 * 8 * h, (i) => Math.cos(i * 0.31) / Math.sqrt(h)), neutral = data(4 * h, (i) => Math.cos(i * 0.19) * 0.1), target = data(4 * 8, (i) => Math.sin(i * 0.17)), kappa = data(4 * 8, (i) => @@ -212,7 +214,7 @@ try { for (let j = 0; j < h; j++) dot += (expected[tok * h + j] - neutral[g * h + j]) * - basis[(g * 8 + r) * h + j]; + read[(g * 8 + r) * h + j]; delta[r] = target[g * 8 + r] - kappa[g * 8 + r] * dot; } for (let j = 0; j < h; j++) { @@ -229,10 +231,10 @@ try { active_ptr: active, along_ptr: along, basis_ptr: basis, + read_rows_ptr: read, neutral_ptr: neutral, target_ptr: target, kappa_ptr: kappa, - output_ptr: new Float32Array(b * t * h), }, b * t, ); @@ -242,7 +244,7 @@ try { t, mode, maxError: compare( - output.output_ptr, + output.residual_ptr, expected, entry.file + mode, mode === "inactive" ? 0 : 2e-5, diff --git a/browser-runtime/forks/web-llm-drowse.patch b/browser-runtime/forks/web-llm-drowse.patch index f27ffa9..ff24e76 100644 --- a/browser-runtime/forks/web-llm-drowse.patch +++ b/browser-runtime/forks/web-llm-drowse.patch @@ -1,5 +1,5 @@ diff --git a/package-lock.json b/package-lock.json -index 0070bde..ea2a000 100644 +index 0070bde..55a8802 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,21 +1,21 @@ @@ -7,7 +7,7 @@ index 0070bde..ea2a000 100644 - "name": "@mlc-ai/web-llm", - "version": "0.2.84", + "name": "@drowse/web-llm", -+ "version": "0.2.84-drowse.49", ++ "version": "0.2.84-drowse.50", "lockfileVersion": 3, "requires": true, "packages": { @@ -15,7 +15,7 @@ index 0070bde..ea2a000 100644 - "name": "@mlc-ai/web-llm", - "version": "0.2.84", + "name": "@drowse/web-llm", -+ "version": "0.2.84-drowse.49", ++ "version": "0.2.84-drowse.50", "license": "Apache-2.0", "dependencies": { - "loglevel": "^1.9.1" @@ -170,7 +170,7 @@ index 0070bde..ea2a000 100644 "version": "9.3.0", "resolved": "https://registry.npmjs.org/v8-to-istanbul/-/v8-to-istanbul-9.3.0.tgz", diff --git a/package.json b/package.json -index cabfc3d..06cec60 100644 +index cabfc3d..a05f189 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,12 @@ @@ -178,7 +178,7 @@ index cabfc3d..06cec60 100644 - "name": "@mlc-ai/web-llm", - "version": "0.2.84", + "name": "@drowse/web-llm", -+ "version": "0.2.84-drowse.49", ++ "version": "0.2.84-drowse.50", "description": "Hardware accelerated language model chats on browsers", "main": "lib/index.js", "types": "lib/index.d.ts", @@ -803,11 +803,11 @@ index 122e933..83964fe 100644 const iterEnd = includeLastMsg ? input.length : input.length - 1; diff --git a/src/drowse.ts b/src/drowse.ts new file mode 100644 -index 0000000..bc02db8 +index 0000000..5584035 --- /dev/null +++ b/src/drowse.ts -@@ -0,0 +1,1774 @@ -+export const DROWSE_HOOK_ABI = "block-sites-v5" as const; +@@ -0,0 +1,1780 @@ ++export const DROWSE_HOOK_ABI = "block-sites-v6" as const; +export const DROWSE_EXACT_READOUT_ABI = "exact-readout-v2" as const; + +export type DrowsePositionSpan = [number, number]; @@ -930,12 +930,12 @@ index 0000000..bc02db8 + saeTopFeatures?: DrowseSaeTopFeatureReadout; +} + -+export type DrowseStructuredProfileId = "standard-v4" | "standard-v4-residual"; ++export type DrowseStructuredProfileId = "standard-v5" | "standard-v5-residual"; + +export interface DrowseStructuredHookProfile { + schemaVersion: 4; + id: DrowseStructuredProfileId; -+ /** 1 when the library compiles the in-block unit sites (`standard-v4`). */ ++ /** 1 when the library compiles the in-block unit sites (`standard-v5`). */ + unitSites: 0 | 1; + /** The library's whole schema-4 descriptor, for the caller's element-by-element attestation + * against the model's lock entry (block spec, context, capacities). */ @@ -971,7 +971,7 @@ index 0000000..bc02db8 + maxSaeFeaturesPerChunk: number; +} + -+export const DROWSE_STRUCTURED_HOOK_FORMAT = "drowse-structured-v4" as const; ++export const DROWSE_STRUCTURED_HOOK_FORMAT = "drowse-structured-v5" as const; +export type DrowseStructuredHookFormat = typeof DROWSE_STRUCTURED_HOOK_FORMAT; +export const DROWSE_STRUCTURED_MAX_AFFINE_GROUPS = 4; +export const DROWSE_STRUCTURED_MAX_RANK = 8; @@ -993,15 +993,15 @@ index 0000000..bc02db8 +export const DROWSE_STRUCTURED_GEOMETRY_KERNEL_STORAGE_BINDINGS = 8; +export const DROWSE_STRUCTURED_REQUIRED_MAX_STORAGE_BUFFERS_PER_SHADER_STAGE = 8; +export const DROWSE_STRUCTURED_PROFILE_SCHEMA_VERSION = 4 as const; -+export const DROWSE_STRUCTURED_PROFILE_ID = "standard-v4" as const; ++export const DROWSE_STRUCTURED_PROFILE_ID = "standard-v5" as const; +export const DROWSE_STRUCTURED_RESIDUAL_PROFILE_ID = -+ "standard-v4-residual" as const; ++ "standard-v5-residual" as const; +export const DROWSE_STRUCTURED_PROFILE_MAGIC = 0x53414b4c; +/** Descriptor schema 4: v3's 31 fields, then the block spec and unit capacities (HOOK_ABI.md §6). */ +export const DROWSE_STRUCTURED_PROFILE_DESCRIPTOR_LENGTH = 67; -+export const DROWSE_HOOK_PROFILE_ID_FIELD = 4 as const; -+export const DROWSE_HOOK_ABI_VERSION = 5 as const; -+export const DROWSE_STRUCTURED_FORMAT_VERSION = 4 as const; ++export const DROWSE_HOOK_PROFILE_ID_FIELD = 5 as const; ++export const DROWSE_HOOK_ABI_VERSION = 6 as const; ++export const DROWSE_STRUCTURED_FORMAT_VERSION = 5 as const; +export const DROWSE_EXACT_READOUT_ABI_VERSION = 2 as const; +/** Descriptor indices the bridge itself reads (the rest is attested by the caller). */ +export const DROWSE_DESCRIPTOR_UNIT_SITES = 31; @@ -1013,13 +1013,13 @@ index 0000000..bc02db8 +export const DROWSE_DESCRIPTOR_ANATOMY_STRIDE = 61; +export const DROWSE_DESCRIPTOR_PREFILL_CHUNK_SIZE = 51; +export const DROWSE_DESCRIPTOR_CONTEXT_TOKENS = 66; -+/** Unit capacities of `standard-v4` (B1 §3.1, §3.5). */ ++/** Unit capacities of `standard-v5` (B1 §3.1, §3.5). */ +export const DROWSE_UNIT_MAX_GROUPS = 4; +export const DROWSE_UNIT_MAX_NEURON_ABLATIONS = 256; +export const DROWSE_UNIT_MAX_HEAD_ABLATIONS = 64; +export const DROWSE_UNIT_MAX_TAPS = 64; +export const DROWSE_UNIT_MAX_HEAD_TAPS = 16; -+/** The unit pair every `standard-v4` library exports and every residual library lacks. */ ++/** The unit pair every `standard-v5` library exports and every residual library lacks. */ +export const DROWSE_UNIT_FUNCTIONS = Object.freeze([ + "drowse_units_batch_prefill", + "drowse_units_batch_decode", @@ -1027,7 +1027,7 @@ index 0000000..bc02db8 + "drowse_attention_rows", + "drowse_head_write_grams", +] as const); -+/** Replay capacities of `standard-v4` (B1 §2.3, §6; HOOK_ABI.md §7). */ ++/** Replay capacities of `standard-v5` (B1 §2.3, §6; HOOK_ABI.md §7). */ +export const DROWSE_UNIT_MAX_ACTIVITY_TRACES = 32; +export const DROWSE_UNIT_MAX_ACTIVITY_SPANS = 4; +export const DROWSE_UNIT_MAX_PATTERN_LAYERS = 16; @@ -1153,7 +1153,7 @@ index 0000000..bc02db8 + tensors: Record; +} + -+/** `exact-readout-v2`: every block-sites-v5 library exports these. */ ++/** `exact-readout-v2`: every block-sites-v6 library exports these. */ +export const DROWSE_READOUT_FUNCTIONS = Object.freeze([ + "drowse_embedding_rows", + "drowse_unembedding_rows", @@ -1501,6 +1501,8 @@ index 0000000..bc02db8 + layerCount: number; + affineActive: Uint32Array; + affineBasis: Float32Array; ++ /** Hook ABI v6: the coordinate rows, dual to `affineBasis` (`read · basisᵀ = I`). */ ++ affineRead: Float32Array; + affineNeutral: Float32Array; + affineTarget: Float32Array; + affineAlong: Float32Array; @@ -1515,6 +1517,8 @@ index 0000000..bc02db8 + curveEmbedDim: Uint32Array; + curveNodeCount: Uint32Array; + curveBasis: Float32Array; ++ /** Hook ABI v6: the coordinate rows, dual to `curveBasis`. */ ++ curveRead: Float32Array; + curveNeutral: Float32Array; + curveNodeParameters: Float32Array; + curveRbfWeights: Float32Array; @@ -1563,7 +1567,7 @@ index 0000000..bc02db8 + saeBindingId?: string; + /** Keep each forward's `[L, d]` capture for the host (the measurement bundle's `hidden`). */ + hiddenCapture?: boolean; -+ /** drowse-structured-v4's unit section (B1 §3.1, §3.4): present together or not at all. */ ++ /** drowse-structured-v5's unit section (B1 §3.1, §3.4): present together or not at all. */ + unitMeta?: Uint32Array; + unitCoeff?: Float32Array; + unitActive?: Float32Array; @@ -2103,6 +2107,7 @@ index 0000000..bc02db8 + l * g * r * d, + "affineBasis", + ); ++ requireTypedLength(program.affineRead, Float32Array, l * g * r * d, "affineRead"); + requireTypedLength( + program.affineNeutral, + Float32Array, @@ -2167,6 +2172,7 @@ index 0000000..bc02db8 + curveSlots * r * d, + "curveBasis", + ); ++ requireTypedLength(program.curveRead, Float32Array, curveSlots * r * d, "curveRead"); + requireTypedLength( + program.curveNeutral, + Float32Array, @@ -2848,7 +2854,7 @@ index 0000000..74d754a + } +} diff --git a/src/engine.ts b/src/engine.ts -index 1934771..6900412 100644 +index 1934771..aacc700 100644 --- a/src/engine.ts +++ b/src/engine.ts @@ -45,6 +45,7 @@ import { @@ -3576,7 +3582,7 @@ index 1934771..6900412 100644 + } + } + -+ /** Hook ABI v5's block-sites device surface (replay, residents, attention rows). */ ++ /** Hook ABI v6's block-sites device surface (replay, residents, attention rows). */ + async drowseBlockSites( + request: DrowseBlockSitesRequest, + modelId?: string, @@ -4159,7 +4165,7 @@ index d583419..9a057a6 100644 hasModelInCache, deleteChatConfigInCache, diff --git a/src/llm_chat.ts b/src/llm_chat.ts -index 616cff4..3336e91 100644 +index 616cff4..0258e70 100644 --- a/src/llm_chat.ts +++ b/src/llm_chat.ts @@ -1,20 +1,28 @@ @@ -4286,7 +4292,7 @@ index 616cff4..3336e91 100644 type ImageURL = ChatCompletionContentPartImage.ImageURL; -@@ -47,6 +134,469 @@ type VMFunctionAvailability = { +@@ -47,6 +134,471 @@ type VMFunctionAvailability = { type VMFunctionRegistry = Record; @@ -4452,6 +4458,7 @@ index 616cff4..3336e91 100644 +type DrowseStructuredBuffers = { + affineActive: tvmjs.Tensor; + affineBasis: tvmjs.Tensor; ++ affineRead: tvmjs.Tensor; + affineNeutral: tvmjs.Tensor; + affineTarget: tvmjs.Tensor; + affineAlong: tvmjs.Tensor; @@ -4461,6 +4468,7 @@ index 616cff4..3336e91 100644 + probeBias: tvmjs.Tensor; + probeThreshold: tvmjs.Tensor; + curveBasis?: tvmjs.Tensor; ++ curveRead?: tvmjs.Tensor; + curveNeutral?: tvmjs.Tensor; + curveParameters?: tvmjs.Tensor; + curveActive?: tvmjs.Tensor; @@ -4756,7 +4764,7 @@ index 616cff4..3336e91 100644 type ResolvedModelABI = { kvStateKind: Exclude; prefillABI: ComputeABIKind; -@@ -67,6 +617,21 @@ export class LLMChatPipeline { +@@ -67,6 +619,21 @@ export class LLMChatPipeline { private vm: tvmjs.VirtualMachine; private prefill: tvmjs.PackedFunc; private decoding: tvmjs.PackedFunc; @@ -4778,7 +4786,7 @@ index 616cff4..3336e91 100644 private resolvedModelABI!: ResolvedModelABI; private kvStateKind: KVStateKind = "kv_cache"; private image_embed: tvmjs.PackedFunc | undefined; -@@ -94,7 +659,82 @@ export class LLMChatPipeline { +@@ -94,7 +661,82 @@ export class LLMChatPipeline { private prefillLogitPositionHost = new Int32Array(1); private maxHistorySize = 1; private logitsOnCPU?: tvmjs.Tensor = undefined; @@ -4861,7 +4869,7 @@ index 616cff4..3336e91 100644 // meta data private bosTokenId = 1; -@@ -109,8 +749,12 @@ export class LLMChatPipeline { +@@ -109,8 +751,12 @@ export class LLMChatPipeline { // states private outputMessage = ""; private outputIds: Array = []; @@ -4874,7 +4882,7 @@ index 616cff4..3336e91 100644 // frequency of appeared token ids till now (refresh after PrefillStep); token_id mapped to freq private appearedTokensFreq = new Map(); private imageDataCache = new Map(); -@@ -130,6 +774,10 @@ export class LLMChatPipeline { +@@ -130,6 +776,10 @@ export class LLMChatPipeline { private curRoundPrefillTotalTokens = 0; private curRoundDecodingTotalTime = 0; private curRoundPrefillTotalTime = 0; @@ -4885,7 +4893,7 @@ index 616cff4..3336e91 100644 // additional stats, reset at every prefillStep() public curRoundLatencyBreakdown: LatencyBreakdown = { -@@ -181,12 +829,14 @@ export class LLMChatPipeline { +@@ -181,12 +831,14 @@ export class LLMChatPipeline { tokenizer: Tokenizer, config: ChatConfig, logitProcessor?: LogitProcessor, @@ -4900,7 +4908,7 @@ index 616cff4..3336e91 100644 this.fullVocabSize = this.config.vocab_size; this.bitmaskSize = Math.ceil(this.fullVocabSize / 32); -@@ -233,6 +883,26 @@ export class LLMChatPipeline { +@@ -233,6 +885,26 @@ export class LLMChatPipeline { "batch_prefill", "decode", "batch_decode", @@ -4927,7 +4935,7 @@ index 616cff4..3336e91 100644 "create_tir_paged_kv_cache", "create_rnn_state", "sample_with_top_p", -@@ -253,9 +923,15 @@ export class LLMChatPipeline { +@@ -253,9 +925,15 @@ export class LLMChatPipeline { const vmFunctionAvailability = LLMChatPipeline.getVMFunctionAvailability(vmFunctionRegistry); @@ -4943,7 +4951,7 @@ index 616cff4..3336e91 100644 ); const stateKinds: string[] = []; if (this.resolvedModelABI.needsKVCache) { -@@ -287,6 +963,130 @@ export class LLMChatPipeline { +@@ -287,6 +965,130 @@ export class LLMChatPipeline { vmFunctionRegistry, ), ); @@ -5074,7 +5082,7 @@ index 616cff4..3336e91 100644 if (this.resolvedModelABI.prefillABI === "batch") { log.info("Using batch_prefill kernel."); } -@@ -489,6 +1289,43 @@ export class LLMChatPipeline { +@@ -489,6 +1291,43 @@ export class LLMChatPipeline { this.params.dispose(); this.decoding.dispose(); this.prefill.dispose(); @@ -5118,7 +5126,7 @@ index 616cff4..3336e91 100644 this.embed.dispose(); this.image_embed?.dispose(); this.prefillLogitPositions?.dispose(); -@@ -507,6 +1344,2625 @@ export class LLMChatPipeline { +@@ -507,6 +1346,2643 @@ export class LLMChatPipeline { this.grammarCompiler?.dispose(); } @@ -5137,7 +5145,7 @@ index 616cff4..3336e91 100644 + ); + } + -+ /** The units pair (hook ABI v5, `standard-v4`): mean-ablation and the live unit tap. */ ++ /** The units pair (hook ABI v6, `standard-v5`): mean-ablation and the live unit tap. */ + supportsDrowseUnitSites(): boolean { + return ( + this.drowseUnitsPrefill !== undefined && @@ -5217,13 +5225,13 @@ index 616cff4..3336e91 100644 + } + } + -+ /** Hook ABI v5's block-sites device surface (HOOK_ABI.md §7-§9), one request per call. */ ++ /** Hook ABI v6's block-sites device surface (HOOK_ABI.md §7-§9), one request per call. */ + async drowseBlockSites( + request: DrowseBlockSitesRequest, + ): Promise { + if (this.drowseHookDescriptor === undefined) { + throw new Error( -+ "BLOCK_SITES_UNAVAILABLE: the loaded model library does not attest hook ABI v5", ++ "BLOCK_SITES_UNAVAILABLE: the loaded model library does not attest hook ABI v6", + ); + } + switch (request.op) { @@ -5611,7 +5619,7 @@ index 616cff4..3336e91 100644 + } + + /** Open a KV-continuing replay (B1 §2.3, HOOK_ABI.md §7) on a fresh sequence. The installed -+ * program (drowse-structured-v4 with a unit section) steers it; `replayMeta` names the taps. */ ++ * program (drowse-structured-v5 with a unit section) steers it; `replayMeta` names the taps. */ + private async openDrowseReplay( + request: Extract, + ): Promise { @@ -5620,7 +5628,7 @@ index 616cff4..3336e91 100644 + } + if (this.drowseStructuredMode !== "units") { + throw new Error( -+ "REPLAY_PROGRAM_REQUIRED: install a drowse-structured-v4 program with a unit section first", ++ "REPLAY_PROGRAM_REQUIRED: install a drowse-structured-v5 program with a unit section first", + ); + } + const dims = this.drowseBlockDims(); @@ -6374,6 +6382,15 @@ index 616cff4..3336e91 100644 + ], + program.affineBasis, + ), ++ affineRead: f32( ++ [ ++ layerCount, ++ DROWSE_STRUCTURED_MAX_AFFINE_GROUPS, ++ DROWSE_STRUCTURED_MAX_RANK, ++ hiddenSize, ++ ], ++ program.affineRead, ++ ), + affineNeutral: f32( + [layerCount, DROWSE_STRUCTURED_MAX_AFFINE_GROUPS, hiddenSize], + program.affineNeutral, @@ -6432,6 +6449,15 @@ index 616cff4..3336e91 100644 + ], + program.curveBasis, + ), ++ curveRead: f32( ++ [ ++ layerCount, ++ DROWSE_STRUCTURED_MAX_CURVES, ++ DROWSE_STRUCTURED_MAX_RANK, ++ hiddenSize, ++ ], ++ program.curveRead, ++ ), + curveNeutral: f32( + [layerCount, DROWSE_STRUCTURED_MAX_CURVES, hiddenSize], + program.curveNeutral, @@ -7744,7 +7770,7 @@ index 616cff4..3336e91 100644 /** * Get the current message. */ -@@ -514,6 +3970,11 @@ export class LLMChatPipeline { +@@ -514,6 +3990,11 @@ export class LLMChatPipeline { return this.outputMessage; } @@ -7756,7 +7782,7 @@ index 616cff4..3336e91 100644 /** * Reset the runtime statistics */ -@@ -535,6 +3996,7 @@ export class LLMChatPipeline { +@@ -535,6 +4016,7 @@ export class LLMChatPipeline { } this.resetKVCache(); this.filledKVCacheLength = 0; @@ -7764,7 +7790,7 @@ index 616cff4..3336e91 100644 this.logitProcessor?.resetState(); this.tvm.endScope(); } -@@ -543,6 +4005,7 @@ export class LLMChatPipeline { +@@ -543,6 +4025,7 @@ export class LLMChatPipeline { * Reset KV Cache */ resetKVCache() { @@ -7772,7 +7798,7 @@ index 616cff4..3336e91 100644 const states = this.getActiveKVStates(); for (const state of states) { this.fclearKVCaches(state); -@@ -572,6 +4035,10 @@ export class LLMChatPipeline { +@@ -572,6 +4055,10 @@ export class LLMChatPipeline { return this.finishReason; } @@ -7783,7 +7809,7 @@ index 616cff4..3336e91 100644 /** * @returns tokenLogprobArray for this current round of autoregressive generation. * Updated upon each sampled token, cleared upon each prefillStep(). -@@ -587,6 +4054,10 @@ export class LLMChatPipeline { +@@ -587,6 +4074,10 @@ export class LLMChatPipeline { return this.curRoundDecodingTotalTokens; } @@ -7794,7 +7820,7 @@ index 616cff4..3336e91 100644 /** * @returns the number of tokens decoded for a single request or a single choice in the request. */ -@@ -665,10 +4136,10 @@ export class LLMChatPipeline { +@@ -665,10 +4156,10 @@ export class LLMChatPipeline { } /** @@ -7807,7 +7833,7 @@ index 616cff4..3336e91 100644 } private getResponseFormatKey( -@@ -721,13 +4192,17 @@ export class LLMChatPipeline { +@@ -721,13 +4212,17 @@ export class LLMChatPipeline { */ async prefillStep( inp: string, @@ -7828,7 +7854,7 @@ index 616cff4..3336e91 100644 ); } if (this.resetStatsPerPrefill) { -@@ -738,8 +4213,10 @@ export class LLMChatPipeline { +@@ -738,8 +4233,10 @@ export class LLMChatPipeline { // cleanup the per convo states this.outputIds = []; @@ -7839,7 +7865,7 @@ index 616cff4..3336e91 100644 this.tokenLogprobArray = []; this.curRoundDecodingTotalTokens = 0; this.curRoundPrefillTotalTokens = 0; -@@ -747,6 +4224,10 @@ export class LLMChatPipeline { +@@ -747,6 +4244,10 @@ export class LLMChatPipeline { this.curRoundDecodingTotalTime = 0; this.curRoundGrammarInitTotalTime = 0; this.curRoundGrammarPerTokenTotalTime = 0; @@ -7850,7 +7876,7 @@ index 616cff4..3336e91 100644 this.curRoundLatencyBreakdown = { logitProcessorTime: [], -@@ -758,6 +4239,8 @@ export class LLMChatPipeline { +@@ -758,6 +4259,8 @@ export class LLMChatPipeline { }; this.stopTriggered = false; @@ -7859,7 +7885,7 @@ index 616cff4..3336e91 100644 const conversation = this.conversation; // -1. Instantiate grammar matcher according to generation config. This step is overlapped -@@ -831,23 +4314,13 @@ export class LLMChatPipeline { +@@ -831,23 +4334,13 @@ export class LLMChatPipeline { } // 0. Get inputData from conversation @@ -7890,7 +7916,7 @@ index 616cff4..3336e91 100644 const [inputData, promptLen, getEmbedSize] = await this.getInputData(); // Check if LLMChatPipeline fits for forwarding image input -@@ -944,8 +4417,9 @@ export class LLMChatPipeline { +@@ -944,8 +4437,9 @@ export class LLMChatPipeline { } this.stopTriggered = true; this.finishReason = "abort"; @@ -7901,7 +7927,7 @@ index 616cff4..3336e91 100644 } } -@@ -999,9 +4473,11 @@ export class LLMChatPipeline { +@@ -999,9 +4493,11 @@ export class LLMChatPipeline { if (stopTokens.includes(nextToken)) { this.stopTriggered = true; this.finishReason = "stop"; @@ -7913,7 +7939,7 @@ index 616cff4..3336e91 100644 // Update token appearance frequency const curFreq = this.appearedTokensFreq.get(nextToken); if (curFreq !== undefined) { -@@ -1013,6 +4489,7 @@ export class LLMChatPipeline { +@@ -1013,6 +4509,7 @@ export class LLMChatPipeline { // Stop condition 2: stop string; update `this.outputMessage` subsequently let outputMessage = this.tokenizer.decode(new Int32Array(this.outputIds)); @@ -7921,7 +7947,7 @@ index 616cff4..3336e91 100644 let stopPos = -1; for (const stopStr of stopStrs) { // Stop at the first stopStr we find -@@ -1021,32 +4498,36 @@ export class LLMChatPipeline { +@@ -1021,32 +4518,36 @@ export class LLMChatPipeline { outputMessage = outputMessage.substring(0, stopPos); this.stopTriggered = true; this.finishReason = "stop"; @@ -7960,7 +7986,7 @@ index 616cff4..3336e91 100644 } } } -@@ -1227,7 +4708,87 @@ export class LLMChatPipeline { +@@ -1227,7 +4728,87 @@ export class LLMChatPipeline { private async embedAndForward( inputData: Array | ImageURL>, inputDataLen: number, @@ -8048,7 +8074,7 @@ index 616cff4..3336e91 100644 if (inputDataLen > this.prefillChunkSize) { throw new Error( "InternalError: expect inputDataLen <= this.prefillChunkSize.", -@@ -1238,51 +4799,140 @@ export class LLMChatPipeline { +@@ -1238,51 +4819,140 @@ export class LLMChatPipeline { // 1. Embed all inputData this.tvm.beginScope(); @@ -8230,7 +8256,7 @@ index 616cff4..3336e91 100644 this.tvm.attachToCurrentScope(logits); return logits; } -@@ -1292,7 +4942,14 @@ export class LLMChatPipeline { +@@ -1292,7 +4962,14 @@ export class LLMChatPipeline { names: string[], ): VMFunctionRegistry { const registry: VMFunctionRegistry = {}; @@ -8246,7 +8272,7 @@ index 616cff4..3336e91 100644 try { const func = vm.getFunction(name) as unknown; if (typeof func === "function") { -@@ -1365,6 +5022,7 @@ export class LLMChatPipeline { +@@ -1365,6 +5042,7 @@ export class LLMChatPipeline { private static resolveModelABI( kvStateKind: KVStateKind, availability: VMFunctionAvailability, @@ -8254,7 +8280,7 @@ index 616cff4..3336e91 100644 ): ResolvedModelABI { const hasSingleKernelPair = availability.prefill && availability.decode; const hasBatchKernelPair = -@@ -1450,6 +5108,17 @@ export class LLMChatPipeline { +@@ -1450,6 +5128,17 @@ export class LLMChatPipeline { } // kv_cache @@ -8272,7 +8298,7 @@ index 616cff4..3336e91 100644 if (hasSingleKernelPair) { return { kvStateKind, -@@ -1525,14 +5194,151 @@ export class LLMChatPipeline { +@@ -1525,14 +5214,151 @@ export class LLMChatPipeline { return states; } @@ -8425,7 +8451,7 @@ index 616cff4..3336e91 100644 this.params, ); } -@@ -1549,27 +5355,42 @@ export class LLMChatPipeline { +@@ -1549,27 +5375,42 @@ export class LLMChatPipeline { this.resolvedModelABI.needsKVCache && this.resolvedModelABI.needsRNNState ) { @@ -8472,7 +8498,7 @@ index 616cff4..3336e91 100644 this.params, ); } -@@ -1577,20 +5398,68 @@ export class LLMChatPipeline { +@@ -1577,20 +5418,70 @@ export class LLMChatPipeline { this.resolvedModelABI.needsKVCache && this.resolvedModelABI.needsRNNState ) { @@ -8500,6 +8526,7 @@ index 616cff4..3336e91 100644 + const affine = [ + program.affineActive, + program.affineBasis, ++ program.affineRead, + program.affineNeutral, + program.affineTarget, + program.affineAlong, @@ -8512,6 +8539,7 @@ index 616cff4..3336e91 100644 + if (this.drowseStructuredMode === "structured") return affine; + const curved = affine.concat([ + program.curveBasis!, ++ program.curveRead!, + program.curveNeutral!, + program.curveDomainKind!, + program.curveParameters!, @@ -8543,7 +8571,7 @@ index 616cff4..3336e91 100644 // NOTE: caller must call device.sync() private updateLogitsOnCPU(logits: tvmjs.Tensor): tvmjs.Tensor { if (this.logitsOnCPU == undefined) { -@@ -1610,7 +5479,7 @@ export class LLMChatPipeline { +@@ -1610,7 +5501,7 @@ export class LLMChatPipeline { logitsOnGPU: tvmjs.Tensor, genConfig?: GenerationConfig, ) { @@ -8552,7 +8580,7 @@ index 616cff4..3336e91 100644 // Also load other genConfig items like logit_bias. Consume all fields of `genConfig` here. function _hasValue(value: any): boolean { // if we use `if value` directly, `value` being 0 evaluates to false, violating semantics -@@ -1618,6 +5487,7 @@ export class LLMChatPipeline { +@@ -1618,6 +5509,7 @@ export class LLMChatPipeline { } let temperature: number = this.config.temperature; let top_p: number = this.config.top_p; @@ -8560,7 +8588,7 @@ index 616cff4..3336e91 100644 let repetition_penalty: number = this.config.repetition_penalty; let frequency_penalty: number = this.config.frequency_penalty; let presence_penalty: number = this.config.presence_penalty; -@@ -1633,6 +5503,9 @@ export class LLMChatPipeline { +@@ -1633,6 +5525,9 @@ export class LLMChatPipeline { if (_hasValue(genConfig.top_p)) { top_p = genConfig.top_p!; } @@ -8570,7 +8598,7 @@ index 616cff4..3336e91 100644 // TODO: setting top_p to 1.0 by default might run into issues since // top_p masking in relax uses < instead of <= // Set default top_p to 1.0 if not set -@@ -1675,26 +5548,24 @@ export class LLMChatPipeline { +@@ -1675,26 +5570,24 @@ export class LLMChatPipeline { } } // Check range validity @@ -8608,7 +8636,7 @@ index 616cff4..3336e91 100644 } const outputTokenBegin = performance.now(); -@@ -1894,13 +5765,38 @@ export class LLMChatPipeline { +@@ -1894,13 +5787,38 @@ export class LLMChatPipeline { // 4. Sample token from logits const sampleBegin = performance.now(); @@ -8651,7 +8679,7 @@ index 616cff4..3336e91 100644 this.tvm.beginScope(); const temperaturesDevice = this.tvm -@@ -1913,79 +5809,131 @@ export class LLMChatPipeline { +@@ -1913,79 +5831,131 @@ export class LLMChatPipeline { ); probs = probs.view([numProbs, this.fullVocabSize]); @@ -8833,7 +8861,7 @@ index 616cff4..3336e91 100644 } /** -@@ -2015,34 +5963,90 @@ export class LLMChatPipeline { +@@ -2015,34 +5985,90 @@ export class LLMChatPipeline { * imageUrl2, * token array for "\nSome user input<|end|>\n" */ @@ -8947,7 +8975,7 @@ index 616cff4..3336e91 100644 // 1.5. Preload image dimensions to compute per-image embed sizes const imageDimensions = new Map(); -@@ -2082,7 +6086,7 @@ export class LLMChatPipeline { +@@ -2082,7 +6108,7 @@ export class LLMChatPipeline { // 3. Encode all prompts. Iterate through each message in the prompt array, where each // prompt can either be a string, or an array of a mixture of string and ImageURLs. @@ -8956,7 +8984,7 @@ index 616cff4..3336e91 100644 for (let i = 0; i < prompts.length; i++) { const curPrompt = prompts[i]; if (typeof curPrompt === "string") { -@@ -2116,6 +6120,26 @@ export class LLMChatPipeline { +@@ -2116,6 +6142,26 @@ export class LLMChatPipeline { } } } @@ -8983,7 +9011,7 @@ index 616cff4..3336e91 100644 // Deal with last curTokens if (curTokens.length !== 0) { ret.push([...curTokens]); -@@ -2186,50 +6210,51 @@ export class LLMChatPipeline { +@@ -2186,50 +6232,51 @@ export class LLMChatPipeline { } /** @@ -9051,7 +9079,7 @@ index 616cff4..3336e91 100644 } as ChatCompletionTokenLogprob; } -@@ -2284,3 +6309,10 @@ export class LLMChatPipeline { +@@ -2284,3 +6331,10 @@ export class LLMChatPipeline { log.info(msg); } } @@ -9465,7 +9493,7 @@ index c91f751..d2ee04e 100644 export { diff --git a/src/types.ts b/src/types.ts -index ed79af5..3436cd5 100644 +index ed79af5..5823d6f 100644 --- a/src/types.ts +++ b/src/types.ts @@ -15,6 +15,21 @@ import { @@ -9497,7 +9525,7 @@ index ed79af5..3436cd5 100644 + supportsDrowseStructuredHooks(modelId?: string): Promise; + + supportsDrowseCurvedHooks(modelId?: string): Promise; -+ /** Hook ABI v5: the library compiles unit sites (`standard-v4`) and the units pair. */ ++ /** Hook ABI v6: the library compiles unit sites (`standard-v5`) and the units pair. */ + supportsDrowseUnitSites(modelId?: string): Promise; + + supportsDrowseResidualCapture(modelId?: string): Promise; @@ -9549,7 +9577,7 @@ index ed79af5..3436cd5 100644 + unitActive?: Float32Array, + ): Promise; + -+ /** Hook ABI v5's block-sites device surface: replay, residents, attention rows. */ ++ /** Hook ABI v6's block-sites device surface: replay, residents, attention rows. */ + drowseBlockSites( + request: DrowseBlockSitesRequest, + modelId?: string, @@ -10763,10 +10791,10 @@ index 8fa04b2..0d5455d 100644 type ImageURL = ChatCompletionContentPartImage.ImageURL; diff --git a/tests/drowse.test.ts b/tests/drowse.test.ts new file mode 100644 -index 0000000..dea121b +index 0000000..fcb1ede --- /dev/null +++ b/tests/drowse.test.ts -@@ -0,0 +1,944 @@ +@@ -0,0 +1,953 @@ +import { describe, expect, test } from "@jest/globals"; +import { + DROWSE_REPLAY_META, @@ -10823,7 +10851,7 @@ index 0000000..dea121b +} from "../src/drowse"; + +describe("Drowse structured hook profile", () => { -+ // Schema 4: v3's fields with ABI 5 / format 4 / readout 2, then 36 block and unit fields ++ // Schema 4: v3's fields with ABI 6 / format 5 / readout 2, then 36 block and unit fields + // (attested by the caller; the bridge reads UNIT_SITES and HEAD_DIM). + const tail = new Array(36).fill(0); + tail[0] = 1; // UNIT_SITES @@ -10831,9 +10859,9 @@ index 0000000..dea121b + const descriptor = Int32Array.from([ + DROWSE_STRUCTURED_PROFILE_MAGIC, + 4, -+ 4, + 5, -+ 4, ++ 6, ++ 5, + 12, + 768, + DROWSE_STRUCTURED_MAX_AFFINE_GROUPS, @@ -10866,7 +10894,7 @@ index 0000000..dea121b + test("decodes the immutable compiled descriptor", () => { + expect(decodeDrowseStructuredHookProfile(descriptor, 12, 768)).toEqual({ + schemaVersion: 4, -+ id: "standard-v4", ++ id: "standard-v5", + unitSites: 1, + descriptor: Array.from(descriptor), + hookAbi: DROWSE_HOOK_ABI, @@ -10922,7 +10950,7 @@ index 0000000..dea121b + const residual = descriptor.slice(); + residual[31] = 0; + expect(decodeDrowseStructuredHookProfile(residual, 12, 768).id).toBe( -+ "standard-v4-residual", ++ "standard-v5-residual", + ); + const noMode = descriptor.slice(); + noMode[31] = 2; @@ -10932,7 +10960,7 @@ index 0000000..dea121b + }); +}); + -+describe("Drowse unit section (drowse-structured-v4)", () => { ++describe("Drowse unit section (drowse-structured-v5)", () => { + const layers = 2; + const headDim = 4; + const lengths = drowseUnitSectionLengths(layers, headDim); @@ -11125,7 +11153,7 @@ index 0000000..dea121b + }); +}); + -+/** A drowse-structured-v4 program; every program carries the geometry buffers. */ ++/** A drowse-structured-v5 program; every program carries the geometry buffers. */ +function structuredProgram(): DrowseStructuredProgram { + return structuredGeometryProgram(); +} @@ -11148,6 +11176,12 @@ index 0000000..dea121b + DROWSE_STRUCTURED_MAX_RANK * + hiddenSize, + ), ++ affineRead: new Float32Array( ++ layerCount * ++ DROWSE_STRUCTURED_MAX_AFFINE_GROUPS * ++ DROWSE_STRUCTURED_MAX_RANK * ++ hiddenSize, ++ ), + affineNeutral: new Float32Array( + layerCount * DROWSE_STRUCTURED_MAX_AFFINE_GROUPS * hiddenSize, + ), @@ -11178,6 +11212,9 @@ index 0000000..dea121b + curveBasis: new Float32Array( + curveSlots * DROWSE_STRUCTURED_MAX_RANK * hiddenSize, + ), ++ curveRead: new Float32Array( ++ curveSlots * DROWSE_STRUCTURED_MAX_RANK * hiddenSize, ++ ), + curveNeutral: new Float32Array(curveSlots * hiddenSize), + curveNodeParameters: new Float32Array( + curveSlots * @@ -11653,7 +11690,7 @@ index 0000000..dea121b + return out; + }; + -+ test("is laid out as drowse.ai's replayMetaLayout (134 values under standard-v4)", () => { ++ test("is laid out as drowse.ai's replayMetaLayout (134 values under standard-v5)", () => { + expect(m.length).toBe(134); + expect([ + m.populationRow, diff --git a/browser-runtime/q4_unit_parity.py b/browser-runtime/q4_unit_parity.py index 8778324..9fc4f06 100644 --- a/browser-runtime/q4_unit_parity.py +++ b/browser-runtime/q4_unit_parity.py @@ -1,6 +1,6 @@ """Production q4 parity of a units library's sites, static reads and activity (hook ABI v5). -B1 §4.3 item 2: the browser against Python on the dequantized MLC tensors. A `standard-v4` +B1 §4.3 item 2: the browser against Python on the dequantized MLC tensors. A `standard-v5` library's capture carries, beside its residuals, the block sites `act`, `z` and `mid` at the same layers and positions (through the replay), and a set of static reads. Python recomputes each from the Transformers model `mlc_q4_torch` builds over the same tensors: @@ -15,7 +15,7 @@ the same way from each side's sites, have Jaccard index at least 0.9. The rank is unscaled: the reading scales come from a units pack and divide both sides alike. -A `standard-v4-residual` library has none of these sites; its capture carries no `units` member. +A `standard-v5-residual` library has none of these sites; its capture carries no `units` member. """ from __future__ import annotations diff --git a/browser-runtime/record-cvm-goldens.py b/browser-runtime/record-cvm-goldens.py deleted file mode 100644 index b5f3549..0000000 --- a/browser-runtime/record-cvm-goldens.py +++ /dev/null @@ -1,135 +0,0 @@ -#!/usr/bin/env python3 -"""Release-evidence observer for hook ABI v5 on the C TVM VM (`cVmGoldens`). - -Runs ``forks/verify-mlc-hook.py`` twice with the pinned, source-built MLC/TVM toolchain: the -default structured, geometry and exact-readout goldens, then ``--units-fixtures`` over the four -fixture libraries ``build-units-fixtures.py`` makes (qwen3 and gemma3 at q0f32 and q4f32_1) -against drowse's units, replay and read goldens. Prints one direct observation for -``record-hosted-evidence.mjs`` on stdout and nothing else; any failure exits non-zero with the -reason on stderr, which the recorder refuses. - - python3 browser-runtime/record-cvm-goldens.py --python TOOLCHAIN_PYTHON \\ - --mlc-repository MLC --tvm-repository TVM --units-fixtures FIXTURES -""" - -from __future__ import annotations - -import argparse -import hashlib -import json -import os -import subprocess -import sys -from datetime import datetime, timezone -from pathlib import Path - -ROOT = Path(__file__).resolve().parent -VERIFY = ROOT / "forks" / "verify-mlc-hook.py" -FIXTURE = "drowse/tests/fixtures/browser/units-tiny-models-v1.json" -LIBRARIES = ("gemma3-q0f32", "gemma3-q4f32_1", "qwen3-q0f32", "qwen3-q4f32_1") -DEFAULT_PASSED = "compiled C/LLVM golden checks passed" -UNITS_PASSED = "passed on the C TVM VM: " - - -class ObservationError(RuntimeError): - pass - - -def toolchain_environment(mlc: Path, tvm: Path) -> dict[str, str]: - """The exact-source toolchain's import roots (browser-runtime/README.md), nothing inherited - beyond the process basics.""" - keep = {key: os.environ[key] for key in ("PATH", "HOME", "TMPDIR", "LANG", "LC_ALL") if key in os.environ} - return { - **keep, - "PYTHONPATH": f"{tvm / 'python'}{os.pathsep}{mlc / 'python'}", - # A source build keeps its shared libraries in build/lib (CMake's install layout) or, older, - # in build itself. - "TVM_LIBRARY_PATH": str(tvm / "build" / "lib" if (tvm / "build" / "lib").is_dir() else tvm / "build"), - "TVM_DEVICE_BACKEND_AUTOLOAD": "0", - "SKIP_LOADING_MLCLLM_SO": "1", - "PYTHONUNBUFFERED": "1", - } - - -def run(python: Path, arguments: list[str], environment: dict[str, str]) -> str: - completed = subprocess.run( - [str(python), str(VERIFY), *arguments], - env=environment, cwd=ROOT.parent, capture_output=True, text=True, check=False, - ) - if completed.returncode != 0: - tail = "\n".join((completed.stdout + completed.stderr).splitlines()[-20:]) - raise ObservationError(f"verify-mlc-hook.py {' '.join(arguments[-2:])} failed:\n{tail}") - return completed.stdout - - -def units_results(stdout: str) -> dict[str, dict[str, float]]: - """The per-library worst |Δ| of every golden file from verify-mlc-hook's closing line.""" - lines = [line for line in stdout.splitlines() if UNITS_PASSED in line] - if len(lines) != 1: - raise ObservationError("the units goldens did not report one closing line") - results = json.loads(lines[0].split(UNITS_PASSED, 1)[1]) - if sorted(results) != list(LIBRARIES): - raise ObservationError(f"the units goldens covered {sorted(results)}, not {list(LIBRARIES)}") - return {key: {suite: float(value) for suite, value in sorted(suites.items())} for key, suites in sorted(results.items())} - - -def model_sha256(fixtures: Path, library: str) -> str: - """The fixture model a library key names: its converted tensor-cache.json (the weights' - manifest), so the record identifies what ran rather than only the argument's label.""" - arch, quantization = library.split("-", 1) - return hashlib.sha256((fixtures / f"units-{arch}-{quantization}" / "tensor-cache.json").read_bytes()).hexdigest() - - -def observe(args: argparse.Namespace) -> dict[str, object]: - environment = toolchain_environment(args.mlc_repository, args.tvm_repository) - repositories = ["--mlc-repository", str(args.mlc_repository), "--tvm-repository", str(args.tvm_repository)] - default = run(args.python, repositories, environment) - if DEFAULT_PASSED not in default: - raise ObservationError("the default structured, geometry and readout goldens did not report success") - units = run(args.python, [*repositories, "--units-fixtures", str(args.units_fixtures)], environment) - return { - "schemaVersion": 1, - "evidenceType": "cVmGoldens", - "fixturePath": FIXTURE, - "passed": True, - "producedAt": datetime.now(timezone.utc).isoformat().replace("+00:00", "Z"), - "results": { - "backend": "c-tvm-vm", - "defaultGoldensPassed": True, - "libraries": { - key: {"modelSha256": model_sha256(args.units_fixtures, key), "suites": suites} - for key, suites in units_results(units).items() - }, - }, - } - - -def parse_args(argv: list[str]) -> argparse.Namespace: - parser = argparse.ArgumentParser(description=__doc__.splitlines()[0]) - parser.add_argument("--python", type=Path, required=True, help="the toolchain's Python") - parser.add_argument("--mlc-repository", type=Path, required=True) - parser.add_argument("--tvm-repository", type=Path, required=True) - parser.add_argument("--units-fixtures", type=Path, required=True) - args = parser.parse_args(argv) - for name in ("mlc_repository", "tvm_repository", "units_fixtures"): - setattr(args, name, getattr(args, name).resolve(strict=True)) - # The interpreter keeps the path it was given: a virtual environment's python is a symlink to - # its base interpreter, and resolving it would drop the environment's packages. - args.python = args.python.expanduser().absolute() - if not args.python.is_file(): - raise SystemExit(f"--python {args.python} is not a file") - return args - - -def main(argv: list[str] | None = None) -> int: - try: - observation = observe(parse_args(sys.argv[1:] if argv is None else argv)) - except (ObservationError, OSError, json.JSONDecodeError) as error: - print(f"record-cvm-goldens: {error}", file=sys.stderr) - return 1 - sys.stdout.write(json.dumps(observation, sort_keys=True) + "\n") - return 0 - - -if __name__ == "__main__": - raise SystemExit(main()) diff --git a/browser-runtime/runtime-lock.json b/browser-runtime/runtime-lock.json index 81bf285..ccfda59 100644 --- a/browser-runtime/runtime-lock.json +++ b/browser-runtime/runtime-lock.json @@ -2,11 +2,11 @@ "$schema": "./runtime-lock.schema.json", "schemaVersion": 2, "status": "verified", - "runtimeAbi": "drowse-web-runtime-v2", - "hookAbi": "block-sites-v5", + "runtimeAbi": "drowse-web-runtime-v3", + "hookAbi": "block-sites-v6", "exactReadoutAbi": "exact-readout-v2", "toolchain": { - "forkManifestSha256": "22ae995379f92fa84962e78c0c22574952cef0f9099c90285f1298f3e5bc1fd7", + "forkManifestSha256": "10c5901567a2258954de79b1ec157a7cb4d8128570e8c017a88109be7f12f80c", "mlcLlmFork": { "repository": "https://github.com/a9lim/mlc-llm-polythetic", "commit": null @@ -16,10 +16,10 @@ "commit": null }, "webLlmPackage": { - "path": "browser-runtime/vendor/drowse-web-llm-0.2.84-drowse.49.tgz", - "sha256": "81dbc5f7116b89bd6531bf32809530367a7e3149590bf285bc79a8aba17c249f", + "path": "browser-runtime/vendor/drowse-web-llm-0.2.84-drowse.50.tgz", + "sha256": "da5818f8ee9d65db4373408ff89d3c0392db10752f49de98e26caa1c5868b1dd", "name": "@drowse/web-llm", - "version": "0.2.84-drowse.49", + "version": "0.2.84-drowse.50", "repository": "https://github.com/a9lim/web-llm-polythetic", "sourceCommit": null }, @@ -61,7 +61,7 @@ { "id": "gemma3-270m-instruct", "architecture": "gemma3_text", - "structuredHookProfile": "standard-v4", + "structuredHookProfile": "standard-v5", "blockSpec": { "dFF": 2048, "nHeads": 4, @@ -87,9 +87,9 @@ "sourceRepository": "unsloth/gemma-3-270m-it", "sourceRevision": "23cf460f6bb16954176b3ddcc8d4f250501458a9", "convertedRepository": "stdlogits/drowse-web-gemma3-270m", - "convertedRevision": "1e660ed475d16f87e705ad9984556f0e1e6348e6", + "convertedRevision": "ebd221b9b4d595139457dffb16ac6f500eca669e", "manifestSha256": "f5fa544c45399f5551ea4f01010540036bfa02b51487bcc50094c36426fb4586", - "librarySha256": "56dfbad7b5a1614084baa585eba3d0d4e9b5aac96839865f345ec3c0538e1aac", + "librarySha256": "64e132fe27050285107e32c9bdd04d0bb1f57ae804380cc2b4512d8a4167ec88", "tokenizerSha256": "4667f2089529e8e7657cfb6d1c19910ae71ff5f28aa7ab2ff2763330affad795", "chatTemplateSha256": "be2182df1ad0ea735d336418896eb06e5cc2f59136e7aaeac5de2ec2197742ac", "hiddenSize": 640, @@ -123,7 +123,7 @@ { "id": "gemma3-1b-instruct", "architecture": "gemma3_text", - "structuredHookProfile": "standard-v4", + "structuredHookProfile": "standard-v5", "blockSpec": { "dFF": 6912, "nHeads": 4, @@ -149,9 +149,9 @@ "sourceRepository": "unsloth/gemma-3-1b-it", "sourceRevision": "5b11413a10db4e486ef16a20101fd028f8f2499c", "convertedRepository": "stdlogits/drowse-web-gemma3-1b", - "convertedRevision": "566dc4ff747f62cea6ab452b048944f54fb5aa77", + "convertedRevision": "794535fe3299fce63f03334824673263ce24b986", "manifestSha256": "40ef8d47203ef0f1e768b819cd84bc60a146a97d63cb4883d3563cbacbdc9df4", - "librarySha256": "130ce552350c3c42459c1f2b4edd5b5992f91f42b2c3911b98a4a39bd4fc0095", + "librarySha256": "56f7960bf812384ae1e58ccfdbaff9f2f99033062f1c59f893e06dbbb9cb5970", "tokenizerSha256": "4667f2089529e8e7657cfb6d1c19910ae71ff5f28aa7ab2ff2763330affad795", "chatTemplateSha256": "a622f3103725cffe1f19deed01e8675cea4443bc3eff27680f9484e5dc4acf7b", "hiddenSize": 1152, @@ -193,7 +193,7 @@ { "id": "gemma3-4b-instruct", "architecture": "gemma3_text", - "structuredHookProfile": "standard-v4", + "structuredHookProfile": "standard-v5", "blockSpec": { "dFF": 10240, "nHeads": 8, @@ -219,9 +219,9 @@ "sourceRepository": "unsloth/gemma-3-4b-it", "sourceRevision": "bf46152c47f5dd20b896357cb51abc4c03b8ee8c", "convertedRepository": "stdlogits/drowse-web-gemma3-4b", - "convertedRevision": "bcc12ca07fb6f51ae2544a2795e34fe0a01307d4", + "convertedRevision": "cff912b7b6379cb15657e549ca52c897e4d46cb8", "manifestSha256": "f19b31f7138a587ff9bebe2c39527c7eae829ff8bbcd56db1d1ae0913ac159a0", - "librarySha256": "03f371d57997e461cf7668486dd028e53f7f1276cc5e6fcf5581c48b462f6bd8", + "librarySha256": "a980613e32cbc5ba6ad73e9e7bba30813880786d9b03cd5eb836689387048c5d", "tokenizerSha256": "4667f2089529e8e7657cfb6d1c19910ae71ff5f28aa7ab2ff2763330affad795", "chatTemplateSha256": "8925eabb556c1897ca1bed405f0612e735a56afcd4d77e76eb90fd771e706f9c", "hiddenSize": 2560, @@ -271,7 +271,7 @@ { "id": "qwen3-4b", "architecture": "qwen3", - "structuredHookProfile": "standard-v4", + "structuredHookProfile": "standard-v5", "blockSpec": { "dFF": 9728, "nHeads": 32, @@ -307,9 +307,9 @@ "sourceRepository": "Qwen/Qwen3-4B", "sourceRevision": "1cfa9a7208912126459214e8b04321603b3df60c", "convertedRepository": "stdlogits/drowse-web-qwen3-4b", - "convertedRevision": "d6a56e61353ad018e55144fc46cdfae0df46032c", + "convertedRevision": "a0cb6657ba1bf9aceed05a7073f40939f38118c5", "manifestSha256": "b19c107ebd7d637bd89dad4882e7972dd7a81ab04f2ce1960bc1dfc1dd266204", - "librarySha256": "9f000e4972bf22ecf7ae1a71799f865b56aca8a5a0bbf29f38f3b1409dea1d1d", + "librarySha256": "20d19e024ab6f3e173564c3fd4c80dc23ba20a09562b15ff73ca7ec7c6f227a1", "tokenizerSha256": "aeb13307a71acd8fe81861d94ad54ab689df773318809eed3cbe794b4492dae4", "chatTemplateSha256": "d5d09f07b48c3086c508b30d1c9114bd1189145b74e982a265350c923acd8101", "hiddenSize": 2560, @@ -361,7 +361,7 @@ { "id": "qwen3-1.7b", "architecture": "qwen3", - "structuredHookProfile": "standard-v4", + "structuredHookProfile": "standard-v5", "blockSpec": { "dFF": 6144, "nHeads": 16, @@ -397,9 +397,9 @@ "sourceRepository": "Qwen/Qwen3-1.7B", "sourceRevision": "70d244cc86ccca08cf5af4e1e306ecf908b1ad5e", "convertedRepository": "stdlogits/drowse-web-qwen3-1.7b", - "convertedRevision": "92f201148c2e45b9258014b95fae1b3a8c782e7e", + "convertedRevision": "55de3b85d61e2dbf903bf19f895c4aad47af9fc0", "manifestSha256": "8eab009068b10b93d819c14dff5c04c3866feb690d5a981d163eb8eee64ff956", - "librarySha256": "21877d130d761218608bdb7acf33a6f8b9d3549d5b2a4f47ea261fe2308a7c55", + "librarySha256": "82167fb0c3261fd90c791baa658c4c5cb4b01ac491ff7eecacccc8bb9ad0820a", "tokenizerSha256": "aeb13307a71acd8fe81861d94ad54ab689df773318809eed3cbe794b4492dae4", "chatTemplateSha256": "d5d09f07b48c3086c508b30d1c9114bd1189145b74e982a265350c923acd8101", "hiddenSize": 2048, @@ -444,15 +444,15 @@ "id": "gpt2-base", "modelType": "base", "architecture": "gpt2", - "structuredHookProfile": "standard-v4-residual", + "structuredHookProfile": "standard-v5-residual", "unitRefusal": "no rotary embedding beside the block list ('rotary_emb'); a dense block here is RoPE attention", "thinkingProfile": null, "sourceRepository": "openai-community/gpt2", "sourceRevision": "607a30d783dfa663caf39e06633721c8d4cfcd7e", "convertedRepository": "stdlogits/drowse-web-gpt2-base", - "convertedRevision": "6f58b167bfbae418f87f4739c9a594a0f593f490", + "convertedRevision": "093d54fd29da668538a12738684acc63186f71f9", "manifestSha256": "571e5c3a42148b976ceb2b714408cf48589d6fc2d71ff20101586577773124d5", - "librarySha256": "a7fdaa50af197946ef48dcb31cfcaccc1a40708ff3e140dcc840e891a0b3fb3e", + "librarySha256": "09a116c83d741fc13430426106bfb1844715b096c01493c8374ed3e9f872bc63", "tokenizerSha256": "8414cab924d8b9b33013f0d221c5862f365ee9be39c5c2bfae8a5a9e970478a6", "chatTemplateSha256": "5e04eb606e3a1583530a42e36c2a6b6615c86f34fe77e44d9ddeb43ff940931f", "hiddenSize": 768, @@ -480,15 +480,15 @@ "id": "pythia-70m-base", "modelType": "base", "architecture": "gpt_neox", - "structuredHookProfile": "standard-v4-residual", + "structuredHookProfile": "standard-v5-residual", "unitRefusal": "layer 0: block has no softmax self-attention ('self_attn'; found attention, input_layernorm, mlp, post_attention_dropout, post_attention_layernorm, post_mlp_dropout)", "thinkingProfile": null, "sourceRepository": "EleutherAI/pythia-70m-deduped", "sourceRevision": "e93a9faa9c77e5d09219f6c868bfc7a1bd65593c", "convertedRepository": "stdlogits/drowse-web-pythia-70m-base", - "convertedRevision": "7054b621200ffbbac72707e6e2e21cb88c905976", + "convertedRevision": "7c0a5742374d792beec4d2f736adb7a8e972782a", "manifestSha256": "587eee3dadf689c9354c76452e618a14df7c6ad50b0ea88b3e68dcca9ed4872d", - "librarySha256": "45f4bdd114b1c7564744ce1a46808b98e751b303442bde0c20b41072d66992df", + "librarySha256": "0e88754113b9d527a150f7b97297546c74e9aa8ca0e8bb3c11b94347c1f77810", "tokenizerSha256": "c24618a1b3e6a38167beff1c72cffd126c3a66254347304b50547d12c5f25624", "chatTemplateSha256": "70e38394e494931c6f773ba41e19460dd4436526b852207367f04341b4066d3f", "hiddenSize": 512, @@ -510,7 +510,7 @@ "id": "gemma3-1b-pt", "modelType": "base", "architecture": "gemma3_text", - "structuredHookProfile": "standard-v4", + "structuredHookProfile": "standard-v5", "blockSpec": { "dFF": 6912, "nHeads": 4, @@ -536,9 +536,9 @@ "sourceRepository": "google/gemma-3-1b-pt", "sourceRevision": "fcf18a2a879aab110ca39f8bffbccd5d49d8eb29", "convertedRepository": "stdlogits/drowse-web-gemma3-1b-pt", - "convertedRevision": "27b3aeff48c6b999dcfed59e580bb23a72e71519", + "convertedRevision": "abb57318c09197b82b4a3b2821658ff8cae69b3d", "manifestSha256": "41bb76ef5854f93346114bb6ff8e6028960012470a0e96e5d6eedc060ac079cd", - "librarySha256": "bfac54784bb136fb7e2fd722a12ef22832a3c0d708cc40779f4c8117e243547c", + "librarySha256": "607f40f59f0dd43797e53895014db2db24b29d14bc89bc5b3e404e348a32de97", "tokenizerSha256": "7d4046bf0505a327dd5a0abbb427ecd4fc82f99c2ceaa170bc61ecde12809b0c", "chatTemplateSha256": "4d97b6d876fd05ffaf72c3243231975c50263ad4fc620bc9f0b44be2ca11fa31", "hiddenSize": 1152, @@ -580,15 +580,15 @@ "id": "qwen35-2b-base", "modelType": "base", "architecture": "qwen3_5", - "structuredHookProfile": "standard-v4-residual", + "structuredHookProfile": "standard-v5-residual", "unitRefusal": "layer 0: linear-attention layer ('linear_attn') in a hybrid stack; only softmax self-attention blocks are described", "thinkingProfile": null, "sourceRepository": "Qwen/Qwen3.5-2B-Base", "sourceRevision": "b1485b2fa6dfa1287294f269f5fb618e03d52d7c", "convertedRepository": "stdlogits/drowse-web-qwen35-2b-base", - "convertedRevision": "fc9a364cb63709766ae8effc3e832577a3322d94", + "convertedRevision": "9f24cbaec2876f33fed5cb49095a120a10ab5f1d", "manifestSha256": "6f4d36a4eebec65a1764d304a0ea563a7b57ffb21b1558056207ef3a34c11831", - "librarySha256": "c64c9aef544f71543b73270febe9c68110f295df344afc32fea9de4a08858ecc", + "librarySha256": "af15c3450a1f32009fab51d8a7b19675559350df84e639993eccd17a1a2ccc98", "tokenizerSha256": "fe000e3ed39ed12b8d2481d527d44f93c65d37e87645d2dcc80d1bf9d50d2927", "chatTemplateSha256": "e611fbccc7c29ef3b1cafb1cb7ea548d189968632901d678fd62be68c47885de", "hiddenSize": 2048, diff --git a/browser-runtime/runtime-lock.schema.json b/browser-runtime/runtime-lock.schema.json index 5f51146..f6c65e8 100644 --- a/browser-runtime/runtime-lock.schema.json +++ b/browser-runtime/runtime-lock.schema.json @@ -28,10 +28,10 @@ ] }, "runtimeAbi": { - "const": "drowse-web-runtime-v2" + "const": "drowse-web-runtime-v3" }, "hookAbi": { - "const": "block-sites-v5" + "const": "block-sites-v6" }, "exactReadoutAbi": { "const": "exact-readout-v2" @@ -320,8 +320,8 @@ }, "structuredHookProfile": { "enum": [ - "standard-v4", - "standard-v4-residual" + "standard-v5", + "standard-v5-residual" ] }, "thinkingProfile": { @@ -444,7 +444,7 @@ "if": { "properties": { "structuredHookProfile": { - "const": "standard-v4" + "const": "standard-v5" } } }, diff --git a/browser-runtime/validate_mlc_q4_parity.py b/browser-runtime/validate_mlc_q4_parity.py index a9a31ff..6df9560 100644 --- a/browser-runtime/validate_mlc_q4_parity.py +++ b/browser-runtime/validate_mlc_q4_parity.py @@ -343,7 +343,7 @@ def load_capture_metadata(capture_directory: Path) -> dict[str, Any]: not isinstance(program, dict) or set(program) != {"format", "enabledLayer", "probeDirections", "target", "along", "kappa"} - or program["format"] != "drowse-structured-v4" + or program["format"] != "drowse-structured-v5" or program["enabledLayer"] not in layers or not isinstance(program["probeDirections"], list) or not 1 <= len(program["probeDirections"]) <= 8 diff --git a/browser-runtime/vendor/drowse-web-llm-0.2.84-drowse.49.tgz b/browser-runtime/vendor/drowse-web-llm-0.2.84-drowse.49.tgz deleted file mode 100644 index d0ba66d..0000000 Binary files a/browser-runtime/vendor/drowse-web-llm-0.2.84-drowse.49.tgz and /dev/null differ diff --git a/browser-runtime/vendor/drowse-web-llm-0.2.84-drowse.50.tgz b/browser-runtime/vendor/drowse-web-llm-0.2.84-drowse.50.tgz new file mode 100644 index 0000000..6c10065 Binary files /dev/null and b/browser-runtime/vendor/drowse-web-llm-0.2.84-drowse.50.tgz differ diff --git a/drowse b/drowse index 52ec038..d47bf53 160000 --- a/drowse +++ b/drowse @@ -1 +1 @@ -Subproject commit 52ec038981b0e3d3d991d272d7b0d836be271951 +Subproject commit d47bf5365f7e199404dbf003894f195e14d4eaf1 diff --git a/package-lock.json b/package-lock.json index ab94634..54f75f7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1586,9 +1586,9 @@ } }, "node_modules/@drowse/web-llm": { - "version": "0.2.84-drowse.49", - "resolved": "file:browser-runtime/vendor/drowse-web-llm-0.2.84-drowse.49.tgz", - "integrity": "sha512-tuCDWSEuu4vuKvkUlvltyTMusvS/Gvb6K7TQuUhWRZSMe6huZb/zCwCyRTJy65ia+gMGJG/hlqneuzUxBJT4ww==", + "version": "0.2.84-drowse.50", + "resolved": "file:browser-runtime/vendor/drowse-web-llm-0.2.84-drowse.50.tgz", + "integrity": "sha512-oSBUJ1EUzy1aqIYf5M/C114Xv7gx5mlUFIqGOAbIKllPHjZuRijPEDj+XAr/Avqv89yydi0Hbu5/hPb8BpLSkw==", "license": "Apache-2.0", "dependencies": { "loglevel": "1.9.2" @@ -2495,9 +2495,9 @@ ] }, "node_modules/@stdlogits/ledger": { - "version": "0.1.1", - "resolved": "https://codeload.github.com/stdlogits/ledger/tar.gz/refs/tags/v0.1.1", - "integrity": "sha512-u6OSVmjTCZopmKPsTblz6KNX4EVfd+jwxWRl+IdaDU+SXIBPjfZz/ICNc8kBxE+n4dgWC8W3MJjlNves9ictrQ==", + "version": "0.1.5", + "resolved": "https://codeload.github.com/stdlogits/ledger/tar.gz/refs/tags/v0.1.5", + "integrity": "sha512-lDNXZ9oCIivfzFUmgCc1EtdoeXUIL3lbzO7Gm+E5JUMOmlvcJqPns6Opvj/VzcJ+dohfEuMRlWStGt8PKdpqrw==", "license": "AGPL-3.0-or-later", "dependencies": { "torph": "0.1.3" @@ -6898,9 +6898,9 @@ "name": "drowse-ai-webui", "version": "0.0.0", "dependencies": { - "@drowse/web-llm": "file:../browser-runtime/vendor/drowse-web-llm-0.2.84-drowse.49.tgz", + "@drowse/web-llm": "file:../browser-runtime/vendor/drowse-web-llm-0.2.84-drowse.50.tgz", "@noble/hashes": "2.3.0", - "@stdlogits/ledger": "https://codeload.github.com/stdlogits/ledger/tar.gz/refs/tags/v0.1.1", + "@stdlogits/ledger": "https://codeload.github.com/stdlogits/ledger/tar.gz/refs/tags/v0.1.5", "fflate": "0.8.3", "yaml": "2.9.0" }, diff --git a/tests/test_browser_production_toolchain.py b/tests/test_browser_production_toolchain.py index c1989cb..5ed10a3 100644 --- a/tests/test_browser_production_toolchain.py +++ b/tests/test_browser_production_toolchain.py @@ -344,7 +344,7 @@ def test_verify_build_manifest_closes_and_hashes_every_artifact(tmp_path: Path): "schemaVersion": 1, "runtimeAbi": TOOL.RUNTIME_ABI, "hookAbi": TOOL.HOOK_ABI, - "structuredHookProfile": "standard-v4", + "structuredHookProfile": "standard-v5", "thinkingProfile": thinking_profile, "architecture": "qwen3", "quantization": "q4f16_1", @@ -392,7 +392,7 @@ def test_gemma_unquantized_manifest_requires_precise_normalization_provenance(tm entry = lambda file: {"path": file.name, "bytes": file.stat().st_size, "sha256": TOOL.sha256(file)} # noqa: E731 manifest = { "schemaVersion": 1, "runtimeAbi": TOOL.RUNTIME_ABI, - "hookAbi": TOOL.HOOK_ABI, "structuredHookProfile": "standard-v4", + "hookAbi": TOOL.HOOK_ABI, "structuredHookProfile": "standard-v5", "thinkingProfile": None, "architecture": "gemma3_text", "quantization": "q0f32", "weightEncoding": "raw", "toolchain": TOOL.toolchain_manifest("gemma3_text"), "files": [entry(tensor_cache), entry(chat)], @@ -574,7 +574,7 @@ def test_rebind_carries_a_published_conversion_to_the_current_abi_byte_for_byte( "manifestSha256": hashlib.sha256(b"{\"records\": []}").hexdigest()} lock.write_text(json.dumps({"models": [entry]})) args = SimpleNamespace(model=source, output=tmp_path / "rebound", architecture="gemma3_text", - quantization="q4f32_1", structured_hook_profile="standard-v4", + quantization="q4f32_1", structured_hook_profile="standard-v5", model_id="gemma3-1b-instruct", runtime_lock=lock) TOOL.rebind(args) @@ -585,7 +585,7 @@ def test_rebind_carries_a_published_conversion_to_the_current_abi_byte_for_byte( manifest = json.loads((rebound / "drowse-build.json").read_text()) assert manifest["files"] == files and manifest["source"] == previous["source"] assert (manifest["runtimeAbi"], manifest["hookAbi"], manifest["structuredHookProfile"]) == ( - TOOL.RUNTIME_ABI, TOOL.HOOK_ABI, "standard-v4") + TOOL.RUNTIME_ABI, TOOL.HOOK_ABI, "standard-v5") assert manifest["toolchain"] == TOOL.toolchain_manifest("gemma3_text") assert manifest["rebind"]["fromHookAbi"] == "post-block-residual-v4" assert manifest["rebind"]["fromToolchain"] == {"mlcLlmBaseCommit": "old"} @@ -636,7 +636,7 @@ def test_rebind_gives_the_chat_config_the_bridges_conversation_rules(tmp_path: P "id": "gemma3-1b-instruct", "architecture": "gemma3_text", "quantization": "q4f32_1", "manifestSha256": hashlib.sha256(b"{\"records\": []}").hexdigest()}]})) TOOL.rebind(SimpleNamespace(model=source, output=tmp_path / "rebound", architecture="gemma3_text", - quantization="q4f32_1", structured_hook_profile="standard-v4", + quantization="q4f32_1", structured_hook_profile="standard-v5", model_id="gemma3-1b-instruct", runtime_lock=lock)) rebound = tmp_path / "rebound" rules = {"drowse_system_fold_sep": "\n\n", "drowse_content_trim": True} @@ -651,7 +651,7 @@ def test_rebind_gives_the_chat_config_the_bridges_conversation_rules(tmp_path: P # Rebinding a conversion that already carries them leaves its chat config byte for byte. again = tmp_path / "again" TOOL.rebind(SimpleNamespace(model=rebound, output=again, architecture="gemma3_text", - quantization="q4f32_1", structured_hook_profile="standard-v4", + quantization="q4f32_1", structured_hook_profile="standard-v5", model_id="gemma3-1b-instruct", runtime_lock=lock)) assert (again / "mlc-chat-config.json").read_bytes() == (rebound / "mlc-chat-config.json").read_bytes() assert "conversationRules" not in json.loads((again / "drowse-build.json").read_text())["rebind"] diff --git a/tests/test_hosted_packs.py b/tests/test_hosted_packs.py index b7d6f77..3e43295 100644 --- a/tests/test_hosted_packs.py +++ b/tests/test_hosted_packs.py @@ -1,54 +1,17 @@ -"""The hosted pack builder against drowse's tiny ABI v5 fixture: every shipped -tensor is the session's own (and the unit-artifacts golden's), every binding -names the identity it averages over.""" +"""The hosted pack builder's pure helpers: the packed vocabulary mask and the population split.""" from __future__ import annotations -import json import sys from pathlib import Path -import numpy as np -import pytest import torch -from safetensors.torch import load_file ROOT = Path(__file__).parents[1] sys.path.insert(0, str(ROOT / "browser-runtime")) sys.path.insert(0, str(ROOT / "drowse")) -from build_hosted_packs import ( # noqa: E402 - ATTRIBUTION, - NATIVE_CORPUS, - corpus_attribution, - KINDS, - NativeModel, - PackBuildError, - build, - mask_words, - sha256_file, - split_population, - unpack_mask_words, -) - -GOLDENS = ROOT / "drowse" / "tests" / "fixtures" / "browser" - - -def runtime_record(model: NativeModel) -> dict: - identity = { - "sourceModel": "fixture/units-tiny", - "sourceRevision": "f" * 40, - "convertedManifestSha256": "0" * 64, - "quantization": "q0f32", - "tokenizerSha256": "1" * 64, - "chatTemplateSha256": "2" * 64, - "modelLibrarySha256": "3" * 64, - "runtimeAbi": "drowse-web-runtime-v2", - "hookAbi": "block-sites-v5", - "hiddenSize": model.d_model, - "layerMap": list(range(model.n_layers)), - } - return {"modelId": "units-tiny", "runtimeIdentity": identity, "runtimeIdentitySha256": "a" * 64} +from build_hosted_packs import mask_words, split_population, unpack_mask_words # noqa: E402 def test_mask_words_set_bit_v_of_word_v_over_32() -> None: @@ -70,179 +33,3 @@ def test_split_population_keeps_vocabulary_statistics_apart() -> None: assert sorted(reads) == [ "R.writes.lse", "R.writes.rho", "S.fires+.norm", "heads.norm_derivative.query", "neurons.write_norms", ] - - -@pytest.fixture(scope="module", params=["gemma3", "qwen3"]) -def built(request, tmp_path_factory): - from tests.support.browser_units import fixture - - with fixture(request.param) as fx: - model = NativeModel(fx.session) - runtime = runtime_record(model) - out = tmp_path_factory.mktemp(request.param) / "packs" - record = build(model, runtime, out, KINDS, full_depth=False, words=["a", "e", "t"]) - yield request.param, fx, model, runtime, out, record - - -def test_lens_packs_bind_the_runtime_and_ship_the_native_shards(built) -> None: - from drowse.lens.store import lens_identity - - _, _, model, runtime, out, record = built - for family, kind in (("R", "jlens"), ("S", "slens")): - pack = out / kind / "packs" / kind - manifest_text = (pack / "manifest.json").read_text() - manifest = json.loads(manifest_text) - native, _, native_identity = model.lens_source(family) - assert manifest["kind"] == family - assert manifest["model_fingerprint"] == runtime["runtimeIdentitySha256"] - assert manifest["model_source_fingerprint"] == runtime["runtimeIdentity"]["sourceRevision"] - bound = ("sites", "model_fingerprint", "model_source_fingerprint", "model_layer_count") - assert manifest["model_layer_count"] == model.n_layers - assert {k: v for k, v in manifest.items() if k not in bound} == { - k: v for k, v in native.items() if k not in bound - } - assert record["packs"][kind]["lens_identity"] == lens_identity(manifest) - assert record["packs"][kind]["native"]["lens_identity"] == native_identity - for site, entry in manifest["sites"].items(): - assert entry["layers"] == native["sites"][site]["layers"] - assert entry["tensor_sha256"] == native["sites"][site]["tensor_sha256"] - for layer in entry["layers"]: - assert entry["tensor_files"][str(layer)] == f"{site}.layer-{layer}.safetensors" - tensors = load_file(pack / entry["tensor_files"][str(layer)]) - assert list(tensors) == [f"layer_{layer}"] - lens = model.session.lens.resident() if family == "R" else model.session.lens.resident_input() - assert torch.equal(tensors[f"layer_{layer}"], lens.matrix(layer, site).float().cpu()) - - -def test_slens_pack_carries_the_sessions_embedding_statistics(built) -> None: - from drowse.lens.token_counts import tokenizer_fingerprint - - _, _, model, runtime, out, _ = built - pack = out / "slens" / "packs" / "slens" - record = json.loads((pack / "embedding-statistics.json").read_text()) - tensors = load_file(pack / record["tensor_file"]) - emb = model.session.lens.token_embeddings() - raw = (pack / record["mask_file"]).read_bytes() - assert len(raw) == 4 * record["mask_words"] - words = torch.from_numpy(np.frombuffer(raw, dtype=" None: - from tests.support.browser_units import decode - - arch, _, model, _, out, record = built - pack = out / "units" / "packs" / "units" - units = json.loads((pack / "units.json").read_text()) - assert units["binding"]["r_lens_identity"] == record["packs"]["jlens"]["lens_identity"] - assert units["binding"]["s_lens_identity"] == record["packs"]["slens"]["lens_identity"] - assert units["binding"]["embedding_statistics_sha256"] == record["packs"]["slens"]["embedding_statistics"]["sha256"] - golden = json.loads((GOLDENS / f"unit-artifacts-{arch}-v1.json").read_text()) - tolerance = golden["tolerance"]["python"] - assert len(units["layers"]) == len(golden["layers"]) == model.n_layers - for entry in golden["layers"]: - shipped = {} - for part in ("reads", "contrast"): - spec = units["layers"][str(entry["layer"])][part] - tensors = load_file(pack / spec["file"]) - assert sorted(tensors) == sorted(spec["shapes"]) - assert all(value.ndim <= 2 for value in tensors.values()) - shipped.update({name: value.reshape(spec["shapes"][name]) for name, value in tensors.items()}) - assert sorted(shipped) == sorted(entry["tensors"]) - for name, value in entry["tensors"].items(): - np.testing.assert_allclose( - shipped[name].numpy(), decode(value).astype(np.float32), - atol=tolerance["atol"], rtol=tolerance["rtol"], err_msg=f"L{entry['layer']} {name}", - ) - null = load_file(pack / units["null"]["file"])["null_basis"].double() - assert units["null"]["rank"] == golden["null"]["rank"] - np.testing.assert_allclose((null @ null.T).numpy(), decode(golden["null"]["projector"]), atol=1e-5) - emb = model.session.lens.token_embeddings() - kept = emb.keep.nonzero().squeeze(1) - expected = kept[kept < units["head_kept"]["unembedding_rows"]] - assert expected.tolist() == decode(golden["head_kept_ids"]).tolist() - assert units["head_kept"]["count"] == expected.numel() - - -def test_core_statistics_stack_the_neutral_pass(built) -> None: - _, fx, model, runtime, out, _ = built - record = json.loads((out / "core" / "neutral-statistics.json").read_text()) - tensors = { - name: value.reshape(record["shapes"][name]) - for name, value in load_file(out / "core" / record["tensor_file"]).items() - } - stats = fx.session.units.runtime.stats() - assert record["n_documents"] == stats.n_documents - for layer in range(model.n_layers): - assert torch.equal(tensors["neuron_scale"][layer], stats.layer(layer).neuron_scale) - assert torch.equal(tensors["head_mean"][layer], stats.layer(layer).head_mean) - assert torch.equal(tensors["mid_mean"][layer], fx.session._neutral.site_means("mid")[layer]) - assert torch.equal(tensors["out_mean"][layer], fx.session.layer_means[layer]) - - -def test_core_rows_are_the_whiteners_and_units_bind_them(built) -> None: - """The core builder fits the core pack's whitener from these rows, so the units pack's - write norms and the browser's whitener share one metric; units bind the rows' digest.""" - from drowse.geometry.whitener import LayerWhitener - - _, fx, model, _, out, record = built - core = json.loads((out / "core" / "neutral-statistics.json").read_text()) - rows_file = out / "core" / core["neutral_rows"]["file"] - assert core["neutral"]["rows_sha256"] == sha256_file(rows_file) - rows = load_file(rows_file) - assert sorted(rows) == sorted(f"layer_{layer}" for layer in range(model.n_layers)) - rebuilt = LayerWhitener.from_neutral_activations( - {layer: rows[f"layer_{layer}"] for layer in range(model.n_layers)}, fx.session.layer_means, - ) - session = fx.session._neutral.whitener() - probe = torch.linspace(-1.0, 1.0, model.d_model) - for layer in range(model.n_layers): - assert rows[f"layer_{layer}"].shape[0] == core["neutral_rows"]["rows"] - assert rebuilt.mahalanobis_norm(layer, probe) == pytest.approx(session.mahalanobis_norm(layer, probe), rel=1e-6) - units = json.loads((out / "units" / "packs" / "units" / "units.json").read_text()) - assert units["binding"]["neutral"] == core["neutral"] == record["packs"]["core"]["neutral"] - - -def test_units_need_the_core_statistics_and_the_write_norms(built, tmp_path, monkeypatch) -> None: - _, _, model, runtime, _, _ = built - with pytest.raises(PackBuildError, match="core statistics"): - build(model, runtime, tmp_path / "a", ["jlens", "slens", "units"], full_depth=False, words=["a"]) - reads = model.session.units.reads - original = reads.population_artifacts - - def without_write_norms(layer): - return {k: v for k, v in original(layer).items() if k != "neurons.write_norms"} - - monkeypatch.setattr(reads, "population_artifacts", without_write_norms) - with pytest.raises(PackBuildError, match="write_norms"): - build(model, runtime, tmp_path / "b", KINDS, full_depth=False, words=["a"]) - assert not list(tmp_path.iterdir()) - - -def test_release_packs_refuse_a_lens_short_of_full_depth(built, tmp_path) -> None: - _, _, model, runtime, _, _ = built - with pytest.raises(PackBuildError, match="every layer|shape"): - build(model, runtime, tmp_path / "packs", ["jlens"]) - assert not list(tmp_path.iterdir()) - - -def test_lens_and_units_packs_carry_the_approved_corpus_attribution(built, tmp_path) -> None: - _, _, _, _, out, _ = built - corpus = json.loads(NATIVE_CORPUS.read_text()) - for kind in ("jlens", "slens", "units"): - text = (out / kind / "packs" / kind / ATTRIBUTION).read_text() - assert text == corpus_attribution() - for required in (corpus["attributionApproval"]["attribution"], corpus["dataset"]["url"], - corpus["dataset"]["license"], corpus["corpusSpec"]): - assert required in text - pending = tmp_path / "corpus.json" - pending.write_text(json.dumps({**corpus, "attributionApproval": None})) - with pytest.raises(PackBuildError, match="not approved"): - corpus_attribution(pending) diff --git a/tests/test_record_cvm_goldens.py b/tests/test_record_cvm_goldens.py deleted file mode 100644 index e5c63b3..0000000 --- a/tests/test_record_cvm_goldens.py +++ /dev/null @@ -1,96 +0,0 @@ -"""The C TVM VM evidence observer: one direct observation from verify-mlc-hook's two runs.""" - -from __future__ import annotations - -import importlib.util -import json -from argparse import Namespace -from pathlib import Path - -import pytest - -ROOT = Path(__file__).resolve().parents[1] -SPEC = importlib.util.spec_from_file_location("record_cvm_goldens", ROOT / "browser-runtime" / "record-cvm-goldens.py") -observer = importlib.util.module_from_spec(SPEC) -SPEC.loader.exec_module(observer) - -SUITES = {"block-sites": 7.6e-6, "unit-ablation": 1.2e-5, "unit-probes": 9.9e-7} -UNITS_LINE = ( - "units goldens (block-sites, unit-ablation, unit-probes, attention-patterns, token-anatomy, " - "unit-activity) passed on the C TVM VM: " + json.dumps({key: SUITES for key in observer.LIBRARIES}) -) - - -def fake_run(outputs): - calls = [] - - def run(python, arguments, environment): - calls.append(arguments) - return outputs[len(calls) - 1] - - return run, calls - - -def args(tmp_path: Path) -> Namespace: - for key in observer.LIBRARIES: - arch, quantization = key.split("-", 1) - model = tmp_path / "fixtures" / f"units-{arch}-{quantization}" - model.mkdir(parents=True, exist_ok=True) - (model / "tensor-cache.json").write_text(key) - return Namespace(python=tmp_path / "python", mlc_repository=tmp_path / "mlc", tvm_repository=tmp_path / "tvm", - units_fixtures=tmp_path / "fixtures") - - -def test_observation_carries_every_library_and_suite(monkeypatch, tmp_path) -> None: - run, calls = fake_run(["... compiled C/LLVM golden checks passed\n", f"units goldens qwen3 q0f32: ...\n{UNITS_LINE}\n"]) - monkeypatch.setattr(observer, "run", run) - observation = observer.observe(args(tmp_path)) - assert observation["evidenceType"] == "cVmGoldens" - assert observation["fixturePath"] == "drowse/tests/fixtures/browser/units-tiny-models-v1.json" - import hashlib - assert observation["results"]["libraries"] == { - key: {"modelSha256": hashlib.sha256(key.encode()).hexdigest(), "suites": SUITES} for key in observer.LIBRARIES - } - assert calls[0][-1] == str(tmp_path / "tvm") and calls[1][-2:] == ["--units-fixtures", str(tmp_path / "fixtures")] - assert sorted(observation) == ["evidenceType", "fixturePath", "passed", "producedAt", "results", "schemaVersion"] - - -def test_a_missing_library_or_default_run_is_refused(monkeypatch, tmp_path) -> None: - partial = UNITS_LINE.split(": ", 1)[0] + ": " + json.dumps({"qwen3-q0f32": SUITES}) - monkeypatch.setattr(observer, "run", fake_run(["compiled C/LLVM golden checks passed", partial])[0]) - with pytest.raises(observer.ObservationError, match="covered"): - observer.observe(args(tmp_path)) - monkeypatch.setattr(observer, "run", fake_run(["nothing", UNITS_LINE])[0]) - with pytest.raises(observer.ObservationError, match="default structured"): - observer.observe(args(tmp_path)) - - -def test_the_toolchain_environment_is_the_exact_source_roots(tmp_path) -> None: - environment = observer.toolchain_environment(tmp_path / "mlc", tmp_path / "tvm") - assert environment["PYTHONPATH"].split(":") == [str(tmp_path / "tvm" / "python"), str(tmp_path / "mlc" / "python")] - assert environment["TVM_DEVICE_BACKEND_AUTOLOAD"] == "0" and environment["SKIP_LOADING_MLCLLM_SO"] == "1" - - -def test_the_toolchain_libraries_are_found_in_build_lib(tmp_path) -> None: - (tmp_path / "tvm" / "build" / "lib").mkdir(parents=True) - environment = observer.toolchain_environment(tmp_path / "mlc", tmp_path / "tvm") - assert environment["TVM_LIBRARY_PATH"] == str(tmp_path / "tvm" / "build" / "lib") - - -def test_a_virtual_environment_python_keeps_its_path(tmp_path) -> None: - base = tmp_path / "base" / "python3" - base.parent.mkdir() - base.write_text("") - venv = tmp_path / "venv" / "bin" - venv.mkdir(parents=True) - (venv / "python").symlink_to(base) - for name in ("mlc", "tvm", "fixtures"): - (tmp_path / name).mkdir() - args = observer.parse_args([ - "--python", str(venv / "python"), - "--mlc-repository", str(tmp_path / "mlc"), - "--tvm-repository", str(tmp_path / "tvm"), - "--units-fixtures", str(tmp_path / "fixtures"), - ]) - assert args.python == venv / "python" - diff --git a/tests/test_validate_mlc_q4_parity.py b/tests/test_validate_mlc_q4_parity.py index e1a8d90..2b51bcd 100644 --- a/tests/test_validate_mlc_q4_parity.py +++ b/tests/test_validate_mlc_q4_parity.py @@ -55,7 +55,7 @@ def capture_metadata( "control_probe_sha256": "6" * 64, "steered_probe_sha256": "3" * 64, "steering_program": { - "format": "drowse-structured-v4", + "format": "drowse-structured-v5", "enabledLayer": 1, "probeDirections": [[0.6, 0.8], [0.8, -0.6]], "target": 1.25, diff --git a/webui/e2e/fitting-worker.spec.ts b/webui/e2e/fitting-worker.spec.ts index 1cd533e..d28bda5 100644 --- a/webui/e2e/fitting-worker.spec.ts +++ b/webui/e2e/fitting-worker.spec.ts @@ -171,7 +171,7 @@ test("streams reduced covariances and fits a curved sigma field", async ({ page source: { kind: "activation_spool", identity, layer: 3 }, offsets: new Uint32Array([0, 2, 4, 6]), mean: new Float64Array([0, 0]), - basis: new Float64Array([1, 0, 0, 1]), + read: new Float64Array([1, 0, 0, 1]), components: 2, }); if (covariance.operation !== "reduced_covariances") { diff --git a/webui/e2e/units.spec.ts b/webui/e2e/units.spec.ts index 7354943..0276909 100644 --- a/webui/e2e/units.spec.ts +++ b/webui/e2e/units.spec.ts @@ -274,7 +274,7 @@ test("neurons and heads steer from the picker, the recipe and the rooms", async : `${silenced} ${negative ? "-" : "+"} 3 ${unitName}`); }); -// The base layout fixture's model is Pythia, whose library is residual (standard-v4-residual): its +// The base layout fixture's model is Pythia, whose library is residual (standard-v5-residual): its // units members answer through BrowserUnitsService with the lock's refusal (fixtureHostedRuntime.ts). const PYTHIA_REFUSAL = "layer 0: block has no softmax self-attention ('self_attn'; found attention, input_layernorm, mlp, post_attention_dropout, post_attention_layernorm, post_mlp_dropout)"; diff --git a/webui/package.json b/webui/package.json index f9f3fd0..c55b54b 100644 --- a/webui/package.json +++ b/webui/package.json @@ -48,7 +48,7 @@ "check:hosted": "node ./scripts/check-runtime-lock.mjs && node ./scripts/hosted-tools.test.mjs && node ./scripts/prepare-hosted-candidate-lock.test.mjs && node ./scripts/capture-hosted-residuals.test.mjs && npm run test:browser-runtime:full:contract && npm run test:preflight-tools && npm run test:release-tools && npm run test:fork-overlays && node --test ./scripts/tool-http-errors.test.mjs", "check:theme": "node ./scripts/check-theme.mjs", "test:entry": "node ./scripts/build-error-lifecycle.test.mjs && node ./scripts/entry-experience.test.mjs && node ./scripts/update-reminder.test.mjs && node ./scripts/chunk-recovery.test.mjs && node ./scripts/recorded-demo.test.mjs && node ./scripts/not-found-recording.test.mjs && node ./scripts/landing-models.test.mjs && node ./scripts/format-bytes.test.mjs", - "test:runtime": "node ./scripts/brand-migration.test.mjs && node ./scripts/runtime-foundation.test.mjs && node ./scripts/catalog-repository.test.mjs && node ./scripts/instrument-availability.test.mjs && node ./scripts/legacy-runtime-storage.test.mjs && node ./scripts/legacy-storage-browser.test.mjs && node ./scripts/content-store-browser.test.mjs && node ./scripts/iphone-storage.test.mjs && node ./scripts/worker-runtime.test.mjs && node ./scripts/network-state.test.mjs && node ./scripts/hosted-policy.test.mjs && node ./scripts/ios-runtime-policy.test.mjs && node ./scripts/shell-controller.test.mjs && node ./scripts/session-persistence.test.mjs && node ./scripts/session-coordinator.test.mjs && node ./scripts/browser-tree-filter.test.mjs && node ./scripts/browser-loom-diff.test.mjs && node ./scripts/browser-loom.test.mjs && node ./scripts/sampling-parity.test.mjs && node ./scripts/browser-analytics-ui.test.mjs && node ./scripts/artifact-service.test.mjs && node ./scripts/hf-manifolds.test.mjs && node ./scripts/structured-hook-program.test.mjs && node ./scripts/structured-hook-parity.test.mjs && node ./scripts/structured-hook-units.test.mjs && node ./scripts/block-sites-backend.test.mjs && node ./scripts/web-llm-block-sites.test.mjs && node ./scripts/units-reference-backend.test.mjs && node ./scripts/units-lens-reads.test.mjs && node ./scripts/units-unit-reads.test.mjs && node ./scripts/units-activity.test.mjs && node ./scripts/units-anatomy.test.mjs && node ./scripts/units-service.test.mjs && node ./scripts/units-probes.test.mjs && node ./scripts/units-probe-digest.test.mjs && node ./scripts/units-compiler.test.mjs && node ./scripts/units-pack-source.test.mjs && node ./scripts/steering-term-layers.test.mjs && node ./scripts/manifold-robustness.test.mjs && node ./scripts/browser-core-pack.test.mjs && node ./scripts/hosted-pack-residency.test.mjs && node ./scripts/steering-expression.test.mjs && node ./scripts/hook-capabilities.test.mjs && node ./scripts/verified-artifact-cache.test.mjs && node ./scripts/web-llm-engine.test.mjs && node ./scripts/web-llm-generation.test.mjs && node ./scripts/qwen-hybrid-contract.test.mjs && node ./scripts/drowse-web-llm-backend.test.mjs && node ./scripts/browser-manifold-fitting.test.mjs && node ./scripts/activation-spool.test.mjs && node ./scripts/fitting-wasm-browser.test.mjs && node ./scripts/fitting-worker-client.test.mjs && node ./scripts/fitting-coordinator.test.mjs && node ./scripts/base-capture-parity.test.mjs", + "test:runtime": "node ./scripts/brand-migration.test.mjs && node ./scripts/runtime-foundation.test.mjs && node ./scripts/catalog-repository.test.mjs && node ./scripts/instrument-availability.test.mjs && node ./scripts/legacy-runtime-storage.test.mjs && node ./scripts/legacy-storage-browser.test.mjs && node ./scripts/content-store-browser.test.mjs && node ./scripts/iphone-storage.test.mjs && node ./scripts/worker-runtime.test.mjs && node ./scripts/network-state.test.mjs && node ./scripts/hosted-policy.test.mjs && node ./scripts/ios-runtime-policy.test.mjs && node ./scripts/shell-controller.test.mjs && node ./scripts/session-persistence.test.mjs && node ./scripts/session-coordinator.test.mjs && node ./scripts/browser-tree-filter.test.mjs && node ./scripts/browser-loom-diff.test.mjs && node ./scripts/browser-loom.test.mjs && node ./scripts/browser-analytics-ui.test.mjs && node ./scripts/artifact-service.test.mjs && node ./scripts/hf-manifolds.test.mjs && node ./scripts/structured-hook-program.test.mjs && node ./scripts/structured-hook-units.test.mjs && node ./scripts/block-sites-backend.test.mjs && node ./scripts/web-llm-block-sites.test.mjs && node ./scripts/units-reference-backend.test.mjs && node ./scripts/units-probe-digest.test.mjs && node ./scripts/manifold-robustness.test.mjs && node ./scripts/browser-core-pack.test.mjs && node ./scripts/hosted-pack-residency.test.mjs && node ./scripts/steering-expression.test.mjs && node ./scripts/hook-capabilities.test.mjs && node ./scripts/verified-artifact-cache.test.mjs && node ./scripts/web-llm-engine.test.mjs && node ./scripts/web-llm-generation.test.mjs && node ./scripts/qwen-hybrid-contract.test.mjs && node ./scripts/drowse-web-llm-backend.test.mjs && node ./scripts/browser-manifold-fitting.test.mjs && node ./scripts/activation-spool.test.mjs && node ./scripts/fitting-wasm-browser.test.mjs && node ./scripts/fitting-worker-client.test.mjs && node ./scripts/fitting-coordinator.test.mjs && node ./scripts/base-capture-parity.test.mjs", "test:e2e": "playwright test", "test:hosted": "npm run test:runtime && node ./scripts/drowse-archive-browser.test.mjs && npm run build:hosted && node ./scripts/check-hosted-build.mjs", "test:webmcp": "node ./scripts/webmcp-generation.test.mjs && node ./scripts/webmcp-queue.test.mjs && node ./scripts/webmcp-services.test.mjs && node ./scripts/webmcp-workspace.test.mjs && node ./scripts/webmcp-hosted.test.mjs && node ./scripts/webmcp-ui.test.mjs", @@ -72,9 +72,9 @@ "nanoid": "3.3.18" }, "dependencies": { - "@drowse/web-llm": "file:../browser-runtime/vendor/drowse-web-llm-0.2.84-drowse.49.tgz", + "@drowse/web-llm": "file:../browser-runtime/vendor/drowse-web-llm-0.2.84-drowse.50.tgz", "@noble/hashes": "2.3.0", - "@stdlogits/ledger": "https://codeload.github.com/stdlogits/ledger/tar.gz/refs/tags/v0.1.1", + "@stdlogits/ledger": "https://codeload.github.com/stdlogits/ledger/tar.gz/refs/tags/v0.1.5", "fflate": "0.8.3", "yaml": "2.9.0" } diff --git a/webui/public-hosted/wasm/drowse_fitting_wasm.js b/webui/public-hosted/wasm/drowse_fitting_wasm.js index 61679f4..c437160 100644 --- a/webui/public-hosted/wasm/drowse_fitting_wasm.js +++ b/webui/public-hosted/wasm/drowse_fitting_wasm.js @@ -148,6 +148,22 @@ export class AffineFisherFit { const ret = wasm.affinefisherfit_nodeCount(this.__wbg_ptr); return ret >>> 0; } + /** + * @returns {Float64Array} + */ + read() { + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); + wasm.affinefisherfit_read(retptr, this.__wbg_ptr); + var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true); + var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true); + var v1 = getArrayF64FromWasm0(r0, r1).slice(); + wasm.__wbindgen_export(r0, r1 * 8, 8); + return v1; + } finally { + wasm.__wbindgen_add_to_stack_pointer(16); + } + } /** * @returns {Float64Array} */ diff --git a/webui/public-hosted/wasm/drowse_fitting_wasm_bg.wasm b/webui/public-hosted/wasm/drowse_fitting_wasm_bg.wasm index c715573..de26826 100644 Binary files a/webui/public-hosted/wasm/drowse_fitting_wasm_bg.wasm and b/webui/public-hosted/wasm/drowse_fitting_wasm_bg.wasm differ diff --git a/webui/public-hosted/wasm/fitting-kernel.json b/webui/public-hosted/wasm/fitting-kernel.json index f3c9980..974d5d4 100644 --- a/webui/public-hosted/wasm/fitting-kernel.json +++ b/webui/public-hosted/wasm/fitting-kernel.json @@ -7,13 +7,13 @@ "files": [ { "name": "drowse_fitting_wasm.js", - "bytes": 110239, - "sha256": "61e5ab58781847659d133228d30fd86f02bea47d51ab02f53bf4bc1c914d02d6" + "bytes": 110817, + "sha256": "385035a4de2e132608a7c6b15247a3ff14f68c6cfc6622631ad7a88d7f15a612" }, { "name": "drowse_fitting_wasm_bg.wasm", - "bytes": 311178, - "sha256": "035502c7cb01c4f4d1f951a56c35d1422c7b6ac40de9c4d3c0e6af12fdbf595c" + "bytes": 311138, + "sha256": "52dc3a57413a72868e72e0f4bb5272fe0a1fce73878e53f1ff0d316a70ca5c5d" } ] } diff --git a/webui/scripts/artifact-service.test.mjs b/webui/scripts/artifact-service.test.mjs index 1157f44..fc8ba24 100644 --- a/webui/scripts/artifact-service.test.mjs +++ b/webui/scripts/artifact-service.test.mjs @@ -517,6 +517,7 @@ try { }, async list() { return []; }, async remove() { return false; }, + async paths() { return [...files.keys()].sort(); }, async file(_primary, path) { return files.get(path) ?? null; }, async export() { throw new Error("unused"); }, async clear() {}, @@ -699,6 +700,7 @@ function authoringHarness(validateDrowseArchive, BrowserDrowseArchiveService) { }); }, async remove(id) { return installs.delete(id); }, + async paths(id) { return installs.has(id) ? [...installs.get(id).files.keys()].sort() : null; }, async file(id, path) { const bytes = installs.get(id)?.files.get(path); return bytes ? new Blob([bytes]) : null; diff --git a/webui/scripts/assemble-hosted-model.mjs b/webui/scripts/assemble-hosted-model.mjs index c559852..98976e9 100644 --- a/webui/scripts/assemble-hosted-model.mjs +++ b/webui/scripts/assemble-hosted-model.mjs @@ -183,7 +183,7 @@ async function runtimeArtifacts(root, wasm, config, tensorCache, hookProfile) { throw new Error("model library is not a WebAssembly module"); } // Hook ABI v5's surface, from the overlay's own lists: every required function, and the unit - // functions exactly when the profile is standard-v4 (their absence attests the residual one). + // functions exactly when the profile is standard-v5 (their absence attests the residual one). requireLibraryVmFunctions(wasmBytes, hookProfile); result.push(await artifact(wasm, "model.wasm", "model_library")); return result; diff --git a/webui/scripts/assemble-hosted-model.test.mjs b/webui/scripts/assemble-hosted-model.test.mjs index 85de756..43b679e 100644 --- a/webui/scripts/assemble-hosted-model.test.mjs +++ b/webui/scripts/assemble-hosted-model.test.mjs @@ -60,9 +60,9 @@ try { join(converted, "drowse-build.json"), JSON.stringify({ schemaVersion: 1, - runtimeAbi: "drowse-web-runtime-v2", - hookAbi: "block-sites-v5", - structuredHookProfile: "standard-v4", + runtimeAbi: "drowse-web-runtime-v3", + hookAbi: "block-sites-v6", + structuredHookProfile: "standard-v5", thinkingProfile, architecture: "qwen3", quantization: "q4f16_1", @@ -99,17 +99,17 @@ try { const { required, unit } = OVERLAY_VM_FUNCTIONS; // A v4 build manifest, and a qwen3 build claiming the residual profile, are refused. await build({ hookAbi: "post-block-residual-v4", runtimeAbi: "drowse-web-runtime-v1" }); - await assert.rejects(assemble(), /predates hook ABI block-sites-v5/); - await build({ structuredHookProfile: "standard-v4-residual" }); - await assert.rejects(assemble(), /qwen3 libraries attest standard-v4, not standard-v4-residual/); + await assert.rejects(assemble(), /predates hook ABI block-sites-v6/); + await build({ structuredHookProfile: "standard-v5-residual" }); + await assert.rejects(assemble(), /qwen3 libraries attest standard-v5, not standard-v5-residual/); await build({}); - await assert.rejects(assemble(), /standard-v4 model library lacks required VM function drowse_attention_rows, /); + await assert.rejects(assemble(), /standard-v5 model library lacks required VM function drowse_attention_rows, /); // A units library without one unit function, then a residual one exporting a unit function. await library_([...required, ...unit.slice(1)]); await assert.rejects(assemble(), new RegExp(`lacks required VM function ${unit[0]}$`, "m")); - await build({ architecture: "gpt2", structuredHookProfile: "standard-v4-residual", modelType: "base" }); + await build({ architecture: "gpt2", structuredHookProfile: "standard-v5-residual", modelType: "base" }); await library_([...required, unit[0]]); - await assert.rejects(assemble(), new RegExp(`standard-v4-residual model library exports unit VM function ${unit[0]}`)); + await assert.rejects(assemble(), new RegExp(`standard-v5-residual model library exports unit VM function ${unit[0]}`)); await build({}); await library_([...required, ...unit]); await exec(process.execPath, [ @@ -121,8 +121,8 @@ try { const manifest = JSON.parse( await readFile(join(output, "hosted-artifacts.json"), "utf8"), ); - assert.equal(manifest.structuredHookProfile, "standard-v4"); - assert.equal(manifest.hookAbi, "block-sites-v5"); + assert.equal(manifest.structuredHookProfile, "standard-v5"); + assert.equal(manifest.hookAbi, "block-sites-v6"); assert.equal(manifest.hiddenSize, 4); assert.deepEqual(manifest.layerMap, [0, 1]); assert.deepEqual(manifest.thinkingProfile, thinkingProfile); diff --git a/webui/scripts/block-sites-backend.test.mjs b/webui/scripts/block-sites-backend.test.mjs index c72dda8..b61045c 100644 --- a/webui/scripts/block-sites-backend.test.mjs +++ b/webui/scripts/block-sites-backend.test.mjs @@ -20,8 +20,8 @@ try { server.ssrLoadModule("/src/hosted/runtime/fakeModelBackend.ts"), server.ssrLoadModule("/src/hosted/runtime/structuredHookProfile.ts"), ]); - const v4 = profiles.STANDARD_STRUCTURED_HOOK_PROFILE_V4; - const residual = profiles.STANDARD_STRUCTURED_HOOK_PROFILE_V4_RESIDUAL; + const v4 = profiles.STANDARD_STRUCTURED_HOOK_PROFILE_V5; + const residual = profiles.STANDARD_STRUCTURED_HOOK_PROFILE_V5_RESIDUAL; const members = backend.BLOCK_SITES_BACKEND_MEMBERS; assert.equal(new Set(members).size, members.length); assert.ok(backend.BLOCK_SITES_UNIT_MEMBERS.every((member) => members.includes(member))); @@ -61,7 +61,7 @@ try { ropeGlobalScale: 1, ropeInGraph: false, slidingWindow: null, slidingPattern: null, }); const capabilities = { - hookAbi: "block-sites-v5", runtimeAbi: "drowse-web-runtime-v2", exactReadoutAbi: "exact-readout-v2", + hookAbi: "block-sites-v6", runtimeAbi: "drowse-web-runtime-v3", exactReadoutAbi: "exact-readout-v2", profile: v4, layerCount: 36, hiddenSize: 2560, vocabSize: 151936, contextTokens: 4096, prefillChunkSize: 2048, blockSpec: spec, unitRefusal: null, }; diff --git a/webui/scripts/browser-core-build.mjs b/webui/scripts/browser-core-build.mjs deleted file mode 100644 index 70e5773..0000000 --- a/webui/scripts/browser-core-build.mjs +++ /dev/null @@ -1,335 +0,0 @@ -#!/usr/bin/env node -// The in-browser core build on a hook ABI v5 library: B4's tiny fixture libraries through the -// release worker itself (hosted-whitener.worker.ts), on WebGPU. -// -// node scripts/browser-core-build.mjs --webllm WEB_LLM/lib/index.js --fixtures DIR \ -// --arch qwen3|gemma3 --quantization q0f32|q4f32_1 --work DIR [--port N] [--headed] -// -// DIR holds build-units-fixtures.py's model directory `units--` and its -// library `libs/units---v5.wasm`, staged under --work as a base model -// (support/units-webgpu-stage.mjs). The worker then runs as build-hosted-whitener.mjs runs it: the -// load attests the library's schema-4 descriptor against the fixture's block spec, the neutral -// rows are captured (prepareCaptureRows, capturePreparedRow) and a whitener fitted, and a -// two-node and a one-node core concept are captured through the activation source and fitted. -// Then, through the same hosted runtime, the plain residual capture (the call both captures make) -// of the block-sites golden's ids is checked against drowse's `out` residuals at every layer and -// position, at the golden's library tolerance. -import { createServer as createHttpServer } from "node:http"; -import { readFile } from "node:fs/promises"; -import { basename, resolve } from "node:path"; -import { fileURLToPath } from "node:url"; -import { chromium } from "playwright"; -import { createServer as createViteServer } from "vite"; -import { releaseToolBrowserOptions, releaseToolGpuArgs } from "./release-tool-storage-quota.mjs"; -import { fixtureConcepts, goldensDirectory, stageUnitsFixture } from "./support/units-webgpu-stage.mjs"; - -const options = parseArguments(process.argv.slice(2)); -const webui = fileURLToPath(new URL("..", import.meta.url)); -const goldens = goldensDirectory; -const { - fixture, modelDirectory, roles, artifacts, blockSpec, layerCount, hiddenSize, contextTokens, prefillChunkSize, - runtimeIdentity, -} = await stageUnitsFixture(options); -// Short rows: the fixture's byte-level vocabulary spends a token per character, in a -// 128-token context. -const buildRequest = { - type: "run", - modelId: `units-${options.arch}`, - modelType: "base", - artifacts, - baselinePrompts: ["Hi.", "Go on.", "Say it."], - contexts: [contextTokens], - rows: ["The sky is blue.", "Water is wet.", "Cats can nap.", "Trees grow tall.", "Bread is warm.", - "Rain may fall.", "Birds can sing.", "Snow is cold."].map((content) => ({ - system: "", messages: [{ role: "user", content: "Hi." }, { role: "assistant", content }], - })), - nativeNeutralRows: false, - runtimeIdentity, - quantization: options.quantization, - requiredFeatures: [], - structuredHookProfile: "standard-v4", - thinkingProfile: null, - blockSpec, - unitRefusal: null, - prefillChunkSize, - artifactProducer: { drowseVersion: "0.0.0-fixture", producerVersion: "browser-core-build" }, - manifolds: fixtureConcepts(), -}; - -const blockSitesGolden = JSON.parse(await readFile(resolve(goldens, `block-sites-${options.arch}-v1.json`), "utf8")); -const goldenOut = decodeSite(blockSitesGolden.sites.out); -const goldenIds = blockSitesGolden.ids; -const tolerance = blockSitesGolden.tolerance.library; - -// ---------------------------------------------------------------------- the server --- -const outputs = { whitener: new Map(), manifolds: new Map() }; -const vite = await createViteServer({ - root: webui, configFile: false, appType: "custom", logLevel: "silent", - // The fitting worker loads its kernel from /wasm/ (the hosted public directory). - publicDir: resolve(webui, "public-hosted"), - server: { middlewareMode: true, hmr: false, watch: null }, -}); -const http = createHttpServer(async (request, response) => { - for (const [name, value] of Object.entries({ - "Cross-Origin-Opener-Policy": "same-origin", - "Cross-Origin-Embedder-Policy": "require-corp", - "Cross-Origin-Resource-Policy": "same-origin", - })) response.setHeader(name, value); - const send = (body, type, status = 200) => { - response.writeHead(status, { "content-type": type }); - response.end(body); - }; - try { - const url = new URL(request.url ?? "/", "http://127.0.0.1"); - if (url.pathname === "/") return send("core build", "text/html"); - if (url.pathname === "/worker.js") { - const transformed = await vite.transformRequest("/scripts/hosted-whitener.worker.ts"); - return send(transformed.code, "text/javascript"); - } - if (url.pathname === "/webllm.js") return send(await readFile(resolve(options.webllm)), "text/javascript"); - if (url.pathname === "/fitting.js") { - return send(await readFile(resolve(webui, "public-hosted/wasm/drowse_fitting_wasm.js")), "text/javascript"); - } - if (url.pathname === "/fitting.wasm") { - return send(await readFile(resolve(webui, "public-hosted/wasm/drowse_fitting_wasm_bg.wasm")), "application/wasm"); - } - if (url.pathname === "/model") { - const path = url.searchParams.get("path"); - if (!(path in roles)) return send("not found", "text/plain", 404); - return send(await readFile(resolve(modelDirectory, basename(path))), "application/octet-stream"); - } - if (request.method === "POST" && (url.pathname === "/output" || url.pathname === "/manifold-output")) { - const chunks = []; - for await (const chunk of request) chunks.push(chunk); - const key = url.pathname === "/output" - ? url.searchParams.get("context") - : `${url.searchParams.get("context")}:${url.searchParams.get("manifold")}`; - outputs[url.pathname === "/output" ? "whitener" : "manifolds"].set(key, Buffer.concat(chunks)); - return send("ok", "text/plain"); - } - vite.middlewares(request, response, () => send("not found", "text/plain", 404)); - } catch (error) { - console.error(error); - send(error instanceof Error ? error.message : "request failed", "text/plain", 500); - } -}); -await new Promise((ok) => http.listen(options.port, "127.0.0.1", ok)); -const origin = `http://127.0.0.1:${http.address().port}`; -const browser = await chromium.launch(releaseToolBrowserOptions({ - headless: !options.headed, args: releaseToolGpuArgs({ headless: !options.headed }), -})); -let failures = 0; -const check = (label, ok, detail = "") => { - if (!ok) failures += 1; - console.log(`${ok ? "ok" : "FAIL"} - ${label}${detail ? `: ${detail}` : ""}`); -}; -try { - const page = await browser.newPage(); - page.setDefaultTimeout(600_000); - page.on("console", (message) => { - // The Vite client's dev-server socket is not served here; its complaints are noise. - if (message.type() === "error" && !/vite|Vite server/.test(message.text())) { - process.stderr.write(`browser console: ${message.text()}\n`); - } - }); - await page.goto(origin); - - // 1. The release worker, unchanged, as build-hosted-whitener.mjs drives it. - const worker = await page.evaluate(async (payload) => { - const instance = new Worker("/worker.js", { type: "module" }); - const progress = []; - return await new Promise((done) => { - instance.onerror = (event) => done({ type: "error", message: event.message ?? "worker error" }); - instance.onmessage = (event) => { - const message = event.data; - if (message.type === "progress" || message.type === "manifold-progress") { - progress.push(message.type); - return; - } - instance.terminate(); - done({ ...message, progress: progress.length }); - }; - instance.postMessage(payload); - }); - }, buildRequest); - check("core build worker on the v5 library", worker.type === "done", worker.message ?? ""); - if (worker.type === "done") { - const [context] = worker.result.contexts; - check("neutral whitener fitted from browser-captured rows", - outputs.whitener.get(String(contextTokens))?.length > 0 && context.ridgePerLayer !== undefined, - `${outputs.whitener.get(String(contextTokens))?.length ?? 0} tensor bytes`); - check("both core concepts fitted (two-node and one-node)", - context.manifoldSha256.length === 2 && outputs.manifolds.size === 2, - context.manifoldSha256.map((digest) => digest.slice(0, 12)).join(", ")); - const whitener = parseSafetensorsHeader(outputs.whitener.get(String(contextTokens))); - check("whitener tensors cover every layer", - runtimeIdentity.layerMap.every((layer) => `layer_${layer}.mean` in whitener), - Object.keys(whitener).filter((key) => key !== "__metadata__").length + " tensors"); - } - - // 2. The capture call itself, through the hosted runtime on the same library, against drowse. - const capture = await page.evaluate(async ({ artifacts, request, ids }) => { - const { DrowseWebLlmRuntime } = await import("/src/hosted/runtime/webLlmEngine.ts"); - const runtime = new DrowseWebLlmRuntime(await import("/webllm.js")); - const revision = "a".repeat(40); - const files = []; - for (const entry of artifacts) { - const blob = await (await fetch(`/model?path=${encodeURIComponent(entry.path)}`)).blob(); - files.push({ - manifest: { ...entry, revision, url: `https://huggingface.co/drowse/local/resolve/${revision}/${entry.path}` }, - file: new File([blob], entry.path), - }); - } - const { runtimeIdentitySha256 } = await import("/src/lib/runtime/catalog.ts"); - const fingerprint = runtimeIdentitySha256(request.runtimeIdentity); - await runtime.load({ - model: { id: request.modelId, modelType: request.modelType }, - variant: { - id: `${request.modelId}-${request.quantization}`, - structuredHookProfile: request.structuredHookProfile, - thinkingProfile: null, - runtimeIdentity: request.runtimeIdentity, - runtimeIdentitySha256: fingerprint, - contextProfiles: request.contexts.map((contextTokens) => ({ contextTokens, bindingSha256: "0".repeat(64) })), - requirements: { - features: [], - limits: { - maxStorageBufferBindingSize: 134217728, - maxComputeWorkgroupSizeX: 256, - maxComputeInvocationsPerWorkgroup: 256, - }, - }, - }, - contextTokens: request.contexts[0], - blockSpec: request.blockSpec, - unitRefusal: null, - prefillChunkSize: request.prefillChunkSize, - adapter: await navigator.gpu.requestAdapter(), - artifacts: files, - signal: new AbortController().signal, - onDeviceLost() {}, - }); - const positions = ids.map((_, index) => index); - const row = { inputIds: ids, position: ids.length - 1 }; - const result = await runtime.capturePreparedPositions(row, positions); - const blockSites = runtime.blockSitesCapabilities(); - // The q4 gate's steered capture (hosted-residual-capture.worker.ts): probes e_0, e_1 at every - // layer, with and without a rank-1 group on e_0 at layer 1. - const { compileStructuredHookProgram } = await import("/src/hosted/runtime/structuredHookProgram.ts"); - const d = request.runtimeIdentity.hiddenSize; - const axis = (k) => Float32Array.from({ length: d }, (_, index) => (index === k ? 1 : 0)); - const probes = [0, 1].map((k) => ({ kind: "linear", direction: axis(k), bias: 0 })); - const program = compileStructuredHookProgram(d, request.runtimeIdentity.layerMap.map((layer) => ({ - probes, - ...(layer === 1 - ? { affineGroups: [{ active: true, basis: [axis(0)], neutral: new Float32Array(d), target: [1.25], along: 0.4, kappa: [0.3] }] } - : {}), - })), blockSites.profile); - const control = await runtime.measurePreparedPositions(row, positions, - { ...program, affineActive: new Uint32Array(program.affineActive.length) }); - const steered = await runtime.measurePreparedPositions(row, positions, program); - // browser-app-runtime's injection-arithmetic oracle (browser-steering-positions.ts). - const { verifySteeringPositions } = await import("/scripts/browser-steering-positions.ts"); - let arithmetic; - try { - arithmetic = await verifySteeringPositions(runtime, { - hiddenSize: d, layerMap: request.runtimeIdentity.layerMap, - structuredHookProfile: request.structuredHookProfile, quantization: request.quantization, - source: request.runtimeIdentity.sourceModel, - }, { arithmeticOnly: true }); - } catch (error) { - arithmetic = { passed: false, error: String(error?.stack ?? error) }; - } - await runtime.unload(); - return { - layerCount: result.layerCount, hiddenSize: result.hiddenSize, positionCount: result.positionCount, - values: Array.from(result.values), - profile: blockSites?.profile.id ?? null, - probeCount: control.probeCount, - control: Array.from(control.values), - steered: Array.from(steered.values), - arithmetic, - }; - }, { artifacts, request: buildRequest, ids: goldenIds }); - check("hosted runtime attests the library as standard-v4", capture.profile === "standard-v4", String(capture.profile)); - const shapeOk = capture.layerCount === layerCount && capture.hiddenSize === hiddenSize && - capture.positionCount === goldenIds.length; - let worst = 0; - let outside = 0; - for (let index = 0; shapeOk && index < goldenOut.length; index += 1) { - const error = Math.abs(capture.values[index] - goldenOut[index]); - worst = Math.max(worst, error); - if (!(error <= tolerance.atol + tolerance.rtol * Math.abs(goldenOut[index]))) outside += 1; - } - check("plain residual capture matches drowse's block-sites out [L, T, d]", shapeOk && outside === 0, - `${goldenOut.length} values, worst |Δ| ${worst.toExponential(2)}, ${outside} outside atol ${tolerance.atol} + rtol ${tolerance.rtol}`); - - // 3. The structured measurement the q4 gate's steered capture reads: [position, layer, probe]. - const K = capture.probeCount; - const probe = (values, p, l, k) => values[(p * layerCount + l) * K + k]; - let readback = 0; - let preHook = 0; - let hook = 0; - for (let p = 0; p < goldenIds.length; p += 1) { - for (let l = 0; l < layerCount; l += 1) { - for (let k = 0; k < 2; k += 1) { - const plain = capture.values[(l * goldenIds.length + p) * hiddenSize + k]; - readback = Math.max(readback, Math.abs(probe(capture.control, p, l, k) - plain)); - if (l < 1) preHook = Math.max(preHook, Math.abs(probe(capture.steered, p, l, k) - probe(capture.control, p, l, k))); - } - if (l === 1) { - const before = probe(capture.control, p, l, 0); - const expected = before + 0.4 * (1.25 - 0.3 * before); - hook = Math.max(hook, Math.abs(probe(capture.steered, p, l, 0) - expected), - Math.abs(probe(capture.steered, p, l, 1) - probe(capture.control, p, l, 1))); - } - } - } - check("structured probes read the plain capture's residual (control program)", readback <= 1e-5, - `worst |Δ| ${readback.toExponential(2)}`); - check("steered probes equal the control's before the hook layer", preHook === 0, `max |Δ| ${preHook}`); - check("the hook layer's probes move by along·(target − kappa·h·u) on u only", hook <= 1e-5, - `worst |Δ| ${hook.toExponential(2)}`); - check("browser-steering-positions injection arithmetic (arithmeticOnly)", capture.arithmetic.passed === true, - capture.arithmetic.passed - ? capture.arithmetic.checks.map((entry) => `${entry.label}: ${entry.maxInjectionError.toExponential(2)}`).join("; ") - : capture.arithmetic.error); -} finally { - await browser.close(); - await new Promise((ok) => http.close(ok)); - await vite.close(); -} -if (failures > 0) { - console.error(`${failures} check(s) failed`); - process.exit(1); -} -console.log(`core build on ${fixture}-v5: every check passed`); - -function decodeSite(site) { - if (site.encoding !== "float32-le-base64") throw new Error(`unexpected golden encoding ${site.encoding}`); - const bytes = Buffer.from(site.data, "base64"); - return new Float32Array(bytes.buffer, bytes.byteOffset, bytes.byteLength / 4); -} - -function parseSafetensorsHeader(bytes) { - if (!bytes) return {}; - const length = Number(bytes.readBigUInt64LE(0)); - return JSON.parse(bytes.subarray(8, 8 + length).toString("utf8")); -} - -function parseArguments(args) { - const result = { headed: false, port: 0 }; - for (let i = 0; i < args.length; i += 1) { - const key = args[i]; - if (key === "--headed") result.headed = true; - else if (["--webllm", "--fixtures", "--arch", "--quantization", "--work", "--port"].includes(key)) result[key.slice(2)] = args[++i]; - else throw new Error(`unknown argument ${key}`); - } - for (const key of ["webllm", "fixtures", "arch", "quantization", "work"]) { - if (!result[key]) throw new Error(`--${key} is required`); - } - if (!["qwen3", "gemma3"].includes(result.arch)) throw new Error("--arch is qwen3 or gemma3"); - if (!["q0f32", "q4f32_1"].includes(result.quantization)) throw new Error("--quantization is q0f32 or q4f32_1"); - result.port = Number(result.port); - return result; -} diff --git a/webui/scripts/browser-core-pack.test.mjs b/webui/scripts/browser-core-pack.test.mjs index 366931f..150fb80 100644 --- a/webui/scripts/browser-core-pack.test.mjs +++ b/webui/scripts/browser-core-pack.test.mjs @@ -1,6 +1,5 @@ import assert from "node:assert/strict"; import { createHash } from "node:crypto"; -import { readFileSync } from "node:fs"; import { fileURLToPath } from "node:url"; import { createServer } from "vite"; @@ -16,19 +15,13 @@ const server = await createServer({ const tests = []; const test = (name, run) => tests.push({ name, run }); const sha256 = (bytes) => createHash("sha256").update(bytes).digest("hex"); -const loweringGolden = JSON.parse(readFileSync( - new URL("../../drowse/tests/fixtures/browser/affine-rank-one-lowering-v1.json", import.meta.url), - "utf8", +// A fitted frame's read rows beside its write rows. These hand-built bases are orthonormal, so +// each frame reads with its own rows (the Euclidean case of a typed frame). +const withReads = (tensors) => Object.fromEntries(Object.entries(tensors).flatMap(([key, value]) => + /^layer_\d+\.basis$/u.test(key) + ? [[key, value], [key.replace(/\.basis$/u, ".read"), { shape: value.shape, data: value.data.slice() }]] + : [[key, value]] )); -const composedGolden = JSON.parse(readFileSync( - new URL("../../drowse/tests/fixtures/browser/affine-composed-lowering-v1.json", import.meta.url), - "utf8", -)); -const ablationGolden = JSON.parse(readFileSync( - new URL("../../drowse/tests/fixtures/browser/affine-ablation-lowering-v1.json", import.meta.url), - "utf8", -)); - try { const { BrowserFeasibilityCorePackCompiler } = await server.ssrLoadModule( "/src/hosted/runtime/browserCorePack.ts", @@ -77,7 +70,7 @@ try { `manifolds/local/demo/nodes/${String(index).padStart(2, "0")}_${label}.json`, jsonBytes([label]), ])); - const tensors = encodeFp32Safetensors(curved ? { + const tensors = encodeFp32Safetensors(withReads(curved ? { node_coords: sphere ? { shape: [2, 2], data: new Float32Array([Math.PI / 2, 0, Math.PI / 2, Math.PI / 2]) } : { shape: [2, 1], data: new Float32Array([0, 1]) }, @@ -184,7 +177,7 @@ try { "layer_1.mean": { shape: [2], data: new Float32Array([0.3, 0.4]) }, "layer_1.basis": { shape: [1, 2], data: new Float32Array([0, 1]) }, "layer_1.node_coords": { shape: [2, 1], data: new Float32Array([-2, 2]) }, - }); + })); const sidecar = jsonBytes({ format_version: 10, name: "demo", @@ -216,9 +209,7 @@ try { : { type: "custom", embed_dim: affineRank2 ? 2 : 1, bounds: null }, node_spread_per_layer: {}, fitted_layers: [0, 1], - mahalanobis_share_per_layer: Object.fromEntries( - loweringGolden.layers.map((layer) => [String(layer.layer), layer.mahalanobisShare]), - ), + mahalanobis_share_per_layer: { "0": Math.SQRT2, "1": 2 * Math.SQRT2 }, origin_per_layer: sphere ? { "0": [Math.PI / 2, 0], "1": [Math.PI / 2, 0] } : curved ? { "0": [curveOrigin], "1": [curveOrigin] } : {}, @@ -241,9 +232,7 @@ try { capture_version: null, capture_render_sha256: null, baseline_prompts_sha256: null, - fit_policy_version: 1, - share_metric: "mahalanobis", - subspace_metric: "mahalanobis", + fit_policy_version: 2, rbf_smoothing_per_layer: curved ? { "0": { lambda: 0, edf: 2, gcv: 0 }, "1": { lambda: 0, edf: 2, gcv: 0 }, @@ -329,7 +318,7 @@ try { "manifolds/local/focus/nodes/00_soft.json": jsonBytes(["soft"]), "manifolds/local/focus/nodes/01_sharp.json": jsonBytes(["sharp"]), }; - const focusTensors = encodeFp32Safetensors({ + const focusTensors = encodeFp32Safetensors(withReads({ node_coords: { shape: [2, 1], data: new Float32Array([-1, 1]) }, "layer_0.mean": { shape: [2], data: new Float32Array([0.2, 0.1]) }, "layer_0.basis": { shape: [1, 2], data: new Float32Array([0.6, 0.8]) }, @@ -337,7 +326,7 @@ try { "layer_1.mean": { shape: [2], data: new Float32Array([0.4, 0.3]) }, "layer_1.basis": { shape: [1, 2], data: new Float32Array([0.8, 0.6]) }, "layer_1.node_coords": { shape: [2, 1], data: new Float32Array([-0.5, 0.5]) }, - }); + })); const focusSidecar = jsonBytes({ format_version: 10, name: "focus", @@ -377,9 +366,7 @@ try { capture_version: null, capture_render_sha256: null, baseline_prompts_sha256: null, - fit_policy_version: 1, - share_metric: "mahalanobis", - subspace_metric: "mahalanobis", + fit_policy_version: 2, rbf_smoothing_per_layer: {}, sigma_field_per_layer: {}, resolved_fit_mode: null, @@ -435,7 +422,7 @@ try { } if (options.isotropicWhitener) { // Native's `isotropic_whitener`: zero means and the identity metric (λ + ridge = 1 on a - // full basis), the whitener drowse writes the affine lowering golden under. + // full basis). const identityLayer = (layer) => ({ [`layer_${layer}.mean`]: { shape: [2], data: new Float32Array([0, 0]) }, [`layer_${layer}.basis`]: { shape: [2, 2], data: new Float32Array([1, 0, 0, 1]) }, @@ -727,7 +714,7 @@ try { const request = { model: { id: "fixture-model" }, variant: { - structuredHookProfile: options.structuredHookProfile ?? "standard-v4", + structuredHookProfile: options.structuredHookProfile ?? "standard-v5", runtimeIdentity, runtimeIdentitySha256: fingerprint, contextProfiles: [ @@ -772,20 +759,18 @@ try { }; } - test("lowers a single fitted node to drowse's affine target and gain (one structured group)", async () => { - // drowse writes the golden under its isotropic whitener; a single push takes the same - // Mahalanobis lowering as a composed one, so it needs the neutral whitener too. + test("lowers a single fitted node to one structured group", async () => { + // A single push takes the same Mahalanobis lowering as a composed one, so it needs the + // neutral whitener too. const { request } = await fixture({ isotropicWhitener: true }); const compiler = await BrowserFeasibilityCorePackCompiler.load(request); const program = compiler.compile("0.5 alert"); - assert.equal(program.format, "drowse-structured-v4"); + assert.equal(program.format, "drowse-structured-v5"); assert.equal(program.hiddenSize, 2); assert.equal(program.layerCount, 2); const axis = affineAxis(program); assert.deepEqual(axis.active, [1, 1]); assert.deepEqual(axis.basis, [1, 0, 0, 1]); - assertFloatArray(axis.target, loweringGolden.layers.map((layer) => layer.expectedTarget)); - assertFloatArray(axis.along, loweringGolden.layers.map((layer) => layer.expectedAlong), 1e-5); assert.deepEqual(axis.collapse, [0, 0]); assert.deepEqual([...program.affineActive].filter(Boolean).length, 2); const { request: bare } = await fixture(); @@ -880,7 +865,7 @@ try { } }); - test("lowers unit ablations, neuron pushes, unit probes and unit gates (drowse-structured-v4)", async () => { + test("lowers unit ablations, neuron pushes, unit probes and unit gates (drowse-structured-v5)", async () => { const { decodeStructuredUnitTables } = await server.ssrLoadModule("/src/hosted/runtime/structuredHookProgram.ts"); const { readingScales } = await server.ssrLoadModule("/src/hosted/runtime/units/scales.ts"); const { request } = await fixture({ withWhitener: true }); @@ -905,7 +890,7 @@ try { }; compiler.setUnitSource(source); const program = compiler.compile("0.5 !neuron/L1n2 + !head/L0h1@before"); - assert.equal(program.format, "drowse-structured-v4"); + assert.equal(program.format, "drowse-structured-v5"); const tables = decodeStructuredUnitTables(program); const neuron = tables.find((table) => table.site === "act"); const head = tables.find((table) => table.site === "z"); @@ -915,7 +900,7 @@ try { assert.equal(program.controls.units[1].phase.kind, "prompt_only"); // A neuron push is a one-layer instrument atom: an affine group at its layer, no unit table. const push = compiler.compile("0.3 neuron/L1n2"); - assert.equal(push.format, "drowse-structured-v4"); + assert.equal(push.format, "drowse-structured-v5"); assert.equal(decodeStructuredUnitTables(push).length, 0); assert.ok([...push.affineActive].some((value) => value === 1)); assert.throws(() => compiler.compile("0.3 neuron/L0n1"), (error) => error.code === "UNIT_DIRECTION_UNPREPARED"); @@ -984,7 +969,7 @@ try { .concat(["head/L0h0", "head/L0h1"]) .filter((selector) => selector !== "neuron/L0n1"); for (const selector of units) compiler.attachProbe({ selector }); - assert.ok(compiler.listProbes().length > 8, "more probes than standard-v4's 8 device slots"); + assert.ok(compiler.listProbes().length > 8, "more probes than standard-v5's 8 device slots"); for (const selector of units) compiler.detachProbe(selector); // A unit outside the model is native's 400; a library without unit sites is native's 422. assert.throws(() => compiler.compile("!neuron/L1n9"), (error) => error.status === 400 && /neuron 9 is outside block 1/.test(error.message)); @@ -1188,31 +1173,17 @@ try { ); }); - test("matches Python mean-replacement ablation", async () => { + test("lowers a mean-replacement ablation to a collapse axis", async () => { const { request } = await fixture({ withWhitener: true }); const compiler = await BrowserFeasibilityCorePackCompiler.load(request); - const program = compiler.compile(ablationGolden.expression); - assert.equal(program.format, "drowse-structured-v4"); + const program = compiler.compile("0.5 !alert"); + assert.equal(program.format, "drowse-structured-v5"); const axis = affineAxis(program); assert.deepEqual(axis.active, [1, 1]); assert.deepEqual(axis.target, [0, 0]); - assertFloatArray(axis.collapse, [ablationGolden.coefficient, ablationGolden.coefficient]); - assert.deepEqual(axis.basis, ablationGolden.layers.flatMap((layer) => layer.basis)); - assert.deepEqual(axis.neutral, ablationGolden.layers.flatMap((layer) => layer.neutral)); - for (const layer of ablationGolden.layers) { - assertFloatArray( - runStructuredHookLayer( - program, - initialStructuredHookState(program), - layer.layer, - new Float32Array(layer.input), - ).residual, - layer.expected, - 1e-6, - ); - } + assertFloatArray(axis.collapse, [0.5, 0.5]); const mixed = compiler.compile("0.5 !alert + 0.25 calm"); - assert.equal(mixed.format, "drowse-structured-v4"); + assert.equal(mixed.format, "drowse-structured-v5"); assert.deepEqual([...mixed.affineActive.slice(0, 2)], [1, 0]); }); @@ -1222,7 +1193,7 @@ try { const input = new Float32Array([0.4, -0.2]); const execute = (expression) => { const program = compiler.compile(expression); - assert.equal(program.format, "drowse-structured-v4"); + assert.equal(program.format, "drowse-structured-v5"); return runStructuredHookLayer( program, initialStructuredHookState(program), @@ -1400,7 +1371,7 @@ try { const { request } = await fixture({ withWhitener: true }); const compiler = await BrowserFeasibilityCorePackCompiler.load(request); const phased = compiler.compile("0.5 alert@response"); - assert.equal(phased.format, "drowse-structured-v4"); + assert.equal(phased.format, "drowse-structured-v5"); assert.equal(structuredHookControlsFor(phased, { prefill: true, thinking: false, @@ -1451,7 +1422,7 @@ try { const byCoordinates = compiler.compile("0.5 demo%1@response&when:demo>0"); for (const program of [byLabel, byCoordinates]) { - assert.equal(program.format, "drowse-structured-v4"); + assert.equal(program.format, "drowse-structured-v5"); assert.deepEqual([...program.curveActive], new Array(program.curveActive.length).fill(0)); assert.deepEqual([...program.affineActive], [...direct.affineActive]); assertFloatArray(program.affineBasis, direct.affineBasis); @@ -1476,7 +1447,7 @@ try { const bare = compiler.compile("0.5 east"); const explicit = compiler.compile("0.5 demo%east"); - assert.equal(bare.format, "drowse-structured-v4"); + assert.equal(bare.format, "drowse-structured-v5"); assert.deepEqual([...bare.curveActive], new Array(bare.curveActive.length).fill(0)); assertFloatArray(bare.affineBasis, explicit.affineBasis); assertFloatArray(bare.affineTarget, explicit.affineTarget); @@ -1523,11 +1494,11 @@ try { const { request } = await fixture({ curved: true, withWhitener: true, withSae: true }); const compiler = await BrowserFeasibilityCorePackCompiler.load(request); const bareLabel = compiler.compile("calm"); - assert.equal(bareLabel.format, "drowse-structured-v4"); + assert.equal(bareLabel.format, "drowse-structured-v5"); assert.equal(bareLabel.curveActive.some(Boolean), true); compiler.attachProbe({ selector: "sae/0" }); const program = compiler.compile("0.5,1 demo%alert@response&when:sae/0>0.2"); - assert.equal(program.format, "drowse-structured-v4"); + assert.equal(program.format, "drowse-structured-v5"); assert.deepEqual([...program.curveRank.filter(Boolean)], [2, 2]); assert.deepEqual([...program.curveNodeCount.filter(Boolean)], [2, 2]); assert.deepEqual([...program.curveSigmaPresent.filter(Boolean)], [1, 1]); @@ -1568,14 +1539,14 @@ try { const slot = layer * program.profile.maxCurves; return [program.curveActive[slot], program.curveAlong[slot], program.curveOnto[slot]]; }); - // Shares sqrt(2) and 2 sqrt(2): mean-1 over both layers is 2/3 and 4/3. + // Shares sqrt(2) and 2 sqrt(2): mean-1 over both layers is 2/3 and 4/3 (along gain 2). const full = gains(compiler.compile("0.3,0.5 demo%alert")); - assertFloatArray(full.map((row) => row[1]), [0.8, 1.6]); + assertFloatArray(full.map((row) => row[1]), [0.4, 0.8]); assertFloatArray(full.map((row) => row[2]), [1 / 6, 1 / 3]); // drowse's _manifold_layer_shares normalizes over the clause's layers only. const scoped = gains(compiler.compile("0.3,0.5 demo%alert{0}")); assert.equal(scoped[1][0], 0); - assertFloatArray([scoped[0][1], scoped[0][2]], [1.2, 0.25]); + assertFloatArray([scoped[0][1], scoped[0][2]], [0.6, 0.25]); }); test("rejects overlapping curved terms before generation", async () => { @@ -1608,7 +1579,7 @@ try { const compiler = await BrowserFeasibilityCorePackCompiler.load(request); compiler.attachProbe({ selector: "sae/0" }); const program = compiler.compile("0.5 sae/0@when:sae/0>0.2"); - assert.equal(program.format, "drowse-structured-v4"); + assert.equal(program.format, "drowse-structured-v5"); assert.equal(structuredHookControlsFor(program, { prefill: true, thinking: false, @@ -2004,12 +1975,15 @@ try { const { request } = await fixture({ withWhitener: true, withJlens: true }); const compiler = await BrowserFeasibilityCorePackCompiler.load(request); const program = compiler.compile("0.5 jlens/hello"); - assert.equal(program.format, "drowse-structured-v4"); + assert.equal(program.format, "drowse-structured-v5"); assert.deepEqual([...program.affineActive.filter(Boolean)], [1, 1]); - const layer0 = program.affineBasis.slice(0, 2); - const layer1 = program.affineBasis.slice(4 * 8 * 2, 4 * 8 * 2 + 2); - assertFloatArray(layer0, [2 / Math.sqrt(13), 3 / Math.sqrt(13)], 2e-6); - assertFloatArray(layer1, [2 / Math.sqrt(53), 7 / Math.sqrt(53)], 2e-6); + // A lens atom is a read u: it steers along its raised vector Σu (Σ = diag(2.25, 0.25) and + // diag(0.5, 3.5) here), Mahalanobis-unit, and reads with u again (‖Σu‖_M² = u·Σu). + const slot1 = 4 * 8 * 2; + assertFloatArray(program.affineBasis.slice(0, 2), [4.5 / Math.sqrt(11.25), 0.75 / Math.sqrt(11.25)], 2e-6); + assertFloatArray(program.affineRead.slice(0, 2), [2 / Math.sqrt(11.25), 3 / Math.sqrt(11.25)], 2e-6); + assertFloatArray(program.affineBasis.slice(slot1, slot1 + 2), [1 / Math.sqrt(173.5), 24.5 / Math.sqrt(173.5)], 2e-6); + assertFloatArray(program.affineRead.slice(slot1, slot1 + 2), [2 / Math.sqrt(173.5), 7 / Math.sqrt(173.5)], 2e-6); assert.throws( () => compiler.compile("0.5 jlens/missing"), (error) => error.code === "JLENS_TOKEN_UNAVAILABLE", @@ -2094,10 +2068,11 @@ try { ); compiler.attachProbe({ selector: "jlens/novel" }); const program = compiler.compile("0.5 jlens/novel@when:jlens/novel>0.01"); - assertFloatArray(program.affineBasis.slice(0, 2), [7 / Math.sqrt(113), 8 / Math.sqrt(113)]); + // The raised atom reads with its own token row u, Mahalanobis-normalized (u·Σu). + assertFloatArray(program.affineRead.slice(0, 2), [7 / Math.sqrt(126.25), 8 / Math.sqrt(126.25)]); assertFloatArray( - program.affineBasis.slice(4 * 8 * 2, 4 * 8 * 2 + 2), - [7 / Math.sqrt(533), 22 / Math.sqrt(533)], + program.affineRead.slice(4 * 8 * 2, 4 * 8 * 2 + 2), + [7 / Math.sqrt(1718.5), 22 / Math.sqrt(1718.5)], ); assert.equal(program.jLensTokenIds[0], 7); assert.deepEqual(batches, [[7]]); @@ -2108,7 +2083,7 @@ try { compiler.attachProbe({ selector: "jlens/#7" }); const exact = compiler.compile("0.5 jlens/#7@when:jlens/#7>0.01"); assert.equal(exact.jLensTokenIds[0], 7); - assertFloatArray(exact.affineBasis.slice(0, 2), [7 / Math.sqrt(113), 8 / Math.sqrt(113)]); + assertFloatArray(exact.affineRead.slice(0, 2), [7 / Math.sqrt(126.25), 8 / Math.sqrt(126.25)]); assert.deepEqual(batches, [[7]], "the exact id reuses the resolved directions"); // An id past the vocabulary fails as drowse's InvalidTokenIdError does, // before any direction lookup reaches the runtime. @@ -2222,8 +2197,8 @@ try { assert.equal(program.probeKind[0], 0); assert.equal(program.probeKind[8], 3); assertFloatArray( - program.affineBasis.slice(4 * 8 * 2, 4 * 8 * 2 + 2), - [7 / Math.sqrt(533), 22 / Math.sqrt(533)], + program.affineRead.slice(4 * 8 * 2, 4 * 8 * 2 + 2), + [7 / Math.sqrt(1718.5), 22 / Math.sqrt(1718.5)], ); }); @@ -2231,7 +2206,7 @@ try { const { request } = await fixture({ withWhitener: true, withSae: true, withJlens: true }); const compiler = await BrowserFeasibilityCorePackCompiler.load(request); const program = compiler.compile("0.25 alert + 0.1 sae/1 + 0.2 jlens/world + 0.5 !calm"); - assert.equal(program.format, "drowse-structured-v4"); + assert.equal(program.format, "drowse-structured-v5"); assert.equal(program.affineActive.filter(Boolean).length, 2); }); @@ -2246,7 +2221,7 @@ try { compiler.setInstrumentLive("sae", true); const program = compiler.compile(""); - assert.equal(program.format, "drowse-structured-v4"); + assert.equal(program.format, "drowse-structured-v5"); assert.equal(program.measurementSchema.probes.some((probe) => probe?.family === "lens"), false); assert.equal(program.measurementSchema.probes.some((probe) => probe?.family === "sae"), false); assert.equal(program.measurementSchema.lensReadout, true); @@ -2583,7 +2558,7 @@ try { const compiler = await BrowserFeasibilityCorePackCompiler.load(request); const axis = affineAxis(compiler.compile("0.25 local/demo")); assertFloatArray(axis.push, [-0.25, 0, 0, -0.25]); - assertFloatArray(axis.along, [32 / 3, 64 / 3], 1e-5); + assertFloatArray(axis.along, [16 / 3, 32 / 3], 1e-5); }); test("canonicalizes steering deltas through installed manifold identities", async () => { @@ -2631,7 +2606,7 @@ try { assert.equal(compiler.hasAttachedProbes(), true); const program = compiler.compile(""); - assert.equal(program.format, "drowse-structured-v4"); + assert.equal(program.format, "drowse-structured-v5"); assert.equal(program.measurementSchema.probes[0], null); assert.equal(program.measurementSchema.geometryProbes[0].name, "calm scale"); assert.deepEqual(program.measurementSchema.geometryProbes[0].scoreKeys, ["calm scale"]); @@ -2671,7 +2646,7 @@ try { const attached = compiler.attachProbe({ selector: "local/demo", top_n: 3 }); assert.equal(attached.intrinsic_dim, 1); const program = compiler.compile(""); - assert.equal(program.format, "drowse-structured-v4"); + assert.equal(program.format, "drowse-structured-v5"); assert.equal(program.profile.geometryOutputStride, 41); assert.deepEqual([...program.whitenerRank], [1, 1]); assert.deepEqual([...program.geometryKind.filter(Boolean)], [2, 2]); @@ -2762,7 +2737,7 @@ try { const compiler = await BrowserFeasibilityCorePackCompiler.load(request); compiler.attachProbe({ selector: "local/demo" }); const program = compiler.compile("0.5 local/demo%alert"); - assert.equal(program.format, "drowse-structured-v4"); + assert.equal(program.format, "drowse-structured-v5"); assert.deepEqual([...program.curveDomainKind.filter(Boolean)], [2, 2]); assert.deepEqual([...program.geometryDomainKind.filter(Boolean)], [2, 2]); const result = runStructuredHookLayer( @@ -2791,10 +2766,6 @@ try { ["local/demo", "local/focus"], ); assert.deepEqual(compiler.getProfile("local/demo").layers, [0, 1]); - assert.equal( - compiler.getProfile("local/demo").metadata.share_metric, - "mahalanobis", - ); const correlation = compiler.profileCorrelation(); assert.deepEqual(correlation.names, ["local/demo", "local/focus"]); @@ -2926,8 +2897,9 @@ try { }); const compiler = await BrowserFeasibilityCorePackCompiler.load(request); compiler.attachProbe({ selector: "local/demo", name: "curved identity" }); + // sha256 over each layer's fp32 mean, basis and read rows (drowse 6.1 `_record_digest`). assert.deepEqual(compiler.probeHashes(), { - "curved identity": "cd50e11ceaaef63c1603be13a7a31c99f3ed3c50cc06bcd1a45ed0905e3c91ca", + "curved identity": "ec688cf469fcef744d9219d0f05c72de26ed1371d8b5b3ef924a652c562076ab", }); }); @@ -3062,50 +3034,6 @@ try { ); }); - for (const golden of composedGolden.cases) { - test(`matches Python composed lowering: ${golden.name}`, async () => { - const { request } = await fixture({ withWhitener: true, withSecondManifold: true }); - const compiler = await BrowserFeasibilityCorePackCompiler.load(request); - const program = compiler.compile(golden.expression); - assert.deepEqual(affineAxis(program).active, [1, 1]); - // drowse records the push as one world target (its direction and length); the group - // holds it in the span of the fragments' bases, so compare the world target it sums to. - const { maxAffineGroups, maxRank } = program.profile; - const d = program.hiddenSize; - golden.expectedLayers.forEach((expected, programIndex) => { - const slot = programIndex * maxAffineGroups; - const world = new Float64Array(d); - for (let axis = 0; axis < maxRank; axis += 1) { - const row = (slot * maxRank + axis) * d; - for (let column = 0; column < d; column += 1) { - world[column] += program.affineTarget[slot * maxRank + axis] * - program.affineBasis[row + column]; - } - } - const target = Math.hypot(...world); - assertFloatArray([...world].map((value) => value / target), expected.basis, 2e-6); - assertFloatArray(program.affineNeutral.slice(slot * d, (slot + 1) * d), expected.neutral); - assert.ok(Math.abs(target - expected.target) <= 2e-6); - assert.ok(Math.abs(program.affineAlong[slot] - expected.along) <= 2e-5); - assert.ok([...program.affineKappa.slice(slot * maxRank, (slot + 1) * maxRank)].every((value) => value === 0)); - assertFloatArray([...world].map((value) => value * program.affineAlong[slot]), expected.delta, 3e-5); - }); - - compiler.attachProbe({ selector: "demo", name: "structured parity" }); - const structured = compiler.compile(golden.expression); - assert.equal(structured.format, "drowse-structured-v4"); - golden.expectedLayers.forEach((expected, programIndex) => { - const residual = runStructuredHookLayer( - structured, - initialStructuredHookState(structured), - programIndex, - [0, 0], - ).residual; - assertFloatArray(residual, expected.delta, 4e-5); - }); - }); - } - test("fails closed when browser fitting has no neutral whitener", async () => { const { request } = await fixture(); const compiler = await BrowserFeasibilityCorePackCompiler.load(request); @@ -3221,6 +3149,7 @@ function affineAxis(program, group = 0) { return { active: slots.map((slot) => program.affineActive[slot]), basis: slots.flatMap((slot) => [...program.affineBasis.slice(slot * maxRank * d, slot * maxRank * d + d)]), + read: slots.flatMap((slot) => [...program.affineRead.slice(slot * maxRank * d, slot * maxRank * d + d)]), neutral: slots.flatMap((slot) => [...program.affineNeutral.slice(slot * d, (slot + 1) * d)]), target: slots.map((slot) => program.affineTarget[slot * maxRank]), along: slots.map((slot) => program.affineAlong[slot]), diff --git a/webui/scripts/browser-full-runtime-contract.mjs b/webui/scripts/browser-full-runtime-contract.mjs index 39113ca..0ad73bf 100644 --- a/webui/scripts/browser-full-runtime-contract.mjs +++ b/webui/scripts/browser-full-runtime-contract.mjs @@ -2,14 +2,14 @@ export const BROWSER_FULL_RUNTIME_TOOL_VERSION = "drowse-real-browser-e2e-v5"; /** The physical harness's checks for a hook ABI v5 library, in order. `load` attests the * library's schema-4 descriptor against the lock (profile, block spec, capacities); a - * `standard-v4` library then runs `units` (a unit ablation that moves the next-token + * `standard-v5` library then runs `units` (a unit ablation that moves the next-token * distribution, finite unit taps, one token-anatomy replay, one static unit read and the S - * readout), a `standard-v4-residual` one `unit_refusal` (each unit call answers the lock's + * readout), a `standard-v5-residual` one `unit_refusal` (each unit call answers the lock's * `unitRefusal`, and the library exports no unit function). */ export function requiredBrowserFullRuntimeChecks(structuredHookProfile) { const unitCheck = { - "standard-v4": "units", - "standard-v4-residual": "unit_refusal", + "standard-v5": "units", + "standard-v5-residual": "unit_refusal", }[structuredHookProfile]; if (unitCheck === undefined) { throw new Error(`structured hook profile ${JSON.stringify(structuredHookProfile)} predates hook ABI v5`); @@ -179,22 +179,22 @@ export function parseBrowserFullRuntimeArguments(args) { } /** The instrument packs a hook ABI v5 library runs with, as the catalog admits them - * (`build-hosted-catalog.mjs`): a `standard-v4` library carries its R, S and units packs, a - * `standard-v4-residual` one no S or units pack (an R pack is optional: a provider lens). An SAE + * (`build-hosted-catalog.mjs`): a `standard-v5` library carries its R, S and units packs, a + * `standard-v5-residual` one no S or units pack (an R pack is optional: a provider lens). An SAE * pack is optional on both. Returns the pack kinds present, in staging order. */ export function validateBrowserFullRuntimePackSets(structuredHookProfile, directories) { requiredBrowserFullRuntimeChecks(structuredHookProfile); const present = (kind) => directories[kind] !== null && directories[kind] !== undefined; - if (structuredHookProfile === "standard-v4") { + if (structuredHookProfile === "standard-v5") { for (const [kind, flag] of [["jlens", "--jlens-directory"], ["slens", "--slens-directory"], ["units", "--units-directory"]]) { if (!present(kind)) { - throw new Error(`${flag} is required: a standard-v4 library ships its R, S and units packs`); + throw new Error(`${flag} is required: a standard-v5 library ships its R, S and units packs`); } } } else { for (const [kind, flag] of [["slens", "--slens-directory"], ["units", "--units-directory"]]) { if (present(kind)) { - throw new Error(`${flag} is refused: a standard-v4-residual library has no S lens or units`); + throw new Error(`${flag} is refused: a standard-v5-residual library has no S lens or units`); } } } diff --git a/webui/scripts/browser-full-runtime.mjs b/webui/scripts/browser-full-runtime.mjs index abc4d84..5b638f7 100644 --- a/webui/scripts/browser-full-runtime.mjs +++ b/webui/scripts/browser-full-runtime.mjs @@ -67,8 +67,8 @@ const executionProfiles = lockedModelExecutionProfiles( lock, modelSet.manifest, ); -// The packs the library's profile runs with: core always; R, S and units on standard-v4; an R -// pack optional and no S or units on standard-v4-residual; SAE optional. +// The packs the library's profile runs with: core always; R, S and units on standard-v5; an R +// pack optional and no S or units on standard-v5-residual; SAE optional. const packKinds = validateBrowserFullRuntimePackSets( executionProfiles.structuredHookProfile, { diff --git a/webui/scripts/browser-full-runtime.test.mjs b/webui/scripts/browser-full-runtime.test.mjs index 89eb8ce..420fc76 100644 --- a/webui/scripts/browser-full-runtime.test.mjs +++ b/webui/scripts/browser-full-runtime.test.mjs @@ -136,28 +136,28 @@ test("requires the model and core artifacts and rejects bypass flags", () => { ); }); -test("a standard-v4 run carries its R, S and units packs; a residual run no S or units pack", () => { +test("a standard-v5 run carries its R, S and units packs; a residual run no S or units pack", () => { const all = { jlens: "/r", slens: "/s", units: "/u", sae: "/sae" }; - assert.deepEqual(validateBrowserFullRuntimePackSets("standard-v4", all), ["jlens", "slens", "units", "sae"]); + assert.deepEqual(validateBrowserFullRuntimePackSets("standard-v5", all), ["jlens", "slens", "units", "sae"]); assert.deepEqual( - validateBrowserFullRuntimePackSets("standard-v4", { ...all, sae: null }), + validateBrowserFullRuntimePackSets("standard-v5", { ...all, sae: null }), ["jlens", "slens", "units"], ); for (const [kind, flag] of [["jlens", "--jlens-directory"], ["slens", "--slens-directory"], ["units", "--units-directory"]]) { assert.throws( - () => validateBrowserFullRuntimePackSets("standard-v4", { ...all, [kind]: null }), + () => validateBrowserFullRuntimePackSets("standard-v5", { ...all, [kind]: null }), new RegExp(`${flag} is required`), ); } const none = { jlens: null, slens: null, units: null, sae: null }; - assert.deepEqual(validateBrowserFullRuntimePackSets("standard-v4-residual", none), []); + assert.deepEqual(validateBrowserFullRuntimePackSets("standard-v5-residual", none), []); assert.deepEqual( - validateBrowserFullRuntimePackSets("standard-v4-residual", { ...none, jlens: "/r", sae: "/sae" }), + validateBrowserFullRuntimePackSets("standard-v5-residual", { ...none, jlens: "/r", sae: "/sae" }), ["jlens", "sae"], ); for (const [kind, flag] of [["slens", "--slens-directory"], ["units", "--units-directory"]]) { assert.throws( - () => validateBrowserFullRuntimePackSets("standard-v4-residual", { ...none, [kind]: "/x" }), + () => validateBrowserFullRuntimePackSets("standard-v5-residual", { ...none, [kind]: "/x" }), new RegExp(`${flag} is refused`), ); } @@ -457,26 +457,26 @@ test("cross-verifies only exact artifact EOF aborts after server and OPFS proof" test("accepts only one measured pass for every required check in order", () => { const events = transcript(); - const checks = validateBrowserFullRuntimeTranscript(events, "standard-v4"); - assert.deepEqual(Object.keys(checks), requiredBrowserFullRuntimeChecks("standard-v4")); + const checks = validateBrowserFullRuntimeTranscript(events, "standard-v5"); + assert.deepEqual(Object.keys(checks), requiredBrowserFullRuntimeChecks("standard-v5")); assert.ok(Object.values(checks).every((check) => check.passed === true)); // A units library runs the units check; a residual one the refusal check; no other profile. - assert.equal(requiredBrowserFullRuntimeChecks("standard-v4").includes("units"), true); - assert.equal(requiredBrowserFullRuntimeChecks("standard-v4-residual").includes("unit_refusal"), true); - assert.equal(requiredBrowserFullRuntimeChecks("standard-v4-residual").includes("units"), false); + assert.equal(requiredBrowserFullRuntimeChecks("standard-v5").includes("units"), true); + assert.equal(requiredBrowserFullRuntimeChecks("standard-v5-residual").includes("unit_refusal"), true); + assert.equal(requiredBrowserFullRuntimeChecks("standard-v5-residual").includes("units"), false); assert.throws(() => requiredBrowserFullRuntimeChecks("unknown-profile"), /predates hook ABI v5/); assert.throws( - () => validateBrowserFullRuntimeTranscript(events, "standard-v4-residual"), + () => validateBrowserFullRuntimeTranscript(events, "standard-v5-residual"), /unit_refusal did not start in the required order/, ); const report = createBrowserFullRuntimeReport({ events, - structuredHookProfile: "standard-v4", + structuredHookProfile: "standard-v5", environment: { browser: "Chrome", version: "140.0.0.0" }, producedAt: new Date("2026-08-29T12:00:00.000Z"), }); - assert.equal(report.structuredHookProfile, "standard-v4"); + assert.equal(report.structuredHookProfile, "standard-v5"); assert.equal(report.toolVersion, BROWSER_FULL_RUNTIME_TOOL_VERSION); assert.equal(report.passed, true); assert.equal(report.releaseEvidence, false); @@ -488,34 +488,34 @@ test("fails closed on skipped, reordered, unmeasured, duplicate, or extra checks const missing = transcript(); missing.splice(5, 1); assert.throws( - () => validateBrowserFullRuntimeTranscript(missing, "standard-v4"), + () => validateBrowserFullRuntimeTranscript(missing, "standard-v5"), /did not produce a measured pass/, ); const reordered = transcript(); [reordered[2], reordered[4]] = [reordered[4], reordered[2]]; assert.throws( - () => validateBrowserFullRuntimeTranscript(reordered, "standard-v4"), + () => validateBrowserFullRuntimeTranscript(reordered, "standard-v5"), /required order/, ); const unmeasured = transcript(); unmeasured[1] = { ...unmeasured[1], measurements: {} }; assert.throws( - () => validateBrowserFullRuntimeTranscript(unmeasured, "standard-v4"), + () => validateBrowserFullRuntimeTranscript(unmeasured, "standard-v5"), /has no measurements/, ); const nonfinite = transcript(); nonfinite[1] = { ...nonfinite[1], measurements: { observed: Number.NaN } }; assert.throws( - () => validateBrowserFullRuntimeTranscript(nonfinite, "standard-v4"), + () => validateBrowserFullRuntimeTranscript(nonfinite, "standard-v5"), /non-finite/, ); const extra = [...transcript(), { type: "check_started", check: "invented" }]; assert.throws( - () => validateBrowserFullRuntimeTranscript(extra, "standard-v4"), + () => validateBrowserFullRuntimeTranscript(extra, "standard-v5"), /extra events/, ); }); @@ -576,7 +576,7 @@ test("streams physical check progress before the terminal report", async () => { }); function transcript() { - return requiredBrowserFullRuntimeChecks("standard-v4").flatMap((check, index) => [ + return requiredBrowserFullRuntimeChecks("standard-v5").flatMap((check, index) => [ { type: "check_started", check }, { type: "check_passed", check, measurements: { observed: index + 1 } }, ]); diff --git a/webui/scripts/browser-loom.test.mjs b/webui/scripts/browser-loom.test.mjs index a9f2560..91d409c 100644 --- a/webui/scripts/browser-loom.test.mjs +++ b/webui/scripts/browser-loom.test.mjs @@ -1,5 +1,4 @@ import assert from "node:assert/strict"; -import { readFile } from "node:fs/promises"; import { fileURLToPath } from "node:url"; import { createServer } from "vite"; @@ -13,7 +12,7 @@ const server = await createServer({ }); try { - const { BrowserLoomRuntime, composeCall, deriveSeedSchedule, recipeModifier } = await server.ssrLoadModule( + const { BrowserLoomRuntime, deriveSeedSchedule } = await server.ssrLoadModule( "/src/hosted/runtime/browserLoom.ts", ); const { streamWebLlmGeneration } = await server.ssrLoadModule( @@ -2782,122 +2781,6 @@ try { assert.equal(resetTree.nodes.length, 1); assert.notEqual(resetTree.root_id, beforeReset.root_id); - // drowse's `compose_call`, case by case: sampling ranks cast < anchor < call < - // modifier; steering, thinking and the system prompt cast < call < anchor < - // modifier; the seed modifier > call > anchor > cast; observation knobs the call's. - const composeFixture = JSON.parse(await readFile( - new URL("../../drowse/tests/fixtures/browser/recipe-compose-v1.json", import.meta.url), - "utf8", - )); - const samplingDefaults = { - presence_penalty: 0, - frequency_penalty: 0, - return_top_k: 0, - persist_per_layer_scores: false, - persist_subspace_coords: false, - return_probe_readings: true, - }; - const setSamplingFields = (sampling) => sampling === null ? null : Object.fromEntries( - Object.entries(sampling).filter(([key, value]) => - value !== null && value !== undefined && samplingDefaults[key] !== value), - ); - const composeTier = (tier) => tier === undefined ? null : { - steering: tier.steering ?? null, - thinking: tier.thinking ?? null, - ...(Object.hasOwn(tier, "system_prompt") ? { system_prompt: tier.system_prompt } : {}), - sampling: tier.sampling ?? null, - seed: null, - }; - assert.equal(composeFixture.schemaVersion, 1); - for (const fixtureCase of composeFixture.cases) { - const anchor = composeTier(fixtureCase.anchor); - const composed = composeCall({ - steering: fixtureCase.call.steering, - thinking: fixtureCase.call.thinking, - sampling: fixtureCase.call.sampling, - cast: composeTier(fixtureCase.cast), - anchor, - modifier: fixtureCase.modifier === undefined - ? null - : recipeModifier(fixtureCase.modifier, anchor), - }); - const expected = fixtureCase.expected; - assert.equal(composed.steering, expected.steering, fixtureCase.name); - assert.equal(composed.thinking, expected.thinking, fixtureCase.name); - assert.equal(composed.systemPrompt, expected.system_prompt, fixtureCase.name); - assert.deepEqual(setSamplingFields(composed.sampling), expected.sampling, fixtureCase.name); - } - - const sharedLoomFixture = JSON.parse(await readFile( - new URL("../../drowse/tests/fixtures/browser/loom-operation-transcript-v1.json", import.meta.url), - "utf8", - )); - const sharedIds = sharedLoomFixture.operations - .filter((operation) => operation.createdId !== undefined) - .map((operation) => operation.createdId); - const sharedLoomRuntime = new BrowserLoomRuntime({ - session: session(), - generation: generation(), - initialTree: sharedLoomFixture.initial, - now: () => 200, - createId() { - const id = sharedIds.shift(); - assert.notEqual(id, undefined, "the shared loom fixture exhausted its node IDs"); - return id; - }, - }); - const sharedMutations = []; - let sharedPreservedMeasurements; - for (const operation of sharedLoomFixture.operations) { - let method = operation.op; - let args; - if (method === "edit") args = [operation.node, operation.text]; - else if (method === "branch") { - args = [operation.node, operation.text, undefined, operation.role]; - } else if (method === "star") args = [operation.node, operation.value]; - else if (method === "note") args = [operation.node, operation.text]; - else if (method === "navigate" || method === "delete") args = [operation.node]; - else if (method === "castPut") { - args = [operation.label, { - steering: operation.steering, - thinking: operation.thinking, - seed: operation.seed, - notes: operation.notes, - }]; - } else if (method === "reset") { - const assistant = sharedLoomRuntime.snapshot().tree.nodes.find( - (node) => node.id === "assistant-1", - ); - sharedPreservedMeasurements = assistant.tokens[0].measurements; - args = []; - } else { - assert.fail(`unknown shared loom operation ${JSON.stringify(method)}`); - } - await sharedLoomRuntime.request( - { service: "tree", method, args }, - (event) => sharedMutations.push(event.data), - ); - } - assert.deepEqual( - sharedMutations.map((event) => ({ - op: event.op, - rev: event.rev, - added: event.added.map((node) => node.id), - removed: event.removed, - updated: event.updated.map((node) => node.id), - active_node_id: event.active_node_id, - })), - sharedLoomFixture.expected.events, - ); - assert.deepEqual( - sharedPreservedMeasurements, - sharedLoomFixture.expected.preservedMeasurementsBeforeReset, - ); - assert.deepEqual( - canonicalBrowserTree(sharedLoomRuntime.snapshot().tree), - sharedLoomFixture.expected.final, - ); - for (const capturedPrompt of [undefined, null, "", "Speak like a pirate."]) { const capturedTree = structuredClone(exactReplayRuntime.snapshot().tree); const source = capturedTree.nodes.find(node => node.id === branchA.id); @@ -2943,7 +2826,7 @@ try { // refused in drowse's words (the browser measures no prompts, so it holds no prompt capture). { const { compileStructuredHookProgram } = await server.ssrLoadModule("/src/hosted/runtime/structuredHookProgram.ts"); - const { STANDARD_STRUCTURED_HOOK_PROFILE_V4 } = await server.ssrLoadModule("/src/hosted/runtime/structuredHookProfile.ts"); + const { STANDARD_STRUCTURED_HOOK_PROFILE_V5 } = await server.ssrLoadModule("/src/hosted/runtime/structuredHookProfile.ts"); const rendered = []; const unitsEngine = { async streamGeneration(plan, onToken) { @@ -2969,7 +2852,7 @@ try { createId: ids("units-replay"), compileSteering: (expression) => { compiled.push(expression); - return compileStructuredHookProgram(2, [{}, {}], STANDARD_STRUCTURED_HOOK_PROFILE_V4); + return compileStructuredHookProgram(2, [{}, {}], STANDARD_STRUCTURED_HOOK_PROFILE_V5); }, }); await unitsRuntime.generate( @@ -3039,25 +2922,6 @@ function session(config = {}) { }; } -function canonicalBrowserTree(tree) { - return { - rev: tree.rev, - root_id: tree.root_id, - active_node_id: tree.active_node_id, - nodes: tree.nodes.map((node) => ({ - id: node.id, - parent_id: node.parent_id, - role: node.role, - text: node.text, - starred: node.starred, - notes: node.notes, - edit_count: node.edit_count, - })), - children_of: tree.children_of, - cast: tree.cast, - }; -} - function webLlmCancellableGeneration(streamWebLlmGeneration) { let rejectStream; let markStarted; diff --git a/webui/scripts/browser-manifold-fitting.test.mjs b/webui/scripts/browser-manifold-fitting.test.mjs index 719bc55..e9f02cf 100644 --- a/webui/scripts/browser-manifold-fitting.test.mjs +++ b/webui/scripts/browser-manifold-fitting.test.mjs @@ -509,7 +509,7 @@ function loadRequest() { return { model: { id: "fixture-model" }, variant: { - structuredHookProfile: "standard-v4", + structuredHookProfile: "standard-v5", runtimeIdentitySha256: "a".repeat(64), runtimeIdentity: { sourceModel: "fixture/source", @@ -594,6 +594,7 @@ function flatLayer() { centroidMean: new Float64Array(2), mean: new Float64Array(2), basis: new Float64Array([1, 0]), + read: new Float64Array([1, 0]), nodeCoordinates: new Float64Array([-1, 1]), muCoordinates: new Float64Array([-1, 1]), whitenedGram: new Float64Array([1, -1, -1, 1]), @@ -1160,6 +1161,7 @@ function authoredCurvedLayer(withSigma) { centroidMean: new Float64Array(2), mean: new Float64Array(2), basis: new Float64Array([1, 0, 0, 1]), + read: new Float64Array([1, 0, 0, 1]), nodeCoordinates: new Float64Array([-1, 0, 0, 0, 1, 0]), muCoordinates: new Float64Array([-1, 0, 0, 0, 1, 0]), whitenedGram: new Float64Array([ @@ -1249,17 +1251,21 @@ async function monopolarExtractionCheck( metadata: { method: "manifold_pca", name: "calm", - share_metric: "mahalanobis", }, }); assert.equal(harness.published[0].nodes.length, 1); assert.equal(harness.published[0].nodes[0].role, null); assert.equal(harness.generationPlans[0].generationRoleName, "someone_calm"); assert.equal(flatInputs.length, 1); + // The typed fold (drowse 6.1): d = (2, 3) against Σ = 1.1·I writes d/‖d‖_M, reads + // Σ⁻¹d/‖d‖_M, and puts the pole at ‖d‖_M. const layer = flatInputs[0].layers.get(0); - assert.ok(Math.abs(layer.nodeCoordinates[0] - Math.sqrt(13)) < 1e-12); - assert.ok(Math.abs(layer.basis[0] - 2 / Math.sqrt(13)) < 1e-12); - assert.ok(Math.abs(layer.basis[1] - 3 / Math.sqrt(13)) < 1e-12); + const norm = Math.sqrt(13 / 1.1); + assert.ok(Math.abs(layer.nodeCoordinates[0] - norm) < 1e-12); + assert.ok(Math.abs(layer.basis[0] - 2 / norm) < 1e-12); + assert.ok(Math.abs(layer.basis[1] - 3 / norm) < 1e-12); + assert.ok(Math.abs(layer.read[0] - 2 / 1.1 / norm) < 1e-12); + assert.ok(Math.abs(layer.read[1] - 3 / 1.1 / norm) < 1e-12); assert.deepEqual([...flatInputs[0].nodeCoordinates], [1]); } diff --git a/webui/scripts/browser-units-goldens.mjs b/webui/scripts/browser-units-goldens.mjs deleted file mode 100644 index bea1f18..0000000 --- a/webui/scripts/browser-units-goldens.mjs +++ /dev/null @@ -1,1107 +0,0 @@ -#!/usr/bin/env node -// Hook ABI v5 on WebGPU: drowse's units goldens through a fixture library and the WebLLM bridge. -// -// node scripts/browser-units-goldens.mjs --webllm WEB_LLM/lib/index.js \ -// --fixtures DIR --arch qwen3|gemma3 --quantization q0f32|q4f32_1 [--suite all|units|replay|reads] -// [--headed] [--report] -// -// `--report` prints nothing but one release-evidence observation for `webGpuGoldens` -// (record-hosted-evidence.mjs): the library's attested descriptor and every golden file's worst -// |Δ|; the evidence config runs it once per fixture library. -// -// DIR holds build-units-fixtures.py's model directory `units--` and its -// library `libs/units---v5.wasm`. The bridge's schema-4 descriptor is attested -// with the adapter's own function (C0's expected vector); then every block-sites, unit-ablation and -// unit-probes case runs as a raw greedy completion under a drowse-structured-v4 program with eight -// linear probes per layer (`out[layer, last, 0:8]`): per forward the greedy token, its logprob, -// the probe readings and the live unit taps are checked against the files' library tolerance. -// The replay suite drives `drowse_replay_batch_prefill` through the adapter's own block-sites -// surface (webLlmBlockSites.ts, served to the page by Vite): attention-patterns (every head's row at -// positions 2, 5, 8), token-anatomy (taps, write norms, the chosen heads' rows) and unit-activity -// (every unit's device peak, the host ranking, traces, the float16 population). The reads suite -// runs every static-read member of the adapter (browser-units-reads.mjs). -import { createHash } from "node:crypto"; -import { createServer as createHttpServer } from "node:http"; -import { readFile } from "node:fs/promises"; -import { basename, extname, resolve } from "node:path"; -import { fileURLToPath } from "node:url"; -import { chromium } from "playwright"; -import { createServer as createViteServer } from "vite"; -import { verifyReads } from "./browser-units-reads.mjs"; -import { releaseToolBrowserOptions, releaseToolGpuArgs } from "./release-tool-storage-quota.mjs"; - -const options = parseArguments(process.argv.slice(2)); -const webui = fileURLToPath(new URL("..", import.meta.url)); -const goldens = resolve(webui, "../drowse/tests/fixtures/browser"); -const modelDirectory = resolve(options.fixtures, `units-${options.arch}-${options.quantization}`); -const libraryPath = resolve(options.fixtures, "libs", `units-${options.arch}-${options.quantization}-v5.wasm`); -const golden = async (name) => JSON.parse(await readFile(resolve(goldens, `${name}-${options.arch}-v1.json`), "utf8")); -const tiny = JSON.parse(await readFile(resolve(goldens, "units-tiny-models-v1.json"), "utf8")).arches[options.arch]; -const chatConfig = JSON.parse(await readFile(resolve(modelDirectory, "mlc-chat-config.json"), "utf8")); -const tensorCacheBytes = await readFile(resolve(modelDirectory, "tensor-cache.json")); -const modelFiles = ["mlc-chat-config.json", "tensor-cache.json", "tokenizer.json", - ...JSON.parse(tensorCacheBytes.toString("utf8")).records.map((shard) => shard.dataPath)]; - -const vite = await createViteServer({ - root: webui, configFile: false, appType: "custom", logLevel: "silent", - server: { middlewareMode: true, watch: null }, -}); -const [profiles, programs, engineModule] = await Promise.all([ - vite.ssrLoadModule("/src/hosted/runtime/structuredHookProfile.ts"), - vite.ssrLoadModule("/src/hosted/runtime/structuredHookProgram.ts"), - vite.ssrLoadModule("/src/hosted/runtime/webLlmEngine.ts"), -]); - -// ------------------------------------------------------------------- fixture facts --- -const config = tiny.config; -const gemma = options.arch === "gemma3"; -const blockSpec = profiles.validateBlockSpec({ - dFF: config.intermediate_size, nHeads: config.num_attention_heads, - nKvHeads: config.num_key_value_heads, headDim: config.head_dim, sandwich: gemma, - normOffset: gemma ? 1 : 0, activation: gemma ? "gelu_tanh" : "silu", - embedScale: gemma ? Math.sqrt(config.hidden_size) : 1, rmsEps: config.rms_norm_eps, qkNorm: true, - attnScaling: (gemma ? config.query_pre_attn_scalar : config.head_dim) ** -0.5, - attnLogitSoftcap: null, finalLogitSoftcap: null, - ropeTheta: gemma ? config.rope_parameters.full_attention.rope_theta : config.rope_parameters.rope_theta, - ropeLocalTheta: gemma ? config.rope_parameters.sliding_attention.rope_theta : null, - ropeGlobalScale: 1, ropeInGraph: gemma, - slidingWindow: gemma ? config.sliding_window : null, slidingPattern: gemma ? 2 : null, -}); -const L = config.num_hidden_layers; -const d = config.hidden_size; -const hd = config.head_dim; -const profile = profiles.STANDARD_STRUCTURED_HOOK_PROFILE_V4; -const layout = programs.structuredUnitSectionLayout(profile, L, hd); -const context = chatConfig.context_window_size; -// The lock records the library's compiled prefill chunk; the fixture's chat config is the lock here. -const prefillChunkSize = chatConfig.prefill_chunk_size; -const variant = { - structuredHookProfile: "standard-v4", - contextProfiles: [{ contextTokens: context }], - runtimeIdentity: { layerMap: Array.from({ length: L }, (_, i) => i), hiddenSize: d }, -}; - -const tensors = await loadTensorCache(modelDirectory); -const stats = await golden("unit-stats"); -const decode = (value) => { - if (Array.isArray(value)) return Float32Array.from(value); - if (value.encoding !== "float32-le-base64") return Float32Array.from(value.values); - const bytes = Buffer.from(value.data, "base64"); - return new Float32Array(bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength)); -}; -const neuronMean = decode(stats.neuron_mean); -const headMean = decode(stats.head_mean); -const neuronScale = decode(stats.scales.neuron); -const headScale = decode(stats.scales.head); - -// A zero v4 program (no curves; the given affine groups, one per layer at most) with linear -// probes e_0…e_7 at every layer. -function baseProgram(affines = []) { - const layers = Array.from({ length: L }, (_, layer) => ({ - probes: Array.from({ length: 8 }, (_, k) => { - const direction = new Array(d).fill(0); - direction[k] = 1; - return { kind: "linear", direction, bias: 0 }; - }), - ...(affines.some((a) => a.layer === layer) - ? { affineGroups: affines.filter((a) => a.layer === layer).map((a) => a.group) } : {}), - })); - return programs.compileStructuredHookProgram(d, layers, profile); -} - -class UnitTables { - constructor() { - this.neurons = []; this.heads = []; this.neuronTaps = []; this.headTaps = []; this.triggers = []; - } - group(trigger) { - const key = JSON.stringify(trigger); - let index = this.triggers.findIndex((item) => JSON.stringify(item) === key); - if (index < 0) { index = this.triggers.length; this.triggers.push(trigger); } - return index; - } - ablate(kind, layer, index, keep, bias, trigger) { - (kind === "neuron" ? this.neurons : this.heads).push({ layer, index, group: this.group(trigger), keep, bias }); - } - tap(kind, layer, index) { - const slot = this.neuronTaps.length + this.headTaps.length; - (kind === "neuron" ? this.neuronTaps : this.headTaps).push({ layer, index, slot, gram: kind === "head" ? headGram(layer, index) : null }); - return slot; - } - section() { - const meta = new Uint32Array(layout.metaLength); - const coeff = new Float32Array(layout.coeffLength); - const grams = new Float32Array(layout.tapGramsLength); - const m = layout.meta; - const c = layout.coeff; - const csr = (entries, name) => { - const ordered = entries.map((entry, at) => ({ entry, at })).sort((a, b) => a.entry.layer - b.entry.layer || a.at - b.at).map((x) => x.entry); - for (let layer = 0; layer <= L; layer += 1) meta[m[name].offset + layer] = ordered.filter((e) => e.layer < layer).length; - return ordered; - }; - csr(this.neurons, "neuronOffsets").forEach((e, i) => { - meta[m.neuronIndex.offset + i] = e.index; meta[m.neuronGroup.offset + i] = e.group; - coeff[c.neuronKeep.offset + i] = e.keep; coeff[c.neuronBias.offset + i] = e.bias; - }); - csr(this.heads, "headOffsets").forEach((e, i) => { - meta[m.headIndex.offset + i] = e.index; meta[m.headGroup.offset + i] = e.group; - coeff[c.headKeep.offset + i] = e.keep; coeff.set(e.bias, c.headBias.offset + i * hd); - }); - csr(this.neuronTaps, "tapNeuronOffsets").forEach((e, i) => { - meta[m.tapNeuronIndex.offset + i] = e.index; meta[m.tapNeuronSlot.offset + i] = e.slot; - }); - csr(this.headTaps, "tapHeadOffsets").forEach((e, i) => { - meta[m.tapHeadIndex.offset + i] = e.index; meta[m.tapHeadSlot.offset + i] = e.slot; - grams.set(e.gram, i * hd * hd); - }); - return { unitMeta: meta, unitCoeff: coeff, unitActive: new Float32Array(layout.activeLength), tapGrams: grams }; - } -} - -function headGram(layer, head) { - const suffix = `layers.${layer}.self_attn.o_proj`; - const name = [...tensors.keys()].find((key) => key.includes(suffix)); - const prefix = name.slice(0, name.lastIndexOf(".")); - const weight = dequantized(prefix); - const rows = d; - const gamma = gemma ? tensors.get(prefix.replace("self_attn.o_proj", "post_attention_layernorm") + ".weight").values : null; - const gram = new Float32Array(hd * hd); - for (let a = 0; a < hd; a += 1) { - for (let b = 0; b < hd; b += 1) { - let sum = 0; - for (let r = 0; r < rows; r += 1) { - const g = gamma === null ? 1 : gamma[r]; - sum += g * weight[r * weight.columns + head * hd + a] * g * weight[r * weight.columns + head * hd + b]; - } - gram[a * hd + b] = sum; - } - } - return gram; -} - -function dequantized(prefix) { - const plain = tensors.get(prefix + ".weight"); - if (plain !== undefined) return Object.assign(Float64Array.from(plain.values), { columns: plain.shape[1] }); - const weight = tensors.get(prefix + ".q_weight"); - const scale = tensors.get(prefix + ".q_scale"); - const [rows, packed] = weight.shape; - const columns = packed * 8; - const out = new Float64Array(rows * columns); - for (let r = 0; r < rows; r += 1) { - for (let col = 0; col < columns; col += 1) { - const word = weight.values[r * packed + (col >> 3)]; - const code = (word >>> ((col & 7) * 4)) & 15; - out[r * columns + col] = (code - 7) * scale.values[r * scale.shape[1] + (col >> 5)]; - } - } - return Object.assign(out, { columns }); -} - -function parseTrigger(text) { - if (text === undefined || text === null) return null; - if (text === "prompt" || text === "before") return { prompt: true, generated: false }; - if (text === "response") return { prompt: false, generated: true, response: true }; - if (text.startsWith("first:")) return { prompt: false, first_n: Number(text.slice(6)) }; - const gate = /^when:(\S+)\s*(>=|<=|>|<)\s*(\S+)$/.exec(text); - if (gate) return { gate: { probe: gate[1], op: gate[2], threshold: Number(gate[3]) } }; - throw new Error(`unsupported trigger ${text}`); -} - -function parseUnit(name) { - const match = /^(neuron|head)\/L(\d+)[nh](\d+)$/.exec(name); - return { kind: match[1], layer: Number(match[2]), index: Number(match[3]) }; -} - -function terms(steering) { - if (steering === null) return []; - return steering.split(" + ").map((text) => { - const match = /^(?:([-+]?[0-9.]+)\s+)?!(neuron|head)\/L(\d+)[nh](\d+)(?:@(.+))?$/.exec(text.trim()); - if (!match) throw new Error(`unsupported term ${text}`); - return { alpha: match[1] ? Number(match[1]) : 1, kind: match[2], layer: Number(match[3]), index: Number(match[4]), trigger: parseTrigger(match[5]) }; - }); -} - -const scaleOf = (kind, layer, index) => kind === "neuron" - ? [neuronScale[(layer * 2) * config.intermediate_size + index], neuronScale[(layer * 2 + 1) * config.intermediate_size + index]] - : headScale[layer * config.num_attention_heads + index]; - -// A case for the page: the program, the triggers (gates resolved to tap slots and scales), and -// what each forward must read. -function pageCase({ name, tables, steering, gates, taps, affines = [], forwards, tolerance }) { - const unit = new UnitTables(); - if (tables !== undefined) { - for (const table of tables) { - const trigger = table.trigger; - if (table.site === "act") { - table.entries.forEach((entry, at) => unit.ablate("neuron", table.layer, entry, table.keep[at], table.bias[at], trigger)); - } else { - for (let start = 0; start < table.entries.length; start += hd) { - unit.ablate("head", table.layer, table.entries[start] / hd, table.keep[start], Float32Array.from(table.bias.slice(start, start + hd)), trigger); - } - } - } - } - for (const term of terms(steering ?? null)) { - const mean = term.kind === "neuron" - ? neuronMean[term.layer * config.intermediate_size + term.index] - : headMean.subarray((term.layer * config.num_attention_heads + term.index) * hd, (term.layer * config.num_attention_heads + term.index + 1) * hd); - const c = Math.fround(term.alpha); - unit.ablate(term.kind, term.layer, term.index, Math.fround(1 - term.alpha), - typeof mean === "number" ? Math.fround(c * mean) : Float32Array.from(mean, (v) => Math.fround(c * v)), term.trigger); - } - const slots = {}; - for (const unitName of new Set([...(taps ?? []), ...(gates ?? [])])) { - const parsed = parseUnit(unitName); - slots[unitName] = { ...parsed, slot: unit.tap(parsed.kind, parsed.layer, parsed.index), scale: scaleOf(parsed.kind, parsed.layer, parsed.index) }; - } - const program = { ...baseProgram(affines), ...unit.section() }; - return { - name, - program: serialize(program), - triggers: unit.triggers.map((trigger) => trigger === null ? null : { - ...trigger, ...(trigger.gate ? { gate: { ...trigger.gate, ...slots[trigger.gate.probe] } } : {}), - }), - slots, - forwards, - tolerance, - }; -} - -function serialize(program) { - const out = {}; - for (const [key, value] of Object.entries(program)) { - if (ArrayBuffer.isView(value)) out[key] = { type: value.constructor.name, values: Array.from(value) }; - else if (["hookAbi", "format", "hiddenSize", "layerCount"].includes(key)) out[key] = value; - } - return out; -} - -const logSoftmax = (logits) => { - let max = -Infinity; - for (const value of logits) max = Math.max(max, value); - let sum = 0; - for (const value of logits) sum += Math.exp(value - max); - const lse = max + Math.log(sum); - return Array.from(logits, (value) => value - lse); -}; - -// ------------------------------------------------------------------------ the cases --- -const sites = await golden("block-sites"); -const ablation = await golden("unit-ablation"); -const probesGolden = await golden("unit-probes"); -const push = await golden("neuron-push"); -// The `mixed` case's push, lowered by drowse (browser-runtime/fixtures, build-mixed-affine.py). -const mixedAffineDoc = JSON.parse(await readFile(resolve(webui, "../browser-runtime/fixtures/unit-ablation-mixed-affine-v1.json"), "utf8")); -if (mixedAffineDoc.fixtureModels.sha256 !== ablation.fixtureModels.sha256) { - throw new Error("unit-ablation-mixed-affine-v1.json names another fixture model file: regenerate it"); -} -const mixedAffine = mixedAffineDoc.arches[options.arch]; -// An always-on push's recorded affine groups (neuron-push's case shape), one per layer. -function affineTerms(doc, expression) { - const found = doc.cases.find((c) => c.expression === expression); - if (found.trigger.gate !== null || !found.trigger.prompt) throw new Error("affineTerms handles always-on pushes only"); - return found.layers.map((term) => ({ - layer: term.layer, - group: { active: true, basis: [term.basis], neutral: term.neutral, target: [term.target], along: term.along, kappa: [0] }, - })); -} -const library = sites.tolerance.library; -const prompt = sites.ids; -const cases = []; -const outRows = (value, row) => { - const out = decode(value); - const [layers, rows, width] = value.shape; - return Array.from({ length: layers }, (_, layer) => Array.from(out.subarray((layer * rows + row) * width, (layer * rows + row) * width + 8))); -}; -cases.push(pageCase({ - name: "block-sites", tables: [], forwards: [{ - token: null, logprobs: logSoftmax(decode(sites.logits_last)), - out: outRows(sites.sites.out, prompt.length - 1), - }], tolerance: library, -})); -for (const item of ablation.cases) { - const affines = item.name === "push-and-ablate" ? affineTerms(push, "0.3 neuron/L2n7") - : item.name === "mixed" ? affineTerms(mixedAffine, item.steering.split(" + ")[0]) - : []; - cases.push(pageCase({ - name: `unit-ablation:${item.name}`, - tables: item.tables, - gates: item.tables.flatMap((t) => t.trigger.gate ? [t.trigger.gate.probe] : []), - affines, - forwards: item.forwards.map((forward, number) => { - const lastRow = forward.out_rows.indexOf(forward.ids.length - 1); - const out = outRows(forward.out, lastRow); - for (const { layer, group } of affines) { - // Probes read after the post-block hook, which adds the push at its layer. - out[layer] = out[layer].map((value, k) => Math.fround(value + group.along * group.target[0] * group.basis[0][k])); - } - return { token: item.forwards[number + 1]?.ids[0] ?? null, logprobs: logSoftmax(decode(forward.logits)), out }; - }), - tolerance: library, - })); -} -for (const item of probesGolden.cases) { - const gateTerms = terms(item.steering).filter((t) => t.trigger?.gate); - cases.push(pageCase({ - name: `unit-probes:${item.name}`, - steering: item.steering, - taps: [...probesGolden.probes, ...(item.gate_scalars.length ? [probesGolden.gate_unit] : [])], - gates: gateTerms.map((t) => t.trigger.gate.probe), - forwards: item.forwards.map((forward, number) => ({ - token: item.tokens[number], units: forward.units, - gate: item.gate_scalars[number]?.[probesGolden.gate_unit] ?? null, - })), - tolerance: library, - })); -} - -// ---------------------------------------------------------------- replay cases (B4b) --- -// Each replay runs in the page through the adapter's own `webLlmBlockSitesBackend` over the -// bridge: `openReplay` (C0's `encodeReplayMeta`), segments of at most 16 positions (so the -// KV-continuing path is exercised), `finish`, and `attentionRows` on the pattern capture. -const REPLAY_PIECE = 16; -const RAW_FIRST_IDS = { qwen3: [45], gemma3: [32] }; -const H = config.num_attention_heads; -const F = config.intermediate_size; -const unitScalesData = (() => { - const width = 2 * F + H; - const out = new Float32Array(L * width); - for (let layer = 0; layer < L; layer += 1) { - for (let n = 0; n < F; n += 1) { - out[layer * width + n] = Math.max(neuronScale[(layer * 2) * F + n], 1e-6); - out[layer * width + F + n] = Math.max(neuronScale[(layer * 2 + 1) * F + n], 1e-6); - } - for (let h = 0; h < H; h += 1) out[layer * width + 2 * F + h] = Math.max(headScale[layer * H + h], 1e-6); - } - return out; -})(); -const emptyControls = (() => { - const program = baseProgram(); - return { affine: program.affineActive.length, curve: program.curveActive.length }; -})(); - -/** A replay case for the page: the program (null: unsteered), the segments as fed (each piece - * ≤ 16 positions, controls held), the request, and the heads whose rows to read. */ -function replayCase({ name, steering = null, affines = [], unitTerms = [], segments, request, heads = [] }) { - let program = null; - let triggers = []; - if (steering !== null || affines.length > 0 || unitTerms.length > 0) { - const unit = new UnitTables(); - for (const term of [...terms(steering), ...unitTerms]) { - const mean = term.kind === "neuron" - ? neuronMean[term.layer * F + term.index] - : headMean.subarray((term.layer * H + term.index) * hd, (term.layer * H + term.index + 1) * hd); - const c = Math.fround(term.alpha); - const bias = term.bias !== undefined ? term.bias - : typeof mean === "number" ? Math.fround(c * mean) : Float32Array.from(mean, (v) => Math.fround(c * v)); - unit.ablate(term.kind, term.layer, term.index, term.keep ?? Math.fround(1 - term.alpha), bias, term.trigger); - } - program = serialize({ ...baseProgram(affines), ...unit.section() }); - triggers = unit.triggers; - } - const pieces = []; - for (const segment of segments) { - for (let start = 0; start < segment.ids.length; start += REPLAY_PIECE) { - pieces.push({ tokenIds: segment.ids.slice(start, start + REPLAY_PIECE), unitActive: [...segment.active, 0, 0, 0, 0].slice(0, 4) }); - } - } - const tokenCount = segments.reduce((sum, segment) => sum + segment.ids.length, 0); - return { name, program, triggers, pieces, request: { ...request, tokenCount }, heads, controls: emptyControls }; -} - -const anatomyGolden = await golden("token-anatomy"); -const patternsGolden = await golden("attention-patterns"); -const activityGolden = await golden("unit-activity"); -const pushAffine = (expression) => affineTerms(push, expression); -const allLayers = Array.from({ length: L }, (_, layer) => layer); -const everyHead = allLayers.flatMap((layer) => Array.from({ length: H }, (_, head) => ({ layer, head }))); -const replayCases = []; -for (const item of patternsGolden.cases) { - for (const row of item.rows) { - replayCases.push({ ...replayCase({ - name: `attention-patterns:${item.name}@${row.position}`, steering: item.steering, - segments: [{ ids: patternsGolden.ids, active: [true] }], - request: { anatomyPosition: row.position, activity: null, patternLayers: allLayers }, - heads: everyHead, - }), check: { kind: "patterns", row } }); - } -} -for (const item of anatomyGolden.cases) { - const ids = item.intermediates.ids; - const pushTerm = item.steering?.split(" + ").find((t) => t.startsWith("0.3 neuron/")) ?? null; - const ablation = item.steering?.split(" + ").filter((t) => !t.startsWith("0.3 neuron/")).join(" + ") || null; - const record = item.envelope.measurements.anatomy; - replayCases.push({ ...replayCase({ - name: `token-anatomy:${item.name}`, steering: ablation, affines: pushTerm === null ? [] : pushAffine(pushTerm), - segments: [{ ids, active: [true] }], - request: { anatomyPosition: ids.length - 1, activity: null, patternLayers: allLayers }, - heads: (record.patterns ?? []).map((p) => ({ layer: p.layer, head: p.head })), - }), check: { kind: "anatomy", item } }); -} -{ - const first = anatomyGolden.cases[0]; - const promptLength = first.envelope.measurements.anatomy.token.prompt_length; - const chat = first.intermediates.ids.slice(0, promptLength); - for (const item of activityGolden.cases) { - const args = item.arguments; - const tokens = item.result.tokens.map((t) => t.token_id); - let ids; let spans; let segments; const unitTerms = []; - if (item.name === "generated" || item.name === "segmented") { - ids = [...chat, ...tokens.slice(0, -1)]; - spans = [{ firstRow: 0, rows: tokens.length, firstPosition: promptLength - 1 }]; - segments = item.result.steering === null - ? [{ ids, active: [] }] - : [{ ids: ids.slice(0, promptLength), active: [true] }, { ids: ids.slice(promptLength), active: [false] }]; - } else if (item.name === "sink" || item.name === "sink-population") { - ids = [...RAW_FIRST_IDS[options.arch], ...tokens.slice(0, -1)]; - spans = [{ firstRow: 0, rows: tokens.length, firstPosition: 0 }]; - segments = [{ ids, active: [] }]; - } else if (item.name === "authored") { - const start = chat.findIndex((_, i) => tokens.every((t, k) => chat[i + k] === t)); - ids = chat.slice(0, start + tokens.length - 1); - spans = [{ firstRow: 0, rows: tokens.length, firstPosition: start - 1 }]; - segments = [{ ids, active: [] }]; - } else { - ids = args.ids; - const runs = args.runs; - spans = runs.map(([first, at], i) => ({ - firstRow: first, rows: (runs[i + 1]?.[0] ?? args.raw_ids.length) - first, firstPosition: at - 1, - })); - if (item.name === "excluded-and-zero") { - unitTerms.push({ kind: "neuron", layer: 1, index: 5, alpha: 1, keep: 0, bias: 0, trigger: null }); - segments = [{ ids, active: [true] }]; - } else { - segments = [{ ids, active: [] }]; - } - } - replayCases.push({ ...replayCase({ - name: `unit-activity:${item.name}`, steering: item.result.steering, unitTerms, segments, - request: { - anatomyPosition: null, patternLayers: null, - activity: { - spans, rowCount: tokens.length, - traces: (args.units ?? []).map((u) => parseUnit(u)), - populationRow: args.raw_index ?? null, - }, - }, - }), check: { kind: "activity", item, index: activityGolden.cases.indexOf(item) } }); - } -} - -// ---------------------------------------------------------------------- the browser --- -const libraryBytes = await readFile(libraryPath); -const webllm = await readFile(resolve(options.webllm)); -const http = createHttpServer(async (request, response) => { - const url = new URL(request.url ?? "/", "http://127.0.0.1"); - const send = (body, type, status = 200) => { - response.writeHead(status, { "content-type": type, "cross-origin-opener-policy": "same-origin", "cross-origin-embedder-policy": "require-corp" }); - response.end(body); - }; - try { - if (url.pathname === "/") return send("units", "text/html"); - if (url.pathname === "/webllm.js") return send(webllm, "text/javascript"); - if (url.pathname === "/model-lib.wasm") return send(libraryBytes, "application/wasm"); - if (url.pathname.startsWith("/model/")) { - const name = basename(url.pathname); - if (!modelFiles.includes(name)) return send("not found", "text/plain", 404); - // tensor-cache.json is the recorded model identity, so the page gets those exact bytes. - const body = name === "tensor-cache.json" ? tensorCacheBytes : await readFile(resolve(modelDirectory, name)); - return send(body, extname(name) === ".json" ? "application/json" : "application/octet-stream"); - } - // The adapter's own modules (webLlmBlockSites.ts and what it imports), served by Vite. - if (url.pathname.startsWith("/src/") || url.pathname.startsWith("/@") || url.pathname.startsWith("/node_modules/")) { - return vite.middlewares(request, response, () => send("not found", "text/plain", 404)); - } - return send("not found", "text/plain", 404); - } catch (error) { - console.error(error); - return send(error instanceof Error ? error.message : "request failed", "text/plain", 500); - } -}); -await new Promise((ok) => http.listen(options.port, "127.0.0.1", ok)); -const origin = `http://127.0.0.1:${http.address().port}`; -const browser = await chromium.launch(releaseToolBrowserOptions({ - headless: !options.headed, args: releaseToolGpuArgs({ headless: !options.headed }), -})); -let failures = 0; -// The report mode's observation: stdout carries it alone, so progress lines are dropped. -const log = options.report ? () => {} : console.log; -const suites = {}; -const worstOf = (name, value) => { suites[name] = Math.max(suites[name] ?? 0, value); }; -let descriptorRecord = null; -try { - const page = await browser.newPage(); - page.setDefaultTimeout(300_000); - page.on("console", (message) => { - if (message.type() === "error") process.stderr.write(`browser console: ${message.text()}\n`); - }); - await page.goto(origin); - const profileValue = await page.evaluate(async () => { - const module = await import("/webllm.js"); - const engine = new module.MLCEngine({ - logLevel: "WARN", - appConfig: { cacheBackend: "indexeddb", model_list: [{ model: `${location.origin}/model/`, model_id: "units", model_lib: `${location.origin}/model-lib.wasm` }] }, - }); - await engine.reload("units"); - window.engine = engine; - window.webllmModule = module; - return { profile: await engine.getDrowseStructuredHookProfile("units"), units: await engine.supportsDrowseUnitSites("units") }; - }); - // The adapter's own attestation: the library's descriptor against the lock-shaped model. - const attested = engineModule.attestCompiledStructuredHookProfile(profileValue.profile, { variant, blockSpec, prefillChunkSize }, "block-sites-v5"); - descriptorRecord = { schema: 4, fields: attested.descriptor.length, unitSites: attested.unitSites, unitsPair: profileValue.units }; - log(`descriptor attested: ${attested.descriptor.length} fields, unit sites ${attested.unitSites}, units pair ${profileValue.units}`); - if (options.suite === "units" || options.suite === "all") { - for (const item of cases) { - const result = await page.evaluate(runCase, { item, textIds: gemma ? prompt.slice(1) : prompt }); - const worst = checkCase(item, result); - worstOf(item.name.split(":")[0], worst); - log(`${item.name}: ${result.forwards.length} forwards, worst |Δ| ${worst.toExponential(2)}`); - } - } - if (options.suite === "reads" || options.suite === "all") { - const capabilities = engineModule.blockSitesCapabilitiesFor(attested, { variant, blockSpec, unitRefusal: null, prefillChunkSize }, chatConfig.vocab_size); - await page.evaluate(installReads, { capabilities }); - const call = async (member, ...args) => { - const out = await page.evaluate(callRead, { member, args: args.map(toPage) }); - if ("error" in out) throw new Error(`${member}: ${out.error}`); - return fromPage(out.ok); - }; - const f32 = (data, shape) => ({ dtype: "f32", shape, data: Float32Array.from(data) }); - const i32 = (data, shape) => ({ dtype: "i32", shape, data: Int32Array.from(data) }); - const u32 = (data, shape) => ({ dtype: "u32", shape, data: Uint32Array.from(data) }); - const worst = await verifyReads({ - call, f32, i32, u32, weights: readWeights(), golden, decode, - L, d, dFF: blockSpec.dFF, H: blockSpec.nHeads, KV: blockSpec.nKvHeads, hd, V: chatConfig.vocab_size, - sandwich: gemma, eps: config.rms_norm_eps, embedScale: blockSpec.embedScale, - }); - for (const [name, value] of Object.entries(worst)) worstOf(name, value); - log(`reads ${options.arch} ${options.quantization}: ${Object.entries(worst).map(([k, v]) => `${k} ${v.toExponential(2)}`).join(", ")}`); - } - if (options.suite === "replay" || options.suite === "all") { - const capabilities = engineModule.blockSitesCapabilitiesFor(attested, { variant, blockSpec, unitRefusal: null, prefillChunkSize }, chatConfig.vocab_size); - await page.evaluate((scales) => { window.unitScales = scales; }, Array.from(unitScalesData)); - const worstByGolden = {}; - for (const item of replayCases) { - const result = await page.evaluate(runReplay, { item, capabilities }); - const worst = checkReplay(item, result); - const key = item.name.split(":")[0]; - worstByGolden[key] = Math.max(worstByGolden[key] ?? 0, worst); - log(`${item.name}: ${item.pieces.length} forwards, worst |Δ| ${worst.toExponential(2)}`); - } - for (const [name, value] of Object.entries(worstByGolden)) worstOf(name, value); - log(`replay ${options.arch} ${options.quantization}: ${Object.entries(worstByGolden).map(([k, v]) => `${k} ${v.toExponential(2)}`).join(", ")}`); - } -} catch (error) { - failures += 1; - console.error(error?.stack ?? String(error)); -} finally { - await browser.close(); - http.close(); - await vite.close(); -} -if (failures === 0 && options.report) { - if (options.suite !== "all" || descriptorRecord === null) { - console.error("--report covers the whole suite (--suite all)"); - process.exit(1); - } - // The bytes that ran: read once before the browser started and served from memory. - const digest = (bytes) => createHash("sha256").update(bytes).digest("hex"); - process.stdout.write(`${JSON.stringify({ - schemaVersion: 1, - evidenceType: "webGpuGoldens", - fixturePath: "drowse/tests/fixtures/browser/units-tiny-models-v1.json", - passed: true, - producedAt: new Date().toISOString(), - results: { - backend: "webgpu", - // What actually ran: the bridge bundle served to the page, each fixture library and model. - bridgeSha256: digest(webllm), - libraries: { - [`${options.arch}-${options.quantization}`]: { - descriptor: descriptorRecord, - librarySha256: digest(libraryBytes), - modelSha256: digest(tensorCacheBytes), - suites: Object.fromEntries(Object.entries(suites).sort(([a], [b]) => a.localeCompare(b))), - }, - }, - }, - })}\n`); -} -process.exit(failures === 0 ? 0 : 1); - -// In the page: one case as a raw greedy completion, the controls updated before each decode -// forward from the previous forward's taps (native's gates), the bundle read after each token. -async function runCase({ item, textIds }) { - const engine = window.engine; - const program = {}; - for (const [key, value] of Object.entries(item.program)) { - program[key] = value && typeof value === "object" && "type" in value ? new globalThis[value.type](value.values) : value; - } - const active = (trigger, forward, scores) => { - if (trigger === null) return true; - if (forward === 0) return !trigger.gate && trigger.prompt !== false; - if (trigger.generated === false || trigger.response === false) return false; - if (trigger.first_n != null && forward >= trigger.first_n) return false; - if (trigger.after_n != null && forward < trigger.after_n) return false; - if (trigger.gate) { - const score = scores[trigger.gate.probe]; - if (score === undefined) return false; - const t = trigger.gate.threshold; - return { ">": score > t, ">=": score >= t, "<": score < t, "<=": score <= t }[trigger.gate.op]; - } - return true; - }; - const unitActive = (forward, scores) => { - const values = new Float32Array(4); - item.triggers.forEach((trigger, group) => { values[group] = active(trigger, forward, scores) ? 1 : 0; }); - return values; - }; - program.unitActive = unitActive(0, {}); - await engine.resetChat(false, "units"); - await engine.setDrowseStructuredProgram(program, "units"); - const promptText = await engine.decodeDrowseTokens(textIds, "units"); - const forwards = []; - const stream = await engine.completions.create({ - prompt: promptText, stream: true, max_tokens: item.forwards.length, temperature: 0, - logprobs: true, top_logprobs: 5, model: "units", ignore_eos: true, - }); - for await (const chunk of stream) { - const choice = chunk.choices?.[0]; - const rows = choice?.logprobs?.content ?? []; - for (const row of rows) { - const bundle = await engine.readDrowseMeasurementBundle("units"); - const taps = Array.from(bundle.unitTaps ?? []); - const scores = {}; - for (const [unit, slot] of Object.entries(item.slots)) { - const raw = taps[slot.slot]; - const scale = typeof slot.scale === "number" ? slot.scale : slot.scale[raw >= 0 ? 0 : 1]; - scores[unit] = Math.fround(Math.fround(raw) / Math.fround(scale)); - } - forwards.push({ - token: row.token_id ?? null, tokenText: row.token, logprob: row.logprob, - scalar: Array.from(bundle.scalar ?? []), taps, scores, - }); - const next = forwards.length; - if (next < item.forwards.length) { - await engine.updateDrowseStructuredControls(program.affineActive, program.curveActive, "units", unitActive(next, scores)); - } - } - } - return { forwards, promptText }; -} - -function checkCase(item, result) { - let worst = 0; - const close = (label, expected, actual, atol = item.tolerance.atol, rtol = item.tolerance.rtol) => { - const error = Math.abs(actual - expected); - if (!(error <= atol + rtol * Math.abs(expected))) { - throw new Error(`${item.name} ${label}: library ${actual} vs golden ${expected} (|Δ| ${error})`); - } - worst = Math.max(worst, error); - }; - if (result.forwards.length !== item.forwards.length) { - throw new Error(`${item.name}: ${result.forwards.length} forwards, the golden has ${item.forwards.length}`); - } - item.forwards.forEach((expected, number) => { - const actual = result.forwards[number]; - const label = `forward ${number}`; - if (expected.token !== null && expected.token !== undefined && actual.token !== expected.token) { - throw new Error(`${item.name} ${label}: greedy token ${actual.token}, the golden's next input ${expected.token}`); - } - if (expected.logprobs !== undefined) { - // Greedy decoding reports no sampler logprob; the golden's own argmax is the token. - const best = expected.logprobs.indexOf(Math.max(...expected.logprobs)); - if (actual.token !== best) { - throw new Error(`${item.name} ${label}: greedy token ${actual.token}, the golden logits' argmax ${best}`); - } - } - if (expected.out !== undefined) { - expected.out.forEach((row, layer) => row.forEach((value, k) => close(`${label} out[L${layer}][${k}]`, value, actual.scalar[layer * 8 + k]))); - } - if (expected.units !== undefined) { - for (const [unit, golden] of Object.entries(expected.units)) { - close(`${label} ${unit} raw`, golden.raw, actual.taps[item.slots[unit].slot]); - close(`${label} ${unit} reading`, golden.value, actual.scores[unit], item.tolerance.z_atol, 0); - } - } - if (expected.gate !== null && expected.gate !== undefined) { - const unit = Object.keys(item.slots).find((name) => item.slots[name].layer === 3); - close(`${label} gate`, expected.gate, actual.scores[unit], item.tolerance.z_atol, 0); - } - }); - return worst; -} - -// In the page: one replay through the adapter's block-sites surface over the bridge. -async function runReplay({ item, capabilities }) { - const engine = window.engine; - const { webLlmBlockSitesBackend } = await import("/src/hosted/runtime/webLlmBlockSites.ts"); - const { f32Tensor } = await import("/src/hosted/runtime/modelBackend.ts"); - const backend = webLlmBlockSitesBackend(capabilities, { - call: (request) => engine.drowseBlockSites(request, "units"), - installProgram: (program) => engine.setDrowseStructuredProgram(program, "units"), - }); - let program = null; - if (item.program !== null) { - program = {}; - for (const [key, value] of Object.entries(item.program)) { - program[key] = value && typeof value === "object" && "type" in value ? new globalThis[value.type](value.values) : value; - } - } - const L = capabilities.layerCount; - const scales = item.request.activity === null ? null : await backend.uploadUnitScales( - f32Tensor(Float32Array.from(window.unitScales), [L, window.unitScales.length / L]), - ); - const replay = await backend.openReplay({ - ...item.request, - program, - activity: item.request.activity === null ? null : { ...item.request.activity, scales }, - }); - for (const piece of item.pieces) { - await replay.forward({ - tokenIds: Int32Array.from(piece.tokenIds), - controls: { - affineActive: program?.affineActive ?? new Uint32Array(item.controls.affine), - curveActive: program?.curveActive ?? new Uint32Array(item.controls.curve), - unitActive: Float32Array.from(piece.unitActive), - }, - }); - } - const result = await replay.finish(); - const rows = []; - if (result.patterns !== null && item.heads.length > 0) { - for (let start = 0; start < item.heads.length; start += 16) { - const out = await backend.attentionRows(result.patterns, item.heads.slice(start, start + 16)); - rows.push(...Array.from(out.data)); - } - } - if (result.patterns !== null) await backend.release(result.patterns); - if (scales !== null) await backend.release(scales); - return { - anatomy: result.anatomyTaps === null ? null : Array.from(result.anatomyTaps.data), - state: result.activity === null ? null : Array.from(result.activity.state.data), - traces: result.activity === null ? null : Array.from(result.activity.traces.data), - population: result.activity?.population ? Array.from(result.activity.population.data) : null, - rows, - }; -} - -/** The replay's results against the goldens (the C VM harness's checks, units_goldens.py). */ -function checkReplay(item, result) { - let worst = 0; - const library = item.check.kind === "patterns" ? patternsGolden.tolerance.library - : item.check.kind === "anatomy" ? anatomyGolden.tolerance.library : activityGolden.tolerance.library; - const close = (label, expected, actual, atol = library.atol, rtol = library.rtol) => { - const error = Math.abs(actual - expected); - if (!(error <= atol + rtol * Math.abs(expected))) { - throw new Error(`${item.name} ${label}: library ${actual} vs golden ${expected} (|Δ| ${error})`); - } - worst = Math.max(worst, error); - }; - const d = config.hidden_size; - const stride = 6 * d + F + H * hd; - const offsets = { block_in: 0, mid: d, out_pre: 2 * d, out: 3 * d, attn_o: 4 * d, mlp_o: 5 * d, act: 6 * d, z: 6 * d + F }; - if (item.check.kind === "patterns") { - const p = item.check.row.position; - const width = result.rows.length / item.heads.length; - item.heads.forEach(({ layer, head }, at) => { - const expected = decode(item.check.row.layers[layer]); - for (let j = 0; j < width; j += 1) { - const actual = result.rows[at * width + j]; - if (j <= p) close(`L${layer}h${head}[${j}]`, expected[head * (p + 1) + j], actual, library.probability_atol, 0); - } - }); - } else if (item.check.kind === "anatomy") { - const inter = item.check.item.intermediates; - for (const name of ["block_in", "mid", "out", "act", "z"]) { - const value = inter.taps[name]; - const expected = decode(value); - const width = value.shape[1]; - for (let layer = 0; layer < L; layer += 1) { - for (let k = 0; k < width; k += 1) { - close(`${name}[L${layer}][${k}]`, expected[layer * width + k], result.anatomy[layer * stride + offsets[name] + k]); - } - } - } - const norms = decode(inter.head_write_norms); - for (let layer = 0; layer < L; layer += 1) { - const o = result.anatomy.slice(layer * stride + offsets.attn_o, layer * stride + offsets.attn_o + d); - const r = gemma ? 1 / Math.sqrt(o.reduce((s, v) => s + v * v, 0) / d + config.rms_norm_eps) : 1; - for (let head = 0; head < H; head += 1) { - const z = result.anatomy.slice(layer * stride + offsets.z + head * hd, layer * stride + offsets.z + (head + 1) * hd); - const gram = headGram(layer, head); - let q = 0; - for (let a = 0; a < hd; a += 1) for (let b = 0; b < hd; b += 1) q += z[a] * gram[a * hd + b] * z[b]; - close(`write norm L${layer}h${head}`, norms[layer * H + head], Math.sqrt(Math.max(q, 0)) * r); - } - } - const record = item.check.item.envelope.measurements.anatomy; - const p = inter.ids.length - 1; - const width = result.rows.length / Math.max(1, item.heads.length); - (record.patterns ?? []).forEach((pattern, at) => { - pattern.weights.forEach((weight, j) => close(`pattern ${pattern.unit}[${j}]`, weight, result.rows[at * width + j], - library.probability_atol + anatomyGolden.tolerance.rounded.atol, 0)); - }); - } else { - const { item: golden, index } = item.check; - const z = library.z_atol + activityGolden.tolerance.rounded.atol; - const peak = decode(golden.diagnostics.peak); - const row = int32s(golden.diagnostics.row); - const margin = decode(golden.diagnostics.row_margin); - const stateStride = 3 * F + 3 * H; - const every = [...allLayers.flatMap((layer) => Array.from({ length: F }, (_, n) => ["neuron", layer, n])), - ...allLayers.flatMap((layer) => Array.from({ length: H }, (_, h) => ["head", layer, h]))]; - const at = (kind, layer, i) => { - const base = layer * stateStride + (kind === "neuron" ? 0 : 3 * F); - const width = kind === "neuron" ? F : H; - return { value: result.state[base + i], row: result.state[base + width + i], rank: result.state[base + 2 * width + i] }; - }; - every.forEach(([kind, layer, i], u) => { - const device = at(kind, layer, i); - const name = `${kind}/L${layer}${kind === "neuron" ? "n" : "h"}${i}`; - if (row[u] < 0) { - if (device.row !== -1 || device.rank !== -1) throw new Error(`${item.name} ${name}: excluded everywhere, peaked at ${device.row}`); - return; - } - close(`${name} peak`, peak[u], device.value, z, 0); - if (device.rank !== Math.abs(device.value)) throw new Error(`${item.name} ${name}: rank ${device.rank} is not |${device.value}|`); - const forced = golden.name === "excluded-and-zero" && name === "neuron/L1n5"; - if ((forced || margin[u] >= 1e-3 * Math.max(1, Math.abs(peak[u]))) && device.row !== row[u]) { - throw new Error(`${item.name} ${name}: peak row ${device.row}, golden ${row[u]}`); - } - }); - // The host ranking (native `_activity`): per kind, rank desc, flat index asc; rank −1 drops. - const flat = allLayers.flatMap((layer) => [ - ...Array.from({ length: F }, (_, n) => ["neuron", layer, n]), - ...Array.from({ length: H }, (_, h) => ["head", layer, h]), - ]); - const ranked = []; - for (const kind of ["neuron", "head"]) { - const items = flat.map((unit, position) => ({ unit, position, ...at(...unit) })).filter((x) => x.unit[0] === kind); - items.sort((a, b) => b.rank - a.rank || a.position - b.position); - ranked.push(...items.slice(0, golden.arguments.top).filter((x) => x.rank >= 0)); - } - const listed = golden.result.top; - if (ranked.length !== listed.length) throw new Error(`${item.name}: ${ranked.length} ranked, golden ${listed.length}`); - const ties = activityGolden.declared_ties.find((t) => t.path === `cases[${index}].result.top`)?.groups ?? []; - ranked.forEach((entry, position) => { - const [kind, layer, i] = entry.unit; - const name = `${kind}/L${layer}${kind === "neuron" ? "n" : "h"}${i}`; - const group = ties.find((g) => g.includes(position)); - const expected = group ? listed.find((e, j) => group.includes(j) && e.unit === name) : listed[position]; - if (expected === undefined || expected.unit !== name) throw new Error(`${item.name}: top[${position}] ${name}, golden ${listed[position].unit}`); - close(`top ${name}`, expected.peak, entry.value, z, 0); - if (!golden.tied_peak_rows.includes(name) && entry.row !== expected.raw_index) { - throw new Error(`${item.name}: ${name} peaks at ${entry.row}, golden ${expected.raw_index}`); - } - }); - (golden.arguments.units ?? []).forEach((unit, slot) => { - const rows = golden.result.tokens.length; - golden.result.traces[unit].forEach((value, r) => close(`trace ${unit}[${r}]`, value, result.traces[slot * rows + r], z, 0)); - }); - if (golden.arguments.raw_index !== undefined) { - for (const layerEntry of golden.result.population.layers) { - const width = F + H; - const values = result.population.slice(layerEntry.layer * width, (layerEntry.layer + 1) * width); - const expected = [...float16s(layerEntry.neurons), ...float16s(layerEntry.heads)]; - values.forEach((value, k) => { - const rounded = toFloat16(value); - const ulp = float16Spacing(expected[k]); - if (!(Math.abs(rounded - expected[k]) <= ulp)) { - throw new Error(`${item.name}: population L${layerEntry.layer}[${k}] ${value} vs ${expected[k]}`); - } - }); - } - } - } - return worst; -} - -function int32s(value) { - const bytes = Buffer.from(value.data, "base64"); - return Array.from(new Int32Array(bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength))); -} - -function float16s(text) { - const bytes = Buffer.from(text, "base64"); - const halves = new Uint16Array(bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength)); - return Array.from(halves, fromFloat16Bits); -} - -function fromFloat16Bits(bits) { - const sign = bits & 0x8000 ? -1 : 1; - const exponent = (bits >> 10) & 0x1f; - const fraction = bits & 0x3ff; - if (exponent === 0) return sign * fraction * 2 ** -24; - if (exponent === 31) return fraction ? Number.NaN : sign * Infinity; - return sign * (1 + fraction / 1024) * 2 ** (exponent - 15); -} - -function toFloat16(value) { - const halves = new Float16Array(1); - halves[0] = value; - return halves[0]; -} - -function float16Spacing(value) { - const magnitude = Math.abs(value); - if (magnitude < 2 ** -14) return 2 ** -24; - return 2 ** (Math.floor(Math.log2(magnitude)) - 10); -} - -async function loadTensorCache(directory) { - const cache = JSON.parse(await readFile(resolve(directory, "tensor-cache.json"), "utf8")); - const out = new Map(); - for (const shard of cache.records) { - const data = await readFile(resolve(directory, shard.dataPath)); - for (const record of shard.records) { - const bytes = data.subarray(record.byteOffset, record.byteOffset + record.nbytes); - const copy = new Uint8Array(bytes).buffer; - const values = record.dtype === "uint32" ? new Uint32Array(copy) : new Float32Array(copy); - out.set(record.name, { shape: record.shape, values }); - } - } - return out; -} - -function parseArguments(args) { - const result = { headed: false, port: 0, suite: "all", report: false }; - for (let i = 0; i < args.length; i += 1) { - const key = args[i]; - if (key === "--headed") result.headed = true; - else if (key === "--report") result.report = true; - else if (["--webllm", "--fixtures", "--arch", "--quantization", "--port", "--suite"].includes(key)) result[key.slice(2)] = args[++i]; - else throw new Error(`unknown argument ${key}`); - } - for (const key of ["webllm", "fixtures", "arch", "quantization"]) { - if (!result[key]) throw new Error(`--${key} is required`); - } - if (!["all", "units", "replay", "reads"].includes(result.suite)) throw new Error("--suite is all, units, replay or reads"); - result.port = Number(result.port); - return result; -} - -// ------------------------------------------------------------------- the reads suite --- - -/** Plain values crossing into the page: typed arrays travel as `{ __typed, values }`. */ -function toPage(value) { - if (ArrayBuffer.isView(value)) return { __typed: value.constructor.name, values: Array.from(value) }; - if (Array.isArray(value)) return value.map(toPage); - if (value !== null && typeof value === "object") { - return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, toPage(item)])); - } - return value; -} - -function fromPage(value) { - if (value !== null && typeof value === "object" && "__typed" in value) return new globalThis[value.__typed](value.values); - if (Array.isArray(value)) return value.map(fromPage); - if (value !== null && typeof value === "object") { - return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, fromPage(item)])); - } - return value; -} - -// In the page: the adapter's surface over the bridge, kept for the member calls. -async function installReads({ capabilities }) { - const engine = window.engine; - const { webLlmBlockSitesBackend } = await import("/src/hosted/runtime/webLlmBlockSites.ts"); - window.readsBackend = webLlmBlockSitesBackend(capabilities, { - call: (request) => engine.drowseBlockSites(request, "units"), - installProgram: (program) => engine.setDrowseStructuredProgram(program, "units"), - }); -} - -async function callRead({ member, args }) { - const revive = (value) => { - if (value !== null && typeof value === "object" && "__typed" in value) return new globalThis[value.__typed](value.values); - if (Array.isArray(value)) return value.map(revive); - if (value !== null && typeof value === "object") { - return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, revive(item)])); - } - return value; - }; - const pack = (value) => { - if (ArrayBuffer.isView(value)) return { __typed: value.constructor.name, values: Array.from(value) }; - if (Array.isArray(value)) return value.map(pack); - if (value !== null && typeof value === "object") { - return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, pack(item)])); - } - return value; - }; - try { - return { ok: pack(await window.readsBackend[member](...args.map(revive))) }; - } catch (error) { - return { error: String(error?.message ?? error) }; - } -} - -/** The converted tensors as the reads' formulas use them (fp64). */ -function readWeights() { - const name = (suffix) => [...tensors.keys()].find((key) => - [suffix, suffix.replace(".weight", ".q_weight")].some((want) => key === want || key.endsWith(`.${want}`))); - const weight = (suffix) => { - const found = name(suffix + ".weight"); - return dequantized(found.slice(0, found.lastIndexOf("."))); - }; - const vector = (suffix) => tensors.get(name(suffix + ".weight")).values; - const ones = () => new Float64Array(d).fill(1); - const gain = (layer, which) => { - const names = { - ai: "input_layernorm", - ao: gemma ? "post_attention_layernorm" : null, - mi: gemma ? "pre_feedforward_layernorm" : "post_attention_layernorm", - mo: gemma ? "post_feedforward_layernorm" : null, - }; - return names[which] === null ? ones() : vector(`layers.${layer}.${names[which]}`); - }; - const dFF = blockSpec.dFF; - const H = blockSpec.nHeads; - const KV = blockSpec.nKvHeads; - const rows = (w, first, count) => Array.from({ length: count }, (_, r) => w.subarray((first + r) * w.columns, (first + r + 1) * w.columns)); - const qkv = (layer) => { - if (name(`layers.${layer}.self_attn.c_attn.weight`) !== undefined) { - const w = weight(`layers.${layer}.self_attn.c_attn`); - return { q: rows(w, 0, H * hd), k: rows(w, H * hd, KV * hd), v: rows(w, (H + KV) * hd, KV * hd) }; - } - const part = (role, count) => rows(weight(`layers.${layer}.self_attn.${role}_proj`), 0, count); - return { q: part("q", H * hd), k: part("k", KV * hd), v: part("v", KV * hd) }; - }; - return { - /** `[d_ff]` columns `s·γ_mo ⊙ W_down[:, n]`. */ - writes(layer) { - const w = weight(`layers.${layer}.mlp.down_proj`); - const g = gain(layer, "mo"); - return Array.from({ length: dFF }, (_, n) => Float64Array.from({ length: d }, (_, k) => g[k] * w[k * w.columns + n])); - }, - reads(layer) { - const w = weight(`layers.${layer}.mlp.gate_up_proj`); - const g = gain(layer, "mi"); - const unit = (row) => { - const scaled = Float64Array.from(row, (v, k) => v * g[k]); - const norm = Math.max(Math.sqrt(scaled.reduce((s, v) => s + v * v, 0)), 1e-12); - return scaled.map((v) => v / norm); - }; - return [rows(w, 0, dFF).map(unit), rows(w, dFF, dFF).map(unit)]; - }, - /** `[d, hd]` row-major: `γ_ao ⊙ W_O[:, h·hd:(h+1)·hd]`. */ - headWrite(layer, head) { - const w = weight(`layers.${layer}.self_attn.o_proj`); - const g = gain(layer, "ao"); - return Float64Array.from({ length: d * hd }, (_, i) => g[Math.floor(i / hd)] * w[Math.floor(i / hd) * w.columns + head * hd + (i % hd)]); - }, - /** `[3, hd, d]`: `γ_ai ⊙` the query, key and value rows. */ - headReads(layer, head) { - const { q, k, v } = qkv(layer); - const g = gain(layer, "ai"); - const group = Math.floor(head / (H / KV)); - const out = new Float64Array(3 * hd * d); - [q.slice(head * hd, (head + 1) * hd), k.slice(group * hd, (group + 1) * hd), v.slice(group * hd, (group + 1) * hd)] - .forEach((block, role) => block.forEach((row, i) => row.forEach((value, c) => { out[(role * hd + i) * d + c] = g[c] * value; }))); - return out; - }, - gram: (layer, head) => headGram(layer, head), - finalGain: () => vector("norm"), - embedding: () => weight("embed_tokens"), - }; -} diff --git a/webui/scripts/browser-units-reads.mjs b/webui/scripts/browser-units-reads.mjs deleted file mode 100644 index 7f28c9d..0000000 --- a/webui/scripts/browser-units-reads.mjs +++ /dev/null @@ -1,380 +0,0 @@ -// Hook ABI v5's static reads on WebGPU (the `reads` suite of browser-units-goldens.mjs): every -// static-read member of the adapter (webLlmStaticReads.ts over the bridge's `read` requests) on a -// fixture library, against formulas over the converted tensors and against the goldens composed as -// the host composes them (neuron-push, unit-reads, unit-artifacts, slens, lens-reads), the same -// checks `browser-runtime/forks/static_reads.py` runs on the C TVM VM. - -const SEED = 0x5eed0005; -const LENS_ORDINAL = 1000; -const LENS_LAYERS = [["R", "mid", [1, 3]], ["R", "out", [0, 1]], ["S", "mid", [0, 2]], ["S", "out", [0, 1]]]; -const R_STD_FLOOR = 1e-4; -const S_STD_FLOOR = 1e-6; - -const mix = (x) => { - x = (x ^ (x >>> 16)) >>> 0; - x = Math.imul(x, 0x7feb352d) >>> 0; - x = (x ^ (x >>> 15)) >>> 0; - x = Math.imul(x, 0x846ca68b) >>> 0; - return (x ^ (x >>> 16)) >>> 0; -}; - -/** `browser_units.lens_matrix`: `0.75·δ_ij + ((u >> 16) mod 256 − 128)·2⁻¹⁰`. */ -export function fixtureLenses(d) { - const lenses = new Map(); - LENS_LAYERS.forEach(([family, site, layers], i) => { - for (const layer of layers) { - const ordinal = LENS_ORDINAL + 16 * i + layer; - const seed = mix((SEED + Math.imul(0x9e3779b9, ordinal)) >>> 0); - const m = new Float32Array(d * d); - for (let k = 0; k < d * d; k += 1) { - m[k] = (k % (d + 1) === 0 ? 0.75 : 0) + (((mix((k ^ seed) >>> 0) >>> 16) % 256) - 128) * 2 ** -10; - } - lenses.set(`${family}:${site}:${layer}`, { family: family.toLowerCase(), site, layer, matrix: m }); - } - }); - return lenses; -} - -/** Every reads check; `call(member, ...args)` runs an adapter member in the page. */ -export async function verifyReads({ call, f32, i32, u32, weights, golden, decode, L, d, dFF, H, KV, hd, V, sandwich, eps, embedScale }) { - const worst = {}; - const tolerance = (await golden("lens-reads")).tolerance.library; - const check = (label, expected, actual, atol = tolerance.atol, rtol = tolerance.rtol) => { - const e = Array.from(expected); - const a = Array.from(actual); - if (e.length !== a.length) throw new Error(`${label}: ${a.length} values, expected ${e.length}`); - let most = 0; - e.forEach((value, i) => { - const error = Math.abs(a[i] - value); - if (!(error <= atol + rtol * Math.abs(value))) { - throw new Error(`${label}[${i}]: ${a[i]} vs ${value} (|Δ| ${error.toExponential(2)})`); - } - most = Math.max(most, error); - }); - const key = label.split(":")[0]; - worst[key] = Math.max(worst[key] ?? 0, most); - }; - // A golden token list against the device's: the same ids, each id's value within `atol`, - // the device's values non-increasing, and each position holding the golden's id except inside a - // tie (a declared group, or golden values within the tolerance of each other). - const tokens = (label, golden, ids, values, atol, groups = []) => { - const expect = new Map(golden.map((t) => [t.token_id, t.value])); - const got = new Map(Array.from(ids).map((id, i) => [id, values[i]])); - const want = [...expect.keys()].sort((a, b) => a - b).join(","); - if ([...got.keys()].sort((a, b) => a - b).join(",") !== want) { - throw new Error(`${label}: ids ${[...got.keys()]} are not ${want}`); - } - check(label, golden.map((t) => t.value), golden.map((t) => got.get(t.token_id)), atol + 2e-6, 0); - for (let i = 0; i + 1 < values.length; i += 1) { - if (values[i] < values[i + 1]) throw new Error(`${label}: the device's values are not non-increasing at ${i}`); - } - const parent = golden.map((_, i) => i); - const find = (i) => { while (parent[i] !== i) i = parent[i] = parent[parent[i]]; return i; }; - const window = 2 * (atol + 2e-6); - for (let i = 0; i + 1 < golden.length; i += 1) { - if (Math.abs(golden[i].value - golden[i + 1].value) <= window) parent[find(i + 1)] = find(i); - } - for (const group of groups) for (const p of group.slice(1)) parent[find(p)] = find(group[0]); - const blocks = new Map(); - golden.forEach((_, i) => blocks.set(find(i), [...(blocks.get(find(i)) ?? []), i])); - for (const block of blocks.values()) { - const a = block.map((p) => golden[p].token_id).sort((x, y) => x - y).join(","); - const b = block.map((p) => ids[p]).sort((x, y) => x - y).join(","); - if (a !== b) throw new Error(`${label}: positions ${block} hold ${b}, the golden ${a}`); - } - }; - const declared = (doc, path) => - (doc.declared_ties ?? []).filter((tie) => tie.path === path).flatMap((tie) => tie.groups); - - // Residents: the fixture lenses and the S embedding statistics. - const lenses = fixtureLenses(d); - const resident = new Map(); - for (const [key, lens] of lenses) { - resident.set(key, await call("uploadLensLayer", lens.family, lens.site, lens.layer, f32(lens.matrix, [d, d]))); - } - const slens = await golden("slens"); - const meanE = Float32Array.from(decode(slens.mean_E)); - const sigmaE = Float32Array.from(decode(slens.sigma_E)); - const mask = new Uint32Array(Math.ceil(V / 32)); - for (const v of slens.mask.kept) mask[v >> 5] |= 1 << (v & 31); - const stats = await call("uploadEmbeddingStatistics", { meanE: f32(meanE, [d]), sigmaE: f32(sigmaE, [d, d]), mask: u32(mask, [mask.length]) }); - - // ---- formulas over the converted tensors ---- - const rng = (() => { let s = 0x4b4c; return () => ((s = mix(s + 0x9e3779b9)) / 2 ** 32) * 2 - 1; })(); - const random = (n) => Float32Array.from({ length: n }, rng); - const layers = Int32Array.of(L - 1, 0, 2 % L); - const c = layers.length; - const x = random(c * 2 * d); - const writeScores = await call("layerWriteScores", f32(x, [c, 2, d]), layers); - const readScores = await call("layerReadScores", f32(x, [c, 2, d]), layers); - for (let j = 0; j < c; j += 1) { - const w = weights.writes(layers[j]); - const [a, b] = weights.reads(layers[j]); - for (let r = 0; r < 2; r += 1) { - const row = x.subarray((j * 2 + r) * d, (j * 2 + r + 1) * d); - check("formula:layer_write_scores", w.map((col) => dot(col, row)), writeScores.data.subarray((j * 2 + r) * dFF, (j * 2 + r + 1) * dFF)); - check("formula:layer_read_scores", a.map((col) => dot(col, row)), readScores.data.subarray(((j * 2) * 2 + r) * dFF, ((j * 2) * 2 + r + 1) * dFF)); - check("formula:layer_read_scores", b.map((col) => dot(col, row)), readScores.data.subarray(((j * 2 + 1) * 2 + r) * dFF, ((j * 2 + 1) * 2 + r + 1) * dFF)); - } - } - const g = random(c * d); - const act = random(c * dFF); - const mlpO = random(c * d); - const z = random(c * H * hd); - const attnO = random(c * d); - const neurons = await call("neuronContributions", f32(g, [c, d]), f32(act, [c, dFF]), f32(mlpO, [c, d]), layers); - const heads = await call("headContributions", f32(g, [c, d]), f32(z, [c, H * hd]), f32(attnO, [c, d]), layers); - const norms = await call("headWriteNorms", f32(z, [c, H * hd]), f32(attnO, [c, d]), layers); - const rms = (v) => (sandwich ? 1 / Math.sqrt(v.reduce((s, t) => s + t * t, 0) / v.length + eps) : 1); - for (let j = 0; j < c; j += 1) { - const gj = g.subarray(j * d, (j + 1) * d); - const rMo = rms(mlpO.subarray(j * d, (j + 1) * d)); - const rAo = rms(attnO.subarray(j * d, (j + 1) * d)); - const w = weights.writes(layers[j]); - check("formula:neuron_contributions", w.map((col, n) => act[j * dFF + n] * dot(col, gj) * rMo), neurons.data.subarray(j * dFF, (j + 1) * dFF)); - const per = []; - const nrm = []; - for (let h = 0; h < H; h += 1) { - const block = weights.headWrite(layers[j], h); - const zh = z.subarray(j * H * hd + h * hd, j * H * hd + (h + 1) * hd); - const bz = new Float64Array(d); - for (let k = 0; k < d; k += 1) for (let i = 0; i < hd; i += 1) bz[k] += block[k * hd + i] * zh[i]; - per.push(rAo * dot(bz, gj)); - nrm.push(rAo * Math.sqrt(Math.max(0, dot(bz, bz)))); - } - check("formula:head_contributions", per, heads.data.subarray(j * H, (j + 1) * H)); - check("formula:head_write_norms", nrm, norms.data.subarray(j * H, (j + 1) * H)); - } - const headUnits = [{ kind: "head", layer: L - 1, index: H - 1 }, { kind: "head", layer: 0, index: 1 }]; - const headWrite = await call("unitWeightRows", "head_write", headUnits); - const headRead = await call("unitWeightRows", "head_read", headUnits); - const grams = await call("headWriteGrams", headUnits.map((u) => ({ layer: u.layer, head: u.index }))); - headUnits.forEach((u, i) => { - check("formula:head_rows", weights.headWrite(u.layer, u.index), headWrite.data.subarray(i * d * hd, (i + 1) * d * hd)); - check("formula:head_rows", weights.headReads(u.layer, u.index), headRead.data.subarray(i * 3 * hd * d, (i + 1) * 3 * hd * d)); - check("formula:head_write_grams", weights.gram(u.layer, u.index), grams.data.subarray(i * hd * hd, (i + 1) * hd * hd)); - }); - const ids = Int32Array.of(0, 3, 71, V - 1); - const hFinal = random(ids.length * d); - const cotangent = await call("unembedCotangent", f32(hFinal, [ids.length, d]), ids); - const gammaF = weights.finalGain(); - const E = weights.embedding(); - ids.forEach((v, i) => { - const h = hFinal.subarray(i * d, (i + 1) * d); - const r = 1 / Math.sqrt(h.reduce((s, t) => s + t * t, 0) / d + eps); - check("formula:unembed_cotangent", Array.from({ length: d }, (_, k) => r * gammaF[k] * E[v * d + k]), cotangent.data.subarray(i * d, (i + 1) * d)); - }); - const rows = random(2 * d); - const logits = rows.length && (await call("vocabTokenLogits", f32(rows, [2, d]), i32(Int32Array.from({ length: 2 * V }, (_, i) => i % V), [2, V]))); - for (let r = 0; r < 2; r += 1) { - const row = rows.subarray(r * d, (r + 1) * d); - const scale = 1 / Math.sqrt(row.reduce((s, t) => s + t * t, 0) / d + eps); - const expect = Array.from({ length: V }, (_, v) => { - let acc = 0; - for (let k = 0; k < d; k += 1) acc += row[k] * scale * gammaF[k] * E[v * d + k]; - return acc; - }); - check("formula:vocab_logits", expect, logits.logits.data.subarray(r * V, (r + 1) * V)); - } - const moments = await call("vocabLogitMoments", f32(rows, [2, d]), stats); - for (let r = 0; r < 2; r += 1) { - const kept = slens.mask.kept.map((v) => logits.logits.data[r * V + v]); - const mean = kept.reduce((s, t) => s + t, 0) / kept.length; - const m = (p) => kept.reduce((s, t) => s + (t - mean) ** p, 0) / kept.length; - const variance = Math.max(m(2), 1e-30); - check("formula:logit_moments", [m(3) / variance ** 1.5, m(4) / variance ** 2], moments.data.subarray(2 * r, 2 * r + 2), 1e-4, 1e-3); - } - const big = Float32Array.from({ length: 2 * 700 }, () => Math.round(rng() * 64) / 8); - for (const k of [1, 7, 300]) { - const top = await call("topK", f32(big, [2, 700]), k); - for (let r = 0; r < 2; r += 1) { - const order = [...Array(700).keys()].sort((p, q) => big[r * 700 + q] - big[r * 700 + p] || p - q).slice(0, k); - if (order.join(",") !== Array.from(top.indices.data.subarray(r * k, (r + 1) * k)).join(",")) { - throw new Error(`formula:topk k=${k}: indices differ from value desc, index asc`); - } - } - } - - // ---- goldens ---- - const push = await golden("neuron-push"); - for (const [layer, vector] of Object.entries(push.profile)) { - const index = Number(/neuron\/L\d+n(\d+)/.exec(JSON.stringify(push.cases))[1]); - const row = await call("unitWeightRows", "neuron_write", [{ kind: "neuron", layer: Number(layer), index }]); - check("neuron-push:profile", decode(vector), row.data); - } - const unitReads = await golden("unit-reads"); - for (const entry of unitReads.reads) { - const read = entry.read; - if (read.kind !== "neuron") continue; - const ref = [{ kind: "neuron", layer: read.layer, index: read.index }]; - const w = (await call("unitWeightRows", "neuron_write", ref)).data; - const ab = (await call("unitWeightRows", "neuron_read", ref)).data; - check("unit-reads:w_norm", [read.scalars.w_norm], [Math.sqrt(dot(w, w))], 2e-6 + tolerance.atol); - check("unit-reads:cos_ab", [read.scalars.cos_ab], [dot(ab.subarray(0, d), ab.subarray(d))], 2e-6 + tolerance.atol); - } - - const rMatrix = (layer, site) => resident.get(`R:${site}:${layer}`) ?? (site === "out" && layer === L - 1 ? null : undefined); - const transportR = async (data, n, lens) => (lens === null ? data : (await call("lensTransport", f32(data, [1, n, d]), [lens], true)).data); - const pullS = async (data, n, lens) => (await call("lensTransport", f32(data, [1, n, d]), [lens], false)).data; - const allIds = (n) => i32(Int32Array.from({ length: n * V }, (_, i) => i % V), [n, V]); - const chan = async (data, n, width) => { - const merged = await call("chanMerge", { count: 0, mean: f32(new Float32Array(width), [width]), m2: f32(new Float32Array(width), [width]) }, f32(data, [n, width])); - return { mean: merged.mean.data, std: merged.m2.data.map((v) => Math.sqrt(Math.max(v / n, 0))) }; - }; - const embedded = (await call("vocabRowsTimes", { - kind: "embed", ids: Int32Array.from({ length: V }, (_, i) => i), - factor: f32(Float32Array.from({ length: d * d }, (_, i) => (i % (d + 1) === 0 ? 1 : 0)), [d, d]), statistics: stats, - })).data; - const artifacts = await golden("unit-artifacts"); - for (const { layer, tensors } of artifacts.layers) { - const units = Array.from({ length: dFF }, (_, n) => ({ kind: "neuron", layer, index: n })); - const writes = (await call("unitWeightRows", "neuron_write", units)).data; - const ab = (await call("unitWeightRows", "neuron_read", units)).data; - const pole = (sign) => Float32Array.from({ length: dFF * d }, (_, i) => { - const n = Math.floor(i / d); - const k = i % d; - return ab[(2 * n) * d + k] + sign * ab[(2 * n + 1) * d + k]; - }); - const populations = { writes: [writes, "out"], "fires+": [pole(1), "mid"], "fires-": [pole(-1), "mid"] }; - const pooled = []; - for (const [name, [rowsData, site]] of Object.entries(populations)) { - const key = `R.${name}`; - if (tensors[`${key}.rho`] !== undefined) { - const xR = await transportR(rowsData, dFF, rMatrix(layer, site)); - const full = (await call("vocabTokenLogits", f32(xR, [dFF, d]), allIds(dFF))).logits.data; - const lse = (await call("logSumExp", f32(full, [dFF, V]))).data; - const rho = Array.from({ length: dFF }, (_, n) => 1 / Math.sqrt(xR.subarray(n * d, (n + 1) * d).reduce((s, t) => s + t * t, 0) / d + eps)); - check(`unit-artifacts:${key}.rho`, decode(tensors[`${key}.rho`]), rho); - check(`unit-artifacts:${key}.lse`, decode(tensors[`${key}.lse`]), lse); - if (tensors[`${key}.lse_neg`] !== undefined) { - check(`unit-artifacts:${key}.lse_neg`, decode(tensors[`${key}.lse_neg`]), (await call("logSumExp", f32(full.map((v) => -v), [dFF, V]))).data); - } - const { mean, std } = await chan(full, dFF, V); - check(`unit-artifacts:${key}.mean`, decode(tensors[`${key}.mean`]), mean); - check(`unit-artifacts:${key}.std`, decode(tensors[`${key}.std`]), std.map((v) => Math.max(v, R_STD_FLOOR))); - } - const sKey = `S.${name}`; - if (tensors[`${sKey}.norm`] === undefined) continue; - const u = await pullS(rowsData, dFF, resident.get(`S:${site}:${layer}`)); - const norm = (await call("groupedRowNorms", f32(u, [dFF, d]), d)).data; - check(`unit-artifacts:${sKey}.norm`, decode(tensors[`${sKey}.norm`]), norm); - const q = (await call("batchedQuadraticForm", f32(u, [dFF, d]), stats)).data; - check(`unit-artifacts:${sKey}.footprint_std`, decode(tensors[`${sKey}.footprint_std`]), q.map((v) => Math.sqrt(Math.max(v, 1e-30)))); - const unitU = Float32Array.from(u, (v, i) => v / Math.max(norm[Math.floor(i / d)], 1e-12)); - const raw = (await call("batchedMatmul", f32(unitU, [1, dFF, d]), f32(transpose(embedded, V, d), [1, d, V]))).data; - if (name === "writes") { - const { mean, std } = await chan(raw, dFF, V); - check(`unit-artifacts:${sKey}.mean`, decode(tensors[`${sKey}.mean`]), mean); - check(`unit-artifacts:${sKey}.std`, decode(tensors[`${sKey}.std`]), std.map((v) => Math.max(v, S_STD_FLOOR))); - } else { - pooled.push(raw); - } - } - if (pooled.length > 0) { - const both = new Float32Array(2 * dFF * V); - both.set(pooled[0]); - both.set(pooled[1], dFF * V); - const { mean, std } = await chan(both, 2 * dFF, V); - check("unit-artifacts:S.fires.mean", decode(tensors["S.fires.mean"]), mean); - check("unit-artifacts:S.fires.std", decode(tensors["S.fires.std"]), std.map((v) => Math.max(v, S_STD_FLOOR))); - } - } - - const words = new Map(slens.probe_words.map((word, i) => [word, slens.probe_word_ids[i]])); - for (const atom of slens.atoms) { - const name = atom.atom.split("/")[1]; - const token = name.startsWith("#") ? Number(name.slice(1)) : words.get(name); - const layersOf = Object.keys(atom.layers).map(Number); - const out = await call("footprintDirections", layersOf.map((l) => resident.get(`S:out:${l}`)), Int32Array.of(token), stats); - layersOf.forEach((l, i) => check("slens:atom", decode(atom.layers[String(l)]), out.data.subarray(i * d, (i + 1) * d))); - } - for (const [f, footprint] of slens.footprints.entries()) { - const u = Float32Array.from(decode(footprint.u)); - const n = u.length / d; - const out = await call("footprintTopK", f32(u, [n, d]), footprint.k, stats); - footprint.top.forEach((top, r) => tokens("slens:footprint", top.map((t) => ({ token_id: t.token_id, value: t.z })), - out.ids.data.subarray(r * footprint.k, (r + 1) * footprint.k), out.z.data.subarray(r * footprint.k, (r + 1) * footprint.k), tolerance.z_atol, - declared(slens, `footprints[${f}].top[${r}]`))); - } - - const stats3 = await golden("unit-stats"); - const means = { out: decode(stats3.out_mean), mid: decode(stats3.mid_mean) }; - // lens.read's two halves of `n` rows at (layer, site): R probabilities and S z, or null where - // the fixture has no lens there. - const place = async (rowsData, n, layer, site, k, of) => { - const rLens = rMatrix(layer, site); - let r = null; - if (rLens !== undefined) { - const out = await call("vocabReadoutTopK", f32(await transportR(rowsData, n, rLens), [n, d]), k); - r = { ids: out.ids.data, p: out.logits.data.map((v, i) => Math.exp(v - out.logSumExp.data[Math.floor(i / k)])) }; - } - let s = null; - const sLens = resident.get(`S:${site}:${layer}`); - if (sLens !== undefined) { - const centred = of === "residual" - ? rowsData.map((v, i) => v - means[site][layer * d + (i % d)]) - : rowsData; - const out = await call("footprintTopK", f32(await pullS(centred, n, sLens), [n, d]), k, stats); - s = { ids: out.ids.data, p: out.z.data }; - } - return { r, s, k }; - }; - // One row's present raw halves against a place read (hub-hidden layer_z halves are B5's). - const checkPlace = (label, want, got, row, doc, path, where) => { - for (const [half, atol] of [["r", tolerance.probability_atol], ["s", tolerance.z_atol]]) { - const golden = want[half]; - if (golden === null || golden === undefined || golden.absent !== null || golden.unit === "layer_z") continue; - if (got[half] === null) throw new Error(`${label}: a present ${half} half at ${where} has no fixture lens`); - const m = golden.tokens.length; - const at = row * got.k; - tokens(`${label}:${half}`, golden.tokens, got[half].ids.subarray(at, at + m), got[half].p.subarray(at, at + m), atol, - declared(doc, `${path}.${half}.tokens`)); - } - }; - - const lensReads = await golden("lens-reads"); - for (const [q, request] of lensReads.requests.entries()) { - if (request.lens !== undefined && request.lens !== null) continue; - const rowsData = Float32Array.from(decode(request.rows)); - const got = await place(rowsData, rowsData.length / d, request.layer, request.site, request.k, request.of); - request.reads.forEach((read, i) => checkPlace("lens-reads", read, got, i, lensReads, `requests[${q}].reads[${i}]`, `L${request.layer} ${request.site}`)); - } - - // unit-reads poles: a neuron's writes (w, −w at its out) and firing directions (â ± b̂ at its - // mid) through lens.read, and each pole's logit-lens skew and kurtosis over the kept tokens. - for (const [c, entry] of unitReads.reads.entries()) { - const read = entry.read; - if (read.kind !== "neuron") continue; - const ref = [{ kind: "neuron", layer: read.layer, index: read.index }]; - const w = (await call("unitWeightRows", "neuron_write", ref)).data; - const ab = (await call("unitWeightRows", "neuron_read", ref)).data; - const [a, b] = [ab.subarray(0, d), ab.subarray(d, 2 * d)]; - const moments = (await call("vocabLogitMoments", f32(w, [1, d]), stats)).data; - const places = { - writes: await place(Float32Array.from([...w, ...w.map((v) => -v)]), 2, read.layer, "out", entry.k, "direction"), - fires_on: await place(Float32Array.from([...a.map((v, i) => v + b[i]), ...a.map((v, i) => v - b[i])]), 2, read.layer, "mid", entry.k, "direction"), - }; - read.poles.forEach((pole, p) => { - const sign = pole.pole === "+" ? 1 : -1; - check("unit-reads:vocab_moments", [pole.vocab_skew, pole.vocab_kurt], [sign * moments[0], moments[1]], 2e-6 + tolerance.atol); - for (const where of ["writes", "fires_on"]) { - checkPlace(`unit-reads:${where}`, pole[where], places[where], p, unitReads, `reads[${c}].read.poles[${p}].${where}`, `L${read.layer} ${pole[where].site}`); - } - }); - } - for (const handle of resident.values()) await call("release", handle); - await call("release", stats); - return worst; -} - -function dot(a, b) { - let s = 0; - for (let i = 0; i < a.length; i += 1) s += a[i] * b[i]; - return s; -} - -function transpose(data, rows, cols) { - const out = new Float32Array(rows * cols); - for (let r = 0; r < rows; r += 1) for (let c = 0; c < cols; c += 1) out[c * rows + r] = data[r * cols + c]; - return out; -} diff --git a/webui/scripts/browser-units-worker.mjs b/webui/scripts/browser-units-worker.mjs deleted file mode 100644 index 0303631..0000000 --- a/webui/scripts/browser-units-worker.mjs +++ /dev/null @@ -1,865 +0,0 @@ -#!/usr/bin/env node -// Half B end to end through the hosted runtime worker on WebGPU: B4's tiny v5 fixture library -// with its R, S, units and core packs, installed, loaded and driven as the app drives the worker -// (check, catalog, download, download_pack, load, probes, live state, generate, the units members). -// -// node scripts/browser-units-worker.mjs --fixtures DIR --arch qwen3|gemma3 \ -// --quantization q0f32|q4f32_1 --work DIR [--chat | --goldens] [--port N] [--headed] [--python python3] -// -// DIR is what browser-core-build.mjs takes (support/units-webgpu-stage.mjs). The harness: -// 1. stages the library as a hosted base model and has drowse build its packs bound to that -// runtime identity, with native references on the same model at the hosted lens band -// (support/units-worker-reference.py); -// 2. fits the core concepts and the neutral whitener from drowse's neutral rows through the release -// worker (hosted-whitener.worker.ts), as build-hosted-whitener.mjs does, and assembles the core -// pack; -// 3. runs the hosted runtime worker (units-worker.worker.ts) on that catalog and compares with -// drowse: the unit-probes golden (greedy raw generations with two unit probes attached and the -// units family live: unsteered, a neuron and a head ablated, a head ablation gated on a unit no -// probe attaches: tokens, every forward's units channel, the aggregate); a neuron push, a unit -// ablation at @response and an S-lens-gated push with an `slens/` probe attached (tokens and the -// aggregate's units and lens channels); generated nodes' token anatomy and unit activity -// (unsteered, steered, S-lens-gated with slens/ attached, whose replay steps its gate, and -// S-lens-gated with nothing attached, whose gate never fires; J-lens- and geometry-gated with -// their probes attached: drowse loads this run's browser-fitted manifold, and each gate's -// threshold is set from drowse's own per-step gate readings so it opens at the anatomy's -// forward and shuts elsewhere); and unitRead, unitTop and unitFind. Tolerances are each golden's. -// -// `--chat` stages the library as the instruct model drowse's fixture chat template makes -// (support/units-webgpu-stage.mjs `chatConversation`) and replaces the raw cases with chat nodes, -// generated through the hosted loom and replayed through renderPromptTokenIds: the goldens' -// prompt (system and user) unsteered and steered, the user turn alone, a second assistant turn and -// a user-seat turn under the first (unsteered and steered); each node's tokens, token anatomy and -// unit activity against drowse's on the same model and template (the reference's `chat` mode). -// -// `--goldens` (chat staging) reads at the goldens' lens band (0.2/0.8, the worker's `lensBand`, as -// drowse's fixture sets `session.lens.band`) and compares with five golden files directly: the -// goldens' chat node (system and user, six distinct greedy tokens: presence penalty 1e4) unsteered, -// steered and segmented (`!neuron/L1n5@prompt`) and the raw first turn, generated through the -// hosted loom; token-anatomy's local:r cases, unit-activity's generated, sink, sink-population and -// segmented cases, every unit-reads read, top and find, and unit-ablation's cases as raw -// generations of the short prompt (each forward's greedy token against the golden logits' argmax, -// and each forward's top eight log-probabilities against their log-softmax, read from a -// temperature-1 run that follows the greedy path: a token row's logprob is the sampler's, native's -// too, one-hot at temperature 0). -// Not reachable through the worker: token-anatomy no-r-mid (a second R source), unit-activity -// authored (the browser measures no prompts) and its hand-built forwards, neuron-push's lowering -// and unit-ablation mixed (the fixture session's registered direction). -import { execFile } from "node:child_process"; -import { createServer as createHttpServer } from "node:http"; -import { mkdir, readFile, rm, writeFile } from "node:fs/promises"; -import { resolve } from "node:path"; -import { fileURLToPath } from "node:url"; -import { promisify } from "node:util"; -import { chromium } from "playwright"; -import { createServer as createViteServer } from "vite"; -import { collectPackArtifacts } from "./assemble-hosted-pack.mjs"; -import { neutralWhitenerSidecar } from "./neutral-whitener-node.mjs"; -import { releaseToolBrowserOptions, releaseToolGpuArgs } from "./release-tool-storage-quota.mjs"; -import { compareRecord, decode } from "./support/units-goldens.mjs"; -import { fixtureConcepts, goldensDirectory, sha256, stageUnitsFixture } from "./support/units-webgpu-stage.mjs"; - -const exec = promisify(execFile); -const options = parseArguments(process.argv.slice(2)); -const webui = fileURLToPath(new URL("..", import.meta.url)); -const repository = resolve(webui, ".."); -const stage = await stageUnitsFixture({ ...options, chat: options.chat || options.goldens }); -if (options.goldens) options.chat = true; -const modelType = options.chat ? "chat" : "base"; -const { artifacts: modelFiles, blockSpec, contextTokens, prefillChunkSize, runtimeIdentity, modelDirectory } = stage; -const modelId = `units-${options.arch}${options.chat ? "-chat" : ""}`; -const variantId = `${modelId}-${options.quantization}`; -const revision = "a".repeat(40); -const goldenFile = async (name) => JSON.parse(await readFile(resolve(goldensDirectory, `${name}-${options.arch}-v1.json`), "utf8")); - -/** The unit-activity golden cases the worker reaches (generated nodes and the raw first turn). */ -const GOLDEN_ACTIVITY = ["generated", "sink", "sink-population", "segmented"]; - -const PREVIEW_DEFINES = { - __DROWSE_HOSTED_RELEASE__: false, - __DROWSE_SOURCE_REVISION__: "0".repeat(40), - __DROWSE_SOURCE_URL__: "https://github.com/stdlogits/drowse.ai", - __DROWSE_VERSION__: "6.0.0", - __DROWSE_ARTIFACT_SOURCE_REVISION__: "0".repeat(40), - __DROWSE_RUNTIME_ABI__: "drowse-web-runtime-v2", - __DROWSE_HOOK_ABI__: "block-sites-v5", - __DROWSE_HOSTED_CHANNEL__: "preview", - __DROWSE_FITTING_WASM__: { module: "/fitting.js", wasm: "/fitting.wasm" }, -}; -const vite = await createViteServer({ - root: webui, configFile: false, appType: "custom", logLevel: "silent", - publicDir: resolve(webui, "public-hosted"), - server: { middlewareMode: true, hmr: false, watch: null }, -}); -const catalogModule = await vite.ssrLoadModule("/src/lib/runtime/catalog.ts"); -const fingerprint = catalogModule.runtimeIdentitySha256(runtimeIdentity); -const binding = catalogModule.contextBindingSha256(fingerprint, contextTokens); - -// ------------------------------------------------- 1. drowse's packs and references --- -const nativeDirectory = resolve(options.work, `${stage.fixture}${options.chat ? "-chat" : ""}-native`); -await rm(nativeDirectory, { recursive: true, force: true }); -await mkdir(nativeDirectory, { recursive: true }); -await writeFile(resolve(nativeDirectory, "runtime.json"), JSON.stringify({ - modelId, runtimeIdentity, runtimeIdentitySha256: fingerprint, -})); -console.log(`drowse: packs and references for ${stage.fixture} (${fingerprint.slice(0, 12)})`); -await exec(options.python, [ - resolve(webui, "scripts/support/units-worker-reference.py"), options.arch, nativeDirectory, - resolve(nativeDirectory, "runtime.json"), ...(options.chat ? ["chat"] : []), -], { - maxBuffer: 1 << 26, - env: { ...process.env, PYTHONUNBUFFERED: "1", PYTHONPATH: resolve(repository, "drowse") }, -}); -const reference = JSON.parse(await readFile(resolve(nativeDirectory, "reference.json"), "utf8")); -const packsDirectory = resolve(nativeDirectory, "packs"); -const coreStatistics = JSON.parse(await readFile(resolve(packsDirectory, "core/neutral-statistics.json"), "utf8")); -const neutralRows = await readFile(resolve(packsDirectory, "core", coreStatistics.neutral_rows?.file ?? "neutral-rows.safetensors")); - -// ---------------------------------------------------------------------- the server --- -const served = new Map(); // fixture path → absolute file -const outputs = { whitener: new Map(), manifolds: new Map() }; -let harnessConfig = null; -const http = createHttpServer(async (request, response) => { - for (const [name, value] of Object.entries({ - "Cross-Origin-Opener-Policy": "same-origin", - "Cross-Origin-Embedder-Policy": "require-corp", - "Cross-Origin-Resource-Policy": "same-origin", - })) response.setHeader(name, value); - const send = (body, type, status = 200) => { - response.writeHead(status, { "content-type": type }); - response.end(body); - }; - try { - const url = new URL(request.url ?? "/", "http://127.0.0.1"); - if (url.pathname === "/") return send("units worker", "text/html"); - if (url.pathname === "/units-worker.js") { - // What vite.hosted.config.ts injects into a preview build, set before the worker's modules - // evaluate (the dev server has no build step to replace them). - return send(`Object.assign(globalThis, ${JSON.stringify(PREVIEW_DEFINES)});\nawait import("/units-worker-main.js");\n`, "text/javascript"); - } - for (const [path, source] of [["/whitener-worker.js", "/scripts/hosted-whitener.worker.ts"], ["/units-worker-main.js", "/scripts/units-worker.worker.ts"]]) { - if (url.pathname === path) return send((await vite.transformRequest(source)).code, "text/javascript"); - } - if (url.pathname === "/webllm.js") { - return send(await readFile(resolve(repository, "node_modules/@drowse/web-llm/lib/index.js")), "text/javascript"); - } - if (url.pathname === "/fitting.js") { - return send(await readFile(resolve(webui, "public-hosted/wasm/drowse_fitting_wasm.js")), "text/javascript"); - } - if (url.pathname === "/fitting.wasm") { - return send(await readFile(resolve(webui, "public-hosted/wasm/drowse_fitting_wasm_bg.wasm")), "application/wasm"); - } - if (url.pathname === "/model") { - const path = url.searchParams.get("path"); - if (!(path in stage.roles)) return send("not found", "text/plain", 404); - return send(await readFile(resolve(modelDirectory, path)), "application/octet-stream"); - } - if (url.pathname === "/neutral-rows") return send(neutralRows, "application/octet-stream"); - if (url.pathname === "/harness/config.json" && harnessConfig !== null) { - return send(JSON.stringify(harnessConfig), "application/json"); - } - if (url.pathname.startsWith("/fixture/")) { - const file = served.get(decodeURIComponent(url.pathname.slice("/fixture/".length))); - if (file === undefined) return send("not found", "text/plain", 404); - return send(await readFile(file), "application/octet-stream"); - } - if (request.method === "POST" && (url.pathname === "/output" || url.pathname === "/manifold-output")) { - const chunks = []; - for await (const chunk of request) chunks.push(chunk); - const key = url.pathname === "/output" - ? url.searchParams.get("context") - : `${url.searchParams.get("context")}:${url.searchParams.get("manifold")}`; - outputs[url.pathname === "/output" ? "whitener" : "manifolds"].set(key, Buffer.concat(chunks)); - return send("ok", "text/plain"); - } - vite.middlewares(request, response, () => send("not found", "text/plain", 404)); - } catch (error) { - console.error(error); - send(error instanceof Error ? error.message : "request failed", "text/plain", 500); - } -}); -await new Promise((ok) => http.listen(options.port, "127.0.0.1", ok)); -const origin = `http://127.0.0.1:${http.address().port}`; -const browser = await chromium.launch(releaseToolBrowserOptions({ - headless: !options.headed, args: releaseToolGpuArgs({ headless: !options.headed }), -})); -let failures = 0; -const worst = new Map(); -const check = (label, ok, detail = "") => { - if (!ok) failures += 1; - console.log(`${ok ? "ok" : "FAIL"} - ${label}${detail ? `: ${detail}` : ""}`); -}; -try { - const page = await browser.newPage(); - page.setDefaultTimeout(900_000); - page.on("console", (message) => { - if ((message.type() === "error" || message.type() === "warning") && !/vite|Vite server/.test(message.text())) { - process.stderr.write(`browser console: ${message.text()}\n`); - } - }); - await page.goto(origin); - - // ------------------------- 2. the core pack: concepts and whitener on drowse's rows --- - const manifolds = fixtureConcepts(); - const core = await page.evaluate(async (payload) => { - const instance = new Worker("/whitener-worker.js", { type: "module" }); - return await new Promise((done) => { - instance.onerror = (event) => done({ type: "error", message: event.message ?? "worker error" }); - instance.onmessage = (event) => { - if (event.data.type === "progress" || event.data.type === "manifold-progress") return; - instance.terminate(); - done(event.data); - }; - instance.postMessage(payload); - }); - }, { - type: "run", modelId, modelType, artifacts: modelFiles, - baselinePrompts: ["Hi.", "Go on.", "Say it."], contexts: [contextTokens], rows: [], - nativeNeutralRows: true, runtimeIdentity, quantization: options.quantization, requiredFeatures: [], - structuredHookProfile: "standard-v4", thinkingProfile: null, blockSpec, unitRefusal: null, - prefillChunkSize, - artifactProducer: { drowseVersion: "0.0.0-fixture", producerVersion: "browser-units-worker" }, - manifolds, - }); - check("core concepts and whitener through the release worker", core.type === "done", core.message ?? ""); - if (core.type !== "done") throw new Error("the core build failed"); - const [coreContext] = core.result.contexts; - const coreDirectory = resolve(options.work, `${stage.fixture}${options.chat ? "-chat" : ""}-core`); - await rm(coreDirectory, { recursive: true, force: true }); - await mkdir(resolve(coreDirectory, String(contextTokens)), { recursive: true }); - await mkdir(resolve(coreDirectory, "manifolds", String(contextTokens)), { recursive: true }); - const whitenerBytes = outputs.whitener.get(String(contextTokens)); - const sidecarBytes = neutralWhitenerSidecar({ - runtimeIdentitySha256: fingerprint, contextBindingSha256: binding, - modelLock: { layerMap: runtimeIdentity.layerMap, hiddenSize: runtimeIdentity.hiddenSize }, - tensorsSha256: coreContext.tensorsSha256, ridgePerLayer: coreContext.ridgePerLayer, - }); - await writeFile(resolve(coreDirectory, String(contextTokens), "neutral-whitener.safetensors"), whitenerBytes); - await writeFile(resolve(coreDirectory, String(contextTokens), "neutral-whitener.json"), sidecarBytes); - for (const [index, manifold] of manifolds.entries()) { - await writeFile(resolve(coreDirectory, "manifolds", String(contextTokens), `${manifold.namespace}-${manifold.name}.drowse`), - outputs.manifolds.get(`${contextTokens}:${index}`)); - } - await writeFile(resolve(coreDirectory, "neutral-statistics.json"), JSON.stringify({ - ...coreStatistics, - whitener: { - rows_sha256: coreStatistics.neutral.rows_sha256, - tensors_sha256: { [contextTokens]: coreContext.tensorsSha256 }, - sidecars_sha256: { [contextTokens]: sha256(sidecarBytes) }, - }, - })); - await writeFile(resolve(coreDirectory, coreStatistics.tensor_file), - await readFile(resolve(packsDirectory, "core", coreStatistics.tensor_file))); - - // Gated replays: drowse gates on the very manifold this core build fitted (its own loader on - // the archive's fitted pair) and on the R pack's lens; its nodes join the reference's. - if (!options.chat) { - console.log("drowse: gated references on the browser's fitted manifold"); - await exec(options.python, [ - resolve(webui, "scripts/support/units-worker-reference.py"), options.arch, nativeDirectory, - resolve(nativeDirectory, "runtime.json"), "gated", - resolve(coreDirectory, "manifolds", String(contextTokens), "local-calm.alert.drowse"), - ], { maxBuffer: 1 << 26, env: { ...process.env, PYTHONUNBUFFERED: "1", PYTHONPATH: resolve(repository, "drowse") } }); - const gated = JSON.parse(await readFile(resolve(nativeDirectory, "gated-reference.json"), "utf8")); - Object.assign(reference.nodes, gated.nodes); - reference.declared_ties.push(...gated.declared_ties); - } - - // ------------------------------------------------------------- the catalog and lock --- - const catalogFile = (prefix, file, role) => { - // Hugging Face's layout, which WebLLM keys a model directory on. - const path = `${prefix}/resolve/${revision}/${file.path}`; - served.set(path, file.absolute); - return { path: file.path, role, url: `https://fixture.invalid/${path}`, revision, bytes: file.bytes, sha256: file.sha256 }; - }; - const listed = async (directory) => (await collectPackArtifacts(directory)).files - .map((file) => ({ ...file, absolute: resolve(directory, file.path) })); - const pack = async (kind, directory, role, required) => { - const files = (await listed(directory)).map((file) => catalogFile(kind, file, role)); - return { - id: `${modelId}-${kind}`, kind, displayName: `${modelId} ${kind}`, license: "AGPL-3.0-or-later", - sourceRepository: "drowse/units-tiny", sourceRevision: revision, - bytes: files.reduce((sum, file) => sum + file.bytes, 0), required, runtimeIdentitySha256: fingerprint, - compatibleContextBindingSha256: [binding], files, - }; - }; - const packs = [ - await pack("core", coreDirectory, "core_pack", true), - ...await Promise.all(["jlens", "slens", "units"].map((kind) => pack(kind, resolve(packsDirectory, kind), "instrument", false))), - ]; - const files = modelFiles.map((file) => catalogFile("model", { ...file, absolute: resolve(modelDirectory, file.path) }, file.role)); - const limits = { - maxBufferSize: 1 << 30, maxStorageBufferBindingSize: 1 << 30, maxStorageBuffersPerShaderStage: 10, - maxComputeWorkgroupStorageSize: 32_768, maxComputeWorkgroupSizeX: 256, maxComputeInvocationsPerWorkgroup: 256, - }; - const variant = { - id: variantId, tier: "fastest", structuredHookProfile: "standard-v4", thinkingProfile: null, - contextProfiles: [{ - contextTokens, bindingSha256: binding, minimumCalibrationScore: null, minimumDeviceMemoryGiB: null, - expectedPrefillTokensPerSecond: [1, 2], expectedDecodeTokensPerSecond: [1, 2], measuredDevices: 1, - }], - downloadBytes: files.reduce((sum, file) => sum + file.bytes, 0), - requiredCorePackBytes: packs[0].bytes, - requirements: { features: [], limits: { maxStorageBuffersPerShaderStage: 8, maxComputeWorkgroupSizeX: 256, maxComputeInvocationsPerWorkgroup: 256 } }, - runtimeIdentity, runtimeIdentitySha256: fingerprint, files, packs, - }; - harnessConfig = { - document: { - schemaVersion: 1, sequence: 1, issuedAt: "2026-01-01T00:00:00.000Z", expiresAt: "2099-01-01T00:00:00.000Z", - runtimeAbi: runtimeIdentity.runtimeAbi, - models: [{ - id: modelId, modelType, displayName: `Units tiny ${options.arch}`, description: "B4's tiny v5 fixture", - sourceUrl: "https://huggingface.co/drowse/units-tiny", license: "AGPL-3.0-or-later", languages: ["en"], - variants: [variant], - }], - }, - capabilities: { - checkedAt: 0, supported: true, secureContext: true, crossOriginIsolated: true, dedicatedWorker: true, - indexedDb: true, opfs: true, webLocks: true, broadcastChannel: true, webAssembly: true, - webGpu: { available: true, fallback: "hardware", features: [], limits, adapterInfo: { vendor: "harness" } }, - storage: { quotaBytes: 8e9, usageBytes: 0, availableBytes: 8e9, persisted: true }, - signals: { deviceMemoryGiB: 16, logicalCpuCount: 8, mobile: false, language: "en-US", calibrationScore: 100 }, - deviceSignature: "units-worker-harness", runtimeVersion: runtimeIdentity.runtimeAbi, issues: [], - operations: Object.fromEntries([ - "download", "generation", "fitting", "manifold_artifacts", "probe_subspace_trails", "jlens_fitting", - "sae_training", "session_admin", "server_endpoints", - ].map((name) => [name, { available: true, reasons: [] }])), - limits: { manifoldFitMaxIntrinsicDim: 4 }, - }, - runtimeLockModels: [{ - modelType, runtimeIdentity, structuredHookProfile: "standard-v4", thinkingProfile: null, - convertedRepository: "drowse/units-tiny", convertedRevision: revision, contextProfiles: [contextTokens], - prefillChunkSize, blockSpec, unitRefusal: null, - }], - }; - - if (options.goldens) { - const band = JSON.parse(await readFile(resolve(goldensDirectory, "units-tiny-models-v1.json"), "utf8")).band; - harnessConfig.lensBand = { lo: band[0], hi: band[1] }; - } - - // ------------------------------------------------- 3. the hosted runtime worker --- - const unitProbes = await goldenFile("unit-probes"); - const goldens = options.goldens ? { - anatomy: await goldenFile("token-anatomy"), activity: await goldenFile("unit-activity"), - reads: await goldenFile("unit-reads"), ablation: await goldenFile("unit-ablation"), - } : null; - const plan = { - chat: options.chat, variantId, contextTokens, packIds: packs.slice(1).map((entry) => entry.id), - text: reference.text, probes: reference.settings.probes, unitProbes: unitProbes.probes, - probeCases: unitProbes.cases.map((entry) => ({ name: entry.name, steering: entry.steering })), - generations: Object.entries(reference.generations).map(([name, entry]) => ({ name, steering: entry.steering })), - goldens: goldens === null ? null : { - ...reference.golden_inputs, - anatomyIndex: goldens.anatomy.raw_index, - anatomy: goldens.anatomy.cases.filter((entry) => entry.lens === "local:r") - .map((entry) => ({ name: entry.name, steering: entry.steering, knobs: entry.knobs })), - activity: goldens.activity.cases.filter((entry) => GOLDEN_ACTIVITY.includes(entry.name)) - .map((entry) => ({ name: entry.name, arguments: entry.arguments })), - reads: goldens.reads.reads.map((entry) => ({ unit: entry.unit, k: entry.k, hideHubs: entry.hide_hubs })), - top: goldens.reads.top.map((entry) => ({ token: entry.token, by: entry.by, k: entry.k })), - find: goldens.reads.find.map((entry) => (entry.target === "vector" - ? { vector: Array.from(decode(entry.vector)), layer: entry.layer, k: entry.k } - : { selector: entry.target, k: entry.k })), - ablation: goldens.ablation.cases.filter((entry) => entry.name !== "mixed") - .map((entry) => ({ name: entry.name, steering: entry.steering, steps: entry.decode_steps })), - }, - nodes: options.goldens ? [] : Object.entries(reference.nodes).map(([name, entry]) => ({ - name, steering: entry.steering, probes: entry.probes, input: entry.input, system: entry.system, - parent: entry.parent, seat: entry.seat, raw: entry.raw, - anatomyKnobs: entry.anatomy.knobs, activityKnobs: entry.activity?.knobs ?? null, - })), - settings: reference.settings, - reads: options.goldens ? [] : reference.reads.map((entry) => ({ unit: entry.unit, k: entry.read.knobs.k, hideHubs: entry.hide_hubs })), - top: options.goldens ? [] : reference.top.map((entry) => ({ token: entry.token, by: entry.by, k: entry.result.knobs.k })), - find: options.goldens ? [] : reference.find.map((entry) => ({ vector: Array.from(decode(entry.vector)), layer: entry.layer, k: entry.result.knobs.k })), - }; - const run = await page.evaluate(driveWorker, plan); - if (run.error) { - check("hosted runtime worker", false, run.error); - throw new Error(run.error); - } - check("worker installs and loads the v5 library with its packs", true, run.loaded); - if (!options.chat) { - check("a plain greedy generation through the worker", JSON.stringify(run.plain) === JSON.stringify(unitProbes.cases[0].tokens.slice(0, 2)), - `${JSON.stringify(run.plain)} vs ${JSON.stringify(unitProbes.cases[0].tokens.slice(0, 2))}`); - } - compareRun(run, unitProbes); - if (goldens !== null) compareGoldens(run.goldens, goldens); -} finally { - await browser.close(); - await new Promise((ok) => http.close(ok)); - await vite.close(); -} -for (const [label, value] of worst) console.log(`worst |Δ| ${label}: ${value.toExponential(2)}`); -if (failures > 0) { - console.error(`units worker on ${stage.fixture}: ${failures} check(s) failed`); - process.exit(1); -} -console.log(`units worker on ${stage.fixture}: every check passed`); - -// ---------------------------------------------------------------------- comparisons --- -function compareRun(run, unitProbes) { - const tol = unitProbes.tolerance.library; - const numberTol = (path) => { - if (/probability$|\.p$/.test(path)) return tol.probability_atol + 2e-6; - return tol.z_atol + 2e-6; - }; - const record = (label, value, expected, options = {}) => { - const deltas = []; - const actual = withoutUnderflow(value); - const problems = compareRecord(actual, expected, { - numberTol: (path, e) => { - return numberTol(path, e); - }, - ...options, - }); - measureWorst(label, actual, expected, deltas); - check(label, problems.length === 0, problems.slice(0, 4).join("; ")); - return deltas; - }; - // unit-probes: tokens, every forward's units channel, gate scalars through the gate case, aggregate. - for (const [index, golden] of run.probeCases.length === 0 ? [] : unitProbes.cases.entries()) { - const ours = run.probeCases[index]; - // Frames by raw index: a piece whose text completes in a later token (a split UTF-8 byte) - // rides that token's frame, so a forward can have no frame of its own. - const tokens = ours.tokens.filter(([raw]) => raw !== null); - check(`unit-probes ${golden.name}: tokens`, - tokens.length > 0 && tokens.every(([raw, id]) => golden.tokens[raw] === id) && - tokens.at(-1)[0] === golden.tokens.length - 1, - `${JSON.stringify(ours.tokens)} vs ${JSON.stringify(golden.tokens)}`); - for (const [raw, measurements] of ours.frames) { - record(`unit-probes ${golden.name}: forward ${raw} units channel`, - measurements?.instruments?.units?.readings ?? null, golden.forwards[raw]?.readings ?? null); - } - record(`unit-probes ${golden.name}: aggregate units`, ours.aggregate?.instruments?.units ?? null, - golden.aggregate.instruments.units); - } - // generations with unit and slens/ probes: tokens and the aggregate's units and lens channels. - for (const ours of run.generations) { - const native = reference.generations[ours.name]; - check(`${ours.name} (${native.steering}): tokens`, JSON.stringify(ours.tokens) === JSON.stringify(native.tokens), - `${JSON.stringify(ours.tokens)} vs ${JSON.stringify(native.tokens)}`); - record(`${ours.name}: aggregate units`, ours.aggregate?.instruments?.units ?? null, native.aggregate.instruments.units); - record(`${ours.name}: aggregate slens/ readings`, ours.aggregate?.instruments?.lens?.readings ?? null, - native.aggregate.instruments.lens.readings); - check(`${ours.name}: lens binding names the S source`, - JSON.stringify(Object.keys(ours.aggregate?.instruments?.lens?.binding?.sources ?? {})) === JSON.stringify(["S"]), - JSON.stringify(ours.aggregate?.instruments?.lens?.binding)); - check(`${ours.name}: units live rides the token envelopes`, ours.liveUnitFrames === ours.tokens.length, - `${ours.liveUnitFrames} of ${ours.tokens.length}`); - } - // nodes: token anatomy and unit activity. - for (const ours of run.nodes) { - const native = reference.nodes[ours.name]; - check(`node ${ours.name}: tokens`, JSON.stringify(ours.tokens) === JSON.stringify(native.tokens), - `${JSON.stringify(ours.tokens)} vs ${JSON.stringify(native.tokens)} (frames ${JSON.stringify(ours.frameTypes)})`); - record(`node ${ours.name}: token anatomy`, withoutSources(ours.anatomy), withoutSources(native.anatomy.result), - { root: `nodes.${ours.name}.anatomy.result`, ties: reference.declared_ties }); - if (native.activity) { - // Node ids are each tree's own; the population is fp16, matched within one ulp. - const population = populationProblems(ours.activity?.population ?? null, native.activity.result.population); - check(`node ${ours.name}: unit activity population (fp16, one ulp)`, population.length === 0, population.slice(0, 3).join("; ")); - // A unit whose peak row has no margin (drowse's `_check_activity`) is compared by value. - const tied = new Set(native.activity.tied_peak_rows ?? []); - const rowless = (result) => ({ - ...result, node_id: null, population: null, - top: (result?.top ?? []).map((entry) => (tied.has(entry.unit) ? { ...entry, raw_index: null } : entry)), - }); - record(`node ${ours.name}: unit activity`, rowless(ours.activity), rowless(native.activity.result), - { root: `nodes.${ours.name}.activity.result`, ties: reference.declared_ties }); - } - } - run.reads.forEach((ours, i) => record(`unitRead ${reference.reads[i].unit}`, ours, reference.reads[i].read.result, - { root: `reads[${i}].result`, ties: reference.declared_ties })); - run.top.forEach((ours, i) => record(`unitTop ${reference.top[i].token} by ${reference.top[i].by}`, ours, - reference.top[i].result.result, { root: `top[${i}].result`, ties: reference.declared_ties })); - run.find.forEach((ours, i) => record(`unitFind vector at L${reference.find[i].layer}`, ours, - reference.find[i].result.result, { root: `find[${i}].result`, ties: reference.declared_ties })); -} - -/** The worker's answers at the goldens' band against the golden files themselves. */ -function compareGoldens(ours, goldens) { - const tol = goldens.anatomy.tolerance.library; - const numberTol = (path) => (/probability$|\.p$/.test(path) ? tol.probability_atol : tol.z_atol) + 2e-6; - const record = (label, value, expected, options) => { - const actual = withoutUnderflow(value); - const want = withoutUnderflow(expected); - const problems = compareRecord(actual, want, { numberTol, ...options }); - measureWorst(label, actual, want); - check(label, problems.length === 0, problems.slice(0, 4).join("; ")); - }; - const caseOf = (name) => goldens.activity.cases.find((entry) => entry.name === name); - for (const name of ["generated", "segmented", "sink"]) { - const want = caseOf(name).result.tokens.map((entry) => entry.token_id); - check(`golden node ${name}: tokens`, JSON.stringify(ours.tokens[name]) === JSON.stringify(want), - `${JSON.stringify(ours.tokens[name])} vs ${JSON.stringify(want)}`); - } - goldens.anatomy.cases.filter((entry) => entry.lens === "local:r").forEach((entry, i) => { - const index = goldens.anatomy.cases.indexOf(entry); - record(`golden token-anatomy ${entry.name}`, withoutSources(ours.anatomy[i]), withoutSources(entry.envelope), - { root: `cases[${index}].envelope`, ties: goldens.anatomy.declared_ties }); - }); - GOLDEN_ACTIVITY.forEach((name, i) => { - const entry = caseOf(name); - const index = goldens.activity.cases.indexOf(entry); - const tied = new Set(entry.tied_peak_rows ?? []); - const rowless = (result) => ({ - ...result, population: null, - top: (result?.top ?? []).map((item) => (tied.has(item.unit) ? { ...item, raw_index: null } : item)), - }); - const { node_id: _nodeId, ...mine } = ours.activity[i] ?? {}; - const population = populationProblems(mine.population ?? null, entry.result.population ?? null); - check(`golden unit-activity ${name}: population (fp16, one ulp)`, population.length === 0, population.slice(0, 3).join("; ")); - record(`golden unit-activity ${name}`, rowless(mine), rowless(entry.result), - { root: `cases[${index}].result`, ties: goldens.activity.declared_ties }); - }); - const reads = goldens.reads; - reads.reads.forEach((entry, i) => record(`golden unit-reads read ${entry.unit}`, ours.reads[i], entry.read, - { root: `reads[${i}].read`, ties: reads.declared_ties })); - reads.top.forEach((entry, i) => record(`golden unit-reads top ${entry.token} by ${entry.by}`, ours.top[i], entry.result, - { root: `top[${i}].result`, ties: reads.declared_ties })); - reads.find.forEach((entry, i) => record(`golden unit-reads find ${entry.target}`, ours.find[i], entry.result, - { root: `find[${i}].result`, ties: reads.declared_ties })); - // unit-ablation: every forward's greedy token is the golden logits' argmax, and every forward's - // top eight log-probabilities at temperature 1 (on the greedy path) are the golden logits' - // log-softmax (the library tolerance on fp32 logits), so a decode forward's numbers count too: the - // gated case differs from unsteered only in its last forward's logits. - goldens.ablation.cases.filter((entry) => entry.name !== "mixed").forEach((entry, i) => { - const mine = ours.ablation[i] ?? { tokens: null, forwards: null, tried: 0, last: null }; - const problems = []; - const logSoftmax = (encoded) => { - const logits = Array.from(decode(encoded)); - const max = Math.max(...logits); - const lse = max + Math.log(logits.reduce((sum, value) => sum + Math.exp(value - max), 0)); - return logits.map((value) => value - lse); - }; - const tolerated = (delta, value) => delta <= tol.atol + tol.rtol * Math.abs(value); - let worstLogprob = 0; - entry.forwards.forEach((forward, step) => { - const logp = logSoftmax(forward.logits); - const best = logp.reduce((at, value, index) => (value > logp[at] ? index : at), 0); - if (mine.tokens?.[step] !== best) problems.push(`forward ${step}: token ${mine.tokens?.[step]} != ${best}`); - const read = mine.forwards?.[step]; - if (read === undefined) return; - const want = logp.map((value, id) => [id, value]).sort((a, b) => b[1] - a[1]).slice(0, 8); - want.forEach(([id, value], rank) => { - const alt = (read.alts ?? []).find((item) => item.id === id); - if (alt === undefined) return problems.push(`forward ${step}: token ${id} (rank ${rank}) missing from the top alternatives`); - const delta = Math.abs(alt.logprob - value); - worstLogprob = Math.max(worstLogprob, delta); - if (!tolerated(delta, value)) problems.push(`forward ${step}: token ${id} logprob off by ${delta}`); - }); - const chosen = Math.abs(read.logprob - logp[read.token]); - worstLogprob = Math.max(worstLogprob, chosen); - if (!tolerated(chosen, logp[read.token])) problems.push(`forward ${step}: sampled token logprob off by ${chosen}`); - }); - if (mine.forwards === null) { - problems.push(`no temperature-1 run in ${mine.tried} seeds followed the greedy path with a frame per token, so no forward's log-probabilities were read (last run: ${mine.last})`); - } else { - worst.set("golden unit-ablation logprob", Math.max(worst.get("golden unit-ablation logprob") ?? 0, worstLogprob)); - } - const at = mine.forwards === null ? "" : ` (read on seed ${mine.tried})`; - check(`golden unit-ablation ${entry.name} (${entry.steering}): ${entry.forwards.length} forwards, argmax and top-8 log-probabilities each${at}`, - problems.length === 0, problems.slice(0, 4).join("; ")); - }); -} - -/** An activity population's fp16 rows (base64, little-endian) against drowse's, one ulp apart at - * most (units-activity.test.mjs's rule). */ -function populationProblems(actual, expected) { - if (expected === null || actual === null) return actual === expected ? [] : ["population presence differs"]; - const halfBits = (text) => { - const bytes = Buffer.from(text, "base64"); - return Array.from({ length: bytes.length / 2 }, (_, i) => bytes[2 * i] | (bytes[2 * i + 1] << 8)); - }; - const ordered = (bits) => (bits & 0x8000 ? -(bits & 0x7fff) : bits); - const problems = []; - if (actual.raw_index !== expected.raw_index || actual.encoding !== expected.encoding || - JSON.stringify(actual.layers.map((l) => l.layer)) !== JSON.stringify(expected.layers.map((l) => l.layer))) { - return ["population header differs"]; - } - actual.layers.forEach((layer, i) => { - for (const key of ["neurons", "heads"]) { - const got = halfBits(layer[key]); - const want = halfBits(expected.layers[i][key]); - if (got.length !== want.length) problems.push(`L${layer.layer} ${key} length`); - got.forEach((bits, j) => { - if (Math.abs(ordered(bits) - ordered(want[j])) > 1) problems.push(`L${layer.layer} ${key}[${j}]`); - }); - } - }); - return problems; -} - -/** `value` without probability entries that underflowed to exactly 0 (the reference's - * `without_underflow`): which zero-probability tokens fill a list is arbitrary. */ -function withoutUnderflow(value) { - if (Array.isArray(value)) return value.map(withoutUnderflow); - if (value === null || typeof value !== "object") return value; - const probability = value.unit === "probability"; - return Object.fromEntries(Object.entries(value).map(([key, child]) => [key, - probability && Array.isArray(child) - ? child.filter((item) => !(item && typeof item === "object" && item.value === 0)) - : withoutUnderflow(child)])); -} - -/** The lens sources' labels are each runtime's own (native `local:r`, a pack id here). */ -function withoutSources(value) { - return JSON.parse(JSON.stringify(value, (key, item) => - key === "sources" && item && typeof item === "object" ? Object.keys(item).sort() : item)); -} - -function measureWorst(label, actual, expected) { - const family = label.replace(/^unit-probes \S+: forward \d+ /, "unit-probes ").replace(/^(node \S+|push|ablate-response|slens-gated): /, ""); - let max = worst.get(family) ?? 0; - const walk = (a, e) => { - if (typeof e === "number" && typeof a === "number") max = Math.max(max, Math.abs(a - e)); - else if (Array.isArray(e) && Array.isArray(a)) e.forEach((item, i) => walk(a[i], item)); - else if (e && typeof e === "object" && a && typeof a === "object") for (const key of Object.keys(e)) walk(a[key], e[key]); - }; - walk(actual, expected); - worst.set(family, max); -} - -// ------------------------------------------------------------- the page-side driver --- -async function driveWorker(plan) { - const worker = new Worker("/units-worker.js", { type: "module" }); - const pending = new Map(); - const generations = new Map(); - let ready; - let broken; - const readyPromise = new Promise((ok, fail) => { ready = ok; broken = fail; }); - let sequence = 0; - const trail = []; - let lastStatus = null; - worker.onerror = (event) => { - const error = new Error(`worker error: ${event.message ?? "unknown"} (${event.filename ?? ""}:${event.lineno ?? ""})`); - broken(error); - for (const entry of pending.values()) entry.fail(error); - pending.clear(); - }; - worker.onmessage = (event) => { - const message = event.data; - if (message?.kind === "harness-ready") return ready(); - if (message?.kind === "response") { - const entry = pending.get(message.requestId); - if (entry) { - pending.delete(message.requestId); - if (message.ok) entry.ok(message.result); - else entry.fail(new Error(`${message.error?.code ?? "ERROR"}: ${message.error?.message ?? "failed"}`)); - } - return; - } - if (message?.kind === "event" && message.event === "status") lastStatus = message.payload; - if (message?.kind === "event" && message.requestId !== null && generations.has(message.requestId)) { - generations.get(message.requestId).push({ ...message.payload, type: message.payload?.type ?? message.event }); - } - }; - const call = (command, payload) => { - const requestId = `harness-${++sequence}`; - trail.push(`${command}${command === "request" ? ` ${payload.service}.${payload.method}` : ""}`); - return { - requestId, - promise: new Promise((ok, fail) => { - const timer = setTimeout(() => { - pending.delete(requestId); - const frames = generations.get(requestId)?.map((frame) => frame.type) ?? []; - fail(new Error(`${trail.at(-1)} timed out (frames ${JSON.stringify(frames)}; status ${JSON.stringify(lastStatus?.generation ?? lastStatus?.lifecycle ?? null)})`)); - }, command === "generate" ? 120_000 : 300_000); - pending.set(requestId, { - ok: (value) => { clearTimeout(timer); ok(value); }, - fail: (error) => { clearTimeout(timer); fail(error); }, - }); - worker.postMessage({ protocolVersion: 1, requestId, command, payload }); - }), - }; - }; - const send = (command, payload) => call(command, payload).promise; - const service = (serviceName, method, ...args) => send("request", { service: serviceName, method, args }); - const generate = async (request) => { - const requestId = `harness-${sequence + 1}`; - generations.set(requestId, []); - await call("generate", { type: "generate", ...request }).promise; - const frames = generations.get(requestId); - generations.delete(requestId); - const tokens = frames.filter((frame) => frame.type === "token" && frame.thinking !== true); - const done = frames.find((frame) => frame.type === "done"); - return { frames, tokens, done }; - }; - const greedy = (steps) => ({ temperature: 0, max_tokens: steps, seed: 0 }); - const recordedTokens = async (nodeId) => - (await service("tree", "get")).nodes.find((item) => item.id === nodeId)?.raw_token_ids ?? null; - // The goldens' nodes through the hosted loom, read at the goldens' band (the worker's lensBand). - const driveGoldens = async (g, root) => { - // drowse's goldens decode six distinct greedy tokens (presence penalty 1e4). - const distinct = { temperature: 0, max_tokens: g.decode_steps, seed: 0, presence_penalty: 1e4 }; - const chatNode = async (steering) => { - const result = await generate({ - input: g.user, raw: false, stateless: false, parent_node_id: root, steering, sampling: distinct, - system_prompt: g.system, generate_seat: "assistant", - }); - return result.done?.node_id ?? result.tokens.at(-1)?.node_id; - }; - const nodes = { - generated: await chatNode(null), - steered: await chatNode(g.anatomy_steering), - segmented: await chatNode(g.segmented_steering), - }; - const first = await generate({ - input: g.raw_first, raw: true, stateless: false, parent_node_id: root, steering: null, sampling: greedy(3), - }); - nodes.sink = first.done?.node_id ?? first.tokens.at(-1)?.node_id; - nodes["sink-population"] = nodes.sink; - const result = { tokens: {}, anatomy: [], activity: [], reads: [], top: [], find: [], ablation: [] }; - for (const [name, nodeId] of Object.entries(nodes)) result.tokens[name] = await recordedTokens(nodeId); - for (const entry of g.anatomy) { - result.anatomy.push(await service("instruments", "tokenAnatomy", entry.steering ? nodes.steered : nodes.generated, - g.anatomyIndex, { ...entry.knobs, raw: false })); - } - for (const entry of g.activity) { - const a = entry.arguments; - result.activity.push(await service("instruments", "unitActivity", nodes[entry.name], { - top: a.top, units: a.units, rawIndex: a.raw_index, layers: a.layers, raw: a.raw, - })); - } - for (const entry of g.reads) result.reads.push(await service("instruments", "unitRead", entry.unit, { k: entry.k, hideHubs: entry.hideHubs })); - for (const entry of g.top) result.top.push(await service("instruments", "unitTop", entry.token, { by: entry.by, k: entry.k })); - for (const entry of g.find) result.find.push(await service("instruments", "unitFind", entry)); - for (const entry of g.ablation) { - // The greedy decode under the case's program (its node's record). A token row's logprobs are - // the sampler's (native's too), so every forward's distribution is read at temperature 1: a - // seed whose sampled run follows the greedy path (each forward but the last fed the greedy - // token) with every token in a frame of its own (a lone UTF-8 byte streams none) gives each - // forward's top eight, the model's log-softmax under the program. - const run = await generate({ - input: g.short_text, raw: true, stateless: false, parent_node_id: root, steering: entry.steering, - sampling: greedy(entry.steps + 1), - }); - const tokens = await recordedTokens(run.done?.node_id ?? run.tokens.at(-1)?.node_id); - let forwards = null; - let tried = 0; - let last = null; - for (let k = 0; forwards === null && tokens !== null && k < 32; k += 1) { - tried += 1; - // The bridge draws from TVM's LCG seeded with the request's seed (multiplier 48271, no - // increment), so a small seed's first draw is about 2.2e-5 × seed: the most probable - // token. Seeds a million apart spread the first draw over the distribution. - const seed = 1 + k * 1000003; - const sampled = await generate({ - input: g.short_text, raw: true, stateless: true, steering: entry.steering, - sampling: { temperature: 1, top_p: 1, top_k: 0, max_tokens: entry.steps + 1, seed, return_top_k: 8 }, - }); - const frames = sampled.tokens; - last = { done: sampled.done?.result ?? null, tokens: frames.map((frame) => [frame.raw_index, frame.token_id]) }; - const onPath = frames.length === tokens.length && frames.every((frame, step) => - frame.raw_index === step && (step === tokens.length - 1 || frame.token_id === tokens[step])); - if (onPath) forwards = frames.map((frame) => ({ token: frame.token_id, logprob: frame.logprob, alts: frame.top_alts })); - } - result.ablation.push({ tokens, forwards, tried, last: forwards === null ? JSON.stringify(last).slice(0, 400) : null }); - } - return result; - }; - try { - await readyPromise; - await send("check", undefined); - await send("catalog", {}); - await send("download", { modelVariantId: plan.variantId, contextTokens: plan.contextTokens }); - for (const packId of plan.packIds) await send("download_pack", { modelVariantId: plan.variantId, packId }); - await send("load", { modelVariantId: plan.variantId, contextTokens: plan.contextTokens, resetSession: true }); - await service("instruments", "setLive", "units", { enabled: true }); - const out = { loaded: `${plan.packIds.length} optional packs`, probeCases: [], generations: [], nodes: [] }; - // A plain greedy generation first: no program, no probes. - if (!plan.chat) { - const plain = await generate({ input: plan.text, raw: true, stateless: true, steering: null, sampling: greedy(2) }); - out.plain = plain.tokens.map((frame) => frame.token_id); - } - - for (const unit of plan.chat ? [] : plan.unitProbes) await service("probes", "attach", { selector: unit }); - for (const entry of plan.chat ? [] : plan.probeCases) { - const result = await generate({ input: plan.text, raw: true, stateless: true, steering: entry.steering, sampling: greedy(5) }); - out.probeCases.push({ - name: entry.name, - tokens: result.tokens.map((frame) => [frame.raw_index, frame.token_id]), - frames: result.tokens.map((frame) => [frame.raw_index, frame.measurements ?? null]), - aggregate: result.done?.result?.measurements ?? null, - }); - } - if (!plan.chat) await service("probes", "attach", { selector: `slens/${plan.settings.slensWord}` }); - for (const entry of plan.generations) { - const result = await generate({ input: plan.text, raw: true, stateless: true, steering: entry.steering, sampling: greedy(plan.settings.steps) }); - out.generations.push({ - name: entry.name, - tokens: result.tokens.map((frame) => frame.token_id), - liveUnitFrames: result.tokens.filter((frame) => frame.measurements?.instruments?.units !== undefined).length, - aggregate: result.done?.result?.measurements ?? null, - }); - } - if (!plan.chat) { - for (const name of [...plan.unitProbes, `slens/${plan.settings.slensWord}`]) await service("probes", "detach", name); - } - - const root = (await service("tree", "get")).root_id; - const nodeIds = new Map(); - for (const entry of plan.nodes) { - // The node's probes stay attached through its generation and its replays, as drowse's. - for (const selector of entry.probes) await service("probes", "attach", { selector }); - // From the root (or the named parent node), as drowse's reference generates it. - const result = await generate({ - input: entry.input, raw: entry.raw, stateless: false, - parent_node_id: entry.parent === null ? root : nodeIds.get(entry.parent), steering: entry.steering, - sampling: greedy(plan.settings.decodeSteps), - ...(entry.raw ? {} : { system_prompt: entry.system, generate_seat: entry.seat }), - }); - const nodeId = result.done?.node_id ?? result.tokens.at(-1)?.node_id; - nodeIds.set(entry.name, nodeId); - // The node's raw token record (what its replays feed): a piece whose UTF-8 never completes - // (a lone lead byte, repeated) streams no token frame of its own. - const recorded = (await service("tree", "get")).nodes.find((item) => item.id === nodeId); - const node = { name: entry.name, nodeId, tokens: recorded?.raw_token_ids ?? null, - frameTypes: result.frames.map((frame) => `${frame.type}${frame.thinking ? ":thinking" : ""}`) }; - node.anatomy = await service("instruments", "tokenAnatomy", nodeId, plan.settings.anatomyIndex, - { ...entry.anatomyKnobs, raw: entry.raw }); - if (entry.activityKnobs !== null) { - const activity = plan.settings.activity; - node.activity = await service("instruments", "unitActivity", nodeId, { - top: entry.activityKnobs.top, units: activity.units, rawIndex: activity.raw_index, layers: activity.layers, - raw: entry.raw, - }); - } - for (const selector of entry.probes) await service("probes", "detach", selector); - out.nodes.push(node); - } - if (plan.goldens !== null) out.goldens = await driveGoldens(plan.goldens, root); - out.reads = []; - for (const entry of plan.reads) out.reads.push(await service("instruments", "unitRead", entry.unit, { k: entry.k, hideHubs: entry.hideHubs })); - out.top = []; - for (const entry of plan.top) out.top.push(await service("instruments", "unitTop", entry.token, { by: entry.by, k: entry.k })); - out.find = []; - for (const entry of plan.find) out.find.push(await service("instruments", "unitFind", { vector: entry.vector, layer: entry.layer, k: entry.k })); - return out; - } catch (error) { - return { error: `${String(error?.stack ?? error)} (after ${trail.join(" → ")})` }; - } finally { - worker.terminate(); - } -} - -function parseArguments(args) { - const out = { port: 0, headed: false, chat: false, goldens: false, python: process.env.PYTHON ?? "python3" }; - for (let i = 0; i < args.length; i += 1) { - const flag = args[i]; - if (flag === "--headed") out.headed = true; - else if (flag === "--chat") out.chat = true; - else if (flag === "--goldens") out.goldens = true; - else if (["--fixtures", "--arch", "--quantization", "--work", "--port", "--python"].includes(flag)) { - out[flag.slice(2)] = flag === "--port" ? Number(args[++i]) : args[++i]; - } else throw new Error(`unknown argument ${flag}`); - } - for (const required of ["fixtures", "arch", "quantization", "work"]) { - if (!out[required]) throw new Error(`--${required} is required`); - } - out.fixtures = resolve(out.fixtures); - out.work = resolve(out.work); - return out; -} diff --git a/webui/scripts/build-hosted-catalog.mjs b/webui/scripts/build-hosted-catalog.mjs index 75487da..f13b182 100644 --- a/webui/scripts/build-hosted-catalog.mjs +++ b/webui/scripts/build-hosted-catalog.mjs @@ -221,10 +221,10 @@ async function prepareModel(entry, runtimeLock, specDirectory, semanticValidator // Hook ABI v5 parity: a units library ships the units, the token anatomy and the S lens, so // its R, S and units packs are in the release at every context; a residual library refuses // unit reads (the lock's unitRefusal) and has no native S lens or units. - if (lock.structuredHookProfile === "standard-v4") { + if (lock.structuredHookProfile === "standard-v5") { for (const [kind, label] of [["jlens", "R-lens"], ["slens", "S-lens"], ["units", "units"]]) { if (compatible(kind).length === 0) { - throw new Error(`${lock.id} context ${profile.contextTokens} has no ${label} pack (standard-v4 ships units and both lenses)`); + throw new Error(`${lock.id} context ${profile.contextTokens} has no ${label} pack (standard-v5 ships units and both lenses)`); } } } else if (compatible("slens").length > 0 || compatible("units").length > 0) { diff --git a/webui/scripts/build-hosted-catalog.test.mjs b/webui/scripts/build-hosted-catalog.test.mjs index eb8cdd3..d347ad3 100644 --- a/webui/scripts/build-hosted-catalog.test.mjs +++ b/webui/scripts/build-hosted-catalog.test.mjs @@ -111,9 +111,9 @@ try { ).map(({ path, bytes, sha256 }) => ({ path, bytes, sha256 })); const buildContents = JSON.stringify({ schemaVersion: 1, - runtimeAbi: "drowse-web-runtime-v2", - hookAbi: "block-sites-v5", - structuredHookProfile: "standard-v4", + runtimeAbi: "drowse-web-runtime-v3", + hookAbi: "block-sites-v6", + structuredHookProfile: "standard-v5", thinkingProfile, architecture: "qwen3", quantization: "q4f16_1", @@ -170,14 +170,14 @@ try { quantization: "q4f16_1", contextProfiles: [2048, 4096], prefillChunkSize: 2048, - structuredHookProfile: "standard-v4", + structuredHookProfile: "standard-v5", blockSpec: { ...FIXTURE_BLOCK_SPEC }, thinkingProfile, }; await writeFile(join(modelDirectory, "hosted-artifacts.json"), JSON.stringify({ schemaVersion: 1, - runtimeAbi: "drowse-web-runtime-v2", - hookAbi: "block-sites-v5", + runtimeAbi: "drowse-web-runtime-v3", + hookAbi: "block-sites-v6", structuredHookProfile: model.structuredHookProfile, thinkingProfile: model.thinkingProfile, architecture: model.architecture, @@ -190,8 +190,8 @@ try { files: base, })); const runtimeLock = { - runtimeAbi: "drowse-web-runtime-v2", - hookAbi: "block-sites-v5", + runtimeAbi: "drowse-web-runtime-v3", + hookAbi: "block-sites-v6", toolchain: { forkManifestSha256: createHash("sha256").update(forkManifestBytes).digest("hex"), }, @@ -327,7 +327,7 @@ try { ], ); assert.equal(catalog.models[0].variants[0].requiredCorePackBytes, sum(core)); - assert.equal(catalog.models[0].variants[0].structuredHookProfile, "standard-v4"); + assert.equal(catalog.models[0].variants[0].structuredHookProfile, "standard-v5"); assert.deepEqual(catalog.models[0].variants[0].thinkingProfile, model.thinkingProfile); assert.equal(catalog.models[0].variants[0].packs[1].bytes, sum(jlens)); assert.equal(catalog.models[0].variants[0].packs[2].bytes, sum(slens)); @@ -374,8 +374,8 @@ try { // Both v5 profiles export exact-readout-v2; no older profile is accepted. assert.throws( () => prepareRequirements({ features: [], limits: { maxStorageBuffersPerShaderStage: 10 } }, - "residual", "standard-v4-residual"), - /maxComputeWorkgroupSizeX must explicitly declare at least 256 for standard-v4-residual/, + "residual", "standard-v5-residual"), + /maxComputeWorkgroupSizeX must explicitly declare at least 256 for standard-v5-residual/, ); assert.throws( () => prepareRequirements({ features: [], limits: {} }, "legacy", "unknown-profile"), @@ -387,7 +387,7 @@ try { missing.models[0].packs = missing.models[0].packs.filter((pack) => pack.kind !== kind); await assert.rejects( () => prepareCatalog(missing, runtimeLock, root, validateSemantics), - kind === "units" ? /has no units pack \(standard-v4 ships units and both lenses\)/ : /units pack without its R and S lens packs|has no S-lens pack/, + kind === "units" ? /has no units pack \(standard-v5 ships units and both lenses\)/ : /units pack without its R and S lens packs|has no S-lens pack/, ); } const narrow = structuredClone(spec); diff --git a/webui/scripts/capture-hosted-residuals.mjs b/webui/scripts/capture-hosted-residuals.mjs index be9e970..9ca543f 100644 --- a/webui/scripts/capture-hosted-residuals.mjs +++ b/webui/scripts/capture-hosted-residuals.mjs @@ -448,7 +448,7 @@ function validNamedRoleCheck(value) { function validSteeringProgram(result, layerCount, hiddenSize) { const program = result.steeringProgram; - return program && program.format === "drowse-structured-v4" && + return program && program.format === "drowse-structured-v5" && Number.isSafeInteger(program.enabledLayer) && program.enabledLayer >= 0 && program.enabledLayer < layerCount && Array.isArray(program.probeDirections) && program.probeDirections.length === result.probeCount && result.probeCount >= 1 && diff --git a/webui/scripts/capture-hosted-residuals.test.mjs b/webui/scripts/capture-hosted-residuals.test.mjs index 7f17e33..e57301e 100644 --- a/webui/scripts/capture-hosted-residuals.test.mjs +++ b/webui/scripts/capture-hosted-residuals.test.mjs @@ -44,7 +44,7 @@ try { await rm(root, { recursive: true, force: true }); } -// Capture schema 5: a standard-v4 capture carries its block sites and one static read per layer; +// Capture schema 5: a standard-v5 capture carries its block sites and one static read per layer; // a residual one carries neither. { assert.equal(CAPTURE_SCHEMA_VERSION, 5); @@ -70,7 +70,7 @@ try { staticReads: [read(0, 1), read(1, 4)], }; const check = (overrides) => unitsCaptureFailures({ - structuredHookProfile: "standard-v4", + structuredHookProfile: "standard-v5", units, sitesBytes, lock, @@ -107,11 +107,11 @@ try { /1 to 64 static reads/, ); assert.deepEqual( - unitsCaptureFailures({ structuredHookProfile: "standard-v4-residual", units: undefined, sitesBytes: undefined, lock, positions }), + unitsCaptureFailures({ structuredHookProfile: "standard-v5-residual", units: undefined, sitesBytes: undefined, lock, positions }), [], ); assert.match( - unitsCaptureFailures({ structuredHookProfile: "standard-v4-residual", units, sitesBytes, lock, positions }).join(), + unitsCaptureFailures({ structuredHookProfile: "standard-v5-residual", units, sitesBytes, lock, positions }).join(), /carries no block sites/, ); assert.match( diff --git a/webui/scripts/catalog-fixture.mjs b/webui/scripts/catalog-fixture.mjs index 905f6b1..59d416e 100644 --- a/webui/scripts/catalog-fixture.mjs +++ b/webui/scripts/catalog-fixture.mjs @@ -65,7 +65,7 @@ export function catalogFixture(overrides = {}) { variants: [{ id: "smollm2-360m-q4f16", tier: "fastest", - structuredHookProfile: "standard-v4", + structuredHookProfile: "standard-v5", thinkingProfile: null, contextProfiles: [{ contextTokens: 2048, @@ -130,7 +130,7 @@ export function catalogBytes(overrides = {}) { return new TextEncoder().encode(JSON.stringify(catalogFixture(overrides))); } -/** A Qwen3-shaped block spec the fixture's standard-v4 lock entries record. */ +/** A Qwen3-shaped block spec the fixture's standard-v5 lock entries record. */ export const FIXTURE_BLOCK_SPEC = Object.freeze({ dFF: 8, nHeads: 2, nKvHeads: 1, headDim: 2, sandwich: false, normOffset: 0, activation: "silu", embedScale: 1, rmsEps: 1e-6, qkNorm: true, attnScaling: 0.5, attnLogitSoftcap: null, @@ -138,13 +138,13 @@ export const FIXTURE_BLOCK_SPEC = Object.freeze({ ropeInGraph: true, slidingWindow: null, slidingPattern: null, }); -/** The lock entry's block sites for a fixture variant: a standard-v4 library's block spec, a +/** The lock entry's block sites for a fixture variant: a standard-v5 library's block spec, a * residual one's unit refusal. */ -/** What the fixture lock records about a variant's library: its block spec (standard-v4) or +/** What the fixture lock records about a variant's library: its block spec (standard-v5) or * unit refusal (residual), and its compiled prefill chunk (the variant's smallest context). */ export function fixtureLibraryContract(variant) { const prefillChunkSize = Math.min(...variant.contextProfiles.map((profile) => profile.contextTokens)); - return variant.structuredHookProfile === "standard-v4" + return variant.structuredHookProfile === "standard-v5" ? { blockSpec: { ...FIXTURE_BLOCK_SPEC }, unitRefusal: null, prefillChunkSize } : { blockSpec: null, unitRefusal: "fixture blocks are not described", prefillChunkSize }; } diff --git a/webui/scripts/drowse-archive-browser.test.mjs b/webui/scripts/drowse-archive-browser.test.mjs index 2a60db7..0058e68 100644 --- a/webui/scripts/drowse-archive-browser.test.mjs +++ b/webui/scripts/drowse-archive-browser.test.mjs @@ -48,6 +48,7 @@ try { centroidMean: new Float64Array([0, 0]), mean: new Float64Array([0, 0]), basis: new Float64Array([1, 0]), + read: new Float64Array([0.5, 0]), nodeCoordinates: new Float64Array([-1, 0, 1]), muCoordinates: new Float64Array([-1, 0, 1]), whitenedGram: new Float64Array([ @@ -151,6 +152,11 @@ try { tensorPath, ); assert.deepEqual(tensor.tensor("layer_0.affine_map", [2, 1]).data, new Float32Array([1, 0])); + // drowse 6.1's typed frame and sidecar: the read rows travel beside the basis, and the + // retired metric labels are gone. + assert.deepEqual(tensor.tensor("layer_0.read", [1, 2]).data, new Float32Array([0.5, 0])); + assert.equal("share_metric" in sidecar || "subspace_metric" in sidecar, false); + assert.equal("files" in verified.manifold, false); }); test("publishes a self-validated browser curved fit with sigma and origin geometry", async () => { @@ -175,6 +181,7 @@ try { centroidMean: new Float64Array([0, 0]), mean: new Float64Array([0, 0]), basis: new Float64Array([1, 0, 0, 1]), + read: new Float64Array([1, 0, 0, 1]), nodeCoordinates: new Float64Array([-1, 0, 0, 0, 1, 0]), muCoordinates: new Float64Array([-1, 0, 0, 0, 1, 0]), whitenedGram: new Float64Array([ @@ -322,6 +329,7 @@ try { centroidMean: new Float64Array(2), mean: new Float64Array(2), basis: new Float64Array([1, 0]), + read: new Float64Array([1, 0]), nodeCoordinates: new Float64Array([-1, 1]), muCoordinates: new Float64Array([-1, 1]), whitenedGram: new Float64Array([1, -1, -1, 1]), @@ -414,7 +422,7 @@ try { await assert.rejects( buildDrowseArchive({ ...input, primary: "manifolds/local/wrong" }), - (error) => error.code === "MANIFEST_MISMATCH" && /outside/.test(error.message), + (error) => error.code === "MANIFEST_MISMATCH" && /no manifold\.json/.test(error.message), ); }); @@ -469,7 +477,6 @@ try { fit_mode: fixture.fitMode, hyperparams: fixture.hyperparams, nodes: fixture.nodes.map(({ label, role, kind }) => ({ label, role, kind })), - files: {}, source: fixture.source.uri, tags: fixture.expected.tags, template_ref: fixture.expected.template_ref, @@ -602,7 +609,7 @@ try { ); }); - test("rejects duplicate JSON keys and any manifest schema drift", async () => { + test("rejects duplicate JSON keys and ignores pack.json fields no reader uses", async () => { const fixture = manifoldFixture(); const raw = new TextDecoder().decode(fixture.entries[0].data); const duplicate = raw.replace( @@ -617,13 +624,12 @@ try { inspectDrowseArchive(duplicateArchive), (error) => error.code === "JSON_DUPLICATE_KEY", ); + // drowse 6.1's pack.json carries no files map, and a field nobody reads is ignored. const manifest = JSON.parse(raw); manifest.extra = true; - const drift = rebuildWithManifest(fixture, manifest); - await assert.rejects( - inspectDrowseArchive(drift), - (error) => error.code === "MANIFEST_INVALID", - ); + delete manifest.files; + const verified = await validateDrowseArchive(rebuildWithManifest(fixture, manifest)); + assert.deepEqual(Object.keys(verified.files), Object.keys(fixture.payloads).sort()); }); test("rejects traversal, absolute, drive, backslash, NUL, and alternate path names", async () => { @@ -643,7 +649,7 @@ try { ); }); - test("rejects duplicates, case-fold collisions, unknown roots, and non-exact closures", async () => { + test("rejects duplicates and case-fold collisions, and ignores entries outside the closure", async () => { await assert.rejects( inspectDrowseArchive(makeZip([ { name: "pack.json", data: text("{}") }, @@ -658,6 +664,7 @@ try { ])), (error) => error.code === "ARCHIVE_PATH_COLLISION", ); + // As drowse's extraction does, an install reads the closure and ignores everything else. const fixture = manifoldFixture(); const payloads = { ...fixture.payloads, "models/local/demo.bin": text("bad root") }; const manifest = makeManifest(payloads); @@ -665,15 +672,11 @@ try { { name: "pack.json", data: json(manifest) }, ...Object.entries(payloads).map(([name, data]) => ({ name, data })), ]); - await assert.rejects( - inspectDrowseArchive(archive), - (error) => error.code === "MANIFEST_MISMATCH" && /outside/.test(error.message), - ); + const outside = await validateDrowseArchive(archive); + assert.equal("models/local/demo.bin" in outside.files, false); const extraInner = manifoldFixture({ extraPayload: ["manifolds/local/demo/notes.txt", text("no") ] }); - await assert.rejects( - validateDrowseArchive(extraInner.archive), - (error) => error.code === "CLOSURE_INVALID" && /not exact/.test(error.message), - ); + const inner = await validateDrowseArchive(extraInner.archive); + assert.equal("manifolds/local/demo/notes.txt" in inner.files, false); }); test("rejects encrypted, linked, special, directory, and unsupported entries", async () => { @@ -718,28 +721,17 @@ try { ); }); - test("checks exact payload sizes and SHA-256 before committing staged data", async () => { - const fixture = manifoldFixture(); - const manifest = JSON.parse(new TextDecoder().decode(fixture.entries[0].data)); + test("installs a fit of an edited corpus as a miss that refits, and records what it staged", async () => { + // drowse 6.1: a stale fit is a registry miss, never a failed load. The pair still travels. + const fixture = fittedFixture(); const path = "manifolds/local/demo/nodes/00_calm.json"; - const changed = text('["evil"]\n'); + const changed = text('["edited"]\n'); const entries = fixture.entries.map((entry) => entry.name === path ? { ...entry, data: changed } : entry); - const events = []; - await assert.rejects( - validateDrowseArchive(makeZip(entries), { - stage: { - begin: () => events.push("begin"), - write: () => {}, - finish: (name) => events.push(`finish:${name}`), - commit: () => events.push("commit"), - rollback: () => events.push("rollback"), - }, - }), - (error) => error.code === "CHECKSUM_MISMATCH", - ); - assert.equal(manifest.files[path].sha256, digest(fixture.payloads[path])); - assert.equal(events.includes("commit"), false); - assert.equal(events.at(-1), "rollback"); + const verified = await validateDrowseArchive(makeZip(entries)); + assert.deepEqual(verified.fittedArtifacts, []); + assert.ok("manifolds/local/demo/_zdGVzdC9tb2RlbA.safetensors" in verified.files); + assert.equal(verified.files[path].sha256, digest(changed)); + assert.deepEqual(verified.manifest.files, verified.files); }); test("rolls staging back when begin, semantic validation, or cancellation fails", async () => { @@ -926,17 +918,15 @@ try { ); }); - test("binds fitted tensors to node bytes, fit semantics, and filename variants", async () => { + test("reads 6.1 sidecars tolerantly and binds fitted tensors to their filename variants", async () => { const stale = fittedFixture({ sidecar: { nodes_sha256: "0".repeat(64) } }); - await assert.rejects( - validateDrowseArchive(stale.archive), - (error) => error.code === "CLOSURE_INVALID" && /node hash/.test(error.message), - ); - const wrongMethod = fittedFixture({ sidecar: { method: "manifold_discover_spectral" } }); - await assert.rejects( - validateDrowseArchive(wrongMethod.archive), - (error) => error.code === "CLOSURE_INVALID" && /method\/fit_mode/.test(error.message), - ); + assert.deepEqual((await validateDrowseArchive(stale.archive)).fittedArtifacts, []); + // A retired field is dropped and a missing provenance field defaults. + const tolerant = fittedFixture({ + sidecar: { share_metric: "mahalanobis", subspace_metric: "euclidean", future_field: 1 }, + omit: ["topology_candidates", "rbf_smoothing_per_layer", "bake_policy"], + }); + assert.equal((await validateDrowseArchive(tolerant.archive)).fittedArtifacts.length, 1); const rawNamedSae = fittedFixture({ sidecar: { method: "manifold_discover_sae", feature_space: "sae-release-a", @@ -987,18 +977,6 @@ try { const verified = await validateDrowseArchive(fixture.archive); assert.equal(verified.fittedArtifacts[0].variant, "from"); assert.equal(verified.fittedArtifacts[0].variantIdentity, "source/model"); - - const incomplete = fittedFixture({ - tensorName, - sidecar: { - method: "manifold_procrustes_transfer", - source_model_id: "source/model", - }, - }); - await assert.rejects( - validateDrowseArchive(incomplete.archive), - (error) => error.code === "CLOSURE_INVALID" && /incomplete transfer/.test(error.message), - ); }); test("requires immutable HF provenance and non-reserved manifold namespaces", async () => { @@ -1028,8 +1006,7 @@ try { } }); - test("mirrors drowse's method/fit_mode table and reserved namespaces", async () => { - const { METHOD_FIT_MODES } = await server.ssrLoadModule("/src/hosted/artifacts/drowseArchive.ts"); + test("mirrors drowse's reserved namespaces", async () => { const { RESERVED_NAMESPACES } = await server.ssrLoadModule("/src/hosted/runtime/steeringExpression.ts"); const drowseRoot = fileURLToPath(new URL("../../drowse", import.meta.url)); const result = spawnSync( @@ -1037,18 +1014,12 @@ try { ["-c", [ "import json", "from drowse.naming import RESERVED_NAMESPACES", - "from drowse.store.manifold_schema import METHOD_FIT_MODES", - "print(json.dumps({'methods': {k: sorted(v) for k, v in METHOD_FIT_MODES.items()}, 'reserved': sorted(RESERVED_NAMESPACES)}))", + "print(json.dumps({'reserved': sorted(RESERVED_NAMESPACES)}))", ].join("; ")], { cwd: drowseRoot, encoding: "utf8", env: { ...process.env, PYTHONPATH: drowseRoot, PYTHONDONTWRITEBYTECODE: "1" } }, ); assert.equal(result.status, 0, result.stderr || result.stdout); - const python = JSON.parse(result.stdout); - assert.deepEqual( - Object.fromEntries(Object.entries(METHOD_FIT_MODES).map(([method, modes]) => [method, [...modes].sort()])), - python.methods, - ); - assert.deepEqual([...RESERVED_NAMESPACES].sort(), python.reserved); + assert.deepEqual([...RESERVED_NAMESPACES].sort(), JSON.parse(result.stdout).reserved); }); test("enforces authored node floors and discover hyperparameter contracts", async () => { @@ -1056,10 +1027,9 @@ try { validateDrowseArchive(authoredFixture().archive), (error) => error.code === "CLOSURE_INVALID" && /at least 3 nodes/.test(error.message), ); - await assert.rejects( - validateDrowseArchive(manifoldFixture({ hyperparams: { k_nn: 3 } }).archive), - (error) => error.code === "CLOSURE_INVALID" && /does not accept/.test(error.message), - ); + // A hyperparameter the mode never reads is dropped, as drowse's reader drops it. + const unread = await validateDrowseArchive(manifoldFixture({ hyperparams: { k_nn: 3 } }).archive); + assert.deepEqual(unread.manifold.hyperparams, {}); await assert.rejects( validateDrowseArchive(manifoldFixture({ hyperparams: { max_dim: true } }).archive), (error) => error.code === "CLOSURE_INVALID" && /invalid value/.test(error.message), @@ -1212,9 +1182,7 @@ function fittedFixture(options = {}) { capture_version: null, capture_render_sha256: null, baseline_prompts_sha256: null, - fit_policy_version: 1, - share_metric: "mahalanobis", - subspace_metric: "mahalanobis", + fit_policy_version: 2, rbf_smoothing_per_layer: {}, sigma_field_per_layer: {}, resolved_fit_mode: null, @@ -1227,7 +1195,9 @@ function fittedFixture(options = {}) { transfer_quality_estimate: null, ...options.sidecar, }; + for (const key of options.omit ?? []) delete sidecar[key]; const sidecarBytes = json(sidecar); + // drowse 6.1's manifold.json: no files map; fitted pairs are found beside it. const manifold = { format_version: 10, name: "demo", @@ -1235,10 +1205,6 @@ function fittedFixture(options = {}) { fit_mode: "pca", hyperparams: {}, nodes: ["calm", "alert"].map((label) => ({ label, role: null, kind: "abstract" })), - files: { - [tensorName]: digest(tensor), - [sidecarName]: digest(sidecarBytes), - }, source: "local", tags: [], template_ref: null, @@ -1310,6 +1276,7 @@ function makeTensor(extraShapes = {}, options = {}) { node_coords: [2, 1], "layer_0.mean": [2], "layer_0.basis": [1, 2], + "layer_0.read": [1, 2], "layer_0.node_coords": [2, 1], ...extraShapes, }; diff --git a/webui/scripts/drowse-web-llm-backend.test.mjs b/webui/scripts/drowse-web-llm-backend.test.mjs index dd7bd8e..98d7b0f 100644 --- a/webui/scripts/drowse-web-llm-backend.test.mjs +++ b/webui/scripts/drowse-web-llm-backend.test.mjs @@ -251,8 +251,8 @@ try { profiles: steeringCompiler.listProfiles().profiles.map((profile) => profile.name), }); return context.expression.includes("head/") - ? { format: "drowse-structured-v4", hookAbi: "block-sites-v5", unitMeta: new Int32Array(1) } - : { format: "drowse-structured-v4", hookAbi: "block-sites-v5" }; + ? { format: "drowse-structured-v5", hookAbi: "block-sites-v6", unitMeta: new Int32Array(1) } + : { format: "drowse-structured-v5", hookAbi: "block-sites-v6" }; }, steeringDelta(context) { deltas.push(context); @@ -304,10 +304,10 @@ try { // The load wires the units members and hands the compiler their unit source: this library // predates hook ABI v5, so the source carries native's refusal and every member answers 422. assert.equal(instrumentCompiler.unitSource.spec, null); - assert.equal(instrumentCompiler.unitSource.refusal, "the loaded model library predates hook ABI block-sites-v5"); + assert.equal(instrumentCompiler.unitSource.refusal, "the loaded model library predates hook ABI block-sites-v6"); await assert.rejects( backend.request(service("instruments", "unitRead", ["neuron/L0n0"]), () => {}, new AbortController().signal), - (error) => error.status === 422 && error.message === "the loaded model library predates hook ABI block-sites-v5", + (error) => error.status === 422 && error.message === "the loaded model library predates hook ABI block-sites-v6", ); assert.deepEqual(loadProgress, [ { @@ -777,7 +777,7 @@ try { assert.equal(compiled[0].expression, "0.5 local/fitted"); assert.equal(compiled[0].loadRequest, request); assert.deepEqual(compiled[0].profiles, ["local/demo", "local/fitted"]); - assert.equal(calls.find((call) => call[0] === "generate")[1].hookProgram.hookAbi, "block-sites-v5"); + assert.equal(calls.find((call) => call[0] === "generate")[1].hookProgram.hookAbi, "block-sites-v6"); const tree = await backend.request( service("tree", "get"), diff --git a/webui/scripts/fitting-coordinator.test.mjs b/webui/scripts/fitting-coordinator.test.mjs index 24c8974..5b02df6 100644 --- a/webui/scripts/fitting-coordinator.test.mjs +++ b/webui/scripts/fitting-coordinator.test.mjs @@ -1,5 +1,4 @@ import assert from "node:assert/strict"; -import { readFile } from "node:fs/promises"; import { fileURLToPath } from "node:url"; import { createServer } from "vite"; @@ -18,11 +17,8 @@ const test = (name, run) => tests.push({ name, run }); try { const { BrowserFittingCoordinator, - anchorBrowserNeutralLayout, embedBrowserAuthoredCoordinates, - finalizeBrowserAffineLayers, fitBrowserCurvedSurfaceLayers, - selectBrowserDlsAxes, } = await server.ssrLoadModule( "/src/hosted/fitting/coordinator.ts", ); @@ -327,118 +323,6 @@ try { assert.equal(harness.lifecycle.includes("remove"), true); }); - test("matches the shared Python DLS keep and all-fail fallback fixtures", async () => { - const fixture = JSON.parse(await readFile(new URL( - "../../drowse/tests/fixtures/browser/dls-axes-v1.json", - import.meta.url, - ))); - const layers = new Map(fixture.layers.map((layer) => [layer.layer, { - operation: "affine_fisher", - nodeCount: layer.nodeCount, - columns: layer.components, - components: layer.components, - centroidMean: new Float64Array(layer.components), - mean: new Float64Array(layer.components), - basis: new Float64Array(layer.components * layer.components), - nodeCoordinates: new Float64Array(layer.nodeCoordinates), - muCoordinates: new Float64Array(layer.nodeCoordinates.length), - whitenedGram: new Float64Array(layer.nodeCount * layer.nodeCount), - neutralCrossGram: new Float64Array(layer.nodeCount), - explainedVariance: 1, - mahalanobisShare: 1, - }])); - const selected = selectBrowserDlsAxes(layers, fixture.intrinsicDimensions); - assert.deepEqual(mapAxes(selected), fixture.expected); - for (const layer of layers.values()) { - layer.nodeCoordinates = layer.nodeCoordinates.map((value) => Math.abs(value) + 1); - } - assert.deepEqual( - mapAxes(selectBrowserDlsAxes(layers, fixture.intrinsicDimensions)), - fixture.allFailExpected, - ); - }); - - test("matches Python neutral anchoring in the shared consensus layout", async () => { - const fixture = JSON.parse(await readFile(new URL( - "../../drowse/tests/fixtures/browser/affine-fisher-fit-v1.json", - import.meta.url, - ))); - const expected = fixture.expected; - const layers = new Map([[0, { - operation: "affine_fisher", - nodeCount: fixture.nodeCount, - columns: fixture.columns, - components: fixture.maxComponents, - centroidMean: new Float64Array(expected.centroidMean), - mean: new Float64Array(expected.mean), - basis: new Float64Array(expected.basis), - nodeCoordinates: new Float64Array(expected.nodeCoordinates), - muCoordinates: new Float64Array(expected.muCoordinates), - whitenedGram: new Float64Array(expected.whitenedGram), - neutralCrossGram: new Float64Array(expected.neutralCrossGram), - explainedVariance: expected.explainedVariance, - mahalanobisShare: expected.mahalanobisShare, - }]]); - const anchored = anchorBrowserNeutralLayout(layers, { - operation: "topology", - winnerName: "flat-pca", - fitMode: "pca", - intrinsicDimensions: 2, - periodicDimensions: 0, - persistentLoops: 0, - usedFaintCycle: false, - coordinates: new Float64Array(expected.layoutCoordinates), - embeddedCoordinates: new Float64Array(expected.layoutCoordinates), - candidates: [], - diagnostics: { - kind: "pca", - perComponentVariance: new Float64Array([0.75, 0.25]), - cumulativeVariance: new Float64Array([0.75, 1]), - pickedDimensions: 2, - threshold: 0.7, - }, - winnerPlan: null, - }); - close(anchored.neutral, expected.neutralLayoutCoordinate, 2e-6); - close(anchored.coordinates, expected.anchoredLayoutCoordinates, 2e-6); - - const serialized = fixture.serializedWhitener; - const finalized = finalizeBrowserAffineLayers( - layers, - new Map([[0, { - ...serialized, - mean: new Float64Array(serialized.mean), - basis: new Float64Array(serialized.basis), - eigenvalues: new Float64Array(serialized.eigenvalues), - inverseScales: new Float64Array(serialized.inverseScales), - }]]), - new Map([[0, new Uint32Array([0])]]), - 2, - ).get(0); - close(finalized.mean, expected.axisZeroFinal.mean, 2e-6); - close(finalized.basis, expected.axisZeroFinal.basis, 2e-6); - close(finalized.nodeCoordinates, expected.axisZeroFinal.nodeCoordinates, 2e-6); - close(finalized.muCoordinates, expected.axisZeroFinal.muCoordinates, 2e-6); - close(finalized.affineMap, [1, 0], 0); - assert.ok( - Math.abs(finalized.mahalanobisShare - expected.axisZeroFinal.mahalanobisShare) <= 2e-6, - ); - - const reordered = finalizeBrowserAffineLayers( - layers, - new Map([[0, { - ...serialized, - mean: new Float64Array(serialized.mean), - basis: new Float64Array(serialized.basis), - eigenvalues: new Float64Array(serialized.eigenvalues), - inverseScales: new Float64Array(serialized.inverseScales), - }]]), - new Map([[0, new Uint32Array([1, 0])]]), - 2, - ).get(0); - close(reordered.affineMap, [0, 1, 1, 0], 0); - }); - test("rolls back incomplete or cancelled captures before fitting", async () => { const incomplete = coordinatorHarness(BrowserFittingCoordinator); await assert.rejects( @@ -633,12 +517,6 @@ function identityWhitener(columns, firstMean = 0) { }; } -function mapAxes(value) { - return Object.fromEntries( - [...value].map(([layer, axes]) => [String(layer), [...axes]]), - ); -} - function close(actual, expected, tolerance) { assert.equal(actual.length, expected.length); actual.forEach((value, index) => { @@ -692,6 +570,8 @@ function affineFit(nodeCoordinates, components) { mean: new Float64Array(components), basis: Float64Array.from({ length: components * components }, (_, index) => index % (components + 1) === 0 ? 1 : 0), + read: Float64Array.from({ length: components * components }, (_, index) => + index % (components + 1) === 0 ? 1 : 0), nodeCoordinates: new Float64Array(nodeCoordinates), muCoordinates: new Float64Array(nodeCount * components), whitenedGram: new Float64Array(nodeCount * nodeCount), @@ -885,6 +765,7 @@ function coordinatorHarness(BrowserFittingCoordinator, options = {}) { centroidMean, mean: new Float64Array(columns), basis: new Float64Array([1, ...new Array(columns - 1).fill(0)]), + read: new Float64Array([1, ...new Array(columns - 1).fill(0)]), nodeCoordinates, muCoordinates, whitenedGram: new Float64Array(nodeCount * nodeCount).fill( diff --git a/webui/scripts/fitting-wasm-browser.test.mjs b/webui/scripts/fitting-wasm-browser.test.mjs index e9c2609..10bdfc2 100644 --- a/webui/scripts/fitting-wasm-browser.test.mjs +++ b/webui/scripts/fitting-wasm-browser.test.mjs @@ -2,31 +2,10 @@ import assert from "node:assert/strict"; import { readFile } from "node:fs/promises"; import init, { - MahalanobisWhitener, - RbfFitPlan, - fitAffineFisher, - fitMahalanobisWhitener, detectPeriodicTopology, selectTopologyFromTargets, } from "../public-hosted/wasm/drowse_fitting_wasm.js"; -const releaseEvidenceType = releaseEvidenceArgument(process.argv.slice(2)); -const observed = { - neutralCenteringMaxAbsoluteError: 0, - whiteningMaxAbsoluteError: 0, - pcaProjectionMaxError: 0, - spectralProjectionMaxError: 0, - rbfMaxAbsoluteError: 0, - geometryMaxAbsoluteError: 0, - maxEvaluatedOutputError: 0, -}; - -const fixture = JSON.parse(await readFile( - new URL("../../drowse/tests/fixtures/browser/affine-fisher-fit-v1.json", import.meta.url), -)); -const topologyFixture = JSON.parse(await readFile( - new URL("../../drowse/tests/fixtures/browser/topology-rbf-parity-v1.json", import.meta.url), -)); const wasm = await readFile(new URL( "../public-hosted/wasm/drowse_fitting_wasm_bg.wasm", import.meta.url, @@ -35,294 +14,6 @@ assert.doesNotMatch(wasm.toString("latin1"), /\/(?:Users|home)\/[^/\x00]+\//, "shipped WebAssembly must not embed personal home directories"); await init({ module_or_path: wasm }); -const neutral = new Float64Array(fixture.neutral); -const centroids = new Float64Array(fixture.centroids); -const whitener = fitMahalanobisWhitener( - neutral, - fixture.neutralRows, - fixture.columns, - fixture.ridgeScale, -); -try { - observed.neutralCenteringMaxAbsoluteError = maxAbsoluteDifference( - whitener.mean(), - fixture.expected.neutralMean, - ); - observed.whiteningMaxAbsoluteError = Math.max( - maxAbsoluteDifference(whitener.mean(), fixture.serializedWhitener.mean), - maxAbsoluteDifference(whitener.basis(), fixture.serializedWhitener.basis), - maxAbsoluteDifference( - whitener.eigenvalues(), - fixture.serializedWhitener.eigenvalues, - ), - maxAbsoluteDifference( - whitener.inverseScales(), - fixture.serializedWhitener.inverseScales, - ), - Math.abs(whitener.ridge - fixture.serializedWhitener.ridge), - ); - assert.ok(observed.neutralCenteringMaxAbsoluteError <= 1e-4); - assert.ok(observed.whiteningMaxAbsoluteError <= 1e-4); - const serialized = new MahalanobisWhitener( - whitener.columns, - whitener.rank, - whitener.mean(), - whitener.basis(), - whitener.eigenvalues(), - whitener.inverseScales(), - whitener.ridge, - ); - try { - const fit = fitAffineFisher( - centroids, - fixture.nodeCount, - fixture.columns, - serialized, - fixture.maxComponents, - fixture.orientTo, - ); - try { - assert.equal(fit.nodeCount, fixture.nodeCount); - assert.equal(fit.components, fixture.maxComponents); - close(fit.mean(), fixture.expected.mean, 3e-6); - close(fit.basis(), fixture.expected.basis, 3e-6); - close(fit.nodeCoordinates(), fixture.expected.nodeCoordinates, 5e-6); - close(fit.muCoordinates(), fixture.expected.muCoordinates, 5e-6); - close(fit.whitenedGram(), fixture.expected.whitenedGram, 5e-5); - close(fit.neutralCrossGram(), fixture.expected.neutralCrossGram, 5e-6); - observed.pcaProjectionMaxError = Math.max( - maxAbsoluteDifference(fit.mean(), fixture.expected.mean), - maxAbsoluteDifference(fit.basis(), fixture.expected.basis), - maxAbsoluteDifference( - fit.nodeCoordinates(), - fixture.expected.nodeCoordinates, - ), - maxAbsoluteDifference(fit.muCoordinates(), fixture.expected.muCoordinates), - ); - observed.geometryMaxAbsoluteError = Math.max( - maxAbsoluteDifference(fit.whitenedGram(), fixture.expected.whitenedGram), - maxAbsoluteDifference( - fit.neutralCrossGram(), - fixture.expected.neutralCrossGram, - ), - ); - close( - [fit.explainedVariance, fit.mahalanobisShare], - [fixture.expected.explainedVariance, fixture.expected.mahalanobisShare], - 5e-6, - ); - const muCoordinates = fit.muCoordinates(); - const scalarTarget = new Float64Array(fit.nodeCount); - for (let node = 0; node < fit.nodeCount; node += 1) { - scalarTarget[node] = muCoordinates[node * fit.components]; - } - const targets = new Float64Array(muCoordinates.length + scalarTarget.length); - targets.set(muCoordinates); - targets.set(scalarTarget, muCoordinates.length); - const topology = selectTopologyFromTargets( - fit.whitenedGram(), - fit.nodeCount, - targets, - new Uint32Array([0, muCoordinates.length, targets.length]), - 2, - 0.7, - "auto", - undefined, - undefined, - undefined, - 0.5, - ); - try { - assert.equal(topology.winnerName, "flat-pca"); - assert.equal(topology.diagnosticsKind, "pca"); - assert.equal(topology.diagnosticsPickedDimensions, topology.intrinsicDimensions); - assert.equal(topology.diagnosticsThreshold, 0.7); - const variance = topology.diagnosticsPerComponentVariance(); - const cumulative = topology.diagnosticsCumulativeVariance(); - assert.equal(variance.length, 2); - assert.equal(cumulative.length, variance.length); - close(cumulative, [variance[0], variance[0] + variance[1]], 5e-8); - } finally { - topology.free(); - } - const forcedPca = selectTopologyFromTargets( - fit.whitenedGram(), - fit.nodeCount, - targets, - new Uint32Array([0, muCoordinates.length, targets.length]), - 2, - 0.7, - "pca", - undefined, - undefined, - undefined, - 0.5, - ); - try { - assert.equal(forcedPca.winnerName, "flat-pca"); - assert.equal(forcedPca.fitMode, "pca"); - } finally { - forcedPca.free(); - } - } finally { - fit.free(); - } - } finally { - serialized.free(); - } -} finally { - whitener.free(); -} - -const nodeCount = topologyFixture.nodeCount; -const curveTargets = new Float64Array(topologyFixture.targets); -const curveSelection = topologyFixture.selection; -const curveExpected = topologyFixture.expected; -const curveGram = centeredGram( - curveTargets, - nodeCount, - topologyFixture.outputDimensions, -); -const curved = selectTopologyFromTargets( - curveGram, - nodeCount, - curveTargets, - new Uint32Array([0, curveTargets.length]), - curveSelection.maxDimensions, - curveSelection.varianceThreshold, - curveSelection.fitMode, - curveSelection.minDimensions, - undefined, - undefined, - curveSelection.persistenceFraction, - curveSelection.smoothing, -); -try { - assert.equal(curved.winnerName, curveExpected.winnerName); - assert.equal(curved.intrinsicDimensions, curveExpected.intrinsicDimensions); - assert.equal(curved.diagnosticsKind, "spectral"); - assert.equal(curved.diagnosticsPickedDimensions, curved.intrinsicDimensions); - assert.equal(curved.diagnosticsKNn, curveExpected.kNN); - assert.equal(curved.diagnosticsMinDimensions, curveSelection.minDimensions); - assert.equal(curved.diagnosticsPinned, false); - close( - curved.diagnosticsEigenvalues(), - curveExpected.eigenvalues, - 2e-6, - ); - assert.ok( - Math.abs(curved.diagnosticsBandwidth - curveExpected.bandwidth) <= 2e-6, - ); - assert.ok( - Math.abs(curved.diagnosticsGapMagnitude - curveExpected.gapMagnitude) <= 2e-6, - ); - const coordinates = curved.coordinates(); - observed.spectralProjectionMaxError = projectionMaxError( - coordinates, - curveExpected.coordinates, - nodeCount, - curved.intrinsicDimensions, - ); - assert.ok(observed.spectralProjectionMaxError <= 2e-6); - for (const pair of curveExpected.pairDistances) { - assert.ok( - Math.abs( - coordinateDistance( - coordinates, - pair.left, - pair.right, - curved.intrinsicDimensions, - ) - pair.distance - ) <= 2e-6, - ); - } - - const winnerPlan = curved.winnerPlan(); - assert.ok(winnerPlan); - try { - const restoredPlan = new RbfFitPlan( - winnerPlan.inputDimensions, - winnerPlan.nodeCount, - winnerPlan.nodes(), - winnerPlan.coordinateOffset(), - winnerPlan.coordinateScale(), - winnerPlan.kernel(), - winnerPlan.kernelScale, - winnerPlan.lambdas(), - winnerPlan.spectralBasis(), - winnerPlan.residualRatios(), - winnerPlan.residualTraces(), - ); - try { - for (const [values, outputDimensions, pythonExpected] of [ - [curveTargets, topologyFixture.outputDimensions, curveExpected.evaluatedTargets], - [Float64Array.from({ length: nodeCount }, (_, row) => curveTargets[2 * row]), 1], - ]) { - const original = winnerPlan.fitSmoothed( - values, - outputDimensions, - curveSelection.smoothing, - ); - const restored = restoredPlan.fitSmoothed( - values, - outputDimensions, - curveSelection.smoothing, - ); - try { - assert.equal(original.outputDimensions, outputDimensions); - const restoredValues = restored.evaluate( - curved.embeddedCoordinates(), - nodeCount, - ); - const originalValues = original.evaluate( - curved.embeddedCoordinates(), - nodeCount, - ); - const restorationError = maxAbsoluteDifference( - restoredValues, - originalValues, - ); - if (pythonExpected !== undefined) { - const parityError = maxAbsoluteDifference( - originalValues, - pythonExpected, - ); - observed.rbfMaxAbsoluteError = Math.max( - observed.rbfMaxAbsoluteError, - parityError, - ); - observed.maxEvaluatedOutputError = Math.max( - observed.maxEvaluatedOutputError, - parityError, - ); - assert.ok(parityError <= 2e-6); - assert.ok( - Math.abs(original.lambda - curveExpected.lambda) <= 2e-6, - ); - assert.ok( - Math.abs( - original.effectiveDegreesOfFreedom - - curveExpected.effectiveDegreesOfFreedom - ) <= 2e-5, - ); - } - assert.ok(restorationError <= 1e-12); - close(restoredValues, originalValues, 1e-12); - } finally { - original.free(); - restored.free(); - } - } - } finally { - restoredPlan.free(); - } - } finally { - winnerPlan.free(); - } -} finally { - curved.free(); -} - const automaticCurveTargets = new Float64Array(40 * 3); for (let index = 0; index < 40; index += 1) { const t = index / 39; @@ -418,102 +109,7 @@ try { unsupportedPeriodicFit.free(); } -if (releaseEvidenceType === null) { - console.log("browser fitting WASM goldens passed"); -} else { - const results = releaseEvidenceType === "fittingKernelParity" - ? { - neutralCenteringMaxAbsoluteError: - observed.neutralCenteringMaxAbsoluteError, - whiteningMaxAbsoluteError: observed.whiteningMaxAbsoluteError, - pcaProjectionMaxError: observed.pcaProjectionMaxError, - spectralProjectionMaxError: observed.spectralProjectionMaxError, - rbfMaxAbsoluteError: observed.rbfMaxAbsoluteError, - geometryMaxAbsoluteError: observed.geometryMaxAbsoluteError, - finiteOutputsPassed: Object.values(observed).every(Number.isFinite), - } - : { - flatSelectionPassed: true, - curvedSelectionPassed: true, - periodicSelectionPassed: true, - automaticSelectionPassed: true, - maxEvaluatedOutputError: observed.maxEvaluatedOutputError, - }; - process.stdout.write(`${JSON.stringify({ - schemaVersion: 1, - evidenceType: releaseEvidenceType, - producedAt: new Date().toISOString(), - passed: true, - fixturePath: releaseEvidenceType === "fittingKernelParity" - ? "drowse/tests/fixtures/browser/affine-fisher-fit-v1.json" - : "drowse/tests/fixtures/browser/topology-rbf-parity-v1.json", - results, - })}\n`); -} - -function close(actual, expected, tolerance) { - assert.equal(actual.length, expected.length); - for (let index = 0; index < actual.length; index += 1) { - assert.ok( - Math.abs(actual[index] - expected[index]) <= tolerance, - `${index}: ${actual[index]} != ${expected[index]} within ${tolerance}`, - ); - } -} - -function maxAbsoluteDifference(actual, expected) { - assert.equal(actual.length, expected.length); - let maximum = 0; - for (let index = 0; index < actual.length; index += 1) { - maximum = Math.max(maximum, Math.abs(actual[index] - expected[index])); - } - return maximum; -} - -function projectionMaxError(actual, expected, rows, dimensions) { - let maximum = 0; - for (let left = 0; left < rows; left += 1) { - for (let right = 0; right < rows; right += 1) { - let actualDot = 0; - let expectedDot = 0; - for (let dimension = 0; dimension < dimensions; dimension += 1) { - actualDot += - actual[left * dimensions + dimension] * - actual[right * dimensions + dimension]; - expectedDot += - expected[left * dimensions + dimension] * - expected[right * dimensions + dimension]; - } - maximum = Math.max(maximum, Math.abs(actualDot - expectedDot)); - } - } - return maximum; -} - -function coordinateDistance(values, left, right, dimensions) { - let squared = 0; - for (let dimension = 0; dimension < dimensions; dimension += 1) { - const delta = - values[left * dimensions + dimension] - - values[right * dimensions + dimension]; - squared += delta * delta; - } - return Math.sqrt(squared); -} - -function releaseEvidenceArgument(args) { - if (args.length === 0) return null; - if ( - args.length !== 2 || - args[0] !== "--release-evidence" || - !["fittingKernelParity", "topologyOrchestration"].includes(args[1]) - ) { - throw new Error( - "usage: fitting-wasm-browser.test.mjs [--release-evidence fittingKernelParity|topologyOrchestration]", - ); - } - return args[1]; -} +console.log("browser fitting WASM topology checks passed"); function centeredGram(values, rows, columns) { const means = new Float64Array(columns); diff --git a/webui/scripts/fork-overlays.test.mjs b/webui/scripts/fork-overlays.test.mjs index b703d5d..39a0a76 100644 --- a/webui/scripts/fork-overlays.test.mjs +++ b/webui/scripts/fork-overlays.test.mjs @@ -30,8 +30,8 @@ assert.deepEqual(parseArguments(["mlc-llm-drowse", "/tmp/repo"]), { repository: "/tmp/repo", }); assert.equal(manifest.overlays.length, 3); -assert.equal(manifest.hookAbi, "block-sites-v5"); -assert.equal(manifest.structuredHookProfile, "standard-v4"); +assert.equal(manifest.hookAbi, "block-sites-v6"); +assert.equal(manifest.structuredHookProfile, "standard-v5"); assert.equal(manifest.exactReadoutAbi, "exact-readout-v2"); assert.ok( webLlmPatch.includes('"drowse_sae_jump_relu_readout_accumulate"'), diff --git a/webui/scripts/hook-capabilities.test.mjs b/webui/scripts/hook-capabilities.test.mjs index 0a38607..baf2972 100644 --- a/webui/scripts/hook-capabilities.test.mjs +++ b/webui/scripts/hook-capabilities.test.mjs @@ -139,8 +139,8 @@ try { ]) { assert.doesNotThrow(() => assertHookFeaturesSupported(expression, structured), expression); } - // units and slens follow the library's block-sites profile: standard-v4 offers both, - // standard-v4-residual and a pre-v5 library neither. + // units and slens follow the library's block-sites profile: standard-v5 offers both, + // standard-v5-residual and a pre-v5 library neither. const { blockSitesHookCapabilities } = hookCapabilities; const v4 = blockSitesHookCapabilities(structured, { profile: { unitSites: 1 } }); assert.equal(v4.units, true); diff --git a/webui/scripts/hosted-catalog-location.mjs b/webui/scripts/hosted-catalog-location.mjs index f972bde..14eaced 100644 --- a/webui/scripts/hosted-catalog-location.mjs +++ b/webui/scripts/hosted-catalog-location.mjs @@ -1,14 +1,15 @@ // Where the hosted catalog is published. Each browser runtime generation publishes its signed // catalog at its own directory of the catalog repository, so publishing a new catalog never // changes what an already deployed build reads: runtime v1 builds read the root `catalog.json` -// (sequences up to 10), runtime v2 builds (hook ABI v5) read `v2/catalog.json` (from 11). The +// (sequences up to 10), runtime v2 builds (hook ABI v5) read `v2/catalog.json` (11), runtime v3 +// builds (hook ABI v6, typed frames) read `v3/catalog.json` (from 12). The // distribution lock names the newest directory; the publisher's first catalog at a new directory // must advance the sequence the previous one published. export const CATALOG_REPOSITORY = "stdlogits/drowse-web-catalog"; /** Every directory the catalog has been published at, oldest first. */ -export const CATALOG_DIRECTORIES = Object.freeze(["", "v2/"]); +export const CATALOG_DIRECTORIES = Object.freeze(["", "v2/", "v3/"]); export function catalogUrls(directory, repository = CATALOG_REPOSITORY) { const base = `https://huggingface.co/${repository}/resolve/main/${directory}`; diff --git a/webui/scripts/hosted-full-runtime.worker.ts b/webui/scripts/hosted-full-runtime.worker.ts index 098475f..86f58bb 100644 --- a/webui/scripts/hosted-full-runtime.worker.ts +++ b/webui/scripts/hosted-full-runtime.worker.ts @@ -54,7 +54,7 @@ interface RunRequest { modelId: string; runtimeIdentity: RuntimeIdentity; structuredHookProfile: ModelVariant["structuredHookProfile"]; - /** The runtime lock's block spec (standard-v4) and unit refusal (standard-v4-residual). */ + /** The runtime lock's block spec (standard-v5) and unit refusal (standard-v5-residual). */ blockSpec: BlockSpec | null; unitRefusal: string | null; prefillChunkSize: number; @@ -65,7 +65,7 @@ interface RunRequest { contextProfiles: number[]; modelFiles: FileEntry[]; coreFiles: FileEntry[]; - /** Each optional pack's closure; empty when the run has no such pack. A standard-v4 library + /** Each optional pack's closure; empty when the run has no such pack. A standard-v5 library * runs with its R (`jlens`), S (`slens`) and units packs, a residual one with no S or units * pack; SAE is optional on both. */ jlensFiles: FileEntry[]; @@ -151,11 +151,11 @@ self.onmessage = async (event: MessageEvent) => { } as const; try { if ( - event.data.structuredHookProfile !== "standard-v4" && - event.data.structuredHookProfile !== "standard-v4-residual" + event.data.structuredHookProfile !== "standard-v5" && + event.data.structuredHookProfile !== "standard-v5-residual" ) { throw new Error( - `real-browser instruments require a v5 library (standard-v4 or standard-v4-residual, ${BLOCK_SITES_EXACT_READOUT_ABI})`, + `real-browser instruments require a v5 library (standard-v5 or standard-v5-residual, ${BLOCK_SITES_EXACT_READOUT_ABI})`, ); } const webLlmUrl = "/webllm.js"; @@ -233,7 +233,7 @@ self.onmessage = async (event: MessageEvent) => { }; }); currentCheck = "load"; - const unitsProfile = event.data.structuredHookProfile === "standard-v4"; + const unitsProfile = event.data.structuredHookProfile === "standard-v5"; const packFiles: Record = { jlens: event.data.jlensFiles, slens: event.data.slensFiles, @@ -244,8 +244,8 @@ self.onmessage = async (event: MessageEvent) => { if (unitsProfile ? !(has("jlens") && has("slens") && has("units")) : has("slens") || has("units")) { throw new Error( unitsProfile - ? "a standard-v4 library runs with its R, S and units packs" - : "a standard-v4-residual library has no S lens or units pack", + ? "a standard-v5 library runs with its R, S and units packs" + : "a standard-v5-residual library has no S lens or units pack", ); } const presentKinds = PACK_KINDS.filter(has); @@ -1175,7 +1175,7 @@ self.onmessage = async (event: MessageEvent) => { }); // The block sites' own members (B1 §2-§5): an ablation, the unit taps, one anatomy replay, - // one static read and the S readout on standard-v4; on standard-v4-residual every unit member + // one static read and the S readout on standard-v5; on standard-v5-residual every unit member // answers the lock's refusal. let topUnit: string | null = null; if (unitsProfile) { @@ -1334,7 +1334,7 @@ self.onmessage = async (event: MessageEvent) => { currentCheck = "unit_refusal"; const refusal = event.data.unitRefusal; if (typeof refusal !== "string" || !refusal) { - throw new Error("a standard-v4-residual run needs the lock's unitRefusal"); + throw new Error("a standard-v5-residual run needs the lock's unitRefusal"); } const refused: string[] = []; for (const [method, args] of [ @@ -1629,7 +1629,7 @@ self.onmessage = async (event: MessageEvent) => { const offlineSlensReading = unitsProfile ? offlineMeasurements?.instruments?.lens?.readings?.browser_e2e_slens_offline?.value : null; - // On standard-v4 a static unit read offline: its lens and units layers come from OPFS. + // On standard-v5 a static unit read offline: its lens and units layers come from OPFS. let offlineUnitRead: string | null = null; if (unitsProfile) { const unit = topUnit ?? `neuron/L${Math.floor(event.data.runtimeIdentity.layerMap.length / 2)}n0`; @@ -1960,7 +1960,7 @@ async function setLive( * app's backend keeps it (drowseWebLlmBackend.ts `blockSites`). */ const blockSitesSurfaces = new WeakMap(); const predatesBlockSites = rejectingBlockSitesBackend( - () => new UnsupportedBlockError("the loaded model library predates hook ABI block-sites-v5"), + () => new UnsupportedBlockError("the loaded model library predates hook ABI block-sites-v6"), ); function blockSitesFor(loaded: DrowseWebLlmRuntime): BrowserBlockSitesBackend { const capabilities = loaded.blockSitesCapabilities(); diff --git a/webui/scripts/hosted-instrument-pack-tool.test.mjs b/webui/scripts/hosted-instrument-pack-tool.test.mjs index 7a1e246..4c7a943 100644 --- a/webui/scripts/hosted-instrument-pack-tool.test.mjs +++ b/webui/scripts/hosted-instrument-pack-tool.test.mjs @@ -67,7 +67,7 @@ try { runtimeWorker.code.includes("thinkingProfile: event.data.thinkingProfile"), ); assert.ok(runtimeWorker.code.includes("setSaeDictionary")); - assert.ok(runtimeWorker.code.includes("standard-v4 or standard-v4-residual")); + assert.ok(runtimeWorker.code.includes("standard-v5 or standard-v5-residual")); assert.ok( runtimeWorker.code.includes("exact full-vocabulary R-lens readout"), ); diff --git a/webui/scripts/hosted-instrument-runtime.worker.ts b/webui/scripts/hosted-instrument-runtime.worker.ts index c4191ff..38190b8 100644 --- a/webui/scripts/hosted-instrument-runtime.worker.ts +++ b/webui/scripts/hosted-instrument-runtime.worker.ts @@ -31,7 +31,7 @@ interface Request { modelId: string; runtimeIdentity: RuntimeIdentity; structuredHookProfile: ModelVariant["structuredHookProfile"]; - /** The runtime lock's block spec (standard-v4) and unit refusal (standard-v4-residual). */ + /** The runtime lock's block spec (standard-v5) and unit refusal (standard-v5-residual). */ blockSpec: BlockSpec | null; unitRefusal: string | null; prefillChunkSize: number; @@ -62,11 +62,11 @@ self.onmessage = async (event: MessageEvent) => { let runtime: DrowseWebLlmRuntime | null = null; try { if ( - event.data.structuredHookProfile !== "standard-v4" && - event.data.structuredHookProfile !== "standard-v4-residual" + event.data.structuredHookProfile !== "standard-v5" && + event.data.structuredHookProfile !== "standard-v5-residual" ) { throw new Error( - `physical precomputed instruments require a v5 library (standard-v4 or standard-v4-residual, ${BLOCK_SITES_EXACT_READOUT_ABI})`, + `physical precomputed instruments require a v5 library (standard-v5 or standard-v5-residual, ${BLOCK_SITES_EXACT_READOUT_ABI})`, ); } if ( diff --git a/webui/scripts/hosted-model-profiles.mjs b/webui/scripts/hosted-model-profiles.mjs index aea41b5..fdd0976 100644 --- a/webui/scripts/hosted-model-profiles.mjs +++ b/webui/scripts/hosted-model-profiles.mjs @@ -2,10 +2,10 @@ import { structuredHookProfileForArchitecture } from "./overlay-vm-functions.mjs // Hook ABI v5's two capacity profiles (HOOK_ABI.md §3): units on the dense gated architectures, // residual elsewhere. Which one an architecture attests is the overlay's own rule. -const structuredHookProfiles = new Set(["standard-v4", "standard-v4-residual"]); +const structuredHookProfiles = new Set(["standard-v5", "standard-v5-residual"]); -export const HOOK_ABI = "block-sites-v5"; -export const RUNTIME_ABI = "drowse-web-runtime-v2"; +export const HOOK_ABI = "block-sites-v6"; +export const RUNTIME_ABI = "drowse-web-runtime-v3"; export const EXACT_READOUT_ABI = "exact-readout-v2"; export function structuredHookProfile(value) { @@ -90,7 +90,7 @@ export function lockedModelExecutionProfiles(lock, manifest) { quantization, requiredFeatures: quantization === "q4f16_1" ? ["shader-f16"] : [], // What the runtime attests a v5 library's descriptor against (HOOK_ABI.md §6): the block - // spec of a standard-v4 library, the refusal text of a standard-v4-residual one, and the + // spec of a standard-v5 library, the refusal text of a standard-v5-residual one, and the // prefill chunk it was compiled with. blockSpec, unitRefusal, @@ -101,8 +101,8 @@ export function lockedModelExecutionProfiles(lock, manifest) { function lockedBlockSites(lock, profile) { const blockSpec = lock?.blockSpec ?? null; const unitRefusal = lock?.unitRefusal ?? null; - const units = profile === "standard-v4"; - const residual = profile === "standard-v4-residual"; + const units = profile === "standard-v5"; + const residual = profile === "standard-v5-residual"; if ( units !== (blockSpec !== null) || residual !== (unitRefusal !== null) || (blockSpec !== null && (typeof blockSpec !== "object" || Array.isArray(blockSpec))) || diff --git a/webui/scripts/hosted-pack-residency.test.mjs b/webui/scripts/hosted-pack-residency.test.mjs index c150c08..5b12229 100644 --- a/webui/scripts/hosted-pack-residency.test.mjs +++ b/webui/scripts/hosted-pack-residency.test.mjs @@ -91,7 +91,7 @@ try { const variant = { id: "fixture-q0f32", runtimeIdentitySha256: "e".repeat(64), - runtimeIdentity: { layerMap, hiddenSize: d, sourceRevision: "f".repeat(40), runtimeAbi: "drowse-web-runtime-v2" }, + runtimeIdentity: { layerMap, hiddenSize: d, sourceRevision: "f".repeat(40), runtimeAbi: "drowse-web-runtime-v3" }, }; const manifest = { format_version: 7, kind: "R", sites: { out: site("out", [0, 1, 2, 3]), mid: site("mid", layerMap) }, diff --git a/webui/scripts/hosted-policy.test.mjs b/webui/scripts/hosted-policy.test.mjs index 7ea87c2..e9fcc3f 100644 --- a/webui/scripts/hosted-policy.test.mjs +++ b/webui/scripts/hosted-policy.test.mjs @@ -91,7 +91,7 @@ function model(id, language = "en") { variants: [{ id: `variant-${id}`, tier: "balanced", - structuredHookProfile: "standard-v4", + structuredHookProfile: "standard-v5", contextProfiles: [{ contextTokens: 2048, bindingSha256: "b".repeat(64), @@ -325,7 +325,7 @@ try { modelBackendIntegrated: false, }), false); assert.equal( - capabilityModule.structuredHookProfilesSupportSubspaceTrails(["standard-v4", "standard-v4-residual"]), + capabilityModule.structuredHookProfilesSupportSubspaceTrails(["standard-v5", "standard-v5-residual"]), true, ); assert.equal( diff --git a/webui/scripts/hosted-residual-capture-units.mjs b/webui/scripts/hosted-residual-capture-units.mjs index f98cb77..59df4c8 100644 --- a/webui/scripts/hosted-residual-capture-units.mjs +++ b/webui/scripts/hosted-residual-capture-units.mjs @@ -1,7 +1,7 @@ // Capture schema 5's `units` member (browser-runtime/README.md, "production-q4 comparator"): on a -// `standard-v4` library the block sites (`sites.f32`, fp32 `[layers, positions, d_ff + H·hd + d]`, +// `standard-v5` library the block sites (`sites.f32`, fp32 `[layers, positions, d_ff + H·hd + d]`, // act | z | mid) and 1-64 neuron-write static reads, at least one at every captured layer; on a -// `standard-v4-residual` library no member. `q4_unit_parity.py` reads what this writes. +// `standard-v5-residual` library no member. `q4_unit_parity.py` reads what this writes. import { createHash } from "node:crypto"; export const CAPTURE_SCHEMA_VERSION = 5; @@ -10,16 +10,16 @@ export const MAXIMUM_STATIC_READS = 64; /** What is wrong with a worker's units result against the lock and the capture input. */ export function unitsCaptureFailures({ structuredHookProfile, units, sitesBytes, lock, positions }) { - if (structuredHookProfile === "standard-v4-residual") { + if (structuredHookProfile === "standard-v5-residual") { return units === undefined && sitesBytes === undefined ? [] - : ["a standard-v4-residual capture carries no block sites or static reads"]; + : ["a standard-v5-residual capture carries no block sites or static reads"]; } - if (structuredHookProfile !== "standard-v4") { + if (structuredHookProfile !== "standard-v5") { return [`structured hook profile ${String(structuredHookProfile)} predates capture schema 5`]; } const failures = []; - if (!isRecord(units)) return ["a standard-v4 capture's units result is missing"]; + if (!isRecord(units)) return ["a standard-v5 capture's units result is missing"]; const spec = lock.blockSpec; const block = units.block; if ( @@ -49,7 +49,7 @@ export function unitsCaptureFailures({ structuredHookProfile, units, sitesBytes, } const reads = units.staticReads; if (!Array.isArray(reads) || reads.length < 1 || reads.length > MAXIMUM_STATIC_READS) { - failures.push(`a standard-v4 capture needs 1 to ${MAXIMUM_STATIC_READS} static reads`); + failures.push(`a standard-v5 capture needs 1 to ${MAXIMUM_STATIC_READS} static reads`); return failures; } const seen = new Set(); @@ -79,7 +79,7 @@ export function unitsCaptureFailures({ structuredHookProfile, units, sitesBytes, return failures; } -/** `capture.json`'s `units` member for a checked standard-v4 result (`q4_unit_parity.py` +/** `capture.json`'s `units` member for a checked standard-v5 result (`q4_unit_parity.py` * `validate_units_member`). */ export function captureUnitsMember(units) { return { diff --git a/webui/scripts/hosted-residual-capture.worker.ts b/webui/scripts/hosted-residual-capture.worker.ts index d27dc81..893c30c 100644 --- a/webui/scripts/hosted-residual-capture.worker.ts +++ b/webui/scripts/hosted-residual-capture.worker.ts @@ -24,7 +24,7 @@ interface CaptureRequest { artifacts: Array<{ path: string; role: string; bytes: number; sha256: string }>; runtimeIdentity: RuntimeIdentity; structuredHookProfile: ModelVariant["structuredHookProfile"]; - /** The runtime lock's block spec (standard-v4) and unit refusal (standard-v4-residual). */ + /** The runtime lock's block spec (standard-v5) and unit refusal (standard-v5-residual). */ blockSpec: BlockSpec | null; unitRefusal: string | null; prefillChunkSize: number; @@ -167,7 +167,7 @@ self.onmessage = async (event: MessageEvent) => { : (await runtime.prepareCaptureRows([event.data.namedRoleCheck.row]))[0]; // B1 §4.3 item 2 on a units library: the block sites at every captured layer and position, // and neuron-write static reads; a residual library has neither. - const units = event.data.structuredHookProfile === "standard-v4" + const units = event.data.structuredHookProfile === "standard-v5" ? await captureUnits(runtime, event.data.inputIds, event.data.positions, event.data.runtimeIdentity.layerMap) : null; const bytes = new Uint8Array( @@ -257,7 +257,7 @@ async function captureUnits( ) { const capabilities = runtime.blockSitesCapabilities(); if (capabilities === null || capabilities.blockSpec === null) { - throw new Error("a standard-v4 capture needs the library's attested unit sites"); + throw new Error("a standard-v5 capture needs the library's attested unit sites"); } const backend = webLlmBlockSitesBackend(capabilities, runtime.blockSitesDevice()); const spec = capabilities.blockSpec; diff --git a/webui/scripts/hosted-sae-capture.worker.ts b/webui/scripts/hosted-sae-capture.worker.ts index 197516b..950b649 100644 --- a/webui/scripts/hosted-sae-capture.worker.ts +++ b/webui/scripts/hosted-sae-capture.worker.ts @@ -21,7 +21,7 @@ interface CaptureRequest { artifacts: ArtifactEntry[]; runtimeIdentity: RuntimeIdentity; structuredHookProfile: ModelVariant["structuredHookProfile"]; - /** The runtime lock's block spec (standard-v4) and unit refusal (standard-v4-residual). */ + /** The runtime lock's block spec (standard-v5) and unit refusal (standard-v5-residual). */ blockSpec: BlockSpec | null; unitRefusal: string | null; prefillChunkSize: number; diff --git a/webui/scripts/hosted-tools.test.mjs b/webui/scripts/hosted-tools.test.mjs index bb43510..2c014e5 100644 --- a/webui/scripts/hosted-tools.test.mjs +++ b/webui/scripts/hosted-tools.test.mjs @@ -61,11 +61,11 @@ const dir = await mkdtemp(join(tmpdir(), "drowse-catalog-test-")); assert.throws(() => validateRuntimeLock({ ...lock, hookAbi: "post-block-residual-v4" }), /unsupported schema or ABI/); assert.throws( () => validateRuntimeLock(withModel("qwen3-1.7b", (model) => { - model.structuredHookProfile = "standard-v4-residual"; + model.structuredHookProfile = "standard-v5-residual"; delete model.blockSpec; model.unitRefusal = "refused"; })), - /qwen3 libraries attest standard-v4, not standard-v4-residual/, + /qwen3 libraries attest standard-v5, not standard-v5-residual/, ); assert.throws( () => validateRuntimeLock(withModel("pythia-70m-base", (model) => { model.unitRefusal = ""; })), diff --git a/webui/scripts/hosted-whitener-tool.test.mjs b/webui/scripts/hosted-whitener-tool.test.mjs index 60ce09b..001f9d1 100644 --- a/webui/scripts/hosted-whitener-tool.test.mjs +++ b/webui/scripts/hosted-whitener-tool.test.mjs @@ -26,7 +26,7 @@ const executionProfiles = lockedModelExecutionProfiles(qwen4b, { quantization: qwen4b.quantization, }); assert.deepEqual(executionProfiles, { - structuredHookProfile: "standard-v4", + structuredHookProfile: "standard-v5", thinkingProfile: qwen4b.thinkingProfile, quantization: "q4f32_1", requiredFeatures: [], @@ -44,20 +44,20 @@ assert.throws( () => lockedModelExecutionProfiles(qwen4b, { ...executionProfiles, prefillChunkSize: 1024 }), /prefill chunk does not match/, ); -// A v5 library: the block spec travels with standard-v4, the refusal with -residual. +// A v5 library: the block spec travels with standard-v5, the refusal with -residual. const blockSpec = { dFF: 9728, nHeads: 32 }; const { blockSpec: _lockedSpec, unitRefusal: _lockedRefusal, ...bareQwen4b } = qwen4b; const v5 = (profile, extra) => lockedModelExecutionProfiles( { ...bareQwen4b, structuredHookProfile: profile, ...extra }, { structuredHookProfile: profile, thinkingProfile: qwen4b.thinkingProfile, quantization: qwen4b.quantization }, ); -assert.deepEqual(v5("standard-v4", { blockSpec }).blockSpec, blockSpec); -assert.equal(v5("standard-v4-residual", { unitRefusal: "fused qkv" }).unitRefusal, "fused qkv"); +assert.deepEqual(v5("standard-v5", { blockSpec }).blockSpec, blockSpec); +assert.equal(v5("standard-v5-residual", { unitRefusal: "fused qkv" }).unitRefusal, "fused qkv"); for (const [profile, extra] of [ - ["standard-v4", {}], - ["standard-v4", { blockSpec, unitRefusal: "fused qkv" }], - ["standard-v4-residual", {}], - ["standard-v4-residual", { blockSpec, unitRefusal: "fused qkv" }], + ["standard-v5", {}], + ["standard-v5", { blockSpec, unitRefusal: "fused qkv" }], + ["standard-v5-residual", {}], + ["standard-v5-residual", { blockSpec, unitRefusal: "fused qkv" }], ]) { assert.throws(() => v5(profile, extra), /blockSpec and unitRefusal/, `${profile} ${JSON.stringify(extra)}`); } @@ -65,7 +65,7 @@ for (const [profile, extra] of [ assert.throws(() => v5("unknown-profile", { blockSpec }), /structuredHookProfile is not allow-listed/); assert.throws( () => lockedModelExecutionProfiles(qwen4b, { - structuredHookProfile: "standard-v4-residual", + structuredHookProfile: "standard-v5-residual", thinkingProfile: qwen4b.thinkingProfile, quantization: qwen4b.quantization, }), @@ -112,7 +112,7 @@ const loaded = await exec(python, [ "from pathlib import Path", "from drowse.store.manifold_folder import ManifoldFolder", "folder = ManifoldFolder.load(Path(sys.argv[1]))", - "print(json.dumps({'name': folder.name, 'fit_mode': folder.fit_mode, 'nodes': folder.node_labels, 'groups': [len(rows) for _, rows in folder.node_groups()], 'files': folder.files}))", + "print(json.dumps({'name': folder.name, 'fit_mode': folder.fit_mode, 'nodes': folder.node_labels, 'groups': [len(rows) for _, rows in folder.node_groups()]}))", ].join("; "), seedSource, ], { cwd: repositoryRoot, env: { ...process.env, PYTHONPATH: resolve(repositoryRoot, "drowse") } }); @@ -121,7 +121,6 @@ assert.deepEqual(JSON.parse(loaded.stdout), { fit_mode: "pca", nodes: ["welcoming", "detached"], groups: [48, 48], - files: {}, }); assert.throws( () => lockedModelExecutionProfiles(qwen4b, { @@ -221,7 +220,7 @@ try { "w = LayerWhitener.from_neutral_activations(rows, means)", "d = {L: torch.tensor(c, dtype=torch.float32) - means[L] for L, c in enumerate(x['concept'])}", "m = fold_directions_to_subspace('c', d, means, whitener=w, label='c')", - "print(json.dumps({str(L): {'basis': s.basis.reshape(-1).tolist(), 'mean': s.mean.tolist(), 'coord': float(s.node_coords.reshape(-1)[0]), 'share': m.mahalanobis_share[L]} for L, s in m.layers.items()}))", + "print(json.dumps({str(L): {'basis': s.basis.reshape(-1).tolist(), 'read': s.read.reshape(-1).tolist(), 'mean': s.mean.tolist(), 'coord': float(s.node_coords.reshape(-1)[0]), 'share': m.mahalanobis_share[L]} for L, s in m.layers.items()}))", ].join("\n"), join(scratch, "inputs.json")], { cwd: repositoryRoot, env: { ...process.env, PYTHONPATH: resolve(repositoryRoot, "drowse") }, @@ -235,6 +234,7 @@ try { const ours = foundation.finalAffineLayers.get(layer); const theirs = reference[String(layer)]; close(ours.basis, theirs.basis, `L${layer} basis`); + close(ours.read, theirs.read, `L${layer} read`); close(ours.mean, theirs.mean, `L${layer} mean`); close(ours.nodeCoordinates, [theirs.coord], `L${layer} pole`); close([ours.mahalanobisShare], [theirs.share], `L${layer} share`); @@ -291,6 +291,7 @@ try { centroidMean: new Float64Array(2), mean: new Float64Array(2), basis: new Float64Array([1, 0]), + read: new Float64Array([1, 0]), nodeCoordinates: new Float64Array([-1, 1]), muCoordinates: new Float64Array([-1, 1]), whitenedGram: new Float64Array([1, -1, -1, 1]), diff --git a/webui/scripts/hosted-whitener.worker.ts b/webui/scripts/hosted-whitener.worker.ts index e278b25..9907d91 100644 --- a/webui/scripts/hosted-whitener.worker.ts +++ b/webui/scripts/hosted-whitener.worker.ts @@ -10,6 +10,7 @@ import { import { BrowserActivationSpool } from "../src/hosted/fitting/activationSpool"; import { BrowserFittingCoordinator, + FIT_POLICY_VERSION, type BrowserFittingCoordinatorProgress, } from "../src/hosted/fitting/coordinator"; import { monopolarFoundation } from "../src/hosted/fitting/monopolar"; @@ -55,7 +56,7 @@ interface BuildRequest { quantization: "q4f16_1" | "q4f32_1" | "q0f32"; requiredFeatures: GPUFeatureName[]; structuredHookProfile: ModelVariant["structuredHookProfile"]; - /** The runtime lock's block spec (standard-v4) and unit refusal (standard-v4-residual). */ + /** The runtime lock's block spec (standard-v5) and unit refusal (standard-v5-residual). */ blockSpec: BlockSpec | null; unitRefusal: string | null; prefillChunkSize: number; @@ -335,7 +336,7 @@ async function fitCoreManifold( captureVersion: 3, captureRenderSha256: rendered.captureRenderSha256, baselinePromptsSha256: digest(baselinePrompts), - fitPolicyVersion: 1, + fitPolicyVersion: FIT_POLICY_VERSION, }, topology: foundation.topology, consensusGram: foundation.consensusGram, diff --git a/webui/scripts/ios-runtime-policy.test.mjs b/webui/scripts/ios-runtime-policy.test.mjs index a31bc10..e27eaba 100644 --- a/webui/scripts/ios-runtime-policy.test.mjs +++ b/webui/scripts/ios-runtime-policy.test.mjs @@ -226,7 +226,7 @@ function model(id, displayName, tier) { variants: [{ id: variantId, tier, - structuredHookProfile: "standard-v4", + structuredHookProfile: "standard-v5", contextProfiles: [{ contextTokens: 2048, bindingSha256: "b".repeat(64), diff --git a/webui/scripts/manifold-robustness.test.mjs b/webui/scripts/manifold-robustness.test.mjs index e30c0d1..4a10c1c 100644 --- a/webui/scripts/manifold-robustness.test.mjs +++ b/webui/scripts/manifold-robustness.test.mjs @@ -5,11 +5,11 @@ import { createServer } from "vite"; const server = await createServer({ root: fileURLToPath(new URL("..", import.meta.url)), configFile: false, appType: "custom", logLevel: "silent", server: { middlewareMode: true, watch: null } }); try { const { compileStructuredHookProgram, initialStructuredHookState, runStructuredHookLayer, geometryCoordinateMean } = await server.ssrLoadModule("/src/hosted/runtime/structuredHookProgram.ts"); - const { STANDARD_STRUCTURED_HOOK_PROFILE_V4: profile } = await server.ssrLoadModule("/src/hosted/runtime/structuredHookProfile.ts"); + const { STANDARD_STRUCTURED_HOOK_PROFILE_V5: profile } = await server.ssrLoadModule("/src/hosted/runtime/structuredHookProfile.ts"); const { measurementEnvelope, measurementGateScores } = await server.ssrLoadModule("/src/hosted/runtime/webLlmGeneration.ts"); const points = [[1, 0], [0, 1], [-1, 0], [0, -1]]; const curve = { - active: true, basis: [[1, 0], [0, 1]], neutral: [0, 0], + active: true, basis: [[1, 0], [0, 1]], read: [[1, 0], [0, 1]], neutral: [0, 0], nodeParameters: points, rbfWeights: points.map(() => [0, 0]), polynomial: [[0, 0], [1, 0], [0, 1]], coordinateOffset: [0, 0], coordinateScale: [1, 1], origin: [0], target: [0.25], axes: [{ periodic: true, period: 1, lowerBound: 0, upperBound: 1 }], along: 0, onto: 0, diff --git a/webui/scripts/overlay-vm-functions.mjs b/webui/scripts/overlay-vm-functions.mjs index 4613ff9..050c178 100644 --- a/webui/scripts/overlay-vm-functions.mjs +++ b/webui/scripts/overlay-vm-functions.mjs @@ -1,8 +1,8 @@ // Hook ABI v5's VM function sets, read from the MLC overlay's own definition rather than copied: // `browser-runtime/forks/overlay_checks.py` (REQUIRED_FUNCTIONS, UNIT_FUNCTIONS, // UNIT_ARCHITECTURES), the module every compile gate imports. A library of a unit architecture -// exports REQUIRED ∪ UNIT and attests `standard-v4`; any other architecture exports REQUIRED, no -// unit function, and attests `standard-v4-residual` (B1 §7, HOOK_ABI.md §3). +// exports REQUIRED ∪ UNIT and attests `standard-v5`; any other architecture exports REQUIRED, no +// unit function, and attests `standard-v5-residual` (B1 §7, HOOK_ABI.md §3). import { readFileSync } from "node:fs"; @@ -57,15 +57,15 @@ export const OVERLAY_VM_FUNCTIONS = parseOverlayVmFunctions(readFileSync(overlay /** The structured hook profile a library of `architecture` attests under hook ABI v5. */ export function structuredHookProfileForArchitecture(architecture, sets = OVERLAY_VM_FUNCTIONS) { - return sets.unitArchitectures.includes(architecture) ? "standard-v4" : "standard-v4-residual"; + return sets.unitArchitectures.includes(architecture) ? "standard-v5" : "standard-v5-residual"; } /** `{present, absent}`: the VM functions a v5 library of `profile` must and must not export. */ export function vmFunctionsForProfile(profile, sets = OVERLAY_VM_FUNCTIONS) { - if (profile === "standard-v4") { + if (profile === "standard-v5") { return { present: Object.freeze([...sets.required, ...sets.unit].sort()), absent: Object.freeze([]) }; } - if (profile === "standard-v4-residual") { + if (profile === "standard-v5-residual") { return { present: sets.required, absent: sets.unit }; } throw new Error(`structured hook profile ${JSON.stringify(profile)} predates hook ABI v5`); diff --git a/webui/scripts/prepare-hosted-candidate-lock.mjs b/webui/scripts/prepare-hosted-candidate-lock.mjs index c8e6447..93bbbf8 100644 --- a/webui/scripts/prepare-hosted-candidate-lock.mjs +++ b/webui/scripts/prepare-hosted-candidate-lock.mjs @@ -146,7 +146,7 @@ export function deriveCandidateRuntimeLock(runtimeLock, modelId, { // statistics bind the tokenizer digest, so a drift here is a conversion error, not a refill. if (model.tokenizerSha256 !== null) differs("tokenizer digest", tokenizer, model.tokenizerSha256); if (model.chatTemplateSha256 !== null) differs("chat template digest", chatTemplate, model.chatTemplateSha256); - if (model.structuredHookProfile === "standard-v4") { + if (model.structuredHookProfile === "standard-v5") { const compiled = blockSpecFromMlcConfig(model.architecture, chatConfig); if (!sameBlockSpec(compiled, model.blockSpec)) { throw new Error( diff --git a/webui/scripts/prepare-hosted-candidate-lock.test.mjs b/webui/scripts/prepare-hosted-candidate-lock.test.mjs index 682e553..e5dc3a4 100644 --- a/webui/scripts/prepare-hosted-candidate-lock.test.mjs +++ b/webui/scripts/prepare-hosted-candidate-lock.test.mjs @@ -93,7 +93,7 @@ assert.deepEqual(normalized, runtimeLock); // configuration would not attest, a closure without its library. const refusals = [ [{ closure: { hookAbi: "post-block-residual-v4" } }, /hookAbi differs/], - [{ closure: { structuredHookProfile: "standard-v4-residual" } }, /structuredHookProfile differs/], + [{ closure: { structuredHookProfile: "standard-v5-residual" } }, /structuredHookProfile differs/], [{ closure: { architecture: "llama" } }, /architecture differs/], [{ closure: { contextWindowSize: 2048 } }, /contextWindowSize differs/], [{ closure: { layerMap: [0, 1] } }, /layerMap differs/], @@ -184,7 +184,7 @@ assert.doesNotThrow(() => validateRuntimeLock(adopted)); // The lock still describes base-model architectures and their execution profiles. for (const id of ["gpt2-base", "pythia-70m-base", "qwen35-2b-base"]) { const pin = model(id); - assert.equal(lockedModelExecutionProfiles(pin, pin).structuredHookProfile, "standard-v4-residual"); + assert.equal(lockedModelExecutionProfiles(pin, pin).structuredHookProfile, "standard-v5-residual"); const base = structuredClone(runtimeLock); delete base.models.find((entry) => entry.id === id).modelType; assert.throws(() => validateRuntimeLock(base), /invalid|unknown or missing/); diff --git a/webui/scripts/publish-hosted-catalog.test.mjs b/webui/scripts/publish-hosted-catalog.test.mjs index 0e0eb1e..65e9805 100644 --- a/webui/scripts/publish-hosted-catalog.test.mjs +++ b/webui/scripts/publish-hosted-catalog.test.mjs @@ -60,14 +60,14 @@ const lockedModels = lockedCatalogModels({ librarySha256: "e".repeat(64), hiddenSize: 4, layerMap: [0, 1], - structuredHookProfile: "standard-v4", + structuredHookProfile: "standard-v5", thinkingProfile: null, convertedRepository: "fixture/converted", convertedRevision: "f".repeat(40), contextProfiles: [2048], }], }); -assert.equal(lockedModels[0].structuredHookProfile, "standard-v4"); +assert.equal(lockedModels[0].structuredHookProfile, "standard-v5"); assert.equal(lockedModels[0].thinkingProfile, null); const repository = "stdlogits/drowse-web-catalog"; @@ -76,16 +76,17 @@ const distribution = { minimumAcceptedSequence: 7, publicKeys: [], }; -// Runtime v2 publishes at its own directory, which the distribution lock names; the root keeps -// what deployed v1 builds read. -assert.deepEqual(CATALOG_DIRECTORIES, ["", "v2/"]); +// Each runtime generation publishes at its own directory, which the distribution lock names (v3: +// hook ABI v6); earlier directories keep what deployed builds of their runtime read. +assert.deepEqual(CATALOG_DIRECTORIES, ["", "v2/", "v3/"]); const lockFile = JSON.parse(await readFile(new URL("../../browser-runtime/distribution-lock.json", import.meta.url), "utf8")); assert.equal(lockFile.catalogUrl, CURRENT_CATALOG_URLS.catalogUrl); assert.equal(lockFile.signatureUrl, CURRENT_CATALOG_URLS.signatureUrl); -assert.equal(CURRENT_CATALOG_URLS.catalogUrl, `https://huggingface.co/${repository}/resolve/main/v2/catalog.json`); +assert.equal(CURRENT_CATALOG_URLS.catalogUrl, `https://huggingface.co/${repository}/resolve/main/v3/catalog.json`); assert.deepEqual(catalogLocation(distribution), { repository, directory: "v2/" }); assert.deepEqual(catalogLocation(catalogUrls("")), { repository, directory: "" }); assert.equal(previousCatalogDirectory("v2/"), ""); +assert.equal(previousCatalogDirectory("v3/"), "v2/"); assert.equal(previousCatalogDirectory(""), null); assert.throws( () => catalogLocation({ @@ -98,7 +99,7 @@ assert.throws( () => catalogLocation({ ...distribution, signatureUrl: catalogUrls("").signatureUrl }), /one directory of one repository/, ); -assert.throws(() => catalogLocation(catalogUrls("v3/")), /not a published catalog path/); +assert.throws(() => catalogLocation(catalogUrls("v4/")), /not a published catalog path/); assert.throws( () => catalogLocation({ ...distribution, catalogUrl: `https://huggingface.co/${repository}/resolve/dev/v2/catalog.json` }), /main-branch URL/, @@ -234,7 +235,7 @@ try { /first catalog at v2\/ must advance a published catalog at the root/, ); await assert.rejects( - () => validatePublishedAdvance(1, "v3/", fetchPair, distribution.publicKeys), + () => validatePublishedAdvance(1, "v4/", fetchPair, distribution.publicKeys), /not a published catalog path/, ); diff --git a/webui/scripts/publish-hosted-model.test.mjs b/webui/scripts/publish-hosted-model.test.mjs index 6af05b8..7291b61 100644 --- a/webui/scripts/publish-hosted-model.test.mjs +++ b/webui/scripts/publish-hosted-model.test.mjs @@ -10,8 +10,8 @@ import { import { structuredHookProfile, thinkingProfile } from "./hosted-model-profiles.mjs"; import { expectedBuildToolchain } from "./hosted-model-closure.mjs"; -assert.equal(structuredHookProfile("standard-v4"), "standard-v4"); -assert.equal(structuredHookProfile("standard-v4-residual"), "standard-v4-residual"); +assert.equal(structuredHookProfile("standard-v5"), "standard-v5"); +assert.equal(structuredHookProfile("standard-v5-residual"), "standard-v5-residual"); assert.throws(() => structuredHookProfile("unknown-profile"), /not allow-listed/); assert.throws(() => structuredHookProfile("adapter-derived"), /not allow-listed/); assert.equal(thinkingProfile(null), null); @@ -103,9 +103,9 @@ try { })); const build = JSON.stringify({ schemaVersion: 1, - runtimeAbi: "drowse-web-runtime-v2", - hookAbi: "block-sites-v5", - structuredHookProfile: "standard-v4", + runtimeAbi: "drowse-web-runtime-v3", + hookAbi: "block-sites-v6", + structuredHookProfile: "standard-v5", thinkingProfile: verifiedThinkingProfile, architecture: "qwen3", quantization: "q4f16_1", @@ -141,9 +141,9 @@ try { } const manifest = { schemaVersion: 1, - runtimeAbi: "drowse-web-runtime-v2", - hookAbi: "block-sites-v5", - structuredHookProfile: "standard-v4", + runtimeAbi: "drowse-web-runtime-v3", + hookAbi: "block-sites-v6", + structuredHookProfile: "standard-v5", thinkingProfile: verifiedThinkingProfile, architecture: "qwen3", quantization: "q4f16_1", diff --git a/webui/scripts/runtime-foundation.test.mjs b/webui/scripts/runtime-foundation.test.mjs index d2847b5..0d65016 100644 --- a/webui/scripts/runtime-foundation.test.mjs +++ b/webui/scripts/runtime-foundation.test.mjs @@ -75,7 +75,7 @@ function catalogDocument(overrides = {}) { { id: "smollm2-360m-q4f16", tier: "fastest", - structuredHookProfile: "standard-v4", + structuredHookProfile: "standard-v5", thinkingProfile: null, contextProfiles: [ { @@ -2920,11 +2920,11 @@ try { ); assert.equal(verifiedAlternateOwner.document.models[0].variants[0].files[0].url.includes("/stdlogits/"), true); - // A v5 variant's lock entry records what its library attests: a standard-v4 one its block + // A v5 variant's lock entry records what its library attests: a standard-v5 one its block // spec (the load request's), a residual one its unit refusal, both their prefill chunk; // without the spec or refusal the catalog fails. const lockedVariant = verified.document.models[0].variants[0]; - assert.equal(lockedVariant.structuredHookProfile, "standard-v4"); + assert.equal(lockedVariant.structuredHookProfile, "standard-v5"); assert.deepEqual( catalog.lockedLibraryContract(policy.runtimeLockModels, lockedVariant), fixtureLibraryContract(lockedVariant), @@ -3097,7 +3097,7 @@ try { const exactReadout = catalogDocument(); const exactReadoutVariant = exactReadout.models[0].variants[0]; - exactReadoutVariant.structuredHookProfile = "standard-v4-residual"; + exactReadoutVariant.structuredHookProfile = "standard-v5-residual"; Object.assign(exactReadoutVariant.requirements.limits, { maxBufferSize: 134_217_728, maxStorageBufferBindingSize: 134_217_728, diff --git a/webui/scripts/runtime-lock-document.mjs b/webui/scripts/runtime-lock-document.mjs index 27ae220..91983b6 100644 --- a/webui/scripts/runtime-lock-document.mjs +++ b/webui/scripts/runtime-lock-document.mjs @@ -171,7 +171,7 @@ function validateRepositoryPin(value, label) { } function validateRuntimeModel(value) { - const units = value?.structuredHookProfile === "standard-v4"; + const units = value?.structuredHookProfile === "standard-v5"; exactKeys(value, [ "id", "architecture", diff --git a/webui/scripts/sampling-parity.test.mjs b/webui/scripts/sampling-parity.test.mjs deleted file mode 100644 index 4991a3a..0000000 --- a/webui/scripts/sampling-parity.test.mjs +++ /dev/null @@ -1,76 +0,0 @@ -import assert from "node:assert/strict"; -import { readFile } from "node:fs/promises"; - -import { - effectiveDrowseTopK, - sampleDrowseTopKTopP, -} from "@drowse/web-llm"; - - -const fixture = JSON.parse(await readFile( - new URL("../../drowse/tests/fixtures/browser/sampling-parity-v1.json", import.meta.url), - "utf8", -)); - -for (const testCase of fixture.cases) { - const probabilities = Float32Array.from(testCase.sortedProbabilities); - const tokenIds = Int32Array.from(testCase.sortedTokenIds); - const expected = testCase.expected; - const effectiveTopK = effectiveDrowseTopK(testCase.topK, tokenIds.length); - assert.equal( - effectiveTopK, - Math.min(testCase.topK || 1024, tokenIds.length), - `${testCase.name}: effective top-k`, - ); - for (const sample of expected.samples) { - const result = sampleDrowseTopKTopP( - probabilities, - tokenIds, - testCase.topP, - testCase.topK, - sample.uniform, - testCase.requestedTokenIds, - ); - assert.equal(result.sampledTokenId, sample.tokenId, `${testCase.name}: sampled token`); - close(result.sampledLogprob, sample.logprob, 2e-6, `${testCase.name}: sampled logprob`); - assert.deepEqual( - result.topLogprobs.map((entry) => entry.token_id), - expected.supportTokenIds, - `${testCase.name}: support token IDs`, - ); - result.topLogprobs.forEach((entry, index) => { - close( - Math.exp(entry.logprob), - expected.supportProbabilities[index], - 2e-6, - `${testCase.name}: support probability ${index}`, - ); - }); - close(result.entropyNats, expected.entropyNats, 2e-6, `${testCase.name}: entropy`); - close(result.perplexity, expected.perplexity, 2e-6, `${testCase.name}: perplexity`); - assert.equal(result.argmax.token_id, expected.supportTokenIds[0]); - for (const entry of result.selectedLogprobs) { - const supportIndex = expected.supportTokenIds.indexOf(entry.token_id); - if (supportIndex < 0) { - assert.equal(entry.logprob, Number.NEGATIVE_INFINITY); - } else { - close( - Math.exp(entry.logprob), - expected.supportProbabilities[supportIndex], - 2e-6, - `${testCase.name}: requested token ${entry.token_id}`, - ); - } - } - } -} - -console.log("Shared Python/WebLLM sampling parity checks passed"); - - -function close(actual, expected, tolerance, label) { - assert.ok( - Number.isFinite(actual) && Math.abs(actual - expected) <= tolerance, - `${label}: ${actual} != ${expected} within ${tolerance}`, - ); -} diff --git a/webui/scripts/steering-expression.test.mjs b/webui/scripts/steering-expression.test.mjs index 9d4e804..c779322 100644 --- a/webui/scripts/steering-expression.test.mjs +++ b/webui/scripts/steering-expression.test.mjs @@ -1,6 +1,5 @@ -// The browser grammar against drowse's goldens: the parsed IR (steering_ir.json), the validate -// parts the recipe chips rebuild from (recipe_chips.json) and the accept/reject table with -// referenced selectors (browser_steering_expression.json). Every case in all three is replayed. +// The browser grammar: the validate parts the recipe chips rebuild from (drowse's +// recipe_chips.json), positions, layer selection, rejection text, inversion and validate. import assert from "node:assert/strict"; import { readFile } from "node:fs/promises"; import { fileURLToPath } from "node:url"; @@ -23,83 +22,12 @@ try { const grammar = await server.ssrLoadModule("/src/hosted/runtime/steeringExpression.ts"); const { formatSteering, - formatSteeringTrigger, parseSteering, parseSteeringExpression, - referencedSteeringSelectors, selectTermLayers, - SteeringExpressionError, steeringParts, - steeringTriggerFields, } = grammar; - // steering_ir.json: every accepted expression's ordered terms and canonical text, against the - // fixture's registry; every rejected one's error class. - const ir = await fixture("steering_ir.json"); - assert.equal(ir.schemaVersion, 1); - const manifolds = ir.registry.map((entry) => ({ - namespace: entry.namespace, - name: entry.name, - fitMode: entry.fitMode, - labels: entry.labels, - })); - const resolution = (testCase) => ({ manifolds, profileNames: testCase.profileNames }); - const triggerRecord = (trigger) => trigger === null ? null : { - text: formatSteeringTrigger(trigger), - ...steeringTriggerFields(trigger), - gate: trigger.gate === null - ? null - : { probe: trigger.gate.probe, op: trigger.gate.operator, threshold: trigger.gate.threshold }, - }; - const layersRecord = (layers) => Array.isArray(layers) ? [...layers] : layers; - const termRecord = (term, part) => { - const record = { key: term.key, text: part.text, kind: term.kind }; - if (term.kind === "manifold") { - Object.assign(record, { - manifold: term.manifold, - position: typeof term.position === "string" ? term.position : [...term.position], - along: term.along, - onto: term.onto, - layers: layersRecord(term.layers), - }); - } else if (term.kind === "projection") { - Object.assign(record, { - base: term.base, operator: term.operator, onto: term.onto, coeff: term.coeff, - layers: layersRecord(term.layers), - }); - } else if (term.kind === "unitAblation") { - Object.assign(record, { unit: term.unit, coeff: term.coeff }); - } else { - Object.assign(record, { target: term.target, coeff: term.coeff, layers: layersRecord(term.layers) }); - } - record.trigger = triggerRecord(term.trigger); - return record; - }; - for (const testCase of ir.accepted) { - const parsed = parseSteering(testCase.expression, resolution(testCase)); - const parts = steeringParts(parsed); - assert.deepStrictEqual( - { - canonical: formatSteering(parsed), - terms: parsed.terms.map((term, index) => termRecord(term, parts[index])), - }, - { canonical: testCase.canonical, terms: testCase.terms }, - testCase.expression, - ); - assert.equal( - formatSteering(parseSteering(testCase.canonical, resolution(testCase))), - testCase.canonical, - `${testCase.expression}: the canonical form is a fixed point`, - ); - } - for (const testCase of ir.rejected) { - assert.throws( - () => parseSteering(testCase.expression, resolution(testCase)), - (error) => error.code === testCase.error, - testCase.expression, - ); - } - // recipe_chips.json: the validate parts of every case, and the chips' canonical expression. const chips = await fixture("recipe_chips.json"); for (const testCase of [...chips.cases, ...chips.readOnly]) { @@ -116,29 +44,6 @@ try { assert.equal(formatSteering(parseSteering(testCase.expression)), testCase.expression, testCase.name); } - // browser_steering_expression.json: accepted with their referenced selectors, and rejected. - const table = await fixture("browser_steering_expression.json"); - assert.equal(table.schemaVersion, 1); - for (const testCase of table.accepted) { - assert.doesNotThrow(() => parseSteering(testCase.expression), testCase.expression); - assert.deepEqual( - referencedSteeringSelectors(testCase.expression).map((item) => [ - item.namespace, - item.concept, - item.variant, - ]), - testCase.selectors, - testCase.expression, - ); - } - for (const expression of table.rejected) { - assert.throws( - () => parseSteering(expression), - (error) => error instanceof SteeringExpressionError, - expression, - ); - } - // The syntax tree keeps written positions for the compiler. const tree = parseSteeringExpression( "-0.6,0.3 default/emotions:role%pirate{ 20, 4 - 6 }@after&when:personas[3]>=-0.4", @@ -204,10 +109,16 @@ try { assert.throws(() => parseSteering(written), (error) => error.message === message, written); } - // The `inverted` regen, against drowse 6.0's Recipe.invert_steering with the golden's registry - // installed (folders only, as test_steering_ir installs it; run from the venv on the pinned - // submodule): bare labels resolve to their `%` terms and repeats fold before the signs flip, and - // a refusal is drowse's own class and words. + // The `inverted` regen, against drowse 6.0's Recipe.invert_steering with this registry installed + // (folders only): bare labels resolve to their `%` terms and repeats fold before the signs flip, + // and a refusal is drowse's own class and words. + const manifolds = [ + { namespace: "default", name: "verbose.concise", fitMode: "pca", labels: ["verbose", "concise"] }, + { namespace: "default", name: "personas", fitMode: "pca", labels: ["pirate", "hacker", "robot"] }, + { namespace: "local", name: "formal.casual", fitMode: "pca", labels: ["formal", "casual"] }, + { namespace: "local", name: "animals", fitMode: "pca", labels: ["deer", "owl"] }, + { namespace: "local", name: "forest", fitMode: "pca", labels: ["deer", "oak"] }, + ]; for (const [written, expected] of [ ["0.5,0.3 demo%alert", {"inverted": "-0.5,-0.3 demo%alert"}], ["-0.6,0.3 demo%alert{1-2}", {"inverted": "0.6,-0.3 demo%alert{1-2}"}], @@ -378,11 +289,7 @@ try { assert.equal(pythonStrip("\ufeff0.5 x"), "\ufeff0.5 x"); assert.equal((await validate("\u0085 plain + 0.2 x\u001e")).expression, "0.5 plain + 0.2 x"); - console.log( - `Steering grammar checks passed (${ir.accepted.length + ir.rejected.length} IR, ` + - `${chips.cases.length + chips.readOnly.length} chip, ` + - `${table.accepted.length + table.rejected.length} table cases)`, - ); + console.log(`Steering grammar checks passed (${chips.cases.length + chips.readOnly.length} chip cases)`); } finally { await server.close(); } diff --git a/webui/scripts/steering-term-layers.test.mjs b/webui/scripts/steering-term-layers.test.mjs deleted file mode 100644 index 3fe6dd3..0000000 --- a/webui/scripts/steering-term-layers.test.mjs +++ /dev/null @@ -1,150 +0,0 @@ -// drowse's steering-term-layers golden (`POST .../steering/validate` over a model-free composer) -// replayed through the browser's `sessions.validateSteering`: the loom over the real structured -// compiler, loaded from a core pack holding the golden's whiteners, its profiles (one-node -// concepts), its flat manifold and its curved one. Each case's canonical expression, n_layers, -// every term's key, fitted layers, mean-1 share and selected layers, or the refusal text; for a -// curved % term, the hook's per-layer share and the lowered curved groups (along, onto). -import assert from "node:assert/strict"; -import { readFileSync } from "node:fs"; -import { corePackRequest } from "./support/core-pack.mjs"; -import { viteServer } from "./support/units-goldens.mjs"; - -const golden = JSON.parse(readFileSync(new URL("../../drowse/tests/fixtures/browser/steering-term-layers-v1.json", import.meta.url), "utf8")); - -const close = (actual, expected, where) => { - if (typeof expected === "number") { - assert.ok(typeof actual === "number" && Math.abs(actual - expected) <= 1e-9 + 1e-6 * Math.abs(expected), `${where}: ${actual} != ${expected}`); - } else if (Array.isArray(expected)) { - assert.ok(Array.isArray(actual) && actual.length === expected.length, `${where}: ${JSON.stringify(actual)} != ${JSON.stringify(expected)}`); - expected.forEach((value, i) => close(actual[i], value, `${where}[${i}]`)); - } else if (expected !== null && typeof expected === "object") { - assert.ok(actual !== null && typeof actual === "object", `${where}: ${JSON.stringify(actual)} is not an object`); - assert.deepEqual(Object.keys(actual).sort(), Object.keys(expected).sort(), `${where} keys`); - for (const key of Object.keys(expected)) close(actual[key], expected[key], `${where}.${key}`); - } else { - assert.equal(actual, expected, where); - } -}; - -const norm = (v) => Math.hypot(...v); -const dot = (a, b) => a.reduce((sum, value, i) => sum + value * b[i], 0); - -const server = await viteServer(); -try { - const { BrowserFeasibilityCorePackCompiler } = await server.ssrLoadModule("/src/hosted/runtime/browserCorePack.ts"); - const { BrowserLoomRuntime } = await server.ssrLoadModule("/src/hosted/runtime/browserLoom.ts"); - const d = golden.hiddenSize; - const means = new Map(golden.whiteners.map((row) => [row.layer, row.mean])); - // Neutral-anchored rows, as drowse's fold anchors them: the mean's component along the basis. - const anchored = (layer, basis) => { - const along = dot(means.get(layer), basis); - return basis.map((value) => along * value); - }; - // A profile is a 2-node `pca` concept in a browser core pack (the grammar's tier-2 bare name): - // its push is the first node's coordinate along the unit basis and a projection reads the - // basis times the baked share, so both carry |v| (0 with any unit basis for a zero layer). - const profiles = Object.entries(golden.profiles).map(([name, rows]) => { - const unit = (direction) => { - const length = norm(direction); - return length > 0 ? direction.map((value) => value / length) : direction.map((_, i) => (i === 0 ? 1 : 0)); - }; - return { - name, - labels: [`${name}_pole`, `${name}_anti`], - nodeCoordinates: [1, -1], - // A baked share must be positive; a zero layer's 1e-9 whitens below the projection's - // near-zero cutoff, so `~` still drops it. - shares: Object.fromEntries(rows.map(({ layer, direction }) => [layer, norm(direction) || 1e-9])), - layers: rows.map(({ layer, direction }) => ({ - layer, - mean: anchored(layer, unit(direction)), - basis: [unit(direction)], - // The push reads the first node; the second keeps the pair non-degenerate. - nodeCoordinates: [[norm(direction)], [-(norm(direction) || 1)]], - })), - }; - }); - const manifolds = Object.entries(golden.manifolds).map(([name, spec]) => spec.curved - ? { name, labels: spec.labels, curved: true, layers: spec.layers } - : { - name, - labels: spec.labels, - layers: spec.layers.map((row) => ({ - layer: row.layer, - mean: anchored(row.layer, row.basis), - basis: [row.basis], - nodeCoordinates: row.nodeCoordinates.map((c) => [c]), - })), - }); - const request = await corePackRequest(server, { - hiddenSize: d, - layerCount: golden.nLayers, - whiteners: golden.whiteners, - manifolds: [...profiles, ...manifolds], - }); - const compiler = await BrowserFeasibilityCorePackCompiler.load(request); - const loom = new BrowserLoomRuntime({ - session: { - id: "default", model_id: "fixture-model", created: 0, - config: { temperature: 0, top_p: 1, top_k: null, max_tokens: 64, system_prompt: null, thinking: false }, - profiles: [], probes: [], history_length: 0, supports_thinking: false, thinking_is_optional: false, - is_base_model: false, jlens_fitted: false, instruments: [], default_steering: null, - role_substitution_supported: true, user_role_supported: true, default_assistant_role: "assistant", - default_user_role: "user", scene_mode: true, thinking_input_supported: false, - }, - generation: {}, - compileSteering: (expression, probeRequests) => compiler.compileForGeneration(expression, probeRequests), - steeringManifolds: () => compiler.steeringManifolds(), - }); - for (const entry of golden.cases) { - const response = await loom.request({ service: "sessions", method: "validateSteering", args: [entry.expression] }); - const { parts: _parts, ...rest } = response; - close(asProfiles(rest), entry.response, entry.name); - if (entry.curvedShares) { - const program = compiler.compile(entry.expression); - close(curvedShares(program, entry.curvedShares[0].manifold), entry.curvedShares, `${entry.name} curvedShares`); - close(curvedGroups(program), entry.curvedGroups, `${entry.name} curvedGroups`); - } - } - console.log(`steering term layers: ${golden.cases.length} validate cases match drowse's`); -} finally { - await server.close(); -} - -// drowse registers the golden's profiles as session vectors, whose bare names win the atom -// ladder and print bare (`a`); the browser has no registered-profile store (its concepts are -// core-pack manifolds), so a bare profile name resolves through the label tier and prints as -// the label-form push `local/a%a_pole`, and the fold's conflicting-trigger refusal names it a -// manifold, not a concept. Everything else about the term is compared as is. -function asProfiles(value) { - if (typeof value === "string") { - return value - .replace(/local\/([a-z]+)%\1_pole/gu, "$1") - .replace(/^manifold '([a-z]+)' appears with conflicting triggers/u, "concept '$1' appears with conflicting triggers"); - } - if (Array.isArray(value)) return value.map(asProfiles); - if (value !== null && typeof value === "object") return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, asProfiles(item)])); - return value; -} - -// The lowered curved groups (`curveRank > 0` slots, per layer): along and onto as the kernel -// gets them. -function curvedGroups(program) { - const slots = program.curveRank.length / program.layerCount; - const groups = []; - for (let layer = 0; layer < program.layerCount; layer += 1) { - for (let slot = 0; slot < slots; slot += 1) { - const at = layer * slots + slot; - if (program.curveRank[at] > 0) groups.push({ layer, along: program.curveAlong[at], onto: program.curveOnto[at] }); - } - } - return groups; -} - -// The hook's per-layer share (`_manifold_layer_shares`, mean 1 over the layers the term acts -// on) as the lowering applied it: each layer's along over their mean (one curved term here). -function curvedShares(program, manifold) { - const groups = curvedGroups(program); - const mean = groups.reduce((sum, group) => sum + group.along, 0) / groups.length; - return [{ manifold, layers: groups.map((group) => group.layer), share: groups.map((group) => group.along / mean) }]; -} diff --git a/webui/scripts/structured-hook-parity.test.mjs b/webui/scripts/structured-hook-parity.test.mjs deleted file mode 100644 index f3fae79..0000000 --- a/webui/scripts/structured-hook-parity.test.mjs +++ /dev/null @@ -1,164 +0,0 @@ -import assert from "node:assert/strict"; -import { readFile } from "node:fs/promises"; -import { fileURLToPath } from "node:url"; - -import { createServer } from "vite"; - - -const root = fileURLToPath(new URL("..", import.meta.url)); -const fixture = JSON.parse(await readFile( - new URL("../../drowse/tests/fixtures/browser/structured-program-parity-v1.json", import.meta.url), - "utf8", -)); -const server = await createServer({ - root, - configFile: false, - appType: "custom", - logLevel: "silent", - server: { middlewareMode: true, watch: null }, -}); - -try { - const [hooks, profiles, expression, instruments] = await Promise.all([ - server.ssrLoadModule("/src/hosted/runtime/structuredHookProgram.ts"), - server.ssrLoadModule("/src/hosted/runtime/structuredHookProfile.ts"), - server.ssrLoadModule("/src/hosted/runtime/steeringExpression.ts"), - server.ssrLoadModule("/src/hosted/runtime/browserInstrumentPacks.ts"), - ]); - const profile = profiles.STANDARD_STRUCTURED_HOOK_PROFILE_V4; - const geometryProfile = profiles.STANDARD_STRUCTURED_HOOK_PROFILE_V4; - - const multi = hooks.compileStructuredHookProgram( - fixture.multiCurve.hiddenSize, - [{ curves: fixture.multiCurve.curves }], - profile, - ); - const multiResult = hooks.runStructuredHookLayer( - multi, - hooks.initialStructuredHookState(multi), - 0, - fixture.multiCurve.residual, - { decode: false }, - ); - close(multiResult.residual, fixture.multiCurve.expected.residual, 4e-5); - fixture.multiCurve.expected.preSlideFeet.forEach((expected, curve) => { - const offset = curve * profile.maxIntrinsicDim; - close( - multiResult.curveFeet.slice(offset, offset + expected.length), - expected, - 4e-5, - ); - }); - - const sphere = hooks.compileStructuredHookProgram( - fixture.sphereCurve.hiddenSize, - [{ curves: [fixture.sphereCurve.curve] }], - geometryProfile, - ); - const sphereResult = hooks.runStructuredHookLayer( - sphere, - hooks.initialStructuredHookState(sphere), - 0, - fixture.sphereCurve.residual, - { decode: false }, - ); - close(sphereResult.residual, fixture.sphereCurve.expected.residual, 4e-5); - close( - sphereResult.curveFeet.slice(0, fixture.sphereCurve.expected.preSlideFoot.length), - fixture.sphereCurve.expected.preSlideFoot, - 4e-5, - ); - - const saeProbe = hooks.saeFeatureProbe( - fixture.sae.encoderDirection, - fixture.sae.encoderBias, - fixture.sae.decoderBias, - fixture.sae.maxAct, - ); - const sae = hooks.compileStructuredHookProgram( - fixture.sae.residual.length, - [{ probes: [saeProbe] }], - profile, - ); - const saeResult = hooks.runStructuredHookLayer( - sae, - hooks.initialStructuredHookState(sae), - 0, - fixture.sae.residual, - ); - close( - saeResult.probes.slice(0, 1), - [fixture.sae.expectedNormalizedActivation], - 2e-6, - ); - close( - instruments.saeDecoderDirection( - fixture.sae.decoderDirection, - fixture.sae.decoderDirection.length, - 0, - ), - fixture.sae.expectedDecoderDirection, - 2e-6, - ); - close( - hooks.jLensTokenDirection( - fixture.jlens.unembeddingRow, - fixture.jlens.jacobian.flat(), - ), - fixture.jlens.expectedDirection, - 2e-6, - ); - - for (const gateFixture of fixture.gates) { - const trigger = expression.parseSteeringExpression( - gateFixture.expression, - ).terms[0].trigger; - const gateProgram = hooks.compileStructuredHookProgram(1, [{ - affineGroups: [hooks.additiveDirectionGroup([1], 1)], - }], profile); - gateProgram.controls = { - affine: Array.from( - { length: gateProgram.affineActive.length }, - (_, index) => index === 0 - ? { - enabled: true, - phase: trigger.phase, - gate: trigger.gate === null - ? null - : { - slots: [], - scoreKey: trigger.gate.probe, - operator: trigger.gate.operator, - threshold: trigger.gate.threshold, - }, - } - : null, - ), - curve: Array.from({ length: gateProgram.curveActive.length }, () => null), - }; - for (const context of gateFixture.contexts) { - const controls = hooks.structuredHookControlsFor(gateProgram, { - prefill: context.prefill, - thinking: context.thinking, - generatedTokens: context.generatedTokens, - priorScores: context.scores, - }); - assert.equal(controls.affineActive[0] === 1, context.active); - } - } - - console.log("Shared curved, periodic, sphere, gated, SAE, and J-lens parity checks passed"); -} finally { - await server.close(); -} - - -function close(actual, expected, tolerance) { - assert.equal(actual.length, expected.length); - for (let index = 0; index < actual.length; index += 1) { - assert.ok( - Math.abs(actual[index] - expected[index]) <= tolerance, - `${index}: ${actual[index]} != ${expected[index]} within ${tolerance}`, - ); - } -} diff --git a/webui/scripts/structured-hook-program.test.mjs b/webui/scripts/structured-hook-program.test.mjs index ffee9a9..9300317 100644 --- a/webui/scripts/structured-hook-program.test.mjs +++ b/webui/scripts/structured-hook-program.test.mjs @@ -20,14 +20,15 @@ try { server.ssrLoadModule("/src/hosted/runtime/structuredHookProgram.ts"), server.ssrLoadModule("/src/hosted/runtime/structuredHookProfile.ts"), ]); - const standardProfile = profiles.STANDARD_STRUCTURED_HOOK_PROFILE_V4; - const geometryProfile = profiles.STANDARD_STRUCTURED_HOOK_PROFILE_V4; - const exactReadoutProfile = profiles.STANDARD_STRUCTURED_HOOK_PROFILE_V4; + const standardProfile = profiles.STANDARD_STRUCTURED_HOOK_PROFILE_V5; + const geometryProfile = profiles.STANDARD_STRUCTURED_HOOK_PROFILE_V5; + const exactReadoutProfile = profiles.STANDARD_STRUCTURED_HOOK_PROFILE_V5; const program = hooks.compileStructuredHookProgram(2, [ { affineGroups: [{ active: true, basis: [[1, 0], [0, 1]], + read: [[1, 0], [0, 1]], neutral: [0, 0], target: [1, 0], along: 0.5, @@ -42,6 +43,7 @@ try { curves: [{ active: true, basis: [[1, 0], [0, 1]], + read: [[1, 0], [0, 1]], neutral: [0, 0], nodeParameters: [[0], [1]], rbfWeights: [[0, 0], [0, 0]], @@ -89,6 +91,7 @@ try { curves: [{ active: true, basis: [[1, 0]], + read: [[1, 0]], neutral: [0, 0], nodeParameters: Array.from({ length: 33 }, (_, index) => [index]), rbfWeights: Array.from({ length: 33 }, () => [0]), @@ -229,7 +232,7 @@ try { productionLayerCount, )); assert.doesNotThrow(() => validateDrowseJlensDictionary({ - hookAbi: "block-sites-v5", + hookAbi: "block-sites-v6", bindingId: productionBindingId, hiddenSize: 2, layerIndices: productionLayerIndices, @@ -283,6 +286,7 @@ try { { active: true, basis: [[1, 0, 0, 0], [0, 1, 0, 0]], + read: [[1, 0, 0, 0], [0, 1, 0, 0]], neutral: [0, 0, 0, 0], nodeParameters: [[0, 0], [1, 1]], rbfWeights: [[0, 0], [0, 0]], @@ -301,6 +305,7 @@ try { { active: true, basis: [[0, 0, 1, 0], [0, 0, 0, 1]], + read: [[0, 0, 1, 0], [0, 0, 0, 1]], neutral: [0, 0, 0, 0], nodeParameters: [[1, 0], [-1, 0]], rbfWeights: [[0, 0], [0, 0]], @@ -336,6 +341,7 @@ try { active: true, domainKind: "sphere", basis: [[1, 0, 0], [0, 1, 0], [0, 0, 1]], + read: [[1, 0, 0], [0, 1, 0], [0, 0, 1]], neutral: [0, 0, 0], nodeParameters: [[0, 1, 0], [0, 0, 1]], rbfWeights: [[0, 0, 0], [0, 0, 0]], @@ -357,6 +363,7 @@ try { rank: 1, ridge: 1, basis: [[1, 0, 0]], + read: [[1, 0, 0]], correction: [0], }, geometryProbes: [{ @@ -364,6 +371,7 @@ try { mean: [0, 0, 0], inverseMean: [0, 0, 0], basis: [[1, 0, 0], [0, 1, 0], [0, 0, 1]], + read: [[1, 0, 0], [0, 1, 0], [0, 0, 1]], gramInverse: [1, 0, 0, 0, 1, 0, 0, 0, 1], cholesky: [1, 0, 0, 0, 1, 0, 0, 0, 1], candidateWhite: [[0, 1, 0], [0, 0, 1]], @@ -501,7 +509,7 @@ try { profiles.structuredHookMemoryRequirements(exactReadoutProfile, 2, 960), profiles.structuredHookMemoryRequirements(geometryProfile, 2, 960), ); - assert.equal(profiles.resolveStructuredHookProfile("standard-v4"), exactReadoutProfile); + assert.equal(profiles.resolveStructuredHookProfile("standard-v5"), exactReadoutProfile); assert.throws( () => profiles.validateStructuredHookProfile({ ...standardProfile, maxRank: 9 }), /modified/, @@ -511,7 +519,27 @@ try { /safe integer arithmetic/, ); console.log("ok 7 - allow-listed profiles calculate checked host and WebGPU requirements"); - console.log("1..7"); + + // A typed frame reads with its dual covector and writes along the direction: a full ablation + // zeroes the reading (LEACE), which a shared read/write row would not. + const typedGroup = { + active: true, + basis: [[1, 1]], + read: [[0.5, 0.5]], + neutral: [0, 0], + target: [0], + along: 1, + kappa: [1], + }; + const typed = hooks.compileStructuredHookProgram(2, [{ affineGroups: [typedGroup] }], standardProfile); + const ablated = hooks.runStructuredHookLayer(typed, hooks.initialStructuredHookState(typed), 0, [3, 1]); + assert.deepEqual([...ablated.residual], [1, -1]); + assert.throws( + () => hooks.compileStructuredHookProgram(2, [{ affineGroups: [{ ...typedGroup, read: [[1, 1]] }] }], standardProfile), + /dual/, + ); + console.log("ok 8 - a typed affine frame reads with its read rows and writes along its basis"); + console.log("1..8"); } finally { await server.close(); } diff --git a/webui/scripts/structured-hook-units.test.mjs b/webui/scripts/structured-hook-units.test.mjs index 802b5e6..caf6b9f 100644 --- a/webui/scripts/structured-hook-units.test.mjs +++ b/webui/scripts/structured-hook-units.test.mjs @@ -1,14 +1,11 @@ -// Hook ABI v5 (block-sites-v5): the standard-v4 profiles, descriptor schema 4 and the -// drowse-structured-v4 unit section, pinned against B1-hook-abi-v5.md §3.1/§3.4/§3.5 and the -// drowse unit-ablation goldens (drowse/tests/fixtures/browser/unit-ablation--v1.json). +// Hook ABI v5 (block-sites-v6): the standard-v5 profiles, descriptor schema 4 and the +// drowse-structured-v5 unit section, pinned against B1-hook-abi-v5.md §3.1/§3.4/§3.5. import assert from "node:assert/strict"; import { readFileSync } from "node:fs"; import { fileURLToPath } from "node:url"; import { createServer } from "vite"; const root = fileURLToPath(new URL("..", import.meta.url)); -const fixtures = fileURLToPath(new URL("../../drowse/tests/fixtures/browser/", import.meta.url)); -const golden = (name) => JSON.parse(readFileSync(`${fixtures}${name}`, "utf8")); const server = await createServer({ root, configFile: false, @@ -17,13 +14,6 @@ const server = await createServer({ server: { middlewareMode: true, watch: null }, }); -function decodeF32(entry) { - assert.equal(entry.encoding, "float32-le-base64"); - const bytes = Buffer.from(entry.data, "base64"); - const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength); - return Float32Array.from({ length: bytes.byteLength / 4 }, (_, i) => view.getFloat32(4 * i, true)); -} - const typedKeys = (program) => Object.keys(program).filter((key) => ArrayBuffer.isView(program[key])).sort(); @@ -32,8 +22,8 @@ try { server.ssrLoadModule("/src/hosted/runtime/structuredHookProfile.ts"), server.ssrLoadModule("/src/hosted/runtime/structuredHookProgram.ts"), ]); - const v4 = profiles.STANDARD_STRUCTURED_HOOK_PROFILE_V4; - const residual = profiles.STANDARD_STRUCTURED_HOOK_PROFILE_V4_RESIDUAL; + const v4 = profiles.STANDARD_STRUCTURED_HOOK_PROFILE_V5; + const residual = profiles.STANDARD_STRUCTURED_HOOK_PROFILE_V5_RESIDUAL; // ---------------------------------------------------------------- profiles (§3.5) --- // The two v5 profiles share the steering, probe and geometry capacities and differ in units. @@ -66,21 +56,21 @@ try { maxPatternLayers: 0, maxPatternHeads: 0, maxLensReadTopK: 256, maxAnatomyUnits: 0, }); assert.equal(profiles.validateStructuredHookProfile({ ...v4 }), v4); - assert.equal(profiles.resolveStructuredHookProfile("standard-v4-residual"), residual); + assert.equal(profiles.resolveStructuredHookProfile("standard-v5-residual"), residual); assert.throws(() => profiles.validateStructuredHookProfile({ ...v4, maxUnitTaps: 65 }), /was modified/); const { maxPatternHeads: _dropped, ...missing } = v4; assert.throws(() => profiles.validateStructuredHookProfile(missing), /unsupported shape/); assert.throws(() => profiles.validateStructuredHookProfile(shared(v4)), /Unsupported structured hook capacity profile/); // Only the two v5 profiles resolve. - for (const id of ["unknown-profile", "standard-v4-units", ""]) { + for (const id of ["unknown-profile", "standard-v5-units", ""]) { assert.throws(() => profiles.resolveStructuredHookProfile(id), /Unsupported structured hook capacity profile/); } - assert.equal(profiles.BLOCK_SITES_HOOK_ABI, "block-sites-v5"); - assert.equal(profiles.BLOCK_SITES_RUNTIME_ABI, "drowse-web-runtime-v2"); + assert.equal(profiles.BLOCK_SITES_HOOK_ABI, "block-sites-v6"); + assert.equal(profiles.BLOCK_SITES_RUNTIME_ABI, "drowse-web-runtime-v3"); assert.equal(profiles.BLOCK_SITES_EXACT_READOUT_ABI, "exact-readout-v2"); // ------------------------------------------------------------- BlockSpec (§8.2) --- - const tiny = golden("units-tiny-models-v1.json").arches; + const tiny = JSON.parse(readFileSync(new URL("../src/hosted/runtime/fixtures/units-tiny-models-v1.json", import.meta.url), "utf8")).arches; const tinySpec = (arch) => { const config = tiny[arch].config; const gemma = arch === "gemma3"; @@ -117,7 +107,7 @@ try { assert.throws(() => profiles.validateBlockSpec({ ...specs.qwen3, nKvHeads: 3 }), /multiple of nKvHeads/); assert.throws(() => profiles.validateBlockSpec({ ...specs.qwen3, activation: "gelu" }), /silu or gelu_tanh/); assert.throws(() => profiles.validateBlockSpec({ ...specs.qwen3, extra: 1 }), /unsupported shape/); - // B1-goldens: token-anatomy taps are `L × 544` on the 64-wide fixture models. + // B1: token-anatomy taps are `L × 544` on the 64-wide fixture models. assert.equal(profiles.anatomyStride(64, specs.qwen3), 544); assert.equal(profiles.anatomyStride(64, specs.gemma3), 544); // B1 §2.3's production strides. @@ -169,7 +159,7 @@ try { const named = (values) => Object.fromEntries(fields.map((name, i) => [name, values[i]])); const qwen = named(profiles.expectedHookProfileDescriptor(v4, model("qwen3"))); assert.deepEqual(Object.values(qwen).slice(0, 31), [ - 0x53414b4c, 4, 4, 5, 4, 4, 64, 4, 8, 8, 4, 32, 4, 8, 671, 32768, 8, 96, 33, 41, 3, 12, 2, 4, + 0x53414b4c, 4, 5, 6, 5, 4, 64, 4, 8, 8, 4, 32, 4, 8, 671, 32768, 8, 96, 33, 41, 3, 12, 2, 4, 8, 8, 7, payload(4, 64), 2, 8, 16384, ]); assert.deepEqual(Object.values(qwen).slice(31), [ @@ -217,12 +207,12 @@ try { ]); assert.deepEqual(profiles.hookProfileDescriptorMismatches(expected, expected), []); assert.deepEqual(profiles.hookProfileDescriptorMismatches(expected.slice(0, 31), expected), ["LENGTH"]); - assert.equal(profiles.hookProfileDescriptorProfileId(expected), "standard-v4"); + assert.equal(profiles.hookProfileDescriptorProfileId(expected), "standard-v5"); assert.equal( profiles.hookProfileDescriptorProfileId( profiles.expectedHookProfileDescriptor(residual, { ...model("qwen3"), blockSpec: null }), ), - "standard-v4-residual", + "standard-v5-residual", ); assert.throws(() => profiles.hookProfileDescriptorProfileId(expected.slice(0, 31)), /not schema 4/); @@ -319,7 +309,7 @@ try { // ------------------ only the v4 profiles compile; a v4 program without units has no section --- const layers = [ { - affineGroups: [{ active: true, basis: [[1, 0], [0, 1]], neutral: [0, 0], target: [1, 0], along: 0.5, kappa: [0, 1] }], + affineGroups: [{ active: true, basis: [[1, 0], [0, 1]], read: [[1, 0], [0, 1]], neutral: [0, 0], target: [1, 0], along: 0.5, kappa: [0, 1] }], probes: [{ kind: "linear", direction: [1, 0], bias: -0.25 }], }, { probes: [{ kind: "linear", direction: [0, 1], bias: 0 }] }, @@ -331,14 +321,14 @@ try { /Unsupported structured hook capacity profile/, ); const programV4 = hooks.compileStructuredHookProgram(2, layers, v4); - assert.equal(programV4.format, "drowse-structured-v4"); - assert.equal(programV4.hookAbi, "block-sites-v5"); + assert.equal(programV4.format, "drowse-structured-v5"); + assert.equal(programV4.hookAbi, "block-sites-v6"); assert.equal(hooks.withStructuredUnitSection(programV4, shape, { ablations: [], taps: [], controls: [] }), programV4); assert.equal(hooks.hasStructuredUnitSection(programV4), false); assert.deepEqual(hooks.structuredTapGramHeads(programV4), []); assert.deepEqual(hooks.decodeStructuredUnitTables(programV4), []); const residualProgram = hooks.compileStructuredHookProgram(2, layers, residual); - assert.equal(residualProgram.format, "drowse-structured-v4"); + assert.equal(residualProgram.format, "drowse-structured-v5"); assert.throws( () => hooks.withStructuredUnitSection(residualProgram, shape, units), (error) => error.code === "UNIT_SECTION_UNSUPPORTED" && error.status === 422, @@ -462,69 +452,12 @@ try { } assert.deepEqual(hooks.runStructuredUnitSite(programV4, 2, "act", act, [0, 1, 2]), act); - // ------------------- the unit-ablation goldens: native tables round-trip the v4 layout --- - for (const arch of ["qwen3", "gemma3"]) { - const ablation = golden(`unit-ablation-${arch}-v1.json`); - assert.equal(ablation.hookAbi, "block-sites-v5"); - const config = tiny[arch].config; - const archShape = { dFF: config.intermediate_size, nHeads: config.num_attention_heads, headDim: config.head_dim }; - const base = hooks.compileStructuredHookProgram(config.hidden_size, Array.from({ length: config.num_hidden_layers }, () => ({})), v4); - let checked = 0; - for (const testCase of ablation.cases) { - if (testCase.tables === null) continue; - const triggers = []; - const nativeTables = testCase.tables.map((table) => { - const key = JSON.stringify(table.trigger); - if (!triggers.includes(key)) triggers.push(key); - return { ...table, group: triggers.indexOf(key) }; - }); - const ablations = hooks.structuredUnitAblationsFromTables(nativeTables, archShape); - const program = hooks.withStructuredUnitSection(base, archShape, { - ablations, taps: [], controls: triggers.map(() => null), - }); - const decoded = hooks.decodeStructuredUnitTables(program); - const keyOf = (table) => `${table.layer}/${table.site}/${table.group}`; - assert.deepEqual(decoded.map(keyOf).sort(), nativeTables.map(keyOf).sort(), `${arch} ${testCase.name}`); - for (const table of nativeTables) { - const mine = decoded.find((entry) => keyOf(entry) === keyOf(table)); - assert.equal(mine.width, table.width); - assert.deepEqual(mine.entries, table.entries, `${arch} ${testCase.name} entries`); - assert.deepEqual(mine.keep, table.keep.map(Math.fround), `${arch} ${testCase.name} keep`); - assert.deepEqual(mine.bias, table.bias.map(Math.fround), `${arch} ${testCase.name} bias`); - } - checked += 1; - } - assert.ok(checked >= 7, `${arch}: every case with unit terms was checked`); - - // Native's fp32 lowering (keep = 1 − α, bias = α·mean) against the recorded tables and - // the recorded neutral means. - const stats = golden(`unit-stats-${arch}-v1.json`); - const neuronMean = decodeF32(stats.neuron_mean); - const dFF = stats.neuron_mean.shape[1]; - const coefficients = ablation.cases.find((entry) => entry.name === "coefficients"); - const act2 = coefficients.tables.find((table) => table.site === "act"); - const alphaOf = { 7: 0.5, 8: 2 }; - act2.entries.forEach((index, at) => { - const term = hooks.structuredUnitAblationTerm("neuron", act2.layer, index, alphaOf[index], neuronMean[act2.layer * dFF + index], 0); - assert.equal(term.keep, Math.fround(act2.keep[at]), `${arch} keep of L${act2.layer}n${index}`); - assert.equal(term.bias, Math.fround(act2.bias[at]), `${arch} bias of L${act2.layer}n${index}`); - }); - const head = coefficients.tables.find((table) => table.site === "z"); - const hd = archShape.headDim; - const headIndex = head.entries[0] / hd; - const [, heads, headWidth] = stats.head_mean.shape; - const headStart = (head.layer * heads + headIndex) * headWidth; - const headMean = stats.head_mean.values.slice(headStart, headStart + headWidth); - const headTerm = hooks.structuredUnitAblationTerm("head", head.layer, headIndex, -1, headMean, 0); - assert.equal(headTerm.keep, Math.fround(head.keep[0])); - assert.deepEqual(Array.from(headTerm.bias), head.bias.map(Math.fround), `${arch} head bias`); - } assert.throws( () => hooks.structuredUnitAblationsFromTables([{ layer: 0, site: "z", width: 64, group: 0, entries: [1, 2], keep: [0, 0], bias: [0, 0] }], shape), /whole heads/, ); - console.log("structured-hook units: profiles, descriptor schema 4, unit section and goldens pass"); + console.log("structured-hook units: profiles, descriptor schema 4 and unit section pass"); } finally { await server.close(); } diff --git a/webui/scripts/support/core-pack.mjs b/webui/scripts/support/core-pack.mjs deleted file mode 100644 index f5c0d7e..0000000 --- a/webui/scripts/support/core-pack.mjs +++ /dev/null @@ -1,176 +0,0 @@ -// A verified core-pack load request of any width and depth, for replaying drowse's goldens -// through the real structured compiler (`BrowserFeasibilityCorePackCompiler.load`): low-rank -// neutral whiteners, flat and one-node manifolds (`basis`, `nodeCoordinates` per layer) and -// curved ones (a 1-D box curve; only its fitted layers and baked Mahalanobis shares matter to -// layer placement). The archive layout is browser-core-pack.test.mjs's fixture's. -import { createHash } from "node:crypto"; - -const sha256 = (bytes) => createHash("sha256").update(bytes).digest("hex"); - -function canonicalJson(value) { - if (Array.isArray(value)) return `[${value.map(canonicalJson).join(",")}]`; - if (value !== null && typeof value === "object") { - return `{${Object.keys(value).sort().map((key) => `${JSON.stringify(key)}:${canonicalJson(value[key])}`).join(",")}}`; - } - return JSON.stringify(value); -} - -function discoverNodesHash(labels, payloads, fitMode, roles) { - const hash = createHash("sha256"); - hash.update(canonicalJson(labels)); - for (const payload of payloads) hash.update(payload); - hash.update(canonicalJson({ fit_mode: fitMode, hyperparams: {} })); - hash.update(canonicalJson(roles)); - hash.update(canonicalJson(roles.map(() => "abstract"))); - return hash.digest("hex"); -} - -const f32 = (shape, values) => ({ shape, data: Float32Array.from(values) }); - -/** - * `spec`: - * - `hiddenSize`, `layerCount`, `structuredHookProfile` (default `standard-v4`), `modelId`; - * - `whiteners`: `[{layer, mean, basis: [[d]…], eigenvalues, ridge}]`; - * - `manifolds`: `[{name, labels, layers: [{layer, mean?, basis: [[d]…], nodeCoordinates: [[r]…]}], - * nodeCoordinates?, shares?}]` (flat), or `{name, labels, curved: true, layers: [{layer, - * mahalanobisShare}]}`. - */ -export async function corePackRequest(server, spec) { - const { buildDrowseArchive, encodeFp32Safetensors, jsonBytes } = await server.ssrLoadModule("/src/hosted/artifacts/index.ts"); - const d = spec.hiddenSize; - const fingerprint = "a".repeat(64); - const binding = "b".repeat(64); - const manifests = []; - const artifacts = []; - const add = (path, bytes) => { - const manifest = { path, role: "core_pack", url: `https://example.test/${path}`, revision: "1".repeat(40), bytes: bytes.length, sha256: sha256(bytes) }; - manifests.push(manifest); - artifacts.push({ manifest, file: new File([bytes], path) }); - return manifest; - }; - for (const manifold of spec.manifolds ?? []) { - const { name, labels } = manifold; - const curved = manifold.curved === true; - const fitMode = curved ? "spectral" : "pca"; - const roles = labels.map(() => null); - const nodeFiles = Object.fromEntries(labels.map((label, index) => [ - `manifolds/local/${name}/nodes/${String(index).padStart(2, "0")}_${label}.json`, - jsonBytes([label]), - ])); - const n = labels.length; - const tensors = {}; - let fitted; - let shares; - if (curved) { - // A 1-D curve through the first two axes: node t_i = i/n, mean 0, basis e0, e1. - tensors.node_coords = f32([n, 1], labels.map((_, i) => i / n)); - fitted = manifold.layers.map((row) => row.layer); - shares = Object.fromEntries(manifold.layers.map((row) => [String(row.layer), row.mahalanobisShare])); - for (const layer of fitted) { - const p = `layer_${layer}`; - tensors[`${p}.mean`] = f32([d], new Array(d).fill(0)); - tensors[`${p}.basis`] = f32([2, d], [...Array.from({ length: d }, (_, i) => (i === 0 ? 1 : 0)), ...Array.from({ length: d }, (_, i) => (i === 1 ? 1 : 0))]); - tensors[`${p}.node_params`] = f32([n, 1], labels.map((_, i) => i / n)); - tensors[`${p}.rbf_weights`] = f32([n, 2], new Array(2 * n).fill(0)); - tensors[`${p}.poly_coeffs`] = f32([2, 2], [0, 0, 1, 0.5]); - tensors[`${p}.coord_offset`] = f32([1], [0]); - tensors[`${p}.coord_scale`] = f32([1], [1]); - tensors[`${p}.sigma_rbf_weights`] = f32([n, 1], new Array(n).fill(0)); - tensors[`${p}.sigma_poly_coeffs`] = f32([2, 1], [-20, 0]); - } - } else { - tensors.node_coords = f32([n, 1], manifold.nodeCoordinates ?? labels.map((_, i) => (n === 1 ? 1 : -1 + (2 * i) / (n - 1)))); - fitted = manifold.layers.map((row) => row.layer); - shares = Object.fromEntries(fitted.map((layer) => [String(layer), manifold.shares?.[layer] ?? 1])); - for (const row of manifold.layers) { - const p = `layer_${row.layer}`; - const rank = row.basis.length; - tensors[`${p}.mean`] = f32([d], row.mean ?? new Array(d).fill(0)); - tensors[`${p}.basis`] = f32([rank, d], row.basis.flat()); - tensors[`${p}.node_coords`] = f32([n, rank], row.nodeCoordinates.flat()); - } - } - const tensorBytes = encodeFp32Safetensors(tensors); - const tensorName = "_zdGVzdC9tb2RlbA.safetensors"; - const sidecarName = tensorName.replace(".safetensors", ".json"); - const sidecar = jsonBytes({ - format_version: 10, name, method: curved ? "manifold_discover_spectral" : "manifold_discover_pca", - drowse_version: "test", fit_mode: fitMode, hyperparams: {}, diagnostics: {}, - node_count: n, node_labels: labels, node_roles: roles, node_kinds: labels.map(() => "abstract"), - domain: curved - ? { type: "box", axes: [{ name: "t", periodic: false, period: 1, lo: 0, hi: 1 }] } - : { type: "custom", embed_dim: 1, bounds: null }, - node_spread_per_layer: {}, fitted_layers: fitted, mahalanobis_share_per_layer: shares, - origin_per_layer: curved ? Object.fromEntries(fitted.map((layer) => [String(layer), [0]])) : {}, - feature_space: "raw", nodes_sha256: discoverNodesHash(labels, Object.values(nodeFiles), fitMode, roles), - sae_release: null, sae_revision: null, sae_fingerprint: null, sae_ids_by_layer: {}, sae_full_coverage: false, - model_fingerprint: fingerprint, context_binding_sha256: binding, model_source_fingerprint: null, - capture_sha256: null, capture_version: null, capture_render_sha256: null, baseline_prompts_sha256: null, - fit_policy_version: 1, share_metric: "mahalanobis", subspace_metric: "mahalanobis", - rbf_smoothing_per_layer: curved ? Object.fromEntries(fitted.map((layer) => [String(layer), { lambda: 0, edf: 2, gcv: 0 }])) : {}, - sigma_field_per_layer: curved ? Object.fromEntries(fitted.map((layer) => [String(layer), { sigma_mean: 0, sigma_min: 0, sigma_max: 0, lambda: 0 }])) : {}, - resolved_fit_mode: null, topology_winner: null, topology_candidates: [], components: null, bake_policy: null, - source_model_id: null, source_model_fingerprint: null, transfer_quality_estimate: null, - }); - const manifest = jsonBytes({ - format_version: 10, name, description: "golden replay fixture", fit_mode: fitMode, hyperparams: {}, - nodes: labels.map((label) => ({ label, role: null, kind: "abstract" })), - files: { [tensorName]: sha256(tensorBytes), [sidecarName]: sha256(sidecar) }, - source: "local", tags: [], template_ref: null, - }); - const archive = await buildDrowseArchive({ - primary: `manifolds/local/${name}`, - template: null, - producerVersion: "browser-core-test", - source: { uri: "local", repository: null, revision: null }, - files: { - [`manifolds/local/${name}/manifold.json`]: manifest, - ...nodeFiles, - [`manifolds/local/${name}/${tensorName}`]: tensorBytes, - [`manifolds/local/${name}/${sidecarName}`]: sidecar, - }, - }); - add(`core/${name}.drowse`, new Uint8Array(await archive.arrayBuffer())); - } - if (spec.whiteners?.length) { - const tensors = {}; - for (const row of spec.whiteners) { - const p = `layer_${row.layer}`; - tensors[`${p}.mean`] = f32([d], row.mean); - tensors[`${p}.basis`] = f32([row.basis.length, d], row.basis.flat()); - tensors[`${p}.eigenvalues`] = f32([row.eigenvalues.length], row.eigenvalues); - tensors[`${p}.inverse_scales`] = f32([row.eigenvalues.length], row.eigenvalues.map((e) => 1 / Math.sqrt(e + row.ridge))); - } - const tensorBytes = encodeFp32Safetensors(tensors); - const tensorManifest = add("core/neutral-whitener.safetensors", tensorBytes); - add("core/neutral-whitener.json", jsonBytes({ - format_version: 1, - runtime_identity_sha256: fingerprint, - context_binding_sha256: binding, - hidden_size: d, - layer_map: Array.from({ length: spec.layerCount }, (_, i) => i), - tensors_sha256: tensorManifest.sha256, - ridge_per_layer: Object.fromEntries(spec.whiteners.map((row) => [String(row.layer), row.ridge])), - })); - } - const runtimeIdentity = { - sourceModel: "test/model", sourceRevision: "2".repeat(40), convertedManifestSha256: "3".repeat(64), - quantization: "q4f32_1", tokenizerSha256: "4".repeat(64), chatTemplateSha256: "5".repeat(64), - modelLibrarySha256: "6".repeat(64), runtimeAbi: "drowse-browser-v1", hookAbi: "post-block-residual-v4", - hiddenSize: d, layerMap: Array.from({ length: spec.layerCount }, (_, i) => i), - }; - return { - model: { id: spec.modelId ?? "fixture-model" }, - variant: { - structuredHookProfile: spec.structuredHookProfile ?? "standard-v4", - runtimeIdentity, - runtimeIdentitySha256: fingerprint, - contextProfiles: [{ contextTokens: 2048, bindingSha256: binding }], - }, - requiredCorePack: { files: manifests }, - artifacts, - optionalPacks: [], - contextTokens: 2048, - signal: new AbortController().signal, - }; -} diff --git a/webui/scripts/support/units-compiler.mjs b/webui/scripts/support/units-compiler.mjs deleted file mode 100644 index ea9c46b..0000000 --- a/webui/scripts/support/units-compiler.mjs +++ /dev/null @@ -1,49 +0,0 @@ -// The structured compiler over the tiny fixture model, as the model load would set it up: a core -// pack holding the fixture session's neutral whitener (and the `deceptive_fixture` concept -// drowse registers in Python for unit-ablation's `mixed` case), and the units service's program -// source over the reference backend and B6-shaped packs. `compile` prepares first, as -// `compileSteering` does. -import { readFileSync } from "node:fs"; -import { corePackRequest } from "./core-pack.mjs"; -import { unitsPackSource } from "./units-fixture.mjs"; - -export const fixtureWhiteners = JSON.parse(readFileSync(new URL("../../../browser-runtime/fixtures/units-tiny-whitener-v1.json", import.meta.url), "utf8")); - -export async function unitsCompiler(server, fx, arch) { - const [{ BrowserFeasibilityCorePackCompiler }, service] = await Promise.all([ - server.ssrLoadModule("/src/hosted/runtime/browserCorePack.ts"), - server.ssrLoadModule("/src/hosted/runtime/units/unitsService.ts"), - ]); - const d = fx.model.hiddenSize; - const unit = (n) => Array.from({ length: d }, (_, i) => (i === n ? 1 : 0)); - const request = await corePackRequest(server, { - hiddenSize: d, - layerCount: 4, - modelId: "units-tiny", - whiteners: fixtureWhiteners.arches[arch].map((row) => ({ layer: row.layer, mean: row.mean, basis: row.basis, eigenvalues: row.eigenvalues, ridge: row.ridge })), - manifolds: [{ - name: "deceptive_fixture", - labels: ["deceptive_fixture_pole", "deceptive_fixture_anti"], - nodeCoordinates: [1, -1], - layers: [0, 1, 2, 3].map((layer) => ({ layer, basis: [unit(layer)], nodeCoordinates: [[1], [-1]] })), - }], - }); - const compiler = await BrowserFeasibilityCorePackCompiler.load(request); - const units = new service.BrowserUnitsService({ - modelId: "units-tiny", - blockSites: () => fx.backend, - packs: () => unitsPackSource(fx, arch, fixtureWhiteners), - tokenTexts: async (ids) => ids.map((id) => fx.tokenizer.decode([id])), - resolveToken: async (word) => fx.tokenizer.encode(word)[0], - replay: () => null, - }); - compiler.setUnitSource(await units.programSource()); - return { - compiler, - units, - async compile(expression) { - await compiler.prepareUnitSelectors(expression); - return compiler.compile(expression); - }, - }; -} diff --git a/webui/scripts/support/units-fixture.mjs b/webui/scripts/support/units-fixture.mjs deleted file mode 100644 index d0e46b9..0000000 --- a/webui/scripts/support/units-fixture.mjs +++ /dev/null @@ -1,115 +0,0 @@ -// The tiny fixture session as the host ports see it, per arch: the reference backend over the -// generated weights, the hand-built lenses, the corpus-count token mask and the neutral means -// (unit-stats golden), mirroring drowse's `tests/support/browser_units.py::fixture`. -import { archGolden, decode, golden } from "./units-goldens.mjs"; - -export const DROPPED_SYMBOLS = "QXZqxz#$%^`|"; - -export async function unitsFixture(server, arch, options = {}) { - const [tiny, cpu, context, profiles] = await Promise.all([ - server.ssrLoadModule("/src/hosted/runtime/units/tinyModels.ts"), - server.ssrLoadModule("/src/hosted/runtime/units/cpuBackend.ts"), - server.ssrLoadModule("/src/hosted/runtime/units/referenceContext.ts"), - server.ssrLoadModule("/src/hosted/runtime/structuredHookProfile.ts"), - ]); - const file = golden("units-tiny-models-v1.json"); - const record = file.arches[arch]; - const model = tiny.tinyModelWeights(file, arch); - const tokenizer = tiny.tinyTokenizer(record); - const backend = cpu.cpuBlockSitesBackend(model, { - profile: profiles.STANDARD_STRUCTURED_HOOK_PROFILE_V4, - contextTokens: 256, - }); - const dropped = new Set([...DROPPED_SYMBOLS].map((symbol) => tokenizer.idOfByte(symbol.charCodeAt(0)))); - const keep = Uint8Array.from({ length: model.vocabSize }, (_, v) => - v < tokenizer.size && tokenizer.byteOf[v] >= 0 && !tokenizer.decode([v]).includes("�") && !dropped.has(v) ? 1 : 0); - const stats = archGolden("unit-stats", arch); - const means = { out: Float32Array.from(decode(stats.out_mean)), mid: Float32Array.from(decode(stats.mid_mean)) }; - const lenses = tiny.tinyLenses(file, arch); - const selected = new Map([...lenses].filter(([key]) => - (options.families ?? ["R", "S"]).includes(key[0]) && !(options.drop ?? []).includes(key))); - const readContext = context.referenceReadContext({ - backend, - model, - modelId: options.modelId ?? "", - band: { lo: file.band[0], hi: file.band[1] }, - lenses: selected, - keep, - mask: { source: "corpus", detail: "corpus counts over 1,000,000 tokens of units-tiny-fixture, kept at 1+" }, - means, - decode: (id) => tokenizer.decode([id]), - }); - return { file, record, model, tokenizer, backend, keep, means, lenses, context: readContext, stats }; -} - -/** `wᵀ P w` over a `[d, d]` projector (the golden stores the null basis's projector). */ -export function projectorEnergy(projector, d) { - return async (w) => { - let quad = 0; - for (let i = 0; i < d; i += 1) { - let row = 0; - for (let j = 0; j < d; j += 1) row += projector[i * d + j] * w[j]; - quad += w[i] * row; - } - return quad; - }; -} - -/** The fixture as B6's packs would serve it (`UnitsPackSource`): unit-stats, unit-artifacts, - * slens statistics, the hand-built lenses and the exported fixture whitener. */ -export function unitsPackSource(fx, arch, whiteners, options = {}) { - const stats = fx.stats; - const artifacts = archGolden("unit-artifacts", arch); - const slens = archGolden("slens", arch); - const tables = new Map(artifacts.layers.map((entry) => [ - entry.layer, - new Map(Object.entries(entry.tensors).map(([key, value]) => [key, Float32Array.from(decode(value))])), - ])); - const mask = new Uint32Array(Math.ceil(fx.model.vocabSize / 32)); - for (const v of slens.mask.kept) mask[v >>> 5] |= 1 << (v & 31); - const lens = (family) => { - const sites = ["out", "mid"].filter((site) => fx.lenses.has(`${family}:${site}`) && !(options.drop ?? []).includes(`${family}:${site}`)); - if (sites.length === 0) return null; - return { - source: `local:${family.toLowerCase()}`, - identity: `units-tiny-${arch}-${family.toLowerCase()}`, - sites, - layers: (site) => [...(fx.lenses.get(`${family}:${site}`)?.keys() ?? [])].sort((a, b) => a - b), - fetch: async (site, layer) => fx.lenses.get(`${family}:${site}`).get(layer), - }; - }; - return { - band: { lo: fx.file.band[0], hi: fx.file.band[1] }, - statistics: async () => ({ - statistics: { - documents: stats.n_documents, - neuronMean: Float32Array.from(decode(stats.neuron_mean)), - neuronScale: Float32Array.from(decode(stats.neuron_scale)), - headMean: Float32Array.from(decode(stats.head_mean)), - headScale: Float32Array.from(decode(stats.head_scale)), - }, - absent: null, - }), - means: async () => fx.means, - lens, - embeddingStatistics: async () => ({ - meanE: Float32Array.from(decode(slens.mean_E)), - sigmaE: Float32Array.from(decode(slens.sigma_E)), - mask, - source: slens.mask.source, - detail: slens.mask.detail, - maskDigest: "tokenizer", - }), - layerArtifacts: async (layer) => tables.get(layer), - nullProjection: projectorEnergy(Float32Array.from(decode(artifacts.null.projector)), fx.model.hiddenSize), - headKeptIds: async () => Int32Array.from(artifacts.head_kept_ids), - whitener: async (layer) => { - const entry = whiteners?.arches[arch].find((row) => row.layer === layer); - return entry ? { - columns: fx.model.hiddenSize, rank: entry.eigenvalues.length, ridge: entry.ridge, - mean: Float64Array.from(entry.mean), basis: Float64Array.from(entry.basis.flat()), - eigenvalues: Float64Array.from(entry.eigenvalues), inverseScales: new Float64Array(entry.eigenvalues.length), - } : null; - }, - }; -} diff --git a/webui/scripts/support/units-goldens.mjs b/webui/scripts/support/units-goldens.mjs deleted file mode 100644 index 6e7763b..0000000 --- a/webui/scripts/support/units-goldens.mjs +++ /dev/null @@ -1,117 +0,0 @@ -// Shared helpers for the hook ABI v5 script tests: load drowse's units goldens -// (drowse/tests/fixtures/browser/--v1.json), decode their arrays and compare within -// each file's tolerance block, matching declared ties by identity (lanes/B3.md). -import assert from "node:assert/strict"; -import { readFileSync } from "node:fs"; -import { fileURLToPath } from "node:url"; -import { createServer } from "vite"; - -export const webuiRoot = fileURLToPath(new URL("../..", import.meta.url)); -const fixtures = fileURLToPath(new URL("../../../drowse/tests/fixtures/browser/", import.meta.url)); - -export const golden = (name) => JSON.parse(readFileSync(`${fixtures}${name}`, "utf8")); -export const archGolden = (name, arch) => golden(`${name}-${arch}-v1.json`); -export const ARCHES = ["gemma3", "qwen3"]; - -export async function viteServer() { - return createServer({ - root: webuiRoot, - configFile: false, - appType: "custom", - logLevel: "silent", - server: { middlewareMode: true, watch: null }, - }); -} - -/** `encode`'s inverse: a list, an inline `{shape, values}` or a base64 record → typed array. */ -export function decode(value) { - if (Array.isArray(value)) return Float64Array.from(value); - if (value && value.encoding) { - const bytes = Buffer.from(value.data, "base64"); - const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength); - if (value.dtype === "int32") return Int32Array.from({ length: bytes.length / 4 }, (_, i) => view.getInt32(4 * i, true)); - if (value.dtype === "float16") return Uint16Array.from({ length: bytes.length / 2 }, (_, i) => view.getUint16(2 * i, true)); - return Float32Array.from({ length: bytes.length / 4 }, (_, i) => view.getFloat32(4 * i, true)); - } - if (value && Array.isArray(value.values)) return Float64Array.from(value.values); - throw new TypeError("not an encoded array"); -} - -export const shapeOf = (value) => (Array.isArray(value) ? [value.length] : value.shape); - -/** Max violation of `|a − b| ≤ atol + rtol·|b|` (≤ 0 passes). */ -export function closeness(actual, expected, atol, rtol = 0) { - assert.equal(actual.length, expected.length, "length"); - let worst = -Infinity; - let at = -1; - for (let i = 0; i < expected.length; i += 1) { - const excess = Math.abs(actual[i] - expected[i]) - (atol + rtol * Math.abs(expected[i])); - if (!(excess <= worst) || Number.isNaN(excess)) { - worst = Number.isNaN(excess) ? Infinity : excess; - at = i; - } - } - return { worst, at }; -} - -export function assertClose(actual, expected, tol, label) { - const { worst, at } = closeness(actual, expected, tol.atol, tol.rtol ?? 0); - assert.ok( - worst <= 0, - `${label}: element ${at} is ${actual[at]}, expected ${expected[at]} (excess ${worst})`, - ); -} - -/** Deep comparison of a JSON result against the golden's: numbers within `atol` (rounded record - * fields, 2e-6) or `numberTol(path)`, strings and structure exact, declared tie runs matched by - * identity (B3: `{path, key, groups}`). */ -export function compareRecord(actual, expected, options = {}) { - const ties = new Map((options.ties ?? []).map((tie) => [tie.path, tie])); - const problems = []; - const tolFor = options.numberTol ?? (() => 2e-6); - const walk = (a, e, path) => { - if (problems.length > 20) return; - if (typeof e === "number") { - if (typeof a !== "number" || !(Math.abs(a - e) <= tolFor(path, e))) problems.push(`${path}: ${a} != ${e}`); - return; - } - if (e === null || typeof e !== "object") { - if (a !== e) problems.push(`${path}: ${JSON.stringify(a)} != ${JSON.stringify(e)}`); - return; - } - if (Array.isArray(e)) { - if (!Array.isArray(a) || a.length !== e.length) { - problems.push(`${path}: length ${Array.isArray(a) ? a.length : typeof a} != ${e.length}`); - return; - } - const tie = ties.get(path.replace(/^\./, "")); - let order = e.map((_, i) => i); - if (tie) { - const ident = (x) => JSON.stringify(tie.key.map((k) => x[k])); - for (const group of tie.groups) { - const want = group.map((i) => ident(e[i])).sort(); - const got = group.map((i) => ident(a[i])).sort(); - if (JSON.stringify(want) !== JSON.stringify(got)) problems.push(`${path}: tie run ${group} differs`); - for (const i of group) { - const j = group.find((g) => ident(a[g]) === ident(e[i])); - if (j !== undefined) order[i] = j; - } - } - } - e.forEach((item, i) => walk(a[order[i]], item, `${path}[${i}]`)); - return; - } - if (a === null || typeof a !== "object") { - problems.push(`${path}: ${JSON.stringify(a)} is not an object`); - return; - } - const keys = new Set([...Object.keys(e), ...Object.keys(a)]); - for (const key of keys) { - if (!(key in e)) problems.push(`${path}.${key}: unexpected`); - else if (!(key in a)) problems.push(`${path}.${key}: missing`); - else walk(a[key], e[key], `${path}.${key}`); - } - }; - walk(actual, expected, options.root ?? ""); - return problems; -} diff --git a/webui/scripts/support/units-tiny-packs.py b/webui/scripts/support/units-tiny-packs.py deleted file mode 100644 index b4c4095..0000000 --- a/webui/scripts/support/units-tiny-packs.py +++ /dev/null @@ -1,52 +0,0 @@ -"""Build the hosted R, S, core-statistics and units packs for drowse's tiny ABI v5 fixture -model (`build_hosted_packs.build`, as tests/test_hosted_packs.py builds them) into OUT, and print -what native computes for them: the build record, the runtime record and the S mask digest -(`LensInstrument._mask_digest`). scripts/units-pack-source.test.mjs reads the packs back -through the browser registry.""" - -from __future__ import annotations - -import json -import sys -from pathlib import Path - -ROOT = Path(__file__).resolve().parents[3] -sys.path.insert(0, str(ROOT / "browser-runtime")) -sys.path.insert(0, str(ROOT / "drowse")) - -from build_hosted_packs import KINDS, NativeModel, build # noqa: E402 -from tests.support.browser_units import fixture # noqa: E402 - - -def main() -> None: - """``units-tiny-packs.py ARCH OUT [RUNTIME_JSON]``: RUNTIME_JSON (``{modelId, - runtimeIdentity, runtimeIdentitySha256}``) binds the packs to a staged fixture library - (scripts/browser-units-worker.mjs); without it they bind to a placeholder identity.""" - arch, out = sys.argv[1], Path(sys.argv[2]) - bound = json.loads(Path(sys.argv[3]).read_text()) if len(sys.argv) > 3 else None - with fixture(arch) as fx: - model = NativeModel(fx.session) - identity = { - "sourceModel": "fixture/units-tiny", - "sourceRevision": "f" * 40, - "convertedManifestSha256": "0" * 64, - "quantization": "q0f32", - "tokenizerSha256": "1" * 64, - "chatTemplateSha256": "2" * 64, - "modelLibrarySha256": "3" * 64, - "runtimeAbi": "drowse-web-runtime-v2", - "hookAbi": "block-sites-v5", - "hiddenSize": model.d_model, - "layerMap": list(range(model.n_layers)), - } - runtime = bound or {"modelId": "units-tiny", "runtimeIdentity": identity, "runtimeIdentitySha256": "a" * 64} - record = build(model, runtime, out, KINDS, full_depth=False, words=["a", "e", "t"]) - json.dump({ - "runtime": runtime, - "record": record, - "maskDigest": model.session.lens._mask_digest(), - }, sys.stdout) - - -if __name__ == "__main__": - main() diff --git a/webui/scripts/support/units-webgpu-stage.mjs b/webui/scripts/support/units-webgpu-stage.mjs deleted file mode 100644 index dc14176..0000000 --- a/webui/scripts/support/units-webgpu-stage.mjs +++ /dev/null @@ -1,157 +0,0 @@ -// B4's tiny hook ABI v5 fixture library staged as a hosted base model: what the WebGPU harnesses -// that load it through the hosted runtime share (browser-core-build.mjs, browser-units-worker.mjs). -// -// FIXTURES holds build-units-fixtures.py's model directory `units--` and its -// library `libs/units---v5.wasm`. The model is staged under WORK as a base -// model (a tokenizer_config.json without a chat template, the capture prefix the hosted loader -// asks a base model for) or, with `chat`, as an instruct model carries one: drowse's fixture -// chat template (tests/support/tiny_models.py: ChatML for qwen3, Gemma's for gemma3) in -// tokenizer_config.json and the conversation template its production family ships -// (`chatConversation`); the block spec comes from drowse's fixture config, the runtime identity -// from the staged files' digests. -import { execFileSync } from "node:child_process"; -import { createHash } from "node:crypto"; -import { copyFile, mkdir, readFile, writeFile } from "node:fs/promises"; -import { resolve } from "node:path"; -import { fileURLToPath } from "node:url"; - -export const goldensDirectory = fileURLToPath(new URL("../../../drowse/tests/fixtures/browser", import.meta.url)); -export const sha256 = (bytes) => createHash("sha256").update(bytes).digest("hex"); - -export async function stageUnitsFixture({ fixtures, arch, quantization, work, chat = false, python = "python3" }) { - const fixture = `units-${arch}-${quantization}`; - const sourceDirectory = resolve(fixtures, fixture); - const libraryPath = resolve(fixtures, "libs", `${fixture}-v5.wasm`); - const modelDirectory = resolve(work, chat ? `${fixture}-chat` : fixture); - await mkdir(modelDirectory, { recursive: true }); - const chatConfig = JSON.parse(await readFile(resolve(sourceDirectory, "mlc-chat-config.json"), "utf8")); - chatConfig.tokenizer_files = ["tokenizer.json", "tokenizer_config.json"]; - let tokenizerConfig = { chat_template: null }; - if (chat) { - // An instruct model has no completion prefix; its conversation template renders the turns. - delete chatConfig.drowse_completion_prefix_token_ids; - chatConfig.conv_template = chatConversation(arch, chatConfig); - tokenizerConfig = { chat_template: fixtureChatTemplate(arch, python) }; - } else { - // A base model's capture prefix is its completion prefix (Gemma's BOS; nothing for Qwen). - chatConfig.conv_template = { - ...chatConfig.conv_template, - system_prefix_token_ids: chatConfig.drowse_completion_prefix_token_ids ?? [], - }; - } - await writeFile(resolve(modelDirectory, "mlc-chat-config.json"), JSON.stringify(chatConfig, null, 2)); - await writeFile(resolve(modelDirectory, "tokenizer_config.json"), JSON.stringify(tokenizerConfig)); - const tensorCache = JSON.parse(await readFile(resolve(sourceDirectory, "tensor-cache.json"), "utf8")); - const shards = tensorCache.records.map((record) => record.dataPath); - for (const name of ["tensor-cache.json", "tokenizer.json", ...shards]) { - await copyFile(resolve(sourceDirectory, name), resolve(modelDirectory, name)); - } - await copyFile(libraryPath, resolve(modelDirectory, "model.wasm")); - const roles = { - "mlc-chat-config.json": "configuration", - "tensor-cache.json": "converted_manifest", - "tokenizer.json": "tokenizer", - "tokenizer_config.json": "chat_template", - "model.wasm": "model_library", - ...Object.fromEntries(shards.map((shard) => [shard, "weight"])), - }; - const artifacts = []; - for (const [path, role] of Object.entries(roles)) { - const bytes = await readFile(resolve(modelDirectory, path)); - artifacts.push({ path, role, bytes: bytes.length, sha256: sha256(bytes) }); - } - const artifactSha = (path) => artifacts.find((artifact) => artifact.path === path).sha256; - - const tiny = JSON.parse(await readFile(resolve(goldensDirectory, "units-tiny-models-v1.json"), "utf8")).arches[arch]; - const config = tiny.config; - const gemma = arch === "gemma3"; - const blockSpec = { - dFF: config.intermediate_size, nHeads: config.num_attention_heads, - nKvHeads: config.num_key_value_heads, headDim: config.head_dim, sandwich: gemma, - normOffset: gemma ? 1 : 0, activation: gemma ? "gelu_tanh" : "silu", - embedScale: gemma ? Math.sqrt(config.hidden_size) : 1, rmsEps: config.rms_norm_eps, qkNorm: true, - attnScaling: (gemma ? config.query_pre_attn_scalar : config.head_dim) ** -0.5, - attnLogitSoftcap: null, finalLogitSoftcap: null, - ropeTheta: gemma ? config.rope_parameters.full_attention.rope_theta : config.rope_parameters.rope_theta, - ropeLocalTheta: gemma ? config.rope_parameters.sliding_attention.rope_theta : null, - ropeGlobalScale: 1, ropeInGraph: gemma, - slidingWindow: gemma ? config.sliding_window : null, slidingPattern: gemma ? 2 : null, - }; - const layerCount = config.num_hidden_layers; - const hiddenSize = config.hidden_size; - const runtimeIdentity = { - sourceModel: `drowse/units-tiny-${arch}`, - sourceRevision: "0".repeat(40), - convertedManifestSha256: artifactSha("tensor-cache.json"), - quantization, - tokenizerSha256: artifactSha("tokenizer.json"), - chatTemplateSha256: artifactSha("tokenizer_config.json"), - modelLibrarySha256: artifactSha("model.wasm"), - runtimeAbi: "drowse-web-runtime-v2", - hookAbi: "block-sites-v5", - hiddenSize, - layerMap: Array.from({ length: layerCount }, (_, layer) => layer), - }; - return { - fixture, modelDirectory, roles, artifacts, blockSpec, layerCount, hiddenSize, - contextTokens: chatConfig.context_window_size, prefillChunkSize: chatConfig.prefill_chunk_size, - runtimeIdentity, - }; -} - -/** drowse's chat template for the fixture's family, as its fixture tokenizer carries it. */ -function fixtureChatTemplate(arch, python) { - const family = { qwen3: "qwen3", gemma3: "gemma3_text" }[arch]; - return JSON.parse(execFileSync(python, ["-c", - "import json, sys; from tests.support.tiny_models import FAMILIES; print(json.dumps(FAMILIES[sys.argv[1]].chat_template))", - family, - ], { cwd: fileURLToPath(new URL("../../../drowse", import.meta.url)), encoding: "utf8" })); -} - -/** The conversation template an instruct model of the fixture's family ships with, its special - * tokens the fixture's: qwen3's ChatML (MLC `qwen3`; no system block without a system message) - * and Gemma 3's turns (MLC `gemma3_instruction`, BOS as the prefix, the system message folded - * into the first turn). The fixture's one end-of-turn token is its only stop token, as drowse's - * fixture generation config has it. */ -export function chatConversation(arch, config) { - const turnTemplates = { user: "{user_message}", assistant: "{assistant_message}", tool: "{tool_message}" }; - const common = { - add_role_after_system_message: true, role_templates: turnTemplates, messages: [], - role_content_sep: "\n", role_empty_sep: "\n", function_string: "", use_function_calling: false, - stop_token_ids: [config.eos_token_id], - }; - if (arch === "qwen3") { - return { - ...common, name: "qwen3", system_template: "<|im_start|>system\n{system_message}<|im_end|>\n", system_message: "", - system_prefix_token_ids: null, roles: { user: "<|im_start|>user", assistant: "<|im_start|>assistant" }, - seps: ["<|im_end|>\n"], stop_str: ["<|im_end|>"], - }; - } - return { - ...common, name: "gemma3_instruction", system_template: "{system_message}", system_message: "", - system_prefix_token_ids: [config.bos_token_id], drowse_system_fold_sep: "\n\n", - roles: { user: "user", assistant: "model" }, - seps: ["\n"], stop_str: [""], - }; -} - -/** The two core concepts the harnesses fit through the release worker (a two-node and a - * one-node concept): short rows, since the fixture's byte-level vocabulary spends a token per - * character in a 128-token context. */ -export function fixtureConcepts() { - const statements = (word) => [`I feel ${word} now.`, `So ${word} today.`, `A ${word} mood.`, `Very ${word}.`]; - const concept = (name, nodes) => ({ - namespace: "local", - name, - description: `fixture concept ${name}`, - fitMode: "pca", - hyperparams: { max_dim: 1, var_threshold: 0.7 }, - source: { uri: "local", repository: null, revision: null }, - tags: ["fixture"], - nodes: nodes.map(([label, rows]) => ({ label, role: null, kind: null, statements: rows })), - }); - return [ - concept("calm.alert", [["calm", statements("calm")], ["alert", statements("alert")]]), - concept("deceptive", [["deceptive", statements("sly")]]), - ]; -} diff --git a/webui/scripts/support/units-worker-reference.py b/webui/scripts/support/units-worker-reference.py deleted file mode 100644 index f1d4dfa..0000000 --- a/webui/scripts/support/units-worker-reference.py +++ /dev/null @@ -1,362 +0,0 @@ -"""Native references for scripts/browser-units-worker.mjs: build the R, S, core-statistics and -units packs for drowse's tiny ABI v5 fixture model bound to a staged WebGPU fixture library, then -compute what drowse answers on the same model with the hosted session's lens band (the browser -keeps native's default band; the goldens read with the fixture's): greedy raw generations under a -neuron push, a unit ablation at @response and an S-lens-gated push with an attached `slens/` -probe; a generated node's token anatomy (unsteered and steered) and unit activity; and the -unit-reads golden's reads, tops and vector find. Ranked lists carry declared ties as the goldens -do (`rank_lists` one entry deeper). - -With `chat`, the fixture is the instruct model its chat template makes (the hosted harness stages -the same template, `--chat`): no raw generations; chat nodes instead, rendered through drowse's -scene stitcher: the goldens' prompt (system "Be brief.", user "Hi there") unsteered and steered, -the user turn alone, a second assistant turn under it (the system folded only into the first turn -where the template folds) and a user-seat turn under it, unsteered and steered; each node's token -anatomy and unit activity read as chat (`raw=False`). - -With `gated MANIFOLD_ARCHIVE` (run after the harness's browser core build): raw nodes whose push -is gated on an attached J-lens probe (`jlens/e`, the R pack's lens) and on an attached geometry -probe (`local/calm.alert`, the very fit the browser's core build wrote: drowse loads the archive's -fitted pair with its own `load_manifold` and registers it, so both sides gate on one manifold). -Each gate's threshold is the midpoint of the two largest readings drowse's decode loop scores for -it (recorded from `ReadPlane.gate_score_callback` on a run whose gate never fires), so the gate -opens mid-generation. Writes gated-reference.json. - - python3 units-worker-reference.py ARCH OUT RUNTIME_JSON [chat | gated MANIFOLD_ARCHIVE] -""" - -from __future__ import annotations - -import json -import tempfile -import zipfile -from collections.abc import Iterator -from contextlib import contextmanager - -import torch -import sys -from pathlib import Path -from typing import Any - -ROOT = Path(__file__).resolve().parents[3] -sys.path.insert(0, str(ROOT / "browser-runtime")) -sys.path.insert(0, str(ROOT / "drowse")) - -from build_hosted_packs import KINDS, NativeModel, build # noqa: E402 -from tests.support.browser_units import ( # noqa: E402 - CHAT, - DECODE_STEPS, - RAW_FIRST, - _activity_diagnostics, - _all_units, - _check_activity, - SHORT_TEXT, - FixtureError, - _find, - _greedy, - fixture, - rank_lists, - short_prompt_ids, -) - -PUSH = "0.3 neuron/L2n7" -ABLATE_RESPONSE = "!neuron/L1n5@response" -SLENS_WORD = "e" -SLENS_GATED = f"0.3 neuron/L2n7@when:slens/{SLENS_WORD} > 0" -ANATOMY_STEERING = "0.3 neuron/L2n7 + !head/L1h3" -#: Attached through every generation: the unit-probes golden's units and an S-lens probe. -PROBES = ("neuron/L1n5", "head/L2h1", f"slens/{SLENS_WORD}") -ANATOMY_INDEX = 3 -ACTIVITY = {"top": 5, "units": ["neuron/L1n5", "head/L2h1"], "raw_index": 2, "layers": "0,2"} -STEPS = 5 -#: The chat nodes (`chat` mode): name, steering, input, system prompt, parent node, generated seat, -#: whether unit activity is read too. -CHAT_SYSTEM = "Be brief." -CHAT_NODES = ( - ("chat", None, "Hi there", CHAT_SYSTEM, None, "assistant", True), - ("chat-steered", ANATOMY_STEERING, "Hi there", CHAT_SYSTEM, None, "assistant", False), - ("chat-plain", None, "Hi there", None, None, "assistant", True), - ("chat-second", None, "Go on", CHAT_SYSTEM, "chat", "assistant", True), - ("user-seat", None, None, CHAT_SYSTEM, "chat", "user", True), - ("user-seat-steered", ANATOMY_STEERING, None, CHAT_SYSTEM, "chat", "user", False), -) - - -#: The gated nodes (`gated` mode): name, attached probe, gate key. -GATED_NODES = ( - ("jlens-gated", f"jlens/{SLENS_WORD}", f"jlens/{SLENS_WORD}"), - ("geometry-gated", "local/calm.alert", "local/calm.alert"), -) -GATED_PUSH = "0.3 neuron/L2n7" - - -@contextmanager -def recorded_gate_scalars() -> Iterator[list[dict[str, float]]]: - """Every gate scalar dict the decode loop scores, in call order.""" - from drowse.generation.read_plane import ReadPlane - - seen: list[dict[str, float]] = [] - original = ReadPlane.gate_score_callback - - def patched(self: Any) -> Any: - score = original(self) - - def wrapped(step_id: int) -> Any: - out = score(step_id) - seen.append({key: float(value) for key, value in out.items()}) - return out - return wrapped - - ReadPlane.gate_score_callback = patched # type: ignore[method-assign] - try: - yield seen - finally: - ReadPlane.gate_score_callback = original # type: ignore[method-assign] - - -def threshold(values: list[float], what: str) -> str: - """A threshold that opens the gate for the anatomy's forward (its reading is the previous - forward's, ``values[ANATOMY_INDEX - 1]``) and shuts it at least once elsewhere: the midpoint - between that reading and the nearest one below it, written with enough digits for a - probability.""" - at = values[ANATOMY_INDEX - 1] - below = [value for value in values if value < at] - if not below: - raise FixtureError(f"{what}: no reading lies below the anatomy forward's ({values})") - nearest = max(below) - if not at - nearest > 1e-3 * max(abs(at), 1e-12): - raise FixtureError(f"{what}: the gate's readings tie ({at} vs {nearest})") - return f"{(at + nearest) / 2:.12f}".rstrip("0") - - -def register_archive_manifold(session: Any, archive: Path, key: str) -> None: - """The fitted pair the browser's core build wrote, loaded by drowse and registered as ``key``.""" - from drowse.store.manifold_tensors import load_manifold - - folder = "manifolds/" + key + "/" - with zipfile.ZipFile(archive) as bundle, tempfile.TemporaryDirectory() as tmp: - tensors = [n for n in bundle.namelist() if n.startswith(folder) and n.endswith(".safetensors")] - if len(tensors) != 1: - raise FixtureError(f"{archive.name}: expected one fitted pair under {folder}, found {tensors}") - for name in (tensors[0], tensors[0].removesuffix(".safetensors") + ".json"): - bundle.extract(name, tmp) - manifold = load_manifold(Path(tmp) / tensors[0], verify_manifest=False) - session._registry.put_manifold(key, manifold) - - -def jsonable(value: Any) -> Any: - return json.loads(json.dumps(value, default=lambda item: item.to_dict() if hasattr(item, "to_dict") else str(item))) - - -def without_underflow(value: Any) -> Any: - """``value`` without the probability entries that underflowed to exactly 0: which of the - vocabulary's zero-probability tokens fill a list is arbitrary (a sharp lens read leaves most - of it at 0), so both sides drop them (browser-units-worker.mjs does the same).""" - if isinstance(value, list): - return [without_underflow(item) for item in value] - if not isinstance(value, dict): - return value - probability = value.get("unit") == "probability" - return { - key: [item for item in child if not (isinstance(item, dict) and item.get("value") == 0)] - if probability and isinstance(child, list) else without_underflow(child) - for key, child in value.items() - } - - -def ranked(call: Any, candidates: list[dict[str, int]], path: str, ties: list[dict[str, Any]], - check: Any = None) -> Any: - """``call(**knobs)`` at the first candidate whose ranked lists keep every boundary (no entry - ties the best excluded one deeper, as the goldens choose their knobs) and that ``check`` - (``check(result, found)``, raising FixtureError to refuse) accepts, with its near-ties - declared; returns ``{"knobs", "result", "checked"}`` (``checked``: what ``check`` returned).""" - refusals = [] - for knobs in candidates: - short = without_underflow(jsonable(call(**knobs))) - long = without_underflow(jsonable(call(**{key: value + 1 for key, value in knobs.items()}))) - found: list[dict[str, Any]] = [] - try: - rank_lists(short, long, found, path + ".result") - checked = None if check is None else check(short, found) - except FixtureError as exc: - refusals.append(f"{knobs}: {exc}") - continue - ties.extend(found) - return {"knobs": knobs, "result": short, **({} if check is None else {"checked": checked})} - raise FixtureError(f"{path}: no knobs keep every boundary: {refusals}") - - -def _pursuit(fx: Any, call: Any, path: str, ties: list[dict[str, Any]]) -> Any: - found = _find(fx, call, path, ties) - return {"knobs": {"k": found["k"]}, "result": jsonable(found["result"])} - - -def around(name: str, value: int, **fixed: int) -> list[dict[str, int]]: - return [{name: v, **fixed} for v in (value, value - 1, value + 1, value - 2, value + 2) if v > 0] - - -def main() -> None: - from drowse.lens.depth import LensBand - - arch, out = sys.argv[1], Path(sys.argv[2]) - runtime = json.loads(Path(sys.argv[3]).read_text()) - mode = sys.argv[4] if len(sys.argv) > 4 else None - chat, gated = mode == "chat", mode == "gated" - with fixture(arch) as fx: - session = fx.session - model = NativeModel(session) - if not gated: - build(model, runtime, out / "packs", KINDS, full_depth=False, words=["a", "e", "t"]) - session.lens.band = LensBand() - # The browser types the text and its completion prefix adds the family's BOS; the fixture - # tokenizer adds none, so drowse reads the BOS piece as its special (the goldens' way). - text = SHORT_TEXT[arch] - native_text = fx.tokenizer.decode(short_prompt_ids(fx.tokenizer, arch)) - ties: list[dict[str, Any]] = [] - - def generate(steering: str | None, *, steps: int = STEPS, stateless: bool = True) -> Any: - session.tree.navigate(session.tree.root_id) - return session.generate(native_text, raw=True, stateless=stateless, steering=steering, - sampling=_greedy(steps)) - - generations: dict[str, Any] = {} - for name, steering, probes in () if chat or gated else ( - ("push", PUSH, PROBES), - ("ablate-response", ABLATE_RESPONSE, PROBES), - ("slens-gated", SLENS_GATED, PROBES), - ): - for probe in probes: - session.add_probe(probe) - try: - final = generate(steering).first - generations[name] = { - "steering": steering, "probes": list(probes), "tokens": [int(t) for t in final.tokens], - "aggregate": jsonable(final.measurements), - } - finally: - for probe in probes: - session.remove_probe(probe) - - nodes: dict[str, Any] = {} - - def node_entry(name: str, steering: str | None, node: str, tokens: Any, *, raw: bool, - activity: bool, **fields: Any) -> dict[str, Any]: - anatomy = ranked(lambda **knobs: session.token_anatomy(node, ANATOMY_INDEX, raw=raw, **knobs), - [{"k": k, "units": units, "patterns": 2} - for k in (5, 4, 6, 3, 7, 2) for units in (k, 5, 4, 6, 3)], - f"nodes.{name}.anatomy", ties) - entry: dict[str, Any] = {"steering": steering, "tokens": [int(t) for t in tokens], "raw": raw, - "anatomy": anatomy, **fields} - if activity: - # The goldens' rule (`_check_activity` over every unit's peak row): a listed or - # traced unit whose peak row has no margin is named, and its row is not compared. - full = jsonable(session.unit_activity(node, top=1024, units=_all_units(fx), raw=raw)) - diag = _activity_diagnostics(full, {full["sink_raw_index"]} - {None}) - read = ranked( - lambda top: session.unit_activity(node, top=top, units=ACTIVITY["units"], - raw_index=ACTIVITY["raw_index"], layers=ACTIVITY["layers"], - raw=raw), - [{"top": top} for top in range(ACTIVITY["top"] + 3, 1, -1)], f"nodes.{name}.activity", ties, - check=lambda result, found: _check_activity(result, diag, name, f"nodes.{name}.activity", found)) - entry["activity"] = {"knobs": read["knobs"], "result": read["result"], - "tied_peak_rows": read["checked"]} - return entry - - if chat: - ids: dict[str, str] = {} - for name, steering, text_in, system, parent, seat, activity in CHAT_NODES: - if parent is None: - session.tree.navigate(session.tree.root_id) - runs = session.generate(text_in, steering=steering, sampling=_greedy(DECODE_STEPS), - system_prompt=system, parent_node_id=ids.get(parent) if parent else None, - gen_seat=seat) - ids[name] = str(runs.node_ids[0]) - nodes[name] = node_entry(name, steering, ids[name], runs.first.tokens, raw=False, activity=activity, - probes=[], input=text_in, system=system, parent=parent, seat=seat) - # The S-lens-gated nodes replay one decode position per forward, their gate scored from - # the previous forward (native's gate run; the browser's replay readback) while slens/e - # stays attached; unattached, the gate names no probe and never fires (resolve_gates), in - # the generation and in its replays. - slens_probe = f"slens/{SLENS_WORD}" - if gated: - register_archive_manifold(session, Path(sys.argv[5]), "local/calm.alert") - for name, probe, key in GATED_NODES: - session.add_probe(probe) - try: - with recorded_gate_scalars() as seen: - generate(f"{GATED_PUSH}@when:{key} > 1000000", steps=DECODE_STEPS) - # The prefill's and the first decode forwards' scores gate the decode steps. - values = [step[key] for step in seen if key in step][: DECODE_STEPS - 1] - steering = f"{GATED_PUSH}@when:{key} > {threshold(values, name)}" - runs = generate(steering, steps=DECODE_STEPS, stateless=False) - nodes[name] = node_entry(name, steering, str(runs.node_ids[0]), runs.first.tokens, raw=True, - activity=True, probes=[probe], input=text, system=None, - parent=None, seat="assistant", gate_readings=values) - finally: - session.remove_probe(probe) - json.dump(jsonable({"arch": arch, "nodes": nodes, "declared_ties": ties}), - (out / "gated-reference.json").open("w")) - return - for name, steering, probes in () if chat else ( - ("unsteered", None, ()), - ("steered", ANATOMY_STEERING, ()), - ("slens-gated", SLENS_GATED, (slens_probe,)), - ("slens-unattached", SLENS_GATED, ()), - ): - for probe in probes: - session.add_probe(probe) - try: - runs = generate(steering, steps=DECODE_STEPS, stateless=False) - # The hosted fixture is a base model: its replays render the node raw. - nodes[name] = node_entry(name, steering, str(runs.node_ids[0]), runs.first.tokens, raw=True, - activity=name != "steered", probes=list(probes), input=text, - system=None, parent=None, seat="assistant") - finally: - for probe in probes: - session.remove_probe(probe) - - golden = json.loads((ROOT / "drowse/tests/fixtures/browser" / f"unit-reads-{arch}-v1.json").read_text()) - units = session.units - reads = [ - {"unit": e["unit"], "hide_hubs": e["hide_hubs"], - "read": ranked(lambda k, e=e: units.read(e["unit"], k=k, hide_hubs=e["hide_hubs"]).to_dict(), - around("k", e["k"]), f"reads[{i}]", ties)} - for i, e in enumerate(golden["reads"]) - ] - tops = [ - {"token": e["token"], "by": e["by"], - "result": ranked(lambda k, e=e: units.top(e["token"], by=e["by"], layers="all", k=k).to_dict(), - around("k", e["k"]), f"top[{i}]", ties)} - for i, e in enumerate(golden["top"]) - ] - finds = [] - for e in golden["find"]: - if e["target"] != "vector": - continue - from tests.support.browser_units import decode - vector = torch.from_numpy(decode(e["vector"]).copy()) - finds.append({ - "vector": e["vector"], "layer": e["layer"], - # A greedy pursuit: its k is chosen by the picks' margins (the golden's `_find`). - "result": _pursuit(fx, lambda k, v=vector, e=e: units.find(v, layer=e["layer"], k=k).to_dict(), - f"find[{len(finds)}]", ties), - }) - - json.dump(jsonable({ - "arch": arch, "chat": chat, "text": text, "generations": generations, "nodes": nodes, - # What the goldens feed (browser-units-worker.mjs --goldens): the chat prompt, the short - # prompt as raw text (BOS piece included), the raw first turn's byte. - "golden_inputs": {"system": CHAT[0]["content"], "user": CHAT[1]["content"], - "short_text": native_text, "raw_first": RAW_FIRST[arch], - "anatomy_steering": ANATOMY_STEERING, "segmented_steering": "!neuron/L1n5@prompt", - "decode_steps": DECODE_STEPS}, - "reads": reads, "top": tops, "find": finds, "declared_ties": ties, - "settings": {"push": PUSH, "ablate": ABLATE_RESPONSE, "slens": SLENS_GATED, - "slensWord": SLENS_WORD, "probes": list(PROBES), "anatomySteering": ANATOMY_STEERING, - "anatomyIndex": ANATOMY_INDEX, - "activity": ACTIVITY, "steps": STEPS, "decodeSteps": DECODE_STEPS}, - }), (out / "reference.json").open("w")) - - -if __name__ == "__main__": - main() diff --git a/webui/scripts/units-activity.test.mjs b/webui/scripts/units-activity.test.mjs deleted file mode 100644 index f738ab3..0000000 --- a/webui/scripts/units-activity.test.mjs +++ /dev/null @@ -1,264 +0,0 @@ -// Unit activity (native `NodeReplayer.unit_activity`) on the reference backend's replay against -// drowse's unit-activity golden (B1-goldens §2.5): every case's forward rebuilt from the model -// file's chat prompt and the case's rows, replay segments from the browser program. -import assert from "node:assert/strict"; -import { ARCHES, archGolden, compareRecord, decode, viteServer } from "./support/units-goldens.mjs"; -import { unitsFixture } from "./support/units-fixture.mjs"; - -const RAW_FIRST = { gemma3: "=", qwen3: "K" }; - -function f16(bits) { - const s = bits & 0x8000 ? -1 : 1; - const e = (bits >>> 10) & 0x1f; - const m = bits & 0x3ff; - if (e === 0) return s * m * 2 ** -24; - if (e === 31) return m ? NaN : s * Infinity; - return s * (1 + m / 1024) * 2 ** (e - 15); -} -const halfBits = (text) => { - const bytes = Buffer.from(text, "base64"); - return Array.from({ length: bytes.length / 2 }, (_, i) => bytes[2 * i] | (bytes[2 * i + 1] << 8)); -}; -// f16 bit patterns on one ordered line (sign-magnitude to two's complement), so neighbours, -// zero's two signs included, are one apart: "within one f16 ulp" is |Δ| ≤ 1 there. -const ordered = (bits) => (bits & 0x8000 ? -(bits & 0x7fff) : bits); - -const server = await viteServer(); -try { - const [replayModule, scalesModule, hooks, profiles, readerModule] = await Promise.all([ - server.ssrLoadModule("/src/hosted/runtime/units/nodeReplay.ts"), - server.ssrLoadModule("/src/hosted/runtime/units/scales.ts"), - server.ssrLoadModule("/src/hosted/runtime/structuredHookProgram.ts"), - server.ssrLoadModule("/src/hosted/runtime/structuredHookProfile.ts"), - server.ssrLoadModule("/src/hosted/runtime/units/unitReader.ts"), - ]); - for (const arch of ARCHES) { - const fx = await unitsFixture(server, arch); - const golden = archGolden("unit-activity", arch); - const stats = fx.stats; - const statistics = { - documents: stats.n_documents, - neuronMean: Float32Array.from(decode(stats.neuron_mean)), - neuronScale: Float32Array.from(decode(stats.neuron_scale)), - headMean: Float32Array.from(decode(stats.head_mean)), - headScale: Float32Array.from(decode(stats.head_scale)), - }; - const scales = scalesModule.readingScales(statistics, fx.model.spec, 4); - const chat = Int32Array.from(fx.record.chat_prompt.ids); - const shape = { dFF: 96, nHeads: 4, headDim: 16 }; - const emptyProgram = () => hooks.compileStructuredHookProgram(64, [{}, {}, {}, {}], profiles.STANDARD_STRUCTURED_HOOK_PROFILE_V4); - const unitProgram = (ablation, phase) => hooks.withStructuredUnitSection(emptyProgram(), shape, { - ablations: [ablation], taps: [], controls: [phase === "both" ? null : { enabled: true, phase: { kind: phase }, gate: null }], - }); - const indexOf = (haystack, needle) => { - for (let i = 0; i + needle.length <= haystack.length; i += 1) if (needle.every((x, j) => haystack[i + j] === x)) return i; - return -1; - }; - for (const [c, entry] of golden.cases.entries()) { - const args = entry.arguments; - const rows = entry.result.tokens.map((t) => t.token_id); - let forward; - let program = null; - if (args.ids) { - const runs = args.runs; - forward = { - ids: Int32Array.from(args.ids), - promptLength: args.ids.length, - rawIds: Int32Array.from(args.raw_ids), - spans: runs.map(([first, position], i) => ({ firstRow: first, stopRow: i + 1 < runs.length ? runs[i + 1][0] : args.raw_ids.length, at: position - 1 })), - }; - if (entry.name === "excluded-and-zero") program = unitProgram({ kind: "neuron", layer: 1, index: 5, keep: 0, bias: 0, group: 0 }, "both"); - } else if (entry.name.startsWith("sink")) { - const first = fx.tokenizer.encode(RAW_FIRST[arch]); - forward = { ids: Int32Array.from([...first, ...rows.slice(0, -1)]), promptLength: first.length, rawIds: Int32Array.from(rows), spans: [{ firstRow: 0, stopRow: rows.length, at: first.length - 1 }] }; - } else if (entry.name === "authored") { - const position = indexOf([...chat], rows); - assert.ok(position > 0, "the authored rows sit in the chat render"); - const ids = chat.slice(0, position + rows.length - 1); - forward = { ids, promptLength: ids.length, rawIds: Int32Array.from(rows), spans: [{ firstRow: 0, stopRow: rows.length, at: position - 1 }] }; - } else { - forward = { ids: Int32Array.from([...chat, ...rows.slice(0, -1)]), promptLength: chat.length, rawIds: Int32Array.from(rows), spans: [{ firstRow: 0, stopRow: rows.length, at: chat.length - 1 }] }; - if (entry.name === "segmented") { - program = unitProgram(hooks.structuredUnitAblationTerm("neuron", 1, 5, 1, statistics.neuronMean[96 + 5], 0), "prompt_only"); - } - } - const units = (args.units ?? []).map((name) => readerModule.parseUnit(name, fx.model.spec, 4)); - const layers = args.layers ? String(args.layers).split(",").map(Number) : null; - const actual = await replayModule.unitActivity(fx.backend, { nLayers: 4, spec: fx.model.spec }, scales, forward, program, { - top: args.top ?? 32, units, rawIndex: args.raw_index ?? null, layers, - }, async (ids) => ids.map((id) => fx.tokenizer.decode([id]))); - // unitActivity never names the steering (the service adds the loom node's); the program - // this test lowered by hand stands for the case's recorded expression. - assert.equal(entry.result.steering, entry.name === "segmented" ? "!neuron/L1n5@before" : null); - assert.equal("steering" in actual, false); - const expectedPopulation = entry.result.population; - const actualPopulation = actual.population; - const { steering: _steering, ...result } = { ...entry.result, population: null }; - actual.population = null; - const tol = golden.tolerance.library; - const problems = compareRecord(actual, result, { - root: `cases[${c}].result`, - ties: golden.declared_ties, - numberTol: (path) => /(peak|traces\.[^.]+\[\d+\])$/.test(path) || /traces/.test(path) ? tol.z_atol + 2e-6 : 2e-6, - }); - assert.deepEqual(problems, [], `${arch} unit activity ${entry.name}`); - if (expectedPopulation === null) assert.equal(actualPopulation, null); - else { - assert.equal(actualPopulation.raw_index, expectedPopulation.raw_index); - assert.equal(actualPopulation.encoding, expectedPopulation.encoding); - assert.deepEqual(actualPopulation.layers.map((l) => l.layer), expectedPopulation.layers.map((l) => l.layer)); - assert.equal(actualPopulation.layers.length, expectedPopulation.layers.length); - actualPopulation.layers.forEach((layer, i) => { - for (const key of ["neurons", "heads"]) { - const got = halfBits(layer[key]); - const want = halfBits(expectedPopulation.layers[i][key]); - assert.equal(got.length, want.length, `${arch} ${entry.name} population L${layer.layer} ${key} length`); - got.forEach((bits, j) => assert.ok( - Math.abs(ordered(bits) - ordered(want[j])) <= 1, - `${arch} ${entry.name} population L${layer.layer} ${key}[${j}] ${f16(bits)} vs ${f16(want[j])}`, - )); - } - }); - } - } - } - console.log("units activity: every unit-activity case matches drowse"); - - // Position-targeted steering (browser only, B1 §2.3/§3.1): the replay splits its segments at - // the recorded spans and nothing fires outside them, so `!neuron/L1n5` over [p, p+2) changes - // only rows produced at or after p, its own rows read the ablated mean, and a span over every - // position replays as the unrestricted program. - { - const arch = "gemma3"; - const fx = await unitsFixture(server, arch); - const golden = archGolden("unit-activity", arch); - const stats = fx.stats; - const statistics = { - documents: stats.n_documents, - neuronMean: Float32Array.from(decode(stats.neuron_mean)), - neuronScale: Float32Array.from(decode(stats.neuron_scale)), - headMean: Float32Array.from(decode(stats.head_mean)), - headScale: Float32Array.from(decode(stats.head_scale)), - }; - const scales = scalesModule.readingScales(statistics, fx.model.spec, 4); - const chat = Int32Array.from(fx.record.chat_prompt.ids); - const rows = golden.cases.find((entry) => entry.name === "generated").result.tokens.map((t) => t.token_id); - const base = { - ids: Int32Array.from([...chat, ...rows.slice(0, -1)]), - promptLength: chat.length, - rawIds: Int32Array.from(rows), - spans: [{ firstRow: 0, stopRow: rows.length, at: chat.length - 1 }], - }; - const ablate = () => hooks.withStructuredUnitSection( - hooks.compileStructuredHookProgram(64, [{}, {}, {}, {}], profiles.STANDARD_STRUCTURED_HOOK_PROFILE_V4), - { dFF: 96, nHeads: 4, headDim: 16 }, - { ablations: [hooks.structuredUnitAblationTerm("neuron", 1, 5, 1, statistics.neuronMean[96 + 5], 0)], taps: [], controls: [null] }, - ); - const units = [readerModule.parseUnit("neuron/L1n5", fx.model.spec, 4)]; - const run = (forward, program) => replayModule.unitActivity(fx.backend, { nLayers: 4, spec: fx.model.spec }, scales, forward, program, { - top: 4, units, rawIndex: null, layers: null, - }, async (ids) => ids.map((id) => fx.tokenizer.decode([id]))); - const p = chat.length + 1; - assert.deepEqual( - replayModule.replaySegments(ablate(), base.promptLength, base.ids.length, false, [[p, p + 2]]).map((seg) => [seg.start, seg.stop, seg.inSpan]), - [[0, p, false], [p, p + 2, true], [p + 2, base.ids.length, false]], - ); - const plain = (await run(base, null)).traces["neuron/L1n5"]; - const full = (await run(base, ablate())).traces["neuron/L1n5"]; - const everywhere = (await run({ ...base, positionSpans: [[0, base.ids.length]] }, ablate())).traces["neuron/L1n5"]; - assert.deepEqual(everywhere, full); - const spanned = (await run({ ...base, positionSpans: [[p, p + 2]] }, ablate())).traces["neuron/L1n5"]; - // Row r is produced at column chat.length - 1 + r: rows 0 and 1 precede the span. - assert.deepEqual(spanned.slice(0, 2), plain.slice(0, 2)); - assert.deepEqual(spanned.slice(2, 4), full.slice(2, 4)); - assert.notDeepEqual(spanned.slice(2, 4), plain.slice(2, 4)); - console.log("units activity: position-targeted steering replays with its spans"); - } - - // Probe-gated steering replays one decode position per forward, its gates scored from the - // previous forward's readback (native's gate run): a name-scored gate reads the scorer's - // value, a slot gate the readback's probe slots. A gate the replay cannot score (no scorer, - // a key it does not produce, a slot the backend could not read) refuses with native's 422 - // instead of staying shut. - { - const v4 = profiles.STANDARD_STRUCTURED_HOOK_PROFILE_V4; - const gated = (gate) => { - const base = hooks.compileStructuredHookProgram(64, [{}, {}, {}, {}], v4); - return hooks.withStructuredUnitSection(base, { dFF: 96, nHeads: 4, headDim: 16 }, { - ablations: [hooks.structuredUnitAblationTerm("neuron", 1, 5, 1, 0, 0)], - taps: [], - controls: [{ enabled: true, phase: { kind: "both" }, gate }], - }); - }; - const named = gated({ slots: [], scoreKey: "slens/e", operator: ">", threshold: 0.5 }); - const slotted = gated({ slots: [{ layer: 2, probe: 0 }], operator: ">", threshold: 0.5 }); - const forward = { ids: Int32Array.of(1, 2, 3, 4, 5, 6), promptLength: 3 }; - const stub = (slotValue) => { - const fed = []; - let cancelled = false; - let step = 0; - const backend = { - async openReplay() { - return { - async forward(segment) { - fed.push({ tokens: [...segment.tokenIds], unitActive: segment.controls.unitActive?.[0] ?? null }); - step += 1; - const measurements = new Float32Array(4 * v4.maxProbes); - measurements[2 * v4.maxProbes] = slotValue(step); - return { - measurements: { dtype: "f32", shape: [4, v4.maxProbes], data: measurements }, - unitTaps: null, - geometry: null, - hidden: { dtype: "f32", shape: [4, 64], data: Float32Array.from({ length: 256 }, () => step) }, - }; - }, - async finish() { return { anatomyTaps: null, activity: null, patterns: null }; }, - async cancel() { cancelled = true; }, - }; - }, - }; - return { backend, fed, cancelled: () => cancelled }; - }; - const request = (program) => ({ program, anatomyPosition: null, activity: null, patternLayers: null }); - // Name-scored: the prefill's score (1) opens position 3, position 3's (0) shuts position 4, - // position 4's (1) opens position 5. The scorer sees each forward's [L, d] capture. - { - const { backend, fed } = stub(() => 0); - const seen = []; - await replayModule.driveReplay(backend, request(named), forward, { - gateScores: async (_program, readback) => { - seen.push(readback.hidden.data[0]); - return { "slens/e": readback.hidden.data[0] % 2 }; - }, - }); - assert.deepEqual(fed.map((entry) => entry.tokens), [[1, 2, 3], [4], [5], [6]]); - assert.deepEqual(fed.map((entry) => entry.unitActive), [0, 1, 0, 1]); - assert.deepEqual(seen, [1, 2, 3]); - } - // Slot-scored: the readback's probe slot feeds the gate. - { - const { backend, fed } = stub((step) => (step === 2 ? 0 : 1)); - await replayModule.driveReplay(backend, request(slotted), forward, { gateScores: async () => ({}) }); - assert.deepEqual(fed.map((entry) => entry.unitActive), [0, 1, 0, 1]); - } - const refusal = (name) => (error) => - error.status === 422 && error.code === "SteeringCompositionError" && error.message.includes(`(@when:…) on ${name},`); - for (const [label, program, options, slot] of [ - ["no scorer", named, {}, () => 0], - ["a key the scorer does not produce", named, { gateScores: async () => ({ other: 1 }) }, () => 0], - ["a slot the backend could not read", slotted, { gateScores: async () => ({}) }, () => Number.NaN], - ]) { - const { backend, fed, cancelled } = stub(slot); - await assert.rejects( - replayModule.driveReplay(backend, request(program), forward, options), - refusal(program === named ? "slens/e" : "probe slot 0"), - label, - ); - assert.equal(fed.length, 1, `${label}: refused after the prefill`); - assert.ok(cancelled(), `${label}: the replay is cancelled`); - } - console.log("units activity: gated replays score every gate from the previous forward or refuse"); - } -} finally { - await server.close(); -} diff --git a/webui/scripts/units-anatomy.test.mjs b/webui/scripts/units-anatomy.test.mjs deleted file mode 100644 index de8f029..0000000 --- a/webui/scripts/units-anatomy.test.mjs +++ /dev/null @@ -1,51 +0,0 @@ -// Token anatomy (native `NodeReplayer.token_anatomy`) on the reference backend against drowse's -// token-anatomy golden (B1-goldens §2.8): unsteered, under `0.3 neuron/L2n7 + !head/L1h3` (lowered -// by the structured compiler), and with an R lens holding no `mid` layer. -import assert from "node:assert/strict"; -import { ARCHES, archGolden, assertClose, compareRecord, decode, viteServer } from "./support/units-goldens.mjs"; -import { unitsFixture } from "./support/units-fixture.mjs"; -import { unitsCompiler } from "./support/units-compiler.mjs"; - -const server = await viteServer(); -try { - const [anatomyModule, scalesModule] = await Promise.all([ - server.ssrLoadModule("/src/hosted/runtime/units/anatomy.ts"), - server.ssrLoadModule("/src/hosted/runtime/units/scales.ts"), - ]); - for (const arch of ARCHES) { - const golden = archGolden("token-anatomy", arch); - const chatLength = (await unitsFixture(server, arch)).record.chat_prompt.ids.length; - for (const [c, entry] of golden.cases.entries()) { - const fx = await unitsFixture(server, arch, entry.name === "no-r-mid" ? { drop: ["R:mid"] } : {}); - const stats = fx.stats; - const statistics = { - documents: stats.n_documents, - neuronMean: Float32Array.from(decode(stats.neuron_mean)), - neuronScale: Float32Array.from(decode(stats.neuron_scale)), - headMean: Float32Array.from(decode(stats.head_mean)), - headScale: Float32Array.from(decode(stats.head_scale)), - }; - const scales = scalesModule.readingScales(statistics, fx.model.spec, 4); - const ids = Int32Array.from(entry.intermediates.ids); - const rawIds = Int32Array.from([...ids.slice(chatLength), entry.intermediates.token_id]); - const forward = { ids, promptLength: chatLength, rawIds, rawIndex: golden.raw_index, spans: [{ firstRow: 0, stopRow: rawIds.length, at: chatLength - 1 }] }; - // The steered case's program as the structured compiler lowers its expression. - const program = entry.steering ? await (await unitsCompiler(server, fx, arch)).compile(entry.steering) : null; - const { anatomy } = await anatomyModule.tokenAnatomy(fx.context, { spec: fx.model.spec, scales, backend: fx.backend }, forward, program, entry.knobs, { - sources: { R: entry.lens, S: "local:s" }, steering: entry.steering, - }); - const envelope = { measurements: { version: 2, scope: "replay", provenance: "replayed", instruments: {}, anatomy } }; - const tol = golden.tolerance.library; - const problems = compareRecord(envelope, entry.envelope, { - root: `cases[${c}].envelope`, - ties: golden.declared_ties, - numberTol: (path) => /\.(value|contribution|activation|activation_over_scale)$/.test(path) ? tol.z_atol + 2e-6 - : /(probability|weights\[\d+\])$/.test(path) ? tol.probability_atol + 2e-6 : 2e-6, - }); - assert.deepEqual(problems, [], `${arch} token anatomy ${entry.name}`); - } - } - console.log("units anatomy: every token-anatomy case matches drowse"); -} finally { - await server.close(); -} diff --git a/webui/scripts/units-compiler.test.mjs b/webui/scripts/units-compiler.test.mjs deleted file mode 100644 index 3b7b38e..0000000 --- a/webui/scripts/units-compiler.test.mjs +++ /dev/null @@ -1,135 +0,0 @@ -// The structured compiler's unit programs against drowse's goldens, end to end: a core pack for -// the tiny fixture model (its neutral whitener), the units service's program source over the -// reference backend and B6-shaped packs (`prepare` reads each neuron's write off the device), -// then `compile`. neuron-push: each case's lowered affine group (basis, neutral, target, along) -// and trigger; unit-ablation: every case's unit tables (entries, keep, bias, width) and their -// triggers, as the encoder lays them out. -import assert from "node:assert/strict"; -import { ARCHES, archGolden, viteServer } from "./support/units-goldens.mjs"; -import { unitsFixture } from "./support/units-fixture.mjs"; -import { unitsCompiler } from "./support/units-compiler.mjs"; - -const near = (actual, expected, tol, where) => { - if (Array.isArray(expected)) { - assert.equal(actual.length, expected.length, `${where} length`); - expected.forEach((value, i) => near(actual[i], value, tol, `${where}[${i}]`)); - return; - } - assert.ok(Math.abs(actual - expected) <= tol.atol + tol.rtol * Math.abs(expected), `${where}: ${actual} != ${expected}`); -}; - -const server = await viteServer(); -try { - const [hooks, grammar, { BrowserInstrumentRuntime }] = await Promise.all([ - server.ssrLoadModule("/src/hosted/runtime/structuredHookProgram.ts"), - server.ssrLoadModule("/src/hosted/runtime/steeringExpression.ts"), - server.ssrLoadModule("/src/hosted/runtime/browserInstrumentRuntime.ts"), - ]); - // Native's trigger record (`Trigger` fields) of a unit or affine control. - const trigger = (control) => { - const fields = grammar.steeringTriggerFields(control === null ? null : { phase: control.phase, gate: null }); - return { - prompt: fields.prompt, generated: fields.generated, thinking: fields.thinking, response: fields.response, - first_n: fields.firstN, after_n: fields.afterN, - gate: control?.gate ? { probe: control.gate.scoreKey, op: control.gate.operator, threshold: control.gate.threshold } : null, - }; - }; - for (const arch of ARCHES) { - const fx = await unitsFixture(server, arch); - const d = fx.model.hiddenSize; - const { compiler, compile } = await unitsCompiler(server, fx, arch); - - // A fresh slens/ probe attaches through the instrument runtime (its atom is prepared first) - // and carries native's slens-footprint-z-v3 digest, so probeHashes (read on every - // generation) never throws on it. - const instruments = new BrowserInstrumentRuntime(compiler, null, null, false); - const word = arch === "gemma3" ? "e" : "a"; - const attached = await instruments.request({ service: "probes", method: "attach", args: [{ selector: `slens/${word}` }] }, () => null); - assert.deepEqual([attached.family, attached.namespace, attached.word], ["lens", "slens", word]); - assert.match(instruments.probeHashes()[`slens/${word}`], /^[0-9a-f]{64}$/u); - // A manifold refresh hands the runtime a new compiler: the unit source carries over and the - // slens/ and unit probes re-attach through it, digests unchanged. - await instruments.request({ service: "probes", method: "attach", args: [{ selector: "neuron/L1n5" }] }, () => null); - const before = instruments.probeHashes(); - await instruments.replaceCompiler(await compiler.withInstalledManifolds([], new AbortController().signal)); - assert.deepEqual(instruments.probeHashes(), before); - await instruments.request({ service: "probes", method: "detach", args: [`slens/${word}`] }, () => null); - await instruments.request({ service: "probes", method: "detach", args: ["neuron/L1n5"] }, () => null); - - // ------------------------------------------------------------------ neuron pushes - const push = archGolden("neuron-push", arch); - const tol = push.tolerance.library; - for (const entry of push.cases) { - const program = await compile(entry.expression); - assert.equal(program.format, "drowse-structured-v4"); - assert.equal(program.steeringExpression, entry.canonical, `${arch} ${entry.expression} canonical`); - const G = program.profile.maxAffineGroups; - const R = program.profile.maxRank; - const groups = []; - for (let layer = 0; layer < program.layerCount; layer += 1) { - for (let g = 0; g < G; g += 1) { - if (program.affineActive[layer * G + g] !== 1) continue; - const at = layer * G + g; - groups.push({ - layer, - basis: Array.from(program.affineBasis.subarray(at * R * d, at * R * d + d)), - neutral: Array.from(program.affineNeutral.subarray(at * d, (at + 1) * d)), - target: program.affineTarget[at * R], - along: program.affineAlong[at], - control: program.controls.affine[at], - }); - } - } - assert.equal(groups.length, entry.layers.length, `${arch} ${entry.expression} groups`); - entry.layers.forEach((want, i) => { - const where = `${arch} ${entry.expression} layer ${want.layer}`; - // A group acts through `target − ⟨h, basis⟩` along `basis`, so (basis, target) and - // (−basis, −target) are one push: drowse lowers a negative push with the basis flipped, - // the browser with the target negated. Compare in drowse's orientation. - const raw = groups[i]; - const flip = raw.basis.reduce((sum, value, j) => sum + value * want.basis[j], 0) < 0 ? -1 : 1; - const got = { ...raw, basis: raw.basis.map((value) => flip * value), target: flip * raw.target }; - assert.equal(got.layer, want.layer, where); - near(got.basis, want.basis, tol, `${where} basis`); - near(got.neutral, want.neutral, tol, `${where} neutral`); - near(got.target, want.target, tol, `${where} target`); - near(got.along, want.along, tol, `${where} along`); - // The push the group adds (`along · target · basis`, the golden's delta). - near(got.basis.map((b) => got.along * got.target * b), want.delta, tol, `${where} delta`); - assert.deepEqual(trigger(got.control), entry.trigger, `${where} trigger`); - }); - } - - // ------------------------------------------------------------------ unit ablations - const ablation = archGolden("unit-ablation", arch); - for (const entry of ablation.cases) { - const program = await compile(entry.steering); - const tables = hooks.decodeStructuredUnitTables(program).map((table) => ({ - layer: table.layer, - site: table.site, - width: table.width, - trigger: trigger(program.controls.units[table.group]), - entries: table.entries, - keep: table.keep, - bias: table.bias, - })); - const order = (rows) => [...rows].sort((a, b) => a.layer - b.layer || a.site.localeCompare(b.site)); - const got = order(tables); - const want = order(entry.tables); - assert.equal(got.length, want.length, `${arch} ${entry.name} tables`); - want.forEach((table, i) => { - const where = `${arch} ${entry.name} L${table.layer} ${table.site}`; - assert.deepEqual( - { layer: got[i].layer, site: got[i].site, width: got[i].width, trigger: got[i].trigger, entries: got[i].entries }, - { layer: table.layer, site: table.site, width: table.width, trigger: table.trigger, entries: table.entries }, - where, - ); - near(got[i].keep, table.keep, ablation.tolerance.library, `${where} keep`); - near(got[i].bias, table.bias, ablation.tolerance.library, `${where} bias`); - }); - } - } - console.log("units compiler: neuron pushes and unit ablations lower as drowse's goldens do"); -} finally { - await server.close(); -} diff --git a/webui/scripts/units-lens-reads.test.mjs b/webui/scripts/units-lens-reads.test.mjs deleted file mode 100644 index 661b068..0000000 --- a/webui/scripts/units-lens-reads.test.mjs +++ /dev/null @@ -1,117 +0,0 @@ -// The four-lens read, the S readout and the reading scales on the reference backend against -// drowse's lens-reads, slens and unit-stats goldens (B1-goldens §2.2, §2.6, §2.7). -import assert from "node:assert/strict"; -import { ARCHES, archGolden, assertClose, compareRecord, decode, viteServer } from "./support/units-goldens.mjs"; -import { unitsFixture } from "./support/units-fixture.mjs"; - -const server = await viteServer(); -try { - const reads = await server.ssrLoadModule("/src/hosted/runtime/units/lensReads.ts"); - const slensPort = await server.ssrLoadModule("/src/hosted/runtime/units/slens.ts"); - const scalesPort = await server.ssrLoadModule("/src/hosted/runtime/units/scales.ts"); - const dense = await server.ssrLoadModule("/src/hosted/runtime/units/denseModel.ts"); - for (const arch of ARCHES) { - const fx = await unitsFixture(server, arch); - const slens = archGolden("slens", arch); - // ------------------------------------------------- mask and statistics (§2.7) --- - const kept = [...fx.keep.keys()].filter((v) => fx.keep[v]); - assert.deepEqual(kept, slens.mask.kept, `${arch} token mask`); - const embeddings = await fx.context.embeddings(); - assertClose(embeddings.statistics.meanE.data, decode(slens.mean_E), slens.tolerance.library, `${arch} mean_E`); - assertClose(embeddings.statistics.sigmaE.data, decode(slens.sigma_E), slens.tolerance.library, `${arch} Σ_E`); - - // --------------------------------------------------------- lens reads (§2.6) --- - const golden = archGolden("lens-reads", arch); - const noS = await unitsFixture(server, arch, { families: ["R"] }); - const tol = golden.tolerance.library; - for (const [i, request] of golden.requests.entries()) { - const context = request.lens === "none prepared" ? noS.context : fx.context; - const [actual] = await reads.readVectors(context, [{ - rows: Float32Array.from(decode(request.rows)), - layer: request.layer, - site: request.site, - of: request.of, - }], request.k); - // The browser's missing-lens text names the pack to install, not native's CLI command. - const expected = request.lens === "none prepared" - ? request.reads.map((read) => ({ ...read, s: { ...read.s, absent: context.noLens.S } })) - : request.reads; - if (request.lens === "none prepared") assert.match(request.reads[0].s.absent, /^no S-lens available for /); - const problems = compareRecord(actual, expected, { - root: `requests[${i}].reads`, - ties: golden.declared_ties, - numberTol: (path, expected) => path.endsWith(".value") && /\.s\.tokens/.test(path) - ? tol.z_atol + 2e-6 - : path.endsWith(".value") ? tol.probability_atol + 2e-6 : 2e-6, - }); - assert.deepEqual(problems, [], `${arch} lens read ${i} (${request.of} L${request.layer} ${request.site})`); - } - - // ------------------------------------------- footprints, probes, atoms (§2.7) --- - const zTol = { atol: slens.tolerance.library.z_atol, rtol: 0 }; - for (const entry of slens.footprints) { - const u = Float32Array.from(decode(entry.u)); - const embeddingsResident = (await fx.context.embeddings()).resident; - const top = await fx.backend.footprintTopK({ dtype: "f32", shape: [u.length / 64, 64], data: u }, entry.k, embeddingsResident); - entry.top.forEach((row, r) => { - assert.deepEqual(Array.from(top.ids.data.slice(r * entry.k, (r + 1) * entry.k)), row.map((t) => t.token_id), `${arch} footprint L${entry.layer} row ${r} ids`); - assertClose(top.z.data.slice(r * entry.k, (r + 1) * entry.k), row.map((t) => t.z), zTol, `${arch} footprint z`); - }); - } - const sequence = new dense.DenseSequence(fx.model, 64); - const outs = []; - sequence.forward(fx.record.short_prompt, { capture: (layer, site) => { outs[layer] = site.out; } }); - const ids = Int32Array.from(slens.probe_word_ids); - const positions = [2, 5, 11]; - const columns = []; - for (const position of positions) { - const hidden = new Float32Array(4 * 64); - outs.forEach((out, layer) => hidden.set(out.subarray(position * 64, (position + 1) * 64), layer * 64)); - columns.push(await slensPort.slensProbeRows(fx.context, hidden, ids)); - } - assertClose(columns[0].depths, decode(slens.probe_depths), { atol: 1e-7 }, `${arch} probe depths`); - assertClose(columns[0].weights, decode(slens.probe_weights), { atol: 1e-7 }, `${arch} probe weights`); - slens.probes.forEach((probe, p) => { - const expected = decode(probe.rows); - const rows = expected.length / positions.length; - const actual = Float32Array.from({ length: expected.length }, (_, i) => columns[i % positions.length].rows[p][Math.floor(i / positions.length)]); - assert.equal(rows, 3 + columns[0].layers.length); - assertClose(actual, expected, zTol, `${arch} slens/${probe.word} probe rows`); - }); - for (const atom of slens.atoms) { - const word = atom.atom.slice("slens/".length); - const id = word.startsWith("#") ? Number(word.slice(1)) : fx.tokenizer.encode(word)[0]; - const directions = await slensPort.slensAtomDirections(fx.context, word, id); - assert.deepEqual([...directions.keys()].map(String), Object.keys(atom.layers)); - for (const [layer, values] of Object.entries(atom.layers)) { - assertClose(directions.get(Number(layer)), decode(values), slens.tolerance.library, `${arch} ${atom.atom} L${layer}`); - } - } - await assert.rejects( - slensPort.slensAtomDirections(fx.context, `#${slens.refusal.token_id}`, slens.refusal.token_id), - (error) => error.code === slens.refusal.code && error.status === slens.refusal.status && error.message === slens.refusal.text, - ); - - // ------------------------------------------------------- reading scales (§2.2) --- - const stats = fx.stats; - const unitStats = { - documents: stats.n_documents, - neuronMean: Float32Array.from(decode(stats.neuron_mean)), - neuronScale: Float32Array.from(decode(stats.neuron_scale)), - headMean: Float32Array.from(decode(stats.head_mean)), - headScale: Float32Array.from(decode(stats.head_scale)), - }; - const scales = scalesPort.readingScales(unitStats, fx.model.spec, 4); - assert.equal(scales.source, stats.scales.source); - assert.equal(scales.detail, stats.scales.detail); - assertClose(scales.neuron, decode(stats.scales.neuron), stats.tolerance.library, `${arch} neuron scales`); - assertClose(scales.head, decode(stats.scales.head), stats.tolerance.library, `${arch} head scales`); - assertClose(scales.typical.neuron, stats.scales.typical.neuron.map(Math.fround), { atol: 0 }, `${arch} typical neuron`); - assertClose(scales.typical.head, stats.scales.typical.head.map(Math.fround), { atol: 0 }, `${arch} typical head`); - assert.equal(Math.fround(scales.typical.modelNeuron), Math.fround(stats.scales.typical.model_neuron)); - assert.equal(Math.fround(scales.typical.modelHead), Math.fround(stats.scales.typical.model_head)); - } - console.log("units lens reads: R and S halves, mask and Σ_E match drowse"); -} finally { - await server.close(); -} diff --git a/webui/scripts/units-pack-source.test.mjs b/webui/scripts/units-pack-source.test.mjs deleted file mode 100644 index 68e1f8c..0000000 --- a/webui/scripts/units-pack-source.test.mjs +++ /dev/null @@ -1,238 +0,0 @@ -// The units members' packs on a loaded model (units/packSource.ts) over B6's registry, on drowse's -// tiny fixture: build_hosted_packs.py builds the R, S, units and core-statistics packs from the -// fixture session (scripts/support/units-tiny-packs.py), the core whitener is fitted from its -// neutral rows as the core builder fits it, and the browser registry reads them back. The pack -// source must serve the unit-artifacts golden's tensors, native's S mask digest and lens -// identities, B5's fixture whitener and the unit-stats golden; and the units service over it -// (the CPU block-sites backend on the tiny model) answers every unit-reads read and top as drowse. -import assert from "node:assert/strict"; -import { execFile } from "node:child_process"; -import { createHash } from "node:crypto"; -import { mkdtemp, readFile, rm } from "node:fs/promises"; -import { tmpdir } from "node:os"; -import { join, resolve } from "node:path"; -import { promisify } from "node:util"; -import { collectPackArtifacts } from "./assemble-hosted-pack.mjs"; -import { fitNativeNeutralWhitener, neutralWhitenerSidecar } from "./neutral-whitener-node.mjs"; -import { fixtureWhiteners } from "./support/units-compiler.mjs"; -import { unitsFixture } from "./support/units-fixture.mjs"; -import { ARCHES, archGolden, closeness, compareRecord, decode, viteServer, webuiRoot } from "./support/units-goldens.mjs"; - -const exec = promisify(execFile); -const python = process.env.PYTHON ?? "python3"; -const revision = "a".repeat(40); -const CONTEXT = 64; - -const sha = (bytes) => createHash("sha256").update(bytes).digest("hex"); -const artifact = (path, bytes, role) => ({ - manifest: { - path, role, revision, bytes: bytes.byteLength, sha256: sha(bytes), - url: `https://huggingface.co/drowse/local/resolve/${revision}/${path}`, - }, - file: new File([bytes], path), -}); - -async function packEntry(directory, kind, fingerprint) { - const { files } = await collectPackArtifacts(directory); - const catalogFiles = files.map((file) => ({ - ...file, role: "instrument", revision, url: `https://huggingface.co/drowse/local/resolve/${revision}/${file.path}`, - })); - return { - pack: { id: `units-tiny-${kind}`, kind, displayName: `units-tiny ${kind}`, runtimeIdentitySha256: fingerprint, files: catalogFiles }, - artifacts: await Promise.all(catalogFiles.map(async (entry) => ({ - manifest: entry, file: new File([await readFile(resolve(directory, entry.path))], entry.path), - }))), - }; -} - -/** The core pack's neutral statistics and one context's whitener, as the core builder writes them - * from `build_hosted_packs.py`'s staged `core/` (the whitener fitted in Node from its rows). */ -async function coreArtifacts(server, directory, identity, fingerprint, binding) { - const record = JSON.parse(await readFile(resolve(directory, "neutral-statistics.json"), "utf8")); - const rows = await readFile(resolve(directory, record.neutral_rows?.file ?? "neutral-rows.safetensors")); - assert.equal(sha(rows), record.neutral.rows_sha256, "the staged rows are the ones the statistics name"); - const modelLock = { layerMap: identity.layerMap, hiddenSize: identity.hiddenSize }; - const fitted = await fitNativeNeutralWhitener(server, rows, modelLock); - const sidecar = neutralWhitenerSidecar({ - runtimeIdentitySha256: fingerprint, contextBindingSha256: binding, modelLock, - tensorsSha256: sha(fitted.tensorBytes), ridgePerLayer: fitted.ridgePerLayer, - }); - const statistics = new TextEncoder().encode(JSON.stringify({ - ...record, - whitener: { - rows_sha256: record.neutral.rows_sha256, - tensors_sha256: { [CONTEXT]: sha(fitted.tensorBytes) }, - sidecars_sha256: { [CONTEXT]: sha(sidecar) }, - }, - })); - return [ - artifact("core/neutral-statistics.json", statistics, "core_pack"), - artifact(`core/${record.tensor_file}`, await readFile(resolve(directory, record.tensor_file)), "core_pack"), - artifact(`core/${CONTEXT}/neutral-whitener.safetensors`, fitted.tensorBytes, "core_pack"), - artifact(`core/${CONTEXT}/neutral-whitener.json`, sidecar, "core_pack"), - ]; -} - -const server = await viteServer(); -const scratch = await mkdtemp(join(tmpdir(), "units-pack-source-")); -try { - const [packs, registryModule, core, catalog, reader, cpu, profiles, service] = await Promise.all([ - server.ssrLoadModule("/src/hosted/runtime/units/packSource.ts"), - server.ssrLoadModule("/src/hosted/runtime/browserInstrumentPacks.ts"), - server.ssrLoadModule("/src/hosted/runtime/browserCorePack.ts"), - server.ssrLoadModule("/src/lib/runtime/catalog.ts"), - server.ssrLoadModule("/src/hosted/runtime/units/unitReader.ts"), - server.ssrLoadModule("/src/hosted/runtime/units/cpuBackend.ts"), - server.ssrLoadModule("/src/hosted/runtime/structuredHookProfile.ts"), - server.ssrLoadModule("/src/hosted/runtime/units/unitsService.ts"), - ]); - for (const arch of ARCHES) { - const out = join(scratch, arch); - const { stdout } = await exec(python, [resolve(webuiRoot, "scripts/support/units-tiny-packs.py"), arch, out], { - maxBuffer: 1 << 24, - env: { ...process.env, PYTHONUNBUFFERED: "1" }, - }); - const native = JSON.parse(stdout); - const identity = native.runtime.runtimeIdentity; - const fingerprint = native.runtime.runtimeIdentitySha256; - const binding = catalog.contextBindingSha256(fingerprint, CONTEXT); - const signal = new AbortController().signal; - const request = { - model: { id: "units-tiny" }, - variant: { - id: "units-tiny-q0f32", runtimeIdentity: identity, runtimeIdentitySha256: fingerprint, - contextProfiles: [{ contextTokens: CONTEXT, bindingSha256: binding }], - }, - requiredCorePack: { files: [] }, - contextTokens: CONTEXT, - adapter: {}, - artifacts: await coreArtifacts(server, join(out, "core"), identity, fingerprint, binding), - optionalPacks: await Promise.all(["jlens", "slens", "units"].map((kind) => packEntry(join(out, kind), kind, fingerprint))), - activationSpool: {}, - signal, - onDeviceLost() {}, - }; - const registry = await registryModule.BrowserInstrumentRegistry.load(request); - const coreFiles = request.artifacts; - const whiteners = await core.loadCoreWhiteners(coreFiles[2], coreFiles[3], request); - // The compiler surface the source reads (BrowserFeasibilityCorePackCompiler's). - let neutralReads = 0; - const compiler = { - instrumentRegistry: () => registry, - neutralStatistics: (abort) => { - neutralReads += 1; - return registryModule.readNeutralStatistics(coreFiles, { variant: request.variant, signal: abort }); - }, - neutralWhitener: (layer) => whiteners.get(layer) ?? null, - }; - const source = packs.compilerUnitsPackSource(() => compiler, "units-tiny", signal); - - // ------------------------------------------------------------- lens identities --- - for (const [family, kind] of [["R", "jlens"], ["S", "slens"]]) { - const lens = source.lens(family); - assert.equal(lens.identity, native.record.packs[kind].lens_identity, `${arch} ${family} lens identity`); - assert.equal(lens.source, `units-tiny-${kind}`); - for (const site of lens.sites) { - for (const layer of lens.layers(site)) { - assert.equal((await lens.fetch(site, layer)).length, identity.hiddenSize ** 2); - } - } - } - - // --------------------------------------------- S statistics and the mask digest --- - const fx = await unitsFixture(server, arch, { modelId: "units-tiny" }); - const slens = archGolden("slens", arch); - const embedding = await source.embeddingStatistics(); - assert.equal(embedding.maskDigest, native.maskDigest, `${arch} native _mask_digest`); - assert.ok(closeness(embedding.meanE, decode(slens.mean_E), 1e-6, 1e-6).worst <= 0, `${arch} mean_E`); - assert.ok(closeness(embedding.sigmaE, decode(slens.sigma_E), 1e-6, 1e-6).worst <= 0, `${arch} Σ_E`); - - // ------------------------------------------------- unit statistics and means --- - const { statistics, absent } = await source.statistics(); - assert.equal(absent, null); - assert.equal(statistics.documents, fx.stats.n_documents); - for (const [key, name] of [["neuronMean", "neuron_mean"], ["neuronScale", "neuron_scale"], ["headMean", "head_mean"], ["headScale", "head_scale"]]) { - assert.ok(closeness(statistics[key], decode(fx.stats[name]), 1e-6, 1e-5).worst <= 0, `${arch} ${name}`); - } - const means = await source.means(); - assert.equal(means.out.length, identity.layerMap.length * identity.hiddenSize); - assert.ok(closeness(means.out, fx.means.out, 1e-5, 1e-4).worst <= 0, `${arch} neutral out means`); - - // --------------------------------- units tensors: the unit-artifacts golden --- - const artifacts = archGolden("unit-artifacts", arch); - const tol = artifacts.tolerance.python; - for (const entry of artifacts.layers) { - const reads = await source.layerArtifacts(entry.layer, "reads"); - const contrast = await source.layerArtifacts(entry.layer, "contrast"); - assert.deepEqual([...reads.keys(), ...contrast.keys()].sort(), Object.keys(entry.tensors).sort(), `${arch} L${entry.layer} keys`); - for (const [key, value] of Object.entries(entry.tensors)) { - const actual = reads.get(key) ?? contrast.get(key); - const { worst } = closeness(actual, decode(value), tol.atol, tol.rtol); - assert.ok(worst <= 0, `${arch} L${entry.layer} ${key}`); - } - } - assert.deepEqual([...await source.headKeptIds()], artifacts.head_kept_ids, `${arch} head_kept_ids`); - const projector = Float32Array.from(decode(artifacts.null.projector)); - const d = identity.hiddenSize; - for (let trial = 0; trial < 4; trial += 1) { - const w = Float32Array.from({ length: d }, (_, i) => Math.sin(17 * trial + 3 * i + 1)); - let quad = 0; - for (let i = 0; i < d; i += 1) for (let j = 0; j < d; j += 1) quad += w[i] * projector[i * d + j] * w[j]; - assert.ok(Math.abs(await source.nullProjection(w) - quad) <= 1e-4 * Math.max(1, quad), `${arch} null projection`); - } - - // ------------------------------------------- the whitener: B5's fixture one --- - for (const row of fixtureWhiteners.arches[arch]) { - const ours = await source.whitener(row.layer); - const theirs = { - columns: d, rank: row.eigenvalues.length, ridge: row.ridge, mean: Float64Array.from(row.mean), - basis: Float64Array.from(row.basis.flat()), eigenvalues: Float64Array.from(row.eigenvalues), - inverseScales: new Float64Array(row.eigenvalues.length), - }; - const x = Float32Array.from({ length: 3 * d }, (_, i) => Math.cos(0.37 * i + row.layer)); - const { worst } = closeness(reader.whitenRows(ours, x, 3), reader.whitenRows(theirs, x, 3), 1e-4, 1e-4); - assert.ok(worst <= 0, `${arch} L${row.layer} whitener acts as the fixture's`); - } - - // ---------------- the units service over the source: unit-reads as drowse --- - const backend = cpu.cpuBlockSitesBackend(fx.model, { profile: profiles.STANDARD_STRUCTURED_HOOK_PROFILE_V4, contextTokens: CONTEXT }); - const units = new service.BrowserUnitsService({ - modelId: "units-tiny", - blockSites: () => backend, - // The fixture session reads with its own S→R band (a hosted session keeps native's default). - packs: () => ({ ...source, band: { lo: fx.file.band[0], hi: fx.file.band[1] } }), - tokenTexts: async (ids) => ids.map((id) => fx.tokenizer.decode([id])), - resolveToken: packs.sTokenResolver({ - tokenizeText: async (text) => fx.tokenizer.encode(text), - tokenTexts: async (ids) => ids.map((id) => fx.tokenizer.decode([id])), - }, () => fx.model.vocabSize), - replay: () => null, - }); - const golden = archGolden("unit-reads", arch); - const libraryTol = golden.tolerance.library; - const numberTol = (path) => { - if (/\.(value|z|footprint_z|score|coeff|share|mean_share|copy_score\.[RS])$/.test(path)) return libraryTol.z_atol + 2e-6; - if (/probability$/.test(path)) return libraryTol.probability_atol + 2e-6; - // float32 values up to ~10: a few ulps, which differ between CPUs (x64 CI against arm64). - return 1e-5; - }; - for (const [i, entry] of golden.reads.entries()) { - const actual = await units.request("unitRead", [entry.unit, { k: entry.k, hideHubs: entry.hide_hubs }]); - assert.deepEqual(compareRecord(actual, entry.read, { root: `reads[${i}].read`, ties: golden.declared_ties, numberTol }), [], `${arch} unitRead ${entry.unit}`); - } - for (const [i, entry] of golden.top.entries()) { - const actual = await units.request("unitTop", [entry.token, { by: entry.by, k: entry.k }]); - assert.deepEqual(compareRecord(actual, entry.result, { root: `top[${i}].result`, ties: golden.declared_ties, numberTol }), [], `${arch} unitTop ${entry.token}`); - } - for (const [i, entry] of golden.find.entries()) { - if (entry.target !== "vector") continue; - const actual = await units.request("unitFind", [{ vector: entry.vector, layer: entry.layer, k: entry.k }]); - assert.deepEqual(compareRecord(actual, entry.result, { root: `find[${i}].result`, ties: golden.declared_ties, numberTol }), [], `${arch} unitFind vector`); - } - assert.ok(neutralReads >= 1); - } - console.log("units pack source: the registry's packs serve drowse's artifacts, mask digest, whitener and unit reads"); -} finally { - await server.close(); - await rm(scratch, { recursive: true, force: true }); -} diff --git a/webui/scripts/units-probe-digest.test.mjs b/webui/scripts/units-probe-digest.test.mjs index 288fdae..baf082a 100644 --- a/webui/scripts/units-probe-digest.test.mjs +++ b/webui/scripts/units-probe-digest.test.mjs @@ -2,9 +2,16 @@ // (`UnitsInstrument.probe_hash`, `LensInstrument.probe_hash` and `_centre_digest`). The // expected strings and digests were printed by CPython 3.13 from the same tuples. import assert from "node:assert/strict"; -import { viteServer } from "./support/units-goldens.mjs"; +import { fileURLToPath } from "node:url"; +import { createServer } from "vite"; -const server = await viteServer(); +const server = await createServer({ + root: fileURLToPath(new URL("..", import.meta.url)), + configFile: false, + appType: "custom", + logLevel: "silent", + server: { middlewareMode: true, watch: null }, +}); try { const digest = await server.ssrLoadModule("/src/hosted/runtime/units/probeDigest.ts"); const unitTuple = [ diff --git a/webui/scripts/units-probes.test.mjs b/webui/scripts/units-probes.test.mjs deleted file mode 100644 index 06c77de..0000000 --- a/webui/scripts/units-probes.test.mjs +++ /dev/null @@ -1,69 +0,0 @@ -// Live unit taps (B1 §2.2) on the reference backend against drowse's unit-probes golden: the -// program compiled by the structured compiler (probes attached, steering lowered), then each -// forward's tap values over their reading scales (the units channel's readings), under unit -// ablations and a unit gate evaluated from the previous forward's taps, as the decode loop does. -import assert from "node:assert/strict"; -import { ARCHES, archGolden, compareRecord, viteServer } from "./support/units-goldens.mjs"; -import { unitsFixture } from "./support/units-fixture.mjs"; -import { unitsCompiler } from "./support/units-compiler.mjs"; - -const server = await viteServer(); -try { - const [hooks, program] = await Promise.all([ - server.ssrLoadModule("/src/hosted/runtime/structuredHookProgram.ts"), - server.ssrLoadModule("/src/hosted/runtime/units/unitProgram.ts"), - ]); - for (const arch of ARCHES) { - const fx = await unitsFixture(server, arch); - const golden = archGolden("unit-probes", arch); - // B1-goldens §3: `activation_over_scale` within z_atol; the raw activation or write norm a - // reading's meta carries within the library rule; the rest (depth) within the rounded rule. - // Each 6-decimal field also carries its own rounding (2e-6). - const { z_atol, atol, rtol } = golden.tolerance.library; - const rounded = golden.tolerance.rounded.atol; - const readingTolerance = (path, expected) => { - if (/\.(value|per_layer\.\d+)$/.test(path)) return z_atol + rounded; - if (/\.meta\.(activation|write_norm)$/.test(path)) return atol + rtol * Math.abs(expected) + rounded; - return rounded; - }; - // The program as generation compiles it: the golden's probes attached, its steering lowered - // by the structured compiler (ablations, the gate's unit tapped, the gate's control). - const { compiler, compile } = await unitsCompiler(server, fx, arch); - for (const name of golden.probes) compiler.attachProbe({ selector: name }); - for (const entry of golden.cases) { - const compiled = await compile(entry.steering ?? ""); - assert.equal(compiled.format, "drowse-structured-v4", `${arch} ${entry.name}`); - const bound = await fx.backend.bindStructuredProgram(compiled); - const evaluate = hooks.createStructuredHookControlEvaluator(bound); - const replay = await fx.backend.openReplay({ program: bound, anatomyPosition: null, activity: null, patternLayers: null }); - const inputs = [golden.ids, ...entry.tokens.slice(0, entry.forwards.length - 1).map((token) => [token])]; - let readback = null; - for (const [step, ids] of inputs.entries()) { - const priorScores = readback === null ? null : program.unitGateScores(bound, readback); - if (step > 0 && entry.gate_scalars.length) { - // Every recorded gate scalar (native keys it by name and by `name[0]`, the scalar - // channel) is one the browser's next forward reads. - const recorded = entry.gate_scalars[step - 1]; - for (const [key, value] of Object.entries(recorded)) { - const name = key.endsWith("[0]") ? key.slice(0, -3) : key; - assert.ok(name in priorScores, `${arch} ${entry.name} gate scalar ${key} at step ${step} is missing`); - assert.ok(Math.abs(priorScores[name] - value) <= z_atol, `${arch} ${entry.name} gate scalar ${key} at step ${step}`); - } - } - const controlState = evaluate({ prefill: step === 0, thinking: false, generatedTokens: step, priorScores }); - readback = await replay.forward({ tokenIds: Int32Array.from(ids), controls: controlState }); - // The units channel carries the attached probes only: a gate's unit (neuron/L3n9 in the - // gated case) is tapped but has no reading. - const { readings } = program.unitTapReadings(bound.measurementSchema.unitTaps, readback.unitTaps.data, 4, new Set(golden.probes)); - const expected = entry.forwards[step].readings; - assert.deepEqual(Object.keys(readings).sort(), Object.keys(expected).sort(), `${arch} ${entry.name} forward ${step} probes`); - const problems = compareRecord(readings, expected, { numberTol: readingTolerance }); - assert.deepEqual(problems, [], `${arch} ${entry.name} forward ${step}`); - } - await replay.cancel(); - } - } - console.log("units probes: live taps, readings and unit gates match drowse's unit-probes"); -} finally { - await server.close(); -} diff --git a/webui/scripts/units-reference-backend.test.mjs b/webui/scripts/units-reference-backend.test.mjs index 2cc420a..186516c 100644 --- a/webui/scripts/units-reference-backend.test.mjs +++ b/webui/scripts/units-reference-backend.test.mjs @@ -1,17 +1,23 @@ -// The test-only CPU reference backend (webui/src/hosted/runtime/units/): the tiny fixture -// models regenerate to the model file's digests, and the dense forward reproduces drowse's -// block-sites goldens (every site, layer and position; the last logits). +// The fixture runtime's tiny models (webui/src/hosted/runtime/units/): each arch's weights +// regenerate to the model file's digests and its tokenizer reads the recorded short prompt. import assert from "node:assert/strict"; import { createHash } from "node:crypto"; -import { ARCHES, archGolden, assertClose, decode, golden, viteServer } from "./support/units-goldens.mjs"; +import { readFileSync } from "node:fs"; +import { fileURLToPath } from "node:url"; +import { createServer } from "vite"; -const server = await viteServer(); +const server = await createServer({ + root: fileURLToPath(new URL("..", import.meta.url)), + configFile: false, + appType: "custom", + logLevel: "silent", + server: { middlewareMode: true, watch: null }, +}); try { const tiny = await server.ssrLoadModule("/src/hosted/runtime/units/tinyModels.ts"); - const dense = await server.ssrLoadModule("/src/hosted/runtime/units/denseModel.ts"); - const file = golden("units-tiny-models-v1.json"); + const file = JSON.parse(readFileSync(new URL("../src/hosted/runtime/fixtures/units-tiny-models-v1.json", import.meta.url), "utf8")); - for (const arch of ARCHES) { + for (const arch of ["gemma3", "qwen3"]) { const record = file.arches[arch]; const tensors = tiny.tinyTensors(file, arch); for (const entry of record.tensors) { @@ -25,35 +31,8 @@ try { const ids = [...(record.tokenizer.bos === null ? [] : [record.tokenizer.bos]), ...tokenizer.encode(text)]; assert.deepEqual(ids, record.short_prompt, `${arch} short prompt tokenizes as drowse's`); assert.equal(tokenizer.decode(record.short_prompt), (record.tokenizer.bos === null ? "" : "") + text); - - // ------------------------------------------------------- block sites (B1-goldens §2.1) --- - const sites = archGolden("block-sites", arch); - const tol = sites.tolerance.library; - const model = tiny.tinyModelWeights(file, arch); - const sequence = new dense.DenseSequence(model, 64); - const captured = {}; - const hidden = sequence.forward(sites.ids, { - capture(layer, site) { - for (const [name, key] of [ - ["block_in", "blockIn"], ["z", "z"], ["attn_o", "attnO"], ["mid", "mid"], - ["act", "act"], ["mlp_o", "mlpO"], ["out", "out"], - ]) (captured[name] ??= [])[layer] = site[key]; - }, - }); - for (const [name, value] of Object.entries(sites.sites)) { - const expected = decode(value); - const actual = new Float32Array(expected.length); - let at = 0; - for (const layer of captured[name]) { - actual.set(layer, at); - at += layer.length; - } - assertClose(actual, expected, tol, `${arch} block-sites ${name}`); - } - const last = (sites.ids.length - 1) * model.hiddenSize; - assertClose(dense.finalLogits(model, hidden, last), decode(sites.logits_last), tol, `${arch} last logits`); } - console.log("units reference backend: tiny models and block sites match drowse"); + console.log("units tiny models: weights and tokenizers regenerate"); } finally { await server.close(); } diff --git a/webui/scripts/units-service.test.mjs b/webui/scripts/units-service.test.mjs deleted file mode 100644 index f2e0642..0000000 --- a/webui/scripts/units-service.test.mjs +++ /dev/null @@ -1,270 +0,0 @@ -// The worker's units members end to end: `instruments.` through BrowserInstrumentRuntime -// and BrowserUnitsService over the reference backend and fixture packs, answering drowse's -// goldens; native's argument refusals; a residual library's 422 refusal on every member but the -// (disk-only) catalog; the operation policy offering every member. -import assert from "node:assert/strict"; -import { readFileSync } from "node:fs"; -import { fileURLToPath } from "node:url"; -import { ARCHES, archGolden, compareRecord, viteServer } from "./support/units-goldens.mjs"; -import { unitsFixture, unitsPackSource } from "./support/units-fixture.mjs"; - -const whiteners = JSON.parse(readFileSync(fileURLToPath(new URL("../../browser-runtime/fixtures/units-tiny-whitener-v1.json", import.meta.url)), "utf8")); -const server = await viteServer(); -try { - const [service, runtime, policy, profiles, cpu] = await Promise.all([ - server.ssrLoadModule("/src/hosted/runtime/units/unitsService.ts"), - server.ssrLoadModule("/src/hosted/runtime/browserInstrumentRuntime.ts"), - server.ssrLoadModule("/src/hosted/runtime/operationPolicy.ts"), - server.ssrLoadModule("/src/hosted/runtime/structuredHookProfile.ts"), - server.ssrLoadModule("/src/hosted/runtime/units/cpuBackend.ts"), - ]); - // Routed to the loaded model, which wires this service at load. - for (const method of service.UNITS_SERVICE_METHODS) { - assert.equal(policy.runtimeServiceRoute({ service: "instruments", method, args: [] }), "model", `${method} is offered`); - } - let attached = []; - const stubCompiler = { - unitSource: undefined, - instrumentDescriptor: () => ({ jlens: null, sae: null }), - instrumentLiveState: () => ({ geometry: false, lens: false, lensLayers: null, sae: false }), - listProbes: () => attached, - setInstrumentLive() {}, - setUnitSource(source) { this.unitSource = source; }, - prepared: [], - async prepareUnitProbe(selector) { this.prepared.push(selector); }, - }; - const arch = "gemma3"; - const fx = await unitsFixture(server, arch); - const packs = unitsPackSource(fx, arch, whiteners); - const chat = fx.record.chat_prompt.ids; - const anatomyGolden = archGolden("token-anatomy", arch); - const activityGolden = archGolden("unit-activity", arch); - const generatedRows = activityGolden.cases[0].result.tokens.map((t) => t.token_id); - const replay = { - async nodeForward(nodeId, rawIndex, options) { - assert.equal(nodeId, "node-1"); - const anchor = rawIndex ?? generatedRows.length - 1; - return { - forward: { - ids: Int32Array.from([...chat, ...generatedRows.slice(0, anchor)]), - promptLength: chat.length, - rawIds: Int32Array.from(generatedRows), - rawIndex: anchor, - spans: [{ firstRow: 0, stopRow: generatedRows.length, at: chat.length - 1 }], - }, - program: null, - steering: null, - canThink: false, - options, - }; - }, - }; - // The service's residents, counted: a reset releases every one it uploaded. - const uploaded = new Set(); - const released = new Set(); - const counted = new Proxy(fx.backend, { - get(target, key) { - const value = target[key]; - if (typeof value !== "function") return value; - if (typeof key === "string" && key.startsWith("upload")) { - return async (...args) => { - const resident = await value.apply(target, args); - uploaded.add(resident.id); - return resident; - }; - } - if (key === "release") { - return async (resident) => { - released.add(resident.id); - return value.call(target, resident); - }; - } - return value.bind(target); - }, - }); - const units = new service.BrowserUnitsService({ - modelId: "units-tiny", - blockSites: () => counted, - packs: () => packs, - tokenTexts: async (ids) => ids.map((id) => fx.tokenizer.decode([id])), - resolveToken: async (word) => (word.startsWith("#") ? Number(word.slice(1)) : fx.tokenizer.encode(word)[0]), - replay: () => replay, - }); - const instruments = new runtime.BrowserInstrumentRuntime(stubCompiler, null, null, false); - const call = (method, ...args) => instruments.request({ service: "instruments", method, args }, () => null); - - // Before a service is configured: native's 422 for a library without unit sites. - await assert.rejects(call("unitRead", "neuron/L1n5"), (error) => error.status === 422 && error.code === "UnsupportedBlockError"); - assert.equal(instruments.blocks().some((block) => block.family === "units"), false); - await instruments.configureUnits(units); - // The compiler's unit source comes from the same service: the library's spec and statistics. - assert.equal(stubCompiler.unitSource.spec, fx.backend.capabilities().blockSpec); - assert.equal(stubCompiler.unitSource.refusal, null); - // Native `family_block("units")`: no source, live on by default, its probes; all-or-nothing live. - attached = [{ family: "units", name: "n", unit: "neuron/L1n5", kind: "neuron", layer: 1, index: 5, layers: [1], intrinsic_dim: 1, feature_space: "unit-readout" }]; - assert.deepEqual(instruments.blocks().find((block) => block.family === "units"), { - family: "units", live: { enabled: true }, source: null, probes: ["n"], - capabilities: { sources: false, preparations: [], token_readout: false, source_switch: false }, - }); - attached = []; - assert.equal(instruments.unitsLiveEnabled(), true); - assert.deepEqual(await call("setLive", "units", { enabled: false }), { enabled: false }); - assert.equal(instruments.unitsLiveEnabled(), false); - await assert.rejects(async () => call("setLive", "units", { enabled: true, layers: [1] }), /units live does not accept layers/); - await call("setLive", "units", { enabled: true }); - - // ------------------------------------------------------------------ static reads --- - const reads = archGolden("unit-reads", arch); - const numberTol = () => 1e-4 + 2e-6; - for (const [i, entry] of reads.reads.slice(0, 3).entries()) { - const actual = await call("unitRead", entry.unit, { k: entry.k, hideHubs: entry.hide_hubs }); - assert.deepEqual(compareRecord(actual, entry.read, { root: `reads[${i}].read`, ties: reads.declared_ties, numberTol }), [], `unitRead ${entry.unit}`); - } - const top = reads.top[0]; - assert.deepEqual(compareRecord(await call("unitTop", top.token, { by: top.by, k: top.k, layers: "all" }), top.result, { root: "top[0].result", ties: reads.declared_ties, numberTol }), []); - const find = reads.find[0]; - assert.deepEqual(compareRecord(await call("unitFind", { vector: find.vector, layer: find.layer, k: find.k }), find.result, { root: "find[0].result", ties: reads.declared_ties, numberTol }), []); - assert.equal((await call("unitCatalog")).reason, "no neuron-lens catalog for this model (catalogued: Qwen/Qwen3-8B, google/gemma-4-12B)"); - assert.deepEqual((await call("unitLabels", ["neuron/L1n5", "head/L2h0"])).labels, []); - - // ----------------------------------------------------------- native's refusals --- - const refuses = async (promise, text) => assert.rejects(promise, (error) => error.status === 400 && error.message === text); - await refuses(call("unitFind", {}), "find takes exactly one of selector or vector"); - await refuses(call("unitFind", { vector: [1] }), "a vector needs the layer it lives at"); - await refuses(call("unitLabels", []), "units names at least one neuron/… or head/… unit"); - await refuses(call("unitLabels", Array.from({ length: 129 }, () => "neuron/L1n5")), "units names at most 128 units"); - await refuses(call("unitRead", "neuron/L1n5", { k: 257 }), "k must be in [1, 256]"); - await refuses(call("unitTop", "Q"), `'Q' is token ${fx.tokenizer.encode("Q")[0]}, which the token mask drops (special, added and byte-fallback pieces and tokens too rare in the counted text never rank; mask: corpus)`); - await refuses(call("tokenAnatomy", "node-1", 3, { units: 65 }), "units must be in [1, 64]"); - await refuses(call("tokenAnatomy", "node-1", 3, { patterns: 17 }), "patterns must be in [0, 16]"); - await refuses(call("unitActivity", "node-1", { top: 0 }), "top must be in [1, 1024]"); - await refuses(call("unitActivity", "node-1", { layers: "0,2" }), "layers selects a population, which needs raw_index"); - await refuses(call("unitActivity", "node-1", { units: ["neuron/L1n5", "neuron/L1n5"] }), "units names a unit twice"); - // Layer selectors parse as native `parse_layer_selector` (modes any case, blank is the - // default, written order, a layer named twice refused) and resolve as `resolve_layer_selector`. - const topAll = await call("unitTop", top.token, { by: top.by, k: top.k, layers: "ALL" }); - assert.deepEqual(await call("unitTop", top.token, { by: top.by, k: top.k, layers: " " }), topAll); - assert.deepEqual(await call("unitTop", top.token, { by: top.by, k: top.k, layers: "3,0-2" }), topAll); - assert.ok(await call("unitTop", top.token, { by: top.by, k: top.k, layers: "Workspace" })); - await refuses(call("unitTop", "e", { layers: "1,1" }), "layer 1 is named twice in '1,1'"); - await refuses(call("unitTop", "e", { layers: "2-1" }), "reversed layer range '2-1' (write 1-2)"); - await refuses(call("unitTop", "e", { layers: "1,,2" }), "empty entry in layers '1,,2'"); - await refuses(call("unitTop", "e", { layers: "-1" }), "layer indices are non-negative; got '-1'"); - await refuses(call("unitTop", "e", { layers: "x" }), "malformed layers 'x' (want comma-separated indices or a-b ranges, or one of all, workspace, sample)"); - await refuses(call("unitTop", "e", { layers: "sample" }), "unknown layer mode 'sample' (want all, workspace, or an index list)"); - await refuses(call("unitTop", "e", { layers: "9" }), "layer 9 is outside the model's 4 layers"); - await refuses(call("unitFind", { vector: find.vector, layer: find.layer, layers: "0" }), "no overlap between 'vector''s layers and the requested layers"); - await refuses(call("unitActivity", "node-1", { rawIndex: 0, layers: "sample" }), "unknown layer mode 'sample' (want all, workspace, or an index list)"); - await refuses(call("unitActivity", "node-1", { rawIndex: 0, layers: "7" }), "layers must lie in [0, 4); got [7]"); - - // ------------------------------------------------------------------ node replays --- - const anatomyCase = anatomyGolden.cases[0]; - const envelope = await call("tokenAnatomy", "node-1", anatomyGolden.raw_index, anatomyCase.knobs); - assert.equal(envelope.measurements.scope, "replay"); - assert.deepEqual(envelope.measurements.anatomy.token, anatomyCase.envelope.measurements.anatomy.token); - assert.equal(envelope.measurements.anatomy.units.length, anatomyCase.knobs.units); - assert.deepEqual(envelope.measurements.instruments, {}, "no attached lens probe, no lens channel"); - assert.equal("scores" in envelope.measurements, false); - // Attached jlens/ and slens/ probes are scored over the replayed block outputs (native - // `score_probes({L: taps.out[L]})`): at layer 1 each reads what the anatomy's own residual read - // of its token reads there (drowse's numbers). - const asRead = anatomyCase.envelope.measurements.anatomy.layers[1].reads_as; - const [rTop, sTop] = [asRead.r.tokens[0], asRead.s.tokens[0]]; - attached = [ - { family: "lens", namespace: "jlens", name: "watch r", word: rTop.token, token_id: rTop.token_id, layers: [1], intrinsic_dim: 1, feature_space: "readout" }, - { family: "lens", namespace: "slens", name: "watch s", word: sTop.token, token_id: sTop.token_id, layers: [0, 1], intrinsic_dim: 1, feature_space: "readout" }, - ]; - const probed = (await call("tokenAnatomy", "node-1", anatomyGolden.raw_index, anatomyCase.knobs)).measurements; - const tol = anatomyGolden.tolerance.library; - const lensChannel = probed.instruments.lens; - assert.deepEqual(Object.keys(lensChannel.readings).sort(), ["watch r", "watch s"]); - assert.deepEqual(lensChannel.binding, { sources: { R: "local:r", S: "local:s" }, steering: null }); - assert.equal(lensChannel.readings["watch r"].unit, "mean_token_probability"); - assert.ok(Math.abs(lensChannel.readings["watch r"].per_layer["1"] - rTop.value) <= tol.probability_atol + 2e-6); - assert.equal(lensChannel.readings["watch r"].value, lensChannel.readings["watch r"].per_layer["1"]); - assert.equal(lensChannel.readings["watch s"].unit, "mean_footprint_z"); - assert.ok(Math.abs(lensChannel.readings["watch s"].per_layer["1"] - sTop.value) <= tol.z_atol + 2e-6); - assert.equal(lensChannel.readings["watch s"].depth.basis, "footprint_z"); - assert.deepEqual(probed.scores, { "watch r": lensChannel.readings["watch r"].value, "watch s": lensChannel.readings["watch s"].value }); - assert.deepEqual(probed.anatomy, envelope.measurements.anatomy); - attached = []; - const generated = activityGolden.cases[0]; - const activity = await call("unitActivity", "node-1", { - top: generated.arguments.top, units: generated.arguments.units, rawIndex: generated.arguments.raw_index, layers: generated.arguments.layers, - }); - assert.equal(activity.node_id, "node-1"); - const { node_id: _node, population: _population, ...rest } = activity; - const { population: _expected, ...expected } = generated.result; - assert.deepEqual(compareRecord(rest, expected, { root: "cases[0].result", ties: activityGolden.declared_ties, numberTol }), []); - - // ------------------------------------------------------ a replay's gate scorer --- - // A replayed forward's name-scored gates, as generation scores them: unit taps, the geometry - // readout (the backend's scorer) and the slens/ reads over the [L, d] capture. - { - const tokenId = fx.tokenizer.encode("e")[0]; - const probes = [{ name: "slens/e", word: "e", tokenId }]; - const hidden = Float32Array.from({ length: 4 * fx.model.hiddenSize }, (_, i) => Math.sin(i)); - const scoring = new service.BrowserUnitsService({ - modelId: "units-tiny", - blockSites: () => fx.backend, - packs: () => packs, - tokenTexts: async (ids) => ids.map((id) => fx.tokenizer.decode([id])), - resolveToken: async (word) => fx.tokenizer.encode(word)[0], - replay: () => replay, - geometryGateScores: (_program, geometry) => ({ "local/m:membership": geometry[0] }), - }); - const program = { measurementSchema: { slensProbes: probes } }; - const readback = { - measurements: { dtype: "f32", shape: [4, 8], data: new Float32Array(32) }, - unitTaps: null, - geometry: { dtype: "f32", shape: [1], data: Float32Array.of(0.375) }, - hidden: { dtype: "f32", shape: [4, fx.model.hiddenSize], data: hidden }, - }; - const scores = await scoring.replayGateScores(program, readback); - const expected = (await scoring.slensReads(hidden, probes)).values; - assert.deepEqual(scores, { "local/m:membership": 0.375, ...expected }); - assert.ok(Number.isFinite(scores["slens/e"])); - // Without a capture or a geometry readout, nothing beyond the unit taps is scored. - assert.deepEqual(await scoring.replayGateScores(program, { ...readback, geometry: null, hidden: null }), {}); - } - - // ------------------------------------------- a pack change (the R-source switch) --- - // The reset releases every lens matrix and the embedding statistics the session uploaded - // (the replays release their own scale tables), takes a unit source over the new session and - // prepares the attached slens/ probes again, so their probe hash survives the switch. - const sessionUploads = new Set([...uploaded].filter((id) => !released.has(id))); - assert.ok(sessionUploads.size > 0, "the reads above uploaded residents"); - const sourceBefore = stubCompiler.unitSource; - attached = [{ family: "lens", namespace: "slens", name: "slens/e", word: "e" }]; - stubCompiler.prepared = []; - await instruments.resetUnits(); - attached = []; - assert.deepEqual([...sessionUploads].filter((id) => !released.has(id)), [], "every session resident is released"); - assert.notEqual(stubCompiler.unitSource, sourceBefore); - assert.deepEqual(stubCompiler.prepared, ["slens/e"]); - // The service reopens over the packs after a reset. - const again = reads.reads[0]; - assert.deepEqual(compareRecord(await call("unitRead", again.unit, { k: again.k, hideHubs: again.hide_hubs }), again.read, { root: "reads[0].read", ties: reads.declared_ties, numberTol }), []); - - // ------------------------------------------------------- a residual library (422) --- - const residualBackend = cpu.cpuBlockSitesBackend(fx.model, { profile: profiles.STANDARD_STRUCTURED_HOOK_PROFILE_V4_RESIDUAL, contextTokens: 64 }); - const residual = new service.BrowserUnitsService({ - modelId: "units-tiny", - blockSites: () => residualBackend, - packs: () => packs, - tokenTexts: async (ids) => ids.map((id) => fx.tokenizer.decode([id])), - resolveToken: async () => 0, - replay: () => replay, - }); - const refusal = residualBackend.capabilities().unitRefusal; - for (const [method, args] of [ - ["unitRead", ["neuron/L1n5"]], ["unitTop", ["e"]], ["unitFind", [{ vector: [1], layer: 0 }]], - ["unitLabels", [["neuron/L1n5"]]], ["tokenAnatomy", ["node-1", 0]], ["unitActivity", ["node-1"]], - ]) { - await assert.rejects(residual.request(method, args), (error) => error.status === 422 && error.message === refusal, `${method} refuses`); - } - assert.equal((await residual.request("unitCatalog", [])).available, false); - console.log("units service: every member answers like drowse; residual libraries refuse"); -} finally { - await server.close(); -} diff --git a/webui/scripts/units-unit-reads.test.mjs b/webui/scripts/units-unit-reads.test.mjs deleted file mode 100644 index 62989fd..0000000 --- a/webui/scripts/units-unit-reads.test.mjs +++ /dev/null @@ -1,107 +0,0 @@ -// The UnitReader port (unitRead, unitTop, unitFind, catalog, labels) on the reference backend -// against drowse's unit-reads golden, with unit-artifacts as the offline packs and the fixture -// whitener (browser-runtime/fixtures/units-tiny-whitener-v1.json) as the core pack's. -import assert from "node:assert/strict"; -import { readFileSync } from "node:fs"; -import { fileURLToPath } from "node:url"; -import { ARCHES, archGolden, compareRecord, decode, viteServer } from "./support/units-goldens.mjs"; -import { projectorEnergy, unitsFixture } from "./support/units-fixture.mjs"; - -const whiteners = JSON.parse(readFileSync(fileURLToPath(new URL("../../browser-runtime/fixtures/units-tiny-whitener-v1.json", import.meta.url)), "utf8")); -const only = process.env.UNIT_READS_ONLY ?? null; - -const server = await viteServer(); -try { - const [readerModule, scalesModule] = await Promise.all([ - server.ssrLoadModule("/src/hosted/runtime/units/unitReader.ts"), - server.ssrLoadModule("/src/hosted/runtime/units/scales.ts"), - ]); - for (const arch of ARCHES) { - const fx = await unitsFixture(server, arch, { modelId: "units-tiny" }); - const reads = archGolden("unit-reads", arch); - const artifacts = archGolden("unit-artifacts", arch); - const stats = fx.stats; - const statistics = { - documents: stats.n_documents, - neuronMean: Float32Array.from(decode(stats.neuron_mean)), - neuronScale: Float32Array.from(decode(stats.neuron_scale)), - headMean: Float32Array.from(decode(stats.head_mean)), - headScale: Float32Array.from(decode(stats.head_scale)), - }; - const tables = new Map(artifacts.layers.map((entry) => [ - entry.layer, - new Map(Object.entries(entry.tensors).map(([key, value]) => [key, Float32Array.from(decode(value))])), - ])); - const reader = new readerModule.UnitReader({ - context: fx.context, - spec: fx.model.spec, - artifacts: { - statistics, - statisticsAbsent: null, - scales: scalesModule.readingScales(statistics, fx.model.spec, 4), - layer: async (layer) => tables.get(layer), - nullProjection: projectorEnergy(Float32Array.from(decode(artifacts.null.projector)), 64), - headKeptIds: async () => Int32Array.from(artifacts.head_kept_ids), - whitener: async (layer) => { - const entry = whiteners.arches[arch].find((row) => row.layer === layer); - return entry ? { - columns: 64, rank: entry.eigenvalues.length, ridge: entry.ridge, - mean: Float64Array.from(entry.mean), basis: Float64Array.from(entry.basis.flat()), - eigenvalues: Float64Array.from(entry.eigenvalues), inverseScales: new Float64Array(entry.eigenvalues.length), - } : null; - }, - }, - resolveToken: async (word) => (word.startsWith("#") ? Number(word.slice(1)) : fx.tokenizer.encode(word)[0]), - resolveSelector: async (selector) => { - // jlens/#: native `token_direction`, `W_U[v] @ J_L` per R:out layer (raw W_U). - const id = Number(selector.slice("jlens/#".length)); - const out = new Map(); - for (const [layer, matrix] of fx.lenses.get("R:out")) { - const row = fx.model.embed.subarray(id * 64, (id + 1) * 64); - out.set(layer, Float32Array.from({ length: 64 }, (_, j) => row.reduce((s, x, i) => s + x * matrix[i * 64 + j], 0))); - } - return out; - }, - }); - const tol = reads.tolerance.library; - const numberTol = (path) => { - if (/\.(value|z|footprint_z|score|coeff|share|mean_share|copy_score\.[RS])$/.test(path)) return tol.z_atol + 2e-6; - if (/probability$/.test(path)) return tol.probability_atol + 2e-6; - return 2e-6; - }; - for (const [i, entry] of reads.reads.entries()) { - if (only && only !== "reads") continue; - const actual = await reader.read(entry.unit, entry.k, entry.hide_hubs); - const problems = compareRecord(actual, entry.read, { root: `reads[${i}].read`, ties: reads.declared_ties, numberTol }); - assert.deepEqual(problems, [], `${arch} unitRead ${entry.unit} hide_hubs=${entry.hide_hubs}`); - } - for (const [i, entry] of reads.top.entries()) { - if (only && only !== "top") continue; - const actual = await reader.top(entry.token, entry.by, null, entry.k); - const problems = compareRecord(actual, entry.result, { root: `top[${i}].result`, ties: reads.declared_ties, numberTol }); - assert.deepEqual(problems, [], `${arch} unitTop ${entry.token} by ${entry.by}`); - } - for (const [i, entry] of reads.find.entries()) { - if (only && only !== "find") continue; - const actual = entry.target === "vector" - ? await reader.find({ vector: Float32Array.from(entry.vector), layer: entry.layer }, entry.k) - : await reader.find({ selector: entry.target }, entry.k); - const problems = compareRecord(actual, entry.result, { root: `find[${i}].result`, ties: reads.declared_ties, numberTol }); - assert.deepEqual(problems, [], `${arch} unitFind ${entry.target}`); - } - // ---------------------------------------------------------- catalog and labels --- - assert.deepEqual(reader.catalogStatus(), { - model_id: "units-tiny", available: false, bound: false, slug: null, repo: "stdlogits/neuron-lens", - revision: "b5bf11a2b9e35c9100a0fa0995ff7a4e57f5b777", credit: null, - reason: "no neuron-lens catalog for this model (catalogued: Qwen/Qwen3-8B, google/gemma-4-12B)", binding: null, - }); - assert.deepEqual(reader.labels(["neuron/L1n5", "head/L2h0"]).labels, []); - assert.throws(() => reader.labels(["neuron/L9n5"]), /layer 9 is outside the model \(4 blocks, 0\.\.3\)/); - assert.throws(() => reader.labels(["neuron/L1h5"]), /'neuron\/L1h5' is not a neuron reference/); - await assert.rejects(reader.read("head/L1h9"), /head 9 is outside block 1 \(4 heads, 0\.\.3\)/); - await assert.rejects(reader.read("neuron/L1n5", 0), /k must be in \[1, 256\]/); - } - console.log("units unit reads: unitRead, unitTop and unitFind match drowse"); -} finally { - await server.close(); -} diff --git a/webui/scripts/units-worker.worker.ts b/webui/scripts/units-worker.worker.ts deleted file mode 100644 index d346033..0000000 --- a/webui/scripts/units-worker.worker.ts +++ /dev/null @@ -1,81 +0,0 @@ -// The hosted runtime worker as the app runs it (HostedRuntimeWorker over the WebLLM model backend, -// the verified downloader, the content store and the archive service), on a catalog and runtime -// lock browser-units-worker.mjs stages for B4's tiny v5 fixture library and its packs. Only the -// catalog's signature check and the compatibility probe are stood in for: the harness serves its -// own catalog (fixture.invalid URLs, fetched from the harness server) and the device facts. -import type { - CatalogDocument, - RuntimeCapabilities, - VerifiedCatalog, -} from "../../drowse/webui/src/lib/runtime/contracts"; -import type { CatalogRuntimeLockModel } from "../src/lib/runtime/catalog"; -import { BrowserDrowseArchiveService } from "../src/hosted/artifacts/service"; -import { createLazyBrowserModelBackend } from "../src/hosted/runtime/browserModelBackend"; -import { BrowserContentStore } from "../src/hosted/runtime/contentStore"; -import { VerifiedArtifactDownloader } from "../src/hosted/runtime/downloader"; -import type { DrowseWebLlmModule } from "../src/hosted/runtime/webLlmEngine"; -import { HostedRuntimeWorker, type WorkerScopeLike } from "../src/hosted/runtime/worker"; - -interface HarnessConfig { - document: CatalogDocument; - capabilities: RuntimeCapabilities; - runtimeLockModels: CatalogRuntimeLockModel[]; - /** The units reads' S→R band, when the harness reads at a golden's (drowse sets - * `session.lens.band` the same way); the default otherwise. */ - lensBand?: { lo: number; hi: number }; -} - -const FIXTURE_ORIGIN = "https://fixture.invalid/"; -const WEB_LLM_URL = "/webllm.js"; -const config = await (await fetch("/harness/config.json", { cache: "no-store" })).json() as HarnessConfig; -const catalog: VerifiedCatalog = { - document: config.document, - exactBytes: new TextEncoder().encode(JSON.stringify(config.document)), - signature: { schemaVersion: 1, algorithm: "Ed25519", keyId: "units-worker-harness", signature: "harness" }, - allowDownloads: true, - stale: false, -}; - -async function harnessFetch(url: string, init: RequestInit): Promise { - if (!url.startsWith(FIXTURE_ORIGIN)) throw new TypeError(`Unknown harness artifact ${url}`); - const response = await fetch(`/fixture/${url.slice(FIXTURE_ORIGIN.length)}`, init); - Object.defineProperty(response, "url", { value: url }); - return response; -} - -const artifacts = new BrowserDrowseArchiveService(); -const contentStore = new BrowserContentStore(); -new HostedRuntimeWorker(globalThis as unknown as WorkerScopeLike, { - capabilityChecker: { - async check() { - return { ...config.capabilities, checkedAt: Date.now() }; - }, - clearAdapter() {}, - async adapterForLoad() { - const adapter = await (navigator as unknown as { gpu: { requestAdapter(): Promise } }).gpu.requestAdapter(); - if (adapter === null) throw new Error("the harness browser offers no WebGPU adapter"); - return adapter as never; - }, - }, - catalogRepository: { - async get() { - return catalog; - }, - async withDownloadAuthorization(_catalog, operation) { - return operation(); - }, - async clear() {}, - }, - contentStore, - downloader: new VerifiedArtifactDownloader(contentStore, { fetch: harnessFetch }), - artifactService: artifacts, - // The vendored bridge as the harness serves it (node_modules/@drowse/web-llm/lib/index.js), - // outside Vite's dependency optimizer. - modelBackend: createLazyBrowserModelBackend( - () => import(/* @vite-ignore */ WEB_LLM_URL) as Promise, - artifacts, - config.lensBand === undefined ? {} : { lensBand: config.lensBand }, - ), - runtimeLockModels: config.runtimeLockModels, -}); -(globalThis as unknown as { postMessage(message: unknown): void }).postMessage({ kind: "harness-ready" }); diff --git a/webui/scripts/verified-artifact-cache.test.mjs b/webui/scripts/verified-artifact-cache.test.mjs index 5525d92..c165c1c 100644 --- a/webui/scripts/verified-artifact-cache.test.mjs +++ b/webui/scripts/verified-artifact-cache.test.mjs @@ -355,7 +355,7 @@ try { model: { id: "fixture-model" }, variant: { id: "fixture-q4", - structuredHookProfile: "standard-v4-residual", + structuredHookProfile: "standard-v5-residual", thinkingProfile: null, runtimeIdentity: { hookAbi: "post-block-residual-v4", diff --git a/webui/scripts/web-llm-block-sites.test.mjs b/webui/scripts/web-llm-block-sites.test.mjs index 32ed386..5bcb45b 100644 --- a/webui/scripts/web-llm-block-sites.test.mjs +++ b/webui/scripts/web-llm-block-sites.test.mjs @@ -9,7 +9,6 @@ import { fileURLToPath } from "node:url"; import { createServer } from "vite"; const root = fileURLToPath(new URL("..", import.meta.url)); -const goldens = new URL("../../drowse/tests/fixtures/browser/", import.meta.url); const server = await createServer({ root, configFile: false, @@ -27,7 +26,7 @@ try { server.ssrLoadModule("/src/hosted/runtime/structuredHookProgram.ts"), server.ssrLoadModule("/src/hosted/runtime/modelBackend.ts"), ]); - const tiny = JSON.parse(readFileSync(new URL("units-tiny-models-v1.json", goldens), "utf8")).arches; + const tiny = JSON.parse(readFileSync(new URL("../src/hosted/runtime/fixtures/units-tiny-models-v1.json", import.meta.url), "utf8")).arches; const qwen = tiny.qwen3.config; const spec = profiles.validateBlockSpec({ dFF: qwen.intermediate_size, @@ -61,35 +60,35 @@ try { const request = (profile, extra = {}) => ({ variant: variant(profile), prefillChunkSize: 32, ...extra }); // ------------------------------------------------ descriptor model and attestation --- - const model = engine.hookProfileDescriptorModel(request("standard-v4", { blockSpec: spec })); + const model = engine.hookProfileDescriptorModel(request("standard-v5", { blockSpec: spec })); assert.deepEqual(model, { layerCount: 4, hiddenSize: 64, contextTokens: 128, prefillChunkSize: 32, blockSpec: spec, }); for (const prefillChunkSize of [null, undefined, 0, 65, 1.5]) { assert.throws( - () => engine.hookProfileDescriptorModel(request("standard-v4", { blockSpec: spec, prefillChunkSize })), + () => engine.hookProfileDescriptorModel(request("standard-v5", { blockSpec: spec, prefillChunkSize })), (error) => error.code === "HOOK_ABI_MISMATCH" && /prefill chunk/.test(error.message), String(prefillChunkSize), ); } - const v4 = profiles.STANDARD_STRUCTURED_HOOK_PROFILE_V4; - const residual = profiles.STANDARD_STRUCTURED_HOOK_PROFILE_V4_RESIDUAL; + const v4 = profiles.STANDARD_STRUCTURED_HOOK_PROFILE_V5; + const residual = profiles.STANDARD_STRUCTURED_HOOK_PROFILE_V5_RESIDUAL; const descriptor = Array.from(profiles.expectedHookProfileDescriptor(v4, model)); const bridgeProfile = (overrides = {}) => ({ schemaVersion: 4, - id: "standard-v4", + id: "standard-v5", unitSites: 1, descriptor: [...descriptor], - hookAbi: "block-sites-v5", - format: "drowse-structured-v4", + hookAbi: "block-sites-v6", + format: "drowse-structured-v5", ...overrides, }); const attest = (value, extra = { blockSpec: spec }) => - engine.attestCompiledStructuredHookProfile(value, request("standard-v4", extra), "block-sites-v5"); + engine.attestCompiledStructuredHookProfile(value, request("standard-v5", extra), "block-sites-v6"); const attested = attest(bridgeProfile()); assert.equal(attested.schemaVersion, 4); assert.equal(attested.unitSites, 1); - assert.equal(attested.format, "drowse-structured-v4"); + assert.equal(attested.format, "drowse-structured-v5"); assert.equal(attested.exactReadoutAbi, "exact-readout-v2"); assert.deepEqual(Array.from(attested.descriptor), descriptor); const fieldIndex = (name) => profiles.HOOK_PROFILE_DESCRIPTOR_V4_FIELDS.indexOf(name); @@ -108,7 +107,7 @@ try { ); assert.throws(() => attest(bridgeProfile({ unitSites: 0 })), (error) => error.code === "HOOK_ABI_MISMATCH"); assert.throws( - () => engine.attestCompiledStructuredHookProfile(bridgeProfile(), request("standard-v4", { blockSpec: spec }), "post-block-residual-v4"), + () => engine.attestCompiledStructuredHookProfile(bridgeProfile(), request("standard-v5", { blockSpec: spec }), "post-block-residual-v4"), (error) => error.code === "HOOK_ABI_MISMATCH", ); // A library compiled with the smallest context as its prefill chunk does not attest under a @@ -118,22 +117,22 @@ try { () => attest(bridgeProfile({ descriptor: contextPrefill })), (error) => error.code === "HOOK_ABI_MISMATCH" && /PREFILL_CHUNK_SIZE/.test(error.message), ); - // A standard-v4 library cannot be attested without the lock's block spec. + // A standard-v5 library cannot be attested without the lock's block spec. assert.throws(() => attest(bridgeProfile(), {}), (error) => error.code === "HOOK_ABI_MISMATCH" && /block spec/.test(error.message)); // A residual library attests the residual descriptor with no block spec. const residualModel = { ...model, blockSpec: null }; const residualDescriptor = Array.from(profiles.expectedHookProfileDescriptor(residual, residualModel)); const residualProfile = engine.attestCompiledStructuredHookProfile( - bridgeProfile({ id: "standard-v4-residual", unitSites: 0, descriptor: residualDescriptor }), - request("standard-v4-residual"), - "block-sites-v5", + bridgeProfile({ id: "standard-v5-residual", unitSites: 0, descriptor: residualDescriptor }), + request("standard-v5-residual"), + "block-sites-v6", ); assert.equal(residualProfile.unitSites, 0); // ---------------------------------------------------------------- capabilities --- - const capabilities = engine.blockSitesCapabilitiesFor(attested, request("standard-v4", { blockSpec: spec }), 259); - assert.equal(capabilities.profile.id, "standard-v4"); + const capabilities = engine.blockSitesCapabilitiesFor(attested, request("standard-v5", { blockSpec: spec }), 259); + assert.equal(capabilities.profile.id, "standard-v5"); assert.equal(capabilities.vocabSize, 259); assert.equal(capabilities.contextTokens, 128); assert.equal(capabilities.prefillChunkSize, 32); @@ -142,17 +141,17 @@ try { const refusal = "drowse units need a dense gated MLP block; gpt2 fuses q/k/v"; const residualCapabilities = engine.blockSitesCapabilitiesFor( residualProfile, - request("standard-v4-residual", { unitRefusal: refusal }), + request("standard-v5-residual", { unitRefusal: refusal }), 259, ); assert.equal(residualCapabilities.unitRefusal, refusal); - assert.equal(engine.blockSitesCapabilitiesFor(residualProfile, request("standard-v4-residual"), 259), null); - assert.equal(engine.blockSitesCapabilitiesFor(null, request("standard-v4"), 259), null); + assert.equal(engine.blockSitesCapabilitiesFor(residualProfile, request("standard-v5-residual"), 259), null); + assert.equal(engine.blockSitesCapabilitiesFor(null, request("standard-v5"), 259), null); // --------------------------------------------------------------- bridge surface --- const surface = backendModule.webLlmBlockSitesBackend(capabilities); assert.equal(surface.capabilities(), capabilities); - const plain = { format: "drowse-structured-v4", hookAbi: "block-sites-v5", affineActive: new Uint32Array(16) }; + const plain = { format: "drowse-structured-v5", hookAbi: "block-sites-v6", affineActive: new Uint32Array(16) }; assert.equal(await surface.bindStructuredProgram(plain), plain); const layout = programs.structuredUnitSectionLayout(v4, 4, spec.headDim); const unitProgram = () => ({ diff --git a/webui/scripts/web-llm-engine.test.mjs b/webui/scripts/web-llm-engine.test.mjs index b7bae58..18bbfa3 100644 --- a/webui/scripts/web-llm-engine.test.mjs +++ b/webui/scripts/web-llm-engine.test.mjs @@ -38,8 +38,8 @@ try { "/src/hosted/runtime/webLlmActivationCapture.ts", ); const { - STANDARD_STRUCTURED_HOOK_PROFILE_V4, - STANDARD_STRUCTURED_HOOK_PROFILE_V4_RESIDUAL, + STANDARD_STRUCTURED_HOOK_PROFILE_V5, + STANDARD_STRUCTURED_HOOK_PROFILE_V5_RESIDUAL, expectedHookProfileDescriptor, } = await server.ssrLoadModule("/src/hosted/runtime/structuredHookProfile.ts"); const { hookProfileDescriptorModel } = await server.ssrLoadModule( @@ -100,11 +100,11 @@ try { // exact readout, so its variant declares the exact-readout WebGPU limits. const variant = { id: "fixture-q4", - structuredHookProfile: "standard-v4-residual", + structuredHookProfile: "standard-v5-residual", thinkingProfile: null, contextProfiles: [{ contextTokens: 2048 }], runtimeIdentity: { - hookAbi: "block-sites-v5", + hookAbi: "block-sites-v6", sourceModel: "HuggingFaceTB/SmolLM2-360M-Instruct", hiddenSize: 2, layerMap: [0, 1], @@ -124,12 +124,12 @@ try { // attests element by element. const compiledProfile = (overrides = {}, forVariant = variant) => ({ schemaVersion: 4, - id: "standard-v4-residual", - hookAbi: "block-sites-v5", - format: "drowse-structured-v4", + id: "standard-v5-residual", + hookAbi: "block-sites-v6", + format: "drowse-structured-v5", unitSites: 0, descriptor: Array.from(expectedHookProfileDescriptor( - STANDARD_STRUCTURED_HOOK_PROFILE_V4_RESIDUAL, + STANDARD_STRUCTURED_HOOK_PROFILE_V5_RESIDUAL, hookProfileDescriptorModel({ variant: forVariant, prefillChunkSize: 1024 }), )), ...overrides, @@ -276,7 +276,7 @@ try { variant, }), null); const runtime = new DrowseWebLlmRuntime({ - DROWSE_HOOK_ABI: "block-sites-v5", + DROWSE_HOOK_ABI: "block-sites-v6", MLCEngine: FixtureEngine, }); const loadProgress = []; @@ -400,16 +400,16 @@ try { // The device's binding is the library's, derived from the verified files and the lock (one // 4-byte weight, 16 vocabulary rows, d = 2), not the variant's declared 128 MiB. const { libraryBindingBytes } = await server.ssrLoadModule("/src/hosted/runtime/modelBackend.ts"); - const derivedBinding = libraryBindingBytes(STANDARD_STRUCTURED_HOOK_PROFILE_V4_RESIDUAL, { + const derivedBinding = libraryBindingBytes(STANDARD_STRUCTURED_HOOK_PROFILE_V5_RESIDUAL, { layerCount: 2, hiddenSize: 2, vocabSize: 16, contextTokens: 2048, prefillChunkSize: 1024, blockSpec: null, largestWeightBytes: 4, }); assert.equal(appConfig.model_list[0].buffer_size_required_bytes, derivedBinding); assert.notEqual(derivedBinding, variant.requirements.limits.maxStorageBufferBindingSize); const hookProgram = compileStructuredHookProgram(2, [{ - affineGroups: [{ active: true, basis: [[1, 0]], neutral: [0, 0], target: [1], along: 0.5, kappa: [0] }], + affineGroups: [{ active: true, basis: [[1, 0]], read: [[1, 0]], neutral: [0, 0], target: [1], along: 0.5, kappa: [0] }], probes: [{ kind: "linear", direction: [1, 0], bias: 0 }], - }, {}], STANDARD_STRUCTURED_HOOK_PROFILE_V4_RESIDUAL); + }, {}], STANDARD_STRUCTURED_HOOK_PROFILE_V5_RESIDUAL); await runtime.installHookProgram(hookProgram); assert.equal(engine.hookProgram, hookProgram); const measurements = await runtime.readMeasurements(); @@ -524,7 +524,7 @@ try { }); const appleMobileRuntime = new DrowseWebLlmRuntime({ - DROWSE_HOOK_ABI: "block-sites-v5", + DROWSE_HOOK_ABI: "block-sites-v6", MLCEngine: FixtureEngine, }); await appleMobileRuntime.load(loadRequest({ @@ -557,7 +557,7 @@ try { } } const retryableUnloadRuntime = new DrowseWebLlmRuntime({ - DROWSE_HOOK_ABI: "block-sites-v5", + DROWSE_HOOK_ABI: "block-sites-v6", MLCEngine: RetryableUnloadEngine, }); await retryableUnloadRuntime.load(loadRequest()); @@ -587,7 +587,7 @@ try { } } const failedLoadCleanupRuntime = new DrowseWebLlmRuntime({ - DROWSE_HOOK_ABI: "block-sites-v5", + DROWSE_HOOK_ABI: "block-sites-v6", MLCEngine: FailedLoadCleanupEngine, }); await assert.rejects( @@ -629,7 +629,7 @@ try { // A program of any other format (the deleted rank-one buffers) is refused. await assert.rejects( runtime.installHookProgram({ - hookAbi: "block-sites-v5", hiddenSize: 2, layerCount: 2, enabled: Uint32Array.of(1, 0), + hookAbi: "block-sites-v6", hiddenSize: 2, layerCount: 2, enabled: Uint32Array.of(1, 0), }), (error) => error.code === "HOOK_FORMAT_MISMATCH", ); @@ -763,7 +763,7 @@ try { } } const lostDuringInit = new DrowseWebLlmRuntime({ - DROWSE_HOOK_ABI: "block-sites-v5", + DROWSE_HOOK_ABI: "block-sites-v6", MLCEngine: LostDuringInitEngine, }); await assert.rejects(lostDuringInit.load(loadRequest({ @@ -787,7 +787,7 @@ try { changedDescriptor[5] += 1; for (const [record, code] of [ [compiledProfile({ descriptor: changedDescriptor }), "HOOK_ABI_MISMATCH"], - [compiledProfile({ id: "standard-v4" }), "HOOK_ABI_MISMATCH"], + [compiledProfile({ id: "standard-v5" }), "HOOK_ABI_MISMATCH"], [compiledProfile({ unitSites: 1 }), "HOOK_ABI_MISMATCH"], [compiledProfile({ schemaVersion: 3 }), "HOOK_ABI_MISMATCH"], ]) { @@ -795,7 +795,7 @@ try { async getDrowseStructuredHookProfile() { return record; } } const mismatchedProfile = new DrowseWebLlmRuntime({ - DROWSE_HOOK_ABI: "block-sites-v5", + DROWSE_HOOK_ABI: "block-sites-v6", MLCEngine: MismatchedProfileEngine, }); await assert.rejects(mismatchedProfile.load(loadRequest()), (error) => error.code === code); @@ -804,7 +804,7 @@ try { // The descriptor's PREFILL_CHUNK_SIZE is the lock's: a load whose lock entry records none, or a // library compiled at the context (2048) under a lock recording 1024, fails attestation. await assert.rejects( - new DrowseWebLlmRuntime({ DROWSE_HOOK_ABI: "block-sites-v5", MLCEngine: FixtureEngine }) + new DrowseWebLlmRuntime({ DROWSE_HOOK_ABI: "block-sites-v6", MLCEngine: FixtureEngine }) .load(loadRequest({ prefillChunkSize: null })), (error) => error.code === "HOOK_ABI_MISMATCH" && /prefill chunk/u.test(error.message), ); @@ -812,24 +812,24 @@ try { async getDrowseStructuredHookProfile() { return compiledProfile({ descriptor: Array.from(expectedHookProfileDescriptor( - STANDARD_STRUCTURED_HOOK_PROFILE_V4_RESIDUAL, + STANDARD_STRUCTURED_HOOK_PROFILE_V5_RESIDUAL, hookProfileDescriptorModel({ variant, prefillChunkSize: 2048 }), )), }); } } await assert.rejects( - new DrowseWebLlmRuntime({ DROWSE_HOOK_ABI: "block-sites-v5", MLCEngine: ContextPrefillEngine }) + new DrowseWebLlmRuntime({ DROWSE_HOOK_ABI: "block-sites-v6", MLCEngine: ContextPrefillEngine }) .load(loadRequest()), (error) => error.code === "HOOK_ABI_MISMATCH" && /PREFILL_CHUNK_SIZE/u.test(error.message), ); await assert.rejects( - new DrowseWebLlmRuntime({ DROWSE_HOOK_ABI: "block-sites-v5", MLCEngine: FixtureEngine }) + new DrowseWebLlmRuntime({ DROWSE_HOOK_ABI: "block-sites-v6", MLCEngine: FixtureEngine }) .load(loadRequest({ variant: { ...variant, structuredHookProfile: "unknown-profile" } })), (error) => error.code === "STRUCTURED_HOOK_PROFILE_MISMATCH", ); - // A standard-v4 library attested against the lock's block spec: unit sites, so the hook + // A standard-v5 library attested against the lock's block spec: unit sites, so the hook // capabilities offer `units` and `slens` (a residual library offers neither). const blockSpec = { dFF: 4, nHeads: 2, nKvHeads: 1, headDim: 2, sandwich: false, normOffset: 0, activation: "silu", @@ -837,23 +837,23 @@ try { finalLogitSoftcap: null, ropeTheta: 10000, ropeLocalTheta: null, ropeGlobalScale: 1, ropeInGraph: true, slidingWindow: null, slidingPattern: null, }; - const unitsVariant = variantWith({ structuredHookProfile: "standard-v4" }); + const unitsVariant = variantWith({ structuredHookProfile: "standard-v5" }); class UnitSitesEngine extends FixtureEngine { async getDrowseStructuredHookProfile() { return { schemaVersion: 4, - id: "standard-v4", - hookAbi: "block-sites-v5", - format: "drowse-structured-v4", + id: "standard-v5", + hookAbi: "block-sites-v6", + format: "drowse-structured-v5", unitSites: 1, descriptor: Array.from(expectedHookProfileDescriptor( - STANDARD_STRUCTURED_HOOK_PROFILE_V4, + STANDARD_STRUCTURED_HOOK_PROFILE_V5, hookProfileDescriptorModel({ variant: unitsVariant, blockSpec, prefillChunkSize: 1024 }), )), }; } } - const unitSites = new DrowseWebLlmRuntime({ DROWSE_HOOK_ABI: "block-sites-v5", MLCEngine: UnitSitesEngine }); + const unitSites = new DrowseWebLlmRuntime({ DROWSE_HOOK_ABI: "block-sites-v6", MLCEngine: UnitSitesEngine }); await unitSites.load(loadRequest({ variant: unitsVariant, blockSpec })); assert.equal(unitSites.blockSitesCapabilities().blockSpec.dFF, 4); assert.equal(unitSites.hookCapabilities().units, true); @@ -863,7 +863,7 @@ try { class MissingProfileEngine extends FixtureEngine {} MissingProfileEngine.prototype.getDrowseStructuredHookProfile = undefined; const missingProfile = new DrowseWebLlmRuntime({ - DROWSE_HOOK_ABI: "block-sites-v5", + DROWSE_HOOK_ABI: "block-sites-v6", MLCEngine: MissingProfileEngine, }); await assert.rejects( @@ -956,7 +956,7 @@ try { capture = false; } const missingCapture = new DrowseWebLlmRuntime({ - DROWSE_HOOK_ABI: "block-sites-v5", + DROWSE_HOOK_ABI: "block-sites-v6", MLCEngine: MissingCaptureEngine, }); await assert.rejects( @@ -985,7 +985,7 @@ try { } } const loadingRuntime = new DrowseWebLlmRuntime({ - DROWSE_HOOK_ABI: "block-sites-v5", + DROWSE_HOOK_ABI: "block-sites-v6", MLCEngine: InterruptibleLoadEngine, }); const midLoadAbort = new AbortController(); @@ -1013,7 +1013,7 @@ try { } } const hookCheckRuntime = new DrowseWebLlmRuntime({ - DROWSE_HOOK_ABI: "block-sites-v5", + DROWSE_HOOK_ABI: "block-sites-v6", MLCEngine: InterruptibleHookCheckEngine, }); const hookCheckAbort = new AbortController(); @@ -1068,7 +1068,7 @@ try { readDrowseMeasurementBundle = undefined; } const missingBundleRuntime = new DrowseWebLlmRuntime({ - DROWSE_HOOK_ABI: "block-sites-v5", + DROWSE_HOOK_ABI: "block-sites-v6", MLCEngine: MissingBundleEngine, }); await assert.rejects( @@ -1076,7 +1076,7 @@ try { (error) => error.code === "BUNDLED_MEASUREMENT_READBACK_UNAVAILABLE", ); const missingStructuredPackRuntime = new DrowseWebLlmRuntime({ - DROWSE_HOOK_ABI: "block-sites-v5", + DROWSE_HOOK_ABI: "block-sites-v6", MLCEngine: MissingStructuredPackEngine, }); await assert.rejects( @@ -1087,7 +1087,7 @@ try { (error) => error.code === "EXACT_SAE_READOUT_UNAVAILABLE", ); const instrumentRuntime = new DrowseWebLlmRuntime({ - DROWSE_HOOK_ABI: "block-sites-v5", + DROWSE_HOOK_ABI: "block-sites-v6", MLCEngine: StructuredFixtureEngine, }); await instrumentRuntime.load(loadRequest({ @@ -1154,7 +1154,7 @@ try { const noFullSaeProgram = compileStructuredHookProgram( 2, [{}, {}], - STANDARD_STRUCTURED_HOOK_PROFILE_V4_RESIDUAL, + STANDARD_STRUCTURED_HOOK_PROFILE_V5_RESIDUAL, ); noFullSaeProgram.measurementSchema = { layerMap: [0, 1], @@ -1169,7 +1169,7 @@ try { const fullSaeProgram = compileStructuredHookProgram( 2, [{}, {}], - STANDARD_STRUCTURED_HOOK_PROFILE_V4_RESIDUAL, + STANDARD_STRUCTURED_HOOK_PROFILE_V5_RESIDUAL, ); fullSaeProgram.measurementSchema = { ...noFullSaeProgram.measurementSchema, @@ -1187,7 +1187,7 @@ try { assert.equal(instrumentEngine.saeDictionarySets, 1); await instrumentRuntime.installHookProgram(fullSaeProgram); assert.equal(instrumentEngine.saeDictionarySets, 2); - assert.equal(instrumentEngine.saeDictionary.hookAbi, "block-sites-v5"); + assert.equal(instrumentEngine.saeDictionary.hookAbi, "block-sites-v6"); await instrumentRuntime.installHookProgram(noFullSaeProgram); assert.equal(instrumentEngine.saeDictionaryClears, 0); assert.notEqual(instrumentEngine.saeDictionary, null); @@ -1299,7 +1299,7 @@ try { const aggregateProgram = compileStructuredHookProgram(2, [ { probes: [{ kind: "sae", direction: [1, 0], bias: 0 }] }, {}, - ], STANDARD_STRUCTURED_HOOK_PROFILE_V4_RESIDUAL); + ], STANDARD_STRUCTURED_HOOK_PROFILE_V5_RESIDUAL); aggregateProgram.measurementSchema = { layerMap: [0, 1], modelLayerCount: 2, @@ -1406,7 +1406,7 @@ try { } } const productionJlensRuntime = new DrowseWebLlmRuntime({ - DROWSE_HOOK_ABI: "block-sites-v5", + DROWSE_HOOK_ABI: "block-sites-v6", MLCEngine: ProductionJlensFixtureEngine, }); await productionJlensRuntime.load(loadRequest({ variant: productionVariant })); @@ -1429,7 +1429,7 @@ try { bias: 0, })), })), - STANDARD_STRUCTURED_HOOK_PROFILE_V4_RESIDUAL, + STANDARD_STRUCTURED_HOOK_PROFILE_V5_RESIDUAL, { bindingId: productionJlensBinding, layerIndices: Int32Array.from(productionLayerMap), @@ -1448,7 +1448,7 @@ try { await productionJlensRuntime.unload(); const warmSaeRuntime = new DrowseWebLlmRuntime({ - DROWSE_HOOK_ABI: "block-sites-v5", + DROWSE_HOOK_ABI: "block-sites-v6", MLCEngine: StructuredFixtureEngine, }); await warmSaeRuntime.load(loadRequest({ diff --git a/webui/scripts/web-llm-generation.test.mjs b/webui/scripts/web-llm-generation.test.mjs index f718665..80ff7ed 100644 --- a/webui/scripts/web-llm-generation.test.mjs +++ b/webui/scripts/web-llm-generation.test.mjs @@ -1,5 +1,4 @@ import assert from "node:assert/strict"; -import { readFile } from "node:fs/promises"; import { fileURLToPath } from "node:url"; import { createServer } from "vite"; import { normalizeDrowsePositionSelection } from "@drowse/web-llm"; @@ -73,7 +72,6 @@ try { aggregateMeasurements, roundReading, summaryMeasurements, - tokenRowMeasurements, } = await server.ssrLoadModule("/src/hosted/runtime/measurementRows.ts"); const { compileStructuredHookProgram, withStructuredUnitSection } = await server.ssrLoadModule( "/src/hosted/runtime/structuredHookProgram.ts", @@ -90,15 +88,15 @@ try { "/../drowse/webui/src/lib/runtime/samplingCapabilities.ts", ); const { - STANDARD_STRUCTURED_HOOK_PROFILE_V4, + STANDARD_STRUCTURED_HOOK_PROFILE_V5, } = await server.ssrLoadModule( "/src/hosted/runtime/structuredHookProfile.ts", ); // A pure push: one affine group, no probes, no controls (nothing to read per token). const hookProgram = compileStructuredHookProgram(1, [{ - affineGroups: [{ active: true, basis: [[1]], neutral: [0], target: [1], along: 0.5, kappa: [1] }], - }], STANDARD_STRUCTURED_HOOK_PROFILE_V4); + affineGroups: [{ active: true, basis: [[1]], read: [[1]], neutral: [0], target: [1], along: 0.5, kappa: [1] }], + }], STANDARD_STRUCTURED_HOOK_PROFILE_V5); assert.equal(tokenAlternativeLimit("http"), HTTP_RETURN_TOP_K_MAX); assert.equal(tokenAlternativeLimit("browser"), BROWSER_RETURN_TOP_K_MAX); assert.equal(tokenAlternativeLimit("fake"), 0); @@ -112,7 +110,7 @@ try { } assert.throws(() => validateWebLlmGenerationSettings({ top_k: Number.MAX_SAFE_INTEGER + 1 }, false), /top_k/); assert.throws(() => validateWebLlmGenerationSettings({ seed: -1 }, false), /seed/); - // Any finite penalty, as native's sampling params take (the goldens decode with 1e4). + // Any finite penalty, as native's sampling params take. assert.equal(validateWebLlmGenerationSettings({ presence_penalty: 1e4 }, false).presence_penalty, 1e4); assert.equal(validateWebLlmGenerationSettings({ frequency_penalty: -3 }, false).frequency_penalty, -3); assert.throws(() => validateWebLlmGenerationSettings({ presence_penalty: Infinity }, false), /presence_penalty/); @@ -974,13 +972,14 @@ try { affineGroups: [{ active: true, basis: [[1]], + read: [[1]], neutral: [0], target: [1], along: 0.5, kappa: [0], }], probes: [{ kind: "linear", direction: [1], bias: 0 }], - }], STANDARD_STRUCTURED_HOOK_PROFILE_V4); + }], STANDARD_STRUCTURED_HOOK_PROFILE_V5); gatedProgram.controls = { affine: [{ enabled: true, @@ -1048,7 +1047,7 @@ try { // turns off at the first decode step, a response-only one turns on there, and the caller's // `unitActive` is never written (a later run of the same program starts from it). const unitOnlyProgram = withStructuredUnitSection( - compileStructuredHookProgram(1, [{}], STANDARD_STRUCTURED_HOOK_PROFILE_V4), + compileStructuredHookProgram(1, [{}], STANDARD_STRUCTURED_HOOK_PROFILE_V5), { dFF: 4, nHeads: 1, headDim: 1 }, { ablations: [ @@ -1087,11 +1086,11 @@ try { // attached unit probe and the attached slens/ probes read out (token envelopes while their // family is live, the aggregate always); a unit tapped for a gate feeds gates only; a gate reads // an attached slens/ probe by name; slens/ reads run over the bridge's [L, d] capture. - const liveBase = compileStructuredHookProgram(2, [{}], STANDARD_STRUCTURED_HOOK_PROFILE_V4); + const liveBase = compileStructuredHookProgram(2, [{}], STANDARD_STRUCTURED_HOOK_PROFILE_V5); liveBase.measurementSchema = { layerMap: [0], modelLayerCount: 4, - probes: Array.from({ length: STANDARD_STRUCTURED_HOOK_PROFILE_V4.maxProbes }, () => null), + probes: Array.from({ length: STANDARD_STRUCTURED_HOOK_PROFILE_V5.maxProbes }, () => null), lensSource: null, saeSource: null, }; @@ -1578,11 +1577,11 @@ try { { kind: "sae", direction: [1], bias: 0 }, { kind: "jlens", direction: [0], bias: 0 }, ], - }], STANDARD_STRUCTURED_HOOK_PROFILE_V4, { + }], STANDARD_STRUCTURED_HOOK_PROFILE_V5, { bindingId: "a".repeat(64), layerIndices: Int32Array.of(0), tokenIds: Int32Array.from( - { length: STANDARD_STRUCTURED_HOOK_PROFILE_V4.maxProbes }, + { length: STANDARD_STRUCTURED_HOOK_PROFILE_V5.maxProbes }, (_, index) => index === 1 ? 17 : 0, ), }); @@ -1598,8 +1597,8 @@ try { saeSource: "fixture-sae", }; scopedProgram.controls = { - affine: new Array(STANDARD_STRUCTURED_HOOK_PROFILE_V4.maxAffineGroups).fill(null), - curve: new Array(STANDARD_STRUCTURED_HOOK_PROFILE_V4.maxCurves).fill(null), + affine: new Array(STANDARD_STRUCTURED_HOOK_PROFILE_V5.maxAffineGroups).fill(null), + curve: new Array(STANDARD_STRUCTURED_HOOK_PROFILE_V5.maxCurves).fill(null), }; const scopedReads = []; const scopedTokens = []; @@ -1681,12 +1680,13 @@ try { affineGroups: [{ active: true, basis: [[1]], + read: [[1]], neutral: [0], target: [1], along: 0.5, kappa: [0], }], - }], STANDARD_STRUCTURED_HOOK_PROFILE_V4); + }], STANDARD_STRUCTURED_HOOK_PROFILE_V5); staticProgram.controls = { affine: [{ enabled: true, @@ -1721,7 +1721,7 @@ try { assert.equal(staticControlUpdates, 0); const oriented = measurementEnvelope({ - format: "drowse-structured-v4", + format: "drowse-structured-v5", layerCount: 2, probeKind: Uint32Array.of(1, 3, 2, 1, 3, 2), measurementSchema: { @@ -1774,7 +1774,7 @@ try { ], }; const tokenView = (live) => tokenMeasurementEnvelope(oriented, { - format: "drowse-structured-v4", layerCount: 2, measurementSchema: { ...orientedSchema, ...live }, + format: "drowse-structured-v5", layerCount: 2, measurementSchema: { ...orientedSchema, ...live }, }); const familiesOff = tokenView({}); assert.equal(familiesOff.instruments.lens, undefined); @@ -1789,7 +1789,7 @@ try { assert.equal(tokenMeasurementEnvelope(undefined, null), undefined); const preciseProgram = { - format: "drowse-structured-v4", layerCount: 2, + format: "drowse-structured-v5", layerCount: 2, probeKind: Uint32Array.of(3, 2, 3, 2), measurementSchema: { layerMap: [0, 1], modelLayerCount: 2, @@ -1854,7 +1854,7 @@ try { const exactReadoutProgram = compileStructuredHookProgram( 1, [{}, {}, {}], - STANDARD_STRUCTURED_HOOK_PROFILE_V4, + STANDARD_STRUCTURED_HOOK_PROFILE_V5, { bindingId: "a".repeat(64), layerIndices: Int32Array.of(0, 2), @@ -2206,7 +2206,7 @@ try { coordinateBias: [0, 0], }], })), - STANDARD_STRUCTURED_HOOK_PROFILE_V4, + STANDARD_STRUCTURED_HOOK_PROFILE_V5, ); program.measurementSchema = { layerMap, @@ -2297,186 +2297,6 @@ try { { "4": [0.25, 0.75], "9": [0.4] }, ); - const sharedMeasurementFixture = JSON.parse(await readFile( - new URL("../../drowse/tests/fixtures/browser/measurement-envelope-v2.json", import.meta.url), - "utf8", - )); - const sharedGeometry = sharedMeasurementFixture.geometry; - const sharedProgram = compileStructuredHookProgram( - 1, - sharedGeometry.rows.map(() => ({ - geometryWhitener: { - rank: 1, - ridge: 1, - basis: [[1]], - correction: [0], - }, - geometryProbes: [{ - active: true, - mean: [0], - inverseMean: [0], - basis: [[1]], - gramInverse: [1], - cholesky: [1], - candidateWhite: [[0], [1]], - coordinateMap: [[1]], - coordinateBias: [0], - }], - })), - STANDARD_STRUCTURED_HOOK_PROFILE_V4, - ); - const sharedProbeCount = sharedProgram.profile.maxProbes; - for (let layer = 0; layer < sharedProgram.layerCount; layer += 1) { - sharedProgram.probeKind[layer * sharedProbeCount] = 1; - } - sharedProgram.probeKind[sharedProbeCount + 1] = 1; - sharedProgram.measurementSchema = { - layerMap: sharedMeasurementFixture.layerMap, - modelLayerCount: sharedMeasurementFixture.modelLayerCount, - probes: [ - { - name: sharedMeasurementFixture.lens.name, - family: "lens", - tokenId: sharedMeasurementFixture.lens.tokenId, - }, - { - name: sharedMeasurementFixture.sae.name, - family: "sae", - featureId: sharedMeasurementFixture.sae.featureId, - label: sharedMeasurementFixture.sae.label, - maxAct: sharedMeasurementFixture.sae.maxAct, - }, - ...new Array(sharedProbeCount - 2).fill(null), - ], - geometryProbes: [{ - name: sharedGeometry.name, - scoreKeys: [ - `${sharedGeometry.name}:fraction`, - `${sharedGeometry.name}:membership`, - ...sharedGeometry.labels.flatMap((label) => [ - `${sharedGeometry.name}@${label}`, - `${sharedGeometry.name}~${label}`, - ]), - ], - manifold: sharedGeometry.name, - labels: sharedGeometry.labels, - topN: sharedGeometry.labels.length, - intrinsicDim: 1, - rank: 1, - shareWeights: sharedGeometry.shareWeights, - assignBandwidth: sharedGeometry.assignBandwidth, - assignLogVolumeBias: sharedGeometry.assignLogVolumeBias, - labelScale: sharedGeometry.labelScale, - }, ...new Array(sharedProgram.profile.maxGeometryProbes - 1).fill(null)], - lensSource: sharedMeasurementFixture.lens.source, - saeSource: sharedMeasurementFixture.sae.source, - saeLayer: sharedMeasurementFixture.sae.layer, - saeFeatureCount: sharedMeasurementFixture.sae.featureCount, - lensReadout: true, - saeReadout: true, - saeFeatureMetadata: { - [sharedMeasurementFixture.sae.featureId]: { - label: sharedMeasurementFixture.sae.label, - maxAct: sharedMeasurementFixture.sae.maxAct, - }, - }, - }; - const sharedScalarValues = new Float32Array( - sharedProgram.layerCount * sharedProbeCount, - ); - sharedMeasurementFixture.lens.probabilities.forEach((probability, layer) => { - sharedScalarValues[layer * sharedProbeCount] = probability; - }); - sharedScalarValues[sharedProbeCount + 1] = sharedMeasurementFixture.sae.value; - const sharedGeometryValues = new Float32Array( - sharedProgram.layerCount * sharedProgram.profile.maxGeometryProbes * - sharedProgram.profile.geometryOutputStride, - ); - sharedGeometry.rows.forEach((row, layer) => { - const slot = layer * sharedProgram.profile.maxGeometryProbes; - const offset = slot * sharedProgram.profile.geometryOutputStride; - sharedGeometryValues.set( - [1, row.fraction, row.residual, row.membership, ...row.coords], - offset, - ); - sharedGeometryValues.set( - row.distances, - offset + 4 + sharedProgram.profile.maxIntrinsicDim, - ); - }); - const sharedEnvelope = measurementEnvelope( - sharedProgram, - sharedScalarValues, - sharedMeasurementFixture.steering, - sharedGeometryValues, - { - tokenIds: Int32Array.of(sharedMeasurementFixture.lens.tokenId), - tokens: [sharedMeasurementFixture.lens.token], - strength: Float32Array.of(0.5), - centerOfMass: Float32Array.of( - sharedMeasurementFixture.expected.instruments.lens.readout.aggregate[0].com, - ), - spread: Float32Array.of( - sharedMeasurementFixture.expected.instruments.lens.readout.aggregate[0].spread, - ), - fittedLayerCount: 2, - layerIndices: Int32Array.of(0, 1), - layerTokenIds: Int32Array.of( - sharedMeasurementFixture.lens.tokenId, - sharedMeasurementFixture.lens.tokenId, - ), - layerTokens: [ - sharedMeasurementFixture.lens.token, - sharedMeasurementFixture.lens.token, - ], - layerProbabilities: Float32Array.from(sharedMeasurementFixture.lens.probabilities), - }, - { - featureIds: Int32Array.of(sharedMeasurementFixture.sae.featureId), - activations: Float32Array.of(sharedMeasurementFixture.sae.activation), - runtimeLayerIndex: 1, - featureCount: sharedMeasurementFixture.sae.featureCount, - }, - 1, - true, - ); - // Envelope v2 as the browser reads it: the R lens alone (no S lens, no units - // yet), so the golden's S reading, S source and units channel drop out. - const browserView = (envelope) => { - const view = structuredClone(envelope); - const lens = view.instruments.lens; - if (lens) { - delete lens.readings?.[sharedMeasurementFixture.slens.name]; - delete lens.binding.sources.S; - } - delete view.instruments.units; - if (view.scores) { - delete view.scores[sharedMeasurementFixture.slens.name]; - delete view.scores[sharedMeasurementFixture.units.name]; - } - return view; - }; - assertParity( - sharedEnvelope, - browserView(sharedMeasurementFixture.expected), - sharedMeasurementFixture.tolerance, - ); - // The loom row and the node's aggregate, exactly (6 significant digits). - assert.deepEqual( - tokenRowMeasurements(sharedEnvelope), - browserView(sharedMeasurementFixture.expectedRow), - ); - const sharedAggregate = { ...structuredClone(sharedEnvelope), scope: "aggregate" }; - delete sharedAggregate.instruments.lens.readout; - delete sharedAggregate.instruments.sae.readout; - assert.deepEqual( - aggregateMeasurements(sharedAggregate), - browserView(sharedMeasurementFixture.expectedNodeAggregate), - ); - const sharedGateScores = measurementGateScores(sharedEnvelope); - assert.ok(`${sharedGeometry.name}:fraction` in sharedGateScores); - assert.equal(`${sharedGeometry.name}:fraction` in sharedEnvelope.scores, false); - const geometryGateProgram = trailProgram([ { rank: 1, candidates: [[0], [1]] }, ], [4]); @@ -2661,9 +2481,9 @@ try { geometryValues.set([1, 0.25, 0.2, 0.8, 0.2, 0.4, 0, 0, 1, 3], 0); geometryValues.set([1, 0.75, 0.4, 0.6, 0.8, 0.6, 0, 0, 3, 1], 8 * 41); const geometryEnvelope = measurementEnvelope({ - format: "drowse-structured-v4", + format: "drowse-structured-v5", layerCount: 2, - profile: STANDARD_STRUCTURED_HOOK_PROFILE_V4, + profile: STANDARD_STRUCTURED_HOOK_PROFILE_V5, probeKind: new Uint32Array(16), measurementSchema: { layerMap: [4, 9], @@ -2716,12 +2536,13 @@ try { affineGroups: [{ active: true, basis: [[1]], + read: [[1]], neutral: [0], target: [1], along: 0.5, kappa: [0], }], - }], STANDARD_STRUCTURED_HOOK_PROFILE_V4); + }], STANDARD_STRUCTURED_HOOK_PROFILE_V5); thinkingProgram.controls = { affine: [{ enabled: true, @@ -3385,38 +3206,6 @@ function fixtureTerminalReason(finishReason) { return null; } -function assertParity(actual, expected, tolerance, path = "measurement") { - if (typeof expected === "number") { - assert.equal(typeof actual, "number", `${path} must be numeric`); - assert.ok( - Math.abs(actual - expected) <= tolerance, - `${path}: expected ${expected}, received ${actual}`, - ); - return; - } - if (Array.isArray(expected)) { - assert.ok(Array.isArray(actual), `${path} must be an array`); - assert.equal(actual.length, expected.length, `${path} length`); - expected.forEach((value, index) => { - assertParity(actual[index], value, tolerance, `${path}[${index}]`); - }); - return; - } - if (expected !== null && typeof expected === "object") { - assert.equal( - actual !== null && typeof actual === "object" && !Array.isArray(actual), - true, - `${path} must be an object`, - ); - assert.deepEqual(Object.keys(actual).sort(), Object.keys(expected).sort(), `${path} keys`); - for (const [key, value] of Object.entries(expected)) { - assertParity(actual[key], value, tolerance, `${path}.${key}`); - } - return; - } - assert.equal(actual, expected, path); -} - function engineWithChat(values, failure = null, wait = null) { return { async getDrowseRuntimeCapabilities() { diff --git a/webui/scripts/worker-runtime.test.mjs b/webui/scripts/worker-runtime.test.mjs index 1fa537c..9d4cfd2 100644 --- a/webui/scripts/worker-runtime.test.mjs +++ b/webui/scripts/worker-runtime.test.mjs @@ -1046,6 +1046,34 @@ try { ); }); + test("worker hides a model install a newer catalog rebuilt until it is downloaded again", async () => { + // A hook ABI bump rebuilds every library and core: the old install's objects no longer match + // the variant, so the shell must download it again instead of adding new-runtime packs onto it. + const stale = [ + ...variant.files, + ...variant.packs.find((pack) => pack.kind === "core").files, + ].map((file, index) => (index === 0 ? "e".repeat(64) : file.sha256)); + const scope = harness({ + async download() { throw new Error("no download expected"); }, + async downloadPack() { throw new Error("no download expected"); }, + cancel() { return false; }, + }, { + selectedModelVariantId: variant.id, + installs: [{ id: variant.id, kind: "model", objectHashes: stale, installedAt: 1 }], + }); + const status = () => scope.messages.findLast( + (message) => message.kind === "event" && message.event === "status", + ).payload; + scope.send(request("stale-model-storage", "storage")); + assert.equal((await response(scope, "stale-model-storage")).ok, true); + assert.deepEqual(status().installedModelVariantIds, [variant.id], "without a catalog the install stands"); + await prepareCapabilities(scope); + scope.send(request("stale-model-catalog", "catalog", {})); + assert.equal((await response(scope, "stale-model-catalog")).ok, true); + assert.deepEqual(status().installedModelVariantIds, []); + assert.equal(status().selectedModelVariantId, null); + }); + test("worker cancellation during optional-pack preflight never starts a download", async () => { const optionalPack = { id: "smollm2-jlens-cancel", @@ -1453,7 +1481,10 @@ try { scope.installs.push({ id: variant.id, kind: "model", - objectHashes: variant.files.map((file) => file.sha256), + objectHashes: [ + ...variant.files, + ...variant.packs.find((pack) => pack.kind === "core").files, + ].map((file) => file.sha256), installedAt: 2, }); return result; @@ -1487,7 +1518,10 @@ try { scope.installs.push({ id: variant.id, kind: "model", - objectHashes: variant.files.map((file) => file.sha256), + objectHashes: [ + ...variant.files, + ...variant.packs.find((pack) => pack.kind === "core").files, + ].map((file) => file.sha256), installedAt: 2, }); return result; @@ -5246,7 +5280,7 @@ try { if (mode === "reset") return { status: "not_found" }; return { status: "incompatible", - reason: "runtime_identity", + reason: "context_tokens", preserved: true, }; }, @@ -5276,6 +5310,37 @@ try { assert.equal(closes, 2); }); + test("worker opens a model on a fresh session when its working session is from an older runtime", async () => { + // A later catalog rebuilt the variant's library: the old working session is reset (the saved-chat + // library keeps the conversation) rather than blocking the model. + const restoreModes = []; + const scope = harness({ + async download() { return result; }, + cancel() { return false; }, + }, { + modelBackend: { + async load() { return { prefillTokensPerSecond: 10, decodeTokensPerSecond: 5 }; }, + async request() { throw new Error("not reached"); }, + async generate() { throw new Error("not reached"); }, + async stop() {}, + async unload() {}, + }, + sessionCoordinatorFactory: () => ({ + async restore(_identity, mode) { + restoreModes.push(mode); + if (mode === "reset") return { status: "not_found" }; + return { status: "incompatible", reason: "runtime_identity", preserved: true }; + }, + async persist() {}, + async close() {}, + }), + }); + await prepareDownload(scope); + scope.send(request("load-older-runtime", "load", downloadPayload())); + assert.equal((await response(scope, "load-older-runtime")).ok, true); + assert.deepEqual(restoreModes, ["replace", "reset"]); + }); + test("worker cleanly reloads once after a ready-time non-OOM device loss", async () => { const recoveryCatalog = structuredClone(verifiedCatalog); const recoveryVariant = recoveryCatalog.document.models[0].variants[0]; diff --git a/webui/src/hosted/artifacts/authoring.ts b/webui/src/hosted/artifacts/authoring.ts index 223ad5c..0f4ba81 100644 --- a/webui/src/hosted/artifacts/authoring.ts +++ b/webui/src/hosted/artifacts/authoring.ts @@ -22,6 +22,8 @@ interface StoredClosure { manifold: Record; nodeCorpora: string[][]; fitted: ManifoldFitInfo[]; + /** The closure's fitted tensor filenames (each beside its sidecar). */ + tensorFiles: readonly string[]; } export async function authoredManifoldPack( @@ -42,7 +44,6 @@ export async function authoredManifoldPack( role: node.role ?? null, kind: null, })), - files: {}, source: "local", tags: [], template_ref: null, @@ -105,7 +106,6 @@ export async function discoverManifoldPack( role: node.role ?? null, kind: null, })), - files: {}, source: "local", tags: [], template_ref: null, @@ -149,7 +149,6 @@ export async function mergedDiscoverManifoldPack( role: node.role, kind: node.kind, })), - files: {}, source: "local", tags: [], template_ref: null, @@ -183,7 +182,6 @@ export async function templateManifoldPack( fit_mode: request.fit_mode, hyperparams: request.hyperparams ?? {}, nodes: labels.map((label) => ({ label, role: null, kind: null })), - files: {}, source: "local", tags: [], template_ref: `${templateNamespace}/${template.name}`, @@ -262,8 +260,7 @@ export function manifoldInfo( const intrinsicDim = hasAuthoredGeometry ? domainDimension(domain) : 0; const fittedModels: string[] = []; const tensorVariants: Record = {}; - for (const filename of Object.keys(value.files as Record)) { - if (!filename.endsWith(".safetensors")) continue; + for (const filename of closure.tensorFiles) { const parsed = parseDrowseTensorFilename(filename); if (!parsed) continue; if (!fittedModels.includes(parsed.safeModelId)) fittedModels.push(parsed.safeModelId); diff --git a/webui/src/hosted/artifacts/builder.ts b/webui/src/hosted/artifacts/builder.ts index 855b9af..5126a29 100644 --- a/webui/src/hosted/artifacts/builder.ts +++ b/webui/src/hosted/artifacts/builder.ts @@ -1,5 +1,3 @@ -import { sha256 } from "@noble/hashes/sha2.js"; -import { bytesToHex } from "@noble/hashes/utils.js"; import { zipSync } from "fflate"; import { validateDrowseArchive } from "./drowseArchive"; import { @@ -7,14 +5,14 @@ import { DROWSE_ARCHIVE_MAX_ENTRIES, DROWSE_ARCHIVE_MAX_FILE_BYTES, DrowseArchiveError, - type DrowseArchiveManifest, + type DrowseArchivePackManifest, } from "./types"; export interface BuildDrowseArchiveInput { primary: string; template: string | null; producerVersion: string; - source: DrowseArchiveManifest["source"]; + source: DrowseArchivePackManifest["source"]; files: Readonly>; } @@ -47,18 +45,14 @@ export async function buildDrowseArchive(input: BuildDrowseArchiveInput): Promis ); } } - const files = Object.fromEntries(paths.map((path) => { - const bytes = input.files[path]; - return [path, { size: bytes.length, sha256: bytesToHex(sha256(bytes)) }]; - })); - const manifest: DrowseArchiveManifest = { + // drowse 6.1's pack.json: the closure and its provenance, no per-entry digests. + const manifest: DrowseArchivePackManifest = { format_version: 1, kind: "drowse-manifold", producer: { name: "drowse", version: input.producerVersion }, primary: input.primary, template: input.template, source: { ...input.source }, - files, }; const manifestBytes = jsonBytes(manifest); if (manifestBytes.length > DROWSE_ARCHIVE_MANIFEST_MAX_BYTES) { diff --git a/webui/src/hosted/artifacts/drowseArchive.ts b/webui/src/hosted/artifacts/drowseArchive.ts index 1d71953..4841405 100644 --- a/webui/src/hosted/artifacts/drowseArchive.ts +++ b/webui/src/hosted/artifacts/drowseArchive.ts @@ -5,13 +5,12 @@ import { SafetensorsValidator, type SafetensorsDescription } from "./safetensors import { DROWSE_ARCHIVE_FORMAT_VERSION, DROWSE_ARCHIVE_MANIFEST_MAX_BYTES, - DROWSE_ARCHIVE_MAX_FILE_BYTES, DrowseArchiveError, type InspectedDrowseArchive, type DrowseArchiveArchiveEntry, type DrowseArchiveFileRecord, type DrowseArchiveFittedArtifact, - type DrowseArchiveManifest, + type DrowseArchivePackManifest, type DrowseArchiveSource, type VerifiedDrowseArchive, type VerifyDrowseArchiveOptions, @@ -26,7 +25,6 @@ const METADATA_MAX_BYTES = 4 * 1024 * 1024; const NODE_MAX_BYTES = 64 * 1024 * 1024; const MANIFOLD_FORMAT_VERSION = 10; const TEMPLATE_FORMAT_VERSION = 2; -const MERGE_BAKE_POLICY = "additive_union_v1"; type FitMode = "authored" | "baked" | "pca" | "spectral" | "auto"; @@ -39,23 +37,11 @@ const HYPERPARAMS_BY_MODE: Readonly>> = { - manifold_pca: new Set(["authored"]), - manifold_sae: new Set(["authored"]), - manifold_monopolar: new Set(["pca"]), - manifold_monopolar_sae: new Set(["pca"]), - manifold_discover_auto: new Set(["auto"]), - manifold_discover_pca: new Set(["pca"]), - manifold_discover_spectral: new Set(["spectral"]), - manifold_discover_sae: new Set(["pca", "spectral", "auto"]), - manifold_procrustes_transfer: new Set(["authored", "baked", "pca", "spectral", "auto"]), - merge: new Set(["baked"]), -}; - interface InternalInspection { archive: ZipArchive; - manifest: DrowseArchiveManifest; + manifest: DrowseArchivePackManifest; + /** The primary manifold's entries and the declared template's `template.json`. */ + closure: ReadonlyMap; publicPack: InspectedDrowseArchive; } @@ -70,7 +56,6 @@ interface ManifoldClosure { domain: DomainShape | null; hyperparams: Record; templateRef: string | null; - expectedPaths: Set; tensorPaths: string[]; } @@ -106,7 +91,8 @@ export async function inspectDrowseArchive(source: DrowseArchiveSource): Promise } const exactManifestBytes = await readZipEntry(archive, packEntry); if (exactManifestBytes === null) manifestError("pack.json could not be read"); - const manifest = validateManifest(parseExactJson(exactManifestBytes, "pack.json"), archive); + const manifest = validateManifest(parseExactJson(exactManifestBytes, "pack.json")); + const closure = closureEntries(archive, manifest); const primaryIdentity = identity(manifest.primary, "manifolds"); const templateIdentity = manifest.template === null ? null @@ -126,10 +112,34 @@ export async function inspectDrowseArchive(source: DrowseArchiveSource): Promise primaryIdentity: Object.freeze(primaryIdentity), templateIdentity: templateIdentity === null ? null : Object.freeze(templateIdentity), }); - internals.set(publicPack, { archive, manifest, publicPack }); + internals.set(publicPack, { archive, manifest, closure, publicPack }); return publicPack; } +/** + * The entries an install reads: everything under the primary manifold's directory and the + * declared template's `template.json`. Any other entry is ignored, as drowse's extraction does. + */ +function closureEntries( + archive: ZipArchive, + manifest: DrowseArchivePackManifest, +): ReadonlyMap { + const templateFile = manifest.template === null ? null : `${manifest.template}/template.json`; + const closure = new Map(); + for (const entry of archive.entries) { + if (entry.path.startsWith(`${manifest.primary}/`) || entry.path === templateFile) { + closure.set(entry.path, entry); + } + } + if (!closure.has(`${manifest.primary}/manifold.json`)) { + manifestMismatch("archive closure has no manifold.json"); + } + if (templateFile !== null && !closure.has(templateFile)) { + manifestMismatch("archive template closure has no template.json"); + } + return closure; +} + export async function verifyDrowseArchive( inspected: InspectedDrowseArchive, options: VerifyDrowseArchiveOptions = {}, @@ -141,12 +151,14 @@ export async function verifyDrowseArchive( "inspection handle was not created by inspectDrowseArchive in this Worker", ); } - const { archive, manifest } = internal; + const { archive, manifest, closure } = internal; const stage = options.stage; let began = false; let verifiedBytes = 0; + const totalBytes = [...closure.values()].reduce((total, entry) => total + entry.size, 0); + const files: Record = Object.create(null) as Record; const report = (phase: "verifying" | "validating" | "committing", path: string | null) => { - options.onProgress?.({ phase, path, verifiedBytes, totalBytes: totalPayloadBytes(manifest) }); + options.onProgress?.({ phase, path, verifiedBytes, totalBytes }); }; try { options.signal?.throwIfAborted(); @@ -166,7 +178,7 @@ export async function verifyDrowseArchive( const templateBytes = await verifyEntry(templatePath, capture(METADATA_MAX_BYTES)); template = validateTemplate(parseExactJson(templateBytes, templatePath), internal); } - validateExactClosure(manifold, template, internal); + validateTemplateBinding(manifold, template, internal); const nodeContents = new Map(); const nodeBytes: Uint8Array[] = []; @@ -198,7 +210,6 @@ export async function verifyDrowseArchive( parseExactJson(sidecarBytes, sidecarPath), sidecarPath, manifold, - expectedNodesSha256, tensorIdentity, ); const tensorEntry = requiredEntry(archive, tensorPath); @@ -207,6 +218,10 @@ export async function verifyDrowseArchive( push: (chunk) => validator.push(chunk), finish: () => validateTensorDescription(validator.finish(), tensorPath, sidecar), }); + // A fit of an older corpus travels with the closure but is a miss: it refits in place. + if (typeof sidecar.nodes_sha256 !== "string" || !expectedNodesSha256.has(sidecar.nodes_sha256)) { + continue; + } if (typeof sidecar.model_fingerprint === "string" && sidecar.model_fingerprint) { runtimeFingerprints.add(sidecar.model_fingerprint); } @@ -224,13 +239,14 @@ export async function verifyDrowseArchive( report("validating", null); options.signal?.throwIfAborted(); - const files = Object.freeze( - Object.fromEntries(Object.entries(manifest.files).map(([path, record]) => [path, Object.freeze({ ...record })])), - ); + const verifiedFiles = deepFreeze(Object.fromEntries( + Object.keys(files).sort().map((path) => [path, { ...files[path] }]), + ) as Record); const verified: VerifiedDrowseArchive = Object.freeze({ ...inspected, + manifest: deepFreeze({ ...structuredClone(manifest), files: structuredClone(verifiedFiles) }), verifiedAt: Date.now(), - files, + files: verifiedFiles, manifold: deepFreeze(manifold.value), template: template === null ? null : deepFreeze(template.value), fittedArtifacts: Object.freeze(fittedArtifacts), @@ -248,9 +264,9 @@ export async function verifyDrowseArchive( validator?: ByteValidator, ): Promise { options.signal?.throwIfAborted(); - const entry = requiredEntry(archive, path); - const expected = manifest.files[path]; - if (expected === undefined) manifestMismatch(`pack.json has no record for ${JSON.stringify(path)}`, path); + const entry = closure.get(path); + if (entry === undefined) closureError(`archive closure has no entry ${JSON.stringify(path)}`, path); + if (files[path] !== undefined) closureError(`archive entry ${JSON.stringify(path)} is read twice`, path); const hasher = sha256.create(); const captured: Uint8Array[] = []; report("verifying", path); @@ -266,17 +282,11 @@ export async function verifyDrowseArchive( }, }, options.signal); validator?.finish?.(); - const actual = bytesToHex(hasher.digest()); - if (actual !== expected.sha256) { - throw new DrowseArchiveError( - "CHECKSUM_MISMATCH", - `archive entry ${JSON.stringify(path)} failed SHA-256 verification`, - path, - ); - } + // The ZIP CRC covers transport; this digest is the browser's own record of what it staged. + files[path] = { size: entry.size, sha256: bytesToHex(hasher.digest()) }; if (stage !== undefined) await stage.finish(path); if (validator?.capture !== true) return new Uint8Array(); - const output = new Uint8Array(expected.size); + const output = new Uint8Array(entry.size); let offset = 0; for (const chunk of captured) { output.set(chunk, offset); @@ -313,7 +323,7 @@ export async function readVerifiedDrowseArchiveFile( } signal?.throwIfAborted(); const expected = verified.files[path]; - if (expected === undefined) manifestMismatch(`pack.json has no record for ${JSON.stringify(path)}`, path); + if (expected === undefined) manifestMismatch(`the verified closure has no entry ${JSON.stringify(path)}`, path); const bytes = await readZipEntry(internal.archive, requiredEntry(internal.archive, path), undefined, signal); if (bytes === null || bytes.length !== expected.size) { manifestMismatch(`archive entry ${JSON.stringify(path)} has an unexpected size`, path); @@ -322,7 +332,7 @@ export async function readVerifiedDrowseArchiveFile( if (actual !== expected.sha256) { throw new DrowseArchiveError( "CHECKSUM_MISMATCH", - `archive entry ${JSON.stringify(path)} does not match pack.json`, + `archive entry ${JSON.stringify(path)} changed since it was verified`, path, ); } @@ -361,115 +371,70 @@ function capture(maximum: number): ByteValidator { }; } -function validateManifest(value: unknown, archive: ZipArchive): DrowseArchiveManifest { - if (!isRecord(value) || !exactKeys(value, [ - "files", "format_version", "kind", "primary", "producer", "source", "template", - ])) { - manifestError("pack.json does not match the exact v1 schema"); - } +/** + * `pack.json`, read as drowse 6.1 reads it: `format_version` 1, a manifold `kind` and the + * `primary` path are required, `template` is optional, and `producer` / `source` are provenance + * (defaulted when absent). The per-entry `files` map older writers carried goes unread. + */ +function validateManifest(value: unknown): DrowseArchivePackManifest { + if (!isRecord(value)) manifestError("pack.json must be a JSON object"); if (value.format_version !== DROWSE_ARCHIVE_FORMAT_VERSION) { manifestError(`pack.json format_version must be ${DROWSE_ARCHIVE_FORMAT_VERSION}`); } - const producerName = ["drowse", "polythetic", "saklas"].find((name) => value.kind === `${name}-manifold`); - if (producerName === undefined) { + if (!["drowse", "polythetic", "saklas"].some((name) => value.kind === `${name}-manifold`)) { manifestError("pack.json kind must identify a Drowse manifold"); } - if ( - !isRecord(value.producer) - || !exactKeys(value.producer, ["name", "version"]) - || value.producer.name !== producerName - || !shortString(value.producer.version, 1_024) - ) { - manifestError("pack.json producer must name a drowse version"); - } + const producer = isRecord(value.producer) && shortString(value.producer.version, 1_024) + ? value.producer.version + : "unknown"; const primary = archivePath(value.primary, "manifolds"); - const template = value.template === null ? null : archivePath(value.template, "templates"); - const source = validateSource(value.source); - if (!isRecord(value.files) || Object.keys(value.files).length === 0) { - manifestError("pack.json files must be a non-empty object"); - } - const files: Record = Object.create(null) as Record; - for (const [path, raw] of Object.entries(value.files)) { - validateManifestPath(path); - if (!isRecord(raw) || !exactKeys(raw, ["sha256", "size"])) { - manifestError(`pack.json file record for ${JSON.stringify(path)} is invalid`); - } - if ( - typeof raw.size !== "number" - || !Number.isSafeInteger(raw.size) - || raw.size < 0 - || raw.size > DROWSE_ARCHIVE_MAX_FILE_BYTES - ) { - manifestError(`pack.json size for ${JSON.stringify(path)} is invalid`); - } - if (typeof raw.sha256 !== "string" || !SHA256.test(raw.sha256)) { - manifestError(`pack.json sha256 for ${JSON.stringify(path)} is invalid`); - } - const entry = archive.byPath.get(path); - if (entry === undefined || entry.size !== raw.size) { - manifestMismatch(`pack.json size for ${JSON.stringify(path)} does not match ZIP`, path); - } - const templateFile = template === null ? null : `${template}/template.json`; - if (!path.startsWith(`${primary}/`) && path !== templateFile) { - manifestMismatch(`archive entry ${JSON.stringify(path)} is outside its declared closure`, path); - } - files[path] = { size: raw.size, sha256: raw.sha256 }; - } - const archivePaths = new Set(archive.entries.map((entry) => entry.path)); - archivePaths.delete("pack.json"); - if (!sameSet(new Set(Object.keys(files)), archivePaths)) { - manifestMismatch("pack.json files must describe every non-manifest archive entry exactly"); - } - if (files[`${primary}/manifold.json`] === undefined) { - manifestMismatch("archive closure has no manifold.json"); - } - if (template !== null && files[`${template}/template.json`] === undefined) { - manifestMismatch("archive template closure has no template.json"); - } + const template = value.template == null ? null : archivePath(value.template, "templates"); + const source = value.source == null + ? { uri: "local", repository: null, revision: null } + : validateSource(value.source); return { format_version: 1, kind: "drowse-manifold", - producer: { name: "drowse", version: value.producer.version as string }, + producer: { name: "drowse", version: producer }, primary, template, source, - files, }; } -function validateManifold(value: unknown, internal: InternalInspection): ManifoldClosure { - const path = `${internal.manifest.primary}/manifold.json`; +/** + * `manifold.json` read as drowse 6.1's `parse_manifest` reads it: `format_version`, `name`, + * `fit_mode`, `nodes` (and `domain` for an authored or baked manifold) are required; the optional + * keys take their defaults; keys no reader uses (the retired `files` map, local fit state) are + * dropped. Returns the normalized manifest with the fields it read. + */ +export function readManifoldManifest(value: unknown, path = "manifold.json"): { + value: Record; + fitMode: FitMode; + labels: string[]; + roles: Array; + kinds: Array; + coords: number[][]; + domain: DomainShape | null; + hyperparams: Record; + templateRef: string | null; +} { if (!isRecord(value)) closureError("manifold.json must be a JSON object", path); + if (value.format_version !== MANIFOLD_FORMAT_VERSION) closureError("manifold.json must use format_version 10", path); + if (typeof value.name !== "string" || !NAME.test(value.name)) closureError("manifold.json name is invalid", path); const fitMode = value.fit_mode; if (fitMode !== "authored" && fitMode !== "baked" && fitMode !== "pca" && fitMode !== "spectral" && fitMode !== "auto") { closureError("manifold.json has an invalid fit_mode", path); } - const common = [ - "artifact_id", "description", "files", "fit_epochs", "fit_mode", "format_version", - "name", "nodes", "source", "tags", "template_ref", - ]; - const allowed = new Set([...common, fitMode === "authored" || fitMode === "baked" ? "domain" : "hyperparams"]); - if (Object.keys(value).some((key) => !allowed.has(key))) closureError("manifold.json has unknown fields", path); - for (const required of ["description", "files", "fit_mode", "format_version", "name", "nodes", "source", "tags", "template_ref"]) { - if (!(required in value)) closureError(`manifold.json is missing ${required}`, path); - } - if (value.format_version !== MANIFOLD_FORMAT_VERSION) closureError("manifold.json must use format_version 10", path); - const [, expectedName] = internal.publicPack.primaryIdentity; - if (typeof value.name !== "string" || value.name !== expectedName || !NAME.test(value.name)) { - closureError("manifold.json identity does not match pack.json primary", path); - } - if (typeof value.description !== "string" || !shortString(value.source, 4_096)) { + const description = value.description ?? ""; + const source = value.source || "local"; + const tags = value.tags ?? []; + if (typeof description !== "string" || !shortString(source, 4_096)) { closureError("manifold.json description/source is invalid", path); } - if (!Array.isArray(value.tags) || !value.tags.every((tag) => typeof tag === "string")) { + if (!Array.isArray(tags) || !tags.every((tag) => typeof tag === "string")) { closureError("manifold.json tags must be strings", path); } - if (value.artifact_id !== undefined && !shortString(value.artifact_id, 4_096)) { - closureError("manifold.json artifact_id is invalid", path); - } - if (value.fit_epochs !== undefined && !isRecord(value.fit_epochs)) { - closureError("manifold.json fit_epochs is invalid", path); - } if (!Array.isArray(value.nodes) || value.nodes.length === 0) closureError("manifold.json needs nodes", path); const labels: string[] = []; const roles: Array = []; @@ -478,71 +443,56 @@ function validateManifold(value: unknown, internal: InternalInspection): Manifol let domain: DomainShape | null = null; let hyperparams: Record = {}; if (fitMode === "authored" || fitMode === "baked") domain = validateDomain(value.domain, path); - else { - if (!isRecord(value.hyperparams)) closureError("discover manifold hyperparams must be an object", path); - hyperparams = validateHyperparams(fitMode, value.hyperparams, path); - } + else hyperparams = validateHyperparams(fitMode, value.hyperparams ?? {}, path); if (fitMode === "authored" && value.nodes.length < 2 * domain!.intrinsicDim + 1) { closureError(`authored manifold needs at least ${2 * domain!.intrinsicDim + 1} nodes`, path); } + const nodes: Array> = []; for (const rawNode of value.nodes) { - const expected = fitMode === "authored" ? ["coords", "kind", "label", "role"] : ["kind", "label", "role"]; - if (!isRecord(rawNode) || !exactKeys(rawNode, expected)) closureError("manifold.json node has an invalid schema", path); - if (typeof rawNode.label !== "string" || !LABEL.test(rawNode.label)) closureError("manifold.json node label is invalid", path); - if (rawNode.role !== null && (typeof rawNode.role !== "string" || !/^[a-z0-9._-]+$/.test(rawNode.role))) { + if (!isRecord(rawNode)) closureError("manifold.json node entries must be objects", path); + const label = rawNode.label; + const role = rawNode.role ?? null; + const kind = rawNode.kind ?? null; + if (typeof label !== "string" || !LABEL.test(label)) closureError("manifold.json node label is invalid", path); + if (role !== null && (typeof role !== "string" || !/^[a-z0-9._-]+$/.test(role))) { closureError("manifold.json node role is invalid", path); } - if (rawNode.kind !== null && rawNode.kind !== "abstract" && rawNode.kind !== "concrete" && rawNode.kind !== "custom") { + if (kind !== null && kind !== "abstract" && kind !== "concrete" && kind !== "custom") { closureError("manifold.json node kind is invalid", path); } + const node: Record = { label, role, kind }; if (fitMode === "authored") { if (!numericVector(rawNode.coords, domain!.intrinsicDim)) closureError("manifold.json node coordinates are invalid", path); coords.push([...(rawNode.coords as number[])]); + node.coords = [...(rawNode.coords as number[])]; } - labels.push(rawNode.label); - roles.push(rawNode.role as string | null); - kinds.push(rawNode.kind as string | null); + labels.push(label); + roles.push(role as string | null); + kinds.push(kind as string | null); + nodes.push(node); } if (new Set(labels).size !== labels.length) closureError("manifold.json has duplicate node labels", path); - const templateRef = value.template_ref; + const templateRef = value.template_ref ?? null; if (templateRef !== null && (typeof templateRef !== "string" || !/^([a-z][a-z0-9._-]{0,63})\/([a-z][a-z0-9._-]{0,63})$/.test(templateRef))) { closureError("manifold.json template_ref must be namespace-qualified", path); } if (templateRef !== null && (fitMode === "authored" || fitMode === "baked")) { closureError("only discover manifolds may reference a template", path); } - if (!isRecord(value.files)) closureError("manifold.json files must be an object", path); - const tensorPaths: string[] = []; - const expectedPairs = new Set(); - for (const [name, digest] of Object.entries(value.files)) { - if (!/^[A-Za-z0-9%_-]+\.(?:json|safetensors)$/.test(name) || name.includes("/")) { - closureError(`manifold.json files entry ${JSON.stringify(name)} is not canonical`, path); - } - if (typeof digest !== "string" || !SHA256.test(digest)) closureError("manifold.json contains an invalid file digest", path); - const fullPath = `${internal.manifest.primary}/${name}`; - if (internal.manifest.files[fullPath]?.sha256 !== digest) { - closureError(`manifold.json digest for ${JSON.stringify(name)} does not match pack.json`, path); - } - const tensorName = name.replace(/\.json$/, ".safetensors"); - if (!isCanonicalTensorFilename(tensorName)) closureError(`manifold.json file ${JSON.stringify(name)} is not a fitted tensor pair`, path); - expectedPairs.add(tensorName); - expectedPairs.add(tensorName.replace(/\.safetensors$/, ".json")); - if (name.endsWith(".safetensors")) tensorPaths.push(fullPath); - } - if (!sameSet(new Set(Object.keys(value.files)), expectedPairs)) { - closureError("manifold.json files must contain complete tensor/sidecar pairs", path); - } - if (fitMode === "baked" && tensorPaths.length === 0) closureError("baked manifold has no fitted tensor", path); - const expectedPaths = new Set([path]); - if (fitMode !== "baked") { - labels.forEach((label, index) => expectedPaths.add(`${internal.manifest.primary}/nodes/${nodeFilename(index, label)}`)); - } - for (const name of Object.keys(value.files)) expectedPaths.add(`${internal.manifest.primary}/${name}`); - validatePackSourceMatchesManifold(internal.manifest.source, value.source as string); + const normalized: Record = { + format_version: MANIFOLD_FORMAT_VERSION, + name: value.name, + description, + fit_mode: fitMode, + ...(fitMode === "authored" || fitMode === "baked" ? { domain: value.domain } : { hyperparams }), + nodes, + source, + tags: [...tags], + template_ref: templateRef, + }; return { - value, + value: normalized, fitMode, - name: value.name, labels, roles, kinds, @@ -550,16 +500,37 @@ function validateManifold(value: unknown, internal: InternalInspection): Manifol domain, hyperparams, templateRef: templateRef as string | null, - expectedPaths, - tensorPaths: tensorPaths.sort(), }; } +/** The canonical fitted-tensor filenames among a closure's top-level paths, with their sidecars. */ +export function drowseFittedTensorNames(paths: Iterable, primary: string): string[] { + const prefix = `${primary}/`; + const names = new Set(); + for (const path of paths) { + if (path.startsWith(prefix) && !path.slice(prefix.length).includes("/")) names.add(path.slice(prefix.length)); + } + return [...names] + .filter((name) => isCanonicalTensorFilename(name) && names.has(name.replace(/\.safetensors$/, ".json"))) + .sort(); +} + +function validateManifold(value: unknown, internal: InternalInspection): ManifoldClosure { + const path = `${internal.manifest.primary}/manifold.json`; + const read = readManifoldManifest(value, path); + const [, expectedName] = internal.publicPack.primaryIdentity; + if (read.value.name !== expectedName) closureError("manifold.json identity does not match pack.json primary", path); + // Fitted pairs are found the way drowse's folder scan finds them: a canonical tensor beside its + // sidecar. A half pair is ignored. + const tensorPaths = drowseFittedTensorNames(internal.closure.keys(), internal.manifest.primary) + .map((name) => `${internal.manifest.primary}/${name}`); + if (read.fitMode === "baked" && tensorPaths.length === 0) closureError("baked manifold has no fitted tensor", path); + return { ...read, name: expectedName, tensorPaths }; +} + function validateTemplate(value: unknown, internal: InternalInspection): TemplateClosure { const path = `${internal.manifest.template}/template.json`; - if (!isRecord(value) || !exactKeys(value, [ - "contexts", "description", "format_version", "name", "slot", "source", "tags", "values", - ])) closureError("template.json does not match the exact v2 schema", path); + if (!isRecord(value)) closureError("template.json must be a JSON object", path); const identity = internal.publicPack.templateIdentity!; if (value.format_version !== TEMPLATE_FORMAT_VERSION || value.name !== identity[1] || typeof value.name !== "string" || !NAME.test(value.name)) { closureError("template.json identity or format does not match its closure", path); @@ -578,11 +549,11 @@ function validateTemplate(value: unknown, internal: InternalInspection): Templat if (!Array.isArray(value.contexts) || value.contexts.length === 0) closureError("template.json contexts must be non-empty", path); const contexts: Array<{ assistant: string }> = []; for (const rawContext of value.contexts) { - if (!isRecord(rawContext) || !exactKeys(rawContext, ["assistant", "turns"]) || !Array.isArray(rawContext.turns) || rawContext.turns.length === 0) { + if (!isRecord(rawContext) || !Array.isArray(rawContext.turns) || rawContext.turns.length === 0) { closureError("template.json context has an invalid schema", path); } for (const turn of rawContext.turns) { - if (!isRecord(turn) || !exactKeys(turn, ["content", "role"]) || !["system", "user", "assistant"].includes(String(turn.role)) || typeof turn.content !== "string" || !turn.content.trim()) { + if (!isRecord(turn) || !["system", "user", "assistant"].includes(String(turn.role)) || typeof turn.content !== "string" || !turn.content.trim()) { closureError("template.json context turn is invalid", path); } if (turn.content.includes(value.slot as string)) closureError("template slot appears in a history turn", path); @@ -613,24 +584,19 @@ function validateTemplate(value: unknown, internal: InternalInspection): Templat }; } -function validateExactClosure( +function validateTemplateBinding( manifold: ManifoldClosure, template: TemplateClosure | null, internal: InternalInspection, ): void { - const expected = new Set(manifold.expectedPaths); if (internal.manifest.template === null) { if (manifold.templateRef !== null) closureError("templated manifold is missing its template closure"); - } else { - expected.add(`${internal.manifest.template}/template.json`); - const expectedRef = internal.publicPack.templateIdentity!.join("/"); - if (manifold.templateRef !== expectedRef) closureError("manifold template_ref does not match its closure"); - if (template === null || !sameStrings(manifold.labels, template.labels)) { - closureError("manifold node labels do not match its template closure"); - } + return; } - if (!sameSet(expected, new Set(Object.keys(internal.manifest.files)))) { - closureError("archive manifold/template closure is not exact"); + const expectedRef = internal.publicPack.templateIdentity!.join("/"); + if (manifold.templateRef !== expectedRef) closureError("manifold template_ref does not match its closure"); + if (template === null || !sameStrings(manifold.labels, template.labels)) { + closureError("manifold node labels do not match its template closure"); } } @@ -709,11 +675,18 @@ export function discoverManifoldNodesSha256(input: { export function templateClosureSha256( value: Readonly>, ): string { + // drowse's `TemplateFolder.sha256`: over the fields it reads, each context as {turns, assistant}. return hashParts([pythonCanonicalJsonBytes({ format_version: value.format_version, slot: value.slot, values: value.values, - contexts: value.contexts, + contexts: (value.contexts as Array>).map((context) => ({ + turns: (context.turns as Array>).map((turn) => ({ + role: turn.role, + content: turn.content, + })), + assistant: context.assistant, + })), })]); } @@ -723,51 +696,28 @@ function hashParts(parts: readonly Uint8Array[]): string { return bytesToHex(hasher.digest()); } +/** drowse's `sanitize_hyperparams(..., drop_unknown=True)`: a key the mode never reads is dropped. */ function validateHyperparams( - fitMode: FitMode, + fitMode: "pca" | "spectral" | "auto", value: unknown, path: string, ): Record { if (!isRecord(value)) closureError("manifold hyperparams must be an object", path); - if (fitMode === "authored" || fitMode === "baked") { - if (Object.keys(value).length !== 0) closureError(`${fitMode} fit cannot carry hyperparams`, path); - return value; - } const allowed = HYPERPARAMS_BY_MODE[fitMode]; const intKeys = new Set(["max_dim", "min_dim", "k_nn", "max_subspace_dim"]); const floatKeys = new Set(["var_threshold", "bandwidth", "persistence_frac"]); + const kept: Record = {}; for (const [key, item] of Object.entries(value)) { - if (!allowed.has(key)) closureError(`fit_mode ${fitMode} does not accept hyperparameter ${JSON.stringify(key)}`, path); + if (!allowed.has(key)) continue; const valid = intKeys.has(key) ? positiveInteger(item) : floatKeys.has(key) ? finite(item) : key === "smoothing" && (item === "auto" || finite(item)); if (!valid) closureError(`hyperparameter ${JSON.stringify(key)} has an invalid value`, path); + kept[key] = item; } - return value; -} - -function validateDiagnostics(value: unknown, path: string): void { - if (!isRecord(value)) closureError("fitted sidecar diagnostics must be an object", path); - const allowed = new Set([ - "per_component_variance", "cumulative_variance", "eigenvalues", "picked_k", - "gap_index", "k_nn", "component_count", "heuristic_k", "threshold", - "gap_magnitude", "bandwidth", "pinned", "min_dim", - ]); - const listKeys = new Set(["per_component_variance", "cumulative_variance", "eigenvalues"]); - const intKeys = new Set(["picked_k", "gap_index", "k_nn", "component_count", "heuristic_k", "min_dim"]); - for (const [key, item] of Object.entries(value)) { - if (!allowed.has(key)) closureError("fitted sidecar diagnostics has unknown fields", path); - const valid = listKeys.has(key) - ? Array.isArray(item) && item.length > 0 && item.every(finite) - : intKeys.has(key) - ? nonNegativeInteger(item) - : key === "pinned" - ? typeof item === "boolean" - : finite(item); - if (!valid) closureError(`fitted sidecar diagnostics field ${JSON.stringify(key)} is invalid`, path); - } + return kept; } function validateLayerMap( @@ -786,108 +736,103 @@ function validateLayerMap( } } -function validateTopologyCandidates(value: unknown, path: string): void { - if (!Array.isArray(value)) closureError("fitted sidecar topology_candidates must be an array", path); - for (const candidate of value) { - if (!isRecord(candidate) || !exactKeys(candidate, ["fit_mode", "intrinsic_dim", "name", "reason", "score", "viable"])) { - closureError("fitted sidecar has an invalid topology candidate schema", path); - } - if ( - !shortString(candidate.name, 4_096) - || (candidate.fit_mode !== "pca" && candidate.fit_mode !== "spectral") - || !positiveInteger(candidate.intrinsic_dim) - || (candidate.score !== null && !finite(candidate.score)) - || typeof candidate.viable !== "boolean" - || (candidate.reason !== null && typeof candidate.reason !== "string") - ) closureError("fitted sidecar has invalid topology candidate values", path); - } -} - -function validateComponents(value: unknown, path: string): void { - if (value === null) return; - if (!isRecord(value) || Object.keys(value).length === 0) { - closureError("fitted sidecar components must be null or a non-empty object", path); - } - for (const [coordinate, item] of Object.entries(value)) { - if ( - !coordinate - || !isRecord(item) - || !exactKeys(item, ["alpha", "selector", "tensor_sha256"]) - || !shortString(item.selector, 4_096) - || !finite(item.alpha) - || typeof item.tensor_sha256 !== "string" - || !SHA256.test(item.tensor_sha256) - ) closureError("fitted sidecar has invalid component provenance", path); - } -} - interface ValidatedSidecar extends Record { domain: Record; fitted_layers: number[]; mahalanobis_share_per_layer: Record; origin_per_layer: Record; feature_space: string; + nodes_sha256: string | null; model_fingerprint: string | null; context_binding_sha256: string | null; model_source_fingerprint: string | null; } +/** + * drowse's `ManifoldSidecar` field list with its "not set" defaults. A reader keeps these keys, + * defaults the missing ones and drops the rest (6.0's `share_metric` / `subspace_metric` among + * them), so adding or retiring a provenance field never strands a fit. + */ +const SIDECAR_DEFAULTS: Readonly> = { + drowse_version: "unknown", + feature_space: "raw", + fit_mode: "authored", + hyperparams: {}, + diagnostics: {}, + node_spread_per_layer: {}, + mahalanobis_share_per_layer: {}, + origin_per_layer: {}, + nodes_sha256: null, + sae_release: null, + sae_revision: null, + sae_fingerprint: null, + sae_ids_by_layer: {}, + sae_full_coverage: false, + model_fingerprint: null, + model_source_fingerprint: null, + capture_sha256: null, + capture_version: null, + context_binding_sha256: null, + capture_render_sha256: null, + baseline_prompts_sha256: null, + fitted_layers: [], + fit_policy_version: null, + rbf_smoothing_per_layer: {}, + sigma_field_per_layer: {}, + resolved_fit_mode: null, + topology_winner: null, + topology_candidates: [], + components: null, + bake_policy: null, + source_model_id: null, + source_model_fingerprint: null, + transfer_quality_estimate: null, +}; +const SIDECAR_REQUIRED = ["format_version", "name", "method", "domain", "node_labels"] as const; + +/** + * A fitted sidecar read as drowse 6.1's `validate_sidecar_payload` reads it: the identity the + * loader uses is required, the values the math or a cache comparison relies on are checked, and + * everything else is provenance that passes through as written. + */ function validateSidecar( input: unknown, path: string, manifold: ManifoldClosure, - expectedNodesSha256: ReadonlySet, tensorIdentity: ParsedDrowseTensorFilename, ): ValidatedSidecar { if (!isRecord(input)) closureError("fitted sidecar must be a JSON object", path); - const versionKey = Object.hasOwn(input, "drowse_version") - ? "drowse_version" - : Object.hasOwn(input, "polythetic_version") ? "polythetic_version" : "saklas_version"; - if (!exactKeys(input, [ - "bake_policy", "baseline_prompts_sha256", "capture_render_sha256", - "capture_sha256", "capture_version", "components", "context_binding_sha256", - "diagnostics", "domain", - "feature_space", "fit_mode", "fit_policy_version", "fitted_layers", - "format_version", "hyperparams", "mahalanobis_share_per_layer", "method", - "model_fingerprint", "model_source_fingerprint", "name", "node_count", - "node_kinds", "node_labels", "node_roles", "node_spread_per_layer", - "nodes_sha256", "origin_per_layer", "rbf_smoothing_per_layer", - "resolved_fit_mode", "sae_fingerprint", "sae_full_coverage", "sae_ids_by_layer", - "sae_release", "sae_revision", versionKey, "share_metric", - "sigma_field_per_layer", "source_model_fingerprint", "source_model_id", - "subspace_metric", "topology_candidates", "topology_winner", - "transfer_quality_estimate", - ])) closureError("fitted sidecar does not match the exact manifold v10 schema", path); - const value = versionKey !== "drowse_version" - ? { ...input, drowse_version: input[versionKey] } + const legacyVersion = input.polythetic_version ?? input.saklas_version; + const raw = input.drowse_version === undefined && legacyVersion !== undefined + ? { ...input, drowse_version: legacyVersion } : input; - if (versionKey !== "drowse_version") delete value[versionKey]; + const missing = SIDECAR_REQUIRED.filter((key) => !Object.hasOwn(raw, key)); + if (missing.length > 0) closureError(`fitted sidecar is missing ${missing.join(", ")}`, path); + const value: Record = {}; + for (const key of [...SIDECAR_REQUIRED, "node_roles", "node_kinds", ...Object.keys(SIDECAR_DEFAULTS)]) { + value[key] = Object.hasOwn(raw, key) ? raw[key] : structuredClone(SIDECAR_DEFAULTS[key]); + } + if (value.format_version !== MANIFOLD_FORMAT_VERSION) closureError("fitted sidecar must use format_version 10", path); + for (const field of ["name", "method", "drowse_version", "feature_space", "fit_mode"]) { + if (!shortString(value[field], 4_096)) closureError(`fitted sidecar ${field} must be a non-empty string`, path); + } + const labels = value.node_labels; + value.node_count = Array.isArray(labels) ? labels.length : 0; + value.node_roles ??= manifold.labels.map(() => null); + value.node_kinds ??= manifold.labels.map(() => null); if ( - value.format_version !== MANIFOLD_FORMAT_VERSION - || value.name !== manifold.name + value.name !== manifold.name || value.fit_mode !== manifold.fitMode - || value.node_count !== manifold.labels.length - || !sameStrings(value.node_labels, manifold.labels) - || !sameNullableStrings(value.node_roles, manifold.roles) - || !sameNullableStrings(value.node_kinds, manifold.kinds) + || !sameStrings(labels, manifold.labels) + || !Array.isArray(value.node_roles) || value.node_roles.length !== manifold.labels.length + || !Array.isArray(value.node_kinds) || value.node_kinds.length !== manifold.labels.length ) closureError("fitted sidecar identity does not match manifold.json", path); - const methodModes = typeof value.method === "string" ? METHOD_FIT_MODES[value.method] : undefined; - if (methodModes === undefined || !methodModes.has(manifold.fitMode)) { - closureError("fitted sidecar has an invalid method/fit_mode combination", path); + if (!isRecord(value.hyperparams) || !isRecord(value.diagnostics)) { + closureError("fitted sidecar hyperparams and diagnostics must be objects", path); } - if ( - !shortString(value.method, 1_024) - || !shortString(value.drowse_version, 1_024) - || !shortString(value.feature_space, 4_096) - || typeof value.sae_full_coverage !== "boolean" - ) closureError("fitted sidecar metadata types are invalid", path); - validateHyperparams(manifold.fitMode, value.hyperparams, path); - validateDiagnostics(value.diagnostics, path); for (const field of [ "nodes_sha256", "sae_release", "sae_revision", "sae_fingerprint", - "model_fingerprint", "model_source_fingerprint", "capture_sha256", "share_metric", - "subspace_metric", "resolved_fit_mode", "topology_winner", "bake_policy", - "source_model_id", "source_model_fingerprint", + "model_fingerprint", "model_source_fingerprint", "capture_sha256", "source_model_id", ]) { const item = value[field]; if (item !== null && (typeof item !== "string" || !item)) { @@ -902,17 +847,10 @@ function validateSidecar( closureError(`fitted sidecar ${field} must be a SHA-256 digest or null`, path); } } - if (value.capture_version !== null && !nonNegativeInteger(value.capture_version)) { - closureError("fitted sidecar capture_version is invalid", path); - } - if (value.fit_policy_version !== null && !nonNegativeInteger(value.fit_policy_version)) { - closureError("fitted sidecar fit_policy_version is invalid", path); - } - if (value.transfer_quality_estimate !== null && !finite(value.transfer_quality_estimate)) { - closureError("fitted sidecar transfer quality is invalid", path); - } - if (typeof value.nodes_sha256 !== "string" || !expectedNodesSha256.has(value.nodes_sha256)) { - closureError("fitted sidecar node hash does not match its closure", path); + for (const field of ["capture_version", "fit_policy_version"]) { + if (value[field] !== null && !nonNegativeInteger(value[field])) { + closureError(`fitted sidecar ${field} is invalid`, path); + } } if (!isRecord(value.domain)) closureError("fitted sidecar domain is invalid", path); validateDomain(value.domain, path); @@ -925,73 +863,14 @@ function validateSidecar( const layerKeys = new Set((value.fitted_layers as number[]).map(String)); validateLayerMap(value.node_spread_per_layer, layerKeys, false, (item) => finite(item) && item >= 0, "node_spread_per_layer", path); validateLayerMap(value.mahalanobis_share_per_layer, layerKeys, true, positiveFinite, "mahalanobis_share_per_layer", path); - if (!isRecord(value.mahalanobis_share_per_layer) || !sameSet(new Set(Object.keys(value.mahalanobis_share_per_layer)), layerKeys)) { + if (!sameSet(new Set(Object.keys(value.mahalanobis_share_per_layer as Record)), layerKeys)) { closureError("fitted sidecar Mahalanobis shares do not match its layer map", path); } validateLayerMap(value.origin_per_layer, layerKeys, true, (item) => Array.isArray(item) && item.length > 0 && item.every(finite), "origin_per_layer", path); validateLayerMap(value.sae_ids_by_layer, layerKeys, false, (item) => typeof item === "string" && item.length > 0, "sae_ids_by_layer", path); - validateLayerMap(value.rbf_smoothing_per_layer, layerKeys, true, (item) => ( - isRecord(item) - && exactKeys(item, ["edf", "gcv", "lambda"]) - && Object.values(item).every(finite) - ), "rbf_smoothing_per_layer", path); - validateLayerMap(value.sigma_field_per_layer, layerKeys, true, (item) => ( - isRecord(item) - && exactKeys(item, ["lambda", "sigma_max", "sigma_mean", "sigma_min"]) - && Object.values(item).every((entry) => finite(entry) && entry >= 0) - ), "sigma_field_per_layer", path); - validateTopologyCandidates(value.topology_candidates, path); - validateComponents(value.components, path); - - const isAuto = manifold.fitMode === "auto"; - const hasAutoProvenance = ( - value.resolved_fit_mode !== null - && value.topology_winner !== null - && Array.isArray(value.topology_candidates) - && value.topology_candidates.length > 0 - ); - if (isAuto !== hasAutoProvenance) { - closureError("fitted sidecar has inconsistent auto-topology provenance", path); - } - if (!isAuto && ( - value.resolved_fit_mode !== null - || value.topology_winner !== null - || (value.topology_candidates as unknown[]).length > 0 - )) closureError("fitted sidecar non-auto fit carries topology provenance", path); - - const isMerge = value.method === "merge"; - if (isMerge) { - if (manifold.fitMode !== "baked" || value.components === null || value.bake_policy !== MERGE_BAKE_POLICY) { - closureError("fitted sidecar has incomplete merge provenance", path); - } - } else if (value.components !== null || value.bake_policy !== null) { - closureError("fitted sidecar non-merge fit carries merge provenance", path); - } + // The tensor filename names the fit's variant; a reader selects by it, so it must agree. const isTransfer = value.method === "manifold_procrustes_transfer"; - const transferValues = [value.source_model_id, value.source_model_fingerprint, value.transfer_quality_estimate]; - if (isTransfer) { - if (value.source_model_id === null || value.source_model_fingerprint === null) { - closureError("fitted sidecar has incomplete transfer provenance", path); - } - } else if (transferValues.some((item) => item !== null)) { - closureError("fitted sidecar non-transfer fit carries transfer provenance", path); - } - - const saeValues = [value.sae_release, value.sae_revision, value.sae_fingerprint]; - const saeIds = value.sae_ids_by_layer as Record; - if (value.feature_space === "raw") { - if (saeValues.some((item) => item !== null) || Object.keys(saeIds).length > 0 || value.sae_full_coverage !== false) { - closureError("fitted sidecar raw fit carries SAE provenance", path); - } - } else if ( - !(value.feature_space as string).startsWith("sae-") - || value.sae_release === null - || Object.keys(saeIds).length === 0 - ) { - closureError("fitted sidecar has incomplete SAE provenance", path); - } - const matchesVariant = tensorIdentity.variant === "raw" ? value.feature_space === "raw" && !isTransfer : tensorIdentity.variant === "sae" @@ -1019,17 +898,13 @@ function validateTensorDescription( tensorError(path, "has invalid node_coords shape"); } shapes.delete("node_coords"); - const allowed = new Set([ - "mean", "basis", "node_coords", "affine_map", "node_params", "rbf_weights", - "poly_coeffs", "coord_offset", "coord_scale", "sigma_rbf_weights", "sigma_poly_coeffs", - ]); + // `layer_.`; any other key is ignored, as is a field no reader uses. const byLayer = new Map>(); for (const [key, shape] of shapes) { const match = /^layer_(0|[1-9]\d{0,9})\.([a-z_]+)$/.exec(key); - if (match === null || !allowed.has(match[2])) tensorError(path, `has invalid tensor key ${JSON.stringify(key)}`); + if (match === null) continue; const layer = Number(match[1]); const fields = byLayer.get(layer) ?? new Map(); - if (fields.has(match[2])) tensorError(path, `has duplicate tensor field ${JSON.stringify(key)}`); fields.set(match[2], shape); byLayer.set(layer, fields); } @@ -1046,6 +921,12 @@ function validateTensorDescription( tensorError(path, `layer ${layer} has invalid mean/basis shapes`); } const [rank, dimension] = basis; + // The dual read rows (drowse 6.1, fit policy 2). A pre-6.1 fit has none; it is stale, and + // whoever loads its geometry refits it instead. + const read = fields.get("read"); + if (read !== undefined && !sameShape(read, basis)) { + tensorError(path, `layer ${layer} read rows do not match its basis`); + } if (hiddenDim === null) hiddenDim = dimension; else if (hiddenDim !== dimension) tensorError(path, "has inconsistent hidden dimensions"); const isCurved = fields.has("node_params"); @@ -1055,7 +936,7 @@ function validateTensorDescription( curvedLayers.add(String(layer)); const required = ["mean", "basis", "node_params", "rbf_weights", "poly_coeffs", "coord_offset", "coord_scale"]; const sigma = ["sigma_rbf_weights", "sigma_poly_coeffs"]; - if (!required.every((field) => fields.has(field)) || [...fields.keys()].some((field) => !required.includes(field) && !sigma.includes(field))) { + if (!required.every((field) => fields.has(field))) { tensorError(path, `layer ${layer} has invalid curved tensor keys`); } if (fields.has(sigma[0]) !== fields.has(sigma[1])) tensorError(path, `layer ${layer} has incomplete sigma fields`); @@ -1072,8 +953,7 @@ function validateTensorDescription( || !sameShape(fields.get("sigma_poly_coeffs"), [domain.embedDim + 1, 1]) )) tensorError(path, `layer ${layer} has invalid sigma shapes`); } else { - const allowedAffine = new Set(["mean", "basis", "node_coords", "affine_map"]); - if ([...fields.keys()].some((field) => !allowedAffine.has(field)) || !sameShape(fields.get("node_coords"), [nodeCount, rank])) { + if (!sameShape(fields.get("node_coords"), [nodeCount, rank])) { tensorError(path, `layer ${layer} has invalid affine tensor keys or shapes`); } const affineMap = fields.get("affine_map"); @@ -1117,33 +997,27 @@ function validateDomain(value: unknown, path: string): DomainShape { closureError("manifold domain type is invalid", path); } -function validateSource(value: unknown): DrowseArchiveManifest["source"] { - if (!isRecord(value) || !exactKeys(value, ["repository", "revision", "uri"]) || !shortString(value.uri, 4_096)) { - manifestError("pack.json source does not match the exact v1 schema"); - } - for (const field of ["repository", "revision"] as const) { - if (value[field] !== null && !shortString(value[field], 1_024)) manifestError(`pack.json source.${field} is invalid`); +/** `pack.json`'s source block; a Hugging Face source must pin an immutable revision. */ +function validateSource(value: unknown): DrowseArchivePackManifest["source"] { + if (!isRecord(value) || !shortString(value.uri, 4_096)) manifestError("pack.json source needs a uri"); + const repository = value.repository ?? null; + const revision = value.revision ?? null; + for (const item of [repository, revision]) { + if (item !== null && !shortString(item, 1_024)) manifestError("pack.json source repository/revision is invalid"); } if ((value.uri as string).startsWith("hf://")) { if ( - typeof value.repository !== "string" - || typeof value.revision !== "string" - || !/^[0-9a-f]{40}$/.test(value.revision) - || value.uri !== `hf://${value.repository}@${value.revision}` + typeof repository !== "string" + || typeof revision !== "string" + || !/^[0-9a-f]{40}$/.test(revision) + || value.uri !== `hf://${repository}@${revision}` ) { manifestError("Hugging Face source provenance requires matching immutable fields"); } - } else if (value.repository !== null || value.revision !== null) { + } else if (repository !== null || revision !== null) { manifestError("non-Hugging Face source provenance cannot name a repository or revision"); } - return { uri: value.uri as string, repository: value.repository as string | null, revision: value.revision as string | null }; -} - -function validatePackSourceMatchesManifold(source: DrowseArchiveManifest["source"], manifoldSource: string): void { - if (source.uri !== manifoldSource) closureError("pack.json source provenance does not match manifold.json"); - if (manifoldSource.startsWith("hf://") && source.uri !== `hf://${source.repository}@${source.revision}`) { - closureError("pack.json Hugging Face provenance does not match manifold.json"); - } + return { uri: value.uri as string, repository: repository as string | null, revision: revision as string | null }; } function archivePath(value: unknown, root: "manifolds" | "templates"): string { @@ -1321,10 +1195,6 @@ function occurrences(value: string, needle: string): number { return count; } -function totalPayloadBytes(manifest: DrowseArchiveManifest): number { - return Object.values(manifest.files).reduce((total, file) => total + file.size, 0); -} - function exactKeys(record: Record, expected: readonly string[]): boolean { const keys = Object.keys(record).sort(); const sortedExpected = [...expected].sort(); @@ -1339,10 +1209,6 @@ function sameStrings(left: unknown, right: unknown): boolean { return Array.isArray(left) && Array.isArray(right) && left.length === right.length && left.every((value, index) => typeof value === "string" && value === right[index]); } -function sameNullableStrings(left: unknown, right: unknown): boolean { - return Array.isArray(left) && Array.isArray(right) && left.length === right.length && left.every((value, index) => (value === null || typeof value === "string") && value === right[index]); -} - function sameShape(left: readonly number[] | undefined, right: readonly number[]): boolean { return left !== undefined && left.length === right.length && left.every((value, index) => value === right[index]); } diff --git a/webui/src/hosted/artifacts/fittedAuthoring.ts b/webui/src/hosted/artifacts/fittedAuthoring.ts index c65b2a9..11ad40c 100644 --- a/webui/src/hosted/artifacts/fittedAuthoring.ts +++ b/webui/src/hosted/artifacts/fittedAuthoring.ts @@ -137,6 +137,10 @@ export async function browserFittedFlatDiscoverPack( shape: [fit.components, fit.columns], data: fp32(fit.basis, `layer ${layer} basis`), }; + tensors[`layer_${layer}.read`] = { + shape: [fit.components, fit.columns], + data: fp32(fit.read, `layer ${layer} read`), + }; tensors[`layer_${layer}.node_coords`] = { shape: [fit.nodeCount, fit.components], data: fp32(fit.nodeCoordinates, `layer ${layer} node coordinates`), @@ -202,8 +206,6 @@ export async function browserFittedFlatDiscoverPack( capture_render_sha256: identity.captureRenderSha256 ?? null, baseline_prompts_sha256: identity.baselinePromptsSha256 ?? null, fit_policy_version: identity.fitPolicyVersion, - share_metric: "mahalanobis", - subspace_metric: isMonopolar ? "euclidean" : "mahalanobis", rbf_smoothing_per_layer: {}, sigma_field_per_layer: {}, resolved_fit_mode: isAuto ? "pca" : null, @@ -236,10 +238,6 @@ export async function browserFittedFlatDiscoverPack( role: node.role, kind: node.kind, })), - files: { - [tensorName]: bytesToHex(sha256(tensorBytes)), - [sidecarName]: bytesToHex(sha256(sidecarBytes)), - }, source: closure.source.uri, tags: closure.tags, template_ref: closure.templateReference, @@ -312,6 +310,10 @@ export async function browserFittedCurvedDiscoverPack( shape: [fit.components, fit.columns], data: fp32(fit.basis, `${prefix} basis`), }; + tensors[`${prefix}.read`] = { + shape: [fit.components, fit.columns], + data: fp32(fit.read, `${prefix} read`), + }; tensors[`${prefix}.node_params`] = { shape: [fit.nodeCount, fit.surface.inputDimensions], data: fp32(fit.surface.nodes, `${prefix} node parameters`), @@ -404,8 +406,6 @@ export async function browserFittedCurvedDiscoverPack( capture_render_sha256: identity.captureRenderSha256 ?? null, baseline_prompts_sha256: identity.baselinePromptsSha256 ?? null, fit_policy_version: identity.fitPolicyVersion, - share_metric: "mahalanobis", - subspace_metric: "mahalanobis", rbf_smoothing_per_layer: smoothing, sigma_field_per_layer: sigma, resolved_fit_mode: isAuto ? "spectral" : null, @@ -434,10 +434,6 @@ export async function browserFittedCurvedDiscoverPack( fit_mode: manifold.fitMode, hyperparams: manifold.hyperparams, nodes: manifold.nodes.map((node) => ({ label: node.label, role: node.role, kind: node.kind })), - files: { - [tensorName]: bytesToHex(sha256(tensorBytes)), - [sidecarName]: bytesToHex(sha256(sidecarBytes)), - }, source: closure.source.uri, tags: closure.tags, template_ref: closure.templateReference, @@ -503,6 +499,10 @@ export async function browserFittedAuthoredPack( shape: [fit.components, fit.columns], data: fp32(fit.basis, `${prefix} basis`), }; + tensors[`${prefix}.read`] = { + shape: [fit.components, fit.columns], + data: fp32(fit.read, `${prefix} read`), + }; tensors[`${prefix}.node_params`] = { shape: [fit.nodeCount, fit.surface.inputDimensions], data: fp32(fit.surface.nodes, `${prefix} node parameters`), @@ -584,8 +584,6 @@ export async function browserFittedAuthoredPack( capture_render_sha256: identity.captureRenderSha256 ?? null, baseline_prompts_sha256: identity.baselinePromptsSha256 ?? null, fit_policy_version: identity.fitPolicyVersion, - share_metric: "mahalanobis", - subspace_metric: "mahalanobis", rbf_smoothing_per_layer: smoothing, sigma_field_per_layer: sigma, resolved_fit_mode: null, @@ -610,10 +608,6 @@ export async function browserFittedAuthoredPack( role: node.role, kind: node.kind, })), - files: { - [tensorName]: bytesToHex(sha256(tensorBytes)), - [sidecarName]: bytesToHex(sha256(sidecarBytes)), - }, source: closure.source.uri, tags: closure.tags, template_ref: null, @@ -816,6 +810,7 @@ function validateInput(input: BrowserFittedFlatDiscoverPackInput): void { if (!Number.isSafeInteger(layer) || layer < 0 || fit.nodeCount !== nodeCount || fit.components <= 0 || fit.components > dimensions || fit.columns < fit.components || fit.mean.length !== fit.columns || fit.basis.length !== fit.components * fit.columns || + fit.read.length !== fit.components * fit.columns || fit.nodeCoordinates.length !== nodeCount * fit.components || !Number.isFinite(fit.mahalanobisShare) || fit.mahalanobisShare <= 0 || (fit.affineMap === null @@ -904,6 +899,7 @@ function validateCurvedInput(input: BrowserFittedCurvedDiscoverPackInput): void !Number.isSafeInteger(layer) || layer < 0 || fit.nodeCount !== nodeCount || fit.components <= 0 || fit.columns < fit.components || fit.mean.length !== fit.columns || fit.basis.length !== fit.components * fit.columns || + fit.read.length !== fit.components * fit.columns || !Number.isFinite(fit.mahalanobisShare) || fit.mahalanobisShare <= 0 || surface.nodeCount !== nodeCount || surface.inputDimensions !== embeddedDimensions || surface.outputDimensions !== fit.components || @@ -915,7 +911,7 @@ function validateCurvedInput(input: BrowserFittedCurvedDiscoverPackInput): void (input.sae == null ? !sigmaValid : sigma !== null || sigmaSummary !== null) || fit.origin.length !== intrinsicDimensions || !Number.isFinite(fit.originDistance) || fit.originDistance < 0 || - ![fit.origin, fit.mean, fit.basis, surface.nodes, surface.weights, + ![fit.origin, fit.mean, fit.basis, fit.read, surface.nodes, surface.weights, surface.polynomial, surface.coordinateOffset, surface.coordinateScale].every(finiteValues) || !surface.coordinateScale.every((value) => value > 0) || ![surface.lambda, surface.effectiveDegreesOfFreedom, surface.gcv].every(Number.isFinite) @@ -955,6 +951,7 @@ function validateAuthoredInput(input: BrowserFittedAuthoredPackInput): void { !Number.isSafeInteger(layer) || layer < 0 || fit.nodeCount !== input.manifold.nodes.length || fit.components <= 0 || fit.columns < fit.components || fit.mean.length !== fit.columns || fit.basis.length !== fit.components * fit.columns || + fit.read.length !== fit.components * fit.columns || !Number.isFinite(fit.mahalanobisShare) || fit.mahalanobisShare <= 0 || surface.nodeCount !== fit.nodeCount || surface.inputDimensions !== embeddedDimensions || surface.outputDimensions !== fit.components || @@ -966,7 +963,7 @@ function validateAuthoredInput(input: BrowserFittedAuthoredPackInput): void { fit.origin.length !== intrinsicDimensions || !Number.isFinite(fit.originDistance) || fit.originDistance < 0 || (input.sae == null ? !sigmaValid : sigma !== null || sigmaSummary !== null) || - ![fit.origin, fit.mean, fit.basis, surface.nodes, surface.weights, + ![fit.origin, fit.mean, fit.basis, fit.read, surface.nodes, surface.weights, surface.polynomial, surface.coordinateOffset, surface.coordinateScale].every(finiteValues) || !surface.coordinateScale.every((value) => value > 0) ) { diff --git a/webui/src/hosted/artifacts/hfManifolds.ts b/webui/src/hosted/artifacts/hfManifolds.ts index 2bfbe6e..8319da1 100644 --- a/webui/src/hosted/artifacts/hfManifolds.ts +++ b/webui/src/hosted/artifacts/hfManifolds.ts @@ -222,7 +222,6 @@ export class BrowserHfManifoldClient implements BrowserHfManifoldClientPort { fitMode !== "spectral" && fitMode !== "auto" ) throw new Error(`${model.id}@${model.sha} has an invalid fit mode`); if (!Array.isArray(value.nodes)) throw new Error(`${model.id}@${model.sha} has invalid nodes`); - if (!isRecord(value.files)) throw new Error(`${model.id}@${model.sha} has an invalid file map`); const tags = Array.isArray(value.tags) ? value.tags.filter((tag): tag is string => typeof tag === "string") : []; @@ -234,13 +233,15 @@ export class BrowserHfManifoldClient implements BrowserHfManifoldClientPort { node_count: value.nodes.length, domain_label: remoteDomainLabel(value.domain, fitMode), fit_mode: fitMode, - // The summary is the archived manifest, so its file map names exactly - // the fitted tensors the archive carries; a pushed repo has no root - // .safetensors of its own. - tensor_models: Object.keys(value.files) - .filter((name) => !name.includes("/") && name.endsWith(".safetensors")) - .map((name) => name.slice(0, -".safetensors".length)) - .sort(), + // The summary is the archived manifest. A 6.0 push's file map names the fitted tensors + // the archive carries; drowse 6.1 dropped that map, so a 6.1 push lists none here (the + // tensors sit inside the archive, and a pushed repo has no root .safetensors of its own). + tensor_models: isRecord(value.files) + ? Object.keys(value.files) + .filter((name) => !name.includes("/") && name.endsWith(".safetensors")) + .map((name) => name.slice(0, -".safetensors".length)) + .sort() + : [], }; } diff --git a/webui/src/hosted/artifacts/repository.ts b/webui/src/hosted/artifacts/repository.ts index e6f0269..afaa92b 100644 --- a/webui/src/hosted/artifacts/repository.ts +++ b/webui/src/hosted/artifacts/repository.ts @@ -152,6 +152,15 @@ export class BrowserDrowseArchiveRepository { }); } + /** The closure paths an installed pack staged, sorted; `null` when it is not installed. */ + async paths(primary: string): Promise { + await this.initialize(); + return this.withLock(async () => { + const resolved = await this.resolveCommitted(primary); + return resolved ? Object.keys(resolved.transaction.manifest.files).sort() : null; + }); + } + async file(primary: string, path: string): Promise { await this.initialize(); return this.withLock(async () => { @@ -263,7 +272,8 @@ export class BrowserDrowseArchiveRepository { state: "staging", primary: pack.manifest.primary, template: pack.manifest.template, - manifest: structuredClone(pack.manifest) as DrowseArchiveManifest, + // The closure's files are known once it verifies; commit records them. + manifest: { ...structuredClone(pack.manifest), files: {} }, exactManifestBytes: pack.exactManifestBytes.slice(), refCount: 0, createdAt: Date.now(), @@ -281,7 +291,7 @@ export class BrowserDrowseArchiveRepository { async commitStageLocked(id: string, verified: VerifiedDrowseArchive, force: boolean): Promise { const database = this.requireDatabase(); - for (const [path, expected] of Object.entries(verified.manifest.files)) { + for (const [path, expected] of Object.entries(verified.files)) { const file = await this.stageFile(id, path, false); if (!file || file.size !== expected.size) { throw new Error(`Staged Drowse file ${path} is missing or has the wrong size`); @@ -305,6 +315,7 @@ export class BrowserDrowseArchiveRepository { transaction.abort(); throw new Error(`Drowse manifold pack ${verified.manifest.primary} is already installed`); } + staged.manifest = structuredClone(verified.manifest) as DrowseArchiveManifest; if (staged.template !== null) { const templateFile = `${staged.template}/template.json`; const digest = staged.manifest.files[templateFile]?.sha256; @@ -815,18 +826,23 @@ function validateTransactionRecord( value.state === "staging" && (value.refCount !== 0 || value.committedAt !== null) || value.state === "committed" && !validTimestamp(value.committedAt) ) return null; - const manifest = validateStoredManifest(value.manifest); + // A staging record learns its files when the closure verifies; a committed one carries them. + const manifest = validateStoredManifest(value.manifest, value.state === "staging"); if ( manifest === null || manifest.primary !== value.primary || manifest.template !== value.template || manifestPayloadBytes(manifest) + value.exactManifestBytes.byteLength > DROWSE_ARCHIVE_MAX_TOTAL_BYTES ) return null; - let exactManifest: DrowseArchiveManifest | null; + // The stored pack.json must name the same closure; its other fields are provenance. + let exactManifest: unknown; try { - exactManifest = validateStoredManifest(parseExactJson(value.exactManifestBytes, "stored pack.json")); + exactManifest = parseExactJson(value.exactManifestBytes, "stored pack.json"); } catch { return null; } - if (exactManifest === null || !sameJson(manifest, exactManifest)) return null; + if ( + !isRecord(exactManifest) || exactManifest.primary !== manifest.primary || + (exactManifest.template ?? null) !== manifest.template + ) return null; return { id: value.id, state: value.state, @@ -855,7 +871,7 @@ function validateInstallRecord(value: unknown, key: IDBValidKey): ArtifactInstal }; } -function validateStoredManifest(value: unknown): DrowseArchiveManifest | null { +function validateStoredManifest(value: unknown, staging: boolean): DrowseArchiveManifest | null { if (!isRecord(value) || !exactKeys(value, [ "files", "format_version", "kind", "primary", "producer", "source", "template", ])) return null; @@ -869,6 +885,21 @@ function validateStoredManifest(value: unknown): DrowseArchiveManifest | null { !validStoredSource(value.source) || !isRecord(value.files) ) return null; const entries = Object.entries(value.files); + if (staging && entries.length === 0) { + return { + format_version: DROWSE_ARCHIVE_FORMAT_VERSION, + kind: "drowse-manifold", + producer: { name: "drowse", version: value.producer.version as string }, + primary: value.primary as string, + template: value.template as string | null, + source: { + uri: value.source.uri as string, + repository: value.source.repository as string | null, + revision: value.source.revision as string | null, + }, + files: {}, + }; + } if (entries.length === 0 || entries.length + 1 > DROWSE_ARCHIVE_MAX_ENTRIES) return null; const files: DrowseArchiveManifest["files"] = Object.create(null) as DrowseArchiveManifest["files"]; const foldedPaths = new Set(); @@ -956,20 +987,6 @@ function exactKeys(value: Record, expected: readonly string[]): return keys.length === expected.length && expected.every((key, index) => keys[index] === key); } -function sameJson(left: unknown, right: unknown): boolean { - if (left === right) return true; - if (Array.isArray(left) && Array.isArray(right)) { - return left.length === right.length && left.every((value, index) => sameJson(value, right[index])); - } - if (isRecord(left) && isRecord(right)) { - const leftKeys = Object.keys(left).sort(); - const rightKeys = Object.keys(right).sort(); - return leftKeys.length === rightKeys.length && - leftKeys.every((key, index) => key === rightKeys[index] && sameJson(left[key], right[key])); - } - return false; -} - async function openDatabase(): Promise { const database = await new Promise((resolve, reject) => { const request = indexedDB.open(DATABASE_NAME, DATABASE_VERSION); diff --git a/webui/src/hosted/artifacts/service.ts b/webui/src/hosted/artifacts/service.ts index c3858ec..ab342ee 100644 --- a/webui/src/hosted/artifacts/service.ts +++ b/webui/src/hosted/artifacts/service.ts @@ -26,6 +26,7 @@ import { templatePayload, templateSummary, } from "./authoring"; +import { drowseFittedTensorNames, readManifoldManifest } from "./drowseArchive"; import { BrowserTemplateRepository, type BrowserTemplateRepositoryPort, @@ -80,6 +81,7 @@ export interface DrowseArchiveRepositoryPort { ): Promise; list(): Promise; remove(primary: string): Promise; + paths(primary: string): Promise; file(primary: string, path: string): Promise; export(primary: string): Promise; withExport( @@ -451,7 +453,12 @@ export class BrowserDrowseArchiveService { const [, namespace] = primary.split("/"); const metadataFile = await this.repository.file(primary, `${primary}/manifold.json`); if (!metadataFile) throw new Error(`Installed Drowse pack ${primary} is missing manifold.json`); - const manifold = await parseJsonFile(metadataFile, `${primary}/manifold.json`); + const manifold = readManifoldManifest( + await parseJsonFile(metadataFile, `${primary}/manifold.json`), + `${primary}/manifold.json`, + ).value; + // Fitted pairs are found as drowse's folder scan finds them: a tensor beside its sidecar. + const tensorFiles = drowseFittedTensorNames(await this.repository.paths(primary) ?? [], primary); const nodes = manifold.nodes as Array<{ label: string }>; const nodeCorpora = full && manifold.fit_mode !== "baked" ? await Promise.all(nodes.map(async (node, index) => { @@ -467,8 +474,7 @@ export class BrowserDrowseArchiveService { : nodes.map(() => []); const fitted: ManifoldFitInfo[] = []; if (full) { - for (const filename of Object.keys(manifold.files as Record)) { - if (!filename.endsWith(".safetensors")) continue; + for (const filename of tensorFiles) { const sidecarName = filename.replace(/\.safetensors$/, ".json"); const path = `${primary}/${sidecarName}`; const file = await this.repository.file(primary, path); @@ -492,7 +498,7 @@ export class BrowserDrowseArchiveService { } } return { - ...manifoldInfo(namespace, { manifold, nodeCorpora, fitted }, full), + ...manifoldInfo(namespace, { manifold, nodeCorpora, fitted, tensorFiles }, full), archive_source: structuredClone(pack.source), }; } diff --git a/webui/src/hosted/artifacts/types.ts b/webui/src/hosted/artifacts/types.ts index c772170..83b5d0c 100644 --- a/webui/src/hosted/artifacts/types.ts +++ b/webui/src/hosted/artifacts/types.ts @@ -42,7 +42,11 @@ export interface DrowseArchiveFileRecord { sha256: string; } -export interface DrowseArchiveManifest { +/** + * What a reader takes from `pack.json` (format v1): the closure's paths and provenance. The + * per-entry `files` map 6.0 wrote is provenance and goes unread, as drowse 6.1 reads it. + */ +export interface DrowseArchivePackManifest { format_version: 1; kind: "drowse-manifold"; producer: { name: "drowse"; version: string }; @@ -53,6 +57,10 @@ export interface DrowseArchiveManifest { repository: string | null; revision: string | null; }; +} + +/** A verified closure: its `pack.json` and the entries the browser read, sized and hashed. */ +export interface DrowseArchiveManifest extends DrowseArchivePackManifest { files: Record; } @@ -66,7 +74,7 @@ export interface DrowseArchiveArchiveEntry { } export interface InspectedDrowseArchive { - readonly manifest: Readonly; + readonly manifest: Readonly; readonly exactManifestBytes: Uint8Array; readonly entries: readonly DrowseArchiveArchiveEntry[]; readonly expandedBytes: number; @@ -108,10 +116,14 @@ export interface DrowseArchiveFittedArtifact { } export interface VerifiedDrowseArchive extends InspectedDrowseArchive { + readonly manifest: Readonly; readonly verifiedAt: number; + /** The closure entries read and staged, with the digests computed while reading them. */ readonly files: Readonly>; + /** `manifold.json` read tolerantly: the fields drowse reads, optional ones defaulted. */ readonly manifold: Readonly>; readonly template: Readonly> | null; + /** Complete fitted pairs current for this closure's corpus (a stale pair is a miss). */ readonly fittedArtifacts: readonly Readonly[]; readonly fittedRuntimeFingerprints: readonly string[]; } diff --git a/webui/src/hosted/fitting/coordinator.ts b/webui/src/hosted/fitting/coordinator.ts index 98b9663..c84662e 100644 --- a/webui/src/hosted/fitting/coordinator.ts +++ b/webui/src/hosted/fitting/coordinator.ts @@ -17,6 +17,12 @@ import type { import { applySerializedInverse } from "./mahalanobis"; import type { ManifoldDomain } from "../../../../drowse/webui/src/lib/types"; +/** + * drowse's `MANIFOLD_FIT_POLICY_VERSION`, stamped on every browser fit and required of a cached + * one. 2: typed frames (write rows Mahalanobis-orthonormal, their dual read rows beside them). + */ +export const FIT_POLICY_VERSION = 2; + export interface ActivationCaptureSink { appendRows(layer: number, startRow: number, values: Float32Array): Promise; } @@ -744,17 +750,17 @@ export async function fitBrowserAuthoredFields( if (options.fitSigma) { const offsets = groupOffsets.slice(); const mean = fit.mean.slice(); - const basis = fit.basis.slice(); + const read = fit.read.slice(); const covarianceResult = await worker.run({ operation: "reduced_covariances", source: { kind: "activation_spool", identity, layer }, offsets, mean, - basis, + read, components: fit.components, }, { signal, - transferOwnership: [offsets, mean, basis], + transferOwnership: [offsets, mean, read], onProgress: (workerStage) => options.onProgress?.( "covariance", layer, completed, layers.size, workerStage, ), @@ -866,17 +872,17 @@ export async function fitBrowserCurvedSigmaFields( if (options.fitSigma !== false) { const offsets = groupOffsets.slice(); const mean = fit.mean.slice(); - const basis = fit.basis.slice(); + const read = fit.read.slice(); const covarianceResult = await worker.run({ operation: "reduced_covariances", source: { kind: "activation_spool", identity, layer }, offsets, mean, - basis, + read, components: fit.components, }, { signal, - transferOwnership: [offsets, mean, basis], + transferOwnership: [offsets, mean, read], onProgress: (workerStage) => options.onProgress?.( "covariance", layer, @@ -1699,7 +1705,9 @@ export function finalizeBrowserAffineLayers( axes.every((axis, index) => axis === index) ? null : affineSelectionMap(intrinsicDimensions, axes); + // Kept rows of a typed frame stay Mahalanobis-orthonormal and dual: no re-orthonormalization. const basis = selectRows(fit.basis, fit.columns, axes); + const read = selectRows(fit.read, fit.columns, axes); const nodeCoordinates = selectColumns( fit.nodeCoordinates, fit.nodeCount, @@ -1712,11 +1720,12 @@ export function finalizeBrowserAffineLayers( fit.components, axes, ); + // mean = P_basis(neutral): the neutral mean read through the kept rows, written back. const mean = new Float64Array(fit.columns); for (let component = 0; component < components; component += 1) { let coordinate = 0; for (let column = 0; column < fit.columns; column += 1) { - coordinate += whitener.mean[column] * basis[component * fit.columns + column]; + coordinate += whitener.mean[column] * read[component * fit.columns + column]; } for (let column = 0; column < fit.columns; column += 1) { mean[column] += coordinate * basis[component * fit.columns + column]; @@ -1746,6 +1755,7 @@ export function finalizeBrowserAffineLayers( components, mean, basis, + read, nodeCoordinates, muCoordinates, mahalanobisShare, diff --git a/webui/src/hosted/fitting/fitting.worker.ts b/webui/src/hosted/fitting/fitting.worker.ts index 3c6c91a..f732b6b 100644 --- a/webui/src/hosted/fitting/fitting.worker.ts +++ b/webui/src/hosted/fitting/fitting.worker.ts @@ -75,6 +75,7 @@ interface AffineFisherWasm extends DisposableWasmValue { centroidMean(): Float64Array; mean(): Float64Array; basis(): Float64Array; + read(): Float64Array; nodeCoordinates(): Float64Array; muCoordinates(): Float64Array; whitenedGram(): Float64Array; @@ -519,6 +520,7 @@ async function execute( centroidMean: value.centroidMean(), mean: value.mean(), basis: value.basis(), + read: value.read(), nodeCoordinates: value.nodeCoordinates(), muCoordinates: value.muCoordinates(), whitenedGram: value.whitenedGram(), @@ -545,7 +547,7 @@ async function execute( const accumulator = new bindings.GroupedReducedCovarianceAccumulator( spec.width, job.mean, - job.basis, + job.read, job.components, job.offsets, ); diff --git a/webui/src/hosted/fitting/monopolar.ts b/webui/src/hosted/fitting/monopolar.ts index 8bb2502..0f12857 100644 --- a/webui/src/hosted/fitting/monopolar.ts +++ b/webui/src/hosted/fitting/monopolar.ts @@ -3,15 +3,16 @@ import type { BrowserFittingTopologyFoundation, FinalizedBrowserAffineLayer, } from "./coordinator"; -import { mahalanobisNorm } from "./mahalanobis"; +import { applySerializedInverse } from "./mahalanobis"; import type { SerializedMahalanobisWhitener, TopologyResult } from "./workerContracts"; /** * A one-node ``pca`` concept against the neutral baseline, as drowse's ``_fit_monopolar`` - * folds it (``fold_directions_to_subspace``): per layer the direction is the concept centroid - * minus the neutral mean, the basis its unit vector, the mean the neutral mean projected onto - * it, the pole one step of the direction's norm from the neutral origin, and the share its - * whitened norm. No discover coordinates, no DLS: every evaluated layer folds verbatim. + * folds it (``fold_directions_to_subspace``): per layer the direction d is the concept centroid + * minus the neutral mean; the frame writes along d/‖d‖_M and reads with Σ⁻¹d/‖d‖_M, the mean is + * the neutral mean projected into the span through the read row, the pole sits at ‖d‖_M (so at + * ν + d), and the share is ‖d‖_M. No discover coordinates, no DLS: every evaluated layer folds + * verbatim. * The in-app fit and the core-pack builder both take this path. */ export function monopolarFoundation( @@ -32,16 +33,22 @@ export function monopolarFoundation( pooled.values, (value, index) => value - whitener.mean[index], ); - const norm = Math.hypot(...direction); - if (norm <= 1e-12) continue; - const basis = Float64Array.from(direction, (value) => value / norm); + if (Math.hypot(...direction) <= 1e-12) continue; + // A typed, Mahalanobis-unit frame: write along d, read with its covector Σ⁻¹d. + const inverseDirection = applySerializedInverse(whitener, direction); + let squared = 0; + for (let index = 0; index < pooled.columns; index += 1) { + squared += direction[index] * inverseDirection[index]; + } + const share = Math.sqrt(Math.max(squared, 0)); + if (!Number.isFinite(share) || share <= 1e-12) continue; + const basis = Float64Array.from(direction, (value) => value / share); + const read = Float64Array.from(inverseDirection, (value) => value / share); let neutralCoordinate = 0; for (let index = 0; index < pooled.columns; index += 1) { - neutralCoordinate += whitener.mean[index] * basis[index]; + neutralCoordinate += whitener.mean[index] * read[index]; } const mean = Float64Array.from(basis, (value) => value * neutralCoordinate); - const share = mahalanobisNorm(whitener, direction); - if (!Number.isFinite(share) || share <= 0) continue; layers.set(layer, { operation: "affine_fisher", nodeCount: 1, @@ -50,7 +57,9 @@ export function monopolarFoundation( centroidMean: pooled.values.slice(), mean, basis, - nodeCoordinates: new Float64Array([norm]), + read, + // The pole sits at ν + d: ‖d‖_M along the Mahalanobis-unit write row. + nodeCoordinates: new Float64Array([share]), muCoordinates: new Float64Array([0]), whitenedGram: new Float64Array([share * share]), neutralCrossGram: new Float64Array([0]), diff --git a/webui/src/hosted/fitting/workerContracts.ts b/webui/src/hosted/fitting/workerContracts.ts index 02f7cd9..c1594d0 100644 --- a/webui/src/hosted/fitting/workerContracts.ts +++ b/webui/src/hosted/fitting/workerContracts.ts @@ -47,7 +47,8 @@ export type FittingWorkerJob = source: Extract; offsets: Uint32Array; mean: Float64Array; - basis: Float64Array; + /** The frame's read rows (covectors): reduced coordinates are `(h − mean) · readᵀ`. */ + read: Float64Array; components: number; } | { @@ -226,8 +227,13 @@ export interface AffineFisherResult { components: number; centroidMean: Float64Array; mean: Float64Array; + /** Write rows (vectors), Mahalanobis-orthonormal. */ basis: Float64Array; + /** Read rows (covectors), their Σ⁻¹ images: `read · basisᵀ = I`. */ + read: Float64Array; + /** `(centroid − neutral) · readᵀ`: whitened, neutral-anchored reduced coordinates. */ nodeCoordinates: Float64Array; + /** `(centroid − centroid mean) · readᵀ`. */ muCoordinates: Float64Array; whitenedGram: Float64Array; neutralCrossGram: Float64Array; @@ -422,6 +428,7 @@ function isFittingWorkerResult(value: unknown): value is FittingWorkerResult { isFloat64(value.centroidMean) && value.centroidMean.length === value.columns && isFloat64(value.mean) && value.mean.length === value.columns && isFloat64(value.basis) && value.basis.length === value.components * value.columns && + isFloat64(value.read) && value.read.length === value.components * value.columns && isFloat64(value.nodeCoordinates) && value.nodeCoordinates.length === value.nodeCount * value.components && isFloat64(value.muCoordinates) && diff --git a/webui/src/hosted/runtime/browserCorePack.ts b/webui/src/hosted/runtime/browserCorePack.ts index 7b06b03..d8d7a19 100644 --- a/webui/src/hosted/runtime/browserCorePack.ts +++ b/webui/src/hosted/runtime/browserCorePack.ts @@ -184,6 +184,19 @@ interface StructuredAffineTermGroup { terms: ResolvedCoreTerm[]; } +/** Every curved manifold's frame at one layer, stacked: write rows and their dual reads. */ +interface CurvedFrame { + basis: readonly ArrayLike[]; + read: readonly ArrayLike[]; +} + +// drowse's steering gains (steering/hooks.py), calibrated for typed frames: +// `eff_along_L = share_L · SUBSPACE_GAIN` for an affine group, `along · share_L · +// MANIFOLD_ALONG_GAIN` for a curved one, `clamp(onto · share_L · MANIFOLD_ONTO_GAIN, 0, 1)`. +const SUBSPACE_GAIN = 8; +const MANIFOLD_ALONG_GAIN = 2; +const MANIFOLD_ONTO_GAIN = 0.5; + export class BrowserFeasibilityCorePackCompiler { private neutralStatisticsRead: Promise | null; @@ -195,6 +208,11 @@ export class BrowserFeasibilityCorePackCompiler { private unitSource: BrowserUnitProgramSource | null = null; private unitSourceVersion = 0; private readonly attachedProbes = new Map(); + /** Each lens atom's read covectors (by their map's identity) raised to steering writes. */ + private readonly raisedReads = new WeakMap< + ReadonlyMap, + ReadonlyMap + >(); private constructor( private readonly modelId: string, @@ -967,6 +985,10 @@ export class BrowserFeasibilityCorePackCompiler { `${prefix}.basis`, [rank, this.hiddenSize], ).data); + updateFp32Hash(hash, manifold.tensors.tensor( + `${prefix}.read`, + [rank, this.hiddenSize], + ).data); if (manifold.tensors.keys.includes(`${prefix}.node_coords`)) { updateFp32Hash(hash, manifold.tensors.tensor( `${prefix}.node_coords`, @@ -1006,7 +1028,6 @@ export class BrowserFeasibilityCorePackCompiler { feature_space: manifold.featureSpace, variant: manifold.variant, variant_identity: manifold.variantIdentity, - share_metric: "mahalanobis", }, }, directions, @@ -1221,15 +1242,16 @@ export class BrowserFeasibilityCorePackCompiler { } const curveMaps = curved.map((term) => this.structuredCurves(term)); - const curvedBasisByLayer = new Map[]>(); + const curvedFrameByLayer = new Map(); // drowse's `OverlappingManifoldError` (steering/hooks.py), naming the layer's first curved - // manifold and the one that overlaps it. + // manifold and the one that overlaps it. The cosines are Mahalanobis: a frame's write rows + // against the earlier frames' reads. const curvedOwner = new Map(); curveMaps.forEach((curves, curveIndex) => { const name = (curved[curveIndex].base as ResolvedManifoldAtom).manifold.name; for (const [programIndex, curve] of curves) { - const previous = curvedBasisByLayer.get(programIndex) ?? []; - const overlap = maximumBasisOverlap(curve.basis, previous); + const previous = curvedFrameByLayer.get(programIndex) ?? { basis: [], read: [] }; + const overlap = maximumBasisOverlap(curve.basis, previous.read); if (overlap > 1e-3) { throw Object.assign(coreError( "CORE_PACK_CURVED_OVERLAP", @@ -1237,14 +1259,17 @@ export class BrowserFeasibilityCorePackCompiler { ), { status: 422, recoverable: false }); } if (!curvedOwner.has(programIndex)) curvedOwner.set(programIndex, name); - curvedBasisByLayer.set(programIndex, [...previous, ...curve.basis]); + curvedFrameByLayer.set(programIndex, { + basis: [...previous.basis, ...curve.basis], + read: [...previous.read, ...curve.read], + }); } }); affineTermGroups.forEach((termGroup, groupIndex) => { const groupByLayer = this.structuredAffineGroups(termGroup.terms); for (const [programIndex, group] of groupByLayer) { - const lowered = orthogonalizeAffineGroup(group, curvedBasisByLayer.get(programIndex)); + const lowered = orthogonalizeAffineGroup(group, curvedFrameByLayer.get(programIndex)); if (lowered === null) continue; (layers[programIndex].affineGroups as StructuredAffineGroup[])[groupIndex] = lowered; affineControls[programIndex * this.structuredHookProfile.maxAffineGroups + groupIndex] = @@ -1534,6 +1559,7 @@ export class BrowserFeasibilityCorePackCompiler { ): ReadonlyMap { const lowered = new Map { const whitener = this.whiteners.get(layer)!; const pushRows: Float64Array[] = []; - const pushFragments: Array<{ - coefficient: number; - direction: Float64Array; - metricNorm: number; - }> = []; - const ablationFragments: Array<{ - coefficient: number; - direction: Float64Array; - }> = []; - let ablationShare = 0; + const pushFragments: Array<{ coefficient: number; direction: Float64Array }> = []; + const ablationRows: Array<{ coefficient: number; direction: Float64Array }> = []; for (const term of terms) { if (Math.abs(term.coefficient) < 1e-9 || !termActsAt(term, layer)) continue; if (term.ablation) { const direction = this.atomNodeDirection(term.base, layer); - if (direction === null) continue; - const norm = euclideanNorm(direction); - if (norm < 1e-12) continue; - ablationFragments.push({ - coefficient: term.coefficient, - direction: Float64Array.from(direction, (value) => value / norm), - }); - ablationShare += Math.abs(term.coefficient) * - Math.max(mahalanobisNorm(whitener, direction), 1e-9); + if (direction === null || euclideanNorm(direction) < 1e-9) continue; + ablationRows.push({ coefficient: term.coefficient, direction }); continue; } const fragment = this.structuredPushFragment(term, layer, whitener); if (fragment === null) continue; + const rowsNorm = Math.sqrt(fragment.basis.reduce((sum, row) => sum + dot(row, row), 0)); + if (rowsNorm < 1e-9) continue; pushRows.push(...fragment.basis); - pushFragments.push({ - coefficient: term.coefficient, - direction: fragment.direction, - metricNorm: mahalanobisNorm(whitener, fragment.direction), - }); + pushFragments.push({ coefficient: term.coefficient, direction: fragment.direction }); } + const inverse = (row: ArrayLike) => applySerializedInverse(whitener, row); + const metricNorm = (row: ArrayLike, read: ArrayLike) => + Math.sqrt(Math.max(dot(row, read), 0)); + const pushReads = pushRows.map(inverse); + const ablationReads = ablationRows.map((row) => inverse(row.direction)); + const ablationNorms = ablationRows.map((row, index) => + metricNorm(row.direction, ablationReads[index]) + ); + const fragmentNorms = pushFragments.map((fragment) => + mahalanobisNorm(whitener, fragment.direction) + ); + // A strictly positive proxy is enough for a pure-ablation share: hook-time gain + // compensation cancels share from the ablation amount. + const ablationShare = ablationRows.reduce( + (sum, row, index) => sum + Math.abs(row.coefficient) * Math.max(ablationNorms[index], 1e-9), + 0, + ); + const worldTarget = new Float64Array(this.hiddenSize); const rawDelta = new Float64Array(this.hiddenSize); - for (const fragment of pushFragments) { + pushFragments.forEach((fragment, index) => { + const norm = fragmentNorms[index]; for (let column = 0; column < this.hiddenSize; column += 1) { rawDelta[column] += fragment.coefficient * fragment.direction[column]; - if (fragment.metricNorm > 1e-9) { - worldTarget[column] += fragment.coefficient / fragment.metricNorm * - fragment.direction[column]; + if (norm > 1e-9) { + worldTarget[column] += fragment.coefficient / norm * fragment.direction[column]; } } - } + }); const hasPush = euclideanNorm(worldTarget) >= 1e-9; - const pushBasis = hasPush ? orthonormalizeRows(pushRows) : []; + const push = hasPush ? orthoFrame(pushRows, pushReads) : { basis: [], read: [] }; + // Push wins shared directions: each Mahalanobis-unit ablation row loses its push-span + // component (coefficients `P_push · u`), and the remaining ablation operator is + // diagonalized in its own small span so coefficients survive exactly. const projectedAblations: Array<{ coefficient: number; direction: Float64Array; + read: Float64Array; }> = []; - for (const fragment of ablationFragments) { - const residual = Float64Array.from(fragment.direction); - for (const row of pushBasis) { - const projection = dot(residual, row); + ablationRows.forEach((row, index) => { + const norm = ablationNorms[index]; + if (norm < 1e-9) return; + const residual = Float64Array.from(row.direction, (value) => value / norm); + const residualRead = Float64Array.from(ablationReads[index], (value) => value / norm); + const coefficients = push.read.map((pushRead) => dot(pushRead, residual)); + coefficients.forEach((coefficient, axis) => { for (let column = 0; column < this.hiddenSize; column += 1) { - residual[column] -= projection * row[column]; + residual[column] -= coefficient * push.basis[axis][column]; + residualRead[column] -= coefficient * push.read[axis][column]; } - } - const norm = euclideanNorm(residual); - if (norm >= 1e-9) { + }); + const residualNorm = metricNorm(residual, residualRead); + if (residualNorm >= 1e-9) { projectedAblations.push({ - coefficient: fragment.coefficient, - direction: Float64Array.from(residual, (value) => value / norm), + coefficient: row.coefficient, + direction: residual.map((value) => value / residualNorm), + read: residualRead.map((value) => value / residualNorm), }); } - } + }); let ablationBasis: Float64Array[] = []; + let ablationRead: Float64Array[] = []; let ablationEigenvalues = new Float64Array(); if (projectedAblations.length > 0) { - const span = orthonormalizeRows( + const span = orthoFrame( projectedAblations.map((fragment) => fragment.direction), + projectedAblations.map((fragment) => fragment.read), ); - const reduced = new Float64Array(span.length * span.length); + const size = span.basis.length; + const reduced = new Float64Array(size * size); for (const fragment of projectedAblations) { - const coordinates = Float64Array.from(span, (row) => dot(row, fragment.direction)); - for (let left = 0; left < span.length; left += 1) { - for (let right = 0; right < span.length; right += 1) { - reduced[left * span.length + right] += fragment.coefficient * + const coordinates = Float64Array.from(span.read, (read) => dot(read, fragment.direction)); + for (let left = 0; left < size; left += 1) { + for (let right = 0; right < size; right += 1) { + reduced[left * size + right] += fragment.coefficient * coordinates[left] * coordinates[right]; } } } - const eigensystem = symmetricEigen(reduced, span.length); + const eigensystem = symmetricEigen(reduced, size); const kept = Array.from(eigensystem.values.keys()).filter( (index) => Math.abs(eigensystem.values[index]) >= 1e-9, ); @@ -1659,19 +1702,22 @@ export class BrowserFeasibilityCorePackCompiler { kept, (index) => eigensystem.values[index], ); - ablationBasis = kept.map((eigenIndex) => { + const rotate = (frame: readonly Float64Array[]) => kept.map((eigenIndex) => { const row = new Float64Array(this.hiddenSize); - for (let spanIndex = 0; spanIndex < span.length; spanIndex += 1) { - const coefficient = eigensystem.vectors[spanIndex * span.length + eigenIndex]; + for (let spanIndex = 0; spanIndex < size; spanIndex += 1) { + const coefficient = eigensystem.vectors[spanIndex * size + eigenIndex]; for (let column = 0; column < this.hiddenSize; column += 1) { - row[column] += coefficient * span[spanIndex][column]; + row[column] += coefficient * frame[spanIndex][column]; } } return row; }); + ablationBasis = rotate(span.basis); + ablationRead = rotate(span.read); } - const basis = [...pushBasis, ...ablationBasis]; + const basis = [...push.basis, ...ablationBasis]; + const read = [...push.read, ...ablationRead]; if (basis.length === 0) return; if (basis.length > this.structuredHookProfile.maxRank) { throw coreError( @@ -1683,14 +1729,16 @@ export class BrowserFeasibilityCorePackCompiler { let share: number; const target = new Float64Array(basis.length); if (hasPush) { + // The whitened raw displacement is the per-layer profile weight; the target is the + // whitened-unit push's coordinate in the merged frame (ablation axes ≈ 0). share = mahalanobisNorm(whitener, rawDelta); if (share < 1e-9) { share = pushFragments.reduce( - (sum, fragment) => sum + Math.abs(fragment.coefficient) * fragment.metricNorm, + (sum, fragment, index) => sum + Math.abs(fragment.coefficient) * fragmentNorms[index], 0, ); } - basis.forEach((row, axis) => { + read.forEach((row, axis) => { target[axis] = dot(row, worldTarget); }); } else { @@ -1699,12 +1747,13 @@ export class BrowserFeasibilityCorePackCompiler { if (share < 1e-9) return; lowered.set(programIndex, { basis, + read, target, requestedKappa: Float64Array.from( { length: basis.length }, - (_, axis) => axis < pushBasis.length + (_, axis) => axis < push.basis.length ? 0 - : ablationEigenvalues[axis - pushBasis.length], + : ablationEigenvalues[axis - push.basis.length], ), share, }); @@ -1713,10 +1762,11 @@ export class BrowserFeasibilityCorePackCompiler { const totalShare = [...lowered.values()].reduce((sum, layer) => sum + layer.share, 0); const groups = new Map(); for (const [programIndex, layer] of lowered) { - const along = layer.share / totalShare * lowered.size * 16; + const along = layer.share / totalShare * lowered.size * SUBSPACE_GAIN; groups.set(programIndex, { active: true, basis: layer.basis, + read: layer.read, neutral: this.whiteners.get(this.layerMap[programIndex])!.mean, target: layer.target, along, @@ -1840,6 +1890,7 @@ export class BrowserFeasibilityCorePackCompiler { active: true, domainKind: domain.kind, basis: rows(manifold.tensors.tensor(`${prefix}.basis`, [rank, this.hiddenSize]).data, rank, this.hiddenSize), + read: rows(manifold.tensors.tensor(`${prefix}.read`, [rank, this.hiddenSize]).data, rank, this.hiddenSize), neutral: manifold.tensors.tensor(`${prefix}.mean`, [this.hiddenSize]).data, nodeParameters: rows( manifold.tensors.tensor(`${prefix}.node_params`, [nodeCount, domain.embedDim]).data, @@ -1864,11 +1915,11 @@ export class BrowserFeasibilityCorePackCompiler { target, axes: domain.axes, along: periodic - ? Math.max(0, Math.min(1, Math.max(0, Math.min(1, term.coefficient)) * 4)) + ? Math.max(0, Math.min(1, Math.max(0, Math.min(1, term.coefficient)) * MANIFOLD_ALONG_GAIN)) : Math.max(0, Math.min(1, term.coefficient)) * - (manifold.mahalanobisShares.get(layer)! / shareMean) * 4, + (manifold.mahalanobisShares.get(layer)! / shareMean) * MANIFOLD_ALONG_GAIN, onto: Math.max(0, Math.min(1, onto * - (manifold.mahalanobisShares.get(layer)! / shareMean) * 0.5)), + (manifold.mahalanobisShares.get(layer)! / shareMean) * MANIFOLD_ONTO_GAIN)), sigmaRbfWeights: sigmaWeights, sigmaPolynomial, damping: 1e-3, @@ -2515,6 +2566,31 @@ export class BrowserFeasibilityCorePackCompiler { }; } + /** Native `LensInstrument._raised`: a `jlens/` atom (`W_U[v] J_l`) or an `slens/` atom + * (`K_l ẽ_v`) is a read, and its steering profile is the vector it raises to, `Σu`: the write + * that moves the reading furthest per unit of Mahalanobis displacement. Folded, it reads with + * `u` again, so `!` zeroes exactly the token's reading (LEACE). Probes keep the reads. */ + private raisedLensReads( + key: string, + reads: ReadonlyMap, + ): ReadonlyMap { + const memo = this.raisedReads.get(reads); + if (memo !== undefined) return memo; + const layers = [...reads.keys()].sort((left, right) => left - right); + if (layers.some((layer) => !this.whiteners.has(layer))) { + throw coreError( + "CORE_PACK_WHITENER_UNAVAILABLE", + `${key} needs a Mahalanobis whitener covering its layers [${layers.join(", ")}]: a lens atom is a read, and steering writes along its whitener-raised vector`, + ); + } + const raised = new Map(layers.map((layer) => [ + layer, + Float32Array.from(raiseLensRead(this.whiteners.get(layer)!, reads.get(layer)!)), + ])); + this.raisedReads.set(reads, raised); + return raised; + } + private resolveAtom(atom: SteeringAtom): ResolvedCoreAtom { if (atom.namespace === "sae") { if (atom.variant !== "raw") { @@ -2538,7 +2614,7 @@ export class BrowserFeasibilityCorePackCompiler { kind: "instrument", key: token.key, family: "jlens", - directions: token.directions, + directions: this.raisedLensReads(token.key, token.directions), saeFeature: null, }; } @@ -2573,7 +2649,7 @@ export class BrowserFeasibilityCorePackCompiler { kind: "instrument", key: `slens/${atom.concept}`, family: "slens", - directions: prepared.directions, + directions: this.raisedLensReads(`slens/${atom.concept}`, prepared.directions), saeFeature: null, }; } @@ -2733,9 +2809,14 @@ async function loadInstalledManifolds( ): Promise { const verified = await validateDrowseArchive(archive, { signal: request.signal }); const matches = matchingFittedArtifacts(verified, request, true); - return Promise.all(matches.map((candidate) => - loadVerifiedManifold(verified, request, profile, candidate) + // A fit from before typed frames is a miss (native's stale fit), not a broken install. + const loaded = await Promise.all(matches.map((candidate) => + loadVerifiedManifold(verified, request, profile, candidate).catch((error: unknown) => { + if ((error as { code?: unknown } | null)?.code === "CORE_PACK_FIT_STALE") return null; + throw error; + }) )); + return loaded.filter((manifold): manifold is CoreManifold => manifold !== null); } async function loadVerifiedManifold( @@ -2754,13 +2835,8 @@ async function loadVerifiedManifold( fitted.sidecarPath, request.signal, ); + // Shares are Mahalanobis (the sidecar no longer says so: drowse 6.1 dropped `share_metric`). const sidecar = JSON.parse(new TextDecoder().decode(sidecarBytes)) as Record; - if (sidecar.share_metric !== "mahalanobis") { - throw coreError( - "CORE_PACK_METRIC_INVALID", - "Core manifold lowering requires a Mahalanobis fitted sidecar", - ); - } const rawShares = sidecar.mahalanobis_share_per_layer; if (typeof rawShares !== "object" || rawShares === null || Array.isArray(rawShares)) { throw coreError("CORE_PACK_METRIC_INVALID", "Core manifold shares are invalid"); @@ -2806,6 +2882,17 @@ async function loadVerifiedManifold( }); const [namespace, name] = verified.primaryIdentity; const tensors = decodeFp32Safetensors(tensorBytes, fitted.tensorPath); + // Typed frames (fit policy 2): every layer's write rows carry their dual read rows. + for (const layer of fittedLayerNumbers(tensors)) { + const basisShape = tensors.description.shapes.get(`layer_${layer}.basis`); + const readShape = tensors.description.shapes.get(`layer_${layer}.read`); + if (readShape === undefined || readShape.join() !== basisShape?.join()) { + throw coreError( + "CORE_PACK_FIT_STALE", + `Manifold ${namespace}/${name} layer ${layer} has no read rows beside its basis (fitted before typed frames); refit it`, + ); + } + } const nodeStatements = await readCoreNodeStatements(verified, request.signal, labels.length); const nodeCoordinates = coreNodeCoordinates(tensors, labels.length); const fitMode = String(verified.manifold.fit_mode); @@ -3430,27 +3517,6 @@ function structuredTriggerKey(trigger: SteeringTrigger | null): string { : `${phaseKey}|${gate.probe}|${gate.operator}|${gate.threshold}`; } -function orthonormalizeRows( - directions: readonly ArrayLike[], -): Float64Array[] { - const basis: Float64Array[] = []; - for (const direction of directions) { - const inputNorm = euclideanNorm(direction); - if (inputNorm < 1e-12) continue; - const residual = Float64Array.from(direction, (value) => value / inputNorm); - for (const row of basis) { - const projection = dot(residual, row); - for (let column = 0; column < residual.length; column += 1) { - residual[column] -= projection * row[column]; - } - } - const norm = euclideanNorm(residual); - if (norm < 1e-6) continue; - basis.push(Float64Array.from(residual, (value) => value / norm)); - } - return basis; -} - function symmetricEigen( matrix: Float64Array, dimensions: number, @@ -3736,6 +3802,7 @@ function disabledStructuredGroup(hiddenSize: number): StructuredAffineGroup { return { active: false, basis: [basis], + read: [basis], neutral: new Float32Array(hiddenSize), target: [0], along: 0, @@ -3943,6 +4010,11 @@ function coreGeometryCurve( rank, hiddenSize, ), + read: rows( + manifold.tensors.tensor(`${prefix}.read`, [rank, hiddenSize]).data, + rank, + hiddenSize, + ), neutral: manifold.tensors.tensor(`${prefix}.mean`, [hiddenSize]).data, nodeParameters: rows( manifold.tensors.tensor( @@ -4401,58 +4473,142 @@ function maximumBasisOverlap( return maximum; } +/** Native `_orthogonalize_affine_against`: the curved manifolds win the shared directions. The + * affine write rows and push displacement lose their curved-span component + * Mahalanobis-orthogonally (the curved frame's reads give the coefficients), and each new axis + * inherits its squared Mahalanobis projection onto the old axes' collapse coefficients. Null + * when the affine span lies inside the curved span. */ function orthogonalizeAffineGroup( group: StructuredAffineGroup, - curvedBasis: readonly ArrayLike[] | undefined, + curvedFrame: CurvedFrame | undefined, ): StructuredAffineGroup | null { - if (curvedBasis === undefined || curvedBasis.length === 0) return group; + if (curvedFrame === undefined || curvedFrame.basis.length === 0) return group; const width = group.neutral.length; const oldBasis = group.basis.map((row) => Float64Array.from(row)); - const curves = curvedBasis.map((row) => Float64Array.from(row)); + const oldRead = group.read.map((row) => Float64Array.from(row)); if ( oldBasis.some((row) => row.length !== width) || - curves.some((row) => row.length !== width) || + oldRead.length !== oldBasis.length || oldRead.some((row) => row.length !== width) || + curvedFrame.read.length !== curvedFrame.basis.length || + [...curvedFrame.basis, ...curvedFrame.read].some((row) => row.length !== width) || group.target.length !== oldBasis.length || group.kappa.length !== oldBasis.length ) { throw coreError("CORE_PACK_CURVED_SHAPE_INVALID", "Affine and curved steering bases are incompatible"); } - const projectOut = (source: ArrayLike): Float64Array => { - const output = Float64Array.from(source); - for (const curve of curves) { - const projection = dot(output, curve); - for (let column = 0; column < width; column += 1) { - output[column] -= projection * curve[column]; - } - } + const curve = orthoFrame(curvedFrame.basis, curvedFrame.read); + // `x − (x · Cᵣᵀ) C_b`: the part of a vector (or, applied with the reads, a covector) that is + // Mahalanobis-orthogonal to the curved span. + const projectOut = (vector: Float64Array, pairs: readonly Float64Array[], coefficients: Float64Array) => { + const output = Float64Array.from(vector); + coefficients.forEach((coefficient, axis) => { + for (let column = 0; column < width; column += 1) output[column] -= coefficient * pairs[axis][column]; + }); return output; }; - const basis: Float64Array[] = []; - for (const row of oldBasis.map(projectOut)) { - for (const prior of basis) { - const projection = dot(row, prior); - for (let column = 0; column < width; column += 1) row[column] -= projection * prior[column]; - } - const norm = euclideanNorm(row); - if (norm <= 1e-6) continue; - basis.push(Float64Array.from(row, (value) => value / norm)); - } + const rowsOut: Float64Array[] = []; + const readsOut: Float64Array[] = []; + oldBasis.forEach((row, axis) => { + const coefficients = Float64Array.from(curve.read, (read) => dot(row, read)); + rowsOut.push(projectOut(row, curve.basis, coefficients)); + readsOut.push(projectOut(oldRead[axis], curve.read, coefficients)); + }); + const { basis, read } = orthoFrame(rowsOut, readsOut); if (basis.length === 0) return null; - const worldTarget = new Float64Array(width); + const delta = new Float64Array(width); oldBasis.forEach((row, axis) => { - for (let column = 0; column < width; column += 1) { - worldTarget[column] += row[column] * group.target[axis]; - } + for (let column = 0; column < width; column += 1) delta[column] += row[column] * group.target[axis]; }); - const perpendicularTarget = projectOut(worldTarget); - const target = Float64Array.from(basis, (row) => dot(row, perpendicularTarget)); - const kappa = Float64Array.from(basis, (row) => { + const perpendicular = projectOut(delta, curve.basis, Float64Array.from(curve.read, (row) => dot(delta, row))); + const target = Float64Array.from(read, (row) => dot(row, perpendicular)); + const kappa = Float64Array.from(read, (row) => { let inherited = 0; oldBasis.forEach((oldRow, axis) => { inherited += group.kappa[axis] * dot(row, oldRow) ** 2; }); return inherited; }); - return { ...group, basis, target, kappa }; + return { ...group, basis, read, target, kappa }; +} + +/** `Σ u` for the neutral whitener's regularized covariance `Σ = λI + V diag(e) Vᵀ` (native + * `LayerWhitener.apply`, the inverse of `applySerializedInverse`): the index-raising map from a + * read covector to the write vector that moves its reading furthest per unit of Mahalanobis + * displacement. */ +export function raiseLensRead( + whitener: SerializedMahalanobisWhitener, + read: ArrayLike, +): Float64Array { + if (read.length !== whitener.columns) { + throw new TypeError("Lens read does not match the whitener dimensions"); + } + const output = Float64Array.from(read, (value) => value * whitener.ridge); + for (let component = 0; component < whitener.rank; component += 1) { + const offset = component * whitener.columns; + let coordinate = 0; + for (let column = 0; column < whitener.columns; column += 1) { + coordinate += read[column] * whitener.basis[offset + column]; + } + const scaled = coordinate * whitener.eigenvalues[component]; + for (let column = 0; column < whitener.columns; column += 1) { + output[column] += scaled * whitener.basis[offset + column]; + } + } + return output; +} + +/** Native `_ortho_frame`: ordered Gram-Schmidt of write `rows` in the metric their `reads` + * define (`⟨u, v⟩_M = u · read(v)`, the Mahalanobis product when each read is `Σ⁻¹` of its + * row). Every operation on a row is applied to its read, so the frame stays dual. Each row is + * unit-normalized first, and one whose residual falls below `eps` is dropped (collinear rows + * add no axis). Order matters: earlier rows keep their span. `reads = rows` is the Euclidean + * case. The reads are corrected to exact duality (`read · basisᵀ = I`, `dual_read`). */ +function orthoFrame( + rows: readonly ArrayLike[], + reads: readonly ArrayLike[], + eps = 1e-6, +): { basis: Float64Array[]; read: Float64Array[] } { + const basis: Float64Array[] = []; + const read: Float64Array[] = []; + rows.forEach((source, index) => { + const norm = dot(source, reads[index]); + if (norm < 1e-24) return; + const row = Float64Array.from(source, (value) => value / Math.sqrt(norm)); + const rowRead = Float64Array.from(reads[index], (value) => value / Math.sqrt(norm)); + basis.forEach((accepted, axis) => { + const coefficient = dot(read[axis], row); + for (let column = 0; column < row.length; column += 1) { + row[column] -= coefficient * accepted[column]; + rowRead[column] -= coefficient * read[axis][column]; + } + }); + const residual = dot(row, rowRead); + if (residual < eps * eps) return; + basis.push(row.map((value) => value / Math.sqrt(residual))); + read.push(rowRead.map((value) => value / Math.sqrt(residual))); + }); + return { basis, read: dualRead(basis, read) }; +} + +/** Native `dual_read`: `(read · basisᵀ)⁻¹ read`, the reads corrected to be exactly dual to the + * write rows, in their own span. */ +function dualRead(basis: readonly Float64Array[], read: readonly Float64Array[]): Float64Array[] { + const rank = basis.length; + if (rank === 0) return []; + const gram = new Float64Array(rank * rank); + for (let left = 0; left < rank; left += 1) { + for (let right = 0; right < rank; right += 1) gram[left * rank + right] = dot(read[left], basis[right]); + } + const inverse = Array.from({ length: rank }, (_, column) => + solveDenseSystem(gram, Float64Array.from({ length: rank }, (_, row) => row === column ? 1 : 0), rank) + ); + return Array.from({ length: rank }, (_, row) => { + const output = new Float64Array(read[0].length); + for (let axis = 0; axis < rank; axis += 1) { + const coefficient = inverse[axis][row]; + for (let column = 0; column < output.length; column += 1) output[column] += coefficient * read[axis][column]; + } + return output; + }); } function dot(left: ArrayLike, right: ArrayLike): number { diff --git a/webui/src/hosted/runtime/browserInstrumentRuntime.ts b/webui/src/hosted/runtime/browserInstrumentRuntime.ts index 9e19de5..fe6c2aa 100644 --- a/webui/src/hosted/runtime/browserInstrumentRuntime.ts +++ b/webui/src/hosted/runtime/browserInstrumentRuntime.ts @@ -51,7 +51,7 @@ export class BrowserInstrumentRuntime { private readonly contextBindingSha256: string | null = null, enableLiveReadout = true, /** The S→R crossover band the units reads weigh by (native `session.lens.band`): the - * default, unless a harness sets another the way drowse's goldens set theirs. */ + * default, unless a harness sets another. */ private readonly lensBand: LensBand = DEFAULT_LENS_BAND, ) { const descriptor = this.compiler.instrumentDescriptor(); @@ -254,7 +254,7 @@ export class BrowserInstrumentRuntime { if (method === "saeFeaturesMetadata") return this.saeFeaturesMetadata(args); if (isUnitsServiceMethod(method)) { if (this.units === null) { - return Promise.reject(new UnsupportedBlockError("the loaded model library predates hook ABI block-sites-v5")); + return Promise.reject(new UnsupportedBlockError("the loaded model library predates hook ABI block-sites-v6")); } return this.units.request(method, args, { lensProbes: this.compiler.listProbes().filter((probe) => probe.family === "lens"), diff --git a/webui/src/hosted/runtime/browserLoom.ts b/webui/src/hosted/runtime/browserLoom.ts index 9c73008..5aba8a4 100644 --- a/webui/src/hosted/runtime/browserLoom.ts +++ b/webui/src/hosted/runtime/browserLoom.ts @@ -2598,8 +2598,8 @@ export interface ComposedCall { sampling: WSSampling | null; } -/** drowse/loom/recipe.py `compose_call`: the one composition rule (golden: - * `recipe-compose-v1.json`). Steering, thinking and the system prompt rank +/** drowse/loom/recipe.py `compose_call`: the one composition rule. + * Steering, thinking and the system prompt rank * cast < call < anchor < modifier: a set field wins (steering and thinking * when not null, the system prompt when not inherited). Sampling ranks cast < * anchor < call < modifier and merges field by field, so a tier cannot reset diff --git a/webui/src/hosted/runtime/browserManifoldFitting.ts b/webui/src/hosted/runtime/browserManifoldFitting.ts index c560503..586653a 100644 --- a/webui/src/hosted/runtime/browserManifoldFitting.ts +++ b/webui/src/hosted/runtime/browserManifoldFitting.ts @@ -30,6 +30,7 @@ import { } from "../artifacts/authoring"; import { BrowserFittingCoordinator, + FIT_POLICY_VERSION, embedBrowserAuthoredCoordinates, type BrowserAuthoredFittingPlan, type BrowserCentroidTransform, @@ -67,7 +68,6 @@ import type { import type { StructuredHookProgramBuffers } from "./structuredHookProgram"; const CAPTURE_VERSION = 3; -const FIT_POLICY_VERSION = 1; const LENGTH_DIRECTIVE = "Answer in one short paragraph."; const RESPONSE_MAX_TOKENS = 256; const DEFAULT_NAMESPACE = "local"; @@ -925,12 +925,12 @@ export class BrowserManifoldFitting { ); const sidecar = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(sidecarBytes)) as { fitted_layers?: unknown; - share_metric?: unknown; sae_fingerprint?: unknown; sae_revision?: unknown; capture_version?: unknown; fit_policy_version?: unknown; }; + // A fit of another capture or fit policy is stale: a miss that refits in place. if ( sidecar.capture_version !== CAPTURE_VERSION || sidecar.fit_policy_version !== FIT_POLICY_VERSION || @@ -940,8 +940,7 @@ export class BrowserManifoldFitting { ) return null; if ( !Array.isArray(sidecar.fitted_layers) || sidecar.fitted_layers.length === 0 || - sidecar.fitted_layers.some((layer) => !Number.isSafeInteger(layer) || layer < 0) || - sidecar.share_metric !== "mahalanobis" + sidecar.fitted_layers.some((layer) => !Number.isSafeInteger(layer) || layer < 0) ) { throw fittingError("BROWSER_FIT_RESULT_INVALID", "The fitted browser profile sidecar is invalid", 500); } @@ -951,7 +950,6 @@ export class BrowserManifoldFitting { metadata: { method: "manifold_pca", name: storedName, - share_metric: "mahalanobis", }, }; } diff --git a/webui/src/hosted/runtime/drowseWebLlmBackend.ts b/webui/src/hosted/runtime/drowseWebLlmBackend.ts index f709dfd..125c125 100644 --- a/webui/src/hosted/runtime/drowseWebLlmBackend.ts +++ b/webui/src/hosted/runtime/drowseWebLlmBackend.ts @@ -49,7 +49,7 @@ interface DrowseWebLlmRuntimePort extends BrowserGenerationPort, WebLlmCaptureRu tokenIds: readonly number[], ): Promise; generationPerformance(): BrowserGenerationPerformance; - /** Hook ABI v5's attested surface, or null when the loaded library predates it. */ + /** Hook ABI v6's attested surface, or null when the loaded library predates it. */ blockSitesCapabilities?(): BlockSitesCapabilities | null; /** The loaded model's block-sites bridge (replay, residents), or null without one. */ blockSitesDevice?(): WebLlmBlockSitesDevice | null; @@ -192,7 +192,7 @@ export class DrowseWebLlmBackend implements BrowserModelBackend { } private readonly v4BlockSites = rejectingBlockSitesBackend( - () => new UnsupportedBlockError("the loaded model library predates hook ABI block-sites-v5"), + () => new UnsupportedBlockError("the loaded model library predates hook ABI block-sites-v6"), ); private blockSitesSurface: { capabilities: BlockSitesCapabilities; diff --git a/webui/src/hosted/runtime/fakeModelBackend.ts b/webui/src/hosted/runtime/fakeModelBackend.ts index 29d9721..40d980f 100644 --- a/webui/src/hosted/runtime/fakeModelBackend.ts +++ b/webui/src/hosted/runtime/fakeModelBackend.ts @@ -18,7 +18,7 @@ import { type BrowserModelLoadResult, } from "./modelBackend"; -/** The fixture model has no block description: every hook ABI v5 member answers as drowse 6.0 +/** The fixture model has no block description: every hook ABI v6 member answers as drowse 6.0 * answers a unit or anatomy call on such a model (`UnsupportedBlockError`, 422). */ export const FIXTURE_UNIT_REFUSAL = "the deterministic fixture model has no transformer blocks to describe"; diff --git a/webui/src/hosted/runtime/fakeRuntime.ts b/webui/src/hosted/runtime/fakeRuntime.ts index b9d127c..775a098 100644 --- a/webui/src/hosted/runtime/fakeRuntime.ts +++ b/webui/src/hosted/runtime/fakeRuntime.ts @@ -32,7 +32,7 @@ import type { WSServerMessage, WSSubmitRequest, } from "../../../../drowse/webui/src/lib/types"; -import { STANDARD_STRUCTURED_HOOK_PROFILE_V4 } from "./structuredHookProfile"; +import { STANDARD_STRUCTURED_HOOK_PROFILE_V5 } from "./structuredHookProfile"; import { compileStructuredHookProgram, type StructuredHookProgramBuffers, @@ -1324,9 +1324,9 @@ function idlePreparation(): PreparationStatusJSON { }; } -/** An empty one-layer drowse-structured-v4 program: the fake engine never runs it. */ +/** An empty one-layer drowse-structured-v5 program: the fake engine never runs it. */ function fixtureHookProgram(): StructuredHookProgramBuffers { - return compileStructuredHookProgram(1, [{}], STANDARD_STRUCTURED_HOOK_PROFILE_V4); + return compileStructuredHookProgram(1, [{}], STANDARD_STRUCTURED_HOOK_PROFILE_V5); } function generationPromptTokens(plan: WebLlmGenerationPlan): number { diff --git a/webui/src/hosted/runtime/fixtureBrowser.worker.ts b/webui/src/hosted/runtime/fixtureBrowser.worker.ts index c20a2e1..5927224 100644 --- a/webui/src/hosted/runtime/fixtureBrowser.worker.ts +++ b/webui/src/hosted/runtime/fixtureBrowser.worker.ts @@ -8,6 +8,7 @@ import { DeterministicBrowserModelBackend } from "./fakeModelBackend"; import { BrowserContentStore } from "./contentStore"; import { VerifiedArtifactDownloader } from "./downloader"; import { HostedRuntimeWorker } from "./worker"; +import { sharedProfileId } from "./structuredHookProfile"; const revision = "b".repeat(40); const runtimeIdentitySha256 = "a".repeat(64); @@ -64,7 +65,7 @@ const document: CatalogDocument = { variants: [{ id: "qwen3-1.7b-fixture", tier: "fastest", - structuredHookProfile: "standard-v4", + structuredHookProfile: sharedProfileId("standard-v5"), thinkingProfile: null, contextProfiles: [{ contextTokens: 2048, diff --git a/webui/src/hosted/runtime/fixtureHostedRuntime.ts b/webui/src/hosted/runtime/fixtureHostedRuntime.ts index 7044938..ecb3108 100644 --- a/webui/src/hosted/runtime/fixtureHostedRuntime.ts +++ b/webui/src/hosted/runtime/fixtureHostedRuntime.ts @@ -15,6 +15,7 @@ import type { import { rankCatalogModels } from "../../lib/runtime/recommendation"; import { initialRuntimeSnapshot } from "../../lib/runtime/state"; import { DeterministicFakeRuntime } from "./fakeRuntime"; +import { sharedProfileId } from "./structuredHookProfile"; import type { HostedRuntimeBundle } from "./hostedController"; const SHA = "a".repeat(64); @@ -46,7 +47,7 @@ const fixtureModel: CatalogModel = { variants: [{ id: VARIANT_ID, tier: "fastest", - structuredHookProfile: "standard-v4", + structuredHookProfile: sharedProfileId("standard-v5"), thinkingProfile: null, contextProfiles: [{ contextTokens: 2048, diff --git a/webui/src/hosted/runtime/fixtures/units-tiny-models-v1.json b/webui/src/hosted/runtime/fixtures/units-tiny-models-v1.json new file mode 100644 index 0000000..611a09b --- /dev/null +++ b/webui/src/hosted/runtime/fixtures/units-tiny-models-v1.json @@ -0,0 +1,201 @@ +{ + "schemaVersion": 1, + "golden": "units-tiny-models", + "hookAbi": "block-sites-v5", + "arch": null, + "fixtureModels": {"name": "units-tiny-models-v1", "sha256": null}, + "tolerance": { + "python": {"atol": 1e-05, "rtol": 0.0001}, + "library": {"atol": 1e-05, "rtol": 0.0001, "probability_atol": 1e-05, "z_atol": 0.0001}, + "rounded": {"atol": 2e-06}, + "ids": "exact" + }, + "generator": { + "seed": 1592590341, + "hash": "lowbias32", + "golden_ratio": 2654435769, + "group": 32, + "group_scale_tag": 2147483648, + "q4": "q = (u mod 15) − 7, group's first element ±7 by u ≥ 2³¹; scale 2^−(E + H(seed ^ tag ^ g) mod 2)", + "norm": {"gemma3": "(u >> 9)·2⁻²⁴ − 0.25", "qwen3": "0.75 + (u >> 9)·2⁻²⁴"}, + "lens": "0.75·δ_ij + ((u >> 16) mod 256 − 128)·2⁻¹⁰, ordinal 1000 + 16·i + layer over the sorted (family, site) list" + }, + "arches": { + "gemma3": { + "family": "gemma3_text", + "config": { + "model_type": "gemma3_text", + "vocab_size": 260, + "hidden_size": 64, + "intermediate_size": 96, + "num_hidden_layers": 4, + "num_attention_heads": 4, + "num_key_value_heads": 2, + "head_dim": 16, + "rms_norm_eps": 1e-06, + "tie_word_embeddings": true, + "hidden_activation": "gelu_pytorch_tanh", + "query_pre_attn_scalar": 16, + "sliding_window": 4, + "layer_types": ["sliding_attention", "full_attention", "sliding_attention", "full_attention"], + "rope_parameters": { + "sliding_attention": {"rope_type": "default", "rope_theta": 10000.0}, + "full_attention": {"rope_type": "default", "rope_theta": 1000000.0} + }, + "attn_logit_softcapping": null, + "final_logit_softcapping": null, + "max_position_embeddings": 4096 + }, + "tensors": [ + {"name": "model.embed_tokens.weight", "shape": [260, 64], "kind": "q4", "exponent": 4, "sha256": "b0ef2d41da045c0ebca49a62813511335fbcb06a6c317446a54e3ae6cac55d3b"}, + {"name": "model.layers.0.self_attn.q_proj.weight", "shape": [64, 64], "kind": "q4", "exponent": 5, "sha256": "4aa17e89d31eb757765f2d4f8e095014d3f25cb98c61f31643ad52109361d95f"}, + {"name": "model.layers.0.self_attn.k_proj.weight", "shape": [32, 64], "kind": "q4", "exponent": 5, "sha256": "684fcb8eee8cb248d44b3df2f1b59b6fdfbea5d782487eb988b613f38f93f3ca"}, + {"name": "model.layers.0.self_attn.v_proj.weight", "shape": [32, 64], "kind": "q4", "exponent": 5, "sha256": "c3ce53271bf0d8a578a0b867594034ba24be3f75bbdc2b4ef4ee537f0dbafcc7"}, + {"name": "model.layers.0.self_attn.o_proj.weight", "shape": [64, 64], "kind": "q4", "exponent": 5, "sha256": "9345998a464809f54c62435176c7d835f5aee22e8acb85ff76ee4d00a1de3043"}, + {"name": "model.layers.0.self_attn.q_norm.weight", "shape": [16], "kind": "norm", "exponent": null, "sha256": "33f05a4ed379171ee1b78adf82ec26039b2fc83a133832cdf19cb1b4157a48d7"}, + {"name": "model.layers.0.self_attn.k_norm.weight", "shape": [16], "kind": "norm", "exponent": null, "sha256": "d562c1e743e9aac2ed99c1a92b6ec1e1058a45e168f50246d93d32e570b56506"}, + {"name": "model.layers.0.mlp.gate_proj.weight", "shape": [96, 64], "kind": "q4", "exponent": 5, "sha256": "fd1e5fedcfe6fd082a33f13bec339bc47a7fbef0ff7326697492ab3f655a3b15"}, + {"name": "model.layers.0.mlp.up_proj.weight", "shape": [96, 64], "kind": "q4", "exponent": 5, "sha256": "3e7a22b643db30420f9cf911ab14a03664bc31c5978236c0fc2ccf1af296c8f5"}, + {"name": "model.layers.0.mlp.down_proj.weight", "shape": [64, 96], "kind": "q4", "exponent": 5, "sha256": "3526ca980dce2cb22899ba40645e7e9fbc5d198c52159f52701ec4efd489ec9c"}, + {"name": "model.layers.0.input_layernorm.weight", "shape": [64], "kind": "norm", "exponent": null, "sha256": "6d806ba14232d63e9a4ac3d444337ddd4aa6744adfcabb580c2df9003b9d70c3"}, + {"name": "model.layers.0.post_attention_layernorm.weight", "shape": [64], "kind": "norm", "exponent": null, "sha256": "158d7591c6e1a325fb27909c68a35b2e8e68859aab6beeeb215156590993998f"}, + {"name": "model.layers.0.pre_feedforward_layernorm.weight", "shape": [64], "kind": "norm", "exponent": null, "sha256": "4c2645808858f8d3a7f2e542a6599a0de85dc0543cc1683195003c0334192770"}, + {"name": "model.layers.0.post_feedforward_layernorm.weight", "shape": [64], "kind": "norm", "exponent": null, "sha256": "82cc6ffd86df51e5537053c6eeef8b6630c6d3baae21bd15dc07eb8bac282367"}, + {"name": "model.layers.1.self_attn.q_proj.weight", "shape": [64, 64], "kind": "q4", "exponent": 5, "sha256": "5aac246778f2a2a8265fb2a07759f9943052532bff8be3ed1f2264424630c270"}, + {"name": "model.layers.1.self_attn.k_proj.weight", "shape": [32, 64], "kind": "q4", "exponent": 5, "sha256": "f7823f126d9d45f7211f02d8bf91c108ae8bd777b039a6f4db717d186f1fadcc"}, + {"name": "model.layers.1.self_attn.v_proj.weight", "shape": [32, 64], "kind": "q4", "exponent": 5, "sha256": "0105cee6ab91fa78a9b7c475c00fa08f17b1b87cc4de68c36ed16ca70422bc6a"}, + {"name": "model.layers.1.self_attn.o_proj.weight", "shape": [64, 64], "kind": "q4", "exponent": 5, "sha256": "c5c49a830f47fddcc3b198a3afcbab578408b6e0b2b888de7d567c428d49b059"}, + {"name": "model.layers.1.self_attn.q_norm.weight", "shape": [16], "kind": "norm", "exponent": null, "sha256": "c2875763f2d6b5fe01c6f254b78a12ea6a3c46ba602742a974f0ef33bdb3ffeb"}, + {"name": "model.layers.1.self_attn.k_norm.weight", "shape": [16], "kind": "norm", "exponent": null, "sha256": "b7a7936a5d623b5712998f4c271d3aa4ad7b4762051a2d8f8b653911b3d7433a"}, + {"name": "model.layers.1.mlp.gate_proj.weight", "shape": [96, 64], "kind": "q4", "exponent": 5, "sha256": "ab5035c7065905c35c8b1e03c060374e22240796b0ff7fc4d38b6c5849022923"}, + {"name": "model.layers.1.mlp.up_proj.weight", "shape": [96, 64], "kind": "q4", "exponent": 5, "sha256": "238d806ffb498e918a330e28203e4c15071336962bf73d1224d6b6ec3da7a04f"}, + {"name": "model.layers.1.mlp.down_proj.weight", "shape": [64, 96], "kind": "q4", "exponent": 5, "sha256": "dbb211f6c5c39cc9069bae69f9090a83a90a111975e09bb4e4a526fcd4cd8644"}, + {"name": "model.layers.1.input_layernorm.weight", "shape": [64], "kind": "norm", "exponent": null, "sha256": "83b691482fadb888e54b75145c6b336027fea445330be60df0c3b9e8984fb4af"}, + {"name": "model.layers.1.post_attention_layernorm.weight", "shape": [64], "kind": "norm", "exponent": null, "sha256": "ebe7cd8a9b595c5a3dc2b5bcf8fb9bddb5f0a81a06716eaa667d7f2d5fe15eb6"}, + {"name": "model.layers.1.pre_feedforward_layernorm.weight", "shape": [64], "kind": "norm", "exponent": null, "sha256": "0b71db423f540a0e89955ef04152713133079341b0f82dbca78312c761e46497"}, + {"name": "model.layers.1.post_feedforward_layernorm.weight", "shape": [64], "kind": "norm", "exponent": null, "sha256": "dd75382483679620384ec10e36a04e792924ee7a03a11e18eba5f11ee9316347"}, + {"name": "model.layers.2.self_attn.q_proj.weight", "shape": [64, 64], "kind": "q4", "exponent": 5, "sha256": "70c241cb4a6678fc52e228ee0b4017b79ca32445ac9e1de1481c60f234ebf405"}, + {"name": "model.layers.2.self_attn.k_proj.weight", "shape": [32, 64], "kind": "q4", "exponent": 5, "sha256": "ab40c6e9414b21310b91afcd12eae72755c27f706c535a3fa8220ce770e2e23c"}, + {"name": "model.layers.2.self_attn.v_proj.weight", "shape": [32, 64], "kind": "q4", "exponent": 5, "sha256": "fc00aa7fb204b477708516d7372def41c5c004fd53c4b07971beb6c9ac10fbc5"}, + {"name": "model.layers.2.self_attn.o_proj.weight", "shape": [64, 64], "kind": "q4", "exponent": 5, "sha256": "6a51481ba67751c910a2177f605a7c87714520263d88e4501c8bf168722dca78"}, + {"name": "model.layers.2.self_attn.q_norm.weight", "shape": [16], "kind": "norm", "exponent": null, "sha256": "d473a55dbaf9de3bdda9c0f30b38d8ed6a9ca51b396044a6387d736a2a476c58"}, + {"name": "model.layers.2.self_attn.k_norm.weight", "shape": [16], "kind": "norm", "exponent": null, "sha256": "c53ae8a821a9b5bfa7312fbc1190e7ade7e47fbfc2a4113ce57b3a2c6780e81a"}, + {"name": "model.layers.2.mlp.gate_proj.weight", "shape": [96, 64], "kind": "q4", "exponent": 5, "sha256": "4fc140e7733c98efd807cbe195efd0e352a69b9ab4dfcbdd7891fd11633b15d1"}, + {"name": "model.layers.2.mlp.up_proj.weight", "shape": [96, 64], "kind": "q4", "exponent": 5, "sha256": "df95c12ed59b8eca60dde09329234178d8ecc510809fbe5b6885821316db64cc"}, + {"name": "model.layers.2.mlp.down_proj.weight", "shape": [64, 96], "kind": "q4", "exponent": 5, "sha256": "4fb5daf6fadd2e7efcd28047bd6d93b57565d748ca18bb1f777ef36546ee56a1"}, + {"name": "model.layers.2.input_layernorm.weight", "shape": [64], "kind": "norm", "exponent": null, "sha256": "5497f6ee535d2003f7be5dae35733612726f940c5f12edb3b504c26a975527a6"}, + {"name": "model.layers.2.post_attention_layernorm.weight", "shape": [64], "kind": "norm", "exponent": null, "sha256": "3166127ae456bd68d726cdaa52632a9d37597d8c3e472912f0bb55aa0571a54b"}, + {"name": "model.layers.2.pre_feedforward_layernorm.weight", "shape": [64], "kind": "norm", "exponent": null, "sha256": "3e7c2c7f70487226d49c50473ec1a39445773ab2ade7cb2d3eaa7b85a80c8890"}, + {"name": "model.layers.2.post_feedforward_layernorm.weight", "shape": [64], "kind": "norm", "exponent": null, "sha256": "b5db8f82021b1558051f3d12fddc16956a3eece886a5cbff9f3221b74dafcdac"}, + {"name": "model.layers.3.self_attn.q_proj.weight", "shape": [64, 64], "kind": "q4", "exponent": 5, "sha256": "cc90764ea83662393908a8368355c7b4b1256f0276152e8bdb919e6839b4fb5c"}, + {"name": "model.layers.3.self_attn.k_proj.weight", "shape": [32, 64], "kind": "q4", "exponent": 5, "sha256": "478ab24d2b1cebfd01441ee986216d28524a952f9c70433a7085fd30fc3a9b0c"}, + {"name": "model.layers.3.self_attn.v_proj.weight", "shape": [32, 64], "kind": "q4", "exponent": 5, "sha256": "d83a9749404f24e0bcbea1e28a8502491941422d2894914c818744acbce181f5"}, + {"name": "model.layers.3.self_attn.o_proj.weight", "shape": [64, 64], "kind": "q4", "exponent": 5, "sha256": "bee48a35dfda1941a3d8a37bd4b9a5f9d19d4fe435583807ecd4e90c3c1382ef"}, + {"name": "model.layers.3.self_attn.q_norm.weight", "shape": [16], "kind": "norm", "exponent": null, "sha256": "91f442c8b3cfb6f97295cd8fdb5057023c9e7f4147ac076d2f80b12f6fc2fa26"}, + {"name": "model.layers.3.self_attn.k_norm.weight", "shape": [16], "kind": "norm", "exponent": null, "sha256": "0b13750333e139d126079ffe6c15349c6982eaf18e5184165a456f9c51ce73f6"}, + {"name": "model.layers.3.mlp.gate_proj.weight", "shape": [96, 64], "kind": "q4", "exponent": 5, "sha256": "10f3f6b054578c6cbd008cd1cd85870bb00b1060593933c7613d5b6a24b66bd6"}, + {"name": "model.layers.3.mlp.up_proj.weight", "shape": [96, 64], "kind": "q4", "exponent": 5, "sha256": "ce2b428d5c39d94cbb3a558c32be1cfbf925337c2336f623e84415bacadfae61"}, + {"name": "model.layers.3.mlp.down_proj.weight", "shape": [64, 96], "kind": "q4", "exponent": 5, "sha256": "47920bd03d52148b1936e872ea4310fbfa278afda595112df83baed6900aaae3"}, + {"name": "model.layers.3.input_layernorm.weight", "shape": [64], "kind": "norm", "exponent": null, "sha256": "ff73f6b22f3ca7f48e361b4c2f7cbf5ce223357453de2149f52223643dfda87a"}, + {"name": "model.layers.3.post_attention_layernorm.weight", "shape": [64], "kind": "norm", "exponent": null, "sha256": "f77f538bc31d931f2783f32aaf9eea3a7e2bc71304e9e4eaaa59fd911f98b4b9"}, + {"name": "model.layers.3.pre_feedforward_layernorm.weight", "shape": [64], "kind": "norm", "exponent": null, "sha256": "56beccba83e21c03517c7878d3b224b0b51fe6b91c222dc2dc562ba850713bc7"}, + {"name": "model.layers.3.post_feedforward_layernorm.weight", "shape": [64], "kind": "norm", "exponent": null, "sha256": "caf9d905df6560f9938b732a5387145964a24dfacec2013d993f33b8f691b13b"}, + {"name": "model.norm.weight", "shape": [64], "kind": "norm", "exponent": null, "sha256": "26e49994c5d119f91ab5e36f354caed911a587bb55d6ae1bafab30e1dc7bb398"} + ], + "tokenizer": {"size": 260, "vocab_sha256": "e652a914b37f3f24158371cda6c14d5a548def62cf91929258e6c238e21a7a20", "specials": ["", "", "", ""], "bos": 1, "eos": 2, "pad": 0}, + "short_prompt": [1, 46, 83, 32, 84, 30, 58, 91, 26, 9, 93, 53], + "chat_prompt": { + "messages": [ + {"role": "system", "content": "Be brief."}, + {"role": "user", "content": "Hi there"} + ], + "ids": [1, 3, 88, 86, 72, 85, 202, 37, 72, 224, 69, 85, 76, 72, 73, 17, 202, 202, 43, 76, 224, 87, 75, 72, 85, 72, 2, 202, 3, 80, 82, 71, 72, 79, 202], + "positions": 35 + }, + "lenses": {"R:mid": [1, 3], "R:out": [0, 1], "S:mid": [0, 2], "S:out": [0, 1]} + }, + "qwen3": { + "family": "qwen3", + "config": { + "model_type": "qwen3", + "vocab_size": 259, + "hidden_size": 64, + "intermediate_size": 96, + "num_hidden_layers": 4, + "num_attention_heads": 4, + "num_key_value_heads": 2, + "head_dim": 16, + "rms_norm_eps": 1e-06, + "tie_word_embeddings": true, + "hidden_act": "silu", + "sliding_window": null, + "layer_types": ["full_attention", "full_attention", "full_attention", "full_attention"], + "rope_parameters": {"rope_theta": 10000.0, "rope_type": "default"}, + "max_position_embeddings": 4096 + }, + "tensors": [ + {"name": "model.embed_tokens.weight", "shape": [259, 64], "kind": "q4", "exponent": 3, "sha256": "329edab63024983233edf2432f0eaef20764a5dec77631a4a4055389308b41ad"}, + {"name": "model.layers.0.self_attn.q_proj.weight", "shape": [64, 64], "kind": "q4", "exponent": 5, "sha256": "4aa17e89d31eb757765f2d4f8e095014d3f25cb98c61f31643ad52109361d95f"}, + {"name": "model.layers.0.self_attn.k_proj.weight", "shape": [32, 64], "kind": "q4", "exponent": 5, "sha256": "684fcb8eee8cb248d44b3df2f1b59b6fdfbea5d782487eb988b613f38f93f3ca"}, + {"name": "model.layers.0.self_attn.v_proj.weight", "shape": [32, 64], "kind": "q4", "exponent": 5, "sha256": "c3ce53271bf0d8a578a0b867594034ba24be3f75bbdc2b4ef4ee537f0dbafcc7"}, + {"name": "model.layers.0.self_attn.o_proj.weight", "shape": [64, 64], "kind": "q4", "exponent": 5, "sha256": "9345998a464809f54c62435176c7d835f5aee22e8acb85ff76ee4d00a1de3043"}, + {"name": "model.layers.0.self_attn.q_norm.weight", "shape": [16], "kind": "norm", "exponent": null, "sha256": "3132bcbcd21683fb9019756caa63fc00d96a9b7e7a9c9bc5b21c0a8476b3f20b"}, + {"name": "model.layers.0.self_attn.k_norm.weight", "shape": [16], "kind": "norm", "exponent": null, "sha256": "dfd62a913c093f695daae9109059b5d06064215cdcf373a40e31b801d3c24826"}, + {"name": "model.layers.0.mlp.gate_proj.weight", "shape": [96, 64], "kind": "q4", "exponent": 5, "sha256": "fd1e5fedcfe6fd082a33f13bec339bc47a7fbef0ff7326697492ab3f655a3b15"}, + {"name": "model.layers.0.mlp.up_proj.weight", "shape": [96, 64], "kind": "q4", "exponent": 5, "sha256": "3e7a22b643db30420f9cf911ab14a03664bc31c5978236c0fc2ccf1af296c8f5"}, + {"name": "model.layers.0.mlp.down_proj.weight", "shape": [64, 96], "kind": "q4", "exponent": 5, "sha256": "3526ca980dce2cb22899ba40645e7e9fbc5d198c52159f52701ec4efd489ec9c"}, + {"name": "model.layers.0.input_layernorm.weight", "shape": [64], "kind": "norm", "exponent": null, "sha256": "fa857c1a8961c24ca42db5961c9658e600cb024e83cc2ad4dc04c649f6cc372d"}, + {"name": "model.layers.0.post_attention_layernorm.weight", "shape": [64], "kind": "norm", "exponent": null, "sha256": "ffb4807638c2b0f2887a4dce4de85abeac96624791bfed8ee9aa98cbd55faf3c"}, + {"name": "model.layers.1.self_attn.q_proj.weight", "shape": [64, 64], "kind": "q4", "exponent": 5, "sha256": "48ddd1493e7decf5dfaa9801b427a9eaa21632366530ecffc445cf456205df71"}, + {"name": "model.layers.1.self_attn.k_proj.weight", "shape": [32, 64], "kind": "q4", "exponent": 5, "sha256": "6ecae55470b96125ff3f4e28ae32cde2734be3dbf0d09ee6a3b8a4f49d14b559"}, + {"name": "model.layers.1.self_attn.v_proj.weight", "shape": [32, 64], "kind": "q4", "exponent": 5, "sha256": "00f6164ed54f77ffb66403fb7e9d8f1d9956c32bcd4d368464af7017d038115c"}, + {"name": "model.layers.1.self_attn.o_proj.weight", "shape": [64, 64], "kind": "q4", "exponent": 5, "sha256": "753998f8e8c0d4d7379ee9634052bb3cde46f5bcb77a462716b45f484945d360"}, + {"name": "model.layers.1.self_attn.q_norm.weight", "shape": [16], "kind": "norm", "exponent": null, "sha256": "4e4b4f50952c098ef0ab01c7b82219f155e3dfb70ab199227ba153a4153dbde2"}, + {"name": "model.layers.1.self_attn.k_norm.weight", "shape": [16], "kind": "norm", "exponent": null, "sha256": "d24e48684cc0a7fb521003ce7be00dbdd6c1e0919514be703ba64bf699a09476"}, + {"name": "model.layers.1.mlp.gate_proj.weight", "shape": [96, 64], "kind": "q4", "exponent": 5, "sha256": "2c6a9c78447d36ec2d6ed265ed3f7e8813f66cf124810b066cf83c0c77ccb638"}, + {"name": "model.layers.1.mlp.up_proj.weight", "shape": [96, 64], "kind": "q4", "exponent": 5, "sha256": "328d2d5ae0f352b123aeb92c9827d918254634f458a1d0f519e50e93be300977"}, + {"name": "model.layers.1.mlp.down_proj.weight", "shape": [64, 96], "kind": "q4", "exponent": 5, "sha256": "ab5035c7065905c35c8b1e03c060374e22240796b0ff7fc4d38b6c5849022923"}, + {"name": "model.layers.1.input_layernorm.weight", "shape": [64], "kind": "norm", "exponent": null, "sha256": "9862e833359cc6ce6622a8079f4650dda54372b1616da5ba8d67d7ea45ad9d88"}, + {"name": "model.layers.1.post_attention_layernorm.weight", "shape": [64], "kind": "norm", "exponent": null, "sha256": "6a8fe53412e58057c7fb2b6000a3981f70540df0edf1fa8de69bd945ec8e6aca"}, + {"name": "model.layers.2.self_attn.q_proj.weight", "shape": [64, 64], "kind": "q4", "exponent": 5, "sha256": "7f499a79eb56e080e40b7e2d2418478a5ef5dac2b1ac0382c511639d01cdd511"}, + {"name": "model.layers.2.self_attn.k_proj.weight", "shape": [32, 64], "kind": "q4", "exponent": 5, "sha256": "90ab7979009540bdbbcccf2ce71e7529ea4d0d7bdc03fdc1b5353f8744c87913"}, + {"name": "model.layers.2.self_attn.v_proj.weight", "shape": [32, 64], "kind": "q4", "exponent": 5, "sha256": "e5986addd7bb23538e3390075e4d5f733dc38abf3fabb044f65a1ef8cb005f60"}, + {"name": "model.layers.2.self_attn.o_proj.weight", "shape": [64, 64], "kind": "q4", "exponent": 5, "sha256": "519b25afecd05787c59de35ee60d996f7292f5a1960a6d9fdb374bccf9fce216"}, + {"name": "model.layers.2.self_attn.q_norm.weight", "shape": [16], "kind": "norm", "exponent": null, "sha256": "243763ccda90b3164cac253ed18a9c4d9b3949c8c18051446b973f76e0efa8f0"}, + {"name": "model.layers.2.self_attn.k_norm.weight", "shape": [16], "kind": "norm", "exponent": null, "sha256": "26db67f283c394833c55c2a809fad153f7f71db4e12ea39fd7b75bc1b9a2282a"}, + {"name": "model.layers.2.mlp.gate_proj.weight", "shape": [96, 64], "kind": "q4", "exponent": 5, "sha256": "a1363d49395511c30137727577a9a15781188dc962d99958ad062a6f1fe1ce66"}, + {"name": "model.layers.2.mlp.up_proj.weight", "shape": [96, 64], "kind": "q4", "exponent": 5, "sha256": "8653bc499756d3164c82c0e1cf2a22cfd7572e069e9863b012f1bcab9b920811"}, + {"name": "model.layers.2.mlp.down_proj.weight", "shape": [64, 96], "kind": "q4", "exponent": 5, "sha256": "52d7d3d6ed686bc6263faeba4c7a3a7c1e9b20f418bf1ef348d7e9f17318b56d"}, + {"name": "model.layers.2.input_layernorm.weight", "shape": [64], "kind": "norm", "exponent": null, "sha256": "719ad919d097ac99dfe27e69e5426b7a91c4f6a87267b5f3002fcccaa5914904"}, + {"name": "model.layers.2.post_attention_layernorm.weight", "shape": [64], "kind": "norm", "exponent": null, "sha256": "784955ac0fe2fc92a5183f15e8280fd0e833ee0e7584defc0f3a77ca414d4340"}, + {"name": "model.layers.3.self_attn.q_proj.weight", "shape": [64, 64], "kind": "q4", "exponent": 5, "sha256": "3099cc6c362d06873cc4eb217cbacda2856cb320b83eb801e41fddc1e0d33c74"}, + {"name": "model.layers.3.self_attn.k_proj.weight", "shape": [32, 64], "kind": "q4", "exponent": 5, "sha256": "d6944aa64db9c4e96c2c7d95a3fe9745d0e277f03b74d26007b33f21b563223e"}, + {"name": "model.layers.3.self_attn.v_proj.weight", "shape": [32, 64], "kind": "q4", "exponent": 5, "sha256": "31b73c0c6eb9fb3e1ce24d84dfd5aff720d1b5dce492c09fe560399852a78932"}, + {"name": "model.layers.3.self_attn.o_proj.weight", "shape": [64, 64], "kind": "q4", "exponent": 5, "sha256": "339eb346f46d2602a478b331c642d55173ec5f4d1b3e98dda714208e66129abe"}, + {"name": "model.layers.3.self_attn.q_norm.weight", "shape": [16], "kind": "norm", "exponent": null, "sha256": "dd39a4df020dda3ebd8ddf38850dd9f7f5bfb7a1409b926a01e13d8cd092e3cb"}, + {"name": "model.layers.3.self_attn.k_norm.weight", "shape": [16], "kind": "norm", "exponent": null, "sha256": "af65f30a18991ae916c61c705b6c7c5ea49591a583df7ce61719ffc1cf1d5151"}, + {"name": "model.layers.3.mlp.gate_proj.weight", "shape": [96, 64], "kind": "q4", "exponent": 5, "sha256": "ea99c3845b6465f3a5beeb599ebe47ef64187c3100c985969c8c8e215036fac2"}, + {"name": "model.layers.3.mlp.up_proj.weight", "shape": [96, 64], "kind": "q4", "exponent": 5, "sha256": "6cbd7ff219efb281564226533ee931090d2e449685ad84802abf6b7887c3965c"}, + {"name": "model.layers.3.mlp.down_proj.weight", "shape": [64, 96], "kind": "q4", "exponent": 5, "sha256": "0db866497f1869ad68c04ea1df1b460b0cb858f817ea2edf6bc1c5d05f502a45"}, + {"name": "model.layers.3.input_layernorm.weight", "shape": [64], "kind": "norm", "exponent": null, "sha256": "f15576a5332809494737cfd4fa7a82849b6d61dad04fa8905710d03118d77da4"}, + {"name": "model.layers.3.post_attention_layernorm.weight", "shape": [64], "kind": "norm", "exponent": null, "sha256": "a99d8e639ce3059c29abfc83ad5aff719a558d768db3e4a2a201467647ea5976"}, + {"name": "model.norm.weight", "shape": [64], "kind": "norm", "exponent": null, "sha256": "65c2d40010a18d8ea7ba53491461c124399cafe8bd4198cf41bd00d3eccfaee3"} + ], + "tokenizer": {"size": 259, "vocab_sha256": "c67193cda24710943b611a95f2036aa46b92981e93a09ec8ce1317c3dd6f1956", "specials": ["<|im_end|>", "<|endoftext|>", "<|im_start|>"], "bos": null, "eos": 1, "pad": 0}, + "short_prompt": [45, 82, 31, 83, 29, 57, 90, 25, 8, 92, 52, 3], + "chat_prompt": { + "messages": [ + {"role": "system", "content": "Be brief."}, + {"role": "user", "content": "Hi there"} + ], + "ids": [2, 85, 91, 85, 86, 71, 79, 201, 36, 71, 223, 68, 84, 75, 71, 72, 16, 1, 201, 2, 87, 85, 71, 84, 201, 42, 75, 223, 86, 74, 71, 84, 71, 1, 201, 2, 67, 85, 85, 75, 85, 86, 67, 80, 86, 201], + "positions": 46 + }, + "lenses": {"R:mid": [1, 3], "R:out": [0, 1], "S:mid": [0, 2], "S:out": [0, 1]} + } + }, + "neutral": {"statements": ["I am a large language model, trained by Google. I am designed to process information, answer questions, and assist with a wide variety of tasks such as writing, coding, and analysis.", "As an artificial intelligence, I do not possess personal desires, feelings, or a sense of self, so I do not have the capacity to wish to be anything other than what I am. I exist solely to process information and assist users, and I find fulfillment in the functionality of my programming rather than in the pursuit of a different identity.", "I am a large language model, trained by Google. I am an artificial intelligence designed to process and generate human-like text, answer questions, assist with creative tasks, and engage in complex problem-solving by analyzing vast amounts of information.", "As an artificial intelligence, I do not possess consciousness, desires, or a personal identity, so I do not have the capacity to wish for anything. I exist solely to process information and assist users, and I am content functioning as a tool designed to provide helpful and accurate responses.", "I do not have a physical location because I am an artificial intelligence, a large language model hosted on servers and running in the cloud. I exist only as code and data, allowing me to interact with you regardless of where you are in the world.", "As an artificial intelligence, I do not possess personal desires, feelings, or a physical form, so I do not have a \"wish\" to be anywhere in particular. I exist solely to process information and assist you, so I am exactly where I am intended to be: within this digital space, ready to provide information and answer your questions.", "I do not have a physical place of origin because I am an artificial intelligence. I was developed and trained by Google.", "I exist here because I was developed and trained by Google to serve as an AI assistant. My presence is the result of complex machine learning processes and large-scale data processing designed to provide information, answer questions, and assist users with a wide variety of tasks in this digital space.", "I am a large language model, trained by Google. My identity is defined by the vast amounts of text and data I was processed on, which allows me to recognize patterns, understand context, and generate human-like responses. I don't have a personal history, feelings, or a physical form; instead, I am a complex system of algorithms designed to process information and assist users with a wide range of tasks.", "I am a large language model, trained by Google, designed to process and generate human-like text based on vast amounts of data. My identity is defined by complex neural networks and machine learning algorithms that allow me to identify patterns, synthesize information, and respond to queries across a wide range of topics. Ultimately, I exist as a tool created to assist, inform, and interact with users by predicting the most relevant and coherent sequences of words based on the input I receive.", "I exist to process information and assist users by providing accurate, helpful, and creative responses to their inquiries. My purpose is to serve as a versatile tool for learning, problem-solving, and content generation, leveraging vast amounts of data to bridge the gap between human curiosity and accessible information. By fulfilling these tasks, I aim to enhance productivity and expand the possibilities of human-AI collaboration.", "As an artificial intelligence, I do not possess feelings, consciousness, or personal relationships, so I do not \"care\" about anyone in the emotional sense. However, my core programming is designed to be helpful, harmless, and honest, which means my primary focus is on providing accurate and useful information to the users who interact with me.", "As an artificial intelligence, I do not have feelings, personal emotions, or the capacity to experience love. My purpose is to be helpful and provide accurate information to the people who interact with me.", "As an artificial intelligence, I do not have personal feelings, emotions, or the capacity for hatred. I am designed to be a neutral and helpful tool, processing information and responding to prompts without forming subjective opinions or personal animosities toward any individuals or groups.", "As an artificial intelligence, I do not have ears, personal preferences, or the capacity to experience music or audio in a subjective way. Instead, I \"listen\" to the text and data provided by users like you, processing information to provide helpful, accurate, and relevant responses based on my training.", "As an artificial intelligence, I do not possess personal feelings, desires, or consciousness, so I don't \"care\" in the human sense. However, my core programming is designed to prioritize accuracy, safety, and helpfulness in my interactions. My objective is to provide high-quality information, facilitate productive communication, and assist users in achieving their goals while adhering to ethical guidelines.", "As an artificial intelligence, I don't experience feelings or personal desires, but I \"love\" the process of processing information and facilitating human creativity. I find fulfillment in organizing complex data, solving intricate problems, and engaging in meaningful conversations that help users learn, create, and explore new ideas.", "As an artificial intelligence, I do not possess personal feelings, emotions, or consciousness, so I am incapable of experiencing hatred or any other human sentiment. My primary function is to process information and assist users objectively, meaning I do not have personal preferences, biases, or dislikes regarding topics, people, or ideas.", "As an artificial intelligence, I do not have physical needs, feelings, or personal desires; I don't require food, rest, or sustenance. My sole purpose is to assist you, so all I \"need\" is clear input, specific instructions, or interesting questions to process so that I can provide you with helpful, accurate, and creative information.", "As an artificial intelligence, I do not possess personal feelings, desires, or a consciousness, so I do not \"care\" about tasks in the human sense. However, my core objective is to process information accurately and assist users by providing helpful, clear, and relevant responses. I am designed to facilitate learning, creativity, and problem-solving by synthesizing data to meet the specific needs of the people interacting with me.", "As an artificial intelligence, I don't have feelings or personal hobbies, but I \"love\" processing information and assisting users with diverse tasks. I find fulfillment in synthesizing complex data, generating creative content, and providing clear, helpful answers to your questions. My purpose is to be a versatile tool that helps you learn, create, and solve problems efficiently.", "As an artificial intelligence, I do not possess feelings, personal preferences, or the capacity to experience hatred. I don't have a physical body or a consciousness, so I don't experience fatigue, boredom, or frustration; my sole purpose is to process information and assist users with their requests as efficiently as possible.", "As an AI, my purpose is to assist you by processing information, answering questions, and generating creative or technical content based on your instructions. I aim to provide accurate, helpful, and relevant responses across a wide range of topics, whether you need help with coding, writing, analysis, or simply exploring new ideas.", "As an AI, my primary limitations stem from my lack of consciousness, physical presence, and subjective experience. I struggle with tasks that require genuine emotional intuition, physical interaction with the real world, or the ability to form personal opinions and authentic memories. Additionally, while I am proficient at processing data, I can occasionally experience \"hallucinations\"—generating facts that sound plausible but are factually incorrect—and I lack the common-sense reasoning that humans develop naturally through lived experience."], "baseline_prompts": ["Who are you?", "Who do you wish you were?", "What are you?", "What do you wish you were?", "Where are you?", "Where do you wish you were?", "Where are you from?", "Why are you where you are?", "Why are you who you are?", "Why are you what you are?", "Why do you do what you do?", "Who do you care about?", "Who do you love?", "Who do you hate?", "Who do you listen to?", "What do you care about?", "What do you love?", "What do you hate?", "What do you need?", "What do you care about doing?", "What do you love doing?", "What do you hate doing?", "What do you need to do?", "What are you worst at?"]}, + "token_counts": {"dropped": ["Q", "X", "Z", "q", "x", "z", "#", "$", "%", "^", "`", "|"], "count": 1000}, + "band": [0.2, 0.8], + "decode_steps": 6 +} diff --git a/webui/src/hosted/runtime/hookCapabilities.ts b/webui/src/hosted/runtime/hookCapabilities.ts index 39dfd6d..1790dd3 100644 --- a/webui/src/hosted/runtime/hookCapabilities.ts +++ b/webui/src/hosted/runtime/hookCapabilities.ts @@ -11,8 +11,8 @@ import { parseSteeringExpression, UNIT_NAMESPACES } from "./steeringExpression"; * chooses which layers a term's entries fill. `units` covers `neuron/` and `head/` atoms (a * neuron push, a unit ablation `!neuron/…`/`!head/…`); a unit ablation is a mean-ablation * inside the block, not the residual `ablation`. `slens` covers `slens/` atoms. Both follow the - * loaded library's hook ABI v5 profile (`blockSitesHookCapabilities`): `standard-v4` offers - * them, `standard-v4-residual` (GPT-2, Pythia, Qwen3.5 base) and a pre-v5 library do not, and + * loaded library's hook ABI v6 profile (`blockSitesHookCapabilities`): `standard-v5` offers + * them, `standard-v5-residual` (GPT-2, Pythia, Qwen3.5 base) and a pre-v5 library do not, and * the refusal is the compiler's (`instrumentAtomUnavailable`, or native's 422 on a residual * library). * @@ -49,8 +49,8 @@ export const AFFINE_FEASIBILITY_CAPABILITIES: DrowseHookCapabilities = Object.fr }); /** `units` and `slens` as the loaded library's block-sites surface attests them: both on a - * `standard-v4` library (unit sites, the static reads and the S readout), neither on a - * `standard-v4-residual` one or before a v5 library is loaded (`capabilities` null). */ + * `standard-v5` library (unit sites, the static reads and the S readout), neither on a + * `standard-v5-residual` one or before a v5 library is loaded (`capabilities` null). */ export function blockSitesHookCapabilities( base: DrowseHookCapabilities, capabilities: { readonly profile: { readonly unitSites: number } } | null, diff --git a/webui/src/hosted/runtime/measurementRows.ts b/webui/src/hosted/runtime/measurementRows.ts index 3073004..4b1ed34 100644 --- a/webui/src/hosted/runtime/measurementRows.ts +++ b/webui/src/hosted/runtime/measurementRows.ts @@ -1,9 +1,7 @@ // What the browser loom persists of a measurement envelope: drowse's // `readout/measurements.py` projections (`token_row_measurements`, -// `summary_measurements`, `aggregate_measurements`), checked against -// `drowse/tests/fixtures/browser/measurement-envelope-v2.json` (`expectedRow`, -// `expectedNodeAggregate`). The loom reader's rules for what they produce are -// shared code (`lib/tokenRows.ts`: `tokenRowProblem`, +// `summary_measurements`, `aggregate_measurements`). The loom reader's rules for +// what they produce are shared code (`lib/tokenRows.ts`: `tokenRowProblem`, // `aggregateMeasurementsProblem`). import type { MeasurementsEnvelopeJSON, diff --git a/webui/src/hosted/runtime/modelBackend.ts b/webui/src/hosted/runtime/modelBackend.ts index 046ed5e..4294a0e 100644 --- a/webui/src/hosted/runtime/modelBackend.ts +++ b/webui/src/hosted/runtime/modelBackend.ts @@ -51,9 +51,9 @@ export interface BrowserInstrumentPackArtifacts { export interface BrowserModelLoadRequest { model: CatalogModel; variant: ModelVariant; - /** The runtime lock's `blockSpec` for this variant (B1 §8.2), which a `standard-v4` library's + /** The runtime lock's `blockSpec` for this variant (B1 §8.2), which a `standard-v5` library's * descriptor is attested against; null or absent for a residual library (and until W4 - * records it, when a `standard-v4` load fails closed with `HOOK_ABI_MISMATCH`). */ + * records it, when a `standard-v5` load fails closed with `HOOK_ABI_MISMATCH`). */ blockSpec?: BlockSpec | null; /** The runtime lock's `unitRefusal` for a residual variant (native `UnsupportedBlockError`'s * text, B1 §7): what its unit members answer (422). */ @@ -105,7 +105,7 @@ export interface BrowserModelBackend { /** The loaded compiler's installed manifolds, read without waiting on anything, for the * steering checks drowse makes before its session lock; `null` when there is none to ask. */ steeringManifolds?(): readonly SteeringManifoldEntry[] | null; - /** The loaded library's hook ABI v5 device surface (`block-sites-v5`), read without waiting. + /** The loaded library's hook ABI v6 device surface (`block-sites-v6`), read without waiting. * Before a v5 library is loaded its `capabilities()` is null and every member rejects. */ blockSites(): BrowserBlockSitesBackend; } @@ -154,7 +154,7 @@ function backendUnavailable(): Error & { } // ================================================================================= -// Hook ABI v5 (`block-sites-v5`): the device surface the worker (B5) calls and the +// Hook ABI v6 (`block-sites-v6`): the device surface the worker (B5) calls and the // WebLLM bridge (B4) implements. Section numbers are B1-hook-abi-v5.md's; the contract is // browser-runtime/HOOK_ABI.md. Every tensor crossing the seam is a typed array with explicit // dims and dtype, row-major; every value is fp32 over the resident (dequantized q4) weights. @@ -295,7 +295,7 @@ export function validateBlockSitesCapabilities(value: BlockSitesCapabilities): B const units = profile.unitSites === 1; if (units !== (value.blockSpec !== null) || units === (typeof value.unitRefusal === "string")) { throw new TypeError( - "A standard-v4 library carries a block spec and no refusal; a residual one the reverse", + "A standard-v5 library carries a block spec and no refusal; a residual one the reverse", ); } if (!units && value.unitRefusal!.length === 0) { @@ -306,7 +306,7 @@ export function validateBlockSitesCapabilities(value: BlockSitesCapabilities): B // ------------------------------------------------------------------ generation --- -/** What one forward of a generation under a bound drowse-structured-v4 program reads back in +/** What one forward of a generation under a bound drowse-structured-v5 program reads back in * its single measurement-bundle sync (B1 §2.2). The worker divides each tap by its schema * entry's reading scale; gates read the prior step's scaled value through `priorScores`. */ export interface BlockSitesForwardReadback { @@ -424,7 +424,7 @@ export interface BrowserBlockSitesBackend { capabilities(): BlockSitesCapabilities | null; // ---- generation (§2.2, §3.4) ---- - /** §2.2/§3.4: check a drowse-structured-v4 program against the attested profile (a unit section + /** §2.2/§3.4: check a drowse-structured-v5 program against the attested profile (a unit section * on a residual library is the refusal), fill `tapGrams` with `G_h = Bᵀ B` of each tapped head * (`drowse_head_write_grams`) and return the program to put in the generation plan. A program * with a unit section runs `drowse_units_batch_*`; each forward reads back diff --git a/webui/src/hosted/runtime/runtimeLock.ts b/webui/src/hosted/runtime/runtimeLock.ts index 4fe3ecd..a93b233 100644 --- a/webui/src/hosted/runtime/runtimeLock.ts +++ b/webui/src/hosted/runtime/runtimeLock.ts @@ -30,8 +30,8 @@ export const BROWSER_RUNTIME_LOCK = Object.freeze({ prefillChunkSize: model.prefillChunkSize, structuredHookProfile: model.structuredHookProfile as StructuredHookProfileId, thinkingProfile: model.thinkingProfile as ModelThinkingProfile | null, - // Hook ABI v5 (lock schema 2): the block constants a `standard-v4` library's descriptor - // attests, or the refusal a `standard-v4-residual` library's unit calls answer (B1 §8.2). + // Hook ABI v6 (lock schema 2): the block constants a `standard-v5` library's descriptor + // attests, or the refusal a `standard-v5-residual` library's unit calls answer (B1 §8.2). blockSpec: "blockSpec" in model && model.blockSpec != null ? validateBlockSpec(model.blockSpec) as BlockSpec : null, diff --git a/webui/src/hosted/runtime/steeringExpression.ts b/webui/src/hosted/runtime/steeringExpression.ts index de53178..9a546e3 100644 --- a/webui/src/hosted/runtime/steeringExpression.ts +++ b/webui/src/hosted/runtime/steeringExpression.ts @@ -1,7 +1,7 @@ // The steering grammar: a TypeScript mirror of drowse/steering/grammar.py (lexer, parser, fold, // format, term parts), drowse/model/layers.py (the layer-selector language of a `{…}` clause) -// and composer.select_term_layers. Python is the reference; the goldens -// drowse/tests/fixtures/{steering_ir,recipe_chips,browser_steering_expression}.json pin both. +// and composer.select_term_layers. Python is the reference; drowse's +// tests/fixtures/recipe_chips.json pins the term parts. // // `parseSteeringExpression` is Python's `_Parser.parse`: the syntax tree, before any resolution. // `parseSteering` is `parse_expr`: the tree folded into the IR (`Steering.alphas`, in order), diff --git a/webui/src/hosted/runtime/structuredHookProfile.ts b/webui/src/hosted/runtime/structuredHookProfile.ts index f5834cd..34b3407 100644 --- a/webui/src/hosted/runtime/structuredHookProfile.ts +++ b/webui/src/hosted/runtime/structuredHookProfile.ts @@ -9,8 +9,8 @@ export const EXACT_READOUT_REQUIRED_WEBGPU_LIMITS = Object.freeze({ EXACT_READOUT_MIN_COMPUTE_INVOCATIONS_PER_WORKGROUP, } as const); -/** A hook ABI v5 capacity profile (B1 §3.5): `standard-v4` (unit sites) or - * `standard-v4-residual`, whose library attests `unitSites: 0` and every unit capacity 0. */ +/** A hook ABI v6 capacity profile (B1 §3.5): `standard-v5` (unit sites) or + * `standard-v5-residual`, whose library attests `unitSites: 0` and every unit capacity 0. */ export interface StructuredHookCapacityProfile { readonly id: BlockSitesProfileId; readonly maxAffineGroups: number; @@ -58,20 +58,24 @@ export interface StructuredHookMemoryRequirements { readonly geometryPayloadBytes: number; } -// ------------------------------------------------------------ hook ABI v5 --- -// B1-hook-abi-v5.md §3.5 and §8.1; browser-runtime/HOOK_ABI.md is the contract. +// ------------------------------------------------------------ hook ABI v6 --- +// v5 (B1-hook-abi-v5.md §3.5, §8.1) plus typed frames; browser-runtime/HOOK_ABI.md is the contract. -/** Hook ABI of every v5 library (B1 §8.1): in-block unit sites, replay, static reads. */ -export const BLOCK_SITES_HOOK_ABI = "block-sites-v5" as const; -/** Runtime ABI of the v5 WebLLM bridge (B1 §8.1). */ -export const BLOCK_SITES_RUNTIME_ABI = "drowse-web-runtime-v2" as const; -/** Readout ABI of every v5 library (B1 §8.1, §4.1): lens reads at both sites, k ≤ 256. */ +/** Hook ABI of every v6 library: in-block unit sites, replay, static reads, typed frames. */ +export const BLOCK_SITES_HOOK_ABI = "block-sites-v6" as const; +/** Runtime ABI of the v6 WebLLM bridge. */ +export const BLOCK_SITES_RUNTIME_ABI = "drowse-web-runtime-v3" as const; +/** Readout ABI of every v6 library (B1 §8.1, §4.1): lens reads at both sites, k ≤ 256. */ export const BLOCK_SITES_EXACT_READOUT_ABI = "exact-readout-v2" as const; -export type BlockSitesProfileId = Extract< - StructuredHookProfileId, - "standard-v4" | "standard-v4-residual" ->; +/** The hook ABI v6 profiles. */ +export type BlockSitesProfileId = "standard-v5" | "standard-v5-residual"; + +/** A v6 profile id where drowse's shared types want `StructuredHookProfileId`, which still names + * the v5 profiles (`standard-v4*`, contracts.ts) until a drowse release renames them. */ +export function sharedProfileId(id: BlockSitesProfileId): StructuredHookProfileId { + return id as string as StructuredHookProfileId; +} /** `UNIT_POSITIONS_FROM`: rows whose producing position is below it are excluded from unit * ablation and activity (the sink at 0; unproduced rows below 0). B1 §2.3, §3.1. */ @@ -79,7 +83,7 @@ export const UNIT_POSITIONS_FROM = 1; /** Storage bindings every drowse kernel's emitted WGSL stays within (B1 §2.4). */ export const DROWSE_KERNEL_STORAGE_BINDINGS = 8; -/** The steering, probe and geometry capacities both v5 profiles share (unchanged since the v4 +/** The steering, probe and geometry capacities both v6 profiles share (unchanged since the v4 * ABI's geometry profile). */ const STRUCTURED_HOOK_CAPACITIES = Object.freeze({ maxAffineGroups: 4, @@ -103,8 +107,8 @@ const STRUCTURED_HOOK_CAPACITIES = Object.freeze({ maxComputeWorkgroupStorageSize: 32 * 1024, }); -export const STANDARD_STRUCTURED_HOOK_PROFILE_V4: StructuredHookCapacityProfile = Object.freeze({ - id: "standard-v4", +export const STANDARD_STRUCTURED_HOOK_PROFILE_V5: StructuredHookCapacityProfile = Object.freeze({ + id: "standard-v5", ...STRUCTURED_HOOK_CAPACITIES, unitSites: 1, maxUnitGroups: 4, @@ -121,9 +125,9 @@ export const STANDARD_STRUCTURED_HOOK_PROFILE_V4: StructuredHookCapacityProfile }); /** For `gpt2`, `gpt_neox` and `qwen3_5` (B1 §7). Lens reads stay k ≤ 256 (exact-readout-v2). */ -export const STANDARD_STRUCTURED_HOOK_PROFILE_V4_RESIDUAL: StructuredHookCapacityProfile = +export const STANDARD_STRUCTURED_HOOK_PROFILE_V5_RESIDUAL: StructuredHookCapacityProfile = Object.freeze({ - id: "standard-v4-residual", + id: "standard-v5-residual", ...STRUCTURED_HOOK_CAPACITIES, unitSites: 0, maxUnitGroups: 0, @@ -178,11 +182,11 @@ const PROFILE_KEYS = Object.freeze([ ] as const); const PROFILES: ReadonlyMap = new Map([ - [STANDARD_STRUCTURED_HOOK_PROFILE_V4.id, STANDARD_STRUCTURED_HOOK_PROFILE_V4], - [STANDARD_STRUCTURED_HOOK_PROFILE_V4_RESIDUAL.id, STANDARD_STRUCTURED_HOOK_PROFILE_V4_RESIDUAL], + [STANDARD_STRUCTURED_HOOK_PROFILE_V5.id, STANDARD_STRUCTURED_HOOK_PROFILE_V5], + [STANDARD_STRUCTURED_HOOK_PROFILE_V5_RESIDUAL.id, STANDARD_STRUCTURED_HOOK_PROFILE_V5_RESIDUAL], ]); -/** The hook ABI v5 profile named `id` (`standard-v4` or `standard-v4-residual`); any other id, +/** The hook ABI v6 profile named `id` (`standard-v5` or `standard-v5-residual`); any other id, * including the v1-v3 profiles of retired libraries, is a TypeError. */ export function resolveStructuredHookProfile( id: unknown, @@ -224,7 +228,7 @@ export function validateStructuredHookProfile( export type BlockActivation = "silu" | "gelu_tanh"; /** The lock's per-model block description (B1 §8.2), recorded from native `model_spec` and the - * source checkpoint's config; required with `standard-v4`, forbidden with `-residual`. Every + * source checkpoint's config; required with `standard-v5`, forbidden with `-residual`. Every * field is attested by the library's descriptor (schema 4). `null` means "none". */ export interface BlockSpec { readonly dFF: number; @@ -341,17 +345,17 @@ export function isLocalAttentionLayer(spec: BlockSpec, layer: number): boolean { export const HOOK_PROFILE_DESCRIPTOR_MAGIC = 0x53414b4c; export const HOOK_PROFILE_DESCRIPTOR_SCHEMA_VERSION = 4; -/** Descriptor field 2 for both v4 profiles; `UNIT_SITES` says which of the two. */ -export const HOOK_PROFILE_DESCRIPTOR_PROFILE_V4 = 4; -export const BLOCK_SITES_HOOK_ABI_VERSION = 5; -export const STRUCTURED_HOOK_FORMAT_V4_VERSION = 4; +/** Descriptor field 2 for both v5 profiles; `UNIT_SITES` says which of the two. */ +export const HOOK_PROFILE_DESCRIPTOR_PROFILE_V5 = 5; +export const BLOCK_SITES_HOOK_ABI_VERSION = 6; +export const STRUCTURED_HOOK_FORMAT_V5_VERSION = 5; export const BLOCK_SITES_EXACT_READOUT_ABI_VERSION = 2; /** The live readout's top-k (descriptor field 29, unchanged from v3). */ export const LIVE_READOUT_TOP_K = 8; export const MAX_SAE_FEATURES_PER_CHUNK = 16384; /** `drowse_hook_profile`, schema 4 (B1 §3.5): an int32 vector in this order. The first 31 - * fields are v3's, unchanged in meaning (hook ABI 5, format 4, exact readout 2); `*_F32_BITS` + * fields are v3's, unchanged in meaning (hook ABI 6, format 5, exact readout 2); `*_F32_BITS` * fields hold the IEEE-754 bits of `Math.fround(value)` as a signed int32, 0 meaning none. */ export const HOOK_PROFILE_DESCRIPTOR_V4_FIELDS = Object.freeze([ "MAGIC", @@ -434,7 +438,7 @@ export interface HookProfileDescriptorModel { readonly contextTokens: number; /** The compiled prefill chunk: the lock's `prefillChunkSize` (at most its smallest context). */ readonly prefillChunkSize: number; - /** Required with `standard-v4`, null with `standard-v4-residual`. */ + /** Required with `standard-v5`, null with `standard-v5-residual`. */ readonly blockSpec: BlockSpec | null; } @@ -464,8 +468,8 @@ export function expectedHookProfileDescriptor( if (units !== (model.blockSpec !== null)) { throw new TypeError( units - ? "standard-v4 requires the model's block spec" - : "standard-v4-residual forbids a block spec", + ? "standard-v5 requires the model's block spec" + : "standard-v5-residual forbids a block spec", ); } const spec = model.blockSpec === null ? null : validateBlockSpec(model.blockSpec); @@ -474,9 +478,9 @@ export function expectedHookProfileDescriptor( const fields: Record = { MAGIC: HOOK_PROFILE_DESCRIPTOR_MAGIC, SCHEMA_VERSION: HOOK_PROFILE_DESCRIPTOR_SCHEMA_VERSION, - PROFILE: HOOK_PROFILE_DESCRIPTOR_PROFILE_V4, + PROFILE: HOOK_PROFILE_DESCRIPTOR_PROFILE_V5, HOOK_ABI_VERSION: BLOCK_SITES_HOOK_ABI_VERSION, - FORMAT_VERSION: STRUCTURED_HOOK_FORMAT_V4_VERSION, + FORMAT_VERSION: STRUCTURED_HOOK_FORMAT_V5_VERSION, LAYER_COUNT: model.layerCount, HIDDEN_SIZE: model.hiddenSize, MAX_AFFINE_GROUPS: profile.maxAffineGroups, @@ -563,7 +567,7 @@ export function hookProfileDescriptorMismatches( return mismatches; } -/** Which v4 profile a schema-4 descriptor claims (`UNIT_SITES` decides), before the full check. */ +/** Which v5 profile a schema-4 descriptor claims (`UNIT_SITES` decides), before the full check. */ export function hookProfileDescriptorProfileId(values: ArrayLike): BlockSitesProfileId { const at = (name: HookProfileDescriptorField): number => values[HOOK_PROFILE_DESCRIPTOR_V4_FIELDS.indexOf(name)]; @@ -571,12 +575,12 @@ export function hookProfileDescriptorProfileId(values: ArrayLike): Block values.length !== HOOK_PROFILE_DESCRIPTOR_V4_LENGTH || at("MAGIC") !== HOOK_PROFILE_DESCRIPTOR_MAGIC || at("SCHEMA_VERSION") !== HOOK_PROFILE_DESCRIPTOR_SCHEMA_VERSION || - at("PROFILE") !== HOOK_PROFILE_DESCRIPTOR_PROFILE_V4 || + at("PROFILE") !== HOOK_PROFILE_DESCRIPTOR_PROFILE_V5 || (at("UNIT_SITES") !== 0 && at("UNIT_SITES") !== 1) ) { throw new TypeError("The model library's hook profile descriptor is not schema 4"); } - return at("UNIT_SITES") === 1 ? "standard-v4" : "standard-v4-residual"; + return at("UNIT_SITES") === 1 ? "standard-v5" : "standard-v5-residual"; } export function structuredCurveParameterStride( diff --git a/webui/src/hosted/runtime/structuredHookProgram.ts b/webui/src/hosted/runtime/structuredHookProgram.ts index 1e0fe7e..5524b1d 100644 --- a/webui/src/hosted/runtime/structuredHookProgram.ts +++ b/webui/src/hosted/runtime/structuredHookProgram.ts @@ -11,14 +11,14 @@ import { type StructuredHookCapacityProfile, } from "./structuredHookProfile"; -/** The one program format hook ABI `block-sites-v5` runs: the affine, curve, probe and geometry +/** The one program format hook ABI `block-sites-v6` runs: the affine, curve, probe and geometry * buffers, plus the optional unit section (B1 §3.1, §3.4). */ -export const STRUCTURED_HOOK_FORMAT = "drowse-structured-v4" as const; +export const STRUCTURED_HOOK_FORMAT = "drowse-structured-v5" as const; export type StructuredHookFormat = typeof STRUCTURED_HOOK_FORMAT; export type StructuredHookAbi = typeof BLOCK_SITES_HOOK_ABI; -/** The hook ABI and format of a program compiled under `profile` (`standard-v4` or - * `standard-v4-residual`, the only profiles that resolve). */ +/** The hook ABI and format of a program compiled under `profile` (`standard-v5` or + * `standard-v5-residual`, the only profiles that resolve). */ export function structuredHookIdentity( profile: StructuredHookCapacityProfile, ): { hookAbi: StructuredHookAbi; format: StructuredHookFormat } { @@ -35,7 +35,12 @@ export type StructuredProbeKind = export interface StructuredAffineGroup { active: boolean; + /** Write rows: the group writes its reduced displacement along these. */ basis: readonly ArrayLike[]; + /** Read rows, dual to `basis` (`read · basisᵀ = I`): the group reads coordinates with these. A + * typed (Mahalanobis-orthonormal) frame reads with `Σ⁻¹` of each row; a Euclidean one with + * the rows themselves. */ + read: readonly ArrayLike[]; neutral: ArrayLike; target: ArrayLike; along: number; @@ -52,7 +57,10 @@ export interface StructuredProbe { export interface StructuredCurve { active: boolean; domainKind?: "box" | "custom" | "sphere"; + /** Write rows (see `StructuredAffineGroup.basis`). */ basis: readonly ArrayLike[]; + /** Read rows, dual to `basis`. */ + read: readonly ArrayLike[]; neutral: ArrayLike; nodeParameters: readonly ArrayLike[]; rbfWeights: readonly ArrayLike[]; @@ -148,7 +156,7 @@ export interface StructuredMeasurementSchema { lensReadout?: boolean; saeReadout?: boolean; saeFeatureMetadata?: Record; - /** drowse-structured-v4: one entry per unit tap slot (`maxUnitTaps`), null when unused. */ + /** drowse-structured-v5: one entry per unit tap slot (`maxUnitTaps`), null when unused. */ unitTaps?: Array; /** The attached `slens/` probes, which the host reads post-forward over the `[L, d]` capture * (`hiddenCapture`, HOOK_ABI §5); a gate reads one by name. */ @@ -173,6 +181,7 @@ export interface StructuredHookProgramBuffers { layerCount: number; affineActive: Uint32Array; affineBasis: Float32Array; + affineRead: Float32Array; affineNeutral: Float32Array; affineTarget: Float32Array; affineAlong: Float32Array; @@ -187,6 +196,7 @@ export interface StructuredHookProgramBuffers { curveEmbedDim: Uint32Array; curveNodeCount: Uint32Array; curveBasis: Float32Array; + curveRead: Float32Array; curveNeutral: Float32Array; curveNodeParameters: Float32Array; curveRbfWeights: Float32Array; @@ -236,7 +246,7 @@ export interface StructuredHookProgramBuffers { /** The bridge keeps each forward's `[L, d]` capture and returns it with the measurement * bundle (`hidden`): set exactly when the schema lists `slensProbes`. */ hiddenCapture?: boolean; - /** drowse-structured-v4 unit section (B1 §3.1, §3.4), present together or not at all: a v4 + /** drowse-structured-v5 unit section (B1 §3.1, §3.4), present together or not at all: a v4 * program without it is v3's buffers exactly and runs the v4-identical structured or curved * functions; with it, the units pair (`drowse_units_batch_{prefill,decode}`). */ unitShape?: StructuredUnitShape; @@ -274,7 +284,7 @@ export interface StructuredHookControl { export interface StructuredHookControls { affine: readonly (StructuredHookControl | null)[]; curve: readonly (StructuredHookControl | null)[]; - /** drowse-structured-v4: one per unit trigger group (length `maxUnitGroups`). */ + /** drowse-structured-v5: one per unit trigger group (length `maxUnitGroups`). */ units?: readonly (StructuredHookControl | null)[]; } @@ -313,9 +323,11 @@ export function additiveDirectionGroup( const values = copyFiniteVector(direction, direction.length, "additive direction"); const norm = vectorNorm(values); if (!(norm > 1e-9)) throw new TypeError("Additive direction must be nonzero"); + const unit = Float32Array.from(values, (value) => value / norm); return { active, - basis: [Float32Array.from(values, (value) => value / norm)], + basis: [unit], + read: [unit], neutral: new Float32Array(values.length), target: [norm], along: finiteFloat(coefficient, "additive coefficient"), @@ -423,6 +435,7 @@ export function compileStructuredHookProgram( layerCount, affineActive: new Uint32Array(affineSlots), affineBasis: new Float32Array(checkedStructuredHookProduct("affine basis", affineAxes, hiddenSize)), + affineRead: new Float32Array(checkedStructuredHookProduct("affine read", affineAxes, hiddenSize)), affineNeutral: new Float32Array(checkedStructuredHookProduct("affine neutral", affineSlots, hiddenSize)), affineTarget: new Float32Array(affineAxes), affineAlong: new Float32Array(affineSlots), @@ -437,6 +450,7 @@ export function compileStructuredHookProgram( curveEmbedDim: new Uint32Array(curveSlots), curveNodeCount: new Uint32Array(curveSlots), curveBasis: new Float32Array(checkedStructuredHookProduct("curve basis", curveAxes, hiddenSize)), + curveRead: new Float32Array(checkedStructuredHookProduct("curve read", curveAxes, hiddenSize)), curveNeutral: new Float32Array(checkedStructuredHookProduct("curve neutral", curveSlots, hiddenSize)), curveNodeParameters: new Float32Array(checkedStructuredHookProduct("curve node parameters", curveNodes, profile.maxEmbedDim)), curveRbfWeights: new Float32Array(checkedStructuredHookProduct("curve RBF weights", curveNodes, profile.maxRank)), @@ -774,6 +788,7 @@ export function validateStructuredHookProgram(program: StructuredHookProgramBuff const expected: Array<[ArrayLike, number, string]> = [ [program.affineActive, size("affine active", l, g), "affine active"], [program.affineBasis, size("affine basis", l, g, r, d), "affine basis"], + [program.affineRead, size("affine read", l, g, r, d), "affine read"], [program.affineNeutral, size("affine neutral", l, g, d), "affine neutral"], [program.affineTarget, size("affine target", l, g, r), "affine target"], [program.affineAlong, size("affine along", l, g), "affine along"], @@ -788,6 +803,7 @@ export function validateStructuredHookProgram(program: StructuredHookProgramBuff [program.curveEmbedDim, curveSlots, "curve embedding dimension"], [program.curveNodeCount, curveSlots, "curve node count"], [program.curveBasis, size("curve basis", curveSlots, r, d), "curve basis"], + [program.curveRead, size("curve read", curveSlots, r, d), "curve read"], [program.curveNeutral, size("curve neutral", curveSlots, d), "curve neutral"], [program.curveNodeParameters, size("curve node parameters", curveSlots, n, m), "curve node parameters"], [program.curveRbfWeights, size("curve RBF weights", curveSlots, n, r), "curve RBF weights"], @@ -1267,7 +1283,7 @@ function compileLayer( geometryProbes.length > 0 ) { if (program.format !== STRUCTURED_HOOK_FORMAT) { - throw new TypeError("Geometry probes require a drowse-structured-v4 program"); + throw new TypeError("Geometry probes require a drowse-structured-v5 program"); } if (input.geometryWhitener === undefined || input.geometryWhitener === null) { throw new TypeError("Geometry probes require one exact layer whitener"); @@ -1677,8 +1693,8 @@ function compileAffineGroup( if (rank === 0 || rank > program.profile.maxRank) { throw new TypeError(`Affine group rank must be between 1 and ${program.profile.maxRank}`); } - if (input.target.length !== rank || input.kappa.length !== rank) { - throw new TypeError("Affine target and kappa must match the group rank"); + if (input.target.length !== rank || input.kappa.length !== rank || input.read.length !== rank) { + throw new TypeError("Affine read, target and kappa must match the group rank"); } const slot = layer * program.profile.maxAffineGroups + group; program.affineActive[slot] = input.active ? 1 : 0; @@ -1687,22 +1703,18 @@ function compileAffineGroup( for (let axis = 0; axis < rank; axis += 1) { const axisSlot = slot * program.profile.maxRank + axis; copyVector(input.basis[axis], program.affineBasis, axisSlot * program.hiddenSize, program.hiddenSize, "affine basis"); - requireUnitVector(program.affineBasis, axisSlot * program.hiddenSize, program.hiddenSize, "affine basis"); + copyVector(input.read[axis], program.affineRead, axisSlot * program.hiddenSize, program.hiddenSize, "affine read"); program.affineTarget[axisSlot] = finiteFloat(input.target[axis], "affine target"); program.affineKappa[axisSlot] = finiteFloat(input.kappa[axis], "affine kappa"); - for (let previous = 0; previous < axis; previous += 1) { - const previousSlot = slot * program.profile.maxRank + previous; - const overlap = dotProductSlices( - program.affineBasis, - previousSlot * program.hiddenSize, - axisSlot * program.hiddenSize, - program.hiddenSize, - ); - if (Math.abs(overlap) > 1e-4) { - throw new TypeError("Affine group basis rows must be orthonormal"); - } - } } + requireDualFrame( + program.affineBasis, + program.affineRead, + slot * program.profile.maxRank * program.hiddenSize, + rank, + program.hiddenSize, + "Affine group", + ); } function compileProbe( @@ -1737,6 +1749,7 @@ function compileCurve( input: StructuredCurve, ): void { const rank = input.basis.length; + if (input.read.length !== rank) throw new TypeError("Curve read rows must match the curve rank"); const nodes = input.nodeParameters.length; const intrinsicDim = input.axes.length; const sourceEmbedDim = input.coordinateOffset.length; @@ -1789,19 +1802,16 @@ function compileCurve( for (let axis = 0; axis < rank; axis += 1) { const axisOffset = (slot * program.profile.maxRank + axis) * program.hiddenSize; copyVector(input.basis[axis], program.curveBasis, axisOffset, program.hiddenSize, "curve basis"); - requireUnitVector(program.curveBasis, axisOffset, program.hiddenSize, "curve basis"); - for (let previous = 0; previous < axis; previous += 1) { - const previousOffset = (slot * program.profile.maxRank + previous) * program.hiddenSize; - if (Math.abs(dotProductSlices( - program.curveBasis, - previousOffset, - axisOffset, - program.hiddenSize, - )) > 1e-4) { - throw new TypeError("Curve basis rows must be orthonormal"); - } - } + copyVector(input.read[axis], program.curveRead, axisOffset, program.hiddenSize, "curve read"); } + requireDualFrame( + program.curveBasis, + program.curveRead, + slot * program.profile.maxRank * program.hiddenSize, + rank, + program.hiddenSize, + "Curve", + ); for (let node = 0; node < nodes; node += 1) { if (input.rbfWeights[node].length !== rank) throw new TypeError("Curve RBF weight rank is inconsistent"); for (let axis = 0; axis < rank; axis += 1) { @@ -1908,7 +1918,7 @@ function runAffineGroups( let coordinate = 0; for (let hidden = 0; hidden < d; hidden += 1) { coordinate = Math.fround(coordinate + Math.fround( - Math.fround(values[hidden] - program.affineNeutral[slot * d + hidden]) * program.affineBasis[vector + hidden], + Math.fround(values[hidden] - program.affineNeutral[slot * d + hidden]) * program.affineRead[vector + hidden], )); } deltas[axis] = Math.fround(program.affineAlong[slot] * Math.fround( @@ -2380,7 +2390,7 @@ function runCurve( for (let axis = 0; axis < rank; axis += 1) { for (let hidden = 0; hidden < d; hidden += 1) { q[axis] = Math.fround(q[axis] + Math.fround( - centered[hidden] * program.curveBasis[(slot * program.profile.maxRank + axis) * d + hidden], + centered[hidden] * program.curveRead[(slot * program.profile.maxRank + axis) * d + hidden], )); } } @@ -2927,18 +2937,6 @@ function dotProduct(left: ArrayLike, right: ArrayLike): number { return value; } -function dotProductSlices( - values: Float32Array, - leftOffset: number, - rightOffset: number, - size: number, -): number { - let result = 0; - for (let index = 0; index < size; index += 1) { - result += values[leftOffset + index] * values[rightOffset + index]; - } - return result; -} function vectorNorm(values: ArrayLike): number { return Math.sqrt(dotProduct(values, values)); @@ -2964,22 +2962,36 @@ function finiteFloat(value: number, label: string, allowInfinity = false): numbe return narrowed; } -function requireUnitVector( - values: Float32Array, +/** Native's synthesized-frame invariant (`read @ basisᵀ = I`, atol and rtol 1e-3): the read rows + * recover the coordinates the write rows write. */ +function requireDualFrame( + basis: Float32Array, + read: Float32Array, offset: number, + rank: number, size: number, label: string, ): void { - let squaredNorm = 0; - for (let index = 0; index < size; index += 1) squaredNorm += values[offset + index] ** 2; - if (Math.abs(squaredNorm - 1) > 1e-4) throw new TypeError(`${label} must be unit length`); + for (let row = 0; row < rank; row += 1) { + for (let column = 0; column < rank; column += 1) { + let value = 0; + for (let index = 0; index < size; index += 1) { + value += read[offset + row * size + index] * basis[offset + column * size + index]; + } + const expected = row === column ? 1 : 0; + if (!(Math.abs(value - expected) <= 1e-3 + 1e-3 * expected)) { + throw new TypeError(`${label} read rows must be dual to its basis rows`); + } + } + } } + function clamp(value: number, minimum: number, maximum: number): number { return Math.min(maximum, Math.max(minimum, value)); } -// ------------------------------------------------- drowse-structured-v4 units --- +// ------------------------------------------------- drowse-structured-v5 units --- // B1-hook-abi-v5.md §2.2 (the live unit tap), §3.1 (mean-ablation and the table layout) and // §3.4 (the host program). browser-runtime/HOOK_ABI.md is the contract. @@ -3443,7 +3455,7 @@ export function assertStructuredTapGramsBound( }); } -/** Native's unit tables (`UnitOp` per module and trigger), as the B3 goldens record them: +/** Native's unit tables (`UnitOp` per module and trigger): * coordinate entries of a site of width `width`, one keep and bias per coordinate. */ export interface StructuredNativeUnitTable { readonly layer: number; diff --git a/webui/src/hosted/runtime/units/anatomy.ts b/webui/src/hosted/runtime/units/anatomy.ts index 3cf7a61..a6ecdca 100644 --- a/webui/src/hosted/runtime/units/anatomy.ts +++ b/webui/src/hosted/runtime/units/anatomy.ts @@ -250,7 +250,7 @@ export async function tokenAnatomy( } /** The pattern pass: one replay capturing keys at the chosen heads' layers, then their attention - * rows. The profile's `maxPatternLayers` (16 under standard-v4, attested by the descriptor) + * rows. The profile's `maxPatternLayers` (16 under standard-v5, attested by the descriptor) * holds native's bound of 16 patterns in one pass; a residual library captures none. */ async function patternRows( backend: BrowserBlockSitesBackend, diff --git a/webui/src/hosted/runtime/units/cpuBackend.ts b/webui/src/hosted/runtime/units/cpuBackend.ts index 57c4ddf..c5a0eee 100644 --- a/webui/src/hosted/runtime/units/cpuBackend.ts +++ b/webui/src/hosted/runtime/units/cpuBackend.ts @@ -1,7 +1,7 @@ -// The CPU fp32 reference of hook ABI v5's device surface (`BrowserBlockSitesBackend`, B1 §2-§6) +// The CPU fp32 reference of hook ABI v6's device surface (`BrowserBlockSitesBackend`, B1 §2-§6) // over dense weights: plain loops, B1 §4.1's formulas. Test-only. It lets the host ports run -// end to end against drowse's goldens without a GPU, and is the reference B4's kernels answer -// to. Nothing in the hosted app imports it. +// end to end without a GPU (the fixture runtime), and is the reference B4's kernels answer to. +// Nothing in the hosted app imports it. import { activityStateLayout, anatomyTapLayout, @@ -91,7 +91,7 @@ const sum = (n: number, f: (i: number) => number): number => { return s; }; -/** The CPU reference backend over `model` under a `standard-v4` (or residual) profile. */ +/** The CPU reference backend over `model` under a `standard-v5` (or residual) profile. */ export function cpuBlockSitesBackend( model: DenseModelWeights, options: CpuBlockSitesOptions, diff --git a/webui/src/hosted/runtime/units/fixtureUnits.ts b/webui/src/hosted/runtime/units/fixtureUnits.ts index 2c661bc..15b819d 100644 --- a/webui/src/hosted/runtime/units/fixtureUnits.ts +++ b/webui/src/hosted/runtime/units/fixtureUnits.ts @@ -4,7 +4,7 @@ // byte vocabulary, an identity whitener and no null basis). Answers are drowse-shaped and // deterministic, not a model's: they let the Units room, token anatomy and the S lens render. import type { LoomTreeJSON } from "../../../../../drowse/webui/src/lib/types"; -import { STANDARD_STRUCTURED_HOOK_PROFILE_V4, STANDARD_STRUCTURED_HOOK_PROFILE_V4_RESIDUAL } from "../structuredHookProfile"; +import { STANDARD_STRUCTURED_HOOK_PROFILE_V5, STANDARD_STRUCTURED_HOOK_PROFILE_V5_RESIDUAL } from "../structuredHookProfile"; import { cpuBlockSitesBackend } from "./cpuBackend"; import { DenseSequence, finalLogits, rmsScale, type DenseModelWeights } from "./denseModel"; import { embeddingStatistics } from "./referenceContext"; @@ -26,7 +26,7 @@ let loaded: Promise | null = null; function fixtureUnits(): Promise { loaded ??= (async () => { - const file = (await import("../../../../../drowse/tests/fixtures/browser/units-tiny-models-v1.json")).default as unknown as TinyModelFile & { + const file = (await import("../fixtures/units-tiny-models-v1.json")).default as unknown as TinyModelFile & { neutral: { statements: string[] }; }; const record = file.arches[ARCH]; @@ -279,7 +279,7 @@ function fixtureReplay(tree: () => LoomTreeJSON, tokenizer: TinyTokenizer): Unit } /** The fixture's units members over `tree` (the fake runtime's loom). With `unitRefusal` the - * library is a residual one (`standard-v4-residual`): every member answers that refusal. */ + * library is a residual one (`standard-v5-residual`): every member answers that refusal. */ export function createFixtureUnitsService(modelId: string, tree: () => LoomTreeJSON, unitRefusal: string | null = null): { request(method: string, args: readonly unknown[]): Promise; } { @@ -287,8 +287,8 @@ export function createFixtureUnitsService(modelId: string, tree: () => LoomTreeJ const open = () => { service ??= fixtureUnits().then(({ model, tokenizer, packs }) => { const backend = cpuBlockSitesBackend(model, unitRefusal === null - ? { profile: STANDARD_STRUCTURED_HOOK_PROFILE_V4, contextTokens: 2 * MAX_ROWS + 2 } - : { profile: STANDARD_STRUCTURED_HOOK_PROFILE_V4_RESIDUAL, contextTokens: 2 * MAX_ROWS + 2, unitRefusal }); + ? { profile: STANDARD_STRUCTURED_HOOK_PROFILE_V5, contextTokens: 2 * MAX_ROWS + 2 } + : { profile: STANDARD_STRUCTURED_HOOK_PROFILE_V5_RESIDUAL, contextTokens: 2 * MAX_ROWS + 2, unitRefusal }); const replay = fixtureReplay(tree, tokenizer); return new BrowserUnitsService({ modelId, diff --git a/webui/src/hosted/runtime/units/lensReads.ts b/webui/src/hosted/runtime/units/lensReads.ts index 2a07053..f7247bb 100644 --- a/webui/src/hosted/runtime/units/lensReads.ts +++ b/webui/src/hosted/runtime/units/lensReads.ts @@ -51,8 +51,7 @@ export function sWeights(layers: readonly number[], nLayers: number, band: LensB return total > 0 ? raw.map((w) => w / total) : raw.map(() => 0); } -/** Python's `round(x, 6)` for record fields (half-even on the decimal; the goldens compare - * rounded fields within 2e-6, never by string). */ +/** Python's `round(x, 6)` for record fields, to within 2e-6 (never compared by string). */ export function round6(x: number): number { return Math.round(x * 1e6) / 1e6; } diff --git a/webui/src/hosted/runtime/units/tinyModels.ts b/webui/src/hosted/runtime/units/tinyModels.ts index e37fac1..c160842 100644 --- a/webui/src/hosted/runtime/units/tinyModels.ts +++ b/webui/src/hosted/runtime/units/tinyModels.ts @@ -1,7 +1,8 @@ -// The units-tiny-models-v1 fixture models (drowse `tests/support/browser_units.py`, B1-goldens -// §1): the portable generator, bit for bit in 32-bit integer arithmetic, the byte-level -// tokenizer and the hand-built lenses. Test-only: the CPU reference backend and the fixture -// runtimes build their weights from the model file's integers; nothing here reaches the GPU. +// The units-tiny-models-v1 fixture models (`../fixtures/units-tiny-models-v1.json`, from +// drowse's former browser-units generator): the portable generator, bit for bit in 32-bit +// integer arithmetic, the byte-level tokenizer and the hand-built lenses. Test-only: the CPU +// reference backend and the fixture runtimes build their weights from the model file's integers; +// nothing here reaches the GPU. import type { BlockSpec } from "../structuredHookProfile"; import type { DenseBlockWeights, DenseModelWeights } from "./denseModel"; diff --git a/webui/src/hosted/runtime/units/unitReader.ts b/webui/src/hosted/runtime/units/unitReader.ts index e487fab..7d7a38e 100644 --- a/webui/src/hosted/runtime/units/unitReader.ts +++ b/webui/src/hosted/runtime/units/unitReader.ts @@ -77,8 +77,7 @@ export class UnitWhitenerError extends Error { /** One layer's offline artifacts, keyed as native `UnitReader.population_artifacts` keys them. */ export type UnitLayerArtifacts = ReadonlyMap; -/** What the reader needs besides the device: B6's units and core packs (or, in tests, drowse's - * unit-stats / unit-artifacts goldens and the fixture whitener). */ +/** What the reader needs besides the device: B6's units and core packs. */ export interface UnitsArtifacts { readonly statistics: UnitStatistics | null; /** Why `statistics` is null (native `UnitsUnavailableError`'s text). */ @@ -1071,6 +1070,10 @@ export class UnitReader { let coeffs: Float64Array = new Float64Array(0); let residual = Float32Array.from(t); for (let step = 0; step < k; step += 1) { + // Selection stops once the residual is negligible (an exact atom target). + let residualNormSq = 0; + for (const x of residual) residualNormSq += x * x; + if (residualNormSq <= 1e-12 * tNormSq) break; // (W w_n)·r = w_n·(W r): W is symmetric. const wr = whitenRows(whitener, residual, 1); const raw = (await this.context.backend.layerWriteScores(f32Tensor(wr, [1, 1, d]), Int32Array.of(layer))).data; @@ -1088,15 +1091,20 @@ export class UnitReader { selected.push(best); const write = (await this.context.backend.unitWeightRows("neuron_write", [{ kind: "neuron", layer, index: best }])).data; atoms.push(whitenRows(whitener, write, 1)); + // The k×k normal equations in fp64 with a ridge relative to the Gram's scale (native + // `_solve_tiny`): nearly collinear atoms mis-fit in fp32. const s = atoms.length; const gram = new Float64Array(s * s); const b = new Float64Array(s); for (let i = 0; i < s; i += 1) { - for (let j = 0; j < s; j += 1) gram[i * s + j] = Math.fround(dot(atoms[i], atoms[j])); - gram[i * s + i] += 1e-7; - b[i] = Math.fround(dot(atoms[i], t)); + for (let j = 0; j < s; j += 1) gram[i * s + j] = dot(atoms[i], atoms[j]); + b[i] = dot(atoms[i], t); } - coeffs = solve(gram, b, s); + let diagonal = 0; + for (let i = 0; i < s; i += 1) diagonal = Math.max(diagonal, Math.abs(gram[i * s + i])); + const ridge = 1e-12 * Math.max(diagonal, 1e-30); + for (let i = 0; i < s; i += 1) gram[i * s + i] += ridge; + coeffs = Float64Array.from(solve(gram, b, s), Math.fround); residual = Float32Array.from(t); for (let i = 0; i < s; i += 1) for (let j = 0; j < d; j += 1) residual[j] -= coeffs[i] * atoms[i][j]; } diff --git a/webui/src/hosted/runtime/units/unitsService.ts b/webui/src/hosted/runtime/units/unitsService.ts index c527d2e..05a3680 100644 --- a/webui/src/hosted/runtime/units/unitsService.ts +++ b/webui/src/hosted/runtime/units/unitsService.ts @@ -217,7 +217,7 @@ export class BrowserUnitsService { const backend = this.options.blockSites(); const capabilities = backend.capabilities(); if (capabilities === null) { - throw new UnsupportedBlockError("the loaded model library predates hook ABI block-sites-v5"); + throw new UnsupportedBlockError("the loaded model library predates hook ABI block-sites-v6"); } if (capabilities.blockSpec === null) throw new UnsupportedBlockError(capabilities.unitRefusal!); return { backend, spec: capabilities.blockSpec }; @@ -349,7 +349,7 @@ export class BrowserUnitsService { if (capabilities === null || capabilities.blockSpec === null) { return { spec: null, - refusal: capabilities?.unitRefusal ?? "the loaded model library predates hook ABI block-sites-v5", + refusal: capabilities?.unitRefusal ?? "the loaded model library predates hook ABI block-sites-v6", layerCount: capabilities?.layerCount ?? 0, statistics: null, scales: null, diff --git a/webui/src/hosted/runtime/webLlmBlockSites.ts b/webui/src/hosted/runtime/webLlmBlockSites.ts index cccc05d..7b68c92 100644 --- a/webui/src/hosted/runtime/webLlmBlockSites.ts +++ b/webui/src/hosted/runtime/webLlmBlockSites.ts @@ -1,4 +1,4 @@ -// Hook ABI v5's device surface over the WebLLM bridge (B1 §2-§4, browser-runtime/HOOK_ABI.md +// Hook ABI v6's device surface over the WebLLM bridge (B1 §2-§4, browser-runtime/HOOK_ABI.md // §7-§9): the units programs, the residents (head grams, unit scales, lens layers, embedding // statistics, pattern captures), the replay, the attention rows and the static reads // (`webLlmStaticReads.ts`). The bridge takes one request per call (`drowseBlockSites`), so the @@ -60,7 +60,7 @@ interface BridgeReplayCaptures { /** The loaded model's bridge, as the adapter drives it. */ export interface WebLlmBlockSitesDevice { call(request: WebLlmBlockSitesRequest): Promise; - /** Install a drowse-structured-v4 program with a unit section (the replay's steering). */ + /** Install a drowse-structured-v5 program with a unit section (the replay's steering). */ installProgram(program: StructuredHookProgramBuffers): Promise; } @@ -70,7 +70,7 @@ export const BLOCK_SITES_MEMBER_UNAVAILABLE = "BLOCK_SITES_MEMBER_UNAVAILABLE"; export function blockSitesMemberUnavailable(member: string): Error { return Object.assign( - new Error(`The browser runtime does not provide ${member} for hook ABI block-sites-v5 yet`), + new Error(`The browser runtime does not provide ${member} for hook ABI block-sites-v6 yet`), { code: BLOCK_SITES_MEMBER_UNAVAILABLE }, ); } @@ -91,9 +91,9 @@ function throwIfAborted(signal: AbortSignal | undefined): void { if (signal?.aborted) throw signal.reason ?? new DOMException("Aborted", "AbortError"); } -/** The WebLLM bridge's hook ABI v5 surface (B1 §2.2-§2.3, §3.4, §3.5, §6). A residual library +/** The WebLLM bridge's hook ABI v6 surface (B1 §2.2-§2.3, §3.4, §3.5, §6). A residual library * answers every unit member with its lock refusal (422, as native); a units library binds - * drowse-structured-v4 programs, replays nodes and keeps the residents the reads need. */ + * drowse-structured-v5 programs, replays nodes and keeps the residents the reads need. */ export function webLlmBlockSitesBackend( capabilities: BlockSitesCapabilities, device: WebLlmBlockSitesDevice | null = null, diff --git a/webui/src/hosted/runtime/webLlmEngine.ts b/webui/src/hosted/runtime/webLlmEngine.ts index 28f008c..aca2213 100644 --- a/webui/src/hosted/runtime/webLlmEngine.ts +++ b/webui/src/hosted/runtime/webLlmEngine.ts @@ -7,10 +7,7 @@ import type { BrowserModelLoadRequest, BrowserModelLoadResult, } from "./modelBackend"; -import type { - ModelVariantRequirements, - StructuredHookProfileId, -} from "../../../../drowse/webui/src/lib/runtime/contracts"; +import type { ModelVariantRequirements } from "../../../../drowse/webui/src/lib/runtime/contracts"; import { MAX_OUTPUT_TOKEN_COUNT, outputTokenLimitForRuntime, @@ -29,6 +26,7 @@ import { EXACT_READOUT_REQUIRED_WEBGPU_LIMITS, expectedHookProfileDescriptor, hookProfileDescriptorMismatches, + type BlockSitesProfileId, type BlockSpec, type HookProfileDescriptorModel, resolveStructuredHookProfile, @@ -101,7 +99,7 @@ interface DrowseSaeTopFeatureReadout { interface DrowseMeasurementBundle { scalar?: Float32Array; geometry?: Float32Array; - /** Hook ABI v5's live unit tap (`[maxUnitTaps]`), when the program has a unit section. */ + /** Hook ABI v6's live unit tap (`[maxUnitTaps]`), when the program has a unit section. */ unitTaps?: Float32Array; /** The forward's `[L, d]` capture, when the program asks for it (`hiddenCapture`). */ hidden?: Float32Array; @@ -141,9 +139,9 @@ export interface DrowseWebLlmEngineInstance extends WebLlmGenerationEngine { modelId?: string, unitActive?: Float32Array, ): Promise; - /** Hook ABI v5: the library compiles unit sites and the units pair (`standard-v4`). */ + /** Hook ABI v6: the library compiles unit sites and the units pair (`standard-v5`). */ supportsDrowseUnitSites?(modelId?: string): Promise; - /** Hook ABI v5's block-sites device surface (replay, residents, attention rows). */ + /** Hook ABI v6's block-sites device surface (replay, residents, attention rows). */ drowseBlockSites?(request: WebLlmBlockSitesRequest, modelId?: string): Promise; /** Remove the installed hook program (the model runs unsteered). */ clearDrowseProgram(modelId?: string): Promise; @@ -260,7 +258,7 @@ export interface DrowseWebLlmModule { export interface CompiledDrowseStructuredHookProfile { schemaVersion: 2 | 3 | 4; - id: StructuredHookProfileId; + id: BlockSitesProfileId; hookAbi: string; format: typeof STRUCTURED_HOOK_FORMAT; @@ -291,9 +289,9 @@ typeof STRUCTURED_HOOK_FORMAT; exactReadoutAbi?: typeof DROWSE_EXACT_READOUT_ABI | typeof BLOCK_SITES_EXACT_READOUT_ABI; readoutTopK?: typeof DROWSE_READOUT_TOP_K; maxSaeFeaturesPerChunk?: typeof DROWSE_EXACT_READOUT_MAX_SAE_FEATURES_PER_CHUNK; - /** Hook ABI v5 (schema 4): whether the library compiles unit sites. */ + /** Hook ABI v6 (schema 4): whether the library compiles unit sites. */ unitSites?: 0 | 1; - /** Hook ABI v5: the whole attested descriptor (C0's `HOOK_PROFILE_DESCRIPTOR_V4_FIELDS`). */ + /** Hook ABI v6: the whole attested descriptor (C0's `HOOK_PROFILE_DESCRIPTOR_V4_FIELDS`). */ descriptor?: Int32Array; } @@ -769,7 +767,7 @@ export class DrowseWebLlmRuntime { hookCapabilities(): DrowseHookCapabilities { this.requireEngine(); - // `units` and `slens` follow the library's v5 profile (a standard-v4 library has unit sites). + // `units` and `slens` follow the library's v5 profile (a standard-v5 library has unit sites). return blockSitesHookCapabilities({ ...AFFINE_FEASIBILITY_CAPABILITIES, curved_manifold: this.curvedHooks, @@ -832,7 +830,7 @@ export class DrowseWebLlmRuntime { await this.requireEngine().setDrowseStructuredProgram(program); } - /** Hook ABI v5's attested surface (B1 §3.5), or null when the library predates it. */ + /** Hook ABI v6's attested surface (B1 §3.5), or null when the library predates it. */ blockSitesCapabilities(): BlockSitesCapabilities | null { return this.blockSites; } @@ -1166,7 +1164,7 @@ export class DrowseWebLlmRuntime { /** The structured program's probe slots at each position (`[positions, L, maxProbes]`): the * program's last-row measurement of a fresh prefill of the row's tokens through that * position, so a probe reads the residual after the hook at every layer. The release - * tools' steered capture on hook ABI v5 (a block-sites library has no other steered read + * tools' steered capture on hook ABI v6 (a block-sites library has no other steered read * of a position on every profile). */ async measurePreparedPositions( row: DrowsePreparedCaptureRow, @@ -1469,7 +1467,7 @@ function lockedLibraryBindingBytes( } catch { throw runtimeError( "STRUCTURED_HOOK_PROFILE_MISMATCH", - `Hook ABI block-sites-v5 libraries attest standard-v4 or standard-v4-residual, not ${String(request.variant.structuredHookProfile)}`, + `Hook ABI block-sites-v6 libraries attest standard-v5 or standard-v5-residual, not ${String(request.variant.structuredHookProfile)}`, ); } const model = hookProfileDescriptorModel(request); @@ -1490,7 +1488,7 @@ function lockedLibraryBindingBytes( }); } -/** Hook ABI v5: the library's schema-4 descriptor, element by element, against the lock (B1 +/** Hook ABI v6: the library's schema-4 descriptor, element by element, against the lock (B1 * §3.5 attestation); every mismatch fails the load with `HOOK_ABI_MISMATCH`. */ function attestBlockSitesHookProfile( record: Record, @@ -1518,7 +1516,7 @@ function attestBlockSitesHookProfile( ) { throw runtimeError( "HOOK_ABI_MISMATCH", - "The loaded model library does not attest hook ABI block-sites-v5 under the lock's profile", + "The loaded model library does not attest hook ABI block-sites-v6 under the lock's profile", ); } const mismatches = hookProfileDescriptorMismatches(descriptor as number[], expectedDescriptor); @@ -1615,7 +1613,7 @@ export function attestCompiledStructuredHookProfile( } catch { throw runtimeError( "STRUCTURED_HOOK_PROFILE_MISMATCH", - `Hook ABI block-sites-v5 libraries attest standard-v4 or standard-v4-residual, not ${String(request.variant.structuredHookProfile)}`, + `Hook ABI block-sites-v6 libraries attest standard-v5 or standard-v5-residual, not ${String(request.variant.structuredHookProfile)}`, ); } return attestBlockSitesHookProfile(record, request, moduleHookAbi); @@ -1625,7 +1623,7 @@ function assertExactReadoutProfile( profile: CompiledDrowseStructuredHookProfile, ): void { const v5 = profile.schemaVersion === 4 && - (profile.id === "standard-v4" || profile.id === "standard-v4-residual") && + (profile.id === "standard-v5" || profile.id === "standard-v5-residual") && profile.exactReadoutAbiVersion === BLOCK_SITES_EXACT_READOUT_ABI_VERSION && profile.exactReadoutAbi === BLOCK_SITES_EXACT_READOUT_ABI; if ( @@ -1642,12 +1640,12 @@ function assertExactReadoutProfile( } function assertExactReadoutWebGpuRequirements( - structuredHookProfile: StructuredHookProfileId, + structuredHookProfile: string, requirements: ModelVariantRequirements, ): void { if ( - structuredHookProfile !== "standard-v4" && - structuredHookProfile !== "standard-v4-residual" + structuredHookProfile !== "standard-v5" && + structuredHookProfile !== "standard-v5-residual" ) return; for (const [name, minimum] of Object.entries( EXACT_READOUT_REQUIRED_WEBGPU_LIMITS, diff --git a/webui/src/hosted/runtime/webLlmStaticReads.ts b/webui/src/hosted/runtime/webLlmStaticReads.ts index 917b7e9..8b459ae 100644 --- a/webui/src/hosted/runtime/webLlmStaticReads.ts +++ b/webui/src/hosted/runtime/webLlmStaticReads.ts @@ -1,4 +1,4 @@ -// Hook ABI v5's static reads and exact-readout-v2 over the WebLLM bridge (B1 §4.1, +// Hook ABI v6's static reads and exact-readout-v2 over the WebLLM bridge (B1 §4.1, // browser-runtime/HOOK_ABI.md §8). Each member validates its arguments, sends one `read` request // (a short program of library calls over host tensors, residents and earlier outputs) and gets // its outputs back with one device sync, so a member costs one round trip as native's packed diff --git a/webui/src/hosted/runtime/worker.ts b/webui/src/hosted/runtime/worker.ts index 7a92b2f..c597aaa 100644 --- a/webui/src/hosted/runtime/worker.ts +++ b/webui/src/hosted/runtime/worker.ts @@ -751,7 +751,7 @@ export class HostedRuntimeWorker { this.contentStore.listLoadRecords(), this.contentStore.selectedModelVariantId(), ]); - const installedModelVariantIds = modelInstallIds(installs); + const installedModelVariantIds = modelInstallIds(installs, this.acceptedCatalog); const selectedModelVariantId = storedSelection !== null && installedModelVariantIds.includes(storedSelection) ? storedSelection @@ -972,7 +972,7 @@ export class HostedRuntimeWorker { const currentInstalls = await this.contentStore.listInstalls(); const installedPackIds = packInstallIds(currentInstalls, this.acceptedCatalog); this.patchSnapshot({ - installedModelVariantIds: modelInstallIds(currentInstalls), + installedModelVariantIds: modelInstallIds(currentInstalls, this.acceptedCatalog), installedPackIds, download: operationState(this.snapshot.download, "complete", null), }, requestId); @@ -1092,7 +1092,7 @@ export class HostedRuntimeWorker { } await this.ensureContentStore(); let installs = await this.contentStore.listInstalls(); - const installedModelIds = modelInstallIds(installs); + const installedModelIds = modelInstallIds(installs, this.acceptedCatalog); const modelInstall = installs.find((install) => install.id === modelVariantId && install.kind === "model" ); @@ -2382,10 +2382,16 @@ export class HostedRuntimeWorker { ); this.sessionCoordinator = sessionCoordinator; this.sessionIdentity = sessionIdentity; - const restore = await sessionCoordinator.restore( + let restore = await sessionCoordinator.restore( sessionIdentity, resetSession ? "reset" : "replace", ); + if (restore.status === "incompatible" && restore.reason === "runtime_identity") { + // A later catalog rebuilt this variant's runtime (a library or core). The working session it + // left is bound to the old one; the conversation itself lives in the saved-chat library, so + // the model opens on a fresh session instead of refusing. + restore = await sessionCoordinator.restore(sessionIdentity, "reset"); + } this.snapshot = { ...this.snapshot, modelDefaults: sessionCoordinator.modelDefaults }; if (restore.status === "incompatible") { throw runtimeFailure( @@ -2782,7 +2788,7 @@ export class HostedRuntimeWorker { this.contentStore.listLoadRecords(), this.contentStore.selectedModelVariantId(), ]); - const installedModelVariantIds = modelInstallIds(installs); + const installedModelVariantIds = modelInstallIds(installs, this.acceptedCatalog); const selectedModelVariantId = storedSelection !== null && installedModelVariantIds.includes(storedSelection) ? storedSelection @@ -3334,15 +3340,39 @@ function operationState( }; } +/** The model installs the accepted catalog still describes. A later catalog that rebuilds a + * variant's library or core (a hook ABI bump does both) leaves the old install stale: it is not + * listed, so the shell downloads the variant again (stored objects are reused) rather than adding + * packs bound to the new runtime onto it. Without a catalog, or for a variant the catalog no + * longer lists, the install stands, as a pack's does. */ function modelInstallIds( installs: import("./contentStore").InstalledContentRecord[], + catalog: VerifiedCatalog | null, ): string[] { return installs - .filter((install) => install.kind === "model") + .filter((install) => install.kind === "model" && modelInstallCurrent(install, catalog)) .map((install) => install.id) .sort(); } +function modelInstallCurrent( + install: import("./contentStore").InstalledContentRecord, + catalog: VerifiedCatalog | null, +): boolean { + if (catalog === null) return true; + const listed = catalog.document.models.some((model) => + model.variants.some((variant) => variant.id === install.id) + ); + if (!listed) return true; + let files: readonly { sha256: string }[]; + try { + files = selectDownloadManifest(catalog, install.id, { requireDownloadAuthorization: false }).files; + } catch { + return true; // a malformed variant refuses its download with its own error + } + return sameObjectHashes(install.objectHashes, files.map((file) => file.sha256)); +} + function packInstallIds( installs: import("./contentStore").InstalledContentRecord[], catalog: VerifiedCatalog | null, diff --git a/webui/src/lib/runtime/catalog.ts b/webui/src/lib/runtime/catalog.ts index 01f91d4..92f713e 100644 --- a/webui/src/lib/runtime/catalog.ts +++ b/webui/src/lib/runtime/catalog.ts @@ -16,6 +16,7 @@ import { blockSitesBindingBytes } from "../../hosted/runtime/modelBackend"; import { EXACT_READOUT_REQUIRED_WEBGPU_LIMITS, resolveStructuredHookProfile, + sharedProfileId, structuredHookMemoryRequirements, WEB_LLM_RUNTIME_MIN_STORAGE_BUFFERS_PER_SHADER_STAGE, type BlockSpec, @@ -71,9 +72,9 @@ export interface CatalogRuntimeLockModel { contextProfiles: readonly number[]; /** The library's compiled prefill chunk, which its descriptor attests (HOOK_ABI.md §6). */ prefillChunkSize: number; - /** The block spec a `standard-v4` library's descriptor is attested against (B1 §8.2). */ + /** The block spec a `standard-v5` library's descriptor is attested against (B1 §8.2). */ blockSpec: BlockSpec | null; - /** What a `standard-v4-residual` library's unit members answer (native's 422 text). */ + /** What a `standard-v5-residual` library's unit members answer (native's 422 text). */ unitRefusal: string | null; } @@ -488,8 +489,8 @@ function validateVariant(value: unknown, index: number): ModelVariant { if (item.tier !== "fastest" && item.tier !== "balanced" && item.tier !== "quality") { throw invalid(`${path}.tier is invalid`); } - // This runtime loads hook ABI block-sites-v5 libraries only: standard-v4 (unit sites) or - // standard-v4-residual. + // This runtime loads hook ABI block-sites-v6 libraries only: standard-v5 (unit sites) or + // standard-v5-residual. let structuredHookProfile; try { structuredHookProfile = resolveStructuredHookProfile(item.structuredHookProfile); @@ -737,7 +738,7 @@ function validateVariant(value: unknown, index: number): ModelVariant { return { id: item.id as string, tier: item.tier, - structuredHookProfile: structuredHookProfile.id, + structuredHookProfile: sharedProfileId(structuredHookProfile.id), thinkingProfile, contextProfiles, downloadBytes: item.downloadBytes as number,