[ABI][LD][Proofs][Docs] M1 groundwork: arena-safety proof + .vbundle contract; embedder lane (M1.5) accepted

- proofs/arena_plan.lean: memory.vplan arena safety (8 theorems + 4
  computational examples, 0 sorryAx): no overlap, checked index bounds,
  no use-before-write, overlap-rejection completeness.
- abi::arena: validator mirroring the proof, checked offset arithmetic
  (invariant #2), explicit error per violation class; 8 tests.
- abi::bundle: .vbundle manifest (ABI_VERSION=1, source+packer fingerprints,
  backend target; incompatible ABI rejected explicitly), checked
  memory.vplan/graph.vplan parsing, arena-validated compile(); 7 tests.
- ld::bundle: read-only load_bundle_plans(dir) over manifest + plan/*.vplan;
  3 tests (good bundle, missing file, ABI mismatch).
- abi::vplan: encoder-lane opcodes (layer_norm, flash_full_attn, gelu_erf,
  mean_pool_l2norm) + wire name mapping for all 22 opcodes, roundtrip test.
- Docs: utility-encoder scope carve-out (dense decoder LMs out, small
  fully-resident encoders in), embedder-lane wire proposal + characteristic
  parity vs vetta-semantics (cosine vs oracle, internal bit-exact goldens),
  16-primitive kernel set, M1.5 milestone; README/AGENTS aligned
  (65 tests, 42 theorems across 4 proof files).
- review/: tandem exchange with the strata-ctl coder (their request +
  observations, our formal reply: embedder accepted, M0 dir cleanup done).

Verified live: RUSTFLAGS="-D warnings" cargo test --workspace = 65/65 PASS;
lean proofs/{slab_ring_dma,bus_lifecycle,serve_session,arena_plan}.lean green,
standard axioms only.
This commit is contained in:
adm committed 2026-11-30 15:22:00 +01:00
1 parent 7b50f1c07c
commit fb92662106
13 files changed
+1235 -16

No files matched your search

+89 -7
View File
@@ -31,6 +31,14 @@ parameters (2B–6B/tok), large total capacity (35B–300B+). `strata-dense`
remains a **technique donor** (Q4 SWAR unpack, MTP lossless verification),
not a target engine.
**Carve-out — utility encoder models (2026-11-30):** the dense exclusion
applies to dense *decoder LMs* (40–70 GB read per generated token). Small
dense **encoders** are a different execution shape — a single forward pass,
fully UMA-resident, no KV growth — and are **in scope** as the M1.5 embedder
lane (BGE-M3 q8 ~600 MB, requested by the strata-ctl agent for its vector
memory; see §6 embedder wire). Utility ≠ generative: the "MoE-only" rule
governs generation only.
### Residency & streaming policy
| Model footprint | Policy |
@@ -130,6 +138,10 @@ Streaming, two stages, **zero intermediate files**:
- `manifest.json` carries: model identity, source fingerprint (FNV-1a),
**packer fingerprint + ABI version + backend target**. A bundle produced by
an incompatible packer/ABI is rejected explicitly, never misread.
**Implemented** (2026-11-30): `abi::bundle` (manifest + `memory.vplan` +
`graph.vplan` parsing, arena-validated `compile`) and `ld::bundle::
load_bundle_plans` (read-only directory load). Device-pointer resolution
into the flat `CompiledPlan` lands with the M1 packer/executor.
```
<model>.vbundle/
@@ -181,6 +193,15 @@ GB-scale weights are never rewritten (0 SSD wear).
`gpu_penalties_topk`. Control-flow opcodes are limited to `loop_layer` /
`branch_b` (batch-size dispatch) — no general computation in the plan.
**Encoder-lane additions (M1.5, embedder):** `layer_norm` (true LN: mean +
variance + affine — not RMSNorm), `flash_full_attn` (bidirectional variant of
`flash_gqa_wmma`: padding mask only, no causal mask — a mask parameter, not a
new primitive), `gelu_erf` (exact-erf FFN epilogue, replaces the SwiGLU
fusion), `mean_pool_l2norm` (pool over `attn_mask == 1` positions + L2
normalize, one small fused kernel). GEMMs, allocator, SlabRing and the HIP
backend are reused unchanged. The executor is selected by the `.vplan` itself
(encoder = single-pass plan, decoder = token loop): `kn` stays model-agnostic.
## 5. Execution Engines
- **`rt` (operational):** zero probes, zero debug branching on the hot path.
@@ -240,6 +261,46 @@ reserved). Keys emitted today by `Sampling::keys()`: `temperature` (>0 only),
parsed by `abi`; strata-ctl does not emit them yet (its Python CLI sibling
did). Additive, no breakage.
### Embedder-lane wire (M1.5, proposal for the next review cycle)
Origin: `review/richieste-embedder.md` + `review/osservazioni-embedder-e-scope.md`
(strata-ctl agent, 2026-11-30). Reference fork: Gitea `iz0eyj/vetta-semantics`,
branch `vetta-semantic` (HEAD `549ebf8d`), local original `../vetta-semantics`
(the `tmp/` clone was removed 2026-11-30). Math source:
`embedder/src/encoder_graph.cpp` / `encoder_runtime.cpp`;
parity oracle: live `vetta-embedder` on `:8091`. First cut = **separate
resident process** `vetta-infer embed` (does not touch the Lean-verified
`serve_session` FSM; different model set, reuses supervision/parsing):
- handshake: `READY` + `INFO embedder=bge-m3 dim=1024 sparse=0 colbert=0 reranker=<0|1>`
(capability discovery is mandatory; transport is negotiable, capabilities are not);
- `ENC <n> [k=v…]` followed by `n` text lines → `n` vector lines + `DONE`;
payload **base64 f32** (lossless, compact, no float-repr ambiguity); CSV only
if the consumer prefers debuggability — to be settled in the review cycle;
- `RERANK <query>` + doc payload → scores + `DONE` (only when `reranker=1`);
- `QUIT` clean. Scope per §6 of the request: **dense only** in the first cut
(batch = slice interface, one-by-one execution), reranker head optional;
sparse/ColBERT/ordered-walk stay in `vetta-semantics`, explicitly excluded.
Acceptance (request §8): `encode([it, code, mixed])` → L2-norm ≈ 1.0 and
**cosine ≥ 0.999 vs `:8091`** on the same corpus; no prompt prefixes for
BGE-M3 (verified: the fork excludes `m3` explicitly); batch result
bit-parity/cosine ≈ 1 vs one-by-one.
**Characteristic parity with the reference engine** (decided 2026-11-30):
per-token activations as first-class outputs are *native* here — the `[T, d]`
pre-pool activation lives in a `memory.vplan` arena and `probe.vplan`/`lab`
is exactly the declared observation mechanism (semantic-walk/ColBERT-style
emission = an output mode, not a fork); sparse/ColBERT heads are extra GEMMs
on the same pass, deferred by scope choice, not by capability. Two honest
exceptions: (1) **bit-identity is internal-only** — our golden/parity tests
are bit-exact against our own CPU references (strata porting rule); against
the ggml oracle the metric is semantic (cosine ≥ 0.999), since WMMA
accumulation order differs by construction; Qdrant Edge is rebuildable, a
one-shot batch re-embed covers any zero-delta migration. (2) Vulkan/portable
CPU fallback is replaced by the `BackendPacker` abstraction (§5); the CPU
reference built for parity tests is the seed of a future CPU backend.
## 7. Minimal Reusable HIP Microkernel Set (`< 15` Primitives)
1. `k_embed_bf16` — BF16 embedding gather
@@ -256,6 +317,12 @@ reserved). Keys emitted today by `Sampling::keys()`: `temperature` (>0 only),
12. `k_moe_grouped_wmma` — compacted active-expert `w13` (fused SwiGLU + quantize) & `w2` + `k_moe_reduce`
13. `k_vit_flash_attn_wmma` — `64×64` FP16 WMMA Vision encoder attention
14. `k_gpu_penalties_topk` — GPU penalties + `top-64` extraction (`<= 512 B` D2H per row instead of `6–16 MB` with `temp > 0`)
15. `k_layer_norm` — true LayerNorm (mean+var+affine) for the encoder lane
16. `k_pool_normalize` — fused mean-pool over mask-active positions + L2 normalize
Bidirectional encoder attention (`flash_full_attn`) and GELU-erf FFN are
mask-parameter / epilogue variants of primitives 4/8, not new kernels — the
encoder lane keeps the set at 16 and reuses everything else.
Porting rule: strata kernels are the reference implementation; each ported
kernel ships a bit-exact parity test (as `clover_gpu_parity_test` did).
@@ -267,7 +334,7 @@ logic (state machines, rings, pools, speculative/rollback, arena plans) is
verified by the Lean kernel **before** implementation. `0 sorryAx`, standard
axioms only, `lean proofs/<file>.lean`.
Verified today (`proofs/slab_ring_dma.lean`, 10 theorems):
Verified (`proofs/slab_ring_dma.lean`, 10 theorems):
- **`SlabRing` DMA safety:** mutual exclusion `io_uring` writes / GPU reads,
fence-gated reclaim, slot isolation (eliminates audit F-01 by construction).
- **`PrefixState` soundness:** no uninitialized MTP hidden-state reuse (F-03).
@@ -275,7 +342,9 @@ Verified today (`proofs/slab_ring_dma.lean`, 10 theorems):
New obligations before the corresponding implementation:
- **`memory.vplan` arena safety:** no overlap, no use-before-write, offsets
within declared arenas (flat opcodes make this decidable). *(pending, M1)*
within declared arenas (flat opcodes make this decidable). **VERIFIED**
(`arena_plan.lean`, 8 theorems + 4 computational examples) and implemented
in `abi::arena` (checked offset arithmetic, invariant #2).
- **Bus lifecycle:** STOP/cancellation drains to a terminal state; no service
observes a half-committed registry entry. **VERIFIED** (`bus_lifecycle.lean`,
14 theorems) and implemented in `kn`.
@@ -315,12 +384,25 @@ Inkling (1244 tensors, 18.18 GiB, checked bounds).
- **M0 (done):** workspace skeleton, Lean contracts, checked IO, serve parsing,
telemetry, HIP ABI — all audit-hardened, 11/11 CPU tests, 10/10 theorems.
- **M0.5 (current):** this specification + crate realignment to `vetta-infer-*`,
- **M0.5 (done):** this specification + crate realignment to `vetta-infer-*`,
faithful policy ports with parity tests, wire-contract deltas closed.
- **M1 (Resident MoE End-to-End — Inkling-2-Mini):** HIP microkernels,
NVFP4/MXFP8 + `Q8_G64_T16` trunk, GPU Vision (`image=` key), write-once
`.vbundle`, strata-ctl drop-in `--serve` parity & speed vs C++ baseline
(`>= 18 tok/s`, `< 4 s` reload).
- **M1 (Resident MoE End-to-End — Inkling-2-Mini, in progress):** HIP
microkernels, NVFP4/MXFP8 + `Q8_G64_T16` trunk, GPU Vision (`image=` key),
write-once `.vbundle`, strata-ctl drop-in `--serve` parity & speed vs C++
baseline (`>= 18 tok/s`, `< 4 s` reload). Landed: serve-session FSM
(`serve_session.lean` + `gw::session`), arena safety (`arena_plan.lean` +
`abi::arena`), `.vbundle` manifest/plan contract (`abi::bundle` +
`ld::bundle`). Next: ModelImporter/BackendPacker → first real `.vbundle`,
device-pointer resolution, HIP kernel ports with parity tests.
- **M1.5 (Embedder lane — BGE-M3):** encoder `.vplan` family + XLM-R
ModelImporter (`ld`), SPM unigram tokenizer + `nmt_nfkc` (`nt`),
`layer_norm`/`flash_full_attn`/`gelu_erf`/`mean_pool_l2norm` kernels (`rt`),
`vetta-infer embed` wire (§6). Acceptance: cosine ≥ 0.999 vs the live
`:8091` oracle on it/code/mixed corpus. May be **pulled before M1 decode**
as the HIP kernel bring-up bench: a standard dense encoder is the easiest
real GPU target and shares the GEMM/flash backend the MoE loop needs.
Reranker head (BGE-Reranker-v2-m3) rides the same executor, only the
`INFO reranker=1` capability is added.
- **M2 (Hybrid GDN + NVMe Zero-Copy DMA Streaming):** Chunkwise Parallel GDN
(WY, `250–350+ ppts`), Clover-35B-A3B & MTP support, `io_uring O_DIRECT` +
`hipHostRegister` `SlabRing` ping-pong, Hot/Cold cache + lookahead prefetch,