Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
165 lines
24 KiB
Markdown
165 lines
24 KiB
Markdown
# Strata Next implementation plan
|
||
|
||
## Product shape
|
||
|
||
The target interface is one Linux command, `strata-next`, with `serve`, `model fetch`, `model verify`, `model prepare`, `doctor`, and `benchmark` operations. A model remains on an external volume. The command must keep production serving independent of Python. The user-facing executable may eventually contain a statically linked Strata engine, but CUDA still needs the installed NVIDIA driver and its `libcuda.so`. The CLI checks the existing driver; it does not install or bundle one. For the current CUDA 13.0 GA baseline, the minimum Linux driver is 580.65.06 per NVIDIA's release notes. Until engine integration is proven, the Rust executable and C++ engine remain separate build artifacts and the CLI reports that limitation clearly.
|
||
|
||
`LAYERED_EXTENDED` is retained as an exact user-provided term; no runtime semantics have been assigned to it yet.
|
||
|
||
## Work packages
|
||
|
||
| ID | Package | Deliverable | Acceptance |
|
||
| --- | --- | --- | --- |
|
||
| P0 | Linux foundation and CI | Pinned Rust, Linux lint/tests, musl CLI artifact, release workflow | CI builds a runnable Linux artifact and rejects format/lint/test failures |
|
||
| P1 | Artifact acquisition | Manifest-pinned model downloads, size/hash verification, safe resume, external volume | Interrupted local HTTP fixture resumes; wrong hash never becomes a completed model |
|
||
| P2 | Model preparation | Inspect GGUF and tokenizer; port pack/index; create and verify provenance-pinned KAR-2 archives | Prepared output matches upstream, with source and archive digests and separate KAR quality gate |
|
||
| P3 | Native API | Tokenization, prompt template, `/v1/responses`, tool calls, schema, live SSE, cancellation | Sanitized Codex replay has no protocol errors or missing terminal events |
|
||
| P4 | Single executable | Link/embed engine and CUDA KAR decoder where viable, check preinstalled NVIDIA driver, one-command startup | Linux node with a compatible driver loads compressed weights and decodes on GPU without Python or manual engine installation |
|
||
| P5 | Reliability and telemetry | Restart, timeouts, backpressure, metrics, graceful drain | Soak and failure injection pass without orphaned slots or incomplete streams |
|
||
| P6 | Performance and scale | Controlled baseline, KAR GPU path, 2×256K, 1×512K, scheduler, with-key and without-key cache profiles | Charter quality/performance gates and reproducible reports pass |
|
||
|
||
## Sequence and dependencies
|
||
|
||
1. Complete P0 and P1 locally. Keep model bytes out of Git and verify every finished file by SHA-256.
|
||
2. Port P2 with differential fixtures from upstream. Do not infer tensor correctness from a file extension alone.
|
||
3. Connect the existing Rust worker pipe to P3. Use the real model only when the GPU node is free; use synthetic protocol tests meanwhile.
|
||
4. Package P4 after the ABI and CUDA link strategy are measured on Linux. Do not label a control-plane-only musl artifact as the complete GPU runtime.
|
||
5. Add P5 before production deployment, then run the baseline and P6 experiments with the charter's gates.
|
||
|
||
## Task queue
|
||
|
||
### P0 — Linux delivery
|
||
|
||
- [x] Pin the Rust toolchain and enforce format, Clippy, Rust tests, and CPU tests.
|
||
- [x] Write the local GitHub Actions workflow for Linux checks, a musl build, ELF dependency checks, artifact upload, and tag prerelease.
|
||
- [ ] Create the Strata Next GitHub repository, add its project remote, and run the workflow on a hosted Linux runner.
|
||
- [ ] Run a CUDA engine build and loader smoke test on Linux GPU hardware (the C++ engine ran earlier; the Rust-port PTX/link path has not been built or linked, see the port queue below).
|
||
- [x] Build the isolated KAR CUDA decoder for RTX 5090 and match synthetic full/row plus two real overlay-record checksums with the CPU oracle.
|
||
|
||
### P1 — model acquisition
|
||
|
||
- [x] Embed a commit-pinned IQ3_S manifest with size and SHA-256 for both GGUF shards.
|
||
- [x] Implement resumable downloads, integrity checks, and a local interrupted-transfer test.
|
||
- [x] Check free disk space for all outstanding shard bytes and again after each resume/restart response.
|
||
- [x] Report per-shard byte and percentage progress while downloading, including resumed offsets.
|
||
- [x] Verify both complete real IQ3_S shards on an external volume and record measured digests.
|
||
- [x] Retry transient model transfer failures with bounded backoff and verified partial-file resume.
|
||
- [x] Accept an optional process-local `HF_TOKEN` for exact HTTPS Hugging Face URLs; reject URL-embedded credentials and keep redirects from forwarding the header across origins.
|
||
|
||
### P2 — native model preparation
|
||
|
||
- [x] Inventory `iq_pack.py`, `pack_index.py`, and `strata_tokenizer.py` outputs and formats.
|
||
- [x] Port bounded GGUF v3 header and tensor-directory inspection into native code.
|
||
- [x] Validate the native inspector against the unmodified `tools/gguf_reader.py` on generated GGUF v3 headers (400 cases: every metadata value type, arrays, alignment, split keys, geometry table); see `docs/offline-port.md`.
|
||
- [ ] Re-run the inspector differential on both real IQ3_S shards (the shards are not on the macOS development host; the Linux full-preparation run indexed them, but no scripted comparison against `gguf_reader.py` exists).
|
||
- [x] Port tokenizer asset extraction without a Python runtime and compare it with upstream on a synthetic GGUF.
|
||
- [x] Port tokenizer encode/decode and compare token IDs with upstream on a synthetic full-byte vocabulary.
|
||
- [x] Extract the SHA-256-verified first real shard’s tokenizer and compare native IDs and roundtrips with the pinned upstream oracle on Unicode and special-token cases.
|
||
- [x] Port the IQ3_S pack/index path (`native_pack.rs`, incl. `--compat-bf16`, `--base`, `--experts-bin`) without a Python runtime; tokenizer assets round-trip. The real-model tokenizer comparison is covered by the earlier Linux run and by the committed per-codepoint differential.
|
||
- [x] Differentially compare metadata, tensor bytes, and tokenizer behavior against the unmodified upstream Python tools on synthetic inputs (2755 pack cases, 400 header cases, 14.5M pre-tokenizer strings; `scripts/offline/diff_*.py`).
|
||
- [ ] Repeat the pack, header and tokenizer differentials on the real shards and tokenizer (needs the model volume on the Linux host; not run).
|
||
- [ ] Add a unified `model prepare` command with source digest, KAR-2 archive validation, atomic completion, and no model data in Git (native pack: `prepare-native-pack` is atomic and writes `receipt.json`; KAR: `ensure-sharded-streamed`).
|
||
- [x] Add bounded native KAR-2 metadata inspection, streaming payload CRC verification, and optional source-manifest identity check (decode still pending).
|
||
- [x] Emit a byte-identical synthetic KAR-2 RAW/NESTED archive from native Rust tensor slices; publish after verification without overwriting an existing file.
|
||
- [x] Index supported GGUF tensor payloads with exact block geometry and bounded per-tensor hashing; reject overlapping, truncated, or malformed source layouts.
|
||
- [x] Stream RAW tensor bytes into KAR-2 with a fixed 1 MiB buffer and per-tensor digest verification.
|
||
- [x] Stream pre-encoded NESTED sections into KAR-2 with checked section geometry, finite f16 values, zero padding, and digest verification.
|
||
- [x] Encode a synthetic f32 tensor to native KAR scales and bit planes using supplied calibration; keep the lossy path experimental.
|
||
- [x] Decode a selected KAR bit-plane prefix into a caller-sized CPU buffer for numerical tests.
|
||
- [x] Decode a bounded arbitrary range of a large nested KAR tensor from stored archive bytes and compare selected real GGUF ranges with pinned ggml values.
|
||
- [x] Fit experimental top-down nested boundaries and f16 books from a supplied normalized sample; match pinned koference synthetic oracles.
|
||
- [x] Wire a small F32 GGUF through native calibration, encoding, reconstruction check, and verified KAR publication under an explicit preview command.
|
||
- [x] Spool each preview tensor as a canonical NESTED section and assemble the archive from file-backed sections; clean staging after success or failure.
|
||
- [x] Decode synthetic GGUF IQ3_S source blocks in native Rust with a pinned ggml grid and bounded output.
|
||
- [x] Define and compute a versioned virtual F32 stream identity for a bounded-memory, all-IQ3_S GGUF, retaining original GGUF and tensor digests separately.
|
||
- [x] Convert a small all-IQ3_S GGUF to an experimental KAR preview with virtual F32 source identity and an original-source provenance sidecar.
|
||
- [x] Recompute the IQ3-derived source against the original GGUF and verify each KAR source record, archive payload CRC, and provenance sidecar.
|
||
- [x] Define and compute a versioned virtual F32 source for a single GGUF mixing IQ3_S with F32, F16, and BF16 tensors.
|
||
- [x] Prepare and independently verify a small KAR preview from a mixed IQ3_S/F32/F16/BF16 virtual source.
|
||
- [x] Compute a versioned virtual F32 identity across manifest-verified GGUF shards in filename order, with global tensor offsets.
|
||
- [x] Encode and independently verify a small, manifest-pinned sharded KAR preview with provenance.
|
||
- [x] Add an experimental sharded preparation command with bounded calibration and encoding and no preview size cap; verify its archive and provenance on synthetic F32/IQ3_S shards.
|
||
- [x] Add an opt-in full-size fetch → verify → prepare → verify CLI path that reuses only a reverified streamed archive.
|
||
- [x] Inspect both target GGUF directories and statically link pinned ggml CPU dequantizers for every type found there; exercise them on bounded synthetic blocks.
|
||
- [x] Check native ggml block size against GGUF geometry and decode a real block of every first-shard type; version the streamed derivation after correcting the kind-18/22 dispatch.
|
||
- [x] Measure a provisional, reproducible IQ3_S/IQ4_NL real-data slice with the streamed KAR path; record archive size, source identity, and reconstruction error without treating the slice as a model-quality gate.
|
||
- [x] Run full streamed preparation and independent verification; both target shards matched their manifest SHA-256 values and representative real blocks/ranges matched the CPU oracle. Model-level quality and GPU execution remain separate gates.
|
||
- [x] Resolve a fully verified base KAR archive plus precision overlay into a per-record selection map; both real archive hashes, all payload CRCs, and 22 replacements passed. GPU loader use remains open.
|
||
- [x] Verify IQ3_S values against upstream CPU dequantization: pinned ggml bit for bit on sampled real blocks, and 69 fixtures across 23 block types bit-exact against pinned `gguf-py` and `iq_fixture.py` (`diff_dequant.py`).
|
||
- [ ] Promote the bounded GGUF/KAR path to a single `model prepare` command after real-shard validation, per-class rate policy, and quality checks (`prepare-native-pack` and `ensure-sharded-streamed` exist separately; they are not unified).
|
||
- [x] One-command `serve` fetches, verifies and prepares the native GGUF pack and reuses it offline (`smoke-native-bootstrap.py`).
|
||
- [ ] Extend the one-command path to the verified compressed KAR archive.
|
||
- [x] Compare KAR reconstruction with its CPU oracle (selected real ranges, kernel model over randomized synthetic records).
|
||
- [ ] Run full-model quality before making the compressed path a default (GPU-gated).
|
||
|
||
### P3 — API and worker
|
||
|
||
- [x] Validate a Responses request subset and build synthetic JSON/SSE traces.
|
||
- [x] Exercise `GEN`/`T`/`DONE` through a resident fake worker.
|
||
- [x] Add native tokenization and Qwen prompt formatting; connect a restricted non-streaming text path to the worker command queue.
|
||
- [x] Stream text deltas directly from the worker with bounded channels, UTF-8 assembly, terminal SSE events, and client cancellation in synthetic tests.
|
||
- [x] Parse complete Qwen function calls in Rust for buffered Responses output, preserving nested delimiter text and checking argument schemas; synthetic HTTP test passes.
|
||
- [x] Render stateless text input arrays with paired function calls and outputs into the next Qwen prompt; synthetic HTTP continuation passes.
|
||
- [x] Store completed responses in a bounded, process-local cache by default and replay `previous_response_id` with new input; synthetic tool-result continuation passes.
|
||
- [x] Stream text, completed function calls and reasoning (`response.reasoning_text.delta/done`) with cancellation, backpressure and terminal events; verified against a mock worker and a split-at-every-byte test. A live engine has not produced reasoning through this path.
|
||
- [ ] Replay sanitized real Codex sessions and compare against the upstream server (replay tooling and synthetic fixtures exist; no comparison against the upstream Python server has been run).
|
||
|
||
### P4–P6 — production and optimization
|
||
|
||
- [ ] Package the C++/CUDA engine with the Rust CLI into one user-facing Linux executable where the link strategy permits.
|
||
- [ ] Keep the KAR archive compressed through GPU residency; integrate `libkar` reserve/decode, PLE row decode, expert miss scheduling, and measured transfer/decode/multiply overlap.
|
||
- [x] Verify base plus precision overlay and account for selected compressed residency and F32 scratch without double-counting replaced records; the real v4 pair was measured as archive metadata, not GPU execution.
|
||
- [ ] Expose `with-key` and experimental `without-key` KV modes; keep QSA indexer keys and pass the separate Keyless quality gate before default use.
|
||
- [ ] Add failure injection and soak tests. Process restart, metrics, auth, idle unload, reload gates and an outside stall watchdog exist in `control-plane` and were tested against mock workers; none was soaked against a live engine.
|
||
- [x] Stop and drain an abandoned internal generation; interrupt an active generation during shutdown.
|
||
- [ ] Capture the 1×256K baseline, then implement and validate 2×256K and 1×512K.
|
||
- [ ] Evaluate speculation, KAR, and Value-Only only under the charter's separate quality gates.
|
||
|
||
### Port — Rust port of the Original C++/CUDA engine (branch `claude/port-main`)
|
||
|
||
Scope and status of each unit are tabulated in [`port-status.md`](port-status.md). In this list "done" means source written, type-checked and, where stated, checked against an executed CPU oracle on macOS. No item below has run on a GPU, and none carries a performance or model-quality claim.
|
||
|
||
- [x] Offline tooling (native pack, GGUF header, tokenizer, dequantization, small packers, MTP pack/fetch, setup.py RAM/context policy, chat template, reasoning budget) ported with live differentials against the unmodified Python tools: `docs/offline-port.md`.
|
||
- [x] RoPE scaling (linear/YaRN), memory planner, context policy and the 262144 pin lift in Rust, with bit-level goldens from the Original C++ on macOS: `docs/rope-and-memory-plan.md`. The committed PTX of four kernels is not regenerated; the lifted contexts (2x256K, 1x512K) are admitted by arithmetic only.
|
||
- [x] Sampler reference (Philox, penalties, top-k/top-p/min-p, coupled-draft counters) bitwise against the Original host reference (322 cases), request plumbing and per-request host sampler: `docs/sampler-reference.md`.
|
||
- [x] Serving surface: operational HTTP routes, CORS, aliases, idle unload, reload gates, stall watchdog, MCP hub, conversation cache/parking/checkpoints, control vectors, SVE1 files and M-RoPE positions, replayed against the Python handlers or golden-tested against Original host code.
|
||
- [x] Original-literal CUDA leaves and host owners (QSA, GDN, GR, PLE, MoE, MMQ, native head, sampler, MTP drafter and loader, verifier arena/schedule, window launch plans, prefill scheduling model, expert cache/stager/file source): source-complete and type-checked, with host-executed oracles for several planners and summation orders.
|
||
- [x] KAR level 2..5 decode on CUDA and the KAR routed-expert source: CPU kernel model matches the CPU oracle bit for bit; the CUDA source was compiled with nvcc 13.2.86 and sealed on 2026-10-15 (no GPU run, no numerical claim). `docs/experiments/2026-10-14-kar-levels-gpu-port.md`.
|
||
- [x] Experimental modes (Q4_0/K8V4/rotated-INT8 KV, Keyless V-only, control vectors, KV streaming, remote-experts planner): references and literal CUDA sources with an emulator-based check; everything is off by default and refuses to load until the forward pass consumes it. `docs/experiments/2026-10-14-experimental-modes-port.md`.
|
||
- [ ] Build and seal the PTX. Done 2026-10-15 with nvcc 13.2.86 (30 assets: the four RoPE/stream PTX, both new window sources, `experimental::PINS`, KAR levels, the closed kernels, the native head and sampler; GPU load is verified separately by the host smokes, no numerical claim). Still open: seal the six remaining placeholder PTX (`mmq_original_group_*`, `mtp_original_scalar_{gr,norm}`, `native_parity`) and re-check the recipes against the pinned toolkit (CUDA 13.0.88, `scripts/build-original-verify-ptx.sh`). Original line: regenerate the four RoPE/stream PTX, seal `original_verify_window_moe_experts` and `original_verify_window_qsa_gate`, seal any remaining placeholder PTX (the audit of 2026-10-12 listed the native head, original sampler, MMQ group and MTP scalar assets), freeze `experimental::PINS`, decide the fast-math re-seal question in `docs/cuda-seal-plan-additions-window.json`.
|
||
- [ ] Link the engine: the runtime-side wiring of the window recorder (weights, QSA/PLE journals, CPU pool callbacks, graph registration), the serving owner that selects `OriginalSpecController`, and the multi-GPU stage handoff (`PORT-GAPS-MODE17.md`).
|
||
- [ ] Run the ignored GPU smokes on the Linux GPU host (`--ignored`: window, MTP bank, KAR levels, experimental programs, sampler, verifier) and record results.
|
||
- [ ] Original17 parity: same prompts, greedy token ids identical between the Original and the Rust port, then sampled-path parity with recorded seeds. Nothing beyond the earlier preview-generation run (one 202-token prompt, 32 greedy tokens) has been compared on a GPU.
|
||
- [ ] Linux execution of the Linux-gated unit tests in `leleka-cuda-driver` and `leleka-runtime` (they are only type-checked on macOS); `scripts/linux-tests/run.sh` (branch `claude/port-linux-tests`) is the intended harness.
|
||
- [ ] Performance and quality gates per `PROJECT_CHARTER.md`: controlled baseline with paired A/B, model-quality gate for every lossy mode, 1x256K baseline, then 2x256K and 1x512K. `docs/performance-ledger.md` still has no entries.
|
||
|
||
## CI/CD policy
|
||
|
||
Pull requests and main commits run Rust format, Clippy, tests, synthetic replay, and CPU engine tests on Linux. CI builds a static musl **CLI/control-plane** artifact and checks that it has no ELF interpreter. Version tags can publish this artifact with a SHA-256 checksum; a full GPU release waits for a Linux CUDA build, runtime smoke test, and signed-off model quality gate. No model weights or tokens enter CI artifacts.
|
||
|
||
The `Rust port` workflow (`.github/workflows/port.yml`) adds, without touching the jobs above: `scripts/check-local.sh --fast` (format, Clippy and tests on the host-buildable crates; known format/Clippy debt in `leleka-model-format` and the Linux-only crates is reported, not fatal, until the owning branches clean it), a type-check of `leleka-cuda-driver` (feature `cuda-driver`) and `leleka-runtime` for `x86_64-unknown-linux-gnu`, the CPU oracle differentials against the unmodified Python tools (optional until green on the hosted runner), and the Docker Linux harness `scripts/linux-tests/run.sh` (optional until branch `claude/port-linux-tests` merges). Type-checking is not execution: no CI job runs a GPU smoke; the Linux `verify` job runs the `leleka-cuda-driver` tests (not yet shown green on this branch) and the `leleka-runtime` tests are only compiled; and `scripts/check-local.sh --fast|--port|--full` selects the same stages locally.
|
||
|
||
## Current status
|
||
|
||
Last reviewed 2026-10-14 against branch `claude/port-main`. No performance or model-quality result is claimed on this page.
|
||
|
||
**Delivery (P0, P1).** The control plane builds as a static musl CLI/control-plane artifact and passes format, Clippy and test gates in the existing Linux workflow. Hosted Actions still needs a GitHub repository and runner; the workflows also reference a Gitea runner. `model fetch` and `model verify` passed both real IQ3_S shard SHA-256 values on the Linux NTFS volume.
|
||
|
||
**Offline model preparation (P2).** The Python offline tools of the Original are ported to Rust and checked live against the unmodified Python on synthetic inputs (no model data): native pack 2755 cases, GGUF header 400, tokenizer 14.5M pre-tokenizer strings, dequantization 69 fixtures across 23 block types, small packers, MTP fetch (10 scenarios), chat template 3000 cases (`docs/offline-port.md`). Deliberate divergences and the tools not ported (`pack_index.py`, `strata_pack.py`, `pack_layer.py`, `canonical_xcheck.py`: Q2_0/AVX-512 only) are listed there. These differentials did not run on the real shards.
|
||
|
||
**KAR and Keyless (pre-port results, unchanged).** The complete level-2 KAR archive was produced from both verified shards (55,295,529,472 bytes from 83,617,662,656 source bytes, 66.13%; independent verifier passed; maximum tensor relative L2 error 0.68008092) and a level-3 overlay of 22 records reduced the error of every selected tensor. These numbers do not pass the model-level quality gate and no serving loader applies the overlay on the production path. An opt-in PLE-only GPU row cache and the Keyless V-only experiments ran on an RTX 5090 earlier; both pretrained Qwen V-only agent variants failed model quality and remain opt-in (`docs/experiments/2026-10-04-keyless-runtime.md`). No KAR or V-only speed improvement is qualified.
|
||
|
||
**API and worker (P3).** The Responses route streams text, completed function calls and reasoning events and supports cancellation, stateless tool-result replay and bounded process-local `previous_response_id`; Chat Completions, Messages and the operational routes of the Python server (`/props`, `/slots`, `/settings`, `/load`, `/unload`, CORS, aliases, idle unload) exist. All of it is tested against mock workers and recorded fixtures. Reasoning-budget wrap-up (`reasoning_budget.rs`) is a tested port of the loop; its wiring into the live worker is open (`docs/offline-port.md`). Live reasoning through a real engine, replay against the upstream server and full-model quality remain pending.
|
||
|
||
**Rust port of the Original engine (`claude/port-main`).** The branch is a Rust host and orchestration layer around CUDA sources that are literal or adapted copies of the Original kernels, loaded through the CUDA driver API; production serving stays independent of Python. What exists, module by module, is in [`port-status.md`](port-status.md). In short:
|
||
|
||
- Pure Rust with executed CPU oracles on macOS: offline tools, RoPE/YaRN tables, memory planner and context policy, sampler chain, serving policy (CORS, idle, watchdog, stride, timings), conversation cache, experimental-mode references, KAR level decode model, tokenizer, quantization dequantizers.
|
||
- Source-complete and type-checked only: the CUDA driver wrappers, the native head, MTP drafter and loader, verifier window recorder, prefill scheduling, expert cache and stager, QSA/GDN/GR/PLE/MoE/MMQ owners, and the KAR routed-expert source. `cargo check --target x86_64-unknown-linux-gnu --all-targets -p leleka-cuda-driver --features cuda-driver -p leleka-runtime` passes; the tests of these two crates compile but were not run on Linux by this effort.
|
||
- The PTX of the new or changed kernels was compiled with nvcc 13.2.86 and sealed on 2026-10-15 (30 assets; six placeholders remain), but the engine is not linked. Unsealed assets fail closed (zero pins, refusing constructors).
|
||
- Not run on a GPU: everything above. The only GPU evidence is the earlier preview-generation run (identical greedy ids for one 202-token prompt; it was far slower than the Original and scaled variants exhausted VRAM), which predates the Original-literal code and does not qualify it.
|
||
- Known test debt on the macOS development host: thirteen worker tests in `strata-control` and four in `leleka-model-format` fail on macOS because of process and path assumptions (also on the base branch); `leleka-cuda-driver`, `leleka-runtime` and `leleka-native-cpu-expert` do not build natively on macOS; `cargo fmt --check` is not clean for `leleka-model-format`, `leleka-experimental-ref`, `leleka-cuda-driver`, `leleka-runtime` and `leleka-native-cpu-expert`.
|
||
|
||
**What remains.** Build and seal the PTX, link the engine, run the GPU smokes, establish Original17 parity, execute the Linux-gated tests, then the charter's controlled baseline, paired A/B and quality gates. Until the performance ledger has entries, nothing here is a performance claim.
|
||
|
||
References: [NVIDIA CUDA 13.0 release notes](https://docs.nvidia.com/cuda/archive/13.0.0/cuda-toolkit-release-notes/index.html), [NVIDIA driver components](https://docs.nvidia.com/deploy/cuda-compatibility/latest/why-cuda-compatibility.html), and [Rust musl target support](https://doc.rust-lang.org/rustc/platform-support.html).
|