Skip to content

[Triton/Gluon] mla_sparse_prefill: triton backend on gfx950, the default at H=32 without a sink - #7681

Open
eppaneamd wants to merge 14 commits into
eppaneamd/gluon-pa-prefill-sparse-gfx950from
eppaneamd/mla-sparse-prefill-triton-backend
Open

eppaneamd wants to merge 14 commits into
eppaneamd/gluon-pa-prefill-sparse-gfx950from
eppaneamd/mla-sparse-prefill-triton-backend

Conversation

@eppaneamd

@eppaneamd eppaneamd commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #7680, and based on its branch: this PR's diff is its own commits.

Summary

mla_sparse_prefill accepts backend="triton": pa_prefill_sparse's gfx950 single-pass kernel from #7680, at H=32
or 64. With backend=None it becomes the default on gfx950 for sink-free bf16 calls with H=32, one KV source and at
least 512 query rows. Other calls keep OPUS.

Motivation

Changes

  • aiter/ops/mla_sparse_prefill.py:
    • backend="triton" calls pa_prefill_sparse with has_invalid=False, at any number of query rows, and always
      runs [Triton/Gluon] pa_prefill_sparse: single-pass gluon kernel for gfx950 at H=32 and 64 #7680's single-pass kernel, never mla_gluon:
      • it serves gfx950, an empty kv_indices_extend, num_kv_splits None or 1 and out None or contiguous;
      • and what the kernel serves (_single_pass_unsupported: bf16 q and unified_kv, H=32 or 64, D=512, a 2-D
        unified_kv, unit inner strides);
      • anything else raises RuntimeError, the module's error for a configuration no backend serves.
    • backend=None takes it for such calls with H=32, without a sink and with at least 512 query rows. Otherwise OPUS,
      as before.
      • Below 512 rows OPUS is faster (Performance): the kernel runs one program per query row and 32 heads, while
        OPUS splits each row's keys.
      • With a sink: only when forced. The kernel supports a sink, but no model with a sink was measured end to end.
    • The import of pa_prefill_sparse is tried once. If it fails (its Gluon kernels need a Triton with Gluon),
      backend=None keeps OPUS and "triton" raises RuntimeError naming the ImportError.
    • The switch is logged once. Module and function docstrings updated.
    • Plugin routing ([OPUS] [RFC #7240] Route MLA sparse prefill where its two public spellings converge #7791): mla_sparse_prefill dispatches the routed op as mla_sparse_prefill_v41 does. Enabled
      providers are tried first and never see backend=; the native fallback then runs the triton backend or OPUS. The
      routed op _mla_sparse_prefill_routed (OPUS), its contract and pa_sparse_prefill_opus are unchanged.
  • op_tests/test_mla_sparse_prefill.py and tests/test_mla_sparse_prefill_backend.py (new): see "Changed op tests".
  • tests/test_plugin_routed_ops.py: the test that keeps the backend pin out of the provider contract also runs with
    backend="triton".

Performance (if applicable)

Kernel, test_mla_sparse_prefill.py, forced triton against opus:

  • uniformly random slots, 64 MiB pool; its inputs carry a sink;
  • each value is the mean of two processes on one GPU.
Hardware Workload/configuration Before (opus, µs) After (triton, µs) Change
MI355X H 32, n 1,024, top-k 2,048 570.23 288.35 −49.4 %
MI355X H 32, n 4,096 2,255.63 1,111.88 −50.7 %
MI355X H 32, n 8,192 4,502.21 2,196.51 −51.2 %
MI355X H 32, n 16,384 8,999.38 4,355.15 −51.6 %
python op_tests/test_mla_sparse_prefill.py --prec bf16 --backend opus triton --h_q 32 64 \
    --window 0 -n 1024 4096 8192 16384 --topk 2048 --total_pages 65536 --no-verify
  • With a 1 GiB pool (--total_pages 1048576 -n 4096 16384), H=32: 2,501.61 → 1,392.05 µs (−44.4 %) and
    10,108.61 → 5,767.11 µs (−42.9 %).
  • At H=64 forced triton is slower: +6.3 to +9.9 % with a 64 MiB pool, +19.8 to +20.7 % with a 1 GiB pool.

Kernel, without a sink, through mla_sparse_prefill(backend=...):

  • Index lists captured from GLM-5.3-Flash prefill in SGLang (3 layers × 8,499 and 16,179 rows): OPUS takes 1.09× the
    triton backend's time at H=32 and 0.90× at H=64.

  • Synthetic lists (rows choose up to 2,048 keys from runs of 4 adjacent slots), H=32: OPUS's time over the triton
    backend's, the minimum over 3 processes.

    Query rows 64 128 256 512 1,024 2,048
    no earlier tokens 0.88 0.86 0.95 1.17 1.27 1.15
    after 8,192 tokens 0.39 0.55 0.75 1.07 1.09 1.09

    512 is the fewest rows from which the triton backend is faster in both rows of the table.

  • Harness outside this PR: the backends interleaved in one process, 512 MiB written before each call; 3 processes per
    input set.

End to end, GLM-5.3-Flash at TP 2 (H=32) on MI355X in SGLang with sgl-project/sglang#49282:

  • Image: lmsysorg/sglang-rocm:v0.5.23-rocm724-mi35x-20261106 with #49282 applied; model revision b5688f25.
  • That image's AITER (285579b621) has no mla_sparse_prefill.
  • Server and load (SGLANG_USE_AITER=1):
    python -m sglang.launch_server --model-path amd/GLM-5.3-Flash-Quark-MXFP4 --tp 2 --trust-remote-code \
        --quantization quark --attention-backend dsa --dsa-prefill-backend aiter --dsa-decode-backend tilelang \
        --context-length 131072 --mem-fraction-static 0.90 --enable-multimodal \
        --limit-mm-data-per-request '{"image": 1}' \
        --mm-process-config '{"image": {"min_image_tokens": 16, "max_image_tokens": 8000}}' --mm-enable-dp-encoder \
        --reasoning-parser glm45 --tool-call-parser glm47
    python -m sglang.benchmark.serving --backend sglang --dataset-name image --image-count 1 \
        --image-resolution 768x1024 --random-input-len 8192 --random-output-len 64 --random-range-ratio 0.8 \
        --request-rate inf --max-concurrency C --num-prompts 10C --warmup-requests C --flush-cache
    
  • Seven servers in turn, each after an untimed pass and all with the same prompts: baseline, patched, baseline,
    patched, baseline, patched, baseline.
Concurrency Baseline (tok/s) Patched (tok/s) Change
16 165.1 167.6 +1.5 %
32 168.6 171.5 +1.7 %
64 176.9 180.3 +1.9 %
  • Output throughput: the mean of the 4 baseline and of the 3 patched runs.
  • Each patched run against the mean of the baseline runs on either side: +1.49 / +1.62 / +1.88 %, SE 0.09 / 0.12 /
    0.11 pp over the three runs.
  • The baseline moved at most 0.8 % between neighbouring runs.
  • Routing, counted in the servers: in the patched runs every prefill call that #49282 sends to AITER ran the triton
    backend; in the baseline runs, OPUS.
  • Accuracy, one baseline and one patched server: MMMU 0.693 → 0.695; GSM8K 0.975 → 0.967 (1,281 → 1,270 of 1,314).
  • Against main's OPUS: about +0.4 to +0.6 %, estimated, not measured. On synthetic lists of 8,192 and 16,384
    rows the image's OPUS takes 1.31× the triton backend's time and main's 1.09×; the gain is scaled by
    (1.09 − 1) / (1.31 − 1).

Testing

  • Unit tests added or updated
  • Performance benchmarks run
  • Tested on MI250X
  • Tested on MI300X

Documentation

  • Docstrings updated
  • User guide updated
  • Performance guide updated
  • No documentation change is needed, with the reason stated below

Dependencies

  • No new third-party dependencies added
  • New dependencies are listed and justified below

Breaking Changes

None in the API. On gfx950, sink-free bf16 calls with H=32, one source and at least 512 rows run the triton backend by
default. Their outputs differ from OPUS's within the test tolerance; backend="opus" keeps the previous kernel.

PR Self-Review

Reviewed revision

20443284ed112d9872cd2937ffca30b636e62f06

Behavior and intent

  • backend=None on gfx950 runs pa_prefill_sparse's single-pass kernel instead of OPUS for sink-free bf16 calls with
    H=32, one KV source and at least 512 rows.
  • backend="triton" forces that kernel at H=32 or 64 and any number of rows. It raises RuntimeError where the kernel
    cannot serve the call or cannot be imported; on main, "triton" raises ValueError.

Validation and unverified scope

  • Hardware: MI355X (gfx950).
  • Image: vllm/vllm-openai-rocm:nightly-rocm100-1648fefab91204f3b15bf8062217316f07f2c4bb (Triton 3.8.0), with FlyDSL
    0.5.0, which main's aiter requires at import.
  • AITER from source, OPUS built from each tree: this branch, and [Triton/Gluon] pa_prefill_sparse: single-pass gluon kernel for gfx950 at H=32 and 64 #7680's head 2718e0df2b (main 85ccf1794d
    merged).
  • python -m pytest op_tests/test_mla_sparse_prefill.py tests/test_mla_sparse_prefill_backend.py:
    • this branch: 50 passed;
    • [Triton/Gluon] pa_prefill_sparse: single-pass gluon kernel for gfx950 at H=32 and 64 #7680's head, whose mla_sparse_prefill.py is main's, with this PR's three test files: 42 passed, 8 failed.
      • ValueError: ... backend must be one of ('opus',) or None, got 'triton': [64-32-0-0-128-bf16] in the op test,
        test_triton_backend × 4, test_default_backend_gfx950[no-sink-32], test_triton_backend_rejects.
      • AttributeError (main has no _pa_prefill_sparse_module): test_default_backend_without_gluon.
      • test_default_backend_gfx950[no-sink-64], [sink-*] and [short-*] pass on both.
  • python -m pytest tests/test_plugin_routed_ops.py -k sparse_prefill: this branch 3 passed; [Triton/Gluon] pa_prefill_sparse: single-pass gluon kernel for gfx950 at H=32 and 64 #7680's head with this
    PR's version 2 passed, [triton] failed (ValueError).
  • python -m pytest op_tests/triton_tests/attention/test_pa_prefill_sparse.py: 29 passed, 43 skipped, as in [Triton/Gluon] pa_prefill_sparse: single-pass gluon kernel for gfx950 at H=32 and 64 #7680.
  • Mutations of this branch and the tests that fail under each (the other parametrizations of the same test pass):
    • _use_triton always False: test_default_backend_gfx950[no-sink-32];
    • _use_triton called with attn_sink=None: [sink-32];
    • _TRITON_MIN_ROWS 0: [short-32]; 513: [no-sink-32];
    • _TRITON_DEFAULT_HEADS (32, 64): [no-sink-64];
    • _triton_unsupported without the single-pass kernel's check: test_triton_backend_rejects;
    • the import without the ImportError fallback: test_default_backend_without_gluon;
    • backend="opus" read as None: test_default_backend_without_gluon;
    • 2 * softmax_scale passed to pa_prefill_sparse: test_triton_backend[8-rows], [h32], [h64] ([empty-pool]
      has no keys: zeros at any scale).
  • In test_default_backend_gfx950's inputs without a sink, the forced opus and triton outputs differ in 2,490 of
    8,388,608 elements at H=32 and 7,626,216 of 16,777,216 at H=64, so the test tells the backends apart.
  • Revisions measured:
    • tests and mutations: this revision;
    • the kernel tables, ratios and 1 GiB lines: 741ac525d2, this revision's parent, with the same kernel and calls;
      there backend=None took the triton backend from 64 rows at H=32 and 64;
    • TP 2 end to end: 1c902a4d25. At this revision those calls compile to the same kernel instructions.
  • One of the 3 processes on the synthetic lists of 8,192 and 16,384 rows ran at a reduced GPU clock (median 891 MHz)
    and is left out of main's 1.09× there; the captured lists and the row-count table use all 3.
  • Unverified:

PR-specific question

  • Fail on main, which rejects backend="triton" with ValueError: every case that forces it (the op test's
    [64-32-0-0-128-bf16], its gfx950 triton candidate; test_triton_backend × 4; test_triton_backend_rejects;
    test_the_backend_pin_is_not_part_of_the_sparse_prefill_contract[triton]) and
    test_default_backend_gfx950[no-sink-32], whose reference is the forced triton output.
  • Fail on main for lack of the import fallback (_pa_prefill_sparse_module): test_default_backend_without_gluon.
  • Pass on main: test_default_backend_gfx950[no-sink-64], [sink-*] and [short-*]. They pin where backend=None
    keeps OPUS: each fails under one of the mutations above.
  • No existing test covers these: the op test's sweep never calls mla_sparse_prefill(backend=None), where the default
    is chosen, and had no gfx950 triton candidate.
  • CI runs that file only as its default sweep, whose extend rows (--window defaults to 128) keep the gfx950
    candidate out; hence the backend tests in tests/.

Changed op tests

op_tests/test_mla_sparse_prefill.py:

  • The triton candidate also runs on gfx950, as mla_sparse_prefill(backend="triton"):
    • for H=32 and 64 with no extend rows and no split-K, checked against the reference like the other backends;
    • among the pytest cases, (64, 32, 0, 0, 128) (empty pools, sink only) runs it; it fails on main.
  • The module docstring describes the gfx950 candidate and gives a CLI example.

tests/test_mla_sparse_prefill_backend.py (new), with the op test's inputs, reference and arch query:

  • test_triton_backend: forced triton against the reference at 8 rows, with empty pools, at H=32 and at H=64.
  • test_default_backend_gfx950 (H=32 and 64; without a sink, with one, and without a sink at 511 rows): backend=None
    gives the forced triton output at H=32 without a sink at 512 rows, else the forced opus output.
  • test_triton_backend_rejects: forced triton raises RuntimeError for a q with inner stride 2 and for a 3-D
    unified_kv.
  • test_default_backend_without_gluon: with pa_prefill_sparse unimportable, backend=None gives the forced opus
    output.

AI assistance (Claude) was used for this PR; the change, tests and measurements were reviewed and run by the submitter.

…ult at H=32 without a sink

mla_sparse_prefill gains backend="triton": pa_prefill_sparse on gfx950 for
bf16 q and unified_kv, H = 32, an empty extend list, no split-K and out None
or contiguous; anything else raises RuntimeError. backend=None takes it for
such calls without a sink when pa_prefill_sparse's single-pass kernel serves
them (its MIN_TOKENS query rows and unit inner strides), and logs the switch
once. Other calls keep opus.

Tests: the bf16 sweep's triton candidate also runs on gfx950, through
mla_sparse_prefill(backend="triton"), for H = 32 cases with no extend rows,
plus one such case; a guard checks that backend=None gives the triton output
without a sink and the opus output with one.

Signed-off-by: Rony Leppänen <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Forced Triton calls can produce incorrect attention results for non-unit inner strides and small-query sink inputs, and normal CI does not exercise the added regressions.

4 open issues
What changed in this PR

This PR connects mla_sparse_prefill to the gfx950 single-pass backend introduced in #7680, making it the default for eligible sink-free bf16 calls while retaining OPUS for other configurations.

Changes:

  • Adds explicit backend="triton" support with configuration checks.
  • Selects Triton automatically for supported H=32, single-source calls with enough query rows.
  • Extends correctness tests and CLI coverage for gfx950, including default-backend selection with and without a sink.
File Description
op_tests/​test_mla_sparse_prefill.py Adds gfx950 Triton cases, default-selection regression coverage, and CLI documentation.
aiter/​ops/​mla_sparse_prefill.py Adds Triton eligibility checks, dispatch, one-time logging, and backend documentation.

Review effort: Balanced

Comment thread aiter/ops/mla_sparse_prefill.py Resolved
Comment thread aiter/ops/mla_sparse_prefill.py Resolved
Comment thread aiter/ops/mla_sparse_prefill.py Resolved
Comment thread op_tests/test_mla_sparse_prefill.py Resolved
…d/mla-sparse-prefill-triton-backend

Signed-off-by: Rony Leppänen <[email protected]>
…kernel serves, H=64 too, and opus when pa_prefill_sparse cannot load

backend="triton" now takes exactly the calls pa_prefill_sparse's gfx950
single-pass kernel serves (_single_pass_unsupported) within its own
contract (one KV source, no split-K, out None or contiguous), and raises
RuntimeError for the rest. Before, it also accepted q or unified_kv with
an inner stride other than 1, and a unified_kv that is not 2-D.
pa_prefill_sparse sent those to mla_gluon, which ignores those strides:
on MI355X every row of a T=256, H=32 call came back wrong. Calls with a
sink below MIN_TOKENS rows now run the kernel inside pa_prefill_sparse
(merged from #7680), where mla_gluon added the sink once per key split.

With #7680's H=64 support the triton backend serves H=64 too, and
backend=None takes it for sink-free H=64 calls with at least MIN_TOKENS
rows, as at H=32. Its choice at H=32 is unchanged.

backend=None raised ImportError where pa_prefill_sparse's module cannot
be imported (its gluon kernels need a Triton with gluon). It now runs
opus there, and logs why once.

Tests: test_triton_backend_rejects (q with inner stride 2, a 3-D
unified_kv), test_default_backend_without_gluon, test_default_backend_gfx950
at H=32 and 64, and an H=64 one-source case in the sweep.

Signed-off-by: Rony Leppänen <[email protected]>
…en its sweep

CI ran the file as a script, whose entry point runs the backend sweep
only, so none of its pytest functions ran: the precision sweep, the
OPUS CSR boundary cases and the backend-choice tests. The file now runs
under pytest first, then as a script. On MI35X the script took 85 s in
CI.

Signed-off-by: Rony Leppänen <[email protected]>
…d/mla-sparse-prefill-triton-backend

Signed-off-by: Rony Leppänen <[email protected]>
…its own 64-row bound

backend=None took triton from pa_prefill_sparse's MIN_TOKENS query rows,
which pa_prefill_sparse is about to drop. The bound stays at 64 rows, now as
this module's _TRITON_MIN_ROWS: below it the single-pass kernel would run
one program per query row, while opus splits each row's keys.

Signed-off-by: Rony Leppänen <[email protected]>
…d/mla-sparse-prefill-triton-backend

Signed-off-by: Rony Leppänen <[email protected]>
…ingle-pass kernel cannot serve; tests in tests/

backend="triton" raises RuntimeError unless pa_prefill_sparse's single-pass
kernel serves the call (unit inner strides, at least MIN_TOKENS query rows).
Before, such a call reached mla_gluon, which is not the kernel the backend
names. _use_triton returns False where pa_prefill_sparse cannot be imported
(Triton < 3.6), so backend=None keeps opus there instead of raising
ImportError; a forced "triton" call still raises it.

The default-backend test and the two guards above move to
tests/test_mla_sparse_prefill_backend.py, which CI's `pytest -q tests` step
runs once a pull request targets main; op_tests/test_mla_sparse_prefill.py
runs there as its default sweep, which never called them.

On MI355X (torch 2.13.0+rocm10.0.0): on the sources of the previous head the
two guard tests fail (DID NOT RAISE; the import halted) and the default-backend
tests pass; with this commit all four pass, 0 skipped; dropping the raise
fails only the first guard, dropping the ImportError guard only the second.
op_tests/test_mla_sparse_prefill.py passes 46 on both, and its default sweep
completes on both.

Signed-off-by: Rony Leppänen <[email protected]>
…ppaneamd/mla-sparse-prefill-triton-backend

Two fixes for the same review findings meet here. The resolution:
- aiter/ops/mla_sparse_prefill.py is this branch's. backend="triton"
  raises where pa_prefill_sparse's single-pass kernel cannot serve the
  call (H, D, dtypes, a 2-D unified_kv, unit inner strides), at any
  number of query rows, since pa_prefill_sparse now sends every call that
  kernel serves to it; the module is imported once, and backend=None keeps
  opus where it cannot be.
- The backend tests live in tests/test_mla_sparse_prefill_backend.py, as
  in cd4d853, where CI's `pytest -q tests` step collects them, in this
  branch's form (H 32 and 64, the 2-D check, no row bound), plus
  test_triton_backend: backend="triton" against the op test's reference,
  in place of the op test's two one-source pytest rows.
- .github/scripts/aiter_test.sh stays as on main: with these tests in
  tests/, the op test's pytest functions need no CI case.

Signed-off-by: Rony Leppänen <[email protected]>
@eppaneamd
eppaneamd force-pushed the eppaneamd/mla-sparse-prefill-triton-backend branch from 8e5164b to 3e40348 Compare November 10, 2026 12:35
@eppaneamd eppaneamd changed the title [Triton/Gluon] mla_sparse_prefill: triton backend on gfx950, the default at H=32 without a sink [Triton/Gluon] mla_sparse_prefill: triton backend on gfx950, the default at H=32 and 64 without a sink Nov 10, 2026
…d/mla-sparse-prefill-triton-backend

Signed-off-by: Rony Leppänen <[email protected]>
…d/mla-sparse-prefill-triton-backend

Signed-off-by: Rony Leppänen <[email protected]>
…ram per query row and 32 heads

Signed-off-by: Rony Leppänen <[email protected]>
…d/mla-sparse-prefill-triton-backend

Brings in main up to 85ccf17 through #7680.

Conflicts:
- aiter/ops/mla_sparse_prefill.py: main routes the op through the plugin
  interface (#7791). mla_sparse_prefill now dispatches as
  mla_sparse_prefill_v41 does: enabled providers first, then a native
  fallback that picks triton or opus from backend=. The routed op
  (_mla_sparse_prefill_routed, opus) and its contract are unchanged.
- op_tests/test_mla_sparse_prefill.py: docstrings. main replaced
  --total_tokens with --window and passes total_tokens=n, so the gfx950
  triton candidate now keys on an empty kv_indices_extend (what the triton
  backend requires) instead of total_tokens == 0.

tests/test_plugin_routed_ops.py: the backend-pin test also covers
backend="triton".

Signed-off-by: Rony Leppänen <[email protected]>
…2 rows

Measured on MI355X against main's OPUS, whose H > 32 kernel #7784 and #7897 sped up:
- H=64: OPUS takes 0.90x the triton backend's time on index lists captured from GLM-5.3-Flash
  prefill and 0.83-0.94x on uniformly random ones, so backend=None keeps OPUS there.
  backend="triton" still serves H=64.
- H=32: OPUS takes 1.09x the triton backend's time on the captured lists and 1.75-2.07x on the
  random ones, but below 512 query rows 0.39-0.95x, so the bound rises from 64 to 512.

test_default_backend_gfx950 runs at the bound, expects OPUS at H=64, and adds a case one row
below the bound, which expects OPUS.

Signed-off-by: Rony Leppänen <[email protected]>
@eppaneamd eppaneamd changed the title [Triton/Gluon] mla_sparse_prefill: triton backend on gfx950, the default at H=32 and 64 without a sink [Triton/Gluon] mla_sparse_prefill: triton backend on gfx950, the default at H=32 without a sink Nov 13, 2026
@eppaneamd
eppaneamd marked this pull request as ready for review November 13, 2026 18:50
@github-actions

Copy link
Copy Markdown
Contributor

No activity for 15 days, so this is now labelled stale. A push or a comment clears it; keep-open exempts it. Nothing is closed automatically.

@github-actions github-actions Bot added the stale The PR hasn't been updated in 2 weeks label Nov 29, 2026

@msaffari-amd msaffari-amd left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this! I ran it on an MI355X (gfx950). The triton path gave the right answers on everything I tried: ragged and empty rows, no sink, 32 and 64 heads, a 1M-row pool, strided q and unified_kv views, a NaN-filled out, and an empty pool. Comparing base against head for backend=None at 32 heads without a sink, it was 43 to 50 % faster from 512 to 16,384 rows, which matches your table. Nothing changed where it still uses OPUS (64 heads, with a sink, or under 512 rows).

Two things I'd like to see before merge (details in the inline comments):

  • Needs updating for the new plugin routing on main
  • These tests don't run in CI on main anymore

One open question: with backend=None, existing callers at 32 heads without a sink will now get triton instead of OPUS, and the only hint is a one-time log line. The two drafts you mention, sglang#49282 and vllm#66424, don't pass backend= and were tested on OPUS. Would a note in the PR or release text pointing to backend="opus" as the way to opt out be enough? Or would a small helper like get_mla_sparse_prefill_v41_backend, so callers can check which kernel they'll get, be useful here too?

out,
num_kv_splits,
)
operation = _mla_sparse_prefill_routed.__aiter_plugin_op__

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs updating for the new plugin routing on main

Heads-up for when this moves onto main after #7680: #8291 changed how mla_sparse_prefill hooks into the plugin system there, so this part won't work as it is.

What changed on main:

  • The function plugins see is now _mla_sparse_prefill_contract, and it no longer takes out.
  • _mla_sparse_prefill_routed isn't decorated anymore, so this line would raise an AttributeError.
  • Git also shows a merge conflict in this file.

mla_sparse_prefill_v41 on main already does the same thing the new way, so copying that is probably the easiest fix. If the caller passes out, skip the plugins and run our own code directly. If not, go through the new function and add out=None back before picking triton or opus.

Roughly like this (written against main, not tested):

    def native_fallback(
        q_, unified_kv_, kv_indices_prefix_, kv_indptr_prefix_, kv_,
        kv_indices_extend_, kv_indptr_extend_, attn_sink_, softmax_scale_,
        out_=None, num_kv_splits_=None,
    ):
        if backend == "triton" or (
            backend is None
            and _use_triton(
                q_, unified_kv_, kv_indices_extend_, attn_sink_, out_, num_kv_splits_
            )
        ):
            return _triton_sparse_prefill(
                q_, unified_kv_, kv_indices_prefix_, kv_indptr_prefix_,
                kv_indices_extend_, attn_sink_, softmax_scale_, out_, num_kv_splits_,
            )
        return _mla_sparse_prefill_native(
            q_, unified_kv_, kv_indices_prefix_, kv_indptr_prefix_, kv_,
            kv_indices_extend_, kv_indptr_extend_, attn_sink_, softmax_scale_,
            out_, num_kv_splits_,
        )

    args = (
        q, unified_kv, kv_indices_prefix, kv_indptr_prefix, kv,
        kv_indices_extend, kv_indptr_extend, attn_sink, softmax_scale,
    )
    if out is not None:
        return native_fallback(*args, out, num_kv_splits)

    def contract_fallback(*contract_args):
        *inputs, num_kv_splits_ = contract_args
        return native_fallback(*inputs, None, num_kv_splits_)

    operation = _mla_sparse_prefill_contract.__aiter_plugin_op__
    registered = _plugin._routed_ops[operation.name]
    return _plugin._dispatch(
        operation, registered.canonicalize, contract_fallback,
        (*args, num_kv_splits), {},
    )

Comment on lines +6 to +9
Lives in ``tests/`` because CI runs ``python3 -m pytest -q tests`` on pull requests
to main, while ``op_tests/test_mla_sparse_prefill.py`` runs there only as its
default sweep, which never calls these tests. The inputs, the reference and the
arch query are the op test's.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests don't run in CI on main anymore

Agreeing with Copilot's earlier comment here. Moving the tests to tests/ used to be enough, but #8352 removed the pytest -q tests step from aiter-test.yaml, and pre-checks.yaml only runs the test_plugin* files. So right now nothing in CI runs this file. The op test's default run doesn't cover it either: its default --window 128 gives every call extend rows, so the gfx950 triton path never gets picked.

The way in on main is the explicit list in .github/scripts/split_tests.sh (it already has tests/test_flydsl_aot_cache.py), and aiter_test.sh already runs tests/test_*.py through pytest. Could you add the file there?

                 "tests/test_flydsl_aot_cache.py" \
-                "tests/test_flydsl_aot_launch.py"
+                "tests/test_flydsl_aot_launch.py" \
+                "tests/test_mla_sparse_prefill_backend.py"

And the docstring would then need a small update:

Suggested change
Lives in ``tests/`` because CI runs ``python3 -m pytest -q tests`` on pull requests
to main, while ``op_tests/test_mla_sparse_prefill.py`` runs there only as its
default sweep, which never calls these tests. The inputs, the reference and the
arch query are the op test's.
Runs in CI from the explicit list in ``.github/scripts/split_tests.sh``
(``aiter_test.sh`` runs ``tests/test_*.py`` through pytest), because
``op_tests/test_mla_sparse_prefill.py``'s default sweep never reaches these
cases. The inputs, the reference and the arch query are the op test's.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale The PR hasn't been updated in 2 weeks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants