Fix all DSpark speculative bottlenecks and long-context/multi-turn bugs: - Single-pass base-unembed Top-512 screen + on-GPU Markov loop & argmax (reads 922 MB unembed once per round, <=32 B D2H). - On-GPU batched verify argmax + forward_batch_taps_no_logits (eliminates double unembed and 4.8 MB D2H per round). - Wave32 online-softmax dspark_block_attn (0 bytes LDS, fixes >16.2k token crash on Global layer 1; regression-tested at c_len=17000). - Vectorized M-tiled Wave32 router_gemv_batched, zero-scratch small-M SWA GQA, WMMA gemm_bf16 for m>=1, fdot2 MoE for b<=12. - Persistent DsparkContext + PrefixCache DsparkSnapshot save/restore (multi-turn RESUME parity tested). - Accepted-count EMA governor starting at n_draft=5 (adapts 2..7). - Docs (README.md, docs/ORIENTATION.md) + changelog in review/2026-12-02-fix-drafter-e-ottimizzazioni.md. Measured on gfx1150 (Inkling-2-Mini, temperature=0, 100% greedy EXACT): - Rust coding (RingBuffer<T>, 128 tok): OFF 6.83 -> VETTA_SPEC=1 13.93 tok/s (2.04x, n_draft=5; strata-inkling 13.66 tok/s). - Short prose (capital, 96 tok): nd=5 4.58 -> 9.09 tok/s (+98.5%); adaptive EMA 8.93 tok/s decode. Validated: cargo test --workspace (-D warnings), all 7 Lean 4 proofs (0 sorryAx), HIP/LD/GW GPU parity gates.
9.3 KiB
9.3 KiB
vetta-infer
MoE-first microkernel inference engine in Rust + minimal AMD ROCm HIP kernels.
Built from the measured hardware physics and engineering lessons of our hardened C++/HIP baseline (strata), targeting unified-memory AMD RDNA 3.5 APUs (Sogliola: Ryzen AI 9 HX 370 / Radeon 890M gfx1150, 48 GiB VRAM carveout + 96 GiB UMA, 81.7 GB/s DRAM, 44 TFLOP/s INT8 WMMA, dual Gen4 NVMe) with optional LAN co-processing on Lyra (2.5 Gbps Ethernet).
New here? If you come from vLLM / llama.cpp / SGLang, read
docs/ORIENTATION.mdfirst — it explains the mental model, the crate map, the honest current state, and the road to the goal.
Core Design Principles
- MoE-first on UMA (
gfx1150): designed vertically around sparse Mixture-of-Experts architectures (Transformer SWA/Full + Vision, Hybrid GDN+GQA, native MTP / Block-Diffusion). Large dense decoder LMs are out of scope (bandwidth physics); small fully-resident utility encoders (BGE-M3 embedder lane, M1.5) are in. - Direct
.safetensors+ Write-OnceO_RDONLYNVMe Cache: zero GGUF conversion, zero SSD wear after initial atomic pack (.tmp.<pid>+fsync+rename), checkedu64bounds everywhere. - Zero-Copy UMA + NVMe DMA Streaming (
SlabRing):io_uring O_DIRECTinto page-aligned buffers mapped directly to GPU viahipHostRegister(zero CPU copy, zerohipMemcpy), with Hot/Cold expert caching + lookahead prefetch for 100B–300B+ MoE models. - Pure-Rust Control Plane + 16 Reusable HIP Microkernels: all scheduling, safetensors/cache I/O, wire protocol (
strata-ctlcompatible, includingGEN 0pre-warm), deterministic zero-alloc sampling, speculative verification, and telemetry live in 100% CPU-testable Rust; GPU compute is isolated behind a thin C/HIP microkernel ABI. - First-Class Inference Telemetry: lock-free statistics capture (per-layer expert routing Zipf curves,
L -> L+1co-activation transitions, domain profiles, speculative acceptance histograms, logit entropy, cache hit/miss, GPU phase timings) exported to JSONL with negligible runtime overhead. - Lean 4 Verified State Machines: every critical concurrency/lifetime/prefix invariant is modeled and machine-checked in Lean 4 (
proofs/, 0sorryAx) before implementation. - LAN Control/Compute Split (Sogliola + Lyra): pluggable
DraftProviderandPrefetchAdvisortraits allow running remote speculative drafting, domain routing, or lightweight Vision/RAG on Lyra over 2.5 Gbps LAN (< 1 KB/step,~0.3 msRTT).
Workspace Layout
| Path | Responsibility |
|---|---|
crates/vetta-infer-abi |
Shared contracts: domain types, bus messages, .vplan opcodes, wire parsing, checked JSON/VTC1 parsers, zero-alloc sampler & Leviathan verifier, DraftProvider/PrefetchAdvisor traits, arena-safety validator, .vbundle manifest/plan compile (zero deps) |
crates/vetta-infer-kn |
Pure microkernel: control bus, service registry & lifecycle (Lean-verified), UMA/DMA broker (SlabRing + UmaSlabPool) |
crates/vetta-infer-ld |
Loader & compiler: checked .safetensors reader, write-once VTC1 atomic writer, read-only .vbundle plan loading; dual-step packer → .vbundle/ (M1) |
crates/vetta-infer-cc |
Cache & storage: Hot/Cold MoE expert policy, O_RDONLY cache reload; io_uring O_DIRECT streaming (M2) |
crates/vetta-infer-rt |
Operational runtime: PrefixState typestate + hybrid checkpoint pool; CompiledPlan executor + HIP FFI (M1) |
crates/vetta-infer-lab |
Laboratory runtime: same executor core as rt + probe.vplan hooks |
crates/vetta-infer-sp |
Speculative coordinator: faithful throughput-aware Adaptive-K (port of clover_policy.h) |
crates/vetta-infer-nt |
Lyra LAN bridge: LyraRpc (remote drafting, domain hints) |
crates/vetta-infer-tm |
Telemetry: lock-free routing/Zipf/domain/spec stats, async JSONL sink |
crates/vetta-infer-gw |
Gateway & CLI: strata-ctl-compatible wire emitters, Lean-verified serve-session FSM, vetta-infer binary (info, version; serve/bench/stats with M1) |
kernels/hip |
Minimal reusable RDNA 3.5 HIP microkernels (Q8_G64_T16, Q4_G64_T16 SWAR, Chunkwise GDN, FlashAttn/GQA, MoE route/WMMA, GPU top-64 sampling) |
proofs/ |
Lean 4 formal contracts (0 sorryAx, audited axioms) |
Milestones
- M0 (Foundation — done): Workspace skeleton, Lean contracts (
slab_ring_dma.lean), checked IO, serve parsing, telemetry, HIP ABI, full CPU test suite. - M0.5 (Architecture realignment — done): approved microkernel design fixed in
docs/ARCHITECTURE.md; crates realigned tovetta-infer-*(abi/kn/ld/cc/rt/lab/sp/nt/tm/gw); bus lifecycle Lean-verified (bus_lifecycle.lean); faithful Adaptive-K port;strata-ctlwire emitters +image=key. - M1 (Resident MoE End-to-End — Target 1:
Inkling-2-Mini, inference landed): full 48-visit forward on realgfx1150weights, EXACT multi-token greedy parity vs thestratareference (per-pass KV pools + unpadded vocab 200058),strata-ctldrop-in--servelink (OpenAI-compatible API, field-for-field wire). Serve-session FSM (serve_session.lean), arena safety (arena_plan.lean+abi::arena),.vbundlecontract (abi::bundle+ld::bundle), loop proof (inkling_loop.lean). Speed vs C++ baseline (>= 18 tok/s,< 4 sreload) is the remaining M2 work.- 🎉 First real interactive GUI conversation — 2026-12-01 (measured): via the
strata-ctlweb GUI on Sogliola, "Ciao, sono Federico" → "Ciao Federico! Piacere di conoscerti. Come posso aiutarti oggi?" — 2650 prompt + 53 completion tokens · 4.2 tok/s decode · first token 618 s (the 618 s is sequential prefill of the ~2650-token agent prompt, ~140 ms/token; decode ~4.2 tok/s). Host-CPU busy-wait eliminated viahipDeviceScheduleBlockingSync(measured A/B 101.2% → 54.2%); the residual ~54% is kernel-launch cost, removed by HIP graph capture (M2). - ⚡ Prefill batched + tensor-core — 2026-12-02 (measured): chunked batched forward (M=B) + FP16 WMMA grouped MoE + BF16 WMMA dense projections + FlashAttention-2 WMMA prefill (P staged in LDS, no global scores scratch). Synthetic 2048-token prefill on
gfx1150(FP16 KV, chunk 256): 60 s → 12.9 s (-78%), ~6.3 ms/token (a 16 k-token agent prompt ~105 s, was ~7 min). Greedy-vs-reference stays EXACT (blocking gate); internal M=1-vs-M=B parity relaxed to a global-scale tolerance (approved P1 policy). The 618 s first-token above is historical (sequential prefill). - 🧠 Flat VRAM + long-prompt clamp — 2026-12-02: persistent per-layer KV/ShortConv states reused across requests (no ±3.75 GB alloc/free sawtooth), SWA-window checkpoints + prefix cache cap 8 (grid-protected, LRU-on-restore), 512 MiB buffer-pool cap; long→short session switches reuse the persistent KV. Generation budget clamped to the window (
clamp_max_new) instead of hard-erroring past 16382 prompt tokens with strata-ctl's fixed max_new=16384; window configurable viaserve --max-context N. Verified live: a 16504-token prompt generates (was ERR 0 tokens). - 🚀 DSpark speculative drafter (opt-in
VETTA_SPEC=1, 100% GPU) — 2026-12-02 (measured): single-pass base-unembed Top-512 screen + on-GPU Markov head + GPU verify argmax (<=32 BD2H), 0-LDS Wave32 online-softmax block attention (safe past 16k+ context), M-tiled Wave32 BF16 router GEMV, zero-scratch small-M SWA GQA,PrefixCacheDsparkSnapshotsave/restore for multi-turn, and accepted-count EMA governor (n_draftstarts at 5, adapts 2..7). Lossless contract proven inproofs/speculative_draft.lean(200-tokenspec_lossless_gateEXACT + multi-turnRESUMEEXACT). Measured ongfx1150(Inkling-2-Mini,temperature=0):- Rust coding prompt (
RingBuffer<T>, 128 tok): OFF6.83 tok/s→VETTA_SPEC=113.93 tok/s(2.04×,n_draft=5, 100% EXACT — matching/edgingstrata-inkling --draft dsparkat13.66 tok/s). - Short prose prompt (
"The capital of France is", 96 tok):nd=54.58 → 9.09 tok/s(+98.5%); adaptive EMA8.93 tok/sdecode.
- Rust coding prompt (
- 🎉 First real interactive GUI conversation — 2026-12-01 (measured): via the
- M1.5 (Embedder lane — BGE-M3): native encoder forward-pass (LayerNorm, bidirectional full-attn, GELU-erf, CLS pooling + L2 — recipe declared in the manifest), XLM-R importer, SPM tokenizer,
vetta-infer embedwire; acceptance cosine ≥ 0.999 vs the livevetta-semanticsoracle (:8091) + publisher fixture + anisotropy canary. Optional reranker head. May double as the HIP kernel bring-up bench. - M2 (Hybrid GDN + NVMe Zero-Copy DMA Streaming): DSpark drafter ✅ landed; next is layer streaming in DMA — the hard memory frontier: Chunkwise Parallel GDN (WY-representation, target
250–350+ ppts),Clover-35B-A3B& MTP MoE support,io_uring O_DIRECT+hipHostRegisterSlabRing, Hot/Cold expert cache + lookahead prefetch. - M3 (Distributed Control Plane — Lyra + Sogliola): Remote
DraftProvider+ domainPrefetchAdvisorover 2.5 Gbps LAN + live telemetry-driven domain expert pre-warming.
Quick Verification
# Lean 4 formal proofs (0 sorryAx, 7 files)
lean proofs/slab_ring_dma.lean
lean proofs/bus_lifecycle.lean
lean proofs/serve_session.lean
lean proofs/arena_plan.lean
lean proofs/inkling_loop.lean
lean proofs/prefix_cache.lean
lean proofs/speculative_draft.lean
# Pure-Rust workspace tests (no GPU required)
cargo test --workspace