Skip to content

Reduce the overhead when cache is disabled - #1010

Merged
hnyls2002 merged 4 commits into
mainfrom
overhead-reduce-cache
Aug 9, 2024
Merged

hnyls2002 merged 4 commits into
mainfrom
overhead-reduce-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

Even if the cache is disabled, there is a loop to iterate every request in the waiting queue.

Modification

Remove this loop, only do this when the mode is lpm or dfs-weight.

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 merged commit 62757db into main Aug 9, 2024
@hnyls2002
hnyls2002 deleted the overhead-reduce-cache branch August 9, 2024 23:36
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 29, 2026
…n it

sgl-project#1008 held correctly and boots 68 and 69 still starved. The request sits in
the running batch, the hold keeps it out of decode, and
_get_new_batch_prefill_raw declines at its very first gate --
`(running_batch.batch_is_full or len(self.waiting_queue) == 0) and
self.chunked_req is None` -- because the request has already left the waiting
queue. Held by one path, invisible to the other, and the instance dies idle on
the 120s ring budget holding a request it never ran. Both boots died that way,
and boot 69 died of it again after sgl-project#1009 had correctly stopped absence being
consumed as a result.

DELIBERATE DEVIATION, named as the standing order of 2026-08-29 requires. The
convention that a request in the running batch is no longer a prefill
candidate encodes "running means its prefill has run". That is true upstream,
where prefill and decode share a round. It is false for a PP request whose
result is still in flight, and following it here produces a request nobody
owns. So the convention is set aside at this one point rather than executed
into a starvation.

THE DOUBLE-ADMISSION ARGUMENT, which is what makes the re-queue legal against
the #968b prohibition: a request goes back only when NO microbatch slot still
holds it and it is not the chunked carry. It has just been filtered out of the
running batch, it is not in the waiting queue -- that is precisely why the
gate fired -- and no slot references it. No door leads to it at all, and the
queue is the only one left. Nothing is reset or truncated; it returns exactly
as it stands, so no executed prefix is recomputed (Kein-Doppel-Prefill).

The slot census is taken BEFORE the filter, because after it the batch no
longer names the requests being judged.

Counter is cumulative and says what a bad reading looks like: a total that
keeps growing for the same rid means the prefill still never completes, which
would be a different defect than the one this fixes.

Evidence: desk, executed. py_compile; the slot census precedes the candidate
selection, the candidate selection precedes the filter, and the re-queue
follows it. Belegstufe: DESK-BEWIESEN -- BOOT-BEWIESEN needs a served prefill.
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 30, 2026
…record why

REFUSED, with reasons, rather than bridged. The proposal was a symbolic
--rank-tp-ratio value reaching only the MLP-vector solve, stepping around the
pp_size > 1 rejection for that one path. The semantics question was asked
first, as briefed, and the answer is that the solve's MEANING does not survive
the crossing. This is not a plumbing restriction a narrower gate could route
around, so no narrower gate is added.

1. THE TWO HALVES OF THE SOLVE DISAGREE ABOUT THE INDEX under PP.
   uneven_perf.apply_auto_performance sizes its budget list as
   `[budgets] * server_args.tp_size` (uneven_perf.py:6633) and builds one rank
   score per entry of --rank-gpu-id (uneven_perf.py:6668). Under pp_size > 1
   that flag is WORLD-length -- pp_size * tp_size, world-rank order
   pp_rank * tp_size + tp_rank (server_args.py:11308). Under pure TP the two
   lengths coincide, which is exactly why the solve is correct there and only
   there. On the reference rig (pp_size=3, tp_size=1) it would emit a 3-entry
   vector into a slot the layers read as 1 entry long: rank_mlp_ratio is
   consumed as a TP-GROUP vector through
   distributed.utils.get_tp_partition_ratios("mlp") (utils.py:166-181, the
   resolver regime_runtime._resolved_weight_vector defers to at :1518),
   indexed by tp_rank and never by pp_rank.

2. UNDER PP THERE IS NO MLP TO SPLIT. Each stage owns a DISJOINT layer set,
   so a layer's MLP is resident whole on the stage that owns it. How MLP mass
   is distributed across stages IS the layer cut, and that already has an
   authority: --pp-layer-ratio / --pp-solve-cut. A per-PP-rank MLP vector
   would be a second authority for one payload.

