From cd853cda8b0ae83ace64e97e7178d8cc192650df Mon Sep 17 00:00:00 2001 From: iz0eyj Date: Tue, 1 Dec 2026 17:43:03 +0100 Subject: [PATCH] [GW] Chat reliability: clean stop at end_message + debug instrumentation In the plain-content path (effort none) the assistant channel closes at <|end_message|> (200010); chat_turn now raises stop there so the reply is exactly the content even when the trailing EOS is delayed by a near-tie (the model used to emit unused special tokens past end_message and run to max_new). Live: the one-word capital question now returns clean 'Paris' instead of 'Paris'+garbage. Add VETTA_DBG_PROMPT (rendered prompt + ids) and VETTA_DBG_LOGITS (per-step top-5) for parity bisection. chat_turn_paris GPU test green; workspace -D warnings green. --- crates/vetta-infer-gw/src/chat.rs | 14 ++++++++++++++ crates/vetta-infer-gw/src/serve.rs | 6 ++++++ 2 files changed, 20 insertions(+) diff --git a/crates/vetta-infer-gw/src/chat.rs b/crates/vetta-infer-gw/src/chat.rs index 9c91762..0a852f5 100644 --- a/crates/vetta-infer-gw/src/chat.rs +++ b/crates/vetta-infer-gw/src/chat.rs @@ -28,8 +28,14 @@ pub fn chat_turn( on_text: &mut dyn FnMut(&str), ) -> Result { let prompt = render_prompt(history, effort)?; + if std::env::var("VETTA_DBG_PROMPT").is_ok() { + eprintln!("[chat] prompt={prompt:?}"); + } let enc = tok.encode(prompt, false).map_err(|e| e.to_string())?; let ids: Vec = enc.get_ids().iter().map(|&x| x as i32).collect(); + if std::env::var("VETTA_DBG_PROMPT").is_ok() { + eprintln!("[chat] prompt_ids={ids:?}"); + } let g = ParsedGen { max_new, sampling: SamplingOpts::default(), // greedy, deterministic @@ -40,6 +46,11 @@ pub fn chat_turn( ids, }; let stop = AtomicBool::new(false); + // In the plain-content path (effort none) the assistant content channel closes + // at <|end_message|> (200010); the model then emits EOS. Stop at end_message so + // the reply is exactly the content even if the trailing EOS is delayed by a + // near-tie (the reference closes the channel here too). + let stop_at_end_message = effort.trim() == "none"; let mut generated: Vec = Vec::new(); let mut printed = 0usize; let mut full = String::new(); @@ -57,6 +68,9 @@ pub fn chat_turn( } full = txt; } + if stop_at_end_message && id == 200010 { + stop.store(true, std::sync::atomic::Ordering::Relaxed); + } }; serve_gen(eng, &g, &stop, &mut emit); } diff --git a/crates/vetta-infer-gw/src/serve.rs b/crates/vetta-infer-gw/src/serve.rs index 6a445b3..005e805 100644 --- a/crates/vetta-infer-gw/src/serve.rs +++ b/crates/vetta-infer-gw/src/serve.rs @@ -229,6 +229,12 @@ pub fn serve_gen( return; } let rep = sample_logits_exact(&mut lg, &opts, &history, None, &mut rng, &mut scratch); + if std::env::var("VETTA_DBG_LOGITS").is_ok() { + let mut idx: Vec = (0..eng.vocab).collect(); + idx.sort_by(|&a, &b| lg[b].partial_cmp(&lg[a]).unwrap()); + let top: Vec<(usize, f32)> = idx[..5].iter().map(|&i| (i, lg[i])).collect(); + eprintln!("[dbg] step={step} pos={pos} top5={top:?}"); + } if rep.nonfinite_logits == eng.vocab { finish = "nonfinite"; break;