Skip to content

Support chunked prefill when radix cache is disabled - #811

Merged
Ying1123 merged 9 commits into
mainfrom
update-cache
Aug 1, 2024
Merged

Ying1123 merged 9 commits into
mainfrom
update-cache

Conversation

@hnyls2002

Copy link
Copy Markdown
Collaborator

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

Make cache an abstract class, which is more convenient for other types of caches than radix cache.

Modification

  • abstraction
  • chunked prefill cache

Checklist

  1. Ensure pre-commit pre-commit run --all-files or other linting tools are used to fix potential lint issues.
  2. Confirm that modifications are covered by complete unit tests. If not, please add more unit tests for correctness.
  3. Modify documentation as needed, such as docstrings or example tutorials.

@hnyls2002 hnyls2002 changed the title Cache refactor Support chunked prefill when radix cache is disabled Jul 31, 2024
@hnyls2002
hnyls2002 requested a review from Ying1123 August 1, 2024 07:25
@Ying1123
Ying1123 merged commit c020f9c into main Aug 1, 2024
@Ying1123
Ying1123 deleted the update-cache branch August 1, 2024 07:29
@Ying1123 Ying1123 mentioned this pull request Aug 1, 2024
15 of 29 tasks
timethink pushed a commit to timethink/sglang that referenced this pull request Mar 9, 2025
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 27, 2026
…he pin's door is on the prefill path

CHECKED BEFORE BUILDING, as ordered, and the check changed the answer.
NOTE_888b §5 recorded "pin release ABSENT" for the mamba anchor pin, taking
NOTE_773's deferral at its word. That was wrong in the safe direction, and my
own sgl-project#902 row inherited it verbatim.

WHAT IS ACTUALLY ON THIS BASE. sgl-project#755's reorder release EXISTS:
`UnifiedRadixCache._mamba_anchor_early_release` (:1022), guarded by
`MambaComponent.anchor_release_admissible` (:564) -- which requires the host
copy to have LANDED (`host_value` present AND the node absent from
`ongoing_write_through`), not merely to have been intended. That guard is
precisely the dead-anchor case sgl-project#767 documents, and it is already built.

WHAT IS NOT. Its ONLY call site is `cache_unfinished_req` (:1173), which runs
while prefill batches are built. So the door lives on the PREFILL path, and
finish releases the pin with everything else the request holds. Under strict
purity the TP window forbids prefill and the seam RETRACTS rather than
finishes -- so in the TP layout no door opens at all.

sgl-project#811 IS THE LAYOUT-INDEPENDENT DOOR AND IS NOT HERE. `[sgl-project#811] Release the mamba
admission anchor pin at the write-through ack`, 14606c6 on
`fix/811-admission-pin-ack-release`, cut from integ/round7 @ a2a47b4. That
parent IS in this base's ancestry; the sgl-project#811 commit is NOT, and its metal proof
is still the open W-811 window ticket. So the honest outcome is neither "just
declare it reachable" nor a duplicate build: the row is corrected to the doors
that exist, and the finding SHARPENS from "no door" to "no door THIS layout
can open".

`gated_by`, AND THE CHECK READS IT. The prefill door sits behind
`mamba_slot_reorder_active` -- three conditions, any of which turns it off. A
door behind an unarmed flag is SHUT, so the condition is a field rather than a
sentence, and `release_path_conformance` emits a third verdict, CONDITIONAL,
naming the gate. Adding a field the check ignored would have been the exact
defect this file exists to prevent, one commit after I wrote that down.

FINDINGS NOW, both true and neither new work:
  pp:  CONDITIONAL mamba_anchor_pin -- prefill door, only while the reorder
       flag is armed
       UNREACHABLE kvso_host_region
  tp:  UNREACHABLE mamba_anchor_pin -- strict purity forbids its only path
       UNREACHABLE kvso_host_region

TEST RESULTS (desk, CUDA_VISIBLE_DEVICES=""):
 * test_release_path_declarations_902.py -- 8 passed. The pin arm now asserts
   the CORRECTED truth in both layouts (conditional in pp, unreachable in tp)
   rather than the inherited "undeclared", and every declared symbol still
   resolves.
 * REGRESSION: participants / 859 / 773 / 755 suites plus this one -- 61
   passed, 0 failed.
 * ruff clean on both touched files.

STILL OPEN, and it is the next slice: kvso_host_region. Unchanged by this
commit -- finish/abort only, no layout reaches it.
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 27, 2026
…freed at park commit

CHECKED BEFORE BUILDING, and for the second time in this ticket the check
changed the answer. NOTE_888b §5 recorded the kvso host region as "finish/
abort paths ONLY. A parked session holds its host region for its whole life",
and my row inherited it verbatim. Both halves are false on this base.

THE REGION IS RELEASED AT PARK COMMIT. `_commit_park`
(kv_session_spill_destination.py:1459-1464):

    mgr._free_regions.append(slot.region)
    mgr.backend._sess_close_slot(t.rpi)

and `_release_parked_req`'s own docstring says so in as many words -- it
"mirrors release_finished_spilled_req MINUS the region/backend-slot part
(already released at park commit)". §5's sweep read the two finish/abort
release sites and did not reach the park-commit one.

AND ITS PATH IS REACHABLE FROM BOTH LAYOUTS. The park flow runs in
`KVSessionOffloadManager.pre_schedule` (kv_session_offload.py:4791), called
from `Scheduler.get_next_batch_to_run` (scheduler.py:6972) -- the per-round
batch builder, gated by neither decode nor prefill. What a parked session
still holds is the SpillSlot payload (kept WHOLE so unparking "just reattaches
a region"), whose door is `_release_parked_req` on that same per-round path.

SO THERE WAS NOTHING TO BUILD. The ticket's option was "build a
layout-reachable release path"; one exists, and building a second would have
been a duplicate actuator on a path that already has one. The #888b relief
pattern's own discipline is that the binder is NAMED FROM MEASUREMENT and
never assumed -- and I had no measurement showing this region binds anything.
Building anyway would have violated the pattern I was told to follow, on a
path whose danger direction is use-after-free.

BOTH OF sgl-project#902's FINDINGS WERE INHERITED PROSE, and that is the ticket's real
result. The check did its job precisely by being wrong in a way the desk could
find: it printed two claims, both were checked, both were corrected at
file:line, and neither cost a window. A note that says "held with no door" is
not evidence; it is a hypothesis that had never been asked to resolve a
symbol.

TESTS RESTRUCTURED ONTO A SYNTHETIC POPULATION. The rule arms (UNREACHABLE,
UNDECLARED, "the declaration is consulted") now own the rows they judge. A
rule test that depends on the live population still containing a defect stops
testing the rule the moment someone fixes one -- which is exactly what just
happened, twice. One arm still asserts the LIVE verdict on purpose, as a
record of what the scheduler says today; if a later commit clears it, that is
the assertion that should fail and be updated with its reason.

FINDINGS NOW:
  pp:  CONDITIONAL mamba_anchor_pin -- prefill door, only while the sgl-project#755
       reorder flag is armed
  tp:  UNREACHABLE mamba_anchor_pin -- strict purity forbids its only path;
       sgl-project#811 adds the layout-independent door and is not in this ancestry
  kvso_host_region: no finding. Released at park commit, per-round path.

TEST RESULTS (desk, CUDA_VISIBLE_DEVICES=""):
 * test_release_path_declarations_902.py -- 9 passed.
 * MUTATION: M1 the declaration is never checked -> 6 failed; M2 `gated_by` is
   never read (the field-nobody-reads defect, added in the previous commit and
   now pinned) -> 1 failed; M3 finish/abort treated as reachable -> 3 failed;
   restored 9 passed.
 * REGRESSION: participants / 859 / 888 / spill / session suites plus this one
   -- 280 passed, 3 subtests, 0 failed.
 * ruff clean on both touched files.

WHAT IS ACTUALLY LEFT: one finding, the mamba anchor pin in the TP window, and
its fix is already written on `fix/811-admission-pin-ack-release` awaiting the
W-811 metal proof. sgl-project#902's job -- make the class evaluable instead of hunted --
is done; the remaining instance has an owner and a ticket.
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 31, 2026
…ilt 2026-08-24, never shipped

CHERRY-PICK OF 14606c6, unchanged apart from one trivial conflict.

WHY IT IS HERE NOW. The sgl-project#1050 forensics found this commit while running the
prior-art gate on its own fix route, and found it in the state the fork keeps
producing: BUILT, hermetically green (16 tests + 4 subtests, 5 mutants killed),
flag-gated so it is byte-identical when off -- and NOT AN ANCESTOR of the
shipping pin. `git merge-base --is-ancestor 14606c6 38c6f28` says no; it
lived only on fix/811-admission-pin-ack-release and fix/849-census-resident-line.
It has stood in WINDOW-QUEUE.md as TICKET W-811 since 2026-08-30 waiting for a
metal proof it never got, because as a pure capacity optimisation it had no
symptom to be measured against.

It has one now. Boot 17 and boot 18 died with `leaked_mamba_pages` of 4 slots
out of 20 beside the full-pool loss -- {13, 3, 5, 14} and {19, 18, 11, 12} --
i.e. exactly the population whose release this commit moves from "finish" to
"write-through ack". So this boot IS the W-811 metal probe, and
`leaked_mamba_pages = 0` is its acceptance criterion.

CONFLICT: one hunk, both sides adding an attribute in `__init__`
(`_chunk_publish_n` from sgl-project#1028 here, `_anchor_ack_release_armed_cached` from
sgl-project#811). Both kept; no semantic overlap.

CHECK, matched to a merge rather than to a new edit: the commit's OWN existing
suite re-run on the merge result -- 16 passed, 4 subtests passed. Not a new
battery; the point of a merge check is that the shipped proof still holds after
seven days of line movement.

NOTE ON HOW IT WAS RUN, because the first run was a FALSE RED: without
PYTHONPATH=<worktree>/python, pytest imported sglang from the serving tree
(/spinning/htsglang-gpu) instead of this worktree and died in collection. A
worktree test that does not set PYTHONPATH is measuring another tree.

The flag stays as designed (`--mamba-anchor-ack-release`, off by default,
planner-emitted, no environment form). Arming it is the launcher's business,
declared per boot.
efschu pushed a commit to efschu/htsglang that referenced this pull request Sep 26, 2026
…e (L(n) - n x 5 statt 38 - 30), der Budget-Check steht vor dem eigenen Pin statt ueber der Eltern-Rekursion, mamba usage rechnet gegen die erreichbaren Slots

Befund (Desk, Baum 192ae05): H95c begrenzt den Mamba-Allocator einer
D-Phase mit n < --d-bs Sitzen auf die Slots 1..L(n) (NF: 38 Slots bei --d-bs 6,
also 7/13/19/25/32/38) und laesst hoechstens n laufende Requests zu
(d_seat_vram.admission_cap). Das sgl-project#581-Pin-Budget (Boden = laufende Menge,
Budget = Pool minus Boden, damit die Zusage unabhaengig vom Ack-Abfluss gilt)
wurde einmal aus dem Boot-Pool und --max-running-requests berechnet und
gecacht: unified_radix_cache._mamba_pin_budget und
hi_mamba_radix_cache._mamba_pin_budget, Metall 'MAMBA-FLOOR pool=38 floor=30
retention_budget=8 (6 x (1 active + 2 ping-pong + 1 donation + 1 pinned
checkpoint))' (fnFL2h91bb2 D-Log Z. 7746). In der n=1-Phase ist das Budget (8)
groesser als jeder erreichbare Slot (7): Write-Through-Pins duerfen alle
halten. Die Garantie Boden + Budget <= Pool bricht fuer n=1..5
(L(n) - 5n = 2/3/4/5/7 < 8).

Erreichbarkeit auf der NF-D-Form (write_back, sgl-project#811 aus): Pins entstehen auf D
nur durch erzwungene Write-Throughs (d_park_runtime.park_running setzt
force_host_write_through, das Attribut wird nie zurueckgesetzt, also auch beim
Finish eines aus dem Park fortgesetzten Requests) und den Flush-Sweep bei
leerer laufender Menge. Solange die Pins von einem Request stammen, der die
laufende Menge verlassen hat, reicht es fuer n>=2 knapp (n=2: 13 - 7 = 6 >= 5).
Der Weg, der NICHT reicht: Flip-Park (erzwungene Pins auf der Kette des
Requests) + awake-Requeue derselben Population (SGLANG_WEG2_D_PARK_AWAKE_
REQUEUE_S, 30 s), solange Acks offen sind. Bei n=1 bis zu 5 Pins (Kette:
Anker + Lock-Knoten + gecachte Checkpoints, die 2 Ping-Pong-Slots frei), der
Request braucht 3 neue (active + 2 ping-pong) von 7 - 5 = 2 -> der COW der
Wiederaufnahme scheitert -> zero_match_result, volles Re-Prefill (oder
MambaLoadBackUnservable -> load_back False). Drain-abhaengig, genau das, was
das Budget ausschliessen soll.

Zweites Loch: write_backup fragt das Budget VOR der Eltern-Rekursion und pinnt
danach; eine erzwungene Einfuegung ueber k ungesicherte Checkpoints bestand k
Pruefungen beim selben Stand und nahm k Pins (auch in der Cap-Form ueber 8).

Nebenbefund: pool_stats_observer zaehlte die zurueckgehaltenen Slots als
belegt -- n=1 im Leerlauf 'mamba usage: 0.82' (31/38), mit einem laufenden
Request 0.92 (35/38). Auf D ist der Prefill-Delayer aus, betroffen sind die
Log-Zeilen und die Gauges mamba_usage/mamba_used_tokens.

Fix (kein Schalter, keine Kollektive, rang-einheitlich: Limit und n kommen
aus dem Wake-Request, der Boden aus server_args):
- allocator/mamba.py: set_phase_limit(limit, seats=None) haelt die Sitzzahl
  der Phase (phase_seats); ohne Limit None.
- d_seat_vram.on_wake uebergibt seats=target.
- mamba_pool_floor.mamba_phase_pin_budget: ohne Limit = mamba_retention_pin_
  budget wie bisher, mit Limit = L - hard_floor(min(n, mrr)). NF: 2/3/4/5/7/8.
  Limit ohne Sitzzahl rechnet mit --max-running-requests (kleineres Budget).
- unified/hi_mamba _mamba_pin_budget: Cache je (phase_limit, phase_seats),
  neu berechnet bei jedem Wake, der sie aendert.
- unified_radix_cache.write_backup: nach der Eltern-Rekursion wird das Budget
  vor dem eigenen Pin erneut gefragt; Ablehnung laesst den Elter gesichert und
  den Knoten dem Publish-Sweep ('mamba_pin').
- pool_stats_observer: mamba_num_used/mamba_usage gegen size -
  phase_withheld_slots (der Mamba-Zwilling von residency_withheld); ohne
  Limit byte-gleich.

Kosten: in kleinen Phasen serialisiert das Budget die Pins eines Parks
(n=1: 2 in flight); der sgl-project#1470-Flush-Sweep schleift mit writing_check
zwischen den Runden bis unbacked == 0, Budget >= 2 in jeder Phase haelt ihn
in Bewegung.

Tests (CPU, echter Allocator/Cache/Pool, incg.sh):
test/registered/unit/weg2/test_weg2_d_seat_pin_budget_h95e.py (9): auf
192ae05 6 rot -- n=1 'the running request was starved of a slot (7 of 7
reachable slots pinned)', Budget 8 != 2, Rekursion 'went on to its transfer
and pin past the budget', mamba_num_used 31 != 0 und 35 != 4 --, n=6 und der
verweigerte Limit-Fall gruen auf beiden; mit Fix 9/9 gruen.
Betroffene Suiten (16 Dateien: h95c, h95d, mamba_pool_floor, from_floor_773,
pin_budget_live_773, reorder_unified_773, anchor_ack_release_811,
lock_ref_pairing_581, form_a_host_shadow_r12, write_backup_l3_parent_x20,
host_tier_contiguous_backup_841, staging_write_ring_810, anchor_aliasing_924,
double_free_924, pool_invariant_double_owned_912, idle_census_1262): Basis
256 gruen / 11 rot, Fix 256 gruen / 11 rot, dieselben 11 Knoten (924
double-free x5, 810 staging ring x6), 0 neu.
efschu pushed a commit to efschu/htsglang that referenced this pull request Oct 18, 2026
…ervice, and the chain consumes the GROUP's hold (SOLL R11, R2)

Review nf-review-s42-1018.

A2 -- the pass's per-iteration HiCache service (check_hicache_events: write-through/load acks and the
drain_storage_control_queues agreement; sgl-project#811 anchor-pin release; 24c placement eviction) sat in
_get_new_batch_prefill_raw under a comment "every rank reaches this point each iteration". A DQH-held
iteration does not reach the pass, and since S42 DQH holds every pass that built nothing while requests wait
-- so on the rc11 14:13 shape this service ran on 1 iteration in 17: the very rank-local room a held queue
waits for drained 17x slower, and on a divergent DQH iteration only the evaluating rank entered the drain
agreement. Moved verbatim into Scheduler._hicache_iteration_service; the pass calls it (through the class, so
its namespace test doubles keep working), the DQH-held branch calls it too, plus the deferred-prefetch retry
the pass runs right after it. Once per iteration on every rank, held or not.

A3 -- a14cf04 claimed "a rank that holds alone only delays the head, same collective count". True for the
budget-site reduce, false for the pass: on an ABSENT group match the X gate ABSTAINS (it does not refuse,
scheduler _weg2_x_refuses), weg2_uncached_extent falls back to rank-local terms, and add_one_req reaches the
Form A per-candidate verdict gather (_form_a_admission_follow_fn -> _form_a_tp_gather, token cut = exactly the
mode DQH runs in) on the lone evaluating rank only -- a collective split and a rank-local admission. The hold
now rides the existing packed MIN reduce as an (x, -x) pair (no new collective, before the tail-indexed
ballot, own head index): the chain consumes MAX(hold) -- held when ANY rank held -- and on a split every rank
disarms DQH, so the next iteration evaluates jointly on a measured vote (named WARNING "S42r DQH GROUP-SPLIT").

Tests: test_weg2_s42_head_vote_hold_1018.py + d_head_hold_int18 + rank_gleichheit_1537b: 54 passed
(new A2/A3 tests red on a14cf04; the builder's lone-hold test now asserts [True, True, True] instead of
[True, False, True]). Mutants 15/15 killed (new S7 held branch skips the service; R3 chain consumes the local
hold; R4 a split does not disarm). Neighbour suites: 100 files touching the budget site, ballot, enforcer,
DQH, check_hicache_events, anchor pins, d_kv_evict, _get_new_batch_prefill_raw, in 4-GiB chunks: failure set
a subset of a14cf04's (pre-existing stub drift), new red 0. No boot, no GPU.
efschu pushed a commit to efschu/htsglang that referenced this pull request Oct 18, 2026
…ervice, and the chain consumes the GROUP's hold (SOLL R11, R2)

Review nf-review-s42-1018.

A2 -- the pass's per-iteration HiCache service (check_hicache_events: write-through/load acks and the
drain_storage_control_queues agreement; sgl-project#811 anchor-pin release; 24c placement eviction) sat in
_get_new_batch_prefill_raw under a comment "every rank reaches this point each iteration". A DQH-held
iteration does not reach the pass, and since S42 DQH holds every pass that built nothing while requests wait
-- so on the rc11 14:13 shape this service ran on 1 iteration in 17: the very rank-local room a held queue
waits for drained 17x slower, and on a divergent DQH iteration only the evaluating rank entered the drain
agreement. Moved verbatim into Scheduler._hicache_iteration_service; the pass calls it (through the class, so
its namespace test doubles keep working), the DQH-held branch calls it too, plus the deferred-prefetch retry
the pass runs right after it. Once per iteration on every rank, held or not.

A3 -- a14cf04 claimed "a rank that holds alone only delays the head, same collective count". True for the
budget-site reduce, false for the pass: on an ABSENT group match the X gate ABSTAINS (it does not refuse,
scheduler _pdflip_x_refuses), pdflip_uncached_extent falls back to rank-local terms, and add_one_req reaches the
Form A per-candidate verdict gather (_form_a_admission_follow_fn -> _form_a_tp_gather, token cut = exactly the
mode DQH runs in) on the lone evaluating rank only -- a collective split and a rank-local admission. The hold
now rides the existing packed MIN reduce as an (x, -x) pair (no new collective, before the tail-indexed
ballot, own head index): the chain consumes MAX(hold) -- held when ANY rank held -- and on a split every rank
disarms DQH, so the next iteration evaluates jointly on a measured vote (named WARNING "S42r DQH GROUP-SPLIT").

Tests: test_pdflip_s42_head_vote_hold_1018.py + d_head_hold_int18 + rank_gleichheit_1537b: 54 passed
(new A2/A3 tests red on a14cf04; the builder's lone-hold test now asserts [True, True, True] instead of
[True, False, True]). Mutants 15/15 killed (new S7 held branch skips the service; R3 chain consumes the local
hold; R4 a split does not disarm). Neighbour suites: 100 files touching the budget site, ballot, enforcer,
DQH, check_hicache_events, anchor pins, d_kv_evict, _get_new_batch_prefill_raw, in 4-GiB chunks: failure set
a subset of a14cf04's (pre-existing stub drift), new red 0. No boot, no GPU.
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.

2 participants