Files
vetta-infer/docs/ORIENTATION.md
T
adm 356f9c458e [HIP][Docs] embed_bf16 + gemm_bf16 kernels (GPU-verified) + newcomer orientation guide
- kernels/hip: k_embed_bf16_gather (BF16 table -> f32 token rows, exact) and
  k_gemm_bf16 (y[M,N] = x[M,K] @ w[N,K]^T, BF16 in / f32 accumulate,
  correctness-first per-element; WMMA tiling is the later performance pass).
  C ABI + safe Rust wrappers (embed_bf16_gather, gemm_bf16) + DeviceBuf
  byte-level h2d/d2h.
- Verified LIVE on gfx1150: embed exact, gemm max_rel_err 0.0 across
  (2,8,16)/(4,32,64)/(1,128,256), rms_norm ~1e-6. Three kernels now cover the
  trunk + projection compute path (embed, norm, gemm).
- docs/ORIENTATION.md: a guide for newcomers arriving from vLLM/llama.cpp/
  SGLang — what this engine is, the five ideas behind the mental-model shift
  (microkernel+services, models compiled to .vbundle, forward pass as a
  Lean-proven validated plan, proof-first, parity discipline), the crate map,
  the honest current state (CPU pipeline done, GPU begun, no token yet), and
  the ordered road to the first agent chat and beyond. Linked from README.

Verified: RUSTFLAGS="-D warnings" cargo test --workspace = 97/97 PASS;
lean proofs (4 files, 42 theorems) green; GPU parity 4/4 (--features hip).
2026-12-01 04:54:05 +01:00

7.1 KiB

Orientation: what you're looking at

If you come from vLLM, llama.cpp, SGLang, or TensorRT-LLM, this repo will feel alien at first. That's expected — it's built on a different mental model. This document explains what vetta-infer is, why it looks the way it does, and the road ahead. Read this before diving into the code.

What it is, in one paragraph

vetta-infer is a MoE-first microkernel inference engine written in safe Rust with a minimal set of AMD ROCm HIP kernels. It is not a general-purpose engine: it targets one specific machine — an AMD Ryzen AI 9 HX 370 APU (gfx1150, RDNA 3.5) with 96 GiB of unified memory and dual NVMe — and one class of models: Mixture-of-Experts decoder LMs (first target: Inkling-2-Mini). Small dense utility encoders (e.g. BGE-M3 embeddings) are in scope as a secondary lane; dense decoder LMs are deliberately out of scope. The engine is co-designed with its consumer, the vetta-agents framework (evolved from strata-ctl), and ultimately serves a principal named Iris.

Why it looks different (the mental-model shift)

