Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
80 lines
3.1 KiB
Rust
80 lines
3.1 KiB
Rust
//! Tests of the memory plan arithmetic: real geometry constants, per-cell bytes, INT8 generic versus literal,
|
|
//! pool derivation quirks, does-not-close messages, overflow reporting, Q4 versus INT8 closing, FP32 indexer store.
|
|
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn real_geometry_constants() {
|
|
let g = Geometry::default();
|
|
assert_eq!(state_bytes(&g).unwrap(), 36 * (128 * 48 * 128 * 4 + 3 * 10240 * 4));
|
|
assert_eq!(state_bytes(&g).unwrap(), 117_669_888);
|
|
// 12 layers x (1056 + 32)
|
|
assert_eq!(kv_bytes_per_token_int8(&g).unwrap(), 13_056);
|
|
}
|
|
|
|
#[test]
|
|
fn per_cell_bytes_on_real_shapes() {
|
|
let s = KvShapes::real();
|
|
assert_eq!(kv_cell_bytes(&s, KvFormat::Fp16).unwrap(), 2048);
|
|
assert_eq!(kv_cell_bytes(&s, KvFormat::Int8).unwrap(), 1056);
|
|
assert_eq!(kv_cell_bytes(&s, KvFormat::Q4_0).unwrap(), 576);
|
|
assert_eq!(kv_cell_bytes(&s, KvFormat::K8V4).unwrap(), 816);
|
|
assert_eq!(kv_cell_bytes(&s, KvFormat::Int8Keyless).unwrap(), 528);
|
|
}
|
|
|
|
#[test]
|
|
fn int8_generic_equals_literal() {
|
|
for g in [Geometry::default(), Geometry { n_kv_heads: 4, head_dim: 128, n_qsa_layers: 9, ..Geometry::default() }] {
|
|
assert_eq!(kv_bytes_per_token(&g, KvFormat::Int8).unwrap(), kv_bytes_per_token_int8(&g).unwrap());
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn pool_derivation_quirks() {
|
|
let c = Costs::default();
|
|
assert_eq!(cli_pool(12_000_000_000, &c).unwrap(), 12_000_000_000);
|
|
// derived 0 becomes the default pool
|
|
let heavy = Costs { dense_bytes: 13_000_000_000, ..c };
|
|
assert_eq!(cli_pool(12_000_000_000, &heavy).unwrap(), vram_pool_bytes());
|
|
assert_eq!(cli_pool(0, &c).unwrap(), vram_pool_bytes());
|
|
}
|
|
|
|
#[test]
|
|
fn does_not_close_messages() {
|
|
let g = Geometry::default();
|
|
let c = Costs::default();
|
|
let e = make_plan(524_288, &g, &c, 5_943_000_000).unwrap_err();
|
|
assert_eq!(
|
|
e.to_string(),
|
|
"max-context 524288 needs 6845104128 B of the 5943000000 B VRAM pool; reduce --max-context"
|
|
);
|
|
// exactly full pool: zero cache slots
|
|
let exact = 13_056 * 1000;
|
|
let e = make_plan(1000, &g, &c, exact).unwrap_err();
|
|
assert_eq!(e.to_string(), "no room for even one expert cache slot at max-context 1000");
|
|
}
|
|
|
|
#[test]
|
|
fn overflow_is_reported_not_wrapped() {
|
|
let g = Geometry::default();
|
|
assert_eq!(make_plan(u64::MAX, &g, &Costs::default(), 1), Err(PlanError::Overflow));
|
|
}
|
|
|
|
#[test]
|
|
fn q4_makes_both_charter_profiles_close_where_int8_does_not() {
|
|
let g = Geometry::default();
|
|
let c = Costs { state_bytes: state_bytes(&g).unwrap(), ..Costs::default() };
|
|
let pool = 5_943_000_000;
|
|
assert!(make_plan_with_format(524_288, &g, KvFormat::Int8, &c, pool).is_err());
|
|
assert!(make_plan_with_format(524_288, &g, KvFormat::Q4_0, &c, pool).is_ok());
|
|
}
|
|
|
|
#[test]
|
|
fn engine_estimate_exposes_fp32_indexer_store() {
|
|
let g = Geometry::default();
|
|
let e = engine_resident_estimate(&g, KvFormat::Int8, 1, 32_768, None).unwrap();
|
|
// 12 layers x (3*128*4 + 128*4 + (32768/4 + 2)*128*4) bytes: the "50 MiB at 32K" of qsa.hpp
|
|
assert_eq!(e.indexer_stores, 12 * (1536 + 512 + 8194 * 512));
|
|
assert!(e.indexer_stores > 50_000_000 && e.indexer_stores < 51_000_000);
|
|
}
|