Skip to content

server: fix prefill speed regression on session resumption - #25417

Closed
SakshamKapoor2911 wants to merge 1 commit into
ggml-org:masterfrom
SakshamKapoor2911:fix-prefill-speed-regression
Closed

server: fix prefill speed regression on session resumption#25417
SakshamKapoor2911 wants to merge 1 commit into
ggml-org:masterfrom
SakshamKapoor2911:fix-prefill-speed-regression

Conversation

@SakshamKapoor2911

Copy link
Copy Markdown

Overview

This PR resolves the prefill speed regression on session resumption (Issue #25213).

Previously, the prefill batch loop in server-context.cpp unconditionally split the batch at any user message start boundary. When resuming a session, this caused the prefill sequence to be fragmented into many tiny batches, severely bottlenecking GPU prefill throughput.

This PR optimizes prefill batching and adds dynamic tool start detection to prevent unnecessary batch splitting:

  1. Conditional Batch Splitting: The prefill batch loop is refactored to conditionally break before a user message start boundary only when context checkpointing is enabled, and a checkpoint is actually scheduled to be taken (i.e., spacing respects checkpoint_min_step).
  2. Tool Response Start Delimiter Detection: Added dynamic tool start detection using template diffing in detect_tool_response_start_marker to ensure tool outputs are not misclassified as user roles.
  3. Delimiter Match Order Overlap: Parsed delimiters are sorted by length descending to ensure longer, specialized delimiters match first instead of partial overlapping short matches.
  4. Restored Default: Reverted the temporary workaround value of checkpoint_min_step from 8192 back to 256 tokens.

Additional information

Requirements

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: YES - AI was used in an assistive capacity to draft code changes for the conditional batch splitting in server-context.cpp, update delimiter sorting in chat.cpp, implement the tool response start detector in chat-diff-analyzer.cpp, and populate the expected test cases in test-chat-auto-parser.cpp. All changes have been compiled, run, and verified locally by the human contributor.

Copilot AI review requested due to automatic review settings July 7, 2026 21:31
@SakshamKapoor2911
SakshamKapoor2911 requested review from a team and ggerganov as code owners July 7, 2026 21:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@SakshamKapoor2911
SakshamKapoor2911 force-pushed the fix-prefill-speed-regression branch from a1c5cd8 to ceb99ac Compare July 17, 2026 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

server testing Everything test related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Misc. bug: Substantial prefill speed regression when resuming long session from a coding agent

2 participants