Repository navigation
[Fix] dsv41: Size prefill indexer score tiles by memory in use to avoid OOM without shrinking them - #43376
Closed
ormandj wants to merge 3 commits into
Closed
[Fix] dsv41: Size prefill indexer score tiles by memory in use to avoid OOM without shrinking them#43376ormandj wants to merge 3 commits into
ormandj wants to merge 3 commits into
Conversation
ormandj
requested review from
BBuf,
DarkSharpness,
Fridge003,
HaiShaw,
HydraQYH,
Qiaolin-Yu,
celve,
hebiao064,
ispobock,
merrymercy and
yuan-luo
as code owners
October 9, 2026 12:48
17 of 56 tasks
ormandj
force-pushed
the
dsv41-indexer-prefill-tile-budget
branch
from
October 19, 2026 17:33
c653738 to
ca267bd
Compare
detain
added a commit
to detain/sglang
that referenced
this pull request
Oct 20, 2026
…indexer) + stack_want decisions - stack.txt: entries 1-2 (local) + Group A boot-critical indexer chain sgl-project#42371/sgl-project#42861/sgl-project#45261/sgl-project#42294/sgl-project#43008 (fe7be85..0dbd8c5). - stack_want.txt: consolidated decision set from 8 parallel evaluators + dsv41(422)/SM120(254) sweeps + sybil/qwen harvests. Records E verdict (merge only sgl-project#43376) and D verdict (merge only sgl-project#42368; sgl-project#33407/sgl-project#34717 dead on flashinfer 0.7.2).
detain
added a commit
to detain/sglang
that referenced
this pull request
Oct 20, 2026
… correctness) - core batch [10-15]: sgl-project#43376 long-ctx indexer OOM bound, sgl-project#42368 FlashInfer-0.7 decode dispatch, sgl-project#39914 extra-KV 64-token page split + candidate fallback, sgl-project#42714 graph-safe page-split buffers, sgl-project#32464 SM120 sparse-prefill test gate, sgl-project#34027 int32->int64 page-split overflow guard. - Group C [16-23]: sgl-project#42717 TP-rank verify-budget, sgl-project#43225/sgl-project#43374 compact-verify seq_lens + padding renorm, sgl-project#42718 packed-verify token->request map, sgl-project#42713 forced-uniform capture metadata, sgl-project#45301 padded-query graph lifetime, sgl-project#44141 bounded-replay guard, sgl-project#45185 V4.1-Flash-1017 FP8 QDQ (env-gated, default OFF). sgl-project#42710 skipped (superseded upstream: step_logits already fp32).
…count their scratch The ratio-1/2 prefill scorers allocate each logits tile (rows x the widest compressed context, fp32) outside every pool --mem-fraction-static sizes. A fixed 2 GiB tile, plus selection scratch it did not count, OOMed a chunk at a 485K-token context; sizing tiles from free memory instead (the first version of this change) avoided that but made the tiles depend on what the caching allocator happens to hold. On a long-running server that is nearly all of the device, so deep chunks fell to one-row-group tiles and prefill slowed by up to an order of magnitude. - The backend holds one pool per device for the tiles, sized at startup from the configured context, chunk size, index heads and the largest declared scratch, within the static budget (SGLANG_DSA_MQA_LOGITS_FREE_MEM_FRACTION of the share --mem-fraction-static leaves free) and the 2 GiB cap. - MqaLogitsPool takes that capacity once per stream into a private allocator pool, which the caching allocator keeps from other allocations and from empty_cache; tiles and their scratch are allocated there and sized by the capacity, not by free memory. Graph capture keeps the default allocator at the same size. - Tiles count their consumer's scratch: the dense-blocks publisher scores block-aligned and masks in place instead of padding a copy, and the sparse-table publisher frees each tile and its block keys before the next.
ormandj
force-pushed
the
dsv41-indexer-prefill-tile-budget
branch
from
October 29, 2026 21:51
ca267bd to
c28c12f
Compare
A score-tile pool held for the life of the server either comes out of the activation headroom, where it starves the MoE workspace (a 2 GiB pool OOMed warmup on 4x RTX PRO 6000 at --mem-fraction-static 0.85), or out of the KV pool, where at DeepSeek-V4.1's ~2 KB per cached token it costs about 500 tokens per MiB. The tiles are live only while their layer scores, so they should share memory with the rest of the forward. - score_tiles takes a budget for its rows and width: the static budget under graph capture, else SGLANG_DSA_MQA_LOGITS_FREE_MEM_FRACTION of free memory, at most 2 GiB. When that reads below the cap, the allocator's unused blocks are returned (empty_cache) and free memory is read again, so the budget follows memory in use, not memory the caching allocator happens to hold. - MqaLogitsPool and the backend's pool sizing are removed.
Emptying the cache before every deep prefill forward cost about 25 ms per 8K chunk on an idle server, whose free memory already gives large tiles. Read free memory again only when the first reading leaves fewer than 256 rows of the forward's widest score row per tile.
ormandj
added a commit
to ormandj/sglang-deepseek-v41-flash-sm120
that referenced
this pull request
Oct 30, 2026
…l fix SGLang main 974831643f with 29 patches (15, 28 and 32 dropped: now upstream or superseded), FlashInfer main 453a7e2450 with fi-01, sgl-project DeepGEMM v0.2.3.post2 and Triton release/3.8.x with tr-01, on the lmsysorg/sglang CUDA 13 nightly of 2026-10-29. Every carried pull request is refreshed on main. Patch 24 (sgl-project/sglang#43376) sizes the prefill indexer's score tiles by memory in use: free memory alone left out the caching allocator's unused blocks, so on a running server deep chunks fell to tiles of a few rows and cold prefill slowed to about 1K tok/s at 300K tokens of depth.
ormandj
added a commit
to ormandj/sglang-deepseek-v41-flash-sm120
that referenced
this pull request
Oct 30, 2026
ormandj
added a commit
to ormandj/sglang-deepseek-v41-flash-sm120
that referenced
this pull request
Oct 30, 2026
…small tiles Patch 24 (sgl-project/sglang#43376 at b7b433967d) empties the caching allocator's cache only when free memory alone would leave score tiles of fewer than 256 rows; rc.1 did it on every deep prefill forward (about 25 ms per idle 8K chunk). Same stack key.
4 of 5 tasks
Contributor
|
Thanks @ormandj. Closing this because you have 25 PRs open and none updated in 7 days, over our soft cap of 5 for idle PRs. Reopen the two or three you most want reviewed - a short active set moves faster than a long idle one. Some directories moved recently, so an older branch may need retargeting: |
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
The DeepSeek-V4.1 ratio-1/2 index layers score every prefill row against the whole compressed context with DeepGEMM
fp8_fp4_mqa_logits, in row tiles (score_tiles/flat_index_logits_tiles). Each tile isrows x max compressed contextfp32, allocated through the caching allocator outside every pool sized by--mem-fraction-static._DEEP_GEMM_SCORE_BUDGET_BYTES), and it counted only the logits: the dense-blocks publisher also allocates a bool causal mask,select_candidate_block_idspadded an unaligned context (F.pad) into a full fp32 copy of the tile, and the sparse-table publisher kept the previous tile and its block keys alive while the next was allocated. At 485K a 2 GiB tile peaked at about 4.2 GiB. On 4x RTX PRO 6000 Blackwell (SM120, about 95 GiB each), TP4,--mem-fraction-static 0.85, chunked prefill 8192, a conversation with about 485K cached tokens growing by small chunks OOMed in_publish_prefill_blocks -> score_tiles -> fp8_fp4_mqa_logits(2.00 GiB requested, 1.98 GiB free).mem_get_infofree memory (SGLANG_DSA_MQA_LOGITS_FREE_MEM_FRACTIONof it) avoids the OOM but leaves out the caching allocator's unused blocks. A long-running server's allocator ends up holding nearly all free memory (measured on the setup above: 0.05 GiB free to the driver, 91.9 GiB reserved, 83.0 GiB allocated), so the budget falls to about 10 MiB and deep chunks run in one-row-group tiles (4 rows at 32 index heads), thousands of DeepGEMM calls per chunk. In production this showed as cold prefill decaying chunk by chunk to about 1K tok/s past 300K tokens of depth.Related: #40967, #31704 (both closed), #39095.
Modifications
scoring.prefill_score_budget_bytes, read byscore_tilesfor its rows and width: the static budget (capped at 2 GiB) under model capture mode, stream capture or torch.compile piecewise graphs, without a device query; otherwisemqa_logits_budget_bytes(the free-memory fraction), capped at 2 GiB. When that first reading would leave fewer than 256 rows of the forward's widest score row per tile, it callstorch.cuda.empty_cache()and reads again, so the budget follows the memory in use rather than what the allocator happens to cache; an idle server's free memory already gives large tiles and skips the extra read. Forwards belowMQA_LOGITS_STATIC_SKIP_ELEMStake the cap without a query. Breakable-graph replay runs these layers eagerly and takes the free-memory budget.flat_index_logits_rows_per_tile/flat_index_logits_tiles/score_tilestake the caller's scratch as bytes a row and bytes a tile. A tile takes all rows when their aligned allocation (rows aligned to the kernel's row group128 // heads, row stride aligned to 256 fp32) plus that scratch fits the budget; otherwise row-group multiples, with one row group as the floor.FLAT_LOGITS_WIDTH_ALIGN(64) columns aligned, whichblock_sizemust divide; it passeslogits[rows, :ceil(lc / block_size) * block_size]toselect_candidate_block_idsand masks padding columns to-infin place, so it no longer pads a copy. It declares the mask, block maxima and block top-k as row scratch and one request's int64 index vector as tile scratch. The dense-blocks consumer declarestopk_among_blocks's candidate gather, masks and picks as row scratch.A fixed score-tile pool held for the server's lifetime was implemented and measured on the setup above, then dropped: held from the activation headroom it left the FlashInfer MoE workspace too little memory (warmup OOM, 942 MiB requested with 808 MiB free), and held from the KV pool it costs about 500 cached tokens per MiB at DeepSeek-V4.1's KV size. The tiles are live only while their layer scores, so they share memory with the rest of the forward.
Accuracy Tests
CPU test
test/registered/unit/layers/test_dsv41_prefill_score_tiles.pyreplaces DeepGEMM and the ragged top-k with exact references and covers allocation alignment and scratch, tiled selection parity at every tile size down to one row group, tile lifetimes, the budget (no reclaim with ample memory or enough rows per tile, oneempty_cacheand a second read when the first is low, the static budget without a query under each capture state, the query under breakable-graph replay, no query for small forwards) and thatscore_tilessizes tiles by the budget for its own rows and width.GPU tests in
test/registered/kernels/ops/attention/test_dense_prefill_indexer.py(SM100 and SM120), at a 485,123-entry compressed context:On this head, rebased onto main
974831643f:test_dsv41_prefill_score_tiles.pypasses (12 tests), and the neighboring DSv4/V4.1 CPU suites (test_dsa_mqa_logits_chunking.py,test_dsv41_candidate_blocks.py,test_dsv41_late_layer_tail_readers.py,test_dsv4_nonpaged_indexer.py,test_dsv4_compressed_pools.py, the DSv4.1 draft/verify metadata glue tests,test_encoder_swa_replay.py) pass, 113 passed and 1 skipped in total. The GPU test file has not yet been run on this head.The OOM scenario: on the setup above, with this change, one cold 491,520-token prompt followed by 12 turns that each resend the history plus 2,000 new tokens (prefix-cached, up to 515,520 tokens), with 8 other requests decoding and the allocator holding all but 50 MiB, ran without an OOM or restart (0.43 to 0.45 s per turn).
Speed Tests and Profiling
DeepSeek-V4.1-Flash on 4x RTX PRO 6000 Blackwell Max-Q (250 W), TP4/EP2, FP8 KV, chunked prefill 8192,
--mem-fraction-static 0.85, DSpark. The same image and server process configuration with only the budget changed (these two files applied to the SGLang tree of that image, which carries the first version of this PR), one cold prompt of whole 8K chunks per cell, prompt tokens per second over the whole request. "This change" was measured at the previous revision, which emptied the cache whenever the first reading was below the 2 GiB cap; that cost about 25 ms per idle 8K chunk (the idle cells), which the 256-row threshold of the current head removes:At about 460K tokens of depth with the allocator holding all but 50 MiB, an 8K chunk took 5.4 s with a 9 MiB budget (8-row tiles, 1,024 per scorer) and 0.69 s with this change (1.48 GiB budget, about 1,660 rows per tile); idle it took 0.68 s. The idle cells are single runs; their 3 to 4% difference is within this setup's run-to-run spread. The "all but 50 MiB" cells park the rest of the free memory in the caching allocator's cache, the state of the production server where the slowdown was found (26 to 136 MiB free to the driver per GPU).
Checklist
Review and Merge Process
/tag-and-rerun-ci,/tag-run-ci-label,/rerun-failed-ciDeveloped with AI assistance.
CI States
Latest PR Test (Base): ❌ Run #40972559104
Latest PR Test (Extra): ❌ Run #40972559177
Latest PR Test (AMD ROCm 10): ❌ Run #40972559088