Skip to content

[3/N][Sync sglang-miles] TITO Support - #23751

Merged
JustinTong0323 merged 7 commits into
sgl-project:mainfrom
zyzshishui:tito
Jun 4, 2026
Merged

JustinTong0323 merged 7 commits into
sgl-project:mainfrom
zyzshishui:tito

Conversation

@zyzshishui

@zyzshishui zyzshishui commented Apr 26, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

Synced from 69018ba and 3606aec.

Modifications

  • Add TITO-style chat support with pre-tokenized input_ids.
  • Allow non-streaming chat responses to return prompt_token_ids and optional meta_info.

Accuracy Tests

Speed Tests and Profiling

Checklist

Review and Merge Process

  1. Ping Merge Oncalls to start the process. See the PR Merge Process.
  2. Get approvals from CODEOWNERS and other reviewers.
  3. Trigger CI tests with comments or contact authorized users to do so.
    • Common commands include /tag-and-rerun-ci, /tag-run-ci-label, /rerun-failed-ci
  4. After green CI and required approvals, ask Merge Oncalls or people with Write permission to merge the PR.

CI States

Latest PR Test (Base): ✅ Run #26835556808
Latest PR Test (Extra): ❌ Run #26835555924

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e02a19bc79

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

for i in range(batch_size):
tmp_obj = obj[i]
state = self.rid_to_state[tmp_obj.rid]
if getattr(tmp_obj, "return_prompt_token_ids", False):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Preserve prompt-token-id flag in batched subrequests

This condition reads return_prompt_token_ids from tmp_obj, but in batched/parallel paths tmp_obj is produced by GenerateReqInput.__getitem__, which does not copy the new field and leaves it at the default False. That means requests with n > 1 (or true batched requests) never set state.prompt_token_ids, so prompt_token_ids is silently omitted from non-streaming chat responses even when callers set return_prompt_token_ids=true.

Useful? React with 👍 / 👎.

