Skip to content

Pr fix max workers - #1456

Merged
merrymercy merged 3 commits into
sgl-project:mainfrom
wellhowtosay:pr-fix-max-workers
Sep 22, 2024
Merged

merrymercy merged 3 commits into
sgl-project:mainfrom
wellhowtosay:pr-fix-max-workers

Conversation

@wellhowtosay

Copy link
Copy Markdown
Contributor

Motivation

the default value for max_workers is the num of cpu on the physical server, this may cause problems when running on a docker with much less cpu cores than its physical server.

#1424

Modifications

add param image_processor_max_workers to ServerArgs as the max_workers for ProcessPoolExecutor

Checklist

  • Format your code according to the Contributor Guide.
  • Add unit tests as outlined in the Contributor Guide.
  • Update documentation as needed, including docstrings or example tutorials.

Comment thread python/sglang/srt/server_args.py Resolved
@merrymercy

Copy link
Copy Markdown
Collaborator

@wellhowtosay Thanks for the contribution. I updated your PR with an environment variable SGLANG_CPU_COUNT

@merrymercy
merrymercy merged commit 2a99993 into sgl-project:main Sep 22, 2024
timethink pushed a commit to timethink/sglang that referenced this pull request Mar 9, 2025
Co-authored-by: baolujia <[email protected]>
Co-authored-by: Lianmin Zheng <[email protected]>
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 17, 2026
…e reads while the group sleeps; the orphan collector spares held requests

