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 / PROJECT.md

172 lines · 12154 bytes Raw Blame History Source

Project: AIEN Sovereign Core TinyLlama Real-Model Execution

Architecture

The AIEN Sovereign Core inference architecture executes real-model weights on NVIDIA DGX Spark (GB10 Grace Blackwell unified memory architecture) with mathematical parity against Hugging Face reference models.

+-----------------------------------------------------------------------------------+
| crates/aien-inference-abi                                                         |
|                                                                                   |
|  +---------------------------+       +-----------------------------------------+  |
|  |       tokenizer.rs        |       |              checkpoint.rs              |  |
|  | - Pure Rust tokenizers    |       | - Strict safetensors header parser      |  |
|  | - TinyLlama chat template |       | - Shape, dtype, range loud validation   |  |
|  | - Special token pinning   |       | - 201 TinyLlama tensor catalog          |  |
|  | - UTF-8 encode / decode   |       | - Dual FP32 (oracle) & BF16 (GPU)       |  |
|  +-------------+-------------+       +--------------------+--------------------+  |
|                |                                          |                       |
|                v                                          v                       |
|  +-----------------------------------------------------------------------------+  |
|  |                        transformer_backend.rs                               |  |
|  | - High-level autoregressive execution and KV cache orchestration            |  |
|  | - Dispatch via decoupled TensorBackend trait                                |  |
|  +-------------------------------------+---------------------------------------+  |
|                                        |                                          |
|                +-----------------------+-----------------------+                  |
|                |                                               |                  |
|                v                                               v                  |
|  +---------------------------+               +---------------------------------+  |
|  |    ReferenceCpuBackend    |               |        OmegaGb10Backend         |  |
|  | - Pure Rust FP32 math     |               | - Unified memory zero-copy      |  |
|  | - rotate_half RoPE        |               | - Omega native kernels, no CUDA |  |
|  | - [out_dim, in_dim] GEMV  |               | - AIEN-owned GPU driver path    |  |
|  | - Correctness oracle      |               | - GB10 sm_121a hardware speed   |  |
|  +---------------------------+               +---------------------------------+  |
+-----------------------------------------------------------------------------------+

Feature Inventory

Every feature identified during survey is mapped directly to a milestone.

