Skip to content

[FLYDSL] Support paged mqa logits fp4 varqlen kernel - #4230

Merged
valarLip merged 5 commits into
mainfrom
zhimding/mqa_logits_prefill_0604
Jul 28, 2026
Merged

valarLip merged 5 commits into
mainfrom
zhimding/mqa_logits_prefill_0604

Conversation

@zhiding512

Copy link
Copy Markdown
Contributor

No description provided.

zhiding512 and others added 2 commits July 14, 2026 06:12
Default parallel_unit_num to None and derive it in compute_varctx_schedule as
batch*next_n*ceil(max_seq_len/block_k) when unset. The value comes purely from
static shape metadata (no context_lens read), so it is cudagraph-safe and is a
multiple of next_n and >= batch*next_n by construction. Callers can now omit the
knob, and it fixes next_n values (e.g. next_n=10) where the old default of 512
was not a multiple of next_n. The op-test passes None through to exercise the
auto path.

Co-authored-by: Cursor <cursoragent@cursor.com>
…ill kernel

Add flydsl_pa_mqa_logits_fp4_varqlen + _build_varqlen_mtp_windows: a cu_seq_q
(per-batch qlen prefix-sum) adapter over the ragged-prefill kernel, so each
batch can have a different query length. Row n of batch b scores KV
[0, ctx_b - qlen_b + n] (MTP tail-causal, same semantics as the uniform-next_n
decode kernel). The builder uses only static shape metadata (no context_lens
value read), so it is cudagraph-safe; no kernel or ABI change is needed. Export
the new entry from aiter.ops.flydsl.

Merge the standalone varqlen op-test into test_flydsl_pa_mqa_logits_fp4_prefill.py
(shared fp4/preshuffle/reference helpers; the builder is unit-checked against an
independent window construction). The varqlen cases also report TFLOPS / GB/s
(kernel-only, useful FLOPs/bytes), gated behind --bench like the prefill perf.

Co-authored-by: Cursor <cursoragent@cursor.com>
@zhiding512
zhiding512 requested review from a team and Copilot July 14, 2026 06:13
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter op tests (gfx942 + gfx950)
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:triton-300x Run an additional Triton test job on MI300X in PRs; main branch always runs both MI35X and MI300X
ci:sglang SGLang integration tests: DeepSeek-R1-MXFP4 accuracy, Qwen 3.5 accuracy
ci:atom ATOM benchmark: DeepSeek-R1-0528, GPT-OSS-120B
ci:atom_full ATOM accuracy suite for PR and main models from ATOM models_accuracy.json
ci:vllm vLLM benchmark: GPT-OSS-120B, DeepSeek-R1-0528, Kimi-K2.5
ci:all All standard extended tests (excludes ci:atom_full)

Only add ci:atom_full for FlyDSL or Triton upgrades.
Add labels via the sidebar or gh pr edit 4230 --add-label <label>

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.

Pull request overview

Adds variable query-length (per-batch MTP) support to the FlyDSL FP4 paged MQA logits path, including an exported flydsl_pa_mqa_logits_fp4_varqlen wrapper and updated scheduling defaults to allow cudagraph-safe auto-derived CTA grids.

Changes:

  • Make parallel_unit_num optional (None = auto-derived) for the decode/varctx scheduling path and update the corresponding op-test defaults/docs.
  • Introduce flydsl_pa_mqa_logits_fp4_varqlen (cu-seq prefix-sum adapter) plus a helper to build MTP tail-causal windows.
  • Extend the prefill op-test to validate varqlen correctness and optionally report kernel-only TFLOPS / GB/s.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
op_tests/test_flydsl_pa_mqa_logits_fp4.py Switches schedule CTA target to optional/auto-derived and updates CLI help.
op_tests/test_flydsl_pa_mqa_logits_fp4_prefill.py Adds varqlen test coverage and perf reporting for the new varqlen path.
aiter/ops/flydsl/kernels/pa_mqa_logits_fp4.py Allows compute_varctx_schedule + decode wrapper to accept parallel_unit_num=None and documents the auto-derivation.
aiter/ops/flydsl/kernels/pa_mqa_logits_fp4_prefill.py Adds _build_varqlen_mtp_windows and flydsl_pa_mqa_logits_fp4_varqlen wrapper.
aiter/ops/flydsl/__init__.py Exports the new public FlyDSL symbol flydsl_pa_mqa_logits_fp4_varqlen.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread aiter/ops/flydsl/kernels/pa_mqa_logits_fp4_prefill.py
Comment thread aiter/ops/flydsl/kernels/pa_mqa_logits_fp4.py
Fuse the cu_seq_q -> (row_to_batch, local_starts, local_ends) construction into
a single Triton kernel (_varqlen_windows_kernel), replacing the ~8 small torch
ops (arange/searchsorted/gathers/arith/clamp). Still cudagraph-safe: the grid
comes from total_q (q.shape[0]) with no context_lens value read. Rename the
builder to compute_varqlen_windows to match compute_prefill_schedule /
compute_varctx_schedule, and export it.

Decouple window-building from the launch so the ragged-row metadata is built
once and reused across many calls: cu_seq_q/context_lens are now keyword-only
(one-shot build), with optional windows=(row_to_batch, local_starts,
local_ends) and cta_info/n_ctas passthrough for repeated launches with a stable
layout. The op-test uses the new signature and adds a windows= reuse check
(torch.equal against the cu_seq_q path).

Co-authored-by: Cursor <cursoragent@cursor.com>
@zufayu
zufayu requested a review from amd-ruitang3 July 15, 2026 02:20
junhaha666 and others added 2 commits July 27, 2026 16:45
Sort the flydsl guarded import block and its __all__ additions, and switch
the varqlen entry point plus the test's local import to the forms ruff
expects. Only diff-context findings are addressed; the files' pre-existing
warnings are left untouched.

Co-authored-by: Cursor <cursoragent@cursor.com>
@valarLip
valarLip merged commit ad2f051 into main Jul 28, 2026
42 checks passed
@valarLip
valarLip deleted the zhimding/mqa_logits_prefill_0604 branch July 28, 2026 07:02
valarLip added a commit that referenced this pull request Jul 28, 2026
Conflicts came from #4230 (FLYDSL paged mqa logits fp4), which touched
five files this branch had also reformatted. Resolved by taking main's
content verbatim for every conflicted file and re-running the lint pass
over it, rather than hand-merging formatting against functional changes:

    git checkout --theirs <files> && ruff check --fix && black

Only mechanical rules applied -- UP045 (5), I001 (2), RUF022 (1), all
safe fixes, no --unsafe-fixes needed. `git diff origin/main` on those
five files now shows lint changes and nothing else, which is the proof
that main's functional content survived intact.
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.

4 participants