# vetta-infer Architecture Blueprint ## 1. Hardware Ground Truth (Measured on Sogliola) | Resource | Measured Value | Architectural Implication | | --- | --- | --- | | GPU | AMD Radeon 890M (`gfx1150`, RDNA 3.5, 16 CU) | Wave32 native, `16×16×16` INT8 WMMA (`~44 TFLOP/s`), `16×16×16` FP16 WMMA (`22.14 TFLOP/s`) | | Memory | `48 GiB` VRAM carveout + `46 GiB` GTT/RAM (`96 GiB` UMA) | VRAM and RAM share the same LPDDR5X (`81.7 GB/s` raw, `~75 GB/s` sustained GEMM). Zero-copy `hipHostRegister` avoids redundant DRAM→DRAM copies | | Storage | Dual Gen4 NVMe (`~4.8 GB/s` single, `~9 GB/s` striped) | `O_RDONLY | O_DIRECT` + `io_uring` into `hipHostRegister` buffers gives **zero-copy NVMe → GPU DMA** on UMA | | LAN Peer | **Lyra** over `2.5 Gbps` Ethernet (`~300 MB/s`, `~0.3 ms` RTT) | Unsuitable for per-layer Tensor Parallelism; ideal for `<1 KB/step` remote drafting, domain routing, and Vision/RAG offload | ## 2. Crate Graph ``` ┌───────────────┐ │ vetta-cli │ └───────┬───────┘ ┌─────────┬───────┼───────┬───────────┐ ▼ ▼ ▼ ▼ ▼ vetta-proto vetta-io vetta-hip vetta-telemetry └─────────┴───────┼───────┴───────────┘ ▼ vetta-core ``` - **`vetta-core`:** zero external dependencies. Defines `QuantFormat`, `TensorMeta`, `SlabRing`, `PrefixState`, `HybridPrefixPool`, `SamplingOpts`, zero-alloc `build_truncated_dist`, `sample_logits_exact`, `verify_draft_exact` (Leviathan lossless), `AdaptiveKController`, `HotColdExpertCache`, `DraftProvider` and `PrefetchAdvisor` traits. - **`vetta-io`:** single checked `.safetensors` reader (`model.safetensors.index.json` + directory fallback + `pread` + overflow-safe slice checks) and single write-once `O_RDONLY` NVMe cache format (`VTC1`, FNV-1a fingerprint, pre-reserve count check, PID-isolated `.tmp.` atomic commit). - **`vetta-proto`:** single `strata-ctl`-compatible line protocol (`INFO`, `READY`, `GEN` including `GEN 0` pre-warm, `RESUME`, `PP`, `T`, `DONE`, `ERR`, `STOP`, `QUIT`, `RESET`) plus compact binary/text messages for Lyra LAN RPC (`DraftReq/DraftResp`, `DomainHint`). - **`vetta-telemetry`:** lock-free ring buffer + background JSONL writer collecting: - per-layer MoE expert activation counts (Zipf curves) and `L -> L+1` transition frequencies; - domain-tagged expert profiles (fed back to `PrefetchAdvisor` for NVMe Hot/Cold pre-warming); - speculative acceptance histograms (`acc[0..=K]`), `ms/tok`, logit entropy, top1-top2 margin, cache hit/miss, DMA bandwidth. - **`vetta-hip`:** thin FFI to `kernels/hip/` (compiled via ROCm `clang++ --offload-arch=gfx1150`) with RAII `DeviceBuf` / `PinnedUmaBuf` bound to HIP events/fences, plus a CPU mock backend for CI/unit testing without a GPU. ## 3. Minimal Reusable HIP Microkernel Set (`< 15` Primitives) 1. `k_embed_bf16` — BF16 embedding gather 2. `k_rms_norm` — fused RMSNorm (+ optional residual add / `+1.0` weight offset) 3. `k_quantize_x_g64` — per-64 activation INT8 quantization (fusable with SwiGLU) 4. `k_gemm_q8_g64_t16` — native RDNA 3.5 INT8 WMMA (`[N/16, K/64, 4, 16, 16]`, FP16 scales) 5. `k_gemm_q4_g64_t16` — SWAR 3-instruction INT4→INT8 WMMA (`0.5625 B/param`) 6. `k_gemm_nvfp4_mxfp8` — direct Inkling NVFP4 / MXFP8 expert & trunk GEMM 7. `k_rope_kv_write` — rotary embedding + FP8/FP16 KV cache write (SWA ring or linear) 8. `k_flash_gqa_wmma` — fused FlashAttention-2 / GQA prefill (`B >= 16`) & Split-KV decode (`B <= 2`) 9. `k_gdn_chunkwise_wy` — **Chunkwise Parallel GDN (WY-representation)** for `250–350+ ppts` prefill 10. `k_gdn_recurrent_step` — 0-spill GDN decode + history snapshot for `<1 ms` speculative rollback 11. `k_moe_route_bucket` — 100% GPU MoE routing + bitonic coreset + NaN/mask-safe compaction (`0` host sync) 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`!) ## 4. Formal Contracts (`proofs/slab_ring_dma.lean`) Verified with Lean `4.36.0` (`0 sorryAx`): - **`SlabRing` DMA safety:** mutual exclusion between `io_uring` host DMA writes and GPU kernel reads, mandatory fence completion before slot reclaim, conservation of slot count. - **`PrefixState` & Checkpoint Grid:** strict soundness of multi-turn `RESUME` with/without MTP (`sc_mtp_hid_` can never be read uninitialized), and guaranteed checkpoint trigger on non-aligned post-`RESUME` prefill chunks.