Repository navigation
Fix tp worker only checking req[0] for stream - #546
Merged
Merged
Conversation
Qubitium
marked this pull request as ready for review
June 14, 2024 03:50
Ying1123
approved these changes
Jun 15, 2024
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.
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.
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].streamand use a newBatch.has_stream(self) -> boolhelper function to check if any batch.req hasstream == true.TESTS: