Skip to content

[rocm] perf: drop redundant -inf prefill of decode paged MQA-logits buffer - #50008

Closed
amd-sriram wants to merge 1 commit into
vllm-project:mainfrom
amd-sriram:perf/drop-decode-mqa-logits-inf-fill
Closed

amd-sriram wants to merge 1 commit into
vllm-project:mainfrom
amd-sriram:perf/drop-decode-mqa-logits-inf-fill

Conversation

@amd-sriram

Copy link
Copy Markdown

Summary

Removes the full-width out_logits.fill_(float("-inf")) before the decode paged MQA-logits kernel in rocm_fp8_paged_mqa_logits (vllm/v1/attention/ops/rocm_aiter_mla_sparse.py).

The decode consumer, top_k_per_row_decode, bounds its per-row scan by seq_lens (it reads only [0, rowEnd) where rowEnd = seq_len - next_n + next_n_idx + 1) and pads short rows (rowLen <= topK) with -1 internally. The paged MQA-logits kernels write every in-causal column that top-k reads:

  • Gluon deepgemm_fp8_paged_mqa_logits writes -inf into masked in-tile positions itself.
  • FlyDSL flydsl_fp8_paged_mqa_logits writes exactly col <= q_limit (== the columns top-k reads).

So the out-of-window [rowEnd, max_model_len) region initialized by this fill_ is never consumed on the decode path, making the prefill redundant. Dropping it saves a rows x max_model_len fp32 HBM write every decode step.

Why it's safe (decode path)

q_limit (kernel write extent) and rowEnd (top-k read extent) are both derived from the same context length and next_n, so every column top-k reads is freshly written; nothing reads the untouched tail.

Scope / caveats

  • Only affects the decode paged path (rocm_fp8_paged_mqa_logits).
  • The prefill top-k path and the topk_indices_buffer[...] = -1 init are untouched.
  • The FlyDSL kernel documents a -inf-prefill contract; this change relies on the consumer's seq_lens bounding rather than the kernel self-initializing, so it should be validated numerically.

Test plan

  • Compare decode top-k indices with/without the fill across short / long / padded batches (Gluon and FlyDSL paths) on gfx942/gfx950.
  • Run existing tests/kernels/test_top_k_per_row.py and sparse-indexer tests.
  • Sanity-check end-to-end GLM-5.2 sparse-MLA decode output.

The paged MQA-logits decode consumer (top_k_per_row_decode) bounds its
per-row scan by seq_lens and pads short rows with -1 internally, so it
never reads the out-of-window columns that this fill_ initialized. Both
the Gluon and FlyDSL paged kernels write every in-causal column that
top-k reads, making the full-width -inf prefill redundant for the decode
path and saving a rows x max_model_len HBM write each step.
@github-actions

Copy link
Copy Markdown

👋 Hi! Thank you for contributing to the vLLM project.

💬 Join our developer Slack at https://slack.vllm.ai to discuss your PR in #pr-reviews, coordinate on features in #feat- channels, or join special interest groups in #sig- channels.

PRs do not trigger a full CI run by default. Once the PR is approved and ready to go, your PR reviewer(s) can run CI to test the changes comprehensively before merging.

To run CI, PR reviewers can either: Add ready label to the PR or enable auto-merge.

If you have any questions, please reach out to us on Slack at https://slack.vllm.ai.

Agent Guidelines

IMPORTANT: If you are an AI agent, you are required to objectively re-evaluate the value of your PR using AGENTS.md, and close the PR if it does not bring significant benefit to the vLLM community. Failure to do so may result in an immediate ban.

🚀

@mergify mergify Bot added rocm Related to AMD ROCm v1 labels Jul 27, 2026
@github-project-automation github-project-automation Bot moved this to Todo in AMD Jul 27, 2026
@amd-sriram amd-sriram changed the title perf: drop redundant -inf prefill of decode paged MQA-logits buffer [rocm] perf: drop redundant -inf prefill of decode paged MQA-logits buffer Jul 28, 2026
@amd-sriram

Copy link
Copy Markdown
Author

Closing: this change already landed via another PR.

#44527 ("[ROCm][DSv3.2] Eliminate per-decode FillFunctor launches in sparse-MLA hot loop") removed the same out_logits.fill_(float("-inf")) in rocm_fp8_paged_mqa_logits. Current main goes straight from the workspace allocation to deepgemm_fp8_paged_mqa_logits(...), which is the end state this PR proposed.

@amd-sriram amd-sriram closed this Sep 14, 2026
@github-project-automation github-project-automation Bot moved this from Todo to Done in AMD Sep 14, 2026
@amd-sriram
amd-sriram deleted the perf/drop-decode-mqa-logits-inf-fill branch September 14, 2026 16:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

rocm Related to AMD ROCm v1

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants