Files
llama.cpp/tools
LumpiastyandClaude Opus 5.5 25d6e1e9b6 server: merge user-message batch breaks when the rest of the prompt fits in one ubatch, keep the first-user-message break (F14)
Knob LLAMA_USERSTART_MERGE=0 (upstream behaviour).

Squashed from 2 fork commits (original subjects and messages below).

---- server: merge user-message batch breaks when the rest of the prompt fits in one ubatch (was 7e738d747)

Upstream (#22929, #24176, #25420) ends a prompt batch at the start of the last
user message (and of earlier ones on a fresh prompt) so that a context
checkpoint lands there. On a hybrid/recurrent model with MoE experts on the
host, that turns a typical chat turn (previous answer + new user message, under
one ubatch) into two partial ubatches, and each one of >= 32 tokens uploads the
host experts again.

When the rest of the prompt from the current batch start fits in one ubatch,
skip the user-start break. The near-end rule still checkpoints the batch start
and the end-4 rule the prompt end, so a later prompt that diverges inside the
last user message re-processes less than one ubatch more, in the same ubatch.
Prompts longer than one ubatch, and batches after a media chunk, keep the
upstream behaviour. LLAMA_USERSTART_MERGE=0 restores it everywhere.

---- server: F14 - keep the batch break at the first user message (system-prompt checkpoint) (was e7e907b7c)

With LLAMA_USERSTART_MERGE on (the default), F14 skipped every user-message
batch break when the rest of the prompt fits in one ubatch. On a fresh
prompt that also dropped the break at the first user message, so no context
checkpoint was left at the end of the system prompt, and a new chat with the
same system prompt re-processed the system prompt from scratch (a
recurrent/hybrid state cannot be cut back without a checkpoint).

Keep that one break in the merged path: the batch ends right before the
first user message, and the next batch starts there and gets the checkpoint
(is_user_start, near-end rule). The batch only reaches the first user
message when the prompt is processed from before it: checkpoints past the
restore point are erased on reuse, so this is a fresh prompt or one that
diverged inside the system prompt. Follow-up turns start past it and keep
the merge (no break at the last user message). Boundaries below 8 tokens
(only a BOS before the first user message) are skipped.

Cost: on a fresh prompt the system prompt runs as its own batch again (the
upstream layout for turn 1), measured before as part of turn 1's
6.08 vs 3.99 s TTFT (FORK.md F14). The unmerged path is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PZz44SLQvTXMyWGio6t9DZ
2026-11-23 11:54:11 +01:00
..
2026-11-12 20:59:09 +02:00
2026-11-04 10:10:22 +02:00
2026-11-12 20:59:09 +02:00
2026-11-12 20:59:09 +02:00