Boot weg2xsn211 (sgl-project#1455): prefill end -> first joint decode 8.0 s (was
11.3). Of the remaining 8 s, 5 s were readmission after the wake: the reads
issued at the hold terminated SHORT (weg2-6-7: 69631 of 99570 pages --
P's write-through had not landed a second after its leg answered), the
drain's sgl-project#1233 orphan collector then closed them ('left the waiting queue
with the prefetch open'), and the missing 30 % loaded only after the wake
(sgl-project#1324 STORE READ INCOMPLETE -> deferred -> re-read at 06:00:04).

* _weg2_hold_refetch (Scheduler.on_idle while dormant with a hold): for
  every held request whose read has finished, the existing shortfall
  detector (_weg2_note_store_shortfall) decides; a short read is re-issued
  from the registered extent on, at most every 2 s per request, its
  deferral fields cleared first.  Fail-soft.
* the orphan collector skips rids in weg2_dormant_hold.

Tests: test_weg2_hold_refetch_1456 (4) + dormant_hold_1445 +
prefetch_deferral_1068: 54 passed.
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 17, 2026
…dir; hold-time presence claims adopt the group MIN instead of DRAFT-DISAGREE STOP

Boot weg2xsn216 (sgl-project#1459): D died at the second park-test request --
WEG2 DRAFT-DISAGREE STOP rid=weg2-6-3 per_rank_claim=[94207, 97870].  The
held request's probe ran 1 s after P's leg answered, while P's write-
through was still landing the tail; TP2 probed ms before TP0/TP1 and read
fewer COMPLETE pages.  That inequality is the write-through's clock, not
a divergent store: for rids in the dormant hold every rank adopts the
group MIN (the same prefix everywhere, sgl-project#1461 DRAFT-CLAIM MIN-ADOPTED) and
the hold's top-up (sgl-project#1456) fetches the rest; outside the hold the law
stays STOP (assert_draft_claims_agree unchanged).  The scheduler keeps
cache_controller.weg2_hold_rids in step with the hold (add / release /
abort).

#1459b: the index file moves out of the arena dir into a sibling dir
(<arena dir>-l3idx/l3idx.bin) -- nothing that scans the arena dir sees it.

Tests: hold_refetch_1456 (+1) + dormant_hold_1445 + l3_index_1459: passed.
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 17, 2026
…stays parked after the wake until its re-read completes

weg2xsn229 (P --max-running-requests 2, sgl-project#1470 flush join): the read
issued at the hold ended short (4095 of 98210; D reads DURING the flip
since sgl-project#1455, before P's write-through and storage backup land), the
sgl-project#1456 refetch was issued, and the wake queued the request anyway -- the
X gate refused it (W31 uncached 94117 > X 4096), P prefilled the same
prompt again, and the second read was complete (served 98210).  The
short prompt weg2-6-2 looped the same way (W53), and D wedged behind it.
_weg2_release_dormant_hold now queues only requests whose read is
complete; the others are parked in weg2_post_wake_settle with their sgl-project#1461
claim kept, re-read every 2 s by _weg2_refetch_one (the sgl-project#1456 body,
factored out) from _weg2_post_wake_settle_tick at every scheduling pass,
and queued when complete or after WEG2_POST_WAKE_SETTLE_S=20 s.
Tests: 1471 (3) + 1456 + 1445 + 1466 + 1470 -> 22 passed.
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 18, 2026
…ASS line; ARENA-GET MISS diagnostic (dormant re-reads answer zero for pages P completed)

xsn326 (33k, bs=4): init_new 425 ms, but add_one_req 2-4 ms per request and
init_load_back 9 ms -- the host term sits in the re-admission's
init_next_round_input (match/load_back) or the loop, not in the adder.
xsn314/322/326: sgl-project#1456 HOLD-REFETCH answers zero-answer 54x per boot while
PP2's ack flips the pages COMPLETE within ~4 s; _arena_page_get names the
first miss (stem, find slot/state, batch_exists of the same keys).
Tests: xsn315/309/303 green (15 passed).
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 18, 2026
… D's presence probe (sgl-project#1439 ARENA-PRESENT) -- the dormant hold's hit query answers 0 (READ-TRACE arena_hits=0, no-file) while the wake finds 520k pages via find_slots_np

xsn327: weg2-6-2 finished on P 14:00:04-07 (its shared 4095-page prefix
node complete since 13:59:31 by PP2's ack), D's sgl-project#1456 re-reads 14:00:06-12
answered zero (READ-TRACE asked=512 readable=0 arena_hits=0), no
ARENA-GET MISS at all -- the hit query never reaches the page get. Both
sides now print the full stem so the key derivation can be compared.
Tests: xsn309/305/307 green (7 passed).
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 24, 2026
… request's finish, before it is served (xsn422/xsn423 HOLD-REFETCH)

xsn423 (G's classification, rid weg2-18-36, 1988 + 1 token END-ANCHOR split):
at 16:18:47 every P rank logs RETAIN-PUBLISH issued=1 pending=2, the front
logs WEG2-SERVED group=P 16:18:47,308 and D-ADMIT 16:18:47,311, and D's
dormant read in the same second answers '#1035c ZERO-ANSWER cause=ASKED-AND-NO
(store holds no leading page)'; the sgl-project#1456 refetch then loads all 1987 pages.
xsn421 (no overlap) had none of these.

Mechanism: under --p-host-overlap the N-1 node's chunk publish is deferred to
right after the LAST chunk's launch, and the rank then sits in that chunk's
output exchange -- #PGAP on the pass after a 1-token final chunk:
output_commit median 734 ms on PP0 (max 2410), 395 ms on PP1, 34 ms on PP2.
No plan runs in that wait, so check_hicache_events never polls the write-
through acks: the copy is done, its ack is not retired, the page is not
COMPLETE in the arena, and the finish serves the request with the publish
still "pending". Without the overlap the publish was issued inside the plan
and a later plan polled its ack before the finish.

Fix (SGLANG_WEG2_P_HOST_OVERLAP=1 only; unset = unchanged): cache_finished_req
calls writing_check() -- its NON-blocking branch (Event.query(); a copy still
running stays pending) -- right after the deferred-publish flush and before
the insert, the sgl-project#1442 hand-off and the RETAIN publish. Every rank retires its
completed copies at its own finish; the forward never waits.

Not closed by this (named): PP0 emits the response; PP1 processes the same
finish only after PP0 forwards the output, so PP1's slice can still complete
a few ms after the response. A hard "served only when complete" needs the
arena's own completeness (all stages) checked on PP0 before the response
(find_states over the request's page stems, bounded), i.e. a parked-response
path in the output streamer -- not built here; the sgl-project#1456 refetch stays the
backstop.

Tests (desk, CPU-only, test27b.sh, one pytest per file):
  test_weg2_p_host_overlap.py 26 passed (+2: the finish polls the acks after
    the flush, under the switch, non-blocking, before pop_committed_kv_cache /
    the hand-off / the retain publish; writing_check retires only completed
    acks and never synchronises a running copy)
  test_unified_radix_cache_unittest.py -k "finished or write_through or
    KVEvents or unfinished or Int8MambaCheckpoint or GridRetention": 96 passed,
    88 skipped. The whole file is killed at ~74% by the 3 GiB test cgroup
    (exit 137) -- twice at the same place; not compared against a base run.
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 24, 2026
…l below the threshold, and a standstill within X recomputes instead of W88 503

Metal weg2xsn437 (P_TRIM=1): two leg-2 requests answered 503 (front W28).
  (a) rid weg2-6-2, N=4316: D delivered=4095 deliverable=4314 shortfall=219;
      the re-read refused 'sgl-project#915 PREFETCH REFUSED reason=vote_negative
      need=219 threshold=256' at 21:09:30 and 21:09:50; W88; 503 at 21:10:38.
  (b) rid weg2-20-37, N=2050: delivered=2047 deliverable=2048 shortfall=1;
      'sgl-project#1456 HOLD-REFETCH ... verdict=declined:too_short'; after the wake
      'W88 Weg2StoreLoadNotProgressing ... no_progress_passes=64 -- terminal,
      answered 503'.

CAUSE, AT THE CODE. The trimmed chain was published WHOLE: P's own lines
'WEG2 END-ANCHOR ... units=4314/4314 ok=True trim=1' and 'units=2048/2048',
'sgl-project#1442 HANDOFF ids=4316 page_keys=4314' = D's 'HANDOFF-KEYS USE pages=4314
covered=4314' -- the bigram units match D's deliverable exactly; no unit is
short. What moved is WHEN the last node goes out: without the trim the N-1
node leaves through the chunk publish (_weg2_publish_at_chunk) one forward
before the finish; trimmed, it is the finish insert and leaves through the
retain publish ('RETAIN-PUBLISH ... issued: 1, pending: 1') at the moment P
answers leg 1. D's first read therefore landed before it: 4095 = the chunk-
published prefix up to the 4096 interval anchor (weg2_anchor_step
'interval'), 2047 = the chunk-published prefix up to the boundary 2048,
which is the trimmed request's own N'-1 'end' step. A race the sgl-project#1324
deferral exists for -- and the deferral could not finish it: the owed
re-read of a tail below prefetch_threshold (256) is refused at the gate
(prefetch_from_storage: 'elif prefetch_length < self.prefetch_threshold:
reason = "too_short"', the group vote then negative), so the chain can only
stand still, and _apply_group_shortfall_deferral's standstill exit on the
windowed path answers W88 503 whatever the remainder -- 221 and 3 tokens
here, against X=4096.

REPAIR (one switch, SGLANG_WEG2_STORE_SHORT_TAIL, default on; 0 = both old
forms for A/B):
  * prefetch_from_storage(min_tokens=...): the smallest read worth issuing;
    None = prefetch_threshold (unchanged). _prefetch_kvcache passes 1 when the
    request carries the short-read stamp (_weg2_store_delivered, written by
    _weg2_note_store_shortfall from the group-synced record, so every rank
    of the group asks the same and the sgl-project#580 vote stays uniform); the call is
    byte-identical otherwise.
  * _weg2_store_short_recompute: a STORE-SHORT read that stands still with
    a remainder (prompt - materialised prefix) within X is admitted -- the
    mark cleared, 'expired', the X gate prices it with the group's match
    and D prefills it (store-short must recompute). Over X it stays the
    named W88: the user's veto against a prefill over X is untouched (the
    sn6s form still ends in W88).
Both helpers are module functions (the file's own rule: stand-ins bind a
curated method list). No P change: the anchor needs no sync on P's path
('Anker bremsen nie'); D now completes the read as soon as P's write lands
(the hold refetch every 2 s during a flip, the retry every pass awake).
Side note, not changed: for a trimmed prompt whose last chunk boundary is
N'-1 (N=2050) G's 'end' step donates one extra anchor there -- harmless.

Tests (hermetic, CPU, each file alone through test27b.sh / incg cap):
  test/registered/unit/weg2/test_weg2_store_short_tail_xsn437.py  11 passed
    -- the two metal forms: P on a real tree (512 chunks, interval 4096,
    bigram): the trimmed chain = D's deliverable (4314, 2048; and 2047 for
    N=2049), the prefix published before the finish = the metal first reads
    (4095, 2047), short by 219 and 1; D: the completion read of 219 and of 1
    token is issued (a fresh one keeps the threshold); a standstill with
    remainder 221 / 3 within X=4096 is recomputed, not W88; sn6s over X stays
    W88; the switch off restores W88.
    RED first on 67b6352 (git-archive, PYTHONPATH): 6 failed -- the
    completion read (219, 1), the stamp helper, the call wiring, the
    standstills 221 and 3 answered 'failed' (W88); the P-side and over-X /
    switch-off cases pass there too (they pin what did not change).
    Mutants, each KILLED: the completion read keeps the threshold; the tree
    ignores min_tokens; the standstill never recomputes; the standstill
    recomputes over X.
  affected: store_consistency_1324 25, prefetch_deferral_1068 42,
    prefetch_gate_census_915 28 (its source pin now names `_min_len`, which
    is prefetch_threshold unless min_tokens is given), participation_desync
    _580 8, hold_refetch_1456 5, hold_refetch_uniform_xsn296 3,
    revoke_reissue_1479 10, prefetch_reissue_retire_939 16,
    leg2_store_probe_1290 9, store_told_1400 19, dormant_hold_1445 9,
    p_trim_end_anchor 18 -- passed. Red on 67b6352 already, identically:
    prefetch_progress_symmetry_580 (8, stale fakes), wcode_uniqueness_1263
    (3, W68 collision). unified_radix_cache_unittest: the full file is
    SIGKILLed by the 3 GiB cap; its prefetch subset (-k prefetch) is equal on
    both trees (1 passed, 57 skipped).
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 26, 2026
…an, never before it; PP0 never after publishing (sgl-project#1456/sgl-project#1471 on tp_size 1)

Follow-up to e5a52d8 path 4. Simulated with the SHIPPED scheduler methods
(_weg2_hold_refetch, _weg2_refetch_one, _weg2_release_dormant_hold,
_weg2_post_wake_settle_tick) on a PP0 and a follower double, told form armed
with SGLANG_WEG2_TOLD_PROBE_TREE_KEY=1 (absolute), tp_size 1 = no group MIN.

Sound (tests only): PP0's hold read answers zero, the sgl-project#1456 re-read tops it up
(and a hand-off file appears in between) -- nothing leaves the hold; after the
wake the follower registers exactly ONCE, with PP0's final told (98304) and
final keys_digest. Same when PP0 parks at the wake (sgl-project#1471) and publishes after
the settle, and for the paced read-ahead (#1416e): it leaves only after the
release. An unregistered follower is "complete" for the hold/settle and never
re-reads on its own.

Defect (red before the fix): _weg2_refetch_one re-issued _prefetch_kvcache(req)
WITHOUT limit_tokens. A follower that absorbs the told while its request is
still in the dormant hold (the Resume normally rides ahead of the told; a
lagging or W114-refused follower wake -- a LOCAL vote on tp_size 1 -- breaks
that) and whose told read answers short re-read to the prompt end, past told:
Weg2StoreToldMismatch at admission. Likewise a stale short record let a
follower start a told-less read, and a PP0 rid back in a hold after its told
was published could be re-read (PP0's record moves under the followers).
Fix: weg2_store_told.refetch_plan(scheduler, req) -- None off the told form
(byte-identical for group D / non-PP), REFETCH_SKIP for a follower without
told and for PP0 once published ("complete", no read), else the follower's
told limit (follower_limit_tokens) for the re-read. No log line changed.

Tests (test27b.sh, PYTHONPATH=wt/python, CUDA_VISIBLE_DEVICES=""):
 test_weg2_store_told_hold_tk.py: before the fix 3 failed / 3 passed, after 6 passed.
 With store_told_1400/positive_tk/paced_1416e, p_twin_defer, p_intake_h91a,
 handoff_1442, handoff_keys_xsn329, intake_stall_xsn272, unify_s5,
 burst_clock_h42c, multi_anchor_tails_h42, dormant_hold_1445, hold_refetch_1456,
 hold_refetch_uniform_xsn296, post_wake_settle_1471, store_short_tail_settle_rc2:
 181 passed. revoke_reissue_1479 (4), wake_kv_first_xsn314 (1),
 x36_settle_dormant (1) fail identically on e5a52d8 -- not this change.
 Mutants killed: follower re-read without limit (1), told-less follower
 re-read (1), PP0 re-read after publish (1).
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 26, 2026
…on the PP form, one final re-read of a zero hold read, told right after the wake

Agent-turn boots: prompt = the store's prefix + the new turn. Once PP0's hold
read had answered ZERO (write-through not landed / revoked), _1471_short stayed
set, the prompt's tail beyond the store (> 256 tokens, P's own prefill) kept the
read "short", and the wake parked PP0 in the sgl-project#1471 settle, re-reading every 2 s
until the 20-s bound -- 20 s per turn, PP0's told waiting with it.
_weg2_note_store_shortfall already answers None on PP for this reason ("a PP
group is the PRODUCER"); the settle path did not.

Fix (scheduler.py, module functions so no curated stand-in misses them):
_weg2_refetch_one on an AWAKE pp_size > 1 group (the wake's release and the
post-wake settle; the sleep's sgl-project#1456 top-up is unchanged) goes to
_weg2_producer_wake_verdict: always "complete" (never parked); a read still in
flight joins the queue as it is (told publish / prefetch gate wait for its
termination); a terminated ZERO answer gets ONE final re-read of what the store
holds now (no 2-s clock, only on tp_size 1 = no collective, with
weg2_store_told.refetch_plan: follower only the told span, PP0 only before
publishing). Group D (pp_size 1, the consumer) never enters it: byte-identical,
its settle still waits for P's write-through. New log tag "#TK WAKE-REREAD"
only; no existing log line changed.

Tests (test27b.sh, PYTHONPATH=wt/python, CUDA_VISIBLE_DEVICES=""):
 test_weg2_store_told_hold_tk.py: agent-turn form (store 95000 + 3000 new):
 PP0 released at the wake, no park, no re-read after the wake, told 95000 in
 the same pass, both ranks admit; zero read at the wake (flip < 2 s): one final
 re-read, released, told 98304; D consumer: same read parks and re-reads on the
 2-s clock as shipped. Before the fix the two P tests failed (wake() == 0,
 parked), the D test passed; after: 8 passed. Replaces last commit's
 "parked at the wake publishes after the settle" test (its premise was the
 park this commit removes).
 With the told / hand-off / hold / settle / intake set (1445, 1456, xsn296,
 1471, rc2 tail, ...): 183 passed; revoke_reissue_1479 (4),
 wake_kv_first_xsn314 (1), x36_settle_dormant (1) fail identically on
 e5a52d8 -- not this change.
 Mutants killed: re-read also a non-zero read (5), D takes the producer path
 (1), no final re-read of a zero answer (1).
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 26, 2026
…an, never before it; PP0 never after publishing (sgl-project#1456/sgl-project#1471 on tp_size 1)

Follow-up to e5a52d8 path 4. Simulated with the SHIPPED scheduler methods
(_weg2_hold_refetch, _weg2_refetch_one, _weg2_release_dormant_hold,
_weg2_post_wake_settle_tick) on a PP0 and a follower double, told form armed
with SGLANG_WEG2_TOLD_PROBE_TREE_KEY=1 (absolute), tp_size 1 = no group MIN.

Sound (tests only): PP0's hold read answers zero, the sgl-project#1456 re-read tops it up
(and a hand-off file appears in between) -- nothing leaves the hold; after the
wake the follower registers exactly ONCE, with PP0's final told (98304) and
final keys_digest. Same when PP0 parks at the wake (sgl-project#1471) and publishes after
the settle, and for the paced read-ahead (#1416e): it leaves only after the
release. An unregistered follower is "complete" for the hold/settle and never
re-reads on its own.

Defect (red before the fix): _weg2_refetch_one re-issued _prefetch_kvcache(req)
WITHOUT limit_tokens. A follower that absorbs the told while its request is
still in the dormant hold (the Resume normally rides ahead of the told; a
lagging or W114-refused follower wake -- a LOCAL vote on tp_size 1 -- breaks
that) and whose told read answers short re-read to the prompt end, past told:
Weg2StoreToldMismatch at admission. Likewise a stale short record let a
follower start a told-less read, and a PP0 rid back in a hold after its told
was published could be re-read (PP0's record moves under the followers).
Fix: weg2_store_told.refetch_plan(scheduler, req) -- None off the told form
(byte-identical for group D / non-PP), REFETCH_SKIP for a follower without
told and for PP0 once published ("complete", no read), else the follower's
told limit (follower_limit_tokens) for the re-read. No log line changed.

Tests (test27b.sh, PYTHONPATH=wt/python, CUDA_VISIBLE_DEVICES=""):
 test_weg2_store_told_hold_tk.py: before the fix 3 failed / 3 passed, after 6 passed.
 With store_told_1400/positive_tk/paced_1416e, p_twin_defer, p_intake_h91a,
 handoff_1442, handoff_keys_xsn329, intake_stall_xsn272, unify_s5,
 burst_clock_h42c, multi_anchor_tails_h42, dormant_hold_1445, hold_refetch_1456,
 hold_refetch_uniform_xsn296, post_wake_settle_1471, store_short_tail_settle_rc2:
 181 passed. revoke_reissue_1479 (4), wake_kv_first_xsn314 (1),
 x36_settle_dormant (1) fail identically on e5a52d8 -- not this change.
 Mutants killed: follower re-read without limit (1), told-less follower
 re-read (1), PP0 re-read after publish (1).
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 26, 2026
…on the PP form, one final re-read of a zero hold read, told right after the wake

Agent-turn boots: prompt = the store's prefix + the new turn. Once PP0's hold
read had answered ZERO (write-through not landed / revoked), _1471_short stayed
set, the prompt's tail beyond the store (> 256 tokens, P's own prefill) kept the
read "short", and the wake parked PP0 in the sgl-project#1471 settle, re-reading every 2 s
until the 20-s bound -- 20 s per turn, PP0's told waiting with it.
_weg2_note_store_shortfall already answers None on PP for this reason ("a PP
group is the PRODUCER"); the settle path did not.

Fix (scheduler.py, module functions so no curated stand-in misses them):
_weg2_refetch_one on an AWAKE pp_size > 1 group (the wake's release and the
post-wake settle; the sleep's sgl-project#1456 top-up is unchanged) goes to
_weg2_producer_wake_verdict: always "complete" (never parked); a read still in
flight joins the queue as it is (told publish / prefetch gate wait for its
termination); a terminated ZERO answer gets ONE final re-read of what the store
holds now (no 2-s clock, only on tp_size 1 = no collective, with
weg2_store_told.refetch_plan: follower only the told span, PP0 only before
publishing). Group D (pp_size 1, the consumer) never enters it: byte-identical,
its settle still waits for P's write-through. New log tag "#TK WAKE-REREAD"
only; no existing log line changed.

Tests (test27b.sh, PYTHONPATH=wt/python, CUDA_VISIBLE_DEVICES=""):
 test_weg2_store_told_hold_tk.py: agent-turn form (store 95000 + 3000 new):
 PP0 released at the wake, no park, no re-read after the wake, told 95000 in
 the same pass, both ranks admit; zero read at the wake (flip < 2 s): one final
 re-read, released, told 98304; D consumer: same read parks and re-reads on the
 2-s clock as shipped. Before the fix the two P tests failed (wake() == 0,
 parked), the D test passed; after: 8 passed. Replaces last commit's
 "parked at the wake publishes after the settle" test (its premise was the
 park this commit removes).
 With the told / hand-off / hold / settle / intake set (1445, 1456, xsn296,
 1471, rc2 tail, ...): 183 passed; revoke_reissue_1479 (4),
 wake_kv_first_xsn314 (1), x36_settle_dormant (1) fail identically on
 e5a52d8 -- not this change.
 Mutants killed: re-read also a non-zero read (5), D takes the producer path
 (1), no final re-read of a zero answer (1).
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 26, 2026
…bb3 starb am Sleep-Drain des zweiten D-Schlafbeins (W120 -> W29)

Metall fnFL2h91bb3 @ 50cd288 (D TP3), erster Boot, auf dem der H91-Park-Pfad wirklich lief:
15:52:39.722 Front WAIT-BOUND FIRED epoch=16 -> /weg2/park_running; D: '#969AD RETRACT site=weg2_park_running', 'WEG2-D-PARK park_running ... parked=[weg2-16-23]' auf 3/3.
15:52:39.905 erstes Schlafbein (kv_cache+cuda_graph): Drain leer, Flush ('sgl-project#1470 FLUSH-PUBLISH' joint die Write-Throughs des Parks VOR dem Reset), pause(kv_cache), 'WEG2-DORMANT set', dann hold_parked -> gewoehnliche Intake: zuerst _prefetch_kvcache (Store->Host-Read registriert, 'sgl-project#1028 HICACHE-ROUND ... ongoing_prefetch=1'), dann sgl-project#1443-Hold ('WEG2-D-PARK hold: 1 parked request(s) at the head of the dormant hold').
15:52:39.985 zweites Schlafbein (weights_*): _weg2_drain_hicache_before_sleep sah 'hicache_prefetch(1: weg2-16-)' auf jedem Rang, 887 Gruppen-Polls / 10,01 s, W120 3/3 -> WEG2-LEG-ABORT -> W29 -> D tot.

Wurzel: weder Selbstblockade gegen den eigenen Write-Through (der war beim Flush gejoint) noch ein Arena-Ack. Ein Prefetch-Record verlaesst ongoing_prefetch nur ueber check_prefetch_progress (Admission, sgl-project#1233-Orphan-Collector -- der gehaltene rids seit sgl-project#1456 bewusst auslaesst --, sgl-project#1456-Top-up), Revoke, Abort oder Re-Issue; check_hicache_events ruft nichts davon. Der Read des Holds soll per Design den ganzen Flip ueberspannen (sgl-project#1455: Host-Read im Schlaf, Device-Load beim Wake; sgl-project#1456: Nachladen waehrend die Gruppe schlaeft). Der Drain jedes SPAETEREN Schlafbeins zaehlte ihn trotzdem als in-flight -- er konnte nie leer werden. Gleiche Klasse fuer jede sgl-project#1443-Ankunft und jeden sgl-project#1456-Re-Issue zwischen zwei Schlafbeinen.

Fix (Richtung b, rang-einheitlich, kein Schalter, keine Reserve, kein Warten): weg2_sleep_drain.hold_owned_prefetch nennt die offenen Prefetch-Records, die der dormant hold besitzt -- nur wenn weg2_dormant (KV-Pool pausiert, kein Device-Ziel mehr) und der rid im Hold steht (Hold repliziert, Registrierung participation-voted). Ein Prefetch-Record ist Store->Host (Host-Pool-Zeilen); seine Device-Haelfte ist ein Load-back (ongoing_load_back) und blockiert weiter, ebenso Write-Through, Backup und jeder Read eines nicht gehaltenen Requests. Der Pre-Sleep-Drain und der Idle-Assert des Release-Beins (_weg2_sleep_idle) nehmen dieselbe Ausnahme (Scheduler.idle_blockers / is_fully_idle mit exempt_prefetch, Default leer = unveraendert); Zeile 'H91e SLEEP-DRAIN HOLD-OWNED prefetch=N rids=[...]'. Der Read laeuft weiter, der Wake gibt den Request zuerst frei, wach ist der Read wieder ein gewoehnlicher Term.

Tests test_weg2_hold_prefetch_sleep_h91e (7; echte Scheduler.idle_blockers/is_fully_idle, echte park_running/hold_parked, echter Drain ueber eine 3-Rang-MAX-Reduktion in Threads): 5 rot auf 50cd288 (bb3-Form: W120 'hicache_prefetch(1: weg2-16-)' auf 3/3, wortgleich zum Metall), alle 7 gruen mit Fix; Park-/Drain-/Idle-Suiten h91b/h91c2/h91c3/h91d/x105/1445/1272/h74/1268/1268-lap/1233/1361/x36/s1: 27 Altlasten identisch zur Basis (s1_memory_saver 26, s3s4_refusals_1233 1), 0 neu.
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 27, 2026
… park retained

Metal dkr27bparkdraftbar1w209270645 (27B, rid weg2-2-5) and dkrnfh91bar1dauer09270859 (NF,
weg2-1-13 / weg2-6-29): the same root on both models, so the repair is model-neutral.

WHY 256 OF 417. park_running retracts with retain=True; cache_finished_req inserts min() of the
components' retention lengths. With --mamba-scheduler-strategy extra_buffer the mamba component
answers req.mamba_last_track_seqlen, the last DECODE TRACK point (multiple of
--mamba-track-interval 256): sgl-project#1469 RETAIN token_ids_len=417 cache_len=256 (NF 47262 -> 47104,
45697 -> 45568). The KV above it is freed and never written (sgl-project#1439 census of the 416 keys:
255 COMPLETE, 161 state 0). 256 IS the last valid mamba anchor; KV beyond it cannot be resumed
without a state and is recomputed anyway -- correct, not the defect.

WHY THE REST WAS NOT READABLE -- never written, and asked for anyway. The dormant-hold read and
the sgl-project#1471 settle registered the request's WHOLE context (417 / 47262 tokens), a span the store
can never complete:
  * NF: prefetch INCOMPLETE delivered=47104 deliverable=47232, every re-read of the 128 declined
    below the threshold (vote_negative), SETTLE-RELEASE lapsed held_after_wake_s=20.0;
  * 27B: the store held 255 bigram pages -- one under prefetch_threshold 256 -- and the prefetch
    thread revoked every read (storage_hit_count < prefetch_threshold), record materialized 0,
    four sgl-project#1456 zero-answers, held_after_wake_s=20.1; after the lapse the fresh read (hand-off keys
    dropped at the wake) answered sgl-project#1035 R13 EMPTY keys=417 and D prefilled all 418 tokens.

THE REPAIR (SGLANG_WEG2_PARK_READ_CAP, default on; 0 = the old read byte for byte):
  * cache_finished_req stamps the raw token span of the key it inserted (weg2/d_park_read.py
    RETAINED_ATTR; bigram = units + 1); park_running clears a stale stamp before the retraction and
    stamps (retained, request length) on every parked request, one line WEG2-D-PARK RETAINED;
  * _prefetch_kvcache ends the store read of a request whose length has not changed since the park
    at that span (after the fork cap): the read lands COMPLETE, nothing to settle, the resume's
    extend computes the tail (< one track interval);
  * that read may be smaller than the threshold (min_tokens=1), and the controller now honours a
    caller's floor on the store hit too (managers/weg2_min_hit.py, registered before the operation
    is queued, consumed once, never raises the threshold) -- the same second-threshold gate had also
    defeated xsn437's sub-threshold tail re-read.
All terms are functions of the request ids and the retained key (identical RETAIN on TP0/1/2 on
both models, Form A workers included) -- no collective, no file.

Not changed: the retain itself (a live-state anchor at the park would need sgl-project#747's grid rule
lifted); PK2's zero-read settle stays as the net.

Tests: test_27b_park_retain_read_0927.py 13 (retained span arithmetic bigram/plain, read span ==
stored units, cap inert once the request grows, switch off/no stamp = old read, controller floor
lowers once never raises + metal numbers 255<256, bounded table, park stamps/clears/logs, REAL
UnifiedRadixCache+MambaComponent: stamp == what the tree holds with a 16-of-21 track cap and the
KV above freed, wiring order). Mutant (stamp the whole span) caught. Affected suites per file
(weg2 park/hold/settle/refetch/store-short, mamba anchor, prefetch gate/participation/generation,
controller reset): branch 380 passed / 8 failed, base 9417507 367 / 8 -- the same 8
(mamba_anchor_seams_747 x1, prefetch_completion_generation_905 x1, participation_desync_580 x6)
fail identically on the base; test_unified_radix_cache_unittest exceeds the 3G test cgroup on both.
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 27, 2026
…ject#1324 delivered stamp

Metal rc12k27 b23 (dkr27bparkodirectdraftbar1w2309270957), rid weg2-24-100: cycle 10:22:21 resumed
from host_hit=79103; at the park 10:23:05 the new hold read answered zero (sgl-project#1456 HOLD-REFETCH
reason=zero-answer n=3,4), yet the wake settle released it -- "sgl-project#1471 SETTLE-TAIL delivered=79103
remainder=1405" read the stamp the PREVIOUS cycle's read had left on the request
(req._weg2_store_delivered is set by _weg2_note_store_shortfall and never cleared). Its admission
found nothing (PHASE-PURITY state=cold host_hit=0), X-GATE uncached=80508 X=12288 -> W31 -> W50
mid-stream, the client's stream died (745 s into it).

park_running now clears the stamp for every request it parks: the flip park opens a new read cycle,
and the settle decides from this cycle's own read (set again by _weg2_note_store_shortfall). A
request without a stamp is unchanged.

Tests: test_27b_park_stale_delivered_0927.py (the park clears 79103, leaves an unstamped request
untouched; remainder/tail-min read None afterwards). With d_park_scheduler_h91b, park_retain_read,
park_immediate: 68 passed.
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 28, 2026
…with a writer the settle hold waits for its ack instead of re-reading every 2 s

NF rc12z17-s0 (103bfdf, D log boot ...09281111): weg2-2-17 (41021 tokens, route=short straight to D) read 40512 of 40960 at the wake 11:18:00, then 'sgl-project#1456 HOLD-REFETCH zero-answer' n=2..4 every 2 s beside 'sgl-project#1442 HANDOFF-KEYS NONE registry=[]' and 'sgl-project#1472 READ-TRACE why=no-file', until 'sgl-project#1471 SETTLE-RELEASE lapsed=True held_after_wake_s=20.0' and 'X-GATE uncached=509 verdict=admit' -- the admission it would have had at 11:18:00. weg2-4-36 (1757, 20.0 s) and weg2-5-37 (191, 20.7 s) the same; 7 such holds per rank in that boot. Nobody was writing: the missing pages were D's own decode tail of the previous turn (never secured when D slept), and P never saw the requests.

After D's wake the only process that can still fill a parked read is P (D awake = P asleep; D's own write-through writes pages D holds on its device, and a page on D's device is a device match, never a store read). What D can SEE of P per rid lives in the shared hand-off directory: the hand-off chain (weg2.handoff record / handoff_keys.CHAIN_ATTR on the request) and the E-tail parts (weg2.tail_handoff: a *.tmp part or a manifest short of its PP ranks = still writing; a complete manifest = the publish ack).

weg2/settle_writer.py classifies (pure: classify, step) and observes (listing at most every 100 ms per request):
* none        (no chain, no hand-off record, no tail part, nothing under write) -> decided now: the request goes to admission without another re-read (within X D prefills it; over X the X gate refuses by name and the front re-routes via P). Line '#1471w SETTLE-NO-WRITER rid remainder X route=D|P held_s re_reads', then 'SETTLE-RELEASE state=no-writer lapsed=False'.
* p-writing   -> no re-read until the ack (the re-read cannot see pages that are not there).
* p-published -> the ack: re-read now, past the 2 s timer, once; still short after it = no writer left -> decided.
* p-handoff   (P prefilled it, no tail parts) -> P's page write-through has no D-visible ack: the 2 s re-read stays, unchanged.
* unknown     (no shared hand-off directory) -> no writer provable: unchanged.
'#1471w SETTLE-WRITER rid writer prev action' on every change of state. Only requests already seen short (_1471_short) are classified; a read in flight ('reading') is never decided. Every verdict goes through the existing group MIN of the settle tick (due-vote and release-vote), so a rank that still sees a writer holds the group. No switch: the lapse released the same request 'as it is' 20 s later.

Tests test_weg2_settle_writer_p4b_0928 (9): on 1bab093 (module present, tick unwired) 4 red -- metal form not released (and re-read), over-X not released, tail part under write re-read on the 2 s clock, publish ack not re-read before the timer -- with the fix 9 green. Neighbours touching the settle tick / refetch / _1471_short (store_told_hold_tk, p_mamba_retention_h113, 27b_park2_metal, hold_refetch_uniform_xsn296, park_l3_248, post_wake_settle_1471, revoke_reissue_1479, store_short_tail_settle_rc2, x36_settle_dormant): 79 passed on the base, 79 with the fix.

Metal marker: '#1471w SETTLE-NO-WRITER ... route=D' within ~1 s of the 'sgl-project#1324 STORE READ INCOMPLETE' of a route=short request, 'SETTLE-RELEASE state=no-writer lapsed=False held_after_wake_s' < 1; no 'lapsed=True' for such rids; the X-GATE admit follows at once.
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.

3 participants