[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.
This commit is contained in:
adm committed 2026-12-01 17:43:03 +01:00
1 parent 74b3384270
commit cd853cda8b
2 files changed
+20

No files matched your search

+14
View File
@@ -28,8 +28,14 @@ pub fn chat_turn(
on_text: &mut dyn FnMut(&str),
) -> Result<String, String> {
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<i32> = 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<u32> = 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);
}
+6
View File
@@ -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<usize> = (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;