[Core] M0 foundation: workspace, Lean 4 SlabRing/PrefixState contracts, checked safetensors/cache IO, serve proto, telemetry, and HIP ABI

This commit is contained in:
adm committed 2026-11-29 21:32:44 +01:00
commit 63b1668a92
25 files changed
+2991

No files matched your search

+24
View File
@@ -0,0 +1,24 @@
# AGENTS.md — vetta-infer
Rules and engineering standards for working on `vetta-infer`.
## Architecture & Scope
- **MoE-first microkernel engine** in Rust (edition 2024) with minimal AMD ROCm HIP kernels (`gfx1150` / RDNA 3.5 primary target; UMA `96 GiB` + dual NVMe).
- **Clear boundary:** all control flow, parsing, caching, scheduling, speculative verification, protocol handling, and telemetry stay in safe, CPU-testable Rust crates. `unsafe` is isolated to `vetta-hip` (FFI/DMA fence wrappers) and `vetta-io` (`io_uring` / `pread` syscalls).
- **No silent regressions or unmeasured claims:** every performance or quality claim must carry real measurements and the exact hardware/model/flags used.
## Hard Invariants (Eliminate Past Audit Classes By Construction)
1. **DMA / Async Transfer Ownership:** never pass a stack variable or short-lived `Vec` to `hipMemcpyAsync` or `io_uring`. Every in-flight transfer owns or pins its `SlabSlot` until its completion fence/CQE is observed (verified in `proofs/slab_ring_dma.lean`).
2. **Checked Bounds Everywhere:** all `.safetensors` header offsets, slices, and NVMe disk-cache metadata counts MUST use checked integer arithmetic (`checked_add`, `checked_sub`, `count <= blob.len() / MIN_REC_BYTES`) before any allocation.
3. **Write-Once / `O_RDONLY` NVMe Caches:** caches are written atomically via `.tmp.<pid>` + `fsync` + `rename` only on miss, and opened strictly `O_RDONLY` on every reload (0 SSD writes).
4. **Typestate Prefix / MTP / Checkpoint Validity:** never rely on loose integer pairs (`prefix_len`, `mtp_prefix_len`) to infer device buffer initialization. Represent state via explicit enums (`PrefixState`), and commit pool metadata only after GPU allocations/copies succeed.
5. **Zero-Allocation Hot-Path Sampling & Explicit Non-Finite Tracking:** no per-token `O(V)` heap allocations, no silent `256`-cap truncation when `top_k == 0` with `top_p`/`min_p`, centralized `mask_token_id` suppression, and explicit reporting of non-finite logits.
6. **Formal Verification with Lean 4:** model non-trivial state machines, ring buffers, checkpoint pools, and speculative/rollback invariants in `proofs/*.lean` (`0 sorryAx`, verified with `lean`) before writing the implementation.
## Verification Commands
- Proofs: `lean proofs/slab_ring_dma.lean`
- CPU workspace tests: `cargo test --workspace`
- Commit prefixes: `[Core]`, `[IO]`, `[HIP]`, `[Proto]`, `[Telemetry]`, `[Proofs]`, `[Docs]`