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
aien-sovereign-core-mv / crates / aien-inference-abi / tests / branch_client_harness.rs
| 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // Copyright 2026 Drake Stapleton (AIEN / aien-dev) |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | |
| 16 | use aien_inference_abi::{ModelConfig, NativeTransformerBackend, TransformerWeights}; |
| 17 | |
| 18 | #[test] |
| 19 | fn test_aegis_branch_client_2_8_32_fork_lifecycle() { |
| 20 | let config = ModelConfig { |
| 21 | num_layers: 2, |
| 22 | num_heads: 4, |
| 23 | num_kv_heads: 2, |
| 24 | head_dim: 16, |
| 25 | hidden_dim: 64, |
| 26 | intermediate_dim: 128, |
| 27 | vocab_size: 256, |
| 28 | block_size: 16, |
| 29 | ..Default::default() |
| 30 | }; |
| 31 | |
| 32 | let weights = TransformerWeights::reference_test_weights(&config); |
| 33 | let mut runtime = NativeTransformerBackend::with_paged_kv(weights, 3000, 16).unwrap(); |
| 34 | |
| 35 | // 1. Parent context with rich 64-token prompt (4 blocks) |
| 36 | let prompt: Vec<u32> = (10..74).collect(); |
| 37 | let parent = runtime.create_context(&prompt).unwrap(); |
| 38 | |
| 39 | // Loop through 2, 8, 32 branch scaling tiers |
| 40 | for &branch_count in &[2, 8, 32] { |
| 41 | let mut branches = Vec::new(); |
| 42 | for _ in 0..branch_count { |
| 43 | let b = runtime.fork_context(parent).unwrap(); |
| 44 | branches.push(b); |
| 45 | } |
| 46 | |
| 47 | // Before decode: all branches share 4 prefix blocks |
| 48 | for &b in &branches { |
| 49 | let r = runtime.get_usage_receipt(b).unwrap(); |
| 50 | assert_eq!(r.shared_pages, 4); |
| 51 | assert_eq!(r.private_pages, 0); |
| 52 | assert_eq!(r.cow_faults, 0); |
| 53 | assert_eq!(r.logical_pages, 4); |
| 54 | assert!(r.bytes_saved_vs_full_copy > 0); |
| 55 | } |
| 56 | |
| 57 | // Each branch appends unique suffix tokens and generates |
| 58 | for &b in &branches { |
| 59 | let (tok, _) = runtime.decode_branch_step(b).unwrap(); |
| 60 | assert!(tok > 0); |
| 61 | |
| 62 | let r = runtime.get_usage_receipt(b).unwrap(); |
| 63 | assert_eq!(r.shared_pages, 4); |
| 64 | assert_eq!(r.private_pages, 1); |
| 65 | assert_eq!(r.logical_pages, 5); |
| 66 | } |
| 67 | |
| 68 | // Release all branches in this tier |
| 69 | for b in branches { |
| 70 | runtime.release_branch(b).unwrap(); |
| 71 | } |
| 72 | |
| 73 | // Verify parent context remains healthy and uncorrupted |
| 74 | let kv = runtime.kv_manager.as_ref().unwrap().read(); |
| 75 | assert_eq!(kv.active_sequence_count(), 1); |
| 76 | assert_eq!(kv.metrics().physical_pages, 4); |
| 77 | assert_eq!(kv.metrics().private_pages, 4); |
| 78 | } |
| 79 | } |