Skip to content

[minor] Make DEFAULT_FORCE_STREAM_INTERVAL configurable via SGLANG_FORCE_STREAM_INTERVAL - #23215

Merged
hnyls2002 merged 2 commits into
sgl-project:mainfrom
ByronHsu:byron/configurable-force-stream-interval
Apr 22, 2026
Merged

[minor] Make DEFAULT_FORCE_STREAM_INTERVAL configurable via SGLANG_FORCE_STREAM_INTERVAL#23215
hnyls2002 merged 2 commits into
sgl-project:mainfrom
ByronHsu:byron/configurable-force-stream-interval

Conversation

@ByronHsu

@ByronHsu ByronHsu commented Apr 20, 2026

Copy link
Copy Markdown
Collaborator

Motivation

For non-streaming requests (stream=False), the scheduler only flushes an intermediate output batch every DEFAULT_FORCE_STREAM_INTERVAL decoded tokens (currently a hardcoded 50). That same flush is when set_first_token_time() runs, so the engine's TTFT histogram (sglang:time_to_first_token_seconds) is biased upward by roughly (N - 1) * ITL — i.e. reported TTFT can be ~50× the true TTFT.

This makes benchmarking TTFT under stream=False hard to interpret, and there is currently no way to override the interval without patching the source.

Modifications

  • Add SGLANG_FORCE_STREAM_INTERVAL to sglang/srt/environ.py (EnvInt(50), default unchanged).
  • Resolve DEFAULT_FORCE_STREAM_INTERVAL from the env var at module import in scheduler_output_processor_mixin.py, so the per-token check stays a plain int % int == 0 comparison with no extra overhead.

Fully backward-compatible. Typical usage for accurate TTFT benchmarks:

SGLANG_FORCE_STREAM_INTERVAL=1 python -m sglang.launch_server ...

Checklist

@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!

Register `SGLANG_FORCE_STREAM_INTERVAL` (default `50`, matching today's
hardcoded value) and resolve `DEFAULT_FORCE_STREAM_INTERVAL` from it at
module import. The constant continues to be a plain int at the call site
so the per-token check stays a cheap integer comparison.

Motivation: for non-streaming requests the scheduler only flushes an
intermediate output batch every `DEFAULT_FORCE_STREAM_INTERVAL` decoded
tokens, which is also when `set_first_token_time()` runs. With the
default of 50, the engine's TTFT histogram is biased upward by roughly
`(N-1) * ITL` tokens of decode time (~50x the true TTFT for short ITLs),
which makes benchmarking TTFT under `stream=False` unreliable. Making
this overridable lets operators / benchmarks dial the interval down
(e.g. `SGLANG_FORCE_STREAM_INTERVAL=1`) for accurate TTFT measurements
without changing engine defaults.
@ByronHsu
ByronHsu force-pushed the byron/configurable-force-stream-interval branch from 2e043b1 to 19e00f6 Compare April 20, 2026 06:03
@ByronHsu ByronHsu changed the title Make DEFAULT_FORCE_STREAM_INTERVAL configurable via SGLANG_FORCE_STREAM_INTERVAL [minor] Make DEFAULT_FORCE_STREAM_INTERVAL configurable via SGLANG_FORCE_STREAM_INTERVAL Apr 20, 2026
@hnyls2002

Copy link
Copy Markdown
Collaborator

/tag-and-rerun-ci

@hnyls2002
hnyls2002 merged commit 0b77284 into sgl-project:main Apr 22, 2026
60 of 101 checks passed
ByronHsu added a commit that referenced this pull request Apr 23, 2026
caitengwei pushed a commit to caitengwei/sglang that referenced this pull request Jun 1, 2026
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants