[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:
adm committed 2026-12-01 18:26:18 +01:00
1 parent b9cac6d0df
commit 7790f48c27
7 files changed
+97 -18

No files matched your search

+2
View File
@@ -125,6 +125,7 @@ mod tests {
#[test]
#[ignore]
fn chat_turn_paris() {
crate::gpu_isolated(|| {
let eng = InklingEngine::new("/mnt/models/Inkling/safetensors").unwrap();
let tok = Tokenizer::from_file("/mnt/models/Inkling/safetensors/tokenizer.json").unwrap();
let history = [ChatMessage::new("user", "What is the capital of France? Answer in one word.")];
@@ -133,5 +134,6 @@ mod tests {
eprintln!("[chat] reply={reply:?} streamed={streamed:?}");
assert_eq!(reply, streamed, "streamed text must equal the full reply");
assert!(reply.to_lowercase().contains("paris"), "reply should name Paris: {reply:?}");
});
}
}
+20
View File
@@ -20,6 +20,26 @@ pub mod serve;
#[cfg(feature = "hip")]
pub mod chat;
/// Serializes the heavy full-model GPU integration tests. Each loads the whole
/// Inkling engine (weights + KV), so running them concurrently exhausts GPU
/// memory; only one engine is resident at a time.
#[cfg(all(test, feature = "hip"))]
pub(crate) static GPU_SERIAL: std::sync::Mutex<()> = std::sync::Mutex::new(());
/// Run a heavy GPU test body under the serial lock with the buffer pool OFF.
/// Two isolation guarantees: (1) only one full-model engine is resident at a
/// time (concurrent engines exhaust GPU memory); (2) the DeviceBuf pool is
/// disabled process-wide so every drop calls hipFree and device memory is
/// actually released between tests — the thread-local pool otherwise retains
/// buffers for the lifetime of each libtest worker thread and OOMs the GPU by
/// the fifth test. Safe: no env mutation, no `unsafe` in the gw crate.
#[cfg(all(test, feature = "hip"))]
pub(crate) fn gpu_isolated<F: FnOnce()>(f: F) {
let _serial = GPU_SERIAL.lock().unwrap_or_else(|e| e.into_inner());
vetta_infer_hip::set_buf_pool_enabled(false);
f();
}
/// Python-repr float spelling (always a decimal point), as `strata-ctl` emits.
fn fmt_float(v: f64) -> String {
let s = format!("{v}");
+2 -1
View File
@@ -11,6 +11,7 @@ fn usage() {
eprintln!(" vetta-infer info <safetensors-dir> Inspect shards, dtypes, and checked bounds");
eprintln!(" vetta-infer tensors <dir> [prefix] List tensors (name, dtype, shape, bytes)");
eprintln!(" vetta-infer serve <safetensors-dir> Resident GEN/STOP/QUIT wire service (GPU, --features hip)");
eprintln!(" (alias: --serve <dir>, as strata-ctl spawns it)");
eprintln!(" vetta-infer chat <dir> [effort] [max_new] Interactive multi-turn chat (GPU, --features hip)");
eprintln!(" vetta-infer version Print version & build info");
}
@@ -94,7 +95,7 @@ fn main() -> ExitCode {
}
}
}
Some("serve") => {
Some("serve") | Some("--serve") => {
let Some(dir) = args.get(1) else {
eprintln!("error: missing <safetensors-dir>");
usage();
+41 -4
View File
@@ -243,10 +243,10 @@ pub fn serve_gen(
finish = "nonfinite";
break;
}
if rep.token == eng.eos {
finish = "stop";
break;
}
// Emit the EOS token as `T <eos>` before closing, exactly like the
// reference strata-inkling --serve: strata-ctl's Inkling dialect decoder
// reads the end-of-sampling channel token to close the model turn.
let is_eos = rep.token == eng.eos;
match sess.on_token(rep.token as u32) {
Ok(lines) => emit_all(emit, lines),
Err(e) => {
@@ -255,6 +255,10 @@ pub fn serve_gen(
return;
}
}
if is_eos {
finish = "stop";
break;
}
history.push(rep.token);
if step + 1 == g.max_new {
finish = "length";
@@ -366,6 +370,7 @@ mod tests {
#[test]
#[ignore]
fn serve_gen_paris_wire() {
crate::gpu_isolated(|| {
let eng = InklingEngine::new("/mnt/models/Inkling/safetensors").unwrap();
let g = match parse_serve_line("GEN 4 temperature=0 371,151451,149879,151194,149884", eng.vocab()).unwrap() {
ServeCommand::Gen(g) => g,
@@ -381,12 +386,14 @@ mod tests {
let dones: Vec<&String> = lines.iter().filter(|l| l.starts_with("DONE ")).collect();
assert_eq!(dones.len(), 1, "exactly one DONE per request");
assert!(dones[0].ends_with("length") || dones[0].ends_with("stop"));
});
}
/// GPU integration: `GEN 0` pre-warm emits DONE with zero tokens (Theorem 7).
#[test]
#[ignore]
fn serve_gen_prewarm_no_tokens() {
crate::gpu_isolated(|| {
let eng = InklingEngine::new("/mnt/models/Inkling/safetensors").unwrap();
let g = match parse_serve_line("GEN 0 371,151451", eng.vocab()).unwrap() {
ServeCommand::Gen(g) => g,
@@ -397,6 +404,7 @@ mod tests {
serve_gen(&eng, &g, &stop, &mut |l| lines.push(l));
assert!(!lines.iter().any(|l| l.starts_with("T ")), "pre-warm emits no tokens");
assert!(lines.iter().any(|l| l.starts_with("DONE 0 2")), "DONE 0 2 ...");
});
}
/// GPU regression: multi-token decode must match the reference EXACTLY. This
@@ -408,6 +416,7 @@ mod tests {
#[test]
#[ignore]
fn serve_gen_multi_token_parity() {
crate::gpu_isolated(|| {
let eng = InklingEngine::new("/mnt/models/Inkling/safetensors").unwrap();
let g = match parse_serve_line("GEN 16 temperature=0 371,151451,149879,151194,149884", eng.vocab()).unwrap() {
ServeCommand::Gen(g) => g,
@@ -422,5 +431,33 @@ mod tests {
.collect();
let want = [152717, 13, 68014, 32, 13, 220, 44781, 164452, 68014, 33, 13, 220, 57345, 745, 164452, 68014];
assert_eq!(tokens, want, "multi-token decode must match reference exactly");
});
}
/// GPU regression: the EOS token must be emitted as `T <eos>` before
/// `DONE ... stop` (wire-compatible with strata-inkling --serve, whose
/// dialect decoder in strata-ctl reads the end-of-sampling channel token).
/// Sequence measured against the reference for the effort-0 capital chat.
#[test]
#[ignore]
fn serve_gen_emits_eos_then_stop() {
crate::gpu_isolated(|| {
let eng = InklingEngine::new("/mnt/models/Inkling/safetensors").unwrap();
let ids = "200002,200004,34182,279,154554,150628,25,220,15,200010,200000,200004,1775,149884,149876,151451,149879,151194,30,154710,149881,150011,151290,13,200010,200001,200004";
let g = match parse_serve_line(&format!("GEN 8 temperature=0 {ids}"), eng.vocab()).unwrap() {
ServeCommand::Gen(g) => g,
_ => panic!("expected Gen"),
};
let stop = AtomicBool::new(false);
let mut lines: Vec<String> = Vec::new();
serve_gen(&eng, &g, &stop, &mut |l| lines.push(l));
let tokens: Vec<i32> = lines.iter()
.filter(|l| l.starts_with("T "))
.map(|l| l[2..].trim().parse().unwrap())
.collect();
assert_eq!(tokens, [3967, 198, 200010, 200006], "EOS must be emitted as the last T");
let done = lines.iter().find(|l| l.starts_with("DONE ")).expect("one DONE");
assert!(done.ends_with(" stop"), "finish must be stop, got {done}");
});
}
}