Skip to content

[Test] [SM120] attention: Stop failing sparse-prefill tests on the expected dense fallback - #32464

Closed
ormandj wants to merge 1 commit into
sgl-project:mainfrom
ormandj:test/dsv4-sm120-sparse-prefill-fallback
Closed

ormandj wants to merge 1 commit into
sgl-project:mainfrom
ormandj:test/dsv4-sm120-sparse-prefill-fallback

Conversation

@ormandj

@ormandj ormandj commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

test_compress_attention_cases_sparse_prefill enables sparse prefill and expects _forward_prefill_sparse to populate sparse_prefill_cache. On SM120, production intentionally stays on the dense flash_mla_with_kvcache_sm120 path because sparse_prefill_fwd is not supported. The test therefore fails at the path assertion even though the backend selected the expected implementation.

This comes up when running the registered DSV4 attention test directly on an SM120 system, or when trying to add that test to an SM120 runner. No unusual server configuration is required: the test sets the sparse-prefill override itself. Production correctly ignores that request on SM120, but the fixture still seeds metadata for the sparse path and then asserts that its cache was populated. The failure happens before the output is compared with the PyTorch reference.

Modifications

Use is_sm120_supported() when deciding which path to seed and assert. The sparse-prefill env override is still enabled, so the test will fail if the SM120 guard is removed and sparse prefill becomes eligible.

Behavior on non-SM120 systems is unchanged. No serving code is modified.

Accuracy Tests

The targeted registered GPU test has not been rerun.

Speed Tests and Profiling

Not applicable; only test setup and assertions change.

Checklist

  • Format changed code.

Review and Merge Process

  1. Ping Merge Oncalls to start the process. See the PR Merge Process.
  2. Get approvals from CODEOWNERS and other reviewers.
  3. Trigger CI tests with comments or contact authorized users to do so.
    • Common commands include /tag-and-rerun-ci, /tag-run-ci-label, /rerun-failed-ci
  4. After green CI and required approvals, ask Merge Oncalls or people with Write permission to merge the PR.

Developed with AI assistance.


CI States

Latest PR Test (Base): ❌ Run #37577729854
Latest PR Test (Extra): ❌ Run #37577729657
Latest PR Test (AMD ROCm 10): ❌ Run #37577729804

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@ormandj

ormandj commented Jul 27, 2026

Copy link
Copy Markdown
Contributor Author

@mmangkad, could you take a look when you have a chance? This is a one-file, test-only follow-up from our SM120 validation work. It makes the existing DSV4 C4/C128 test honor the production dense fallback when sparse prefill is requested, so upcoming SM120 kernel and dispatch changes can use it as a real quality gate. The targeted registered test passes on RTX PRO 6000 Blackwell. If it looks right, could you enable CI?

efschu added a commit to efschu/htsglang that referenced this pull request Aug 2, 2026
…device actually has

Boot 11 failed on both architectures of this rig for two different reasons,
and neither was a missing capability -- both were a dispatch that named one
architecture where it meant "has this kernel".

TP0 (5090, sm120) entered the sparse-prefill branch and hit
"Sparse Attention Forward Kernel is only supported on SM90a and SM100f".
Upstream already fixed exactly this in the merged PR sgl-project#30272 by adding
"and not _is_sm120" to the predicate; our base predates it (git log -S on
that file is empty, so this is an old base, not a fork regression). Adopted
rather than rebuilt, but phrased as flash_mla_sparse_fwd_supported(device) --
the kernel states its own domain in its error text, so the gate says
major in (9, 10) and covers Ampere with the same line. The dense branch it
falls to is handed the SAME swa_page_indices / swa_topk_lengths the indexer
produced: the kernel changes, the attention support does not. Two independent
confirmations that this is lossless rather than an approximation: upstream
sgl-project#32464 calls the SM120 dense route intended production behaviour, and our own
test kit compares both branches against one _pure_torch_dsv4_combined_reference.

TP1/TP2 (3080, sm86) died in dsv4/dequant_k_cache.py on "type fp8e4nv not
supported in this architecture". The V4 KV layout is fp8-e4m3 BY ARCHITECTURE
(448 fp8 nope + 64 bf16 rope + 7 ue8m0 scale bytes in a uint8 pool);
--kv-cache-dtype cannot move it, the pool asserts store_dtype == uint8.
Triton's NVIDIA backend admits fp8e4nv only from capability 8.9.

The briefing named one file. The bug has four call sites, and fixing only the
named one would have MOVED the failure rather than removed it -- the two KV
*writers* run before any attention:
  * dequant_k_cache.py (read)     -> manual decode
  * flash_mla_sm120_triton.py     -> manual decode; this is the one that
    actually becomes load-bearing on sm86 once the sparse branch is left
  * index_buf_accessor.py (write) -> turned out to be a pure byte copy with no
    arithmetic between load and store, so both ends are viewed as uint8
    unconditionally: byte-identical everywhere, no gate needed
  * quant_k_cache.py (write)      -> a real encode. Rather than hand-roll
    round-to-nearest-even in Triton, the fallback stages the already-clamped
    float32 and lets torch do the cast, which sgl-project#262 proved bit-exact on sm86.
    f32 not bf16 staging: bf16 has 8 mantissa bits and would double-round.

Third finding, from sgl-project#33194's report and confirmed here: the compile failure
is triggered by the kernel ARGUMENT, not the load -- an fp8-typed tensor fails
at the def line even if the pointer is never dereferenced. An in-kernel branch
alone cannot fix it, so the host passes the uint8 view and a tl.constexpr
selects the decode. nope_cache_view returns view and flag together, following
sgl-project#192's pairing invariant: a caller cannot take one without the other.

Also removed the module-level SGLANG_SM120_FLASHMLA_BACKEND read in
flash_mla_sm120.py -- the exact sgl-project#343 anti-pattern, and its default resolves to
a flashinfer kernel gated to cc 120/121, so on a mixed group every rank got
whichever card imported first. Resolution is per device now; an explicitly set
value still applies everywhere (a statement about the launch, not a probe),
and is downgraded loudly, not silently, where the kernel cannot exist.

TESTS (desk, CUDA_VISIBLE_DEVICES=99, no GPU touched)
  test_dsv4_fp8_triton_compat_417.py  12 tests / 262 subtests green. Runs the
    production @triton.jit decode under TRITON_INTERPRET=1 against a pure
    Python IEEE-754 reference that never touches a torch fp8 dtype (sgl-project#262's
    rule: a torch reference would share torch's own Ampere bug and pass
    vacuously), with an e5m2 cross-probe so a comparison of nothing fails.
    All 256 codes, signed zero at 0x80, both NaN codes, plus the whole paged
    kernel vs the torch ref.
    CAN-FAIL: bits & 7 -> bits & 6 gives 128 failed / 10 passed.
  test_dsv4_arch_dispatch_417.py      16 tests / 28 subtests green, incl. the
    two cards of this rig disagreeing inside one process.
    CAN-FAIL: _FLASH_MLA_CUDA_MAJORS -> (8, 9, 10) gives 7 failed / 15 passed.
  Regression: unit/layers/attention + unit/utils, 44 failed / 362 passed on
    this branch vs 44 failed / 334 passed at a56f33aafd (throwaway detached
    worktree). Failing set diff EMPTY; all 44 pre-existing "No CUDA GPUs are
    available". The +28 are these tests.
  ruff 1 finding on the touched files, the identical 1 at the base (F841,
    pre-existing). codespell, black, isort clean. mypy clean on both new
    modules.

NOT proved at the desk, by construction: that these kernels COMPILE on a real
sm86 card. The Triton interpreter never invokes the NVIDIA backend, which is
where fp8e4nv is rejected. Gates for the card window are written down in
docs/dev/PLAN_417_dsv4_arch_paths.md along with the full per-architecture
coverage matrix, the upstream survey, and the open risks -- chief among them
that the indexer (dsv4/indexer.py:667, DeepGEMM metadata) is NOT addressed
here and may well be where boot 12 stops, and that sgl-project#33194's chain ends at FP4
routed experts, a wall we expect to miss because we serve GGUF.
efschu added a commit to efschu/htsglang that referenced this pull request Aug 2, 2026
…roduction takes

The compact runner pins SGLANG_OPT_FLASHMLA_SPARSE_PREFILL and then asserts
sparse_prefill_cache was populated. With the sparse-prefill gate in place that
assertion is now false on every device without flash_mla_sparse_fwd -- SM120
and Ampere both -- and it fires BEFORE the output is compared against the
pure-torch reference, so a real regression would be hidden behind a known
false failure. Upstream PR sgl-project#32464 makes the same fix for SM120 alone; this
uses the same predicate as production, so it covers Ampere too.

The env override deliberately stays on: production ignores the request on
these architectures, and if the production gate were removed this test would
go red again rather than quietly following it. The C4 seeding dispatches on
the resolved path for the same reason it dispatched on the flag before -- the
two must not disagree about which branch is being exercised.

Desk: black, isort, codespell, ruff clean on the file (ruff was already clean
at the base). unit/layers/attention 44 failed / 362 passed, unchanged failing
set. The kit itself needs a GPU and is a card-window item.
@ormandj ormandj changed the title test(dsv4): expect dense prefill fallback on SM120 Fix false SM120 sparse-prefill test failures for the expected dense fallback Sep 6, 2026
@ormandj
ormandj force-pushed the test/dsv4-sm120-sparse-prefill-fallback branch from 806c572 to e918cab Compare September 30, 2026 01:20
@ormandj

ormandj commented Sep 30, 2026

Copy link
Copy Markdown
Contributor Author

Updated the code and PR body. The sparse-prefill test uses the SM120 capability guard to seed and assert the expected dense fallback, while keeping the sparse-prefill override enabled so removing the guard is detected.

@ormandj
ormandj force-pushed the test/dsv4-sm120-sparse-prefill-fallback branch from e918cab to f1eb1f5 Compare October 7, 2026 05:43
@ormandj ormandj changed the title Fix false SM120 sparse-prefill test failures for the expected dense fallback [Test] [SM120] attention: Stop failing sparse-prefill tests on the expected dense fallback Oct 19, 2026
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).
@github-actions

Copy link
Copy Markdown
Contributor

Thanks @ormandj. Closing this because you have 46 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:
sgl-kernel/ -> python/sglang/kernels/aot/, python/sglang/jit_kernel/
-> python/sglang/kernels/jit/, docs/ -> docs/docs/ (.mdx),
bench_serving.py -> benchmark/serving.py, test/srt/ -> test/registered/.

@github-actions github-actions Bot closed this Nov 13, 2026
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