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 / crates / aien-inference-abi / tests / smollm2_pin.rs

76 lines · 3052 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//! Pins SmolLM2-1.7B-Instruct on the CPU reference path so the Qwen3 loader change cannot
17//! alter a Llama-architecture model: composed prompt ids, and the exact last-position
18//! logits (FNV-1a over every f32 bit pattern, plus the top-5 ids). Values were computed on
19//! origin/main 845f58f (before the Qwen3 change) with the model directory
20//! `SmolLM2-1.7B-Instruct-31b70e2e869a`. Set `AIEN_SMOLLM2_DIR` to run; skipped otherwise.
21
22use aien_inference_abi::tokenizer::ChatTokenizer;
23use aien_inference_abi::{load_model_config, TransformerWeights};
24use std::path::Path;
25
26const TURNS: &[(&str, &str)] = &[("system", "You are terse."), ("user", " What is 2+2?\n")];
27
28fn fnv1a(logits: &[f32]) -> u64 {
29 let mut h: u64 = 0xcbf29ce484222325;
30 for v in logits {
31 for b in v.to_bits().to_le_bytes() {
32 h ^= b as u64;
33 h = h.wrapping_mul(0x100000001b3);
34 }
35 }
36 h
37}
38
39#[test]
40fn smollm2_prompt_ids_and_forward_logits_are_pinned() {
41 let Ok(dir) = std::env::var("AIEN_SMOLLM2_DIR") else {
42 eprintln!("AIEN_SMOLLM2_DIR not set: SmolLM2 pin skipped");
43 return;
44 };
45 let dir = Path::new(&dir);
46 let tok = ChatTokenizer::from_model_dir(dir, None).expect("tokenizer");
47 let text = tok.template().render(TURNS);
48 let ids = tok.encode(&text).expect("encode");
49 println!("PIN smollm2 ids={ids:?}");
50 assert_eq!(ids, PIN_IDS);
51
52 let config = load_model_config(dir).expect("config");
53 let weights = TransformerWeights::load_from_safetensors(dir.join("model.safetensors"), &config)
54 .expect("weights");
55 let logits =
56 weights.forward_sequence_with_diagnostics(&ids).activations["last_token_logits"].clone();
57 let mut order: Vec<usize> = (0..logits.len()).collect();
58 order.sort_by(|a, b| logits[*b].total_cmp(&logits[*a]));
59 let top5: Vec<usize> = order[..5].to_vec();
60 println!(
61 "PIN smollm2 len={} fnv={:#018x} top5={top5:?}",
62 logits.len(),
63 fnv1a(&logits)
64 );
65 assert_eq!(logits.len(), PIN_LEN);
66 assert_eq!(top5, PIN_TOP5);
67 assert_eq!(fnv1a(&logits), PIN_FNV);
68}
69
70const PIN_IDS: &[u32] = &[
71 1, 9690, 198, 2683, 359, 1733, 313, 30, 2, 198, 1, 4093, 3805, 1812, 314, 216, 34, 27, 34, 47,
72 198, 2, 198, 1, 520, 9531, 198,
73];
74const PIN_LEN: usize = 49152;
75const PIN_TOP5: [usize; 5] = [36, 34, 19622, 504, 10345];
76const PIN_FNV: u64 = 0x6862d0b2920753e4;