feat(session): honor request chat_template_kwargs in local render and outbound - #1820
Open
guapisolo wants to merge 2 commits into
Open
feat(session): honor request chat_template_kwargs in local render and outbound#1820guapisolo wants to merge 2 commits into
guapisolo wants to merge 2 commits into
Conversation
guapisolo
requested review from
Shi-Dong,
Zhichenzzz,
fzyzcjy,
jybsuper,
maocheng23 and
yueming-yuan
as code owners
July 27, 2026 07:33
Contributor
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
guapisolo
force-pushed
the
refactor/session-generated-checkpoints
branch
from
July 27, 2026 20:53
bf1445c to
9b335c1
Compare
… outbound The session server forwarded request chat_template_kwargs to SGLang but rendered input_ids with the startup tokenizer's kwargs, so a client setting its response mode split the local token stream from SGLang's parser view. Merge the request kwargs over the launch-time values into a request-scoped TITO tokenizer (a clone over the shared HF tokenizer) so the same resolved kwargs drive both the locally rendered input_ids and the outbound SGLang request; family constructors re-derive dependent kwargs (DeepSeek's effective thinking), so a stale derived value never survives the override. Family-fixed history kwargs stay authoritative: a conflicting value fails as a clear 400 via the constructor's fixed-template validation. Known accepted gaps, marked FIXME at the merge site: top-level reasoning/reasoning_effort request fields are not mirrored into the kwargs; mid-session mode-change safety is a per-family property with no guard yet (DeepSeek V3.2/V4 render history under one mode, so a flip strands old-mode prefix tokens, while Nemotron 3 and Qwen3/3.5 carry the setting per turn or only in the generation prompt and are safe — the guard belongs on FixedTemplate); and compute_session_mismatch still renders with the startup tokenizer. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
guapisolo
force-pushed
the
feat/session-request-chat-template-kwargs
branch
from
July 28, 2026 07:26
f2ae6e8 to
f1be8e9
Compare
Keep only the end-to-end request override test, relying on existing constructor coverage for conflicts and derived modes. Shorten the clone overhead note and clarify the SGLang field-mapping FIXME.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
One merged
chat_template_kwargsset drives both localinput_idsrender and the SGLang request.Motivation
The session server forwarded request chat_template_kwargs to SGLang but rendered input_ids with the startup tokenizer's kwargs, so a client setting its response mode split the local token stream from SGLang's parser view. Both sides must resolve the response mode from the same kwargs.
Usage
The request value is merged over the launch-time kwargs; the merged set renders the local
input_ids, the same set replaces the outboundchat_template_kwargs, a value conflicting with the family's fixed kwargs returns 400.Design Notes
chat_completionsbuilds a request-scoped TITO tokenizer viaclone_with_chat_template_kwargs, which re-runs the family constructor over the same HF tokenizer with the merged kwargs.core.py: top-level reasoning/reasoning_effort spellings are not mirrored into the kwargs, mid-session mode-change safety is a per-family property with no guard yet,compute_session_mismatchstill renders with the startup tokenizer.Verification
test_chat_template_kwargs_override_reaches_render_and_backend,test_chat_rejects_non_object_template_kwargs,test_chat_unknown_template_kwarg_passes_throughintest_sessions.py;TestCloneWithChatTemplateKwargsintest_tito_tokenizer.py(113 passed at this commit).Review Focus
core.pychat_completionsfor request spellings that bypass the nested object.clone_with_chat_template_kwargsfor family state the constructor does not re-pin.