Skip to content

Commit 2f61c0f

Browse files
vinkal-chudgarCISC
andauthored
llama-cli: prevent spurious assistant token (ggml-org#16202)
* tools/main: llama-cli: prevent spurious assistant token (ggml-org#13402) During prompt ingestion, prompt tokens are accepted into the sampler history (for repetition penalties). The conversation-mode path then appended `common_sampler_last(smpl)` to `assistant_ss` before any new token was sampled. At that point, "last" was a prompt-side token (e.g., an input prefix), so the assistant chat message began with an extra piece. Fix: append to `assistant_ss` only for a newly sampled (non-EOG) token. This affects only chat message assembly (`assistant_ss` / `chat_msgs` / `common_chat_format_single`); terminal stdout is unchanged. Sampling order/logits are unchanged. Fixes ggml-org#13402. Signed-off-by: Vinkal Chudgar <[email protected]> * Update tools/main/main.cpp Co-authored-by: Sigbjørn Skjæret <[email protected]> * tools/main: remove outdated comment Signed-off-by: Vinkal Chudgar <[email protected]> --------- Signed-off-by: Vinkal Chudgar <[email protected]> Co-authored-by: Sigbjørn Skjæret <[email protected]>
1 parent 3ffd0fa commit 2f61c0f

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

tools/main/main.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,10 @@ int main(int argc, char ** argv) {
707707

708708
embd.push_back(id);
709709

710+
if (params.conversation_mode && !waiting_for_first_input && !llama_vocab_is_eog(vocab, id)) {
711+
assistant_ss << common_token_to_piece(ctx, id, false);
712+
}
713+
710714
// echo this to console
711715
input_echo = true;
712716

@@ -824,11 +828,7 @@ int main(int argc, char ** argv) {
824828
}
825829
}
826830

827-
// if current token is not EOG, we add it to current assistant message
828831
if (params.conversation_mode && !waiting_for_first_input) {
829-
const auto id = common_sampler_last(smpl);
830-
assistant_ss << common_token_to_piece(ctx, id, false);
831-
832832
if (!prompt.empty()) {
833833
prompt.clear();
834834
is_interacting = false;

0 commit comments

Comments
 (0)