Skip to content

feat(session): honor request chat_template_kwargs in local render and outbound - #1820

Open
guapisolo wants to merge 2 commits into
mainfrom
feat/session-request-chat-template-kwargs
Open

feat(session): honor request chat_template_kwargs in local render and outbound#1820
guapisolo wants to merge 2 commits into
mainfrom
feat/session-request-chat-template-kwargs

Conversation

@guapisolo

Copy link
Copy Markdown
Collaborator

Depends on: #1819
Stacked on the parent PR's branch. Review / merge the parent first.

Summary

One merged chat_template_kwargs set drives both local input_ids render 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

POST /sessions/{session_id}/v1/chat/completions
{"messages": [...], "chat_template_kwargs": {"enable_thinking": false}}

The request value is merged over the launch-time kwargs; the merged set renders the local input_ids, the same set replaces the outbound chat_template_kwargs, a value conflicting with the family's fixed kwargs returns 400.

Design Notes

  • Key choices: chat_completions builds a request-scoped TITO tokenizer via clone_with_chat_template_kwargs, which re-runs the family constructor over the same HF tokenizer with the merged kwargs.
  • Re-running the constructor gives conflict validation for free; it also re-derives dependent kwargs such as DeepSeek's effective thinking.
  • The startup singleton is never mutated; the clone is request-scoped.
  • Accepted gaps are marked FIXME in 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_mismatch still renders with the startup tokenizer.

Verification

  • Tests added: test_chat_template_kwargs_override_reaches_render_and_backend, test_chat_rejects_non_object_template_kwargs, test_chat_unknown_template_kwarg_passes_through in test_sessions.py; TestCloneWithChatTemplateKwargs in test_tito_tokenizer.py (113 passed at this commit).

Review Focus

  • Scrutinize the kwargs merge block in core.py chat_completions for request spellings that bypass the nested object.
  • Scrutinize clone_with_chat_template_kwargs for family state the constructor does not re-pin.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@guapisolo
guapisolo force-pushed the refactor/session-generated-checkpoints branch from bf1445c to 9b335c1 Compare July 27, 2026 20:53
Base automatically changed from refactor/session-generated-checkpoints to main July 28, 2026 07:04
… 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
guapisolo force-pushed the feat/session-request-chat-template-kwargs branch from f2ae6e8 to f1be8e9 Compare July 28, 2026 07:26
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant