Repository navigation
Fix max_tokens for OpenAI chat completion API - #766
Merged
Merged
Conversation
3 tasks
zhyncs
approved these changes
Jul 27, 2024
Merged
timethink
pushed a commit
to timethink/sglang
that referenced
this pull request
Mar 9, 2025
efschu
pushed a commit
to efschu/htsglang
that referenced
this pull request
Aug 20, 2026
…ion, not before the exchange
A boot reached serving, one admissible queued request was never served, and the
process died. The wedge detector reported "1 queued, 0 running, NO first token
for 340-370s and no prefill chunk either" and named its own gap in the same
line -- "no phase-policy corroboration seen -- the wedge class is broader than
that path". It was right: this is not an admission defect at all.
EVIDENCE OF RECORD. py-spy on the specimen (WEDGE_788_specimen.log:732/915/1083)
catches all three ranks in a circular wait:
PP0, PP1 gloo waitSend _pp_commit_comm_work (scheduler_pp_mixin.py:2465)
from _pp_forward_and_process_input_requests:1007
PP2 gloo waitRecv _pp_recv_typed_dict:2709
from _pp_recv_proxy_tensors:2803
The request chain was flushed at the TOP of the pass, before the rank had
posted anything else it owed its peers that iteration -- the proxy tensor-dict
send and the output-ring send both come later in _event_loop_pp_body. A
downstream whose progress needs one of those was therefore waiting on a rank
that was itself waiting on that downstream. The chain recv is posted only at
the top of a pass (:420) and nowhere else in the loop body, so a rank parked in
the proxy receive cannot drain the message its upstream is blocked flushing.
THE FIX IS ONE ADDITION. _pp_forward_and_process_input_requests is byte-identical
to before: it still commits send_req_work, then posts the async forward, then
runs process_input_requests. What is new is _pp_commit_pending_req_work, called
once per iteration from _event_loop_pp_body after the proxy isend and the output
commit and BEFORE the phase-flip round hook. By the time that loop returns to
the top-of-pass commit, the handle has already been waited on and cleared, so
the old call site is a no-op there -- and the two disaggregation loops (:618,
:765), which do not call the new method, keep their previous behaviour exactly.
Deleting rather than moving the old call site is deliberate on both counts: it
keeps the sgl-project#633 ordering contract literally intact (commit, then forward, then
process, with send_req_work holding this pass's handle on return -- pinned by
test_scheduler_pp_request_order_633), and it avoids a second staging slot. An
earlier shape of this fix did stage the send separately; it broke that contract
and left the two disagg loops overwriting a live P2PWork handle every pass.
Precedent: a7ff250 "[sgl-project#753] Flush the output sends after the exchange, not
before it" made the same move for the OUTPUT channel. This is that fix for the
REQUEST channel, ungated -- the hazard is not gapped-specific.
NEGATIVE FINDING, RECORDED RATHER THAN BURIED. A deterministic 3-process gloo
reproduction of the specimen deadlock was attempted and NOT achieved under a
faithful model of the loop. Two candidate mechanisms were tested and refuted:
- Eager-send asymmetry. Hypothesis: an empty request list puts one 8-byte
tensor on the wire and completes eagerly, so only a large first request can
block. MEASURED FALSE: a 2-process probe with a 2.0s-delayed matching recv
blocked for the full delay at every payload size from 8 B to 1 MiB in this
build. No eager completion at any size.
- Schedule asymmetry. A linear chain+proxy relay that flushes the old handle
before dispatching the new one is deadlock-free by induction (each rank's
flush needs only its immediate downstream one pass behind), and dozens of
real 3-process runs across depths and offset combinations all completed.
So the reduced two-channel model cannot close a cycle. The production graph has
an edge that model lacks: the output ring closes last-rank -> rank 0
(_pp_send_recv_and_preprocess_output_tensors:3038, last-rank branch :3012-3014,
via next_first_rank_mb_id at :416/:608/:754). That, and real GPU compute skew,
are the two named unconfirmed candidates for the missing ingredient. Neither is
built into the test, and the gap is stated in its docstring rather than papered
over. The mechanism's evidence of record therefore remains the py-spy trace
above plus the sgl-project#753 precedent, and the survival boot is the integration proof.
RECOVERY RUNG. The detector gains one bounded action: after a wedge stays
continuously alarming past a threshold well above the report threshold (default
3x, env SGLANG_ADMISSION_WEDGE_RECOVERY_SECONDS; non-positive values fall back
to the default rather than firing every poll), it makes ONE forced-admission
attempt per episode through the existing corridor_admission actuator and logs it
loudly either way. Its own docstring is explicit that it relieves VRAM pressure
at the admission site and will NOT move a comms deadlock like this one, and that
calling an actuator from the watchdog thread is a new cross-thread shape over
CUDA allocator state.
TESTS
test_pp_chain_flush_deadlock_788.py (new; 3 real gloo processes, CPU only)
- load-bearing: runtime ordering pin. The SHIPPED _pp_commit_pending_req_work
is wrapped and the observed sequence asserted to be
proxy_send -> chain_flush -> round_hook for every pass and every non-last
rank, so the flush cannot drift back past the collective and cost it the
"last blocking op of the iteration" property its own comment relies on.
- can-fail: the same run with the flush relocated to the top records a
different sequence, so the pin discriminates placement.
- the honest negative case described above, in place of the deleted
hang-repro. A test that is green or red for the wrong reason is worse
than no test.
test_pp_flip_leftover_proxy_757.py: harness-only repair, no assertion touched.
It was silently DEAD on this branch -- its _GlooWire predated
rank_in_group/world_size and the src positional recv_typed_tensor_dict now
passes, so it errored 3/3 before reaching an assertion. Now 3 passed and a
working regression check again.
Verified green with this diff: test_pp_chain_flush_deadlock_788 and
test_scheduler_pp_request_order_633 (8 passed), test_phase_policy (90 passed),
test_pp_flip_leftover_proxy_757 (3 passed).
PRE-EXISTING FAILURES, MEASURED NOT ASSUMED. The managers slice reads 43F/2707P
here against 39F/2705P at a pristine detached ff5651a worktree. Every delta
is accounted for: -3 (the 757 repair above now passes), +5 stub drift and +1
ordering-contract break, both introduced by the earlier staging-slot shape and
both gone with it, +1 test_pp_drain_completeness_787 which is INTENTIONALLY RED
here -- that file's fix lives on fix/787-drain-completeness and it flips green
at the merge, which makes it a free integration can-fail. The residual 39 are
the same interface-drift family (rank_in_group, _pp_gapped_wire) plus one stale
constant, all present at base with no part of this diff.
DEBTS
sgl-project#789 the two disaggregation PP loops keep the top-of-pass
flush and therefore still carry this hazard
sgl-project#757-harness-drift repaired here; the same drift still blinds
test_pp_proxy_stamp_631 and test_pp_slot_last_batch_631
sgl-project#753-stale-constant 10.923 != 11.923 in the gapped entry protocol test
sgl-project#766-pointer-stale the register points sgl-project#766 at ARM_defaultfull7.log, which
is a 26-line host-ledger snapshot with no
Bar1CollectiveAborted and no proxy/drain lines
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.
Fix the early stop issue in #765