3. ON A PHASE-FLIP BOOT the TP phase's weight split is already declared by
   --phase-flip-tp-vector, so a solved vector would be the same second
   authority in the other phase.

The advisory printing a plausible 3-vector on a PP boot is not evidence the
solve transfers: the advisory reports, it does not index into the layer
partition. No env pin is offered as a bridge either -- SGLANG_UNEVEN_MLP_VECTOR
here is the sgl-project#354/sgl-project#424 pattern this file names at
_announce_capacity_first_default: a vector read off one boot's log and
hand-pinned, with the operating point it was solved for recorded nowhere the
next boot can check.

Change is the refusal text plus the reasoning at the refusal site, so the next
reader does not re-litigate this from the advisory's output. The message now
names the authorities that DO decide the split under PP.

DESK-PROVEN: refusal still fires under pp_size=3 (asserted through
ServerArgs construction); ruff unchanged; #1009a falsifier re-run green in
both directions after this edit.
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 30, 2026
…s ~2x and breaks serving

d7c3736 (sgl-project#1015) was merged, booted, and REVERTED (a204832). It is not a
mis-scoped refactor -- it takes serving down.

MEASURED, boot_855_cons1_0840f82601_0830_073758 vs the same tree without it:

  TP-phase "weights + runtime state" (GiB)   before sgl-project#1015   with sgl-project#1015
    PP0                                          4.252        26.581
    PP1                                          2.719        14.788
    PP2                                          3.662        15.435
    sum                                         10.633        56.804

  The checkpoint is 27.5 GiB. sgl-project#1015 swung the post from under-booking (10.63,
  the defect I reported in sgl-project#1014) straight past correct to ~2x OVER-booking:
  56.8 GiB of weights charged for a 27.5 GiB model, i.e. roughly the WHOLE
  model on EVERY rank instead of that rank's shard.

  Consequence, same boot:
    TP-phase PP0 KV budget "rest"    24.195 GiB  ->   1.867 GiB
    EFFECTIVE max_total_num_tokens    615,434    ->   185,344   (-70 %)
    per-rank capacities         597210/448290/449378 -> 61152/57920/68724
    coherence probe (/generate, greedy, "capital of France")  -> NO RESPONSE

  The recalibrator then reacted to the collapsed capacities and moved the
  token vector [30,17,17] -> [21,20,23], which is correct behaviour on wrong
  inputs and would have written a garbage vector into the next boot's hint.

REVERT VERIFIED: a204832 restores TP world 615,434 and the probe answers
"Paris". One file, 60 lines
(model_executor/model_runner_kv_cache_mixin.py) -- so the runtime blast radius
of d7c3736 is exactly the weight post, which isolates the attribution.

WHAT I GOT WRONG AND SHOULD HAVE CAUGHT FIRST: I supplied the sgl-project#1014 diff that
motivated this fix, including the expected TP shard figures (~13.75/6.9/6.9
GiB from the 32,16,16 vector). I flagged at the time that I had NOT verified
whether the flip re-materialises weights or re-views the PP residency, and
that if it re-views them the "correct" TP post may legitimately be smaller
than shard arithmetic. That caveat turned out to be the whole question, and a
fix built on the arithmetic alone overshot. A boot-time falsifier -- assert
the summed TP weight post lies between the largest single rank shard and the
whole checkpoint -- would have caught this at the desk.

The rest of the planner chain (#1009a/sgl-project#1010/sgl-project#1018/sgl-project#1019) is NOT reverted: it
came in via cc70a6d and the earlier merges and is unaffected.

ALSO ON THIS BOOT, and it works: sgl-project#778 cold-post-spill (5379340) is live and
its markers fire on the real seam --
  "phase-release LEND pp_to_tp: 65536 rows (~1024 MiB)" on PP0,
  131072 rows (~1024 MiB) on PP1 and PP2 (row counts differ because the PP
  cell differs: 16384 B on PP0, 8192 B on PP1/PP2),
  "phase-release REPAY tp_to_pp: loan -> 0 rows" on all three before the
  prefill leg resumes.
REPAY reports "0 MiB returned" -- the dial had not yet grown into the credit
at that seam, so the repayment had nothing to hand back. That is the
convergence behaviour the author described, not a leak, but it means the
LEND's token effect is NOT yet demonstrated on metal and must not be counted
in any ladder until a boot under load shows the pool actually taking it.
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.

1 participant