interplane.Get Omega
Read in your language

aien-sovereign-core-mv

AienOS host runtime: inference scheduling, paged KV state, the aien CLI and Spark verification tooling. Its inference engine is in alpha testing (DGX Spark GB10); Omega is the implementation destination.

Brought by drakestapleton

branch main Branches Tags History

aien-sovereign-core-mv / docs / AIEN_INFERENCE_ABI_SPEC.md

244 lines · 10431 bytes Raw Blame History Rendered
1# AIEN Inference ABI & Native Runtime Architecture Specification
2
3## 1. Research Thesis
4Modern inference engines expend substantial compute and memory overhead mitigating runtime friction introduced by Python, dynamic tracing guards, and interpreter-level scheduling.
5
6This research branch evaluates the thesis:
7> How much of modern LLM inference latency, memory pressure, and energy consumption belongs to forward tensor mathematics, and how much is an artifact of the software orchestration stack?
8
9By systematically replacing each layer of the inference engine with native compiled Rust and Omega kernels, I measure the empirical delta across each removal.
10
11---
12
13## 2. Silicon Execution Architecture
14
15AIEN serves as the native compiled inference runtime. High-performance tensor execution is decoupled into silicon backends conforming to the AIEN Inference ABI:
16
17```text
18 AIEN / ENOS
19 │
20 aien-inference-abi
21 │
22 ┌───────────────┴────────────────┐
23 │ │
24 ▼ ▼
25 Blackwell Native Native CPU
26 GB10 fast path fallback
27 │ │
28 └───────────────┬────────────────┘
29 │
30 AIEN Scheduler
31 │
32 aien-kv-cache
33 │
34 Model State
35```
36
37| Subsystem | Fast Path (Blackwell) | Fallback Path (Native CPU) | Test Oracle |
38| :--- | :--- | :--- | :--- |
39| **Scheduler** | AIEN Native Continuous Batching Scheduler | AIEN Native Continuous Batching Scheduler | Deterministic Step Scheduler |
40| **KV Management** | AIEN Physical Unified CoW Pool | In-process Paged Pool | Virtual Page Table |
41| **Execution Engine** | GB10 sm_121 Omega native kernels (`OmegaGb10Backend`, no CUDA) | Rayon Multi-Core NEON/AVX | ReferenceCpuBackend (FP32 Oracle) |
42| **Inference Backend** | `BlackwellInferenceBackend` | `NativeCpuInferenceBackend` | `MockInferenceBackend` |
43| **Memory Substrate** | DGX Spark 128 GB Unified Coherent Memory | Standard Host DRAM | Heap Slices |
44
45### Monitored Telemetry per Stage
461. **TTFT (Time To First Token)**: Prefill latency in milliseconds.
472. **ITL (Inter-Token Latency)**: Decode step time in milliseconds (p50, p95, p99).
483. **Throughput**: Sustained output tokens per second under concurrency sweeps (C = 1, 4, 16, 64).
494. **Memory Footprint**: Host RSS (MB), GPU Allocated VRAM (MB), GPU Reserved VRAM (MB).
505. **KV Efficiency**: Physical block fragmentation percentage, prefix reuse hit rate.
516. **Host Resource Draw**: CPU Utilization (%), GPU Tensor Core Utilization (%), NVLink-C2C bus saturation (GB/s).
527. **Thermodynamic Efficiency**: Measured Joules / token via power sampling.
53
54---
55
56## 3. Core Architecture: AIEN Inference ABI
57
58The inference interface belongs to AIEN. Silicon backends conform to this trait:
59
60```rust
61use async_trait::async_trait;
62use std::collections::HashMap;
63
64#[derive(Debug, Clone)]
65pub struct ModelConfig {
66 pub model_id: String,
67 pub max_sequence_length: usize,
68 pub block_size: usize,
69 pub num_layers: usize,
70 pub num_heads: usize,
71 pub head_dim: usize,
72}
73
74#[derive(Debug, Clone)]
75pub struct SequenceRequest {
76 pub request_id: u64,
77 pub prompt_tokens: Vec<u32>,
78 pub sampling_params: SamplingParams,
79}
80
81#[derive(Debug, Clone)]
82pub struct SamplingParams {
83 pub temperature: f32,
84 pub top_p: f32,
85 pub max_tokens: usize,
86 pub stop_token_ids: Vec<u32>,
87}
88
89#[derive(Debug, Clone)]
90pub struct ScheduledBatch {
91 pub prefill_requests: Vec<SequenceRequest>,
92 pub decode_requests: Vec<u64>,
93 pub block_tables: HashMap<u64, Vec<usize>>,
94}
95
96#[derive(Debug, Clone)]
97pub enum DecodeOutput {
98 Token { token_id: u32, logprob: Option<f32> },
99 Finished { reason: FinishReason },
100}
101
102#[derive(Debug, Clone, Copy, PartialEq, Eq)]
103pub enum FinishReason {
104 StopToken,
105 LengthLimit,
106 Aborted,
107}
108
109#[async_trait]
110pub trait AienInferenceBackend: Send + Sync {
111 async fn load_model(&mut self, config: &ModelConfig) -> Result<(), String>;
112 async fn execute_step(
113 &mut self,
114 batch: &ScheduledBatch,
115 ) -> Result<Vec<DecodeOutput>, String>;
116}
117```
118
119---
120
121## 4. Native Scheduling & Paged KV-Cache Management
122
123### KV Block Table Specification
124Blocks are fixed-token chunks (e.g. 16 or 32 tokens) allocated from a pre-mapped pool in unified host/device memory.
125
126```rust
127pub struct KvBlock {
128 pub block_id: usize,
129 pub ref_count: usize,
130 pub is_shared: bool,
131}
132
133pub struct BlockTable {
134 pub blocks: Vec<usize>,
135}
136
137pub struct AienKvManager {
138 total_blocks: usize,
139 free_blocks: Vec<usize>,
140 allocated_tables: HashMap<u64, BlockTable>,
141}
142
143impl AienKvManager {
144 pub fn allocate_prompt_blocks(&mut self, token_count: usize) -> Result<BlockTable, String>;
145 pub fn fork_sequence(&mut self, parent_req_id: u64, child_req_id: u64) -> Result<(), String>;
146 pub fn free_sequence(&mut self, req_id: u64);
147}
148```
149
150### Prefix Sharing & Zero-Copy Subagent Branching
151When a subagent forks from a parent agent:
1521. The parent's `BlockTable` entries have their `ref_count` incremented.
1532. `is_shared` is marked true.
1543. The child agent inherits the exact block indices without copying KV memory.
1554. During decode, if a child writes to a shared block, copy-on-write allocates a new private block.
156
157---
158
159## 5. Empirical Benchmark Telemetry & Live Pressure Verification
160
161> [!NOTE]
162> **Control Plane Scope Clarification**:
163> The throughput and latency figures in Sections 5.1 through 5.4 measure native control plane execution:
164> block-table indexing, sequence queue transitions, reference-counting mutations, and batch assembly.
165> Block indices represent coordinate pointers in pre-allocated unified memory.
166> Physical tensor manipulation across the Blackwell GPU substrate begins in Stages 2 through 4.
167
168
169Execution Substrate: NVIDIA DGX Spark (NVIDIA Grace Blackwell GB10, aarch64, 121 GB Unified LPDDR5X Memory, Linux 7.0.0-1019-nvidia).
170
171### 5.1 Paged KV Cache Block-Table Allocator Throughput (Control Plane)
172Benchmark binary: `bench_inference_stack` (it measured the Modular MAX engine and was removed from the tree on 2026-10-15; the results below are kept only as a record)
173- Workload: 10,000 sequence allocations (160,000 block-table indices managed, block size = 16 tokens).
174
175| Metric | Result | Sub-unit Latency |
176| :--- | :--- | :--- |
177| Allocation Throughput | 134,338,182.94 blocks/sec | 119.10 ns/sequence (7.44 ns/block) |
178| Deallocation Throughput | 238,709,061.40 blocks/sec | 67.03 ns/sequence (4.19 ns/block) |
179| Memory Management Status | Zero-allocation pooling verified | Deterministic constant time O(1) |
180
181### 5.2 Subagent Zero-Copy Sequence Fork vs Naive Memory Copy
182Parent sequence context: 4,096 tokens (256 KV blocks).
183
184| Subagents Forked | Zero-Copy Fork Time | Naive Copy Est. | Speedup Ratio | Projected Tensor Memory Saved |
185| :--- | :--- | :--- | :--- | :--- |
186| 1 | 1.58 µs | 1.92 ms | 1,212.1x | 0.38 GB |
187| 10 | 0.46 µs | 19.20 ms | 4,152.2x | 3.75 GB |
188| 50 | 0.47 µs | 96.00 ms | 4,067.8x | 18.75 GB |
189| 100 | 0.39 µs | 192.00 ms | 4,977.2x | 37.50 GB |
190| 500 | 0.45 µs | 960.00 ms | 4,236.1x | 187.50 GB |
191
192### 5.3 Copy-on-Write (CoW) Mutation Latency
193- Iterations: 1,000 token generations on shared parent blocks.
194- Latency per CoW Token Append: 8.96 nanoseconds.
195- Divergence Overhead: Negligible. Subagents branch without stalling parent streams.
196
197### 5.4 Continuous Batching Scheduler Step Overhead
198- Scheduler Config: Max batch tokens = 8,192, max prefill tokens = 4,096, chunked prefill enabled.
199
200| Active Sequences | Batch Build Time (µs) | Scheduler Overhead Ratio (in 10ms step) |
201| :--- | :--- | :--- |
202| 1 | 1.01 µs | 0.0101% |
203| 9 | 2.02 µs | 0.0202% |
204| 40 | 5.20 µs | 0.0520% |
205| 96 | 9.66 µs | 0.0966% |
206| 192 | 17.68 µs | 0.1768% |
207
208### 5.5 Live Microservice Call Stress & Memory Pressure
209Benchmark harness: `target/release/stress_aien_live` executing against live production endpoints on `spark`.
210
211#### Cortex-rs Vector Memory Call Stress (Port 18080, `/api/cortex/search`)
212| Concurrency | Total Calls | Throughput (req/s) | p50 Latency (ms) | p95 Latency (ms) | p99 Latency (ms) | Success Rate |
213| :--- | :--- | :--- | :--- | :--- | :--- | :--- |
214| 10 | 200 | 1,637.21 req/s | 6.03 ms | 7.10 ms | 11.35 ms | 100.0% |
215| 25 | 200 | 1,867.17 req/s | 10.97 ms | 29.68 ms | 41.53 ms | 100.0% |
216| 50 | 200 | 1,960.52 req/s | 11.82 ms | 57.90 ms | 78.56 ms | 100.0% |
217| 100 | 200 | 2,103.73 req/s | 23.02 ms | 68.83 ms | 88.18 ms | 100.0% |
218
219#### Cortex Transformer Encoder Batch & Density Stress (Port 18081, `/embed`)
220- Model: `BAAI/bge-base-en-v1.5` (ONNX INT8, CPU).
221
222| Batch Size | Total Texts | Duration (ms) | Throughput (texts/sec) | Per-Text Latency (ms) |
223| :--- | :--- | :--- | :--- | :--- |
224| 1 | 20 | 100.21 ms | 199.59 texts/s | 5.01 ms |
225| 4 | 80 | 451.71 ms | 177.11 texts/s | 5.65 ms |
226| 8 | 160 | 851.81 ms | 187.84 texts/s | 5.32 ms |
227| 16 | 320 | 1547.26 ms | 206.82 texts/s | 4.84 ms |
228| 32 | 640 | 3165.60 ms | 202.17 texts/s | 4.95 ms |
229
230#### MAX LLM Streaming & Latency Pressure (Port 18082, `unsloth/Llama-3.2-1B-Instruct`)
231| Concurrent Streams | TTFT p50 (ms) | ITL p50 (ms) | ITL p95 (ms) | Aggregate Tok/s | E2E Latency p50 (ms) |
232| :--- | :--- | :--- | :--- | :--- | :--- |
233| 1 | 130.59 ms | 90.62 ms | 97.77 ms | 11.58 tok/s | 2,763.97 ms |
234| 4 | 5,652.78 ms | 86.60 ms | 103.46 ms | 11.61 tok/s | 8,299.38 ms |
235| 8 | 11,198.92 ms | 87.25 ms | 101.76 ms | 11.59 tok/s | 13,795.19 ms |
236| 16 | 22,234.08 ms | 84.76 ms | 100.95 ms | 11.66 tok/s | 24,854.70 ms |
237
238#### Resident Set Size (RSS) Memory Stability Under Pressure
239| Service | Baseline RSS | Peak Concurrency RSS | Post-Stress Delta | Memory Stability |
240| :--- | :--- | :--- | :--- | :--- |
241| cortex-rs | 15.97 MB | 18.57 MB | +2.60 MB | Confirmed leak-free |
242| cortex-encoder-rs | 780.02 MB | 780.39 MB | +0.36 MB | Confirmed leak-free |
243| max inference engine | 9,011.61 MB | 9,013.99 MB | +2.38 MB | Confirmed leak-free |
244| aegis daemon | 4.80 MB | 4.80 MB | +0.00 MB | Zero drift |