Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aien-sovereign-core-mv/blob/main/docs/inference/own30b-omega-door.rs # 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 Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aien-sovereign-core-mv / docs / inference / own30b-omega-door.rs` 124 lines ยท 5406 bytes Raw Blame History 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 //! Reading guide: the Omega engine behind the HTTP door's `Engine` trait (OWN-30B). 17 //! 18 //! NOT COMPILED. The live code is `crates/aien-serve-http/src/omega_engine.rs`; when this 19 //! sketch and that file disagree, that file wins. Refreshed for sc#522 against main `bdd58a2b` 20 //! (the first version of this file was the cut 3 x cut 4 seam, before the GPU lock, sampling, 21 //! whole-prompt prefill and persistent KV existed). Bodies are trimmed to the steps, in order. 22 //! 23 //! Wiring in `main.rs` (`--engine omega`): 24 //! let mut door = OmegaDoor::load(&model_dir, max_ctx, weights, spin_us, prefill)?; 25 //! if AIEN_KV_STORE_DIR is set { door.set_persistence(kv_persist::open_with_test_fault(..).0) } 26 //! Arc::new(door) // the server's Arc 27 use std::path::{Path, PathBuf}; 28 use std::sync::atomic::AtomicUsize; 29 use std::time::Duration; 30 31 use aien_inference_abi::qwen3_moe_omega::{self as omega, OmegaEngine, WeightFormat}; 32 33 use crate::engine::{Engine, EngineError, GenerateOutcome, GenerateParams}; 34 use crate::kv_persist::PersistState; 35 36 /// The hive's GPU lock: held only around a generation (and the load), never while idle. 37 pub const GPU_LOCK_PATH: &str = "/tmp/aien-gb10.lock"; 38 /// How long `generate` waits for the GPU lock before answering `EngineError::Busy` (HTTP 503). 39 pub const LOCK_WAIT: Duration = Duration::from_secs(30); 40 /// Host memory the load needs free. 41 pub const LOAD_MIN_FREE_GB: f64 = 45.0; 42 43 /// Prefill path; both ON by default in the door (the engine and `own30b_check` default OFF: 44 /// see the doc on `PrefillMode` in the live file). 45 pub struct PrefillMode { 46 pub whole_prompt: bool, 47 pub device_host: bool, 48 } 49 50 pub struct OmegaDoor { 51 /// Declared first: a running store drains its parks before the engine goes. 52 persist: PersistState, 53 engine: OmegaEngine, 54 lock_wait: Duration, 55 lock_path: PathBuf, 56 /// Prompt tokens the last generation reused (RAM or restored prefix). 57 reused_last: AtomicUsize, 58 } 59 60 impl OmegaDoor { 61 /// 1. refuse below LOAD_MIN_FREE_GB available, or when the binary carries the CPU stub of 62 /// omega, or when FP8 experts are asked for without the FP8 GEMV linked; 63 /// 2. apply `spin_us`; take the GPU lock (LOCK_WAIT); 64 /// 3. `OmegaEngine::load_with(model_dir, max_context, format, progress)`; 65 /// 4. still under the lock: `set_whole_prompt(..)`, then `set_whole_prompt_device_host(..)` 66 /// when whole-prompt is on (a refusal is fatal and names the `off` switch); 67 /// 5. log the load report and the paths in use; `from_parts(engine, GPU_LOCK_PATH, LOCK_WAIT)`. 68 pub fn load( 69 model_dir: &Path, 70 max_context: usize, 71 format: WeightFormat, 72 spin_us: Option, 73 prefill: PrefillMode, 74 ) -> Result { 75 unimplemented!("see omega_engine.rs") 76 } 77 78 /// A door over a built engine (tests: a private lock file and the host test engine). 79 /// Persistence starts `PersistState::Off`. 80 pub fn from_parts(engine: OmegaEngine, lock_path: PathBuf, lock_wait: Duration) -> Self { 81 unimplemented!("see omega_engine.rs") 82 } 83 84 /// Installs the persistence state, before the door is shared. 85 pub fn set_persistence(&mut self, state: PersistState) { 86 self.persist = state; 87 } 88 } 89 90 impl Engine for OmegaDoor { 91 fn kind(&self) -> &str { 92 self.engine.kind() 93 } 94 95 fn max_context_tokens(&self) -> usize { 96 self.engine.max_context_tokens() 97 } 98 99 /// 1. empty prompt -> `Failed`; prompt >= context -> `PromptTooLong`; 100 /// 2. map the params to `omega::GenerateParams`; 101 /// 3. persistent KV on with restore: fetch the longest stored prefix that beats the RAM 102 /// prefix, WITHOUT the GPU lock; 103 /// 4. take the GPU lock at `lock_path` (wait `lock_wait`), else `EngineError::Busy`; 104 /// 5. restore the fetched K/V (all or nothing; on error the engine resets and prefills); 105 /// 6. `engine.generate_with(prompt, &q, &mut sampler, on_token)` with the server's own 106 /// `SamplingObserver`, so CPU and Omega pick tokens the same way; 107 /// 7. persistent KV on: snapshot (park) under the lock; release the lock; then submit the 108 /// park for writing; 109 /// 8. map the finish (`Constraint` reads as `Stop`) and return the sampling record. 110 fn generate( 111 &self, 112 prompt: &[u32], 113 p: &GenerateParams, 114 on_token: &mut dyn FnMut(u32) -> bool, 115 ) -> Result { 116 unimplemented!("see omega_engine.rs") 117 } 118 119 /// `/health` `persistent_kv`: absent when off, `refused` with the reason, or the store's 120 /// status when on. 121 fn persistence_status(&self) -> Option { 122 unimplemented!("see omega_engine.rs") 123 } 124 }