Five ideas explain almost everything that will surprise you:

  1. Pure microkernel + services. There is no monolithic runtime. A tiny kernel (kn) owns the bus, registry, and UMA/DMA broker and contains zero model logic. Everything else — loading, compilation, execution, sampling, speculative decoding, telemetry, the wire gateway — is a separate service crate. Control flow stays in safe, CPU-testable Rust; unsafe is confined to the HIP FFI (hip) and IO syscalls (io).

  2. Models are compiled, not loaded. A dual-step loader turns a HuggingFace .safetensors model into a canonical IR, then a BackendPacker lowers it into a portable .vbundle/ (manifest + weights + plans). You don't point the engine at raw weights; you build a bundle once and boot from it. The manifest carries identity-by-provenance (sha256), ABI version, and target.

  3. The forward pass is a declared, validated plan. Instead of imperative kernel calls scattered through C++ files, the model's compute is expressed as graph.vplan (an op sequence) + memory.vplan (buffer arenas). At boot these lower to a flat CompiledPlan. Before any GPU launch, the plan is checked by an arena validator (no buffer overlap, checked bounds, no use-before-write) whose correctness is proven in Lean 4. The graph is data, not code.

  4. Proof-first for complex logic. Non-trivial state machines — the DMA slab ring, bus lifecycle, serve session, arena plans — are modeled and verified in proofs/*.lean (0 sorryAx, standard axioms only) before the Rust is written. Simple logic just gets ordinary CPU tests. This is a hard rule, not a nicety: it eliminates whole classes of bugs by construction.

  5. Parity discipline, no unmeasured claims. Every kernel is checked against a CPU oracle (and the hardened strata C++/HIP reference) before it is wired in. Every performance claim must carry real measurements and the exact hardware/model/flags. "It should be fast" is not a sentence we accept.

The crate map

Crate Responsibility
vetta-infer-abi Shared contracts: .vbundle manifest/plans, vplan opcodes, arena validator, JSON, sha256, serve wire types.
vetta-infer-kn The microkernel: bus, registry, UMA/DMA broker. No model logic.
vetta-infer-ld Loader: safetensors reader, ModelImporter (config → IR → graph), BackendPacker, bundle I/O.
vetta-infer-hip HIP FFI/DMA backend (gfx1150). unsafe isolated here. Feature-gated kernel build.
vetta-infer-cc Compilation/control services.
vetta-infer-rt Operational runtime: executes the CompiledPlan on the HIP backend.
vetta-infer-lab Laboratory/probing runtime; shares the rt executor core.
vetta-infer-sp Speculative decoding / MTP verification.
vetta-infer-nt NVMe streaming / disk cache (io_uring, write-once O_RDONLY).
vetta-infer-tm Telemetry.
vetta-infer-gw Wire gateway: the stdin/stdout line protocol the agent speaks; CLI.

Current state (honest)

  • CPU planning pipeline: complete and live-verified. Inkling config → total tensor classification (1244/1244) → canonical IR → physical schedule (looped core unrolled to 48 steps) → a full base decode graph (675 ops) that passes the Lean-proven arena validator.
  • GPU execution: begun. Three kernels verified on the real gfx1150 (embed_bf16 exact, gemm_bf16 exact, rms_norm ~1e-6 relative error). The hipcc → static-lib → FFI → launch → parity pipeline works end-to-end.
  • No token generated yet. The engine does not currently run inference. The GPU execution half (remaining kernels + executor + packer + serve wiring) is the work in progress. Do not mistake the validated plan for a running engine.

The road to the goal

The destination: a working, measured inference engine that the agent framework can talk to over the wire, replacing the old strata engine for a real conversation. The path, in order:

  1. Inkling graph parity — layer the model-specific refinements onto the base graph: the learned attention-residual block-mix, loop controllers, ShortConv4, relative-position bias, sliding-window attention, paged KV. (Blueprint: docs/inkling-forward-design.md.)
  2. Remaining kernels — flash attention (GQA, SWA, split-KV), MoE NVFP4 routing + experts + reduce, RoPE/KV-write, penalties/top-k. Each parity-verified before use.
  3. Executor (rt) — lower the CompiledPlan to kernel launches, UMA arena broker, KV-cache management.
  4. BackendPacker + .vbundle — weights → device, the real bundle build.
  5. Serve wiring — connect the (already proven) serve-session FSM to real generation and to vetta-agents over the line protocol. First chat.
  6. M2 performance — WMMA tiling, expert residency/streaming, measured tok/s against the reference.
  7. M3 Lyra co-processor — remote drafting, semantic domain routing, domain-aware expert prefetch.

How to verify

# CPU workspace tests (host-independent, no GPU/toolchain needed):
RUSTFLAGS="-D warnings" cargo test --workspace

# Lean proofs (0 sorryAx, standard axioms):
lean proofs/slab_ring_dma.lean
lean proofs/bus_lifecycle.lean
lean proofs/serve_session.lean
lean proofs/arena_plan.lean

# Opt-in live tests against the real Inkling artifact:
cargo test -p vetta-infer-ld -- --ignored inkling

# GPU kernel parity (requires gfx1150 + ROCm; builds kernels via hipcc):
cargo test -p vetta-infer-hip --features hip -- --ignored
  • docs/ARCHITECTURE.md — the decision-complete spec (microkernel, services, .vbundle, plans, wire contract, milestones).
  • docs/inkling-forward-design.md — the Inkling forward pass, extracted from the reference, that the graph emitter follows.
  • proofs/*.lean — the verified state machines and arena plan.
  • AGENTS.md — the engineering rules and hard invariants.

Welcome. Take your time with the mental model first; the code reads much more naturally once the five ideas above click.