Skip to content

Fix tp worker only checking req[0] for stream - #546

Merged
Ying1123 merged 1 commit into
sgl-project:mainfrom
Qubitium:fix-tpworker-stream-check
Jun 15, 2024
Merged

Ying1123 merged 1 commit into
sgl-project:mainfrom
Qubitium:fix-tpworker-stream-check

Conversation

@Qubitium

@Qubitium Qubitium commented Jun 14, 2024 •

Copy link
Copy Markdown
Contributor

One condition of early exiting the decoding batch (fixed 10 size) loop is to check if batch contains streaming requests.

Fix the current code in tp_worker which only checks the first request self.running_batch.reqs[0].stream and use a new Batch.has_stream(self) -> bool helper function to check if any batch.req has stream == true.

TESTS:

  • PASSED Mixed stream + non-stream + tp=2

@Qubitium
Qubitium marked this pull request as ready for review June 14, 2024 03:50
@Ying1123
Ying1123 merged commit bbec01c into sgl-project:main Jun 15, 2024
@Qubitium
Qubitium deleted the fix-tpworker-stream-check branch June 15, 2024 13:35
timethink pushed a commit to timethink/sglang that referenced this pull request Mar 9, 2025
efschu added a commit to efschu/htsglang that referenced this pull request Aug 4, 2026
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 5, 2026
…buffer with garbage

The sgl-project#286 ledger parked a module by capturing state_dict() and restored it with
to_empty(device=...) followed by load_state_dict(..., strict=True).
state_dict() omits NON-PERSISTENT buffers by definition; to_empty()
re-materialises them anyway, with whatever was in that memory; and the strict
load then fills only the keys the state dict has. So every non-persistent
buffer came back as uninitialised memory, while park and restore both reported
success and the measured restore latency looked healthy. strict=True cannot
catch it: the keys are missing from BOTH sides, which is precisely why the
asymmetry is invisible at the seam.

For the translator that buffer is the rotary inv_freq. The symptom is NaN
cos/sin -> NaN attention scores -> NaN logits -> "probability tensor contains
inf, nan or element < 0" from torch.multinomial, one park and thirty layers
from the cause, and only when sampling actually runs.

REACHABLE BY DEFAULT. IdleParkConfig.enabled is True, and the sgl-project#546 translator
idle park drives exactly this pair: ledger.park_all() on the way down,
ensure_resident() -> ledger.restore() on the way back. So the corruption was on
the default path of a default-on feature, not behind a flag.

The same failure already had a repair on the LOAD path
(qwen3_tts_compat.refresh_rotary_buffers, whose docstring describes this NaN
chain in full). The RESTORE path never got an equivalent and nothing connected
the two -- the fork had diagnosed the failure once and stayed exposed to it
through a second door.

Fixed GENERICALLY in the ledger rather than per-module: park captures the
non-persistent buffers (named_buffers() minus the state-dict keys, skipping
meta) alongside the state dict, and restore writes them back through
register_buffer(persistent=False) into the owning submodule, so the flag
survives the round trip and a second park still finds them. The bytes are
carried VERBATIM rather than recomputed -- recomputation is a per-module repair
someone has to remember to write for each new buffer, while copying is correct
for every module the ledger will ever be handed, and is bit-exact besides.
Kept in its own dict, not merged into _cpu_state, because the restore's
strict=True load rejects keys the module does not expect.

A module with no non-persistent buffers takes the unchanged path.

Tests (CUDA_VISIBLE_DEVICES=99, hermetic, no GPU, no server):
  PYTHONPATH=python pytest test/registered/translator -q
  -> 645 passed, 2 warnings, 37 subtests passed in 24.80s

CAN-FAIL PROVEN: neutralising the restore write-back turns 3 of the 5 new tests
red -- "the non-persistent buffer did not survive the park round" for the
bit-identity test, plus the second-round and nested-submodule tests -- because
to_empty leaves the buffer holding whatever the allocator handed out. The other
two are the no-regression halves (persistent state untouched; a module without
such buffers unchanged) and stay green either way, which is their job.

The tests assert CORRECTNESS AFTER RESTORE -- the values, and that inv_freq is
genuinely absent from state_dict() so the premise is checked rather than
assumed -- not how many such buffers a model has, which is a property of the
model and no constant worth pinning.

FEATURE_CATALOG gains the round-trip-asymmetry family entry.
ruff check: no new findings. ruff format: clean on all added lines.
codespell: clean.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants