← Back to Pull requests

feat(sm120_dsa_indexer): DeepSeek-V4.1 candidate blocks and mixed-length scheduling for ragged prefill #10072

Closed
unknown closed this pull request without merging on Dec 01, 2026 23:52 UTC
View on GitHub
unknown unknown commented on Nov 26, 2026 22:11 UTC
Author

📌 Description

This PR extends the experimental SM120 DSA indexer (dsa_indexer_det_topk(..., backend="sm120"), ragged form) in three ways:

  • it supports DeepSeek-V4.1's candidate layers;

  • it schedules mixed-length and small prefill calls over every SM;

  • it speeds up the prefill scan.
  • Every decision that depends on row lengths is made on the device, so the launch sequence depends only on the shapes and the call is CUDA-graph safe. Results don't depend on the route or the schedule: they are bitwise identical across schedules, and the tests check this.

    Candidate blocks (DeepSeek-V4.1)

  • Source rows pass candidate_out and candidate_block_size (8 or 16). The RESIDENT and SCAN epilogues write each row's block maxima. A per-row selection then writes the row's candidate blocks into candidate_out, in no particular order.

  • Consumer rows pass candidate_blocks. Each row is masked to its listed blocks: a key in an unlisted block scores −inf, and the sample threshold counts only listed keys.

  • - A split consumer row too long for one selection CTA's registers, but with top-k to that many listed keys, is selected over its listed keys only. split_select_kernel moves them to the front of the row, guided by the row's block bitmap, and maps the selected positions back to keys.

    Both run in separate kernel instantiations (kSeg, kMask), so calls without candidates run the same code as before.

    Scheduling of the resident route

    Rows short enough for the resident route run as query blocks, one block per CTA, in length classes. Before this PR, a call whose blocks didn't fill whole waves left most SMs idle in its last partial wave. A class with few long blocks took one SM's latency per block, whatever the other SMs were doing.

  • One class, leftover blocks. The blocks past the whole waves may leave them. rows_kernel decides this on the device from a cost rule: the leftover's longest row, its block count, top-k and the SM count (split_min_keys, rest_min_keys). Leaving blocks are split over every SM (stream-K over their tiles), and their rows are selected by split_select_kernel, one CTA per row.

  • Several classes. split_plan_kernel runs after rows_kernel and splits any class with fewer blocks than SMs, by the same rule. All classes' remaining whole blocks run in one launch whose CTAs claim blocks from the plan's list, longest first. That list is in block order within 1024-key length buckets.

  • - The queue and the split classes run on per-thread side streams beside the scan. They do so only when the launch stream has the whole device, so never on a green context or partition.
  • Join through a counter. The waves count their CTAs' ends, and the split selection, the call's last launch, waits for that count. So a split launch with no block exits immediately instead of waiting at its exit.

  • - With whole waves, the waves let the split launch start early only when the leftover blocks leave. An early release otherwise slowed the waves' own last blocks.
    - With no whole wave, the split launch starts at once and waits for the waves' end.
  • Calibration. The cost rule's constants come from calls of equal blocks timed both ways (keep vs split) over block count, row length, format, head count and top-k. On that calibration grid the rule's mean regret is about 0.3 µs, against about 2.5 µs for always splitting.
  • Scan operands in registers

    The prefill SCAN kernel keeps operands that are fixed for a query block in registers for the whole block, instead of reloading them for every 128-key tile:

  • FP8: the B fragments.

  • FP4: the head weights, in addition to the fragments it already kept.
  • Scores are bit-identical. Only the four SCAN instantiations change.

    What stays the same

  • The base SAMPLE, EXACT and RESIDENT instantiations compile to the same SASS as main (compared per kernel, with parameter offsets normalized). Each new choice is a template parameter or lives in a separate instantiation.

  • The decode path is unchanged: its kernels' SASS matches main. Split rows use their own selection kernel (SplitSelParams), so the decode select_kernel and its parameters are as on main.
  • Fix: decode-scan stage refills

    The decode logits scan reads its Q and K stages with ldmatrix / ld.shared, then arrives on the empty barrier. The arrive doesn't order the generic-proxy reads against the TMA refill. The producer now issues a proxy fence after its empty-barrier wait, before each refill: one fence per refill rather than one per consumer warp.

    Performance

    Setup: RTX PRO 6000 Blackwell Server Edition (188 SMs). CUPTI kernel spans, cold L2, CUDA-graph replay, median µs.

  • Every comparison is a speedup: the other pipeline's time divided by this PR's. Above 1× this PR is faster.

  • vs main compares with this PR's base. vs best other compares with the fastest valid pipeline among DeepGEMM logits plus the vLLM, GVR, SGLang or FlashInfer top-k, and b12x.

  • Index sets are checked against DeepGEMM + vLLM; a pipeline whose sets differ beyond k-th ties is left out.

  • Each grid ran in one pass on one GPU. The regressions below were reproduced in alternating runs on one idle GPU.
  • Prefill grid, indices only. T query rows over C cached keys, causal; 76 cells per format (32 and 64 heads, top-k 512 and 2048):

    | format | vs main, geomean | vs main, range | vs best other, geomean | vs best other, lowest |
    |---|---|---|---|---|
    | FP8 | 1.04× | 0.99–1.14× | 1.15× | 0.98× |
    | MXFP4 | 1.05× | 0.97–1.14× | 1.26× | 1.02× |

    FP8, 32 heads, top-k 2048:

    | cell | PR (µs) | vs main | vs best other |
    |---|---|---|---|
    | fresh T=2K | 44.5 | 1.01× | 1.25× (vLLM) |
    | fresh T=16K | 1993.4 | 1.00× | 1.16× (SGLang) |
    | append T=2K, C=32K | 1177.8 | 0.99× | 1.01× (GVR) |
    | append T=2K, C=254K | 6485.3 | 1.12× | 1.38× (GVR) |
    | append T=8K, C=128K | 14531.1 | 1.12× | 1.23× (GVR) |
    | append T=16K, C=240K | 51991.1 | 1.11× | 1.30× (GVR) |
    | mixed 4×2K, C=0/16K/64K/200K | 8283.7 | 1.12× | 1.21× (GVR) |
    | mixed 8×1K, C=0..248K | 9550.7 | 1.14× | 1.27× (GVR) |

    MXFP4, 64 heads, top-k 512:

    | cell | PR (µs) | vs main | vs best other |
    |---|---|---|---|
    | fresh T=2K | 57.8 | 1.00× | 1.14× (vLLM) |
    | fresh T=16K | 2058.6 | 1.00× | 1.22× (SGLang) |
    | append T=2K, C=32K | 1230.2 | 0.98× | 1.10× (GVR) |
    | append T=2K, C=254K | 6880.2 | 1.09× | 1.47× (GVR) |
    | append T=8K, C=32K | 4696.1 | 0.98× | 1.16× (GVR) |
    | append T=16K, C=240K | 55037.6 | 1.08× | 1.38× (GVR) |
    | mixed 4×2K, C=0/16K/64K/200K | 8503.2 | 1.08× | 1.31× (GVR) |
    | mixed 8×1K, C=0..248K | 10092.7 | 1.08× | 1.29× (GVR) |

    Where the gains come from:

  • Long contexts: the scan's operands kept in registers.

  • Mixed contexts: classes scheduled together beside the scan, and short-handed classes split.
  • Known regression against main: MXFP4 64-head appends with C ≈ 32K run at 0.97–0.98×, from the queue launch's code generation. Every other cell is at 0.99× or above.

    Loss bar: one cell trails the best other pipeline: FP8 32-head top-k 512 append T=2K C=32K, at 0.98× against GVR (0.93× on main). Every MXFP4 cell is ahead.

    DeepSeek-V4.1 layers (32 heads, FP8, top-k 512, 2048 candidate blocks of 8). Dense layers take an 8K-token chunk; candidate layers replay the chunk's last 128 rows per request. The baseline is DeepGEMM logits plus vLLM's candidate helpers and top-k (main has no candidate support). Cells are the speedup over the baseline, with this PR's time in µs:

    | step | dense | source (replay) | consumer (replay) |
    |---|---|---|---|
    | one chunk at 0K | 1.15× (302.3) | 1.87× (35.6) | 1.03× (36.4) |
    | one chunk at 32K | 1.14× (2336.0) | 1.40× (133.9) | 1.09× (118.4) |
    | one chunk at 128K | 1.44× (7834.4) | 1.23× (347.4) | 1.20× (325.0) |
    | one chunk at 512K | 2.07× (25295.9) | 1.66× (1075.7) | 1.57× (1056.2) |
    | 8 requests, mixed contexts | 1.68× (2353.6) | 5.06× (677.7) | 5.71× (632.6) |
    | 16 requests, mixed contexts | 2.03× (6016.7) | 3.27× (2961.6) | 3.50× (2801.3) |

    Decode: unchanged; the kernels' SASS is main's.

    🔍 Related Issues

  • Tracking issue: #7084

  • #9761 also fences the decode scan's stage releases (see the fix section above).
  • 🚀 Pull Request Checklist

    ✅ Pre-commit Checks

  • I have installed pre-commit by running pip install pre-commit (or used your preferred method).

  • I have installed the hooks with pre-commit install.

  • I have run the hooks manually with pre-commit run --all-files and fixed any reported issues.
  • 🧪 Tests

  • Tests have been added or updated as needed.

  • All tests are passing (unittest, etc.).

  • This PR requires full-scope CI, not targeted tests (expensive; justify below).
  • tests/experimental/test_sm120_dsa_indexer.py: 328 passed on two RTX PRO 6000 machines. One of them runs an RTX PRO 5500 vBIOS with 170 SMs. New and extended cases:

  • candidate source and consumer rows;

  • queue, split and partition schedules, bitwise against the serial launches, also on a 64-SM green context;

  • the leftover-block split with whole waves and with a partial wave, for plain and candidate rows, under CUDA graphs;

  • leftover blocks straddling two requests, and a longer class's leftover with no whole wave;

  • scratch bounds for the candidate roles.
  • 🔬 Experimental Track

  • This PR is experimental: it adds or changes code under flashinfer/experimental/ and/or an @flashinfer_experimental_api. Tracking issue: #7084

  • - [x] The tracking issue names an owner, the reason for the experimental path, and a graduation plan with a target release.
    - [x] Core changes are limited to a thin entry point (signature, shared validation, feature-gate check, backend selection, handoff).
    - [x] Tests live in tests/experimental/ and were validated on the intended hardware; a runnable example is included.
    - [x] Nothing is registered in flashinfer/aot.py, and no experimental backend is reachable from backend="auto" without FLASHINFER_ALLOW_EXPERIMENTAL_AUTO_BACKENDS=1. (Calling an @flashinfer_experimental_api or naming a backend explicitly is itself the opt-in and needs no environment variable.)
    - [x] Test scope declared below. The experimental CI lane runs exactly these targets, so keep them as narrow as the change allows.

    ``experimental-tests
    tests/experimental/test_sm120_dsa_indexer.py
    `

    ---

    This PR was developed with AI assistance (Claude Code). Every change was reviewed, tested on SM120 hardware and benchmarked by the author.

    🤖 Generated with Claude Code

    <!-- This is an auto-generated comment: release notes by coderabbit.ai -->
    <!-- coderabbit-ai-generated:v1 -->

    Summary by CodeRabbit

    New Features
    Ragged inputs now support candidate-block selection, including selecting source candidates and restricting results to listed candidates. Unlisted visible keys are ranked at negative infinity.
    Candidate outputs are supported for ragged inputs, including calls with no keys, which return
    -1` entries.
    Improvements
    Selection scheduling better handles varied workloads, including long rows and mixed segments, by distributing work across available processing resources.
    Documentation
    * Clarified candidate-block behavior and limitations for paged and ragged inputs.
    <!-- end of auto-generated comment: release notes by coderabbit.ai -->

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: lucifer1004 Review duration: 7300m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #10072"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 20.5% · Safe to merge
    20.5%