[GW][HIP][LD] Link vetta-infer to strata-ctl; isolate GPU tests; size KV per pass
End-to-end verified: strata-ctl --serve spawns vetta-infer and serves the OpenAI-compatible API. Live: 'capital of France' -> Paris (finish stop), and Italian multi-turn context -> Napoli. Two wire-compat gaps closed: - accept '--serve <dir>' alias (strata-ctl engine_argv prepends --serve). - emit the EOS token as 'T <eos>' before 'DONE ... stop', matching the reference strata-inkling --serve (strata-ctl's dialect decoder reads the end-of-sampling channel token). chat parity now EXACT incl. EOS. GPU test isolation (the 5th full-model test OOM'd): HIP-visible VRAM is 48 GiB (model 18 GiB; one live instance peaks ~15 GiB and releases cleanly). The OOM was the harness, not a leak: the thread-local DeviceBuf pool retains buffers for each libtest worker thread's lifetime, so 5 engines' weights accumulated past 48 GiB. Fix: gw gpu_isolated() runs heavy tests under a serial lock with the pool disabled via a new safe hip::set_buf_pool_enabled (no env mutation, gw stays unsafe-free), so every drop hipFrees between tests. KV sizing: LayerState.k_cache/v_cache are now Vec sized to the passes a layer actually runs (core 3, prelude/coda 1) instead of 3 for every layer, removing ~1.6 GiB of unused KV at max context. Parity unchanged (EXACT 16 tok). Suite: workspace -D warnings green; 18 ld + 18 hip + 5 gw GPU; 5 Lean 0 sorryAx.
This commit is contained in:
1 parent
b9cac6d0df
commit
7790f48c27
7 files changed
+97
-18
No files matched your search
@@ -38,10 +38,10 @@ pub struct LayerWeights {
|
||||
/// Persistent per-layer decode state.
|
||||
pub struct LayerState {
|
||||
// KV cache is PER-VISIT (exact strata visit_kv_slot: every core pass owns a
|
||||
// distinct SWA/global KV pool, 40 SWA + 8 global). Index by pass: prelude/coda
|
||||
// use pass 0; the core's 3 passes use pass 0/1/2. Sharing one cache across
|
||||
// passes corrupts multi-token attention (the systematic token-2+ parity gap).
|
||||
pub k_cache: [DeviceBuf; 3], pub v_cache: [DeviceBuf; 3], // [n_kv, max_seq, hd] each
|
||||
// distinct SWA/global KV pool, 40 SWA + 8 global). One cache per pass the
|
||||
// layer actually runs: core layers 3 (pass 0/1/2), prelude/coda 1 (pass 0).
|
||||
// Sharing one cache across passes corrupts multi-token attention.
|
||||
pub k_cache: Vec<DeviceBuf>, pub v_cache: Vec<DeviceBuf>, // per-pass [n_kv, max_seq, hd]
|
||||
// ShortConv history is PER-VISIT (exact strata hist_pool_all + visit*stride):
|
||||
// each core pass has its own history ring, NOT shared across passes. Index
|
||||
// by pass (prelude/coda use pass 0; core uses pass 0/1/2).
|
||||
@@ -179,7 +179,7 @@ pub fn load_layer(ar: &SafetensorsArchive, ip: usize, is_swa: bool) -> Result<La
|
||||
})
|
||||
}
|
||||
|
||||
pub fn new_state(d: &Dims, max_seq: usize) -> Result<LayerState, String> {
|
||||
pub fn new_state(d: &Dims, max_seq: usize, n_passes: usize) -> Result<LayerState, String> {
|
||||
let zero = |n: usize| -> Result<DeviceBuf, String> { let b = DeviceBuf::alloc(n * 4)?; b.h2d(&vec![0f32; n])?; Ok(b) };
|
||||
// KV cache dtype: F32 by default (the verified CPU-oracle baseline); FP16 via
|
||||
// VETTA_F16_KV=1 matches the strata default (KvDtype::FP16) and its
|
||||
@@ -192,9 +192,10 @@ pub fn new_state(d: &Dims, max_seq: usize) -> Result<LayerState, String> {
|
||||
let b = DeviceBuf::alloc(kv_n * 4)?; b.h2d(&vec![0f32; kv_n])?; Ok(b)
|
||||
}
|
||||
};
|
||||
let kv_vec = || -> Result<Vec<DeviceBuf>, String> { (0..n_passes.max(1)).map(|_| kv_buf()).collect() };
|
||||
Ok(LayerState {
|
||||
k_cache: [kv_buf()?, kv_buf()?, kv_buf()?],
|
||||
v_cache: [kv_buf()?, kv_buf()?, kv_buf()?],
|
||||
k_cache: kv_vec()?,
|
||||
v_cache: kv_vec()?,
|
||||
hist_k: [zero(3 * d.kv_dim())?, zero(3 * d.kv_dim())?, zero(3 * d.kv_dim())?],
|
||||
hist_v: [zero(3 * d.kv_dim())?, zero(3 * d.kv_dim())?, zero(3 * d.kv_dim())?],
|
||||
hist_a: [zero(3 * d.hidden)?, zero(3 * d.hidden)?, zero(3 * d.hidden)?],
|
||||
@@ -405,7 +406,7 @@ pub fn forward_swa_layers(
|
||||
let mut blocks: Vec<DeviceBuf> = Vec::new();
|
||||
for &ip in schedule {
|
||||
let w = cache.swa_layer(ip)?;
|
||||
let mut st = new_state(d, max_seq)?;
|
||||
let mut st = new_state(d, max_seq, 1)?;
|
||||
layer_forward_swa(cache, &w, &mut st, d, &cur, &mut blocks, pos, 0, None)?;
|
||||
}
|
||||
Ok((cur, blocks))
|
||||
@@ -490,7 +491,11 @@ fn run_layer(
|
||||
states: &mut [Option<LayerState>], max_seq: usize, pos: i32, pass: usize,
|
||||
ctrl: Option<(&ControllerWeights, &LoopMsgs)>,
|
||||
) -> Result<(), String> {
|
||||
if states[ip].is_none() { states[ip] = Some(new_state(d, max_seq)?); }
|
||||
if states[ip].is_none() {
|
||||
// Core layers run 3 loop passes (3 distinct KV pools); prelude/coda run 1.
|
||||
let n_passes = if (6..18).contains(&ip) { 3 } else { 1 };
|
||||
states[ip] = Some(new_state(d, max_seq, n_passes)?);
|
||||
}
|
||||
let st = states[ip].as_mut().unwrap();
|
||||
let r = if is_swa(ip) {
|
||||
let w = cache.swa_layer(ip)?;
|
||||
@@ -880,7 +885,7 @@ mod tests {
|
||||
let mut seed = vec![0f32; d.hidden]; cur.d2h(&mut seed).unwrap();
|
||||
let b0 = DeviceBuf::alloc(d.hidden * 4).unwrap(); b0.h2d(&seed).unwrap(); blocks.push(b0);
|
||||
let w = load_full_layer(&ar, 5, &d).unwrap();
|
||||
let mut st = new_state(&d, 1).unwrap();
|
||||
let mut st = new_state(&d, 1, 3).unwrap();
|
||||
layer_forward_full(&cache, &w, &mut st, &d, &cur, &mut blocks, 0, 0, None).unwrap();
|
||||
assert_eq!(blocks.len(), 1, "ip=5 does not snapshot (5%6!=0)");
|
||||
let mut out = vec![0f32; d.hidden]; cur.d2h(&mut out).unwrap();
|
||||
|
||||
@@ -713,7 +713,7 @@ mod tests {
|
||||
// === GPU full layer via the reusable layer forward (ld::layer) ===
|
||||
let dims = crate::layer::Dims { hidden, n_head, n_kv, hd, d_rel, rel_extent, inter, n_experts, top_k, block_size: 6, qk_clip, rel_clip, eps, route_scale, beta, lb, swa_win: 1024 };
|
||||
let lw = crate::layer::load_layer(&ar, 0, true).unwrap();
|
||||
let mut st = crate::layer::new_state(&dims, steps).unwrap();
|
||||
let mut st = crate::layer::new_state(&dims, steps, 3).unwrap();
|
||||
let cur = DeviceBuf::alloc(hidden * 4).unwrap(); cur.h2d(&x).unwrap();
|
||||
let mut blocks: Vec<DeviceBuf> = Vec::new();
|
||||
let cache = crate::layer::WeightCache::new(&ar);
|
||||
@@ -836,7 +836,7 @@ mod tests {
|
||||
let x: Vec<f32> = (0..hidden).map(|i| ((i % 53) as f32 - 26.0) * 0.02).collect();
|
||||
let dims = crate::layer::Dims { hidden, n_head, n_kv, hd, d_rel, rel_extent, inter, n_experts, top_k, block_size: 6, qk_clip, rel_clip, eps, route_scale, beta, lb, swa_win: 1024 };
|
||||
let lw = crate::layer::load_full_layer(&ar, ip, &dims).unwrap();
|
||||
let mut st = crate::layer::new_state(&dims, 1).unwrap();
|
||||
let mut st = crate::layer::new_state(&dims, 1, 3).unwrap();
|
||||
let cur = DeviceBuf::alloc(hidden * 4).unwrap(); cur.h2d(&x).unwrap();
|
||||
let mut blocks: Vec<DeviceBuf> = Vec::new();
|
||||
let cache = crate::layer::WeightCache::new(&ar);
|
||||
|
||||
Reference in new issue
Block a user