# only stop tokens and tool_call_constraint are needed.
if request.input_ids is not None:
result = MessageProcessingResult(
prompt=self.tokenizer_manager.tokenizer.decode(request.input_ids),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Avoid tokenizer decode in pretokenized input_ids path

The pre-tokenized input_ids branch unconditionally calls self.tokenizer_manager.tokenizer.decode(...). In deployments with skip_tokenizer_init=True, the tokenizer can be None while input_ids requests are still valid, so this path crashes before generation. This breaks the new TITO flow for tokenizer-less configurations that should otherwise accept raw token IDs.

Useful? React with 👍 / 👎.

message=ChatMessage(
role="assistant",
content=text if text else None,
content=text if text else "",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Not sure whether this is acceptable. Cuz many chat template will treat None as None string... It will be weird.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

+1

@guapisolo guapisolo Jun 2, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Sorry my previous word is confusing. I mean whether it should be modified to ""? Cuz original impl, we insert None instead of "", then the text will be <|assistant|> None, which is weird.

@zyzshishui

Copy link
Copy Markdown
Contributor Author

/tag-run-ci-label

@github-actions github-actions Bot added the run-ci CI: run the baseline test suite on this PR label Jun 1, 2026

# Handle single vs multiple requests
if is_multimodal:
prompt_kwargs = {"text": processed_messages.prompt}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Prioritize request.input_ids here before the multimodal text branch. The input_ids path sets processed_messages.prompt to "", but this branch still sends text="" whenever model_config.is_multimodal is true, so TITO requests on multimodal model servers silently generate from an empty prompt instead of the supplied token IDs. Add an is_multimodal=True regression test for the pre-tokenized path.

@zyzshishui zyzshishui Jun 2, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I temporarily leave the last else for the existing non-multimodal path, but do you think it's better to do a different factoring like

if request.input_ids is not None or (
    not is_multimodal and not isinstance(processed_messages.prompt_ids, str)
):

to avoid the repeated prompt_kwargs = {"input_ids": processed_messages.prompt_ids}?

message=ChatMessage(
role="assistant",
content=text if text else None,
content=text if text else "",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

+1

@zyzshishui
zyzshishui requested a review from JustinTong0323 June 2, 2026 17:08

@JustinTong0323 JustinTong0323 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good to me.

@JustinTong0323
JustinTong0323 enabled auto-merge (squash) June 3, 2026 03:57
@guapisolo

Copy link
Copy Markdown
Collaborator

/rerun-failed-ci

@JustinTong0323
JustinTong0323 merged commit e03dfa8 into sgl-project:main Jun 4, 2026
186 of 232 checks passed
@zyzshishui
zyzshishui deleted the tito branch June 4, 2026 03:34
linnanwang added a commit to linnanwang/Gym that referenced this pull request Aug 3, 2026
Chat-side TITO is native in the 0.5.13 release, not main-only: sgl-project/sglang#23751
merged 2026-06-04 and v0.5.13 was cut 2026-06-13, so the tag contains it. Stock
0.5.13 exposes `return_prompt_token_ids` / `return_meta_info` on the request and
`prompt_token_ids` / `meta_info` on each choice. No patched build or fork is
required -- ProRL's `patch_sglang_0513_token_metadata.sh` only makes
`logprobs=true` imply those flags, which this server sets explicitly.

`transport: chat` (new default) therefore inherits everything from VLLMModel and
overrides only `_attach_token_id_information`. Prompt templating, tool-call
parsing, sampling params, auth and context-overflow handling all move server-side,
which removes -- rather than patches -- the local-tokenizer drift, the missing
Authorization header, the client-side `cap_to_context` truncation, the dropped
sampling params, and the event-loop blocking of local tokenization.

`transport: generate` keeps the native `/generate` path for builds that predate
chat-side TITO (e.g. forks serving diffusion LLMs), with fixes: merged
`chat_template_kwargs` so per-request overrides are honored, `tools` rendered into
the prompt, an Authorization header, expanded sampling params plus a loud warning
for ones it cannot honor, and an overflowing prompt returning a filterable empty
`finish_reason="length"` instead of a head-truncated prompt.

In both transports a generation SGLang reports as `finish_reason="abort"` now
raises, so a server-cancelled partial rollout cannot enter a training batch
looking like a normal completion.

Also: `trust_remote_code` defaults to false, `transformers` is pinned and imported
lazily, the cross-server import uses a plain import (matching
local_vllm_model_proxy), and `cap_to_context` rejects a context too small to
generate instead of POSTing a negative `max_new_tokens`.

Tests are rebuilt on the vllm_model convention -- a real SGLangModel with a mocked
ServerClient -- so the real inherited preprocess runs rather than being stubbed,
and all patching goes through `monkeypatch` so module globals cannot leak between
tests. 27 pure-logic tests pass (up from 19).

The on-policy guarantee is documented as single-turn and AR-mode: under block
diffusion the per-token logprob is an estimator, not the logprob of an AR draw.
The obsolete vllm-vs-sglang diagnostic is dropped; its finding (the version
boundary) is now stated in the README.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: linnan wang <[email protected]>
linnanwang added a commit to linnanwang/Gym that referenced this pull request Aug 3, 2026
Chat-side TITO is native in the 0.5.13 release, not main-only: sgl-project/sglang#23751
merged 2026-06-04 and v0.5.13 was cut 2026-06-13, so the tag contains it. Stock
0.5.13 exposes `return_prompt_token_ids` / `return_meta_info` on the request and
`prompt_token_ids` / `meta_info` on each choice. No patched build or fork is
required -- ProRL's `patch_sglang_0513_token_metadata.sh` only makes
`logprobs=true` imply those flags, which this server sets explicitly.

`transport: chat` (new default) therefore inherits everything from VLLMModel and
overrides only `_attach_token_id_information`. Prompt templating, tool-call
parsing, sampling params, auth and context-overflow handling all move server-side,
which removes -- rather than patches -- the local-tokenizer drift, the missing
Authorization header, the client-side `cap_to_context` truncation, the dropped
sampling params, and the event-loop blocking of local tokenization.

`transport: generate` keeps the native `/generate` path for builds that predate
chat-side TITO (e.g. forks serving diffusion LLMs), with fixes: merged
`chat_template_kwargs` so per-request overrides are honored, `tools` rendered into
the prompt, an Authorization header, expanded sampling params plus a loud warning
for ones it cannot honor, and an overflowing prompt returning a filterable empty
`finish_reason="length"` instead of a head-truncated prompt.

In both transports a generation SGLang reports as `finish_reason="abort"` now
raises, so a server-cancelled partial rollout cannot enter a training batch
looking like a normal completion.

Also: `trust_remote_code` defaults to false, `transformers` is pinned and imported
lazily, the cross-server import uses a plain import (matching
local_vllm_model_proxy), and `cap_to_context` rejects a context too small to
generate instead of POSTing a negative `max_new_tokens`.

Tests are rebuilt on the vllm_model convention -- a real SGLangModel with a mocked
ServerClient -- so the real inherited preprocess runs rather than being stubbed,
and all patching goes through `monkeypatch` so module globals cannot leak between
tests. 27 pure-logic tests pass (up from 19).

The on-policy guarantee is documented as single-turn and AR-mode: under block
diffusion the per-token logprob is an estimator, not the logprob of an AR draw.
The obsolete vllm-vs-sglang diagnostic is dropped; its finding (the version
boundary) is now stated in the README.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: linnan wang <[email protected]>
Chronostasys pushed a commit to MindLab-Research/sglang that referenced this pull request Aug 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

run-ci CI: run the baseline test suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants