Desktop foundation / core (ubuntu-latest) (push) Failing after 28s
Desktop foundation / core (macos-latest) (push) Canceled after 0s
Desktop foundation / core (windows-latest) (push) Canceled after 0s
Linux / verify (push) Canceled after 0s
Linux / keyless-cuda (push) Canceled after 0s
Linux / static-cuda-package (push) Canceled after 0s
Linux / hosted-cuda-package (push) Canceled after 0s
Linux / linux-static-cli (push) Canceled after 0s
Linux / linux-cli-container (push) Canceled after 0s
Linux / release-cli (push) Canceled after 0s
70 lines
2.3 KiB
Rust
70 lines
2.3 KiB
Rust
//! Model-free routed-expert fixture, using the production KAR writer.
|
|
use sha2::{Digest, Sha256};
|
|
use std::path::Path;
|
|
use strata_control::kar_writer::{self, SourceIdentity, Tensor, TensorData};
|
|
|
|
fn main() -> Result<(), String> {
|
|
let args: Vec<_> = std::env::args().collect();
|
|
if args.len() != 2 {
|
|
return Err("usage: kar-expert-fixture NEW_OUTPUT.kar".into());
|
|
}
|
|
const H: u64 = 64;
|
|
const F: u64 = 32;
|
|
const E: u64 = 2;
|
|
let scales = vec![0x2800u16; (H * F * E / 32) as usize]; // 1/32
|
|
let mut plane = vec![u32::MAX; (H * F / 32) as usize];
|
|
plane.extend(vec![0u32; (H * F / 32) as usize]);
|
|
let book = [0xbc00u16, 0x3c00]; // expert 0 positive, expert 1 negative
|
|
let books: [&[u16]; 1] = [&book];
|
|
let planes: [&[u32]; 1] = [&plane];
|
|
let raw: Vec<u8> = (0..3)
|
|
.flat_map(|_| {
|
|
(0..H * F * E).flat_map(|i| {
|
|
(if i < H * F {
|
|
1.0f32 / 32.0
|
|
} else {
|
|
-1.0f32 / 32.0
|
|
})
|
|
.to_le_bytes()
|
|
})
|
|
})
|
|
.collect();
|
|
let source = SourceIdentity {
|
|
name: "synthetic-routed-experts",
|
|
architecture: "synthetic",
|
|
builder: "strata-next/kar-expert-fixture-v1",
|
|
digest: Sha256::digest(&raw).into(),
|
|
total_elements: H * F * E * 3,
|
|
bytes: raw.len() as u64,
|
|
};
|
|
let dims = [[H, F, E], [H, F, E], [F, H, E]];
|
|
let names = [
|
|
"blk.0.ffn_gate_exps.weight",
|
|
"blk.0.ffn_up_exps.weight",
|
|
"blk.0.ffn_down_exps.weight",
|
|
];
|
|
let tensors: Vec<_> = (0..3)
|
|
.map(|role| Tensor {
|
|
name: names[role],
|
|
dims: &dims[role],
|
|
source_dtype: 0,
|
|
source_digest: Sha256::digest(
|
|
&raw[role * (H * F * E * 4) as usize..(role + 1) * (H * F * E * 4) as usize],
|
|
)
|
|
.into(),
|
|
source_offset: role as u64 * H * F * E * 4,
|
|
data: TensorData::Nested {
|
|
group: 32,
|
|
nesting: 0,
|
|
planes_min: 1,
|
|
planes_max: 1,
|
|
scales: &scales,
|
|
books: &books,
|
|
planes: &planes,
|
|
},
|
|
})
|
|
.collect();
|
|
kar_writer::write_archive(Path::new(&args[1]), &source, &tensors)?;
|
|
Ok(())
|
|
}
|