#FeatureDescriptionMilestoneSource
F1Strict Safetensors LoaderRead safetensors, parse JSON metadata without synthetic fallbackM1R1, Survey 1
F2Loud Validation & CatalogValidate all 201 tensors, shapes, BF16 dtype, byte rangesM1R1, Survey 1
F3Dual Weight StorageMaintain decoded FP32 for oracle and raw BF16 for accelerated kernelsM1R1, Survey 1
F4Pure Rust TokenizerLoad tokenizer.json via tokenizers crate without Python runtimeM2R2, Survey 1
F5Chat Template & Special TokensFormat TinyLlama chat template, pin IDs (<s>=1, </s>=2, <unk>=0)M2R2, Survey 1
F6Encode & Decode EngineString to token ID encoding, EOS stopping, token ID to UTF-8 textM2R2, Survey 1
F7Reference Oracle ScriptPython script on Spark capturing exact intermediate activationsM3R3, Survey 2
F8Deterministic Oracle FixturesImmutable tinyllama_oracle.safetensors and SHA-256 manifestM3R3, Survey 2
F9Algorithmic Core AlignmentCorrect RoPE to rotate_half, matmul to [out_dim, in_dim], decode indexM4R4, Survey 1, 2
F10Multi-Stage Parity Test5-stage test asserting tokenizer, shape, activations, logits, decodeM4R4, Survey 2
F11Decoupled TensorBackend TraitNarrow abstraction for RMSNorm, RoPE, GQA, SwiGLU, matmul, logitsM5R5, Survey 3
F12ReferenceCpuBackendComplete FP32 reference implementation satisfying TensorBackendM5R5, Survey 3
F13Mojo GB10 C-ABI KernelsRemoved 2026-10-15 with Modular MAX and Mojo; GPU path is OmegaGb10BackendM5R5, Survey 3
F14MojoGb10Backend ImplementationRemoved 2026-10-15 with Modular MAX and MojoM5R5, Survey 3
F15Neutral Benchmark DriverStandalone AIEN benchmark driver on DGX Spark (the MAX engine was removed 2026-10-15; speed is measured against the machine's physical limit, and correctness against my own reference)M6R6, Survey 3
F16Concurrency Sweeps & TelemetryC=1..64 sweeps, TTFT, ITL, throughput, RSS, power, energy metricsM6R6, Survey 3
F17Hardware & Secrets ComplianceUser drakestapleton on Spark, zero disk secrets (TPM atlas-vault)M7R7, Survey 3
F18PR Lifecycle & Cortex ReceiptBranch feat/real-model-execution-tinyllama, squash merge, Cortex writeM7R7, Survey 3

Milestones

#NameScopeDependenciesStatus
M1Strict Safetensors Checkpoint LoaderImplement checkpoint.rs with loud validation, MissingTensor/ShapeMismatch errors, 201-tensor catalog, dual FP32/BF16 storagenoneDONE
M2Pure Rust Tokenizer and Chat TemplateIntegrate tokenizers crate in aien-inference-abi, implement TinyLlama chat template, special token pinning, encode/decodenoneDONE
M3Reference Oracle Fixture GenerationAuthor scripts/generate_tinyllama_oracle.py on Spark, generate tinyllama_oracle.safetensors, export JSON manifest with SHA-256noneDONE
M4Algorithmic Alignment and Parity Test HarnessAlign RoPE split-half and matmul layout in tensor.rs, implement crates/aien-inference-abi/tests/tinyllama_parity.rs passing 5 stagesM1, M2, M3DONE
M5Decoupled TensorBackend and Mojo GB10 AccelerationDefine TensorBackend trait, implement ReferenceCpuBackend and MojoGb10Backend (libaien_kernels.so) on Spark GB10M4DONE (Mojo backend removed 2026-10-15)
M6Neutral Apples-to-Apples Benchmark DriverBuild benchmarks/crates/bench_apples_to_apples, run AIEN and MAX on DGX Spark across C=1..64, record telemetryM5DONE (MAX engine removed 2026-10-15)
M7Invariant Verification, Autonomous PR Lifecycle, and Cortex ReceiptVerify zero disk secrets, sovereign voice, execute PR squash merge, commit receipt to Cortex memoryM6DONE

Interface Contracts

checkpoint.rs <-> weights.rs / backend.rs

pub enum CheckpointError {
    MissingTensor(String),
    ShapeMismatch { tensor: String, expected: Vec<usize>, actual: Vec<usize> },
    DtypeMismatch { tensor: String, expected: String, actual: String },
    OffsetOutOfBounds { tensor: String, offset: usize, buffer_len: usize },
    InvalidHeader(String),
}

pub struct LoadedCheckpoint {
    pub fp32_weights: std::collections::HashMap<String, Vec<f32>>,
    pub raw_bf16_weights: std::collections::HashMap<String, Vec<u8>>,
    pub shapes: std::collections::HashMap<String, Vec<usize>>,
}

pub fn load_safetensors_checkpoint<P: AsRef<std::path::Path>>(path: P) -> Result<LoadedCheckpoint, CheckpointError>;

tokenizer.rs <-> transformer_backend.rs

pub struct TinyLlamaTokenizer {
    // wraps tokenizers::Tokenizer
}

impl TinyLlamaTokenizer {
    pub const BOS_TOKEN_ID: u32 = 1;
    pub const EOS_TOKEN_ID: u32 = 2;
    pub const UNK_TOKEN_ID: u32 = 0;
    pub const MAX_CONTEXT_LEN: usize = 2048;

    pub fn from_file<P: AsRef<std::path::Path>>(path: P) -> Result<Self, TokenizerError>;
    pub fn format_chat_prompt(&self, system: Option<&str>, user: &str) -> String;
    pub fn encode(&self, text: &str) -> Result<Vec<u32>, TokenizerError>;
    pub fn decode(&self, tokens: &[u32]) -> Result<String, TokenizerError>;
}

TensorBackend Trait

pub trait TensorBackend: Send + Sync {
    fn rmsnorm(&self, out: &mut [f32], x: &[f32], weight: &[f32], eps: f32);
    fn apply_rope(&self, q: &mut [f32], k: &mut [f32], pos: usize, head_dim: usize, num_q_heads: usize, num_kv_heads: usize, theta: f32);
    fn matmul_vec(&self, out: &mut [f32], x: &[f32], weight: &[f32], out_dim: usize, in_dim: usize);
    fn swiglu(&self, out: &mut [f32], gate: &[f32], up: &[f32]);
    fn gqa_attention(&self, out: &mut [f32], q: &[f32], k_cache: &[f32], v_cache: &[f32], seq_len: usize, num_q_heads: usize, num_kv_heads: usize, head_dim: usize);
    fn compute_logits(&self, logits: &mut [f32], hidden: &[f32], embed_weight: &[f32], vocab_size: usize, hidden_dim: usize);
}

Numerical Parity Tolerances (tinyllama_parity.rs)

pub const ABSOLUTE_TOLERANCE: f32 = 1e-4;
pub const RELATIVE_TOLERANCE: f32 = 1e-4;
pub const MIN_COSINE_SIMILARITY: f32 = 0.9999;

Code Layout

crates/aien-inference-abi/
├── Cargo.toml                              (owns: M1, M2 dependency wiring)
├── src/
│   ├── lib.rs                              (exports checkpoint, tokenizer, backend)
│   ├── checkpoint.rs                       (owns: M1 strict safetensors parsing and validation)
│   ├── tokenizer.rs                        (owns: M2 pure Rust tokenizers and chat templates)
│   ├── tensor.rs                           (owns: M4 rotate_half RoPE and row-major matmul)
│   ├── backend.rs                          (owns: M5 TensorBackend trait and ReferenceCpuBackend)
│   ├── omega_backend.rs                    (owns: OmegaGb10Backend, the GB10 GPU path)
│   ├── transformer_backend.rs              (owns: M4 decode position index, M5 backend dispatch)
│   └── weights.rs                          (owns: legacy compatibility delegating to checkpoint.rs)
├── tests/
│   ├── tinyllama_parity.rs                 (owns: M4 5-stage numerical parity test harness)
│   └── fixtures/                           (owns: M3 compact oracle and tokenizer fixtures)
scripts/
└── (no Python; the TinyLlama oracle generator was removed, only its recorded outputs are kept as test fixtures)
benchmarks/
├── Cargo.toml                              (owns: M6 benchmark workspace)
└── crates/
    └── bench_apples_to_apples/
        ├── Cargo.toml                      (owns: M6 benchmark crate dependencies)
        └── src/
            └── main.rs                     (owns: M6 AIEN driver and telemetry)

Execution Constraints

Acceptance Criteria Cross-Check

The M5 Mojo and M6 MAX items below are the record of what shipped then; that code was removed on 2026-10-15.