docs(architecture): carry independent engine handoff into Gitea
Linux / keyless-cuda-gate (pull_request) Skipped
Linux / verify (pull_request) Successful in 3m12s
Linux / keyless-cuda (pull_request) Skipped
Linux / static-cuda-package (pull_request) Skipped
Linux / hosted-cuda-package (pull_request) Skipped
Linux / linux-cli-container (pull_request) Failing after 2m10s
Linux / linux-static-cli (pull_request) Failing after 5m6s
Linux / release-cli (pull_request) Skipped
Linux / keyless-cuda-gate (pull_request) Skipped
Linux / verify (pull_request) Successful in 3m12s
Linux / keyless-cuda (pull_request) Skipped
Linux / static-cuda-package (pull_request) Skipped
Linux / hosted-cuda-package (pull_request) Skipped
Linux / linux-cli-container (pull_request) Failing after 2m10s
Linux / linux-static-cli (pull_request) Failing after 5m6s
Linux / release-cli (pull_request) Skipped
This commit is contained in:
@@ -1,222 +1,317 @@
|
||||
# Independent NVIDIA engine: architecture handoff
|
||||
|
||||
**Status:** architecture proposal, awaiting Tech Lead review. This is a source
|
||||
inventory and migration design; it does not claim a working inference engine.
|
||||
**Status:** architecture proposal. No working inference engine is claimed.
|
||||
|
||||
**Decision already made by the project owner:** Rust owns the runtime. Strata is
|
||||
an upstream source for selected behavior and algorithms, not a build, runtime,
|
||||
or deployment dependency. The new implementation repository is the private
|
||||
Gitea repository `git@vezha.io:para/leleka.git`; its remote is reachable and was
|
||||
empty when checked on 2026-10-05. Keep this architecture record and the existing
|
||||
Strata provenance in `strata-next`; implement the replacement in Leleka.
|
||||
**Owner decision:** Rust owns serving. Strata is a source of selected behavior,
|
||||
not a build, runtime, or deployment dependency. Implement the replacement in
|
||||
private Gitea repo `git@vezha.io:para/leleka.git`; preserve this record and
|
||||
Strata provenance here. The private Gitea repository now contains the imported
|
||||
workspace; the legacy Strata engine remains coupled until the migration gates pass.
|
||||
|
||||
## 1. Options and recommendation
|
||||
|
||||
| Option | Benefits | Costs and risks | Decision |
|
||||
| --- | --- | --- | --- |
|
||||
| Keep the current C++ Strata engine and Rust control plane | Reuses the most inference code; shortest path to the existing Qwen setup | Production remains coupled to Strata's executable, `--serve` wire format, build and model profile | Reject as the target; preserve only as the behavior/reference baseline |
|
||||
| Rust-owned engine and scheduler, with CUDA C++ kernels behind a narrow internal ABI | Rust owns model loading, tensors, routing, KV, admission, scheduling, lifecycle and API integration; existing CUDA kernels can be ported in measured steps | Initial CUDA kernels still need the CUDA build toolchain; FFI ownership, shape and stream contracts need tests | **Recommend.** This meets the owner's independence goal without pretending CUDA kernels can be safely rewritten in one pass |
|
||||
| Rewrite all runtime and kernels in Rust immediately | One main language and fewer long-term language boundaries | Rust does not remove the need for CUDA/PTX; kernel parity and performance need separate proofs, and a big-bang rewrite delays a usable runtime | Reject as the first migration stage; replace individual kernels only after parity and paired performance gates |
|
||||
| Rust host with a separate Python/C++ serving engine | Can compose existing libraries quickly | Keeps a second runtime, protocol bridge, process lifecycle and extra packaging dependencies; violates the desired self-contained production runtime | Reject for production. Python remains allowed only for offline research/evaluation where useful |
|
||||
- **Keep C++ Strata + Rust control plane:** shortest Qwen path; keeps Strata
|
||||
executable, wire format, build, and model profile in production. Reject as target.
|
||||
- **Rust engine/scheduler + narrow CUDA C ABI:** Rust owns serving; port CUDA
|
||||
kernels in measured steps. Recommend; test FFI ownership, shapes, and streams.
|
||||
- **Rewrite all kernels in Rust now:** CUDA/PTX remains necessary; parity/perf
|
||||
need proof. Reject as a big-bang first stage.
|
||||
- **Rust host + Python/C++ serving engine:** quick library reuse, but adds a
|
||||
second runtime and bridge. Reject for production; Python remains offline-only.
|
||||
|
||||
This is a staged C++/Python-to-Rust migration, not a literal syntax
|
||||
translation. Move ownership of serving behavior first. Keep CUDA C++ only at a
|
||||
small kernel boundary while each kernel is ported or replaced against a numeric
|
||||
oracle. The shipped Linux runtime should need an installed NVIDIA driver, not
|
||||
the CUDA toolkit, a compiler, Python, or a Strata installation. Build-time CUDA
|
||||
toolkit use is acceptable. The release gate must inspect the final artifact's
|
||||
ELF dependencies to prove the driver-only installation claim.
|
||||
This is a staged C++/Python-to-Rust migration, not syntax translation. Keep
|
||||
CUDA C++ only at a narrow kernel boundary until each replacement passes a
|
||||
numeric oracle. Serving should need an NVIDIA driver, not the toolkit,
|
||||
compiler, Python, or Strata; build-time CUDA is acceptable. Audit ELF at release.
|
||||
|
||||
## 2. Existing coupling inventory
|
||||
## 2. Existing Strata coupling
|
||||
|
||||
The current repository is an intermediate product. These references explain
|
||||
what Leleka must replace; they are not a requirement to copy the imported tree.
|
||||
These are source references to replace, not a requirement to copy the imported
|
||||
tree. The cited build/package sources distinguish serving, preparation, and
|
||||
test-only behavior.
|
||||
|
||||
| Area | Current source | What it means for independence |
|
||||
| --- | --- | --- |
|
||||
| CPU engine build | [`scripts/build-cpu.sh`](../../scripts/build-cpu.sh#L13) configures CMake from `engine/strata/` | Remove this from the Leleka build and release path |
|
||||
| CUDA engine build | [`scripts/build-static-cuda.sh`](../../scripts/build-static-cuda.sh#L14) compiles target `strata`; its checks run the imported engine's ELF audit and `--help` | Replace the engine source and qualify the new binary; do not call `--help` an inference test |
|
||||
| Hosted CUDA package workflow | [`.github/workflows/linux.yml`](../../.github/workflows/linux.yml#L139) builds the actual Strata engine; later steps combine and package it | Leleka CI must build its own runtime from pinned sources and retain build provenance |
|
||||
| CLI image license | [`deploy/Dockerfile.static-cli`](../../deploy/Dockerfile.static-cli#L13) copies the imported engine license into the CLI-only image | Preserve required notices for any source actually reused; remove the Strata license copy only when no Strata code is shipped |
|
||||
| Worker process boundary | [`worker.rs`](../../control-plane/src/worker.rs#L84) accepts an executable and arguments; the worker process is supervised and generation is sent to it | Replace the serving child process with an in-process Rust `InferenceBackend`; keep process isolation as an optional later boundary |
|
||||
| Strata serving wire | [`wire.rs`](../../control-plane/src/wire.rs#L1) explicitly implements the resident Strata `--serve` stdin/stdout protocol | Delete this adapter from the replacement path; the public API must not inherit this private wire protocol |
|
||||
| Embedded engine package | [`embedded_engine.rs`](../../control-plane/src/embedded_engine.rs#L1) stores and starts a separately built engine executable, and says model/shared libraries are not bundled | Package the Rust engine directly; model assets remain independently acquired and SHA-verified |
|
||||
| Qwen-only model prep | [`native_model.rs`](../../control-plane/src/native_model.rs#L30) has one `RuntimeProfile::Qwen4expFlashNext`; GGUF/native pack helpers are preparation code, not an inference implementation | Keep Qwen import/preparation behind a model adapter or offline tool; define a versioned model descriptor instead of extending a single-profile enum |
|
||||
| Build-time GGML C code | [`build.rs`](../../control-plane/build.rs#L6) compiles a vendored pinned `ggml-quants.c` plus `ggml_bridge.c`; [`ggml_bridge.rs`](../../control-plane/src/ggml_bridge.rs) uses it for GGUF quant conversion | This is a preprocessing dependency rather than serving inference. Move it to an optional offline packer crate so the shipped serving CLI does not need a C compiler or GGML bridge |
|
||||
| Offline scripts | [`compare-real-tokenizer.py`](../../scripts/compare-real-tokenizer.py), [`prepare-keyless-routing.py`](../../scripts/prepare-keyless-routing.py), and pack smoke scripts import Strata tools or inspect Strata sources | Replace or retire them one at a time; keep them out of serving and never silently treat their output as production support |
|
||||
| KAR experimental adapters | [`gpu/kar/README.md`](../../gpu/kar/README.md#L3) documents a narrow experimental expert component and explicit limits | Port the file/container concepts and proven kernels selectively; do not port the Strata callback as the new runtime boundary |
|
||||
| Provenance | [`docs/upstream.md`](../upstream.md#L1) pins the imported Strata SHA and describes subtree update procedure | Preserve this historical record unchanged. Add a separate Leleka source/provenance manifest; do not rewrite the old upstream identity |
|
||||
- **CPU build:** [`build-cpu.sh`](../../scripts/build-cpu.sh) configures
|
||||
CMake from `engine/strata/`. Remove it from Leleka build/release.
|
||||
- **CUDA build:** [`build-static-cuda.sh`](../../scripts/build-static-cuda.sh)
|
||||
builds `strata`, then ELF-audits it and runs GPU-hidden `--help`
|
||||
([audit](../../scripts/build-static-cuda.sh),
|
||||
[help](../../scripts/build-static-cuda.sh)). `--help` is not inference.
|
||||
- **Cargo embedding:** [`build.rs`](../../control-plane/build.rs) reads
|
||||
three `STRATA_EMBED_ENGINE_*` variables ([first](../../control-plane/build.rs),
|
||||
[last](../../control-plane/build.rs)); partial settings fail
|
||||
([check](../../control-plane/build.rs)). It verified-copies the payload
|
||||
([copy](../../control-plane/build.rs)) or emits empty bytes
|
||||
([empty case](../../control-plane/build.rs)). It also compiles vendored
|
||||
GGML C for prep ([sources](../../control-plane/build.rs),
|
||||
[compile](../../control-plane/build.rs)). Leleka replaces the embedded
|
||||
child with its Rust backend; prep code stays a separately gated tool/crate.
|
||||
- **Linux package:** [`build-linux-package.py`](../../scripts/build-linux-package.py)
|
||||
snapshots/hashes engine ([snapshot](../../scripts/build-linux-package.py)),
|
||||
sets embedding vars ([env](../../scripts/build-linux-package.py)),
|
||||
builds `x86_64-unknown-linux-musl` ([Cargo](../../scripts/build-linux-package.py)),
|
||||
probes identity/provision ([identity](../../scripts/build-linux-package.py),
|
||||
[provision](../../scripts/build-linux-package.py)), and writes provenance
|
||||
and SHA sums ([receipt](../../scripts/build-linux-package.py),
|
||||
[sums](../../scripts/build-linux-package.py)). It does not build OCI.
|
||||
- **OCI package:** [`build-runtime-image.py`](../../scripts/build-runtime-image.py)
|
||||
checks pinned base/package receipt ([freeze](../../scripts/build-runtime-image.py),
|
||||
[receipt](../../scripts/build-runtime-image.py)), then Docker-builds and
|
||||
probes ([build](../../scripts/build-runtime-image.py),
|
||||
[probes](../../scripts/build-runtime-image.py)).
|
||||
[`Dockerfile.runtime`](../../deploy/Dockerfile.runtime) copies executable
|
||||
and receipts ([copies](../../deploy/Dockerfile.runtime)) and sets entrypoint
|
||||
([entry](../../deploy/Dockerfile.runtime)). These consume, not compile,
|
||||
CUDA. Reuse only after changing the artifact contract to Leleka.
|
||||
- **Hosted workflow:** [`linux.yml`](../../.github/workflows/linux.yml)
|
||||
builds CUDA on hosted CPU ([runner](../../.github/workflows/linux.yml)),
|
||||
then packages it. Leleka needs its own pinned-source build and provenance.
|
||||
- **License:** [`Dockerfile.static-cli`](../../deploy/Dockerfile.static-cli)
|
||||
copies the engine license. Keep notices for reused code; remove only when no
|
||||
Strata code ships.
|
||||
- **Worker process:** [`worker.rs`](../../control-plane/src/worker.rs#L86)
|
||||
defines executable/args ([args](../../control-plane/src/worker.rs#L87)); it
|
||||
spawns a child ([spawn](../../control-plane/src/worker.rs)) and writes
|
||||
requests to stdin ([write](../../control-plane/src/worker.rs)). Replace
|
||||
serving child with in-process `InferenceBackend`; isolation may remain optional.
|
||||
- **Private wire:** [`wire.rs`](../../control-plane/src/wire.rs) serializes
|
||||
requests; [`parse_line`](../../control-plane/src/wire.rs) reads child events
|
||||
([worker arg](../../control-plane/src/worker.rs)). Do not expose this
|
||||
protocol as Leleka's public API.
|
||||
- **Embedded metadata:** [`embedded_engine.rs`](../../control-plane/src/embedded_engine.rs)
|
||||
resolves payload; metadata says shared libraries and models are not bundled
|
||||
([libraries](../../control-plane/src/embedded_engine.rs),
|
||||
[models](../../control-plane/src/embedded_engine.rs)). Its GPU-hidden
|
||||
probe is help-only ([call](../../control-plane/src/embedded_engine.rs)).
|
||||
- **Qwen prep:** [`native_model.rs`](../../control-plane/src/native_model.rs)
|
||||
has one `Qwen4expFlashNext` profile. GGUF/native pack helpers prepare data;
|
||||
they do not infer. Use a versioned model adapter/descriptor.
|
||||
- **GGML prep:** [`build.rs`](../../control-plane/build.rs) compiles vendored
|
||||
`ggml-quants.c` and `ggml_bridge.c` ([compile](../../control-plane/build.rs));
|
||||
[`ggml_bridge.rs`](../../control-plane/src/ggml_bridge.rs) validates block
|
||||
geometry ([dequant](../../control-plane/src/ggml_bridge.rs)). Move this
|
||||
prep-only dependency to an offline packer, not the serving CLI.
|
||||
- **Offline scripts:** [`compare-real-tokenizer.py`](../../scripts/compare-real-tokenizer.py)
|
||||
uses Strata's tokenizer oracle; [`prepare-keyless-routing.py`](../../scripts/prepare-keyless-routing.py)
|
||||
reads GGUF. Smoke harnesses load native-pack/MTP fixtures
|
||||
([native](../../scripts/smoke-native-pack.py),
|
||||
[MTP](../../scripts/smoke-mtp-pack.py)). Retire/replace individually;
|
||||
never treat offline output as production support.
|
||||
- **KAR:** [`gpu/kar/README.md`](../../gpu/kar/README.md) documents an
|
||||
experimental expert component, not full-model support; see cache limits
|
||||
([limits](../../gpu/kar/README.md)) and quality/speed caveat
|
||||
([caveat](../../gpu/kar/README.md)). Port only proven container/kernel
|
||||
behavior, not the Strata callback.
|
||||
- **Upstream record:** [`docs/upstream.md`](../upstream.md) records Strata SHA
|
||||
and update procedure ([update](../../docs/upstream.md)). Preserve it; add
|
||||
a separate Leleka provenance manifest.
|
||||
- **Responses API:** [`responses.rs`](../../control-plane/src/responses.rs)
|
||||
imports tokenizer/worker types ([wire](../../control-plane/src/responses.rs));
|
||||
[`/v1/responses`](../../control-plane/src/app.rs) routes to it. Keep HTTP,
|
||||
SSE, auth, cancellation, and health in Rust control plane with replay tests;
|
||||
call Leleka API instead of Strata tokenizer/process/wire.
|
||||
|
||||
`responses.rs` is a Rust protocol layer that currently consumes worker/tokenizer
|
||||
types. Its role can remain in the Rust control plane, but it must call the new
|
||||
backend API rather than depend on Strata's tokenizer, worker executable or
|
||||
wire format. The public `/v1/responses`, SSE, cancellation, auth and health
|
||||
contracts need their own replay tests; the model engine should not implement
|
||||
HTTP semantics.
|
||||
## 3. Current build dependency versions and pin status
|
||||
|
||||
## 3. Leleka backend boundary
|
||||
This inventory describes the current Gitea CUDA/package path at `e3ca464`.
|
||||
It does not claim that the independent engine is implemented or qualified.
|
||||
A version recorded in provenance is not necessarily an immutable build input.
|
||||
|
||||
### Ownership
|
||||
- **Rust:** `1.99.0`, minimal profile with `rustfmt` and `clippy`, fixed in
|
||||
[rust-toolchain.toml](../../rust-toolchain.toml). Workspace dependency versions
|
||||
and checksums are fixed by root [Cargo.lock](../../Cargo.lock), lock format 4.
|
||||
[install-pinned-rustup.sh](../../scripts/install-pinned-rustup.sh) fixes installer
|
||||
`1.29.0` and SHA-256
|
||||
`4acc9acc76d5079515b46346a485974457b5a79893cfb01112423c89aeb5aa10`.
|
||||
The `rust:1.99-bookworm` CLI builder tag is not digest-pinned.
|
||||
- **CUDA:** redistributable release `13.0.1`, manifest SHA-256
|
||||
`9c494bc13b34e8fbcad083a6486d185b0906068b821722502edf9d0e3bd14096`.
|
||||
[cuda-toolkit.lock.json](../../deploy/cuda-toolkit.lock.json) pins seven archive
|
||||
hashes: `cuda_nvcc`, `cuda_crt`, `cuda_cudart`, `libnvvm` at `13.0.88`;
|
||||
`cuda_cccl`, `cuda_culibos` at `13.0.85`; `libcublas` at `13.0.2.14`.
|
||||
These are build inputs; they do not pin or install the host NVIDIA driver.
|
||||
- **CUDA compiler container:** Ubuntu 24.04 amd64 base digest
|
||||
`f610ab94648195aa356059f5b41d6085c9d4d903c072430cdd1af7bdb646106b`
|
||||
in [Dockerfile.cuda-builder](../../deploy/Dockerfile.cuda-builder).
|
||||
Hosted CUDA compiles inside this GPU-hidden Docker container on a CPU runner.
|
||||
GNU Make is the selected CMake generator's dependency. GCC/G++ major 13 is
|
||||
explicitly selected by [linux.yml](../../.github/workflows/linux.yml).
|
||||
Its apt package revisions, CMake, Make, binutils, Git, Python and CA packages
|
||||
are resolved from moving apt repositories; no apt snapshot is pinned.
|
||||
The runner CA bundle is copied into the builder; its contents are not pinned.
|
||||
- **Runner and packaging:** `ubuntu-latest` is the available Gitea runner label,
|
||||
not an immutable OS image. Host apt supplies `ca-certificates`, `musl-tools`,
|
||||
`binutils`, `docker.io`, `python3`; the musl package step also requires
|
||||
`/usr/bin/time`, which its current install list does not provide explicitly.
|
||||
Runner image, Bash, utilities, Docker CLI/daemon,
|
||||
BuildKit and host apt revisions remain unpinned. Exact CUDA builder image ID,
|
||||
package revisions, GCC/NVCC output and source SHA are recorded in provenance.
|
||||
- **OCI runtime:** [build-runtime-image.py](../../scripts/build-runtime-image.py)
|
||||
defaults to exact amd64 base digest
|
||||
`88a381d5b5eeb2b35d3ad70925a362c37ce569daf43ede89ff818ec20e4d3794`.
|
||||
It consumes the verified combined executable; it does not compile CUDA.
|
||||
The OCI base and compiler-container base are separate inputs.
|
||||
- **Actions:** `actions/checkout@v4`, `actions/upload-artifact@v4` and
|
||||
`actions/download-artifact@v4` in [linux.yml](../../.github/workflows/linux.yml)
|
||||
are major tags rather than immutable action commits.
|
||||
- **Runtime boundary:** outer Rust executable is static musl. The embedded
|
||||
legacy CUDA engine statically links its CUDA/C++ runtimes, while host driver
|
||||
and audited glibc/loader requirements remain. ELF checks in
|
||||
[check-static-cuda-elf.py](../../scripts/check-static-cuda-elf.py) and
|
||||
[build-linux-package.py](../../scripts/build-linux-package.py) define the
|
||||
actual dependency allowance. Static packaging alone does not remove Strata
|
||||
or prove installed-driver inference, model quality, or rollback.
|
||||
|
||||
Leleka is a Rust workspace with at least these logical crates:
|
||||
The current build is not hermetic: host/apt/action inputs can move. Python is
|
||||
used for offline build, conversion and evaluation only; production serving
|
||||
remains native. The replacement must retain provenance and narrow its final
|
||||
runtime dependencies to the driver contract through separate release gates.
|
||||
|
||||
1. `leleka-api`: versioned request, model descriptor, capability, memory-plan,
|
||||
error and event types. No CUDA or model implementation dependency.
|
||||
2. `leleka-engine`: Rust-owned model loader, tensor/layout registry, tokenizer
|
||||
integration, router, KV allocator, scheduler, sampling and lifecycle.
|
||||
3. `leleka-cuda`: safe Rust wrappers over a narrow private CUDA C ABI. It owns
|
||||
device/context/stream/event/buffer lifetimes; kernels cannot retain pointers
|
||||
after the wrapper's borrow or stream completion.
|
||||
4. `leleka-server`: HTTP/API translation, SSE, auth, cancellation and
|
||||
observability. It talks to `leleka-api`, not to model-specific tensor layouts.
|
||||
5. `leleka-tools`: offline conversion/evaluation only. It is not a dependency
|
||||
of the serving binary and may contain Python during the transition.
|
||||
## 4. Leleka backend boundary
|
||||
|
||||
The initial backend is compiled into the process. Rust trait objects are not a
|
||||
stable cross-version plugin ABI; if external native plugins are needed later,
|
||||
define a layout-safe C ABI with explicit size/version fields and opaque handles.
|
||||
Proposed Rust workspace:
|
||||
|
||||
### Versioned contract (proposal)
|
||||
- `leleka-api`: versioned requests, model/capability/memory/error/event types;
|
||||
no CUDA or model implementation dependency.
|
||||
- `leleka-engine`: loader, tensor/layout registry, tokenizer, router, KV,
|
||||
scheduler, sampling, and lifecycle.
|
||||
- `leleka-cuda`: safe Rust over private CUDA C ABI; owns device/context/stream/
|
||||
event/buffer lifetimes. Kernels cannot retain pointers past borrow/completion.
|
||||
- `leleka-server`: HTTP/SSE/auth/cancel/observability; uses API, not tensor layouts.
|
||||
- `leleka-tools`: offline conversion/evaluation only; Python may remain here.
|
||||
|
||||
`leleka-api` has an explicit `API_MAJOR` and a capability-schema version.
|
||||
Incompatible event, layout or error semantic changes increment the major
|
||||
version. Release metadata records engine commit, CUDA kernel source digests,
|
||||
toolchain, model adapter version and supported quantization IDs.
|
||||
Compile the initial backend in-process. Rust trait objects are not a stable
|
||||
cross-version plugin ABI; add a versioned C ABI with opaque handles only if
|
||||
external plugins become a real requirement.
|
||||
|
||||
The backend contract contains these operations:
|
||||
### Versioned API proposal
|
||||
|
||||
- `capabilities() -> CapabilitySet`: architecture IDs, quantization/layout
|
||||
identifiers, attention/KV forms, limits, cancellation and streaming support.
|
||||
- `load(ModelArtifact, ModelConfig) -> LoadedModel`: validate artifact digest,
|
||||
descriptor, hardware/driver constraints and required tensors before publishing
|
||||
a ready model. Partial failure drops all owned allocations.
|
||||
- `memory_plan(ModelDescriptor, RequestDemand) -> MemoryPlan` and
|
||||
`admit(MemoryPlan) -> Result<Admission, InsufficientMemory>`: account for
|
||||
weights, cache, KV, scratch/workspace, simultaneous slots and safety margin;
|
||||
reject before mutation when the request cannot fit.
|
||||
- `health()`, `readiness()` and `model_metadata()`: readiness is false until
|
||||
weights, kernels, tokenizer and required runtime state are verified.
|
||||
- `generate(Request, CancellationToken) -> Stream<BackendEvent>`: stream
|
||||
token IDs and optional token bytes/diagnostics plus a single terminal result.
|
||||
The server maps those events to Responses/chat SSE. The stream has bounded
|
||||
backpressure and a request ID.
|
||||
- `cancel(request_id)` and `drain(deadline)`: stop future work, cancel active
|
||||
work at a documented safe boundary, then release allocations exactly once.
|
||||
- `unload()`: reject new admissions, drain/cancel according to policy, release
|
||||
model/KV/cache ownership, then report unloaded.
|
||||
`leleka-api` declares `API_MAJOR` and capability-schema version. Breaking event,
|
||||
layout, or error semantics increment major. Release metadata records engine
|
||||
commit, CUDA source digests, toolchain, adapter version, and quantization IDs.
|
||||
|
||||
Errors are typed: `UnsupportedArchitecture`, `UnsupportedQuantization`,
|
||||
- `capabilities()`: architecture, quant/layout, attention/KV, limits, stream,
|
||||
cancellation support.
|
||||
- `load(artifact, config)`: validate digests, descriptor, hardware/driver, and
|
||||
tensors before ready; partial failure releases allocations.
|
||||
- `memory_plan()` / `admit()`: budget weights, cache, KV, scratch, slots, margin;
|
||||
reject before mutation if the request does not fit.
|
||||
- `health()`, `readiness()`, `model_metadata()`: ready only after weights,
|
||||
kernels, tokenizer, and required runtime state are verified.
|
||||
- `generate(request, cancellation)`: bounded stream of token IDs/events and one
|
||||
terminal result; server maps events to Responses/chat SSE.
|
||||
- On upstream disconnect before terminal completion, classify the attempt as
|
||||
`UpstreamIncomplete` and retry automatically with bounded attempts and the
|
||||
same request/idempotency key. Never dispatch a partial or malformed tool call.
|
||||
- Reconcile retries with emitted events: do not replay visible deltas as if
|
||||
they were new. Use explicit resumable/attempt sequencing, or stop with a
|
||||
retryable incomplete result when transparent replay is unsafe.
|
||||
- `cancel(id)` / `drain(deadline)`: stop admission, cancel at safe boundary, and
|
||||
release allocations exactly once.
|
||||
- `unload()`: reject admissions, drain/cancel by policy, release model/KV/cache,
|
||||
then report unloaded.
|
||||
|
||||
Typed errors: `UnsupportedArchitecture`, `UnsupportedQuantization`,
|
||||
`UnsupportedCapability`, `ArtifactMismatch`, `InsufficientMemory`,
|
||||
`DriverIncompatible`, `LoadFailure`, `Cancelled`, `DeadlineExceeded`,
|
||||
`DeviceLost`, `BackendFault`, and `ProtocolViolation`. No unsupported format
|
||||
may silently fall back to a lossy conversion. Every accepted generation emits
|
||||
exactly one terminal event (`completed`, `cancelled`, `length`, or `failed`);
|
||||
after a terminal event no more deltas for that request are legal. Error details
|
||||
are machine-readable and safe for API mapping; raw prompts, model tensors and
|
||||
secret values are never diagnostics.
|
||||
`DeviceLost`, `BackendFault`, `ProtocolViolation`. Never silently convert to a
|
||||
lossy format. Each accepted request has exactly one `completed`, `cancelled`,
|
||||
`length`, or `failed` terminal event; no later delta is legal. Diagnostics are
|
||||
machine-readable and exclude prompts, tensors, and secrets.
|
||||
|
||||
The model descriptor is immutable per loaded model and includes architecture
|
||||
family/revision, layer and expert geometry, router semantics, attention/KV
|
||||
layout, tokenizer/template digests, tensor names/shapes, quantization scheme,
|
||||
packing schema, context bound, required auxiliary heads and artifact digest.
|
||||
Model-family names alone do not authorize tensor reinterpretation.
|
||||
Immutable model descriptor binds family/revision, layer/expert geometry, router,
|
||||
attention/KV, tokenizer/template digests, tensor shapes, quantization/packing,
|
||||
context, auxiliary heads, and artifact digest. Family name alone never permits
|
||||
tensor reinterpretation.
|
||||
|
||||
## 4. Capability and optimization portability
|
||||
## 5. Optimization portability and safe fallback
|
||||
|
||||
| Concept | Reusable part | Model/quantization-specific part | Safe behavior until qualified |
|
||||
| --- | --- | --- | --- |
|
||||
| Compressed weights resident in VRAM | Block store, byte-range validation, residency planner and bounded scratch allocation | Archive/tensor mapping, scale/group geometry, codebook and dequant arithmetic | Accept only exact versioned pack schema and tensor digest; otherwise reject or use an explicitly supported native format |
|
||||
| Bounded expert cache | LRU/admission/eviction accounting and metrics | Expert IDs, dimensions, routing semantics, packed payload size and CUDA tile geometry | Cache only verified experts from the loaded descriptor; evict or fall back to a verified native path |
|
||||
| KAR decoder | Container reader and generic bounded decode orchestration after schema validation | Current KAR top-down group-32 expert shape, levels, quant bytes and F32 accumulation; current code does not establish model-quality parity | Experimental opt-in only; reject shape/schema mismatch; never claim full-model residency or speed from the component probe |
|
||||
| Expert routing and scheduling | Queue, batching windows, cancellation, fair admission and cost accounting | Router weights, top-k, shared/routed experts, normalization, correction bias and token-to-expert mapping | Use the model adapter's exact reference routing; unsupported router versions fail closed |
|
||||
| KV allocation/streaming | Page/slot allocator, budget policy, asynchronous transfer lifecycle and accounting | MHA/GQA/MLA tensor layout, head sizes, position encoding, quantization, scales and block packing | Select only a declared KV format supported by that adapter; otherwise reject or use its verified lossless/default format |
|
||||
| PLE | Sparse table paging/cache and row-request abstraction | Table meaning, lookup geometry, packing and exact association with model layers/experts | Disable unless manifest binds PLE artifact to model digest and adapter validates geometry |
|
||||
| MTP/speculative decoding | Draft/verify scheduler mechanics and accepted-token counters | Trained draft heads, tokenizer, logits alignment, depth and model-specific verification semantics | Disable by default; enable only for an artifact declaring compatible heads and after exact greedy/quality gates |
|
||||
| Value-only KV / lossy KV | Cache policy experiments and measurement hooks | Quality behavior depends on the exact model, workload, context and cache policy | Keep disabled; the existing Qwen V-only pretrained quality screen failed |
|
||||
| Tokenizer and chat template | Byte streaming and API event mapping | Vocabulary, merge rules, special tokens, template and tool-call grammar | Require matching digests; no approximate tokenizer/template fallback |
|
||||
- **Compressed weights:** share block store/range checks/residency/scratch;
|
||||
mapping, scales, groups, codebook, and dequant are format-specific. Require
|
||||
exact pack schema/digest or reject/use declared native format.
|
||||
- **Expert cache:** share LRU/admission/eviction/accounting; expert geometry,
|
||||
routing, payload, and CUDA tiles are adapter-specific. Cache verified experts;
|
||||
evict or use verified native path.
|
||||
- **KAR:** share container/bounded decode after schema validation; current
|
||||
group-32 shape, levels, bytes, F32 accumulation are specific. Experimental;
|
||||
reject mismatch. No quality/full-model/speed claim from component probe.
|
||||
- **Routing/scheduling:** share queue/batching/cancel/fair admission; router
|
||||
weights, top-k, normalization, bias, and expert mapping are specific. Match
|
||||
reference router or fail closed.
|
||||
- **KV:** share allocator/budget/transfer accounting; MHA/GQA/MLA, heads, RoPE,
|
||||
quant/scales/packing are specific. Use declared adapter format or reject.
|
||||
- **PLE:** share table paging/cache abstraction; meaning, geometry, packing and
|
||||
layer binding are model-specific. Disable without model-digest-bound manifest.
|
||||
- **MTP/speculation:** share draft/verify scheduler/counters; trained heads,
|
||||
tokenizer, logits, depth, verification are specific. Off by default; require
|
||||
compatible artifact and greedy/quality gates.
|
||||
- **Lossy/value-only KV:** experiments/hooks are generic; quality is model,
|
||||
workload and context-specific. Keep disabled; Qwen V-only quality screen failed.
|
||||
- **Tokenizer/template:** share byte streaming/API mapping; vocabulary, tokens,
|
||||
template and tool grammar are specific. Require matching digests; no fallback.
|
||||
|
||||
“MoE-compatible” means the model uses sparse experts, not that its weights,
|
||||
router, attention, tokenizer, cache, quantization or speculative heads can be
|
||||
reused. Every matrix row must be keyed by a model and pack manifest, not a broad
|
||||
architecture label.
|
||||
MoE means sparse experts; it does not make weights, router, attention,
|
||||
tokenizer, cache, quantization, or draft heads interchangeable. Key each claim
|
||||
to model and pack manifests, never a broad architecture label.
|
||||
|
||||
## 5. Candidate model families and evidence gaps
|
||||
## 6. Candidate families, not supported models
|
||||
|
||||
These are adapter/evaluation candidates, not supported models.
|
||||
- **Mixtral-8x7B-v0.1:** official
|
||||
[model card](https://huggingface.co/mistralai/Mixtral-8x7B-v0.1) lists
|
||||
Apache-2.0 and sparse MoE; weights/reference runtime make tensor/logit and
|
||||
greedy-token oracles feasible. Needs a separate safetensors/router adapter
|
||||
and documented quant pack; do not reuse Qwen IQ3. No tensor map, converted
|
||||
artifact, quality corpus, or protocol trace is checked in. 32-GB useful-context
|
||||
fit is unproven.
|
||||
- **DeepSeek-V2-Lite:** official
|
||||
[model card](https://huggingface.co/deepseek-ai/DeepSeek-V2-Lite) lists
|
||||
16B total / 2.4B active, safetensors, and its use-based license;
|
||||
[paper](https://arxiv.org/abs/2405.04434) describes MLA + DeepSeekMoE. Needs
|
||||
separate latent-KV/router adapter; published context is 32K, not Qwen
|
||||
256K/512K. License review, converted artifact, quality/protocol evidence,
|
||||
and 32-GB launch remain open.
|
||||
|
||||
| Candidate | Public artifact and license evidence | Compatibility and the first port-specific work | Evaluation feasibility and blocker |
|
||||
| --- | --- | --- | --- |
|
||||
| Mistral Mixtral-8x7B-v0.1 | Official [model card](https://huggingface.co/mistralai/Mixtral-8x7B-v0.1) lists Apache-2.0 and describes a sparse MoE; official weights are available | Conventional attention plus sparse expert feed-forward gives a second-vendor router/weight-map adapter. Validate safetensors mapping and select a documented quant pack; do not reuse Qwen IQ3 conversion | Public reference weights and a reference runtime make tensor/logit and greedy-token oracle generation feasible. No Mixtral tensor map, converted artifact, quality corpus, or protocol trace is currently checked in; 32-GB fit at useful context depends on quantization and remains unproven |
|
||||
| DeepSeek-V2-Lite | Official [model card](https://huggingface.co/deepseek-ai/DeepSeek-V2-Lite) lists 16B total / 2.4B active parameters, safetensors and the DeepSeek model license; the [paper](https://arxiv.org/abs/2405.04434) describes MLA + DeepSeekMoE | Distinct latent-attention KV state and DeepSeekMoE routing require a separate attention/KV and router adapter. Published model context is 32K; do not assume Qwen's 256K/512K profile | Public reference weights/paper permit an adapter smoke and deterministic oracle suite. The model license has use-based conditions; compliance review and the exact license must accompany any distribution. No converted artifact or project quality/protocol evidence exists; 32-GB quantized launch and long-context target are unproven |
|
||||
Qwen3 MoE is a lower-variance first adapter but does not add a second vendor or
|
||||
attention family. Mixtral and DeepSeek expand architecture coverage; lawful
|
||||
weights and evaluation corpus are prerequisites.
|
||||
|
||||
If the owner wants the first extra family to be easier to serve on a 32-GB
|
||||
card, Qwen3 MoE is a lower-variance adapter step but does not demonstrate a
|
||||
second vendor or distinct attention family. Mixtral and DeepSeek-V2-Lite are
|
||||
therefore the stronger architecture-coverage candidates; lawful artifact
|
||||
selection and evaluation-data availability remain explicit gates.
|
||||
## 7. Migration and qualification gates
|
||||
|
||||
## 6. Migration and qualification stages
|
||||
1. **Foundation:** clean Leleka Rust workspace; provenance/licenses; pinned
|
||||
Rust/CUDA inputs; versioned API; mock lifecycle/cancel/admission tests.
|
||||
2. **Qwen correctness:** one lossless pack; compare tokenizer IDs, tensor/dequant
|
||||
bytes, routing, logits, greedy tokens to pinned reference. Replay sanitized
|
||||
protocol traces for SSE, disconnect/retry before and after deltas, partial
|
||||
tool calls, at-most-once dispatch, cancel, timeout, reconnect, and worker/device loss.
|
||||
3. **NVIDIA artifact:** reproducible executable/image. On clean driver host,
|
||||
audit ELF, load model, readiness, API/cancel, restart, rollback. No Strata,
|
||||
Python, CUDA toolkit, or compilers at host install; pin model assets.
|
||||
4. **Optimizations:** port residency, KV, KAR, PLE/MTP one at a time, each with
|
||||
numeric oracle and separate quality gate. Lossy/experimental stays off.
|
||||
Retain CUDA kernels only after parity and paired end-to-end gain.
|
||||
5. **Families:** separate Mixtral and DeepSeek adapters, exact quant, protocol/
|
||||
quality suites, and license review. One passing family grants no others.
|
||||
6. **Cutover:** retain Strata as reference until protocol/model/quality/deploy
|
||||
suites pass. Paired workload, recorded config/cache/tokens, canary service,
|
||||
rollback artifact; remove Strata from release only after acceptance.
|
||||
|
||||
1. **Repository and interface foundation (Leleka).** Create a clean Rust
|
||||
workspace in the new Gitea repo, record licenses/provenance, pin Rust/CUDA
|
||||
build inputs, define the API/capability schema, and add mock-backend
|
||||
lifecycle/cancellation/memory-admission tests. No model or GPU is needed.
|
||||
2. **Qwen correctness path.** Add a Qwen adapter and one explicit lossless
|
||||
quant/pack path. Compare tokenizer IDs, tensor loads/dequant bytes, routing,
|
||||
logits and greedy token IDs against the pinned reference. Then replay
|
||||
sanitized real protocol traces: non-streaming, SSE terminal events, tool
|
||||
calls/results, cancellation, timeout, reconnect and worker/device failure.
|
||||
3. **Linux NVIDIA runtime artifact.** Build a reproducible self-contained
|
||||
executable/image in CI. On a clean Linux host with an NVIDIA driver, audit
|
||||
ELF dependencies, load the model, verify readiness, exercise API/cancel,
|
||||
stop/restart and rollback. Host installation must not need Strata, Python,
|
||||
CUDA toolkit or compilers. Model assets remain separately pinned and
|
||||
integrity-checked.
|
||||
4. **Port optimizations one at a time.** Start with bounded expert residency,
|
||||
then KV policy/streaming, then exact-format KAR work, then optional PLE/MTP.
|
||||
Each stage has a numeric oracle and its own isolated quality gate; lossy or
|
||||
experimental arms remain off by default. Port CUDA kernels only when exact
|
||||
output/tensor requirements pass and paired end-to-end measurements justify
|
||||
keeping them.
|
||||
5. **Model-family expansion.** Land Mixtral adapter + exact quant path and
|
||||
protocol/quality suite; separately land DeepSeek-V2-Lite with MLA/KV tests
|
||||
and license review. Passing one family does not imply support for other MoE
|
||||
variants.
|
||||
6. **Cutover.** Preserve Strata as the reference until the same sanitized API,
|
||||
model, quality and deployment suites pass. Run a controlled paired workload
|
||||
comparison with engine/model/config/cache/token counts recorded. Canary on a
|
||||
separate port/service with artifact rollback; keep the last accepted
|
||||
runtime selectable until the new build passes gates. Only after acceptance
|
||||
remove Strata from the Leleka production/release path; retain historical
|
||||
source provenance in `strata-next`.
|
||||
Compilation, synthetic kernels, mocks, source inspection, or model loading alone
|
||||
do not prove performance or quality. Required profiles remain `1 x 512K` and
|
||||
`2 x 256K`; `1 x 256K` is interim only.
|
||||
|
||||
No stage claims performance from compilation, synthetic kernels, mock-backend
|
||||
tests, source inspection, or model loading alone. Required project profiles
|
||||
remain `1 x 512K` and `2 x 256K` on the stated target; `1 x 256K` is an interim
|
||||
local profile and cannot stand in for them.
|
||||
## 8. Immediate Leleka work breakdown
|
||||
|
||||
## 7. Immediate implementation work breakdown
|
||||
After TL acceptance, create bounded tasks:
|
||||
|
||||
The next implementation tasks belong in Leleka, after this handoff receives
|
||||
Tech Lead acceptance:
|
||||
1. Clean repo/CI and versioned `leleka-api`; mock backend, no Strata dependency.
|
||||
2. Move API/events behind the crate; test lifecycle, cancel, terminal-event,
|
||||
and admission contracts.
|
||||
3. Split offline GGUF/tokenizer prep from serving; pin sources/assets; no
|
||||
production Python.
|
||||
4. Add Rust loader and safe CUDA wrapper; CPU/mock + driver contract first.
|
||||
5. Implement one Qwen lossless path; exact parity and reserved-host GPU/protocol/
|
||||
quality gates.
|
||||
6. Create Mixtral/DeepSeek tasks only after licensed weights, quant path, and
|
||||
evaluation corpus are pinned.
|
||||
|
||||
1. Establish clean repo/CI and the versioned `leleka-api` crate with a mock
|
||||
backend; verify no Strata import/build/runtime dependency.
|
||||
2. Move the Rust control-plane event/API contract behind `leleka-api`; add
|
||||
lifecycle, cancellation, single-terminal-event and admission tests.
|
||||
3. Split offline GGUF/tokenizer preparation from the serving build; pin source
|
||||
and artifact digests, with no production Python import.
|
||||
4. Add the Rust-owned engine/model-loader skeleton and CUDA safe-wrapper crate;
|
||||
first acceptance is CPU/mock behavior plus CUDA driver/toolchain contract,
|
||||
not GPU inference.
|
||||
5. Implement one Qwen lossless model path, exact numerical/token parity, then
|
||||
run its real NVIDIA/protocol/quality gates on a host explicitly reserved for
|
||||
qualification.
|
||||
6. Create separately scoped Mixtral and DeepSeek adapter tasks only after the
|
||||
corresponding legal artifact, supported quantization and evaluation corpus
|
||||
are pinned.
|
||||
|
||||
These are proposed bounded work items, not evidence that the deliverables
|
||||
already exist. The new repository was empty at the time of this handoff; no
|
||||
model files, traces, credentials, build artifacts or user workload data are
|
||||
copied into it.
|
||||
These are proposals, not delivered features. No models, traces, credentials,
|
||||
build artifacts, or user workload data are copied into Leleka.
|
||||
|
||||
Reference in New Issue
Block a user