Repository navigation
Add support for logprobs in OpenAI chat API - #852
Conversation
|
cc @merrymercy @hnyls2002 @Ying1123 @zhyncs for review, I think it is ready to merge |
|
I've just tested the code from this branch and encountered an error: |
|
@isukharev Computing logprobs take more memory, try to reduce |
|
@hnyls2002 Thanks! After reducing |
|
@isukharev When you want to get the logprob of the prompt, the prefix radix cache will be turned off. This is because we only cache the KV cache, not the logits. Do you need logprob for prompts or do you only need the logprob for generation? If you only need the logprob for generation, we can implement an additional flag just for your use case. Then you should see a similar cache hit rate. |
|
@Ying1123 Only need this for generation, we are using LLM as a CrossEncoder as shown here: |
|
@yichuan520030910320 @hnyls2002 It should be easy to do. Can you implement this feature? |
…eturn W24's flip-sticky root. 43 of 45 binding refusals on PP0's corridor gate read cause=phantom_capacity, every 60-75 s for 21.6 min: the allocator-cache post promised ~309-324 MiB (memory_reserved - memory_allocated), an empty_cache() draw delivered 0, sgl-project#828's law 2 derated the post to zero, and the next pass re-promised the same bytes and paid for the same sync again. sgl-project#828 made the VERDICT honest. The PROMISE stayed dishonest, and a silent derate loop is what that costs. ROOTED AGAINST THE LOG, and two hypotheses are closed for good: - stale pricing KILLED: the derate denominator takes 21 distinct values, drifting 320464384 -> 325639168 B. It is re-measured every pass. - missing release KILLED: _reclaim_cached_blocks has no production hook and 43/43 phantom lines are tagged [reclaim figures measured this pass], against the one scarcity line tagged [reclaim figures never measured]. - wrong-rank read: no positive evidence; all PP0, one device per worker. - fragmentation survives as the only candidate but is NOT PROVEN: the log carries no allocator-segment telemetry at all (inactive_split, fragment and segment appear zero times in 14490 lines). So this does not assume the root, it MEASURES it. inactive_split_bytes is the free-but-trapped remainder inside segments still in use, and empty_cache() returns only whole free segments, so releasable = reserved - allocated - inactive_split is what a draw can actually hand the driver. A raw-nonzero, releasable-zero cache becomes an honest zero that NAMES the fragmentation, and the cause reads scarcity rather than phantom_capacity -- nothing was promised, so nothing is phantom. The seam then skips a sync it can prove will return nothing. The fix is correct under every one of the four hypotheses: a cache that really is releasable measures nonzero, draws and pays exactly as before, with law 2 still underneath as the backstop for an estimator that over-promises. The discriminator W24 lacked is now emitted every pass -- the predicted releasable figure printed next to what the draw actually returned. Agreement confirms the fragmentation account; a nonzero prediction against a zero delivery falsifies it and indicts this estimator instead. THE ABSTENTION IS LOAD-BEARING. Under expandable_segments:True, reserved counts a VIRTUAL extent -- measured in this tree at 36910 MiB on a 32607 MiB card -- so the arithmetic is void. Subtracting there UNDER-reports, and an under-report suppresses a draw that would have paid, making the flip stickier: the precise defect this commit removes. It abstains instead, along with a backend lacking the counter and an empty reservation, each returning the seam to sgl-project#828 behaviour byte for byte. All three live in a pure function over a stats mapping so they are falsifiable without a GPU. TESTS (hermetic, CUDA_VISIBLE_DEVICES=""): test_honest_cache_pricing_852.py 19 passed test/registered/unit/managers/ 3800 passed, 18 skipped, 334 subtests (740 s) test/registered/unit/mem_cache/ 1710 passed, 1658 skipped, 361 subtests (128 s) ruff check + format clean Red-both-ways proven: the census wire was red as 'releasable not found in ... cause=phantom_capacity' before wiring, and the expandable-segments guard was red as '524288000 is not None' -- the 500 MiB under-report -- with the guard disabled.
…, and can be wrong W24 residual defect (iii), and the ticket's own remedy is NOT what shipped. The 09:01:37 specimen carries TWO defects; "break the band when the decode bundle is not draining" is neither of them. THE ARITHMETIC THAT REFUSES THE TICKET'S REMEDY. At the measured decode_contention (sigma) = 1 the scheduler gives prefill absolute priority per iteration -- `_differential_flip_threshold` records the measurement verbatim: "an iteration with any prefill chunk pending runs THAT batch and never reaches the decode branch". So while prefill is pending in TP the decode bundle CANNOT shrink, by construction. "Bundle not draining" is therefore IMPLIED by the band's own operating condition, not evidence about it, and a band that broke on it would collapse to the plain break-even for every load with a request decoding -- silently deleting the sgl-project#665-F1 differential model. That is a policy rewrite wearing a bug fix. (A) THE DETECTOR READ A BAR THE POLICY NEVER APPLIED. The alarm printed `bar_tok=20057` and fired on `pending 22887 > 20057`, while the hold it indicted names its own bar in its own text: `> N=20057 but <= 30086`. 30086 is `effective_flip_threshold(cfg, running_bs=1)`, the differential bar, which at sigma = 1 is N0 x (1+2B)/(1+B) -- exactly 20057 x 1.5. The policy compared 22887 against 30086 and HELD, correctly. So W24's single LAYOUT-ECONOMY ANOMALY is a FALSE POSITIVE, and the "first metal catch of the detector" reads better as its first metal self-indictment. This is sgl-project#819's ONE READING rule -- "the bar the policy APPLIED and the bar the log REPORTS can never be two different numbers" -- holding inside phase_policy and breaking at the module boundary. It is the sgl-project#851 class root exactly ("the DECIDERS still read their own bookkeepers"), occurring inside an sgl-project#851-family detector, which is the same shape sgl-project#853(i) already found once this build. The applied bar is now passed from the one authority that computes it, and is REQUIRED rather than defaulted: a default is the mechanism by which a caller silently re-creates the divergence. The gate takes max(break-even, applied), which bounds the blast radius to one direction -- it can only RAISE the bar, so it can only remove false positives and can never invent an alarm. That also covers strict purity, where the threshold is 0 by construction. (B) THE BAND HAD NO FALSIFIER FOR ITS OWN PREMISE. It was the ONLY hold in `_decide_from_load` that could not be wrong. Every neighbour carries a bound: min dwell yields to `starved` (sgl-project#768), drain mode to the sgl-project#833 stall deadline, the idle lock to the idle dwell (sgl-project#748). The band says "prefilling it in tp beats the round trip" -- a claim priced at the TP prefill RATE, true only while the backlog is actually being prefilled here. The falsifier is taken on the axis the claim is made on: PREFILL PROGRESS. `pending_prefill_tokens` is "admitted but not yet computed", measured at the chunk fill boundary, so it drops every round a chunk is computed -- even mid-way through one long prompt. Frozen for a whole decode window means no chunk was computed for a whole decode window. The clock is sgl-project#677(a)'s existing `last_prefill_progress_at`; the window is `drain_stall_deadline_s`, the same quantity sgl-project#833 and the sgl-project#838 detector already use, so policy and detector cannot come to hold two different ideas of one decode window. Unstamped reads as no stall, so a caller that never observed cannot flip on it. THE TWO HALVES AGREE ON THE SPECIMEN INSTEAD OF DOUBLE-COUNTING IT. W24's pending oscillated 0 -> ~22.5k -> 0 on a ~5-min period, so prefill progress was live and this break would have stayed SILENT there -- consistent with (A), which says that hold was right. That is what makes them two separable defects rather than one defect described twice. NOT REBUILT (prior-art gate): the ticket pairs (iii) with "a completed flip should clear the staging backoff". Already implemented -- `note_flip_completed` pops last_abandon_at / arm_refusals / arm_hold_until / arm_degraded for the direction -- and already pinned by test_phase_policy_flip_reachability.py:: test_a_completion_clears_the_staging_rate_limit_outright. Cited, not duplicated. A band-break is paced by that limiter like any other arm, which is correct: `_decide_rules` applies it after `_decide_from_load`, and `_demand_outweighs_a_retry` still overrides it when the backlog outweighs the wait. WHAT THIS DOES NOT CLOSE: it does not move the flip. W24's stuck phase was FUNDING -- 153 arms refused after the policy had already said the load wanted the flip, 43 of 45 binding refusals reading cause=phantom_capacity, which is sgl-project#852's territory. (iii) must not be cited as a flip-stickiness fix. TESTS (hermetic, CUDA_VISIBLE_DEVICES=""): test_band_premise_853.py 15 passed test_layout_conformance_838.py (updated) unregressed test_flip_threshold_repricing_819.py unregressed test_phase_policy_flip_reachability.py unregressed test/registered/unit/managers/ 3833 passed, 18 skipped, 334 subtests (759 s) test/registered/unit/mem_cache/ 1710 passed, 1658 skipped, 361 subtests (127 s) ruff check + format clean Red-first, both halves and both directions. (A) was red as the specimen FIRING -- "a hold inside the policy's own band was alarmed on" -- with the can-fail direction proving a detector that merely went quiet dies (pending above the applied bar still fires, and a window-3-shaped span at 119x the bar is above BOTH bars and stays an anomaly). (B) was red as the frozen backlog holding forever, measured: 25 observations at a constant 25065 tok returned "too short for the round trip" every time, with the can-fail direction being that a progressing prefill, a sub-window stall, a sub-band backlog and an unexpired min dwell must all still HOLD.
…being ambiguous
W25 ran a sustained TP-sticky prefill phase -- `Prefill batch phase=tp` live on
all three ranks at 11:38:51, 16-24k prompts, no cutover after 11:33:57 -- and
THE USER FOUND IT BY EYE while
grep -c "LAYOUT-ECONOMY ANOMALY" boot_w25_0824_1125.log -> 0
for the whole boot. Fourth instance of the failure form sgl-project#838 exists to prevent,
against a standing order that a human eye is never the instrument.
THE DETECTOR IS EXONERATED, AND THAT IS SAID PLAINLY RATHER THAN PAPERED OVER.
Its class-2 gate 5 requires `pending > the bar the policy applied`. The hold
reasons across the sticky phase:
19x pending prefill <= N=18614, running it in tp (BELOW the bar)
6x > N=18614 but <= 27921 with 1 req decoding (inside the band)
25x staging rate limit / 18x drain mode / 7x min dwell
Pending was 16-20k against a LIVE break-even of 18614: sgl-project#819 reprices N from the
measured seam, the seam had risen to 8.50s against a 3.2s seed, and the bar
moved 7004 -> 18614 with it. The policy's own arithmetic said TP was cheaper,
so an alarm would have been precisely the over-eager mutant
`test_mutant_overeager_detector_dies` exists to kill. NO ALARM IS ADDED HERE.
The real defect behind the sticky phase is the SEAM COST that raised the bar --
W25 root R1, recorded in NOTE_851 and NOT fixed by this commit.
WHAT IS ACTUALLY BROKEN IS THAT THE ZERO CANNOT BE READ. `c2 = 0` conflates:
ran every round and correctly declined (what happened)
never ran (the W24 shape, one ticket ago)
not wired on this pin
threw inside the try/except and was swallowed
That is the sgl-project#851 defect class -- the silent multi-valued zero -- occurring
INSIDE the detector, one commit after sgl-project#853(i) had to remove the identical shape
from the exposure gate. It is why a person's eye ended up being the instrument,
and it is the same remedy: the instrument announces what it decided.
LAYOUT-ECONOMY CHECKED (sgl-project#838) the verdict ran and declined, with the
declining gate and both bars in the line
Counted always, logged on a 60 s heartbeat (DECLINE_REANNOUNCE_S, deliberately
slower than the 10 s alarm cadence: an alarm is urgent, a decline is a liveness
proof and must be cheap enough that nobody switches it off). At INFO, not
DEBUG -- W25 ran at INFO and would not have seen a DEBUG line, which is the
correction sgl-project#853(i) already had to make once on the exposure clamp. The counter
field gains `c2ok`, so `c2=0, c2ok>0` reads healthy and `c2=0, c2ok=0` reads
never-ran. `_should_say` takes the cadence as a PARAMETER rather than growing a
second copy that could drift from the first.
THE CAN-FAIL DIRECTION IS THE WHOLE RISK and is pinned: a fix that downgraded
real anomalies into heartbeats would satisfy every liveness assertion in the
file while destroying the detector. So an anomaly must still alarm, must count
as an anomaly and never as a check, the two markers must be distinct strings,
and an alarm line must not contain the CHECKED marker -- that last one because
sgl-project#853(i) already caught a marker quoting another marker's text and restoring the
ambiguity while passing everything else.
TESTS (hermetic, CUDA_VISIBLE_DEVICES=""):
test_economy_detector_liveness_854.py 14 passed
test_layout_conformance_838.py (periodic field updated for c2ok)
unregressed
test_band_premise_853.py unregressed
test/registered/unit/managers/ 3847 passed, 18 skipped,
334 subtests (737 s)
ruff check + format clean
Red-first: `note_economy_declined` did not exist, so every liveness assertion
failed at AttributeError, and the periodic-field test failed as
'c1=1, c2=2, c2ok=0' != 'c1=1, c2=2' -- the field genuinely changed shape and
the existing pin was updated deliberately rather than loosened.
Also recorded in docs/dev/NOTE_851_build_caveats.md: W25's three new roots
(R1 seam cost, R2 the gate short ~210 MiB beside kv-slack's 2432 MiB, R3 sgl-project#852
still over-promising a stable 88 MiB and saying so through its own
discriminator). sgl-project#852 must not be cited as closed.
The user asked why a tp_to_pp flip takes 11.6 s, and whether 16 waves over
116502 live slots could not just be moved in one parallel shot. The capture
answers the first half and refutes the premise of the second.
THE 116502 LIVE SLOTS AND THE 16 WAVES ARE NOT THE COST. W25's own seam
census names one segment:
seam-census] timing tp_to_pp rank 0: 10466.8 ms across 448 segment(s),
worst 'refill_highwater->weights_refill' 9516.2 ms (91% of the walk)
kv_write->gdn_state 174.3 | cutover->done 152.4 |
flip_writeback->hicache_quiesce 74.8 | kv_pack->kv_local_read 57.4
Three consecutive tp_to_pp flips: 9516.2 / 9496.5 / 12108.2 ms in that one
segment, against totals of 10466.8 / 10568.0 / 13181.2. Meanwhile the ENTIRE
KV movement at the largest observed reshard (epoch 11, 116502 live slots,
995.31 MiB sent / 825.03 MiB received) is read 19.9 + exchange 486.0 + write
394.8 = 901 ms, and the GDN blob is 11.69-18.70 MiB. Across the window live
slots grew 947x (123 -> 116502) while the flip grew 1.26x (5077.9 -> 6416.0
ms). The ranks are already parallel: totals agree within ~40 ms while movers
legs differ by ~600 ms, and the peers absorb PP0's overrun as CUTOVER WAIT
(1313.3 / 1220.8 ms vs PP0's 225.3). A rendezvous, exactly as sgl-project#690 recorded.
SO THE SEAM IS A WEIGHTS-REFILL RATE PROBLEM, and the rate is direction-
asymmetric for reasons nothing in the tree explains. Same rank, within 2.7%
of the same bytes:
pp_to_tp 15925.8 MiB 3214-3915 MiB/s 4.07-4.96 s
tp_to_pp 16362.7 MiB 1351-1723 MiB/s 9.50-12.11 s
FOUR CANDIDATE EXPLANATIONS WERE CHECKED AND ALL FOUR FAIL, and they are
recorded so nobody re-derives them:
* not a path fallback -- SGLANG_PHASE_FLIP_REFILL_STAGED defaults True
(environ.py:348), unset in the boot, and arena_refill dispatches on the
image being file-backed, not on direction. Both take _staged_file_refill.
* not a missing fd -- both sgl-project#802 warning paths ("could not open a read fd",
"O_DIRECT unavailable") appear ZERO times in the 3.45 MB capture, against
9 "flip host image FILE-BACKED" registrations.
* not the O_DIRECT alignment cliff (sgl-project#809's 8304 -> 2595 MiB/s) -- the loop
only issues aligned offsets: chunks are 32 MiB multiples of
_DIRECT_ALIGN=4096 and `want` is rounded down to it; only the trailing
checksum tail is buffered, by design.
* not the pre-sgl-project#802 fault path -- on sgl-project#802's own discriminator the fault path
makes rank rates CONVERGE (821/775 MiB/s on links differing 1.80x). W25
DIVERGES with the link in both directions (1.59x and 1.40x).
THE INSTRUMENT IS WHAT IS MISSING, NOT THE MECHANISM. The leg reports ONE
aggregate MiB/s. The read (os.preadv) and the H2D (copy_ on a stream, depth
2) are pipelined, so that aggregate is min(read_rate, h2d_rate) with no way
to see which bound it hit. That is the sgl-project#851 class -- one number with several
meanings -- sitting inside the term that is 91% of the seam, which is why two
independent readers could not attribute the gap from code.
WHAT SHIPPED. `RefillLegTiming` accumulates, on the existing path:
read_s wall time inside preadv -- storage/ARC bound
h2d_wait_s wall time blocked on a prior DMA -- PCIe/link bound
drain_s the pipeline tail, counted apart so it can never be mistaken
for either bound
They are near-exclusive by construction: the ring only waits on a buffer
whose copy has not landed, so a read-bound leg never blocks there and a
link-bound leg blocks almost every turn.
`refill_bound_phrase` is a PURE function over that record -- no GPU -- so
both directions are falsifiable off metal, the same split sgl-project#852 used for the
allocator-cache estimator and for the same reason: a rule that can only be
exercised on metal is one this corpus has repeatedly shipped inert.
THE CAN-FAIL DIRECTION IS THE WHOLE RISK and is pinned. A phrase that always
named a bound would satisfy every "it says something" assertion while being
exactly as useless as the aggregate it replaces. So "unattributed" (not
instrumented, or no time accounted) and "MIXED" (neither half dominates) are
first-class outcomes, asserted directly, and a 101-point sweep across the
whole read-share range proves the three verdicts neither overlap nor leave a
hole.
NO BEHAVIOUR CHANGE: the timing record is optional and defaults to None, so
every caller that does not pass one runs byte-identically.
ONE PINNING TEST HAD TO MOVE, and it is worth naming because widening it
blindly was the tempting wrong answer. `test_arena_high_water_631.py`'s
`fake_arena_refill` stub replaces `arena_refill` to prove the arena is
committed before it is copied into; it did not accept the new kwarg and all
six of its refill tests failed with TypeError -- the sgl-project#624 stub-drift shape.
The stub now accepts `timing=None` (which is the whole adaptation, since the
record is an instrument with no semantics the test pins), AND it captures
what it was handed, with a new `test_the_refill_leg_is_instrumented`
asserting the caller really does pass a `RefillLegTiming`. Without that, the
signature widening would have silently tolerated the instrument being
unwired again -- a stub that accepts anything proves nothing.
TESTS (hermetic, CUDA_VISIBLE_DEVICES=""):
test_refill_bound_856.py 9 passed, 101 subtests
test/registered/unit/model_executor/ 15 failed / 763 passed, against a
VERIFIED HEAD baseline of 15 failed / 754 passed -- identical failure
set, pre-existing, unrelated to this path (bf16 vendor fallback,
coresidence budget, expert-offload kv regain). Checked by reverting this
change and re-running, not asserted.
ruff format clean; the one F401 in phase_flip_boot.py is pre-existing at
HEAD (verified against git show HEAD:...).
Full ledger, with every figure and every failed search set:
docs/dev/NOTE_856_seam_cost_ledger.md
W25 reopened sgl-project#852 with its own discriminator. Five times, stable to the MiB, while the general cache drifted 310 -> 308 -> 307 -> 305: staging reclaim: driver free 2896 -> 2896 MiB (+0 returned, predicted releasable 88 MiB), 310 MiB still cached A NONZERO PREDICTION AGAINST A ZERO DELIVERY -- the reading sgl-project#852's own text names: "falsifies it and indicts this estimator instead". The phantom was down 3.6x from W24's ~309-324 MiB and the cause split moved from 43/2 to 8/2 phantom/scarcity, so the fix was real; but 88 MiB survived it. THE TELL WAS THE STABILITY, not the size. A term that does not move while its neighbours drift is not fragmentation. It is a fixed structure. IT IS THE GRAPH POOLS. `speculative/adaptive_graph_memory.py:841` takes a PER-TAG `torch.cuda.graph_pool_handle()` and :873 captures into it (`torch.cuda.graph(cuda_graph, pool=pool, stream=stream)`). This boot captured decode graphs -- decode backend='full', bs 1..24 (the PP stack captures none, "no CUDA graphs captured by construction"). Torch's `release_cached_blocks` frees whole blocks from the GENERAL large_blocks/small_blocks pools ONLY; a private pool goes back solely via `graph_pools_freeable`, once nothing references the graph. But reserved_bytes.all / allocated_bytes.all / inactive_split_bytes.all are DEVICE-GLOBAL and count those segments. So `reserved - allocated - inactive_split` promises bytes the driver can never be handed, for as long as the graphs live -- which is the whole TP phase. Torch's own structure is the citation, not an inference: `SegmentInfo.owner_private_pool_id = {0, 0}` (c10/core/CachingDeviceAllocator.h:98), surfaced in the snapshot as `segment_pool_id`, which torch/_inductor/cudagraph_trees.py:1827 uses for exactly this purpose -- selecting the segments belonging to a graph pool. WHAT SHIPPED. The figure is now computed SEGMENT BY SEGMENT instead of from device-global counters. `releasable_cache_bytes_from_segments` sums total_size over segments that are (a) entirely free, (b) not in a private pool, (c) not expandable -- which is precisely what `release_blocks` can free. The three-term arithmetic REMAINS as the fallback when a snapshot cannot be read, so this buys precision and never behaviour. `graph_pool_free_bytes_from_segments` names the trapped figure, and the reclaim line prints it beside the prediction -- the same discipline sgl-project#852 used when it printed the prediction beside the delivery. The next window reads the attribution directly instead of inferring it. THE ABSTENTIONS ARE UNCHANGED, DELIBERATELY. The expandable-segments abstention still keys on the ENV, not on the per-segment is_expandable flag. sgl-project#852's reason for it is that `reserved` describes a VIRTUAL extent under that allocator (36910 MiB measured on a 32607 MiB card) and the comparison is void; an under-report there suppresses a draw that would have paid and makes the flip STICKIER -- the precise defect sgl-project#852 exists to remove. Narrowing that abstention is a separate decision with its own evidence, not a side effect of naming the fourth term. RED-FIRST, and it is the assertion that makes this the right term rather than a plausible one: `test_the_three_term_proxy_counts_the_graph_pool` feeds the SHIPPED arithmetic a segment set of the W25 shape and gets back EXACTLY 88 MiB. The can-fail direction is pinned too -- an implementation returning 0 for everything would satisfy every "the graph pool is not promised" assertion while destroying the draw sgl-project#852 exists to keep paying, so a wholly-free GENERAL segment must still be promised, and is. `None` (no verdict) never collapses into 0 (no trapped bytes). A torch version that drops the field degrades to "general pool" -- the already-shipped reading -- never to a wrong subtraction, and both field spellings are accepted. TESTS (hermetic, CUDA_VISIBLE_DEVICES=""): test_releasable_graph_pool_852.py 10 passed ruff check + format clean sgl-project#852 is NOT recorded as closed by this either. What is closed is the over-report: the estimator no longer promises graph-pool bytes. Whether the REMAINING general-pool free space is genuinely fragmented is still the open question, and the reclaim line now carries both numbers needed to settle it on metal.
… its two callers
ANALYSE_851 site 4: `spendable_bytes` reads the allocator cache raw. The
finding is sharper than "underated" -- the SAME figure is correct for one
caller and wrong for the other, and only one of the two has an argument.
`_allocator_cache_bytes` (reserved - allocated) documents overstating as the
safe direction, and it IS safe where it sizes `want`: "overstating the cache
understates `want`, and an understated want costs a late arm". But
`spendable_bytes` ADDS it to a budget --
return free + cache - delta
-- so there an overstatement WIDENS the prefill chunk this actuator grants,
and the one thing that same function calls unsurvivable ("an allocation larger
than what can be served") is exactly what it then permits. Same number,
opposite error.
AND THE OVERSTATEMENT NOW HAS A NAME AND A NUMBER (sgl-project#852 R3, 9aa5b6e). Free
blocks inside a CUDA-graph PRIVATE pool are counted by `reserved - allocated`,
because those are device-global `.all` counters, but an ordinary forward
allocation cannot take them -- they are reachable only while capturing into
that pool. W25 measured that term at a stable 88 MiB. This is the same
reconciliation the one-job-one-mover rule asks for: a canonical way to price
trapped cache now exists, so every bespoke reader of the same payload is
checked against it.
THE SHARED FIGURE IS DELIBERATELY NOT CHANGED. Subtracting inside
`_allocator_cache_bytes` would have fixed the budget caller by breaking the
ladder caller's documented argument. Only the budget caller subtracts, and a
test pins that separation by reading both function sources.
TESTABLE OFF METAL, which the first version was not. That version put the rule
behind `torch.cuda.is_available()`, which under the hermetic
CUDA_VISIBLE_DEVICES="" regime is always False -- so the subtraction could
never be exercised, the "shipped inert" failure this corpus keeps recording.
The arithmetic is now the pure `takeable_cache_bytes`, and the probe is
injectable, so BOTH outcomes are asserted: inert without a device, and
actually subtracting with a probe. A test proving only the first would not
distinguish "inert under CVD=''" from "inert everywhere".
Its own can-fail tests killed two bugs while being written: `int(1.5e400)`
raised an uncaught OverflowError, and the negative-trapped case could have
INFLATED a budget above the real cache -- the direction that grants an
unservable chunk.
TESTS (hermetic, CUDA_VISIBLE_DEVICES=""):
test_takeable_cache_856.py 13 passed, 3 subtests
test_corridor_steering_657.py 26 passed (unregressed)
ruff check + format clean
ATTRIBUTION, HONESTLY. A `-k "admission or corridor or steering"` sweep showed
1 failure (test_pp_admission_wraparound_never_blocks) that a reverted-tree run
did not. I could NOT get a clean A/B: that `-k` selection pulls in a family of
multiprocess PP-admission tests that hang on `Process.join` under load (caught
live with py-spy in test_pp_admission_send_handle_dropped_796), and two
attempts wedged there. So the claim rests on a direct proof instead of a
suite diff: under CVD="" `_takeable_cache_bytes` returns EXACTLY
`_allocator_cache_bytes()` (325058560 == 310 MiB, demonstrated), and
`torch.cuda.is_available()` is False there -- the change is byte-identical in
every hermetic test and cannot have caused that failure. The wraparound test
also passes standalone both with and without the change.
NOT VALIDATED ON METAL. The subtraction only engages with a device, so its
real effect is unproven until a window. It is strictly conservative -- it can
only narrow a cut, never widen one -- which is why it is safe to land ahead of
that.
…all three falsifiers First slice of the user's flip-image design: RAM holds ONE layout image plus a small overshoot, and at the flip the incoming layout streams RAM -> VRAM while the outgoing one streams VRAM -> RAM into the pages just freed. PCIe is full duplex, so the copy-back rides the idle return direction. THE COPY-BACK IS NOT WRITE-BACK. The weights are immutable and nothing is saved; it is residency PLACEMENT for the next flip, which is what a single-layout RAM budget requires. Written into the module docstring because a later reader who mistakes it for a write-back will optimise it away and break the following flip. WHY THIS AND NOT THE PARTIAL PIN: W26 proved the dual pin impossible here -- both pin arms OOM-killed in the LAUNCH phase, before any flip. One layout plus eps (~30 GiB vs ~68.7 GiB) fits AND takes the disk off the steady-state critical path, which is what reaches the physics floor; a partial pin leaves a disk share behind, and W26 measured the leg 99.8-100 % storage-bound. THIS SLICE IS THE ARITHMETIC ONLY, deliberately. The overshoot sizing and the interleaved schedule are pure functions over byte counts, so every invariant the scheme rests on is falsifiable WITHOUT a GPU -- the same split sgl-project#852's estimator and sgl-project#856(a)'s bound phrase use, and for the same reason. OVERSHOOT = size asymmetry + in-flight window, sized from the LARGER direction. The asymmetry is W26's measured one (PP0 15925.8/16362.7, PP1 8573.8/8961.3, PP2 8573.8/9481.6 MiB); a single fixed reservation has to cover whichever direction the next flip takes, so a mean is the OOM. The in-flight term is separate and pinned: an implementation returning only the asymmetry gives 0 for equal layouts and stalls immediately. ALL THREE NAMED FALSIFIERS ARE ASSERTED: * no actual overlap -- `rotation_totals` counts co-scheduled steps; a real rotation must have them and must have them as the DOMINANT shape (>90 % of steps), not as an accident of the tails. Its can-fail partner: a one-sided rotation must report zero overlap. * RAM leak across cycles -- three full A->B->A cycles must return host occupancy exactly to its start. Three, because W27-retry's leak fired on the THIRD cycle, not the first. * checksum -- verified against the real source: the image is `payload = image[:layout.total_bytes]` plus an int64 trailer, checked with `uint8_checksum(dst)` over the ARENA. That last part is what makes a D2H reproducible: bytes returned from VRAM verify exactly as bytes read from disk do, so only the 8-byte trailer is new. A FINDING THE TESTS PRODUCED, and it is why the budget test first passed vacuously: THE RAM BUDGET BINDS IN ONLY ONE DIRECTION. Pressure exists solely when the OUTGOING layout is LARGER than the incoming one, because only then does the copy-back need more RAM than the H2D frees -- PP0 copying back its 16362.7 MiB tp image while the smaller 15925.8 MiB pp image streams in leaves 436.9 MiB with nowhere to go. The opposite direction schedules cleanly at zero overshoot. Both halves are now asserted so the asymmetry is recorded rather than rediscovered. Under-sizing STALLS LOUDLY rather than proceeding: a scheduler that kept going would be holding both layouts, which is precisely the state that OOM-killed W26's pin arms. GATE (foreground, family-batched): managers core (45 PP files excluded) 3554 passed, 336 subtests, 0 failed model_executor 777 passed / 15 failed (+14 new) The 15 are the pre-existing sgl-project#815 family. ZERO new failures. NOT YET BUILT, and not claimed: the device-side execution (streams, the pinned ring registered once per sgl-project#720/sgl-project#729, the planner-priced host post per sgl-project#721/sgl-project#770), and the separately-instrumented priming flip. This slice is the plan those will execute.
…remise POSTEN 1 -- MEASURED FIRST, AND THE PREMISE DOES NOT SURVIVE THE MEASUREMENT. The instruction was: the guard is inert because there is no readable total, so cap `memory.current` against a constant 111.3 GiB from sgl-project#721. Measured on this box before touching anything: pinned_host_memory_bytes() -> total=118.05 GiB available=112.95 GiB so it does NOT land on the :245 "no honest number" branch. The guard is ACTIVE, a total IS readable, and `PINNED_HOST_RESERVE_BYTES` = 10 GiB is therefore NOT inert as a subtraction. The clamp binds too: MemAvailable 113.19 -> 112.95 GiB, reduced by the cgroup's own resident accounting exactly as rule 2 of `honest_host_memory_bytes` documents. `MemAvailable > MemTotal` is FALSE right now, so the pathological lxcfs reading is not present either. AND THE PROPOSED CAP WOULD NOT HAVE BOUND ANYTHING. Every level of the visible hierarchy is unlimited -- root, system.slice and system.slice/claude.service all read `memory.max = max`, and all three report `oom_kill 0` today (sgl-project#721's 17 kills predate this boot; `memory.peak` 101.98 GiB of 118.05). With no enforcing cgroup anywhere, the physical machine IS the ceiling, which is what MemTotal reports. A hand-carried 111.3 GiB constant would have been a third floor with no enforcer behind it -- the rule this ticket already established, applied to its own instruction. Not built. THE REAL DEFECT IS ONE BUCKET OVER, AND IT IS THE sgl-project#695 CLASS AGAIN. Prior art via the new index: commit c043235 measured that "CUDA pinned host memory is accounted in the cgroup's `file` bucket, not `anon` ... the offload ledger reported 20.78 + 14.44 + 14.44 = 49.66 GiB of pinned pool while `anon` sat steady at 14.6 GiB." Confirmed live on this box: anon 2.12 GiB, file 19.06 GiB, current 21.39 GiB -- the clamp charges ~2.4 GiB of a cgroup holding 21.4. `honest_host_memory_bytes` charges anon + kernel + unreclaimable shmem and NEVER charges `file`, correctly, because page cache is reclaimable. Pinned bytes there are not. sgl-project#695 already fixed one member of this class (shmem hiding in `file`); pinned host memory is the second and is still uncounted. IT ALSO PUTS A DOCUMENTED PREMISE IN DOUBT, and the doubt is precise: `pinned_host_budget.py:253` credits already-registered posts BACK to available because "their bytes are therefore already missing from it". For a post whose bytes land in `file`, they are NOT missing from it -- the clamp never subtracted them -- so the credit-back would count them as free twice. The 2026-08-17 measurement quoted there is sound for the weight images it was taken against; whether it holds for THIS pin depends on which bucket the pin's bytes land in. DELIBERATELY NOT FIXED HERE. That question is decidable only by watching `anon` and `file` across an actual pin allocation, which is a boot. Changing admission arithmetic on a shared path used by HiCache and kv-session-offload, on a guess about which bucket, would be the "capping on a fabricated figure" the module exists to prevent. So it is INSTRUMENTED instead -- the window script prints the before/after pair and names the consequence -- and the arithmetic is left alone until the boot answers it. POSTEN 2 -- `chunk_blocks_quiescence` (phase_flip_runtime.py:144): SAME CLOCK DIVERGENCE, and the determination is not a formality. It is the same class as the retention gap: a consumer (the cutover) and a writer (the chunk boundary that inserts into the tree) on different clocks. Under STRICT the clocks are SYNCHRONISED -- the cutover waits for the prefill, which is what "waiting for prefill to finish IS drain-and-flip" means in its docstring -- and the residual is exactly the NON-STRICT case where they are not. THE DIFFERENCE THAT MATTERS, and why this is one root and not two: the chunk case has a BOUNDED wait available (a prefill completes in finitely many chunks), while a mid-decode resident does not. That is why STRICT can fix one and nothing can fix the other by waiting. But the NON-STRICT chunk case cannot be fixed by waiting either -- an unconditional block re-creates sgl-project#631 defect O, the 32768-token prefill that ran in the slow layout and paid two cutovers for nothing. So BOTH halves need the same missing capability: persisting PARTIAL work at the seam. Neither is closable without it, and that capability is `seam_copy_state` / `restore_seam_state` (schedule_batch.py:2054/:2089) -- sgl-project#875's active territory. Reported, not touched, per Posten 4. Unlike the sgl-project#813/sgl-project#852/sgl-project#715 convergence I rejected last round, this one IS a shared root, and I am saying so because the evidence supports it, not because it tidies. POSTEN 3 -- `scripts/window_871a_verify.py`: one call, PASS/FAIL with numbers. Decides all three open claims from a boot log plus the cgroup. Exit 0 all passed, 1 a decided negative, 2 UNDECIDED -- and 2 is never a pass: "the evidence was not there" is a different fact from "the claim is false", and it sends the reader back to the boot. It boots nothing, claims no card, restores no serving. It also prints the sgl-project#721 HOST-LEDGER pair (posts + memory.current / peak / anon / file, before vs after) that Posten 1 needs. IT SHIPPED A FALSE PASS AND I CAUGHT IT BEFORE THE WINDOW, which is the whole argument for mock-smoking a window script. The first version summed `acked=` over the WHOLE log and returned PASS on the W40 boot -- the very boot in which all 21 fences reported `acked=0`. Seven lines there carry `acked=` from an unrelated subsystem, three of them `acked=24`, so it credited 72 acknowledgements no fence ever made. A window script that reports a false PASS is worse than none: it CLOSES an open claim. Now scoped to the fence's own lines, with that exact log shape as a permanent self-test case. The strongest desk check available is wired in: run against the real W40 log it must reproduce that boot's known split -- tier armed PASS, store delivery FAIL, exit 1 -- and it does. TESTS (hermetic; no boot; no card touched). CUDA_VISIBLE_DEVICES="" verified at the process and `nvidia-smi --query-compute-apps` empty throughout; GPUs 0/0/0. Runner reported its exclusions. * the script's own --self-test decides SIX cases in the intended direction, both polarities, including the false-PASS regression. * can-fail by mutation: un-scoping the acked regex reddens the real-boot reproduction and the self-test (2 red); restored green. * A SECOND SELF-INFLICTED DEFECT FOUND AND FIXED: the test located the script by counting `dirname` calls, landed on `test/` instead of the repo root, and failed all six cases -- a green arm red for a reason unrelated to the thing under test. It now walks up to the root. * partitioned tier-2 gate: 0 failing, 4421 passed (wide 3775 / narrow 292 / serial 354). Serial +6 over 348 is exactly the six tests added here. names=0 agrees with the summary on every lane. * test/registered/unit/mem_cache: 2 failed / 1802 passed -- the known pre-existing test_acceptance_emitters_758 RefillTiming pair, unchanged. POSTEN 4 -- boundary held. Nothing in schedule_batch.py, phase_flip_spill.py or seam_kv_recover was read into or written. Both Posten 2's root and A's remedy lead there; both are reported rather than resolved. NOT ESTABLISHED. Which cgroup bucket the phase-flip pin's bytes land in -- the question Posten 1 turns on -- needs the boot. Whether the admission ever refuses on this box, likewise. And sgl-project#721's 17 oom_kills are from a previous boot: today's counters are zero at every level, so nothing here re-measures that incident, it only records that the enforcement it implies is absent.
THE QUESTION WAS "DOES sgl-project#721'S HOST-POSTEN-LEDGER EXIST", AND THE ANSWER IS (a) WITH TWO NAMED HOLES -- NEITHER OF WHICH IS WHAT sgl-project#721 ASKED FOR. IT EXISTS AND IT IS WIRED. `mem_cache/pinned_host_budget.py` is a named, individually-priced posts ledger, and it IS a hard boot precondition: three paths reach `joint_pinned_host_error` from `ServerArgs.__post_init__` and raise `ValueError` -- server_args.py:6937 -> _handle_kv_session_offload -> :8173 server_args.py:6962 -> _handle_phase_flip -> :8416 -> :8961 server_args.py:7019 -> _handle_hicache -> :8916 -> :9029 Four posts are priced there over CONFIGURED numbers (HiCache host tier, HiCache staging host tier x ranks, phase-flip rotation staging ring x ranks, kv-session-offload spill pool), and eight more register at runtime in the workers (memory_pool_host x4, read_buffer_pool, weights_arena, and the two halves of the phase-flip staging pin this branch added in db1b07e). So it is not (b) "nobody calls it" and not (c) "an intention". BUT sgl-project#721'S TWO PRESCRIPTIONS WERE BOTH DECLINED, AND BOTH DECLINES ARE RIGHT. * "16G floor against `free -g`" -- not implemented, and must not be: `free -g` is lxcfs-synthesised in this container. That was settled in #871b, which moved the boot gate onto the sgl-project#407 owner instead. * "sonst Posten schrumpfen" -- deliberately not implemented. The module's own charter: "The guard SUMS, it never caps. Nothing in this module shrinks a request. Silently capping a pinned pool moves the failure from a boot-time message that names both posts to a later allocation whose victim the OOM killer chooses." That is a better answer than the measure it declines, and it is the reason the ledger prices every post separately -- so an operator can shrink the right flag himself. THE ONE REAL DEFECT, AND IT IS A COUNTER DESCRIBED AS AN ACTUATOR (sgl-project#464/sgl-project#578/ sgl-project#852). `check_and_register_pinned_post` carried this, about the largest claimant in the system: "`_register_image_post` declares the post BEFORE `_alloc_host_image` allocates ... deliberately, so the registry refuses an over-commitment at the DECLARATION rather than discovering it at the allocation." THE REGISTRY REFUSES NOTHING THERE. `register_pinned_post` is a bare dict write with no comparison in it; `_register_image_post`'s own first line says "Never raises"; and `grep -c check_and_register_pinned_post weights_arena.py` -> 0. So the ~27 GiB of phase-flip host weight images are COUNTED, never ADMITTED. THE BEHAVIOUR IS CORRECT AND STAYS. sgl-project#695 chose it at the call site and wrote why: "Registered, not CHECKED: a new refusal path here could break a boot that works today, and the diagnosis this is for is served by the number being present, not by a veto." Registering early still makes those bytes visible to every LATER admission, which is the half that matters. Only the comment was wrong -- and a comment promising a veto that does not exist is worse than none, because the next person sizing a pinned pool against this module would leave exactly the headroom that post already spent. WHY A TEST AND NOT JUST A RE-COMMENT. Prose cannot be regression-tested; the CONTRACT can. The split is now pinned in both directions -- counting never refuses however absurd the post, admitting refuses and names every post, a refused post is not left in the registry, and weights_arena uses the counting entry point only. If someone later wires the admitting one in there, that is a real decision with a boot-refusal consequence and it surfaces here instead of in a boot. A RULE I PROVED ON MYSELF, THIRD INSTANCE IN ONE SESSION. The first version of the prose test asserted the false sentence was ABSENT from the module -- and failed against the FIXED file, because a correction has to QUOTE the claim it corrects. Same shape as #871a's floor-promise assertion and #871b's /proc/meminfo probe assertion. The general rule, now written into the test: ABSENCE OF PROSE IS NOT TESTABLE where a correction must restate what it corrects. Prose gets one positive marker; the behaviour tests carry the contract. THE WEIGHTS TRANSIENT, DECIDED WITH REASONS AS ASKED. It is a SPIKE, not a standing post, and the existing treatment is already the right compromise: it is registered at declaration (so concurrent posts see it), and taken back both when the allocation raises (weights_arena.py:1044) and when the image is freed (:1082). Booking it as a permanent resident would refuse too early; leaving it invisible would be the sgl-project#721 outcome. What it is NOT is admitted -- and turning that on is a behaviour change with a boot-refusal consequence that needs a loaded box to justify, not a desk. LOAD REMAINS UNMEASURED, AND THAT IS IN THE CODE, NOT ONLY HERE. #871b's 0.24 GiB delta between the raw and honest readings is an IDLE measurement. A precondition gate bites under load. No load figure is asserted anywhere as a threshold. TESTS (hermetic; no boot; no card touched). CUDA_VISIBLE_DEVICES="" verified at the process, `nvidia-smi --query-compute-apps` empty throughout, cards 0/0/0. * red-first: 1 of 6 red against the uncorrected module, extracted == summary. * can-fail in the danger direction: making the COUNTING entry point refuse (a counter grown into an actuator) reddens `test_counting_never_refuses_however_absurd_the_post`. Green restored. * turnkey + this suite together: 175 passed, 0 failed. * partitioned tier-2 gate: wide 3775 / narrow 292 / serial 353 passed, 24 exclusions reported by the runner, names=1 agrees with the summary on every lane. The single failure -- test_pp_admission_wraparound_never_blocks::test_blocking_wraparound_wedges_the_ring -- is PRE-EXISTING: on the clean base 726f11e that module fails TWO tests, i.e. MORE than here, and it touches nothing in this commit. * test/registered/unit/mem_cache: 2 failed / 1808 passed. The two are the known test_acceptance_emitters_758 RefillTiming pair; +6 over 1802 is exactly this suite. NOT ESTABLISHED. Whether the ~27 GiB image post SHOULD be admitted -- that needs a box tight enough for the answer to differ, i.e. load. Whether the four launcher posts plus eight runtime posts are the COMPLETE set of pinned claimants: I enumerated every `PinnedHostPost(` and every register call in the tree, but a pinned allocation that never posts at all is invisible to that method by construction. And ZFS cache, named in sgl-project#721's list, is kernel-side and cannot be a process post in this ledger at all.
… BEHOBEN (Metallbeweis), ein ZWEITER Defekt liegt dahinter == DER FIX == `torch.cuda.memory_snapshot()` lief PRO SCHEDULER-RUNDE auf dem Admissions- Pfad (corridor_admission.py:748, erreicht ueber scheduler.py:7578 -> 6121 -> 8317 -> 635 -> 620 -> 720; CPG-Kette geprueft und deckungsgleich mit den py-spy-Stacks des Wedge). Jetzt hinter einer Zeit-Kadenz von 30 s. WARUM KADENZ UND NICHT BILLIGERE QUELLE -- geprueft, nicht angenommen: `torch.cuda.memory_stats()` KANN den Term nicht tragen, und das ist die Praemisse von `graph_pool_free_bytes_from_segments` selbst, deren Docstring argumentiert, dass `reserved`/`allocated` device-globale `.all`-Zaehler sind, die die Private-Pool-Bytes MITZAEHLEN statt sie zu trennen. Die Trennung braucht die Per-Segment-Pool-Id (`_segment_pool_id`), die nur der Snapshot liefert. Also war Kadenz die einzige Achse. DER TRADE, BENANNT: der Wert kann bis zu 30 s alt sein. Die Kosten sind klein NACH DER EIGENEN EVIDENZ DIESES TERMS -- sgl-project#852 R3 mass ihn "stable to the MiB" ueber fuenf Durchgaenge (88 MiB), waehrend der allgemeine Cache im selben Fenster 310 -> 305 MiB driftete, und schloss: "a term that does not move while its neighbours do is not fragmentation; it is a fixed structure". Er bewegt sich nur, wenn ein Graph-Pool entsteht oder freigegeben wird, also bei Capture und Flip -- beide weit seltener als 30 s. Und eine veraltete Lesung ist in der einzigen relevanten Richtung SICHER: der Wert wird vom spendable Budget ABGEZOGEN (:620), ein zu grosser Altwert verengt einen Cut, er weitet ihn nie. KEINE Verhaltensaenderung am Korridor-Verdikt -- nur die Kostenquelle. == METALLBEWEIS == Boot boot_855_fix1027_0840f82601_0830_112900.log. Instrument feuert wie gefordert: "sgl-project#1027 graph-pool-free probe: source=torch.cuda.memory_snapshot (memory_stats cannot separate private pools), cadence=30s, first call 0.8 ms, trapped=100536320" trapped = 95,9 MiB, unabhaengig plausibel neben den 88 MiB aus sgl-project#852 R3. Suite-Re-Run ab Pack 4 (der Pack, der die Gruppe getoetet hatte): dataextract-15 13/15 (87%) Referenz 11 -> UEBER Referenz DE-07, die Frage, an der die Gruppe wedgte: 72,7 s DURCHGELAUFEN (verifier_fail = Inhaltsfehler, kein Haenger). Deadman still, health 200. reasonmath-15 11/12 bestanden bevor abgebrochen Referenz 7 -> bereits darueber Damit ALLE FUENF Packs auf oder ueber Referenz: 13/15, 15/15, 14/15, 13/15, 11+/15 gegen 12, 14, 14, 11, 7. == ABER: EIN ZWEITER, ANDERER LIVENESS-DEFEKT LIEGT DAHINTER == Pack 5 blieb bei RM-13 stehen, health 503, GPU 0%. Die Stacks zeigen etwas GANZ ANDERES als sgl-project#1027: PP0 (active+gil) is_fully_idle (scheduler.py:11917) <- on_idle (:11763) detokenizer (idle) recv_pyobj <- event_loop (detokenizer_manager.py:165) Der Scheduler haelt sich fuer IDLE, der Detokenizer wartet gesund auf Arbeit, der Client wartet auf die Antwort: der Request ist GESTRANDET, waehrend jede Komponente untaetig ist. Kein Kollektiv, kein Lock, und die sgl-project#1027-Signatur (PP2 im Korridor-Pfad gegen PP0 im all_reduce) ist ABWESEND. Das ist ein zweiter Defekt, den der sgl-project#1027-Fix erst SICHTBAR gemacht hat, indem die Suite lange genug lief, um ihn zu erreichen -- sequentielle Entdeckung, keine Regression. Warnung fuer den Nachfolger: die Health-Meldung nennt den Detokenizer, und der ist gesund. Stale ist der HEARTBEAT. Detektion richtig, Erklaerung falsch -- dieselbe Klasse wie im `instrument-text-luegt`-Eintrag. Einstieg ist der gestrandete Request, nicht der Detokenizer. Specimen: /spinning/gpu-arb/W855-STRANDED-REQ-SPECIMEN.md. Braucht eine Nummer. == ABNAHME == NICHT erteilt. Alle fuenf Packs liegen auf oder ueber Referenz, aber die Suite lief nicht end-to-end durch. "Es laeuft" ist fuer sgl-project#1027 erreicht und fuer die Form als ganzes NICHT. BELEG-STUFE: sgl-project#1027-Fix BOOT-BEWIESEN am Symptom (der toetende Pack laeuft durch, Signatur aus den Stacks verschwunden). Zweiter Defekt BOOT-BEOBACHTET, Wurzel NICHT bestimmt.
Thank you for your contribution, we really appreciate it. The following instructions will help improve your pull request and make it easier to receive feedback. If there are any items you don't understand, don't worry. Just submit the pull request and ask the maintainers for help.
Motivation
Fix #839
Modification
Add support for logprobs in OpenAI chat API and cater real OAI API output
Checklist
pre-commit run --all-filesor other linting tools are used to fix potential lint issues.