Repository navigation
Fix bugs in sampler with CUDA graph / torch.compile - #1306
Merged
Merged
Conversation
hnyls2002
force-pushed
the
fix-sampler
branch
from
September 2, 2024 22:32
ec0fe88 to
52f3cd9
Compare
zhyncs
approved these changes
Sep 2, 2024
5 tasks done
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
Sep 13, 2026
…11b's cushion breach Wand 11b (sgl-project#1377) is the open host blocker for the goal-question boot: the bounce prices 5 measured lanes x 3.00 GiB + 0.75 GiB staging = 15.75 GiB on xsn31/3's own checkpoint (front.log:111 xchg_bounce=15.75, front.log:106 lanes=5 source=measured), and the sleep-leg cushion floor (1.50 GiB) latches at 0.20 (W98 Weg2HostRateLatched) because that growth ate the room. sgl-project#1370 made the bounce PRICED HONESTLY; it did not make it SMALLER. ONE SOURCE, the --xchg-bounce-depth shape (48adc00) reused rather than a second publication path: `BounceTerms.lanes_concurrent` (0 = "not stated", byte-identical -- the same convention `max_tag_bytes` already uses two fields over) caps how many of `n_lanes` price at once through a new `lanes_priced` property; `total_bytes` reads that property instead of `n_lanes` directly. The field rides `_TERM_FIELDS`, so P, D and the host ledger recompute the identical capped total from the published inputs, never a second formula. `checkpoint_census.widest_layer_terms` and `launcher.choose_host_ledger` / `xchg_bounce_terms_for_arm` pass it through unchanged; `main()` resolves the CLI value exactly once (`xchg_bounce.resolve_lanes_concurrent`) and hands the same resolved int to both the ranks' publication call and the ledger's own call, so the two sides cannot disagree about which values are refused. REFUSAL, NOT SILENT DEGRADATION: `--xchg-lanes-concurrent 0` (or negative) is refused (W103 Weg2XchgLanesConcurrentInvalid) rather than folded into the same 0 sentinel BounceTerms uses for "unset" -- collapsing them would run every lane concurrently while the argv says the opposite. W103 is the next free number after a tree-wide census (`grep -rhoE 'W[0-9]+'` tops out at W102); W52/W53/W54/W56/W58 are a documented collision class (sgl-project#1265/sgl-project#1306) of guessed digits, so this one is taken from the census. NAMED AND COUNTED, NEVER SILENT: `WEG2-XCHG-LANES-CONCURRENT lanes_concurrent= lanes_total= lanes_priced= serialised=` is appended to the arm's own line list (appended, not inserted, so lines[0..2]'s existing positional readers are untouched) so a boot can put a number beside the flip-time cost of serialising the lanes this cap does not price. THE COMPUTED EFFECT, on xsn31/3's own geometry (largest tag 2907 MiB, 128 MiB slots -> 24 slots/lane -> 3072 MiB/lane, 0.75 GiB staging, 5 measured lanes): concurrent=2 charges 2 x 3.00 + 0.75 = 6.75 GiB (a 9.00 GiB reduction from the measured 15.75); concurrent=1 charges 3.75 GiB (12.00 GiB reduction). Against xsn31/3's own cushion_min=0.20 (floor 1.50): 0.20 - (-9.00) = 9.20 >= 1.50 at concurrent=2, and 0.20 - (-12.00) = 12.20 >= 1.50 at concurrent=1 -- the invariant holds with wide margin either way, using the boot record's own linear-tracking method (6.99 -> 0.20 explained by the +7.96 GiB bounce growth). NOTE: depth (1 vs 2) changes NOTHING on this checkpoint -- Option 1's tag-need (23 slots + 1 shadow = 24) dominates the depth floor (2 or 3) at both depth=1 and depth=2, so the entire saving here comes from lanes_concurrent alone, not from --xchg-bounce-depth. HONESTY GATE, NAMED HERE NOT BUILT: this commit wires the cap through PRICING only. `weight_updater.py`'s per-rank leg driver still allocates a buffer for every lane it owns unconditionally -- no cross-process concurrency permit exists yet, so a real boot's tmpfs usage may still reach `lanes_total`'s worth even though the ledger now charges `lanes_priced`. A WEG2-XCHG-LANES-CONCURRENT-CAVEAT line names this explicitly whenever a cap actually serialises lanes, pointing at the same 3-way measurement (sgl-project#1358: tmpfs holders, cgroup d_shmem, host-slot lines) that must confirm the real peak before this ARM number is trusted. Tests: test_weg2_xchg_lanes_concurrent_1385.py, 23 cases (hermetic, CUDA_VISIBLE_DEVICES=""), covering the default byte-identical path, the cap actually shrinking the charge (the mutant guard for the OOM direction -- manually verified: reverting `lanes_priced` to `n_lanes` in `total_bytes` fails 3 tests immediately, restored after), refusal for N<1, the W103 census-not-guess check, the named/counted log line (source and execution smoke through a real fake checkpoint), and the one-source property (single `resolve_lanes_concurrent(` call in `main`, both call sites take the same resolved value). test_weg2_widest_layer_census_1332b.py's line-count assertion updated 3->4 for the new appended line (positional indices unchanged). 193 tests green across the full bounce/lane/ledger neighbour suite plus the new file; ruff clean. Default is byte-identical: lanes_concurrent=0 is the "not stated" sentinel, `lanes_priced` returns `n_lanes` unchanged, and no existing caller passes the new keyword.
efschu
pushed a commit
to efschu/htsglang
that referenced
this pull request
Sep 14, 2026
…her than a second scanner Prior-art gate first (per order): sgl-project#1328's own file (test_weg2_xchg_refusal_reachability_1328.py) already answers "can production reach this raise/verdict at all" via a name-based AST reference graph (_Index/build_index/reachable), with an empty-allowlist ratchet plus a frozen, classified UNWIRED_DEBT for the exceptions, and a synthetic-tree plant-proof (TestTheRatchetCanFail) that RED/GREENs its own failure mode. sgl-project#1306 (test_weg2_wcode_uniqueness_1263.py) answers a different question (is one W-code used twice) and isn't the right host. Extended sgl-project#1328's file rather than building a second walker. THE NEW QUESTION sgl-project#1389 ASKS, different from sgl-project#1328's: does the code that READS a producer's log-line marker run under the SAME precondition the producer's own construction requires? Five real instances from one night (2026-09-13/14): 1-3. W7/W10 (P and D) and W9: count_marker() gates in launcher.py read markers ('sgl-project#706 canonical KV page active', 'canonical GDN blob active', 'sgl-project#1233 HICACHE BIGRAM KEYS FORCED') that only managers/cache_controller.py's HiCacheController ever prints, built only inside mem_cache/registry.py:192's `if ctx.enable_hierarchical_cache:` -- the gates ran unconditionally. ALREADY FIXED (sgl-project#1386 follow-ups 2/3, commits 683ccc5/2ef1a0979d). 4. W45: launcher.py's carrier census reads 'sgl-project#915 PREFETCH LIMIT', whose producer (mem_cache/prefetch_budget.py's log_prefetch_limit) is a no-op whenever its caller passes no cache_controller. ALREADY FIXED (sgl-project#1386 follow-up 4, d6c3d19). 5. The W100 guard bound to _weg2_xchg_inject_from_peer, which runs zero times on the metal (the real call site is _weg2_xchg_bounce_leg) -- DESK10's own test passed because it checks the same wrong function. UNFIXED, in files locked to DESK10 (weight_updater.py) -- reported as a finding, not fixed here. 6. A wait-loop entry-vs-condition race (P enters 03:19:28Z, the condition it waits for exists at 03:19:32Z) -- no expressible static form found. THE MECHANISM (ThePresenceRatchet): for each registered (gate anchor, guard names, producer anchor, producer guard names) tuple, _guard_chain_by_line walks the file's AST once and maps every line to the source text of every enclosing `if` test (presence, not polarity -- an `if X: skip / else: gate` shape records X for lines in EITHER branch, since both fix shapes in the corpus are exactly that). Two per-entry checks (gate side guarded, producer side guarded) plus a DEBT_SIZE_ON_THE_LINE-style pinned corpus size (4) so a removed entry cannot silently pass -- the corpus itself is the required "does the scan find the known corpus" probe (sgl-project#1341/sgl-project#1306's own lesson: a scan that finds nothing reads green). Instances 5 and 6 are DECLARED BOUNDARIES (PRESENCE_RATCHET_BOUNDARIES), not invented rules: sgl-project#1328's own RESOLUTION docstring already states the honest bound this ratchet shares (name-based resolution can call an unwired path wired, never the reverse; no ordering/timing semantics). Instance 5 gets one structural fact this file CAN verify without touching the locked source -- the exact AST call-site count and line of the wrapper _weg2_xchg_inject_from_peer (1, at weight_updater.py:1045) -- pinned so a future desk can diff DESK10's rewire against it. Tests: ThePresenceRatchet (4 corpus checks + shape/naming pins), TestThePresenceRatchetCanFail (synthetic plant-proof: unguarded shape RED, guarded shape GREEN, ambiguous/absent anchors reported not silently misread), TestTheBoundariesAreDeclaredNotInvented (boundary entries carry real reasons; the W100 wrapper's call-site count is pinned). 10 new tests, all green; full file 27/27 green (17 pre-existing + 10 new). Manually verified both required danger-direction mutants: (1) removed one entry from PRESENCE_GATES -- exactly test_the_corpus_cannot_shrink_or_grow_silently goes red, the two per-entry scans stay green over what remains (proving the corpus-size pin, not the per-entry logic, is what catches a silent removal); restored, diff empty. (2) reverted the REAL launcher.py's W7/W10 group P guard to its historical, unconditional pre-fix shape -- the ratchet goes red against the ACTUAL file, not just a synthetic one, naming the exact entry; restored, diff empty (git diff confirmed clean before re-committing).
efschu
pushed a commit
to efschu/htsglang
that referenced
this pull request
Sep 14, 2026
…against sgl-project#1348's coverage dumps The presence ratchet (previous commit) and sgl-project#1328's reachability ratchet both answer STATIC questions -- can production reach this raise, does a gate's guard chain match its producer's. Neither can see instance 5: the W100 guard bound to _weg2_xchg_inject_from_peer has a real AST call site (weight_updater.py:1045, inside _weg2_xchg_inject_weights) and reads WIRED to both instruments, correctly by their own rules, while the real boot routes around it through _weg2_xchg_bounce_leg instead ("laeuft am Metall NULL MAL"). Name-based AST resolution can call a dead path wired, never the reverse -- sgl-project#1328's own docstring already names this honest bound. The order's own diagnosis: AST is the wrong tool for this half; the answer is EXECUTION EVIDENCE, composed from two instruments already in the tree rather than a third scanner. entry_evidence() crosses sgl-project#1328's already-resolved function against weg2/lane_coverage.py's (sgl-project#1348) per-boot-per-rank JSON dump: a function is "entered" iff the dump's `executed` set for its file contains any line in (def_lineno, end_lineno] -- deliberately excluding the def line itself. latest_dump_of_tag() finds the most recent dump (by boot_token's own epoch) among whatever `phase_coverage_{group}_rank*.json` files exist under a directory, filtered to a given boot-tag prefix. THREE TRAPS, each named in the order and each with its own test: 1. "Never executed" != "dead" -- a guard whose body ran and whose condition read false is ALIVE; this ratchet only asks whether the body was entered at all, never which branch inside it fired (test_falle_1_a_condition_that_ran_and_read_false_is_not_a_finding). 2. No dump (or a dump of a DIFFERENT boot tag) is NOT-MEASURED, never a silent green -- the sgl-project#1306 trap in new clothes (test_falle_2_no_dump_is_not_measured_never_green, which also proves a weg2ring1 dump can never answer a weg2xsn31 question -- the named counter-case, a parallel ring-arm boot of a different form). 3. `imported_before_arm=True` marks a module whose import-time lines (the def line itself among them) ran before the tracer armed and so read unexecuted despite the module having genuinely run (#1352f). The discriminator excludes the def line from evidence entirely and reads `imported` (never a body-line proxy) for "was this module loaded" -- tested in both directions (a genuine body hit under imported_before_arm=True still reads entered; a stray def-line-only hit never reads entered on its own). CALIBRATION: EXECUTION_WATCHLIST's one entry is _weg2_xchg_inject_from_peer, tag weg2xsn31, groups P and D, cited to BOOT_weg2xsn31_0913_4.md VERSUCH 8 (2026-09-14, window 2thy75): the `WEG2-XCHG COLLECT tag=%s pieces=0` marker this function's collect path would print appears zero times in either P.log or D.log across the whole boot. The boot's own P.log confirms its rank dumps were written (`lane_coverage: final dump .../phase_coverage_P_rank0.json legs=0` at 03:21:36Z, PP0) -- but by the time this ratchet was built, those files were no longer on disk (this shared box's evidence directory is a scratch location every concurrent boot can write into without a dedicated --evidence-dir, and something later removed them). The required mutant's own fixture therefore RECONSTRUCTS the dump from the boot's own printed log lines (legs=0, PP0, cited file:line) rather than claiming to replay the original bytes -- stated explicitly in the test class docstring so nobody mistakes it for the literal file. TheExecutionRatchet.test_the_watchlist_against_the_live_evidence_tree is a best-effort REPORT against whatever is currently on the shared box (never a pinned assertion, since other seats' concurrent boots mutate this directory continuously) -- run just now, it correctly prints NOT MEASURABLE for both P and D, matching the fact just established that the real dumps are gone. Tests: TheExecutionRatchet (2 cases) + TheExecutionRatchetCanFail (7 cases, all hermetic, synthetic dumps in temp dirs). 9 new, all green; full file 36/36 green (27 prior + 9 new). Manually verified the required danger-direction mutant: entry_evidence short-circuited to always return "entered" -- exactly test_the_instance_5_case_is_reported_not_entered (the required calibration case) and test_falle_3_the_def_line_itself_is_never_used_as_evidence go red; restored, diff empty.
efschu
pushed a commit
to efschu/htsglang
that referenced
this pull request
Sep 14, 2026
…gl-project#1391) TRAIN2's census against the MERGED tree (independently confirmed here by manual grep across weg2/managers/mem_ledger/planner/model_executor/scripts on train tip bb70894): W100 was double-assigned. host_ledger.py's Weg2SleepLegCushionDeficit (8799c7f, sgl-project#1361 fix6) held it first; Weg2XchgLaneNeverDrainedRefused (weg2_memory_saver.py / weight_updater.py, picked tonight for sgl-project#1391) is the later arrival and moves, per the "census keys on the exception name, never the digit" rule. W106 (this branch's own Weg2XchgWakeSourceGapRefused, sgl-project#1369) is unaffected -- it was free against the merged tree from the start. W108 verified free by the same manual grep, both against the merged tree and this branch. Two call sites renumbered (weg2_memory_saver.py's VramCredit.wait_for, weight_updater.py's _weg2_xchg_inject_from_peer), both raise-message f-strings only -- no behavioural change, this is a label fix. The one consumer that pinned the digit, test_weg2_undrained_lane_refusal_1391.py (two `assert "W100" in msg`), now pins `Weg2XchgLaneNeverDrainedRefused` by name instead, which is the actual fix against the next collision (sgl-project#1265/sgl-project#1306 precedent, named explicitly by the coordinator): a class-name pin survives a future renumber, a digit pin does not. Narrative W100-mentions elsewhere in that file's own docstring and in test_weg2_1394_1369_wake_source_gap.py's docstring updated to record the renumber rather than silently going stale. Not touched: test_weg2_sleep_leg_gate_1361.py's own "W100" pin (that IS Weg2SleepLegCushionDeficit, the ORIGINAL, unchanged holder -- host_ledger.py, outside this desk's file boundary and not part of this collision) and test_weg2_xchg_lanes_concurrent_1385.py's W100 mention (a sibling-code citation for the same unchanged host_ledger.py class). Regression: 141 passed / 10 subtests across the W106/sgl-project#1394 suite, the gate-axis tests, sgl-project#1391's own suite (renumbered), inject-wiring, the wcode census, and both the sleep-leg-gate and lanes-concurrent tests that cite the OTHER W100 (confirming they are genuinely unaffected).
efschu
pushed a commit
to efschu/htsglang
that referenced
this pull request
Sep 14, 2026
…gl-project#1391) TRAIN2's census against the MERGED tree (independently confirmed here by manual grep across weg2/managers/mem_ledger/planner/model_executor/scripts on train tip bb70894): W100 was double-assigned. host_ledger.py's Weg2SleepLegCushionDeficit (8799c7f, sgl-project#1361 fix6) held it first; Weg2XchgLaneNeverDrainedRefused (weg2_memory_saver.py / weight_updater.py, picked tonight for sgl-project#1391) is the later arrival and moves, per the "census keys on the exception name, never the digit" rule. W106 (this branch's own Weg2XchgWakeSourceGapRefused, sgl-project#1369) is unaffected -- it was free against the merged tree from the start. W108 verified free by the same manual grep, both against the merged tree and this branch. Two call sites renumbered (weg2_memory_saver.py's VramCredit.wait_for, weight_updater.py's _weg2_xchg_inject_from_peer), both raise-message f-strings only -- no behavioural change, this is a label fix. The one consumer that pinned the digit, test_weg2_undrained_lane_refusal_1391.py (two `assert "W100" in msg`), now pins `Weg2XchgLaneNeverDrainedRefused` by name instead, which is the actual fix against the next collision (sgl-project#1265/sgl-project#1306 precedent, named explicitly by the coordinator): a class-name pin survives a future renumber, a digit pin does not. Narrative W100-mentions elsewhere in that file's own docstring and in test_weg2_1394_1369_wake_source_gap.py's docstring updated to record the renumber rather than silently going stale. Not touched: test_weg2_sleep_leg_gate_1361.py's own "W100" pin (that IS Weg2SleepLegCushionDeficit, the ORIGINAL, unchanged holder -- host_ledger.py, outside this desk's file boundary and not part of this collision) and test_weg2_xchg_lanes_concurrent_1385.py's W100 mention (a sibling-code citation for the same unchanged host_ledger.py class). Regression: 141 passed / 10 subtests across the W106/sgl-project#1394 suite, the gate-axis tests, sgl-project#1391's own suite (renumbered), inject-wiring, the wcode census, and both the sleep-leg-gate and lanes-concurrent tests that cite the OTHER W100 (confirming they are genuinely unaffected).
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.
Motivation
To fix #1301 and the min p sampling with CUDA graph.
Modifications
torch.compile.Performance
Checklist