mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #822] [CLOSED] Add assistant prefill support for chat completions #2852
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#2852
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/822
Author: @j-luwierski
Created: 10/4/2026
Status: ❌ Closed
Base:
main← Head:feat/assistant-prefix📝 Commits (10+)
749d957setup (--backend hip): a system ROCm without the HIP development files falls back to the wheels (#446)5a30024calibrate: the engine's arguments come from the server's engine_args; a failed tuning says why (#447)9f60d13serve, setup: name the small split card that caps the prompt chunk; setup recommends the big card alone (#448)eb8da1d/metrics: each request's speculative draft counts, and their sums in the totals (#457)6a09387setup (--gguf-dir): GGUFs Strata cannot run are named as such, with the --family/--model to use (#444)d6a91e2docs: the Coder is weaker outside code, Chinese/CJK text included; the unpruned sizes for that (#438)d8d4ad3Merge branch 'f-135-eng' into rel-0.1.357b600d5Merge branch 'f-135-small' into rel-0.1.35d9ab843Engine 0.1.35: Windows AMD uses its bundled HIP runtime (#468 #461), the low-RAM resident mode on Windows 32 GB PCs (#467), fixes #460 #459 #446 #447 #457 #448 #444; setup requires it57bd713sycl: pipeline the expert cache's profile fill (model load 3-4x faster)📊 Changes
3 files changed (+192 additions, -53 deletions)
View changed files
📝
docs/DETAILS.md(+19 -13)📝
serve/server.py(+17 -7)📝
serve/test_server.py(+156 -33)📄 Description
Problem
Strata's chat pipeline always rendered assistant turns as complete messages.
For Qwen-style chat templates, an assistant message is serialized roughly as:
and
add_generation_promptthen starts a fresh assistant turn.Because of that, there was no way to represent a partially completed assistant response and continue generation directly from it.
For example, this could not previously be expressed correctly:
with generation continuing immediately after
is.The C++/CUDA engine itself did not need any changes: it already prefills every supplied prompt token and begins decode after the final prompt token. The missing functionality was entirely in the Python chat-rendering layer.
Solution
This PR adds optional assistant prefill support through:
The prefix is treated as already-existing assistant output and becomes part of the prompt prefill.
Generation then starts immediately after the final prefix token.
Conceptually:
instead of:
No changes were required to:
Implementation
The request path remains:
The new behavior is implemented in the Python frontend/rendering layer.
Request parsing
Both supported API dialects accept the optional:
field.
Behavior:
null→ unchanged behavior""→ unchanged behaviorPrompt construction
With a prefix present, Strata renders an unfinished assistant turn rather than a complete assistant message followed by a new generation header.
The implementation renders an empty assistant turn, removes the template-generated final assistant terminator from that synthetic header, and then appends the supplied prefix directly.
This is important for two reasons:
the prefix cannot accidentally be truncated when it itself ends with text such as:
leading and trailing whitespace in the supplied prefix is preserved exactly.
The complete prompt is tokenized only after the prefix has been appended, so tokenizer boundaries remain correct.
API semantics
Given:
the prefix becomes part of prefill.
If the model generates:
the API returns only the newly generated continuation:
not:
The logical full response can therefore be reconstructed as:
Streaming follows the same rule: only newly generated deltas are emitted.
Reasoning behavior
For models using Strata's reasoning format, the assistant prefix is placed after the synthetic completed reasoning block.
As a result, newly generated continuation is returned in normal:
rather than incorrectly appearing in:
unless the model explicitly starts a new reasoning section itself.
Context accounting
Assistant-prefix tokens behave exactly like normal prompt tokens.
They:
For example:
The prefix is never inserted later as fake generated output.
Tools
assistant_prefixis supported together with tool definitions.Tool definitions continue to render in the normal system/tool section, while the prefix starts the final unfinished assistant response.
The resulting prompt retains:
Structured output
Assistant prefill also works with structured-output / JSON-schema requests.
The structured-output instruction is still inserted before the assistant turn, and validation remains active for newly generated output.
Tests verify both paths:
structured_output_failederrorAssistant prefill does not disable or bypass structured-output validation.
Special-token text
Strata tokenizes prompts with:
so literal special-token strings in
assistant_prefix, such as:retain the same semantics as equivalent text elsewhere in the existing prompt pipeline.
This behavior is intentional, tested, and documented.
Literal
<think>/</think>handling continues to follow the existing Strata reasoning-markup rules.Debug tracing
With
STRATA_DEBUGenabled, Strata reports assistant-prefill accounting without logging the prefix itself:Tests verify:
Tests
The
AssistantPrefixtest coverage now contains 20 focused cases, including:None</think><|im_end|><|im_end|>\nThe relevant test suite result is:
The remaining failure is:
and was independently reproduced on clean
main, so it is unrelated to this change.Live validation
Validated on:
Test prompt:
Without assistant prefill
Model output:
With
generated continuation:
The reconstructed logical assistant response is therefore:
Observed accounting:
Additional live validation covered:
/v1/chat/completions/v1/messagesIn streaming mode the emitted deltas contained only the generated continuation; the supplied prefix was never duplicated.
Compatibility
Without
assistant_prefix, existing prompt construction is unchanged.The following cases have explicit regression coverage:
Scope
This PR intentionally does not change:
It only adds a correct representation of a partially completed assistant turn before tokenization.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.