Skip to content

Mixed style of chunked prefill - #1013

Merged
merrymercy merged 23 commits into
mainfrom
mix-chunk
Aug 16, 2024
Merged

merrymercy merged 23 commits into
mainfrom
mix-chunk

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

This is to reduce the first token latency.

Modification

When mixed style is turned on, try to fill some prefill tokens into the running batch.

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 marked this pull request as draft August 10, 2024 19:00
@merrymercy
merrymercy marked this pull request as ready for review August 13, 2024 09:31
@zhyncs zhyncs added enhancement New feature or request high priority labels Aug 13, 2024
@merrymercy

Copy link
Copy Markdown
Collaborator

Can you resolve the conflicts?

Comment thread python/sglang/srt/server_args.py Resolved
@merrymercy
merrymercy enabled auto-merge (squash) August 16, 2024 08:53
@merrymercy
merrymercy merged commit 3694f8f into main Aug 16, 2024
@merrymercy
merrymercy deleted the mix-chunk branch August 16, 2024 09:13
hnyls2002 added a commit to yichuan-w/sglang that referenced this pull request Aug 16, 2024
@merrymercy merrymercy mentioned this pull request Aug 27, 2024
15 of 29 tasks
timethink pushed a commit to timethink/sglang that referenced this pull request Mar 9, 2025
shun8686 pushed a commit to shun8686/sglang that referenced this pull request Jul 25, 2026
…d-difficulty

test: port retract_decode (extend), scheduler_control and weight_checker_e2e to NPU
efschu pushed a commit to efschu/htsglang that referenced this pull request Aug 30, 2026
ROOT, corrected against the handover's framing. The handover read the store
census as "15457 KV pages vs 11 mamba anchors = grid behaviour" and ordered
the anchors published at every write-through. Measured on the same boot
(boot_855_1028fence), that premise is a PAGE-vs-NODE denominator mix and the
ordered fix is already in place:

  * `#969H BACKUP` = 33 lines = n=1..11 on EACH of PP0/PP1/PP2 at identical
    timestamps. The probe logs every call up to n<=40, so 11 lines means
    `write_backup` reached its component loop exactly 11 times per rank in the
    whole run -- and all 11 carried `mamba_value=has_value`.
    => mamba coverage OF THE HOST-BACKUP PATH is 11/11 = 100%, not 11/15457.
  * All 11 `.mamba` hashes in the store are also full-KV page hashes
    (intersection 11, mamba-only 0): one anchor per node at a real page
    boundary, shared key namespace.
  * The 15457 KV pages are the PAGES of those same 11 nodes:
    `write_backup_storage` writes `keys=node.hash_value` (every page of the
    node) while the mamba branch writes `keys=[node.hash_value[-1]]` (one
    trailing page).

The real hole is one link earlier and is not mamba-specific: `_inc_hit_count`
returns before any backup when `chunked=True` (upstream's "skip the hit count
update for chunked requests"). Under chunked prefill NOTHING is published per
chunk -- so the 11 backups are the 11 FINISHED requests, and a chunked prefill
that never finishes publishes nothing at all.

That is why the 13179-token prompt found its deepest anchor at 3072 and
recomputed the remaining 10107 tokens: the anchors are as dense as finished
requests, not as dense as chunks.

FIX: allow a chunked-prefill node to reach the host tier, gated structurally
on (storage tier present AND a MAMBA component present). The per-chunk node
already carries a donated state on the device
(`MambaComponent.prepare_for_caching_req`, is_finished=False branch); this
early return was the only reason it never reached host or storage.

UPSTREAM-MINIMAL: the chunked skip IS upstream (`hiradix_cache.py`), so this
is a DEVIATION and carries its burden of proof. Named: (1) drain-and-flip --
a chunked prefill interrupted by a flip never reaches `cache_finished_req`
(sgl-project#856 removed the carry, the flip DISCARDS it), so upstream's publish-at-finish
never fires; (2) GDN hybrid -- a recurrent state is valid at exactly one token
position, so the per-chunk anchor has no pure-attention analogue. Gate off =
byte-identical to upstream (verified: branch truth table, 0 mismatches over
all 8 chunked/write_back/force combinations).

LAWS: `mamba-per-knoten-nicht-gitter` in its own words ("states per radix
node/chunk like KV pages"), and it waives write volume explicitly.
`kein-doppel-prefill` (sgl-project#939): loss bound becomes ONE chunk.

sgl-project#968 PP0 DEBT -- WHERE THIS PATH STAYS RANK-LOCAL: the publish decision is
taken at the scheduler's chunk boundary, which every rank runs for the same
request at the same split, so it is unanimous BY CONSTRUCTION, not by
agreement; this path holds no reduce (the `check_prefetch_progress` MIN is
TP-scoped and the boot runs tp_size=1/pp_size=3, so it is structurally
skipped). `raenge-nie-uneins` is met by construction and `#1028P
CHUNK-PUBLISH` is how the claim gets CHECKED: identical n at identical
timestamps across ranks, the evidence shape `#969H` gave for the 11.
The one rank-local input reachable from here is the sgl-project#581/sgl-project#773 write-through
pin budget, which fired ZERO times in that boot (trap-safe: bare 0, genuine 0)
because 11 backups never approached it. Per-chunk publishing makes it
reachable for the first time; `pin_skipped` rides on the same line so a
nonzero count next to a divergent n is the divergence, named in advance.

COST, QUANTIFIED NOT BUILT: one `.mamba` blob is 78446592 B = 74.8 MiB
(measured, all 11 identical); a KV page is 32768 B. A published 4096-token
chunk therefore adds 74.8 MiB of anchor on top of 128 MiB of KV (+58% L3).
Host RAM is UNCHANGED -- the host mamba pool is pre-sized at boot from
`hicache_ratio` (1.5) x device slots, so anchors roll through a fixed tier and
land on disk. The int8-anchor idea (sgl-project#1013) would cut the 74.8 MiB and is
deliberately NOT built here.

ALSO: #1028B FETCH CAP instrument at the `min` in `hicache_storage.py`, the
cap that decides how much of an existing KV prefix a prefetch may claim. It
printed nothing: `final_pages`, `kv_pages`, `boundary=`, `hit_pages` each
occur 0 times in the whole 5.87 MB log, so "anchors too sparse" and "KV prefix
too short" produced the same number and were NOT separable from that boot.
Now both terms print on one line.

Desk checks (error-class matched): ruff F821/F811/F841/E9 clean on both
changed files (new names + new attribute reads); branch truth table executed,
gate-off equivalence exact. The gate is deliberately NOT memoised --
`enable_storage` is False at __init__ and only set in `init_hicache`, and a
memoised early False would leave a wired-but-inert write path, the sgl-project#742/sgl-project#745
class this area has produced before.

NOT YET BOOT-PROVEN. Acceptance is the next boot.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request high priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants