Skip to content

[ROCm][MLA] Add guarded gfx942 FP8 context prefill - #51551

Closed
maeehart wants to merge 7 commits into
vllm-project:mainfrom
maeehart:maeehart/kimi-k3-gfx942-fp8-prefill-vllm
Closed

maeehart wants to merge 7 commits into
vllm-project:mainfrom
maeehart:maeehart/kimi-k3-gfx942-fp8-prefill-vllm

Conversation

@maeehart

@maeehart maeehart commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds an opt-in gfx942 FP8 context-prefill path for Kimi-K3 MLA using the D192/V128 kernel from ROCm/aiter#4645. It also supports checkpoint-specific static per-head scales through a versioned external artifact, removing dynamic amax reductions while preserving the existing attention boundary.

Background

The existing AITER FP8 ASM kernels do not cover Kimi-K3's asymmetric D192 Q/K and D128 V shape on gfx942. ROCm/aiter#4645 adds a packed variable-length Gluon implementation and static per-head quantization for this shape.

What this PR does

  • Enables the AITER FP8 path only with VLLM_ROCM_KIMI_K3_FP8_PREFILL=1.
  • Restricts dispatch to BF16 Kimi-K3 MLA on gfx942 with 12 heads, D192 Q/K, and D128 V.
  • Quantizes Q once per context pass and reuses its per-head scale across context segments.
  • Collects layer-owned Q/K/V maxima after warmup in eager calibration mode.
  • Writes atomic TP-rank shards and merges them into a versioned safetensors artifact.
  • Validates model revision, TP/PP topology, cache mode, dimensions, dtype, layer coverage, and finite positive descales before compilation.
  • Uses a one-kernel static quantizer when an artifact is configured. Missing or incompatible artifacts fail instead of silently falling back.
  • Keeps the BF16 path for unsupported shapes and short contexts.

Validation

Model: moonshotai/Kimi-K3, TP8, MI325X.

  • Full five-shot gsm8k: 0.9606 exact match with 0.0054 stderr.
  • Needle retrieval: 9 of 9 passed at 128K, 512K, and 1,047,552 tokens with needle depths 10%, 50%, and 90%.
  • Deterministic completion sanity checks: 3 of 3 passed.
  • Matched 1,047,552-token dynamic TTFT: 434.65 s, 404.80 s, and 404.83 s.
  • Matched static TTFT: 431.38 s, 402.44 s, and 402.44 s.
  • Mean static TTFT improved by 0.64%. The two warm repeats improved by 0.59%.
  • AITER synthetic gfx942 tests: 9 passed.
  • vLLM artifact and configuration tests: 8 passed.

Notes / scope

This PR depends on ROCm/aiter#4645. The feature remains disabled by default. Calibration and validation prompt sets are separate, and calibration is eager-only.

Test plan

  • Full gsm8k, five-shot, 1319 samples
  • 128K, 512K, and one-million-token needle retrieval
  • Three matched one-million-token dynamic and static repeats
  • API sanity checks
  • Artifact compatibility and merge tests

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@mergify mergify Bot added the rocm Related to AMD ROCm label Aug 9, 2026
@github-project-automation github-project-automation Bot moved this to Todo in AMD Aug 9, 2026
@maeehart

maeehart commented Aug 9, 2026

Copy link
Copy Markdown
Contributor Author

I have read the DCO document and hereby sign off past commits made by me.

@maeehart
maeehart force-pushed the maeehart/kimi-k3-gfx942-fp8-prefill-vllm branch from 8439431 to 490340e Compare August 9, 2026 15:11
Comment thread vllm/v1/attention/backends/mla/prefill/aiter_flash_attn.py Outdated
Comment thread vllm/v1/attention/backends/mla/prefill/aiter_flash_attn.py Outdated
Comment thread vllm/v1/attention/backends/mla/prefill/aiter_flash_attn.py
@maeehart

Copy link
Copy Markdown
Contributor Author

I have read the DCO and I hereby sign off the commits in this pull request.

@maeehart

Copy link
Copy Markdown
Contributor Author

I have read the DCO and I hereby sign off on the commits in this pull request.

@maeehart
maeehart force-pushed the maeehart/kimi-k3-gfx942-fp8-prefill-vllm branch from d521ac8 to f57de88 Compare August 11, 2026 20:52
@maeehart

Copy link
Copy Markdown
Contributor Author

Follow-up commit 22ab1fa46 makes static validation fail closed and hardens artifacts. Rank shards now require immutable checkpoint and calibration-run identities, the merger rejects malformed maxima, runtime cache and backend compatibility are checked, empty PP stages emit shards, worker cleanup survives save errors, and older dynamic-only AITER builds keep working. The artifact and configuration suite passes 9 tests.

@maeehart
maeehart marked this pull request as draft August 11, 2026 21:57
@mergify

mergify Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

This pull request has merge conflicts that must be resolved before it can be
merged. Please rebase the PR, @maeehart.

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@mergify mergify Bot added the needs-rebase label Aug 13, 2026
@maeehart
maeehart force-pushed the maeehart/kimi-k3-gfx942-fp8-prefill-vllm branch from 22ab1fa to cf2fa9a Compare August 14, 2026 15:52
@maeehart

Copy link
Copy Markdown
Contributor Author

Rebased onto current main. The conflict resolution preserves current main's context-chunk output-buffer contract and adds the calibration parameters as keyword-only arguments.

Focused validation passes 11 tests. The Python 3.10 mypy hook passes for the changed modules, and Ruff check and formatting pass. The new head is cf2fa9addc. The PR remains draft until ROCm/aiter#4645 is available.

@maeehart

Copy link
Copy Markdown
Contributor Author

Follow-up a59030238f addresses the pre-commit findings from the rebased branch: the merge tool now has the required SPDX header, calibration shutdown uses torch.accelerator.synchronize(), and the unit test mocks the portable API. The focused suite passes 11 tests, and both previously failing portability checks pass locally.

@mergify mergify Bot removed the needs-rebase label Aug 14, 2026
@mergify

mergify Bot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

This pull request has merge conflicts that must be resolved before it can be
merged. Please rebase the PR, @maeehart.

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

maeehart and others added 6 commits August 24, 2026 13:25
Use the AITER D192/V128 kernel for BF16 Kimi-K3 requests once the cached context reaches 786432 tokens. Keep the path opt-in, quantize Q once per context pass, and fall back to the existing BF16 implementation when the shape or dependency is unsupported.

Co-authored-by: Cursor <cursoragent@cursor.com>
Signed-off-by: Markus Hartikainen <markus.hartikainen@amd.com>
The FP8 V path and 786432-token threshold are validated behavior, not independent configuration. Keep only the dependency opt-in until ROCm/aiter#4645 lands, and cover the fixed dispatch choices with focused tests.

Signed-off-by: Markus Hartikainen <markus.hartikainen@amd.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Dynamic per-head reductions add work to every long-context prefill step. Collect checkpoint-specific maxima after warmup, validate and load an external scale artifact before compilation, and use a one-kernel static quantizer while keeping the existing attention boundary.

Co-authored-by: Cursor <cursoragent@cursor.com>
Signed-off-by: Markus Hartikainen <markus.hartikainen@amd.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Require immutable checkpoint and calibration identities, validate cache and backend compatibility, and reject malformed rank maxima before merging. Preserve worker cleanup when calibration saving fails and keep dynamic FP8 available with older AITER builds.

Signed-off-by: Markus Hartikainen <markus.hartikainen@amd.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Current main types MLAAttention.impl as a generic AttentionImpl, so forwarding calibration state through ad-hoc attributes fails mypy. Narrow to MLACommonBaseImpl, declare the shared state, and update focused tests for AttentionConfig and the calibrated quantizer call.

Co-authored-by: Cursor <cursoragent@cursor.com>
Signed-off-by: Markus Hartikainen <markus.hartikainen@amd.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Add the required SPDX header to the calibration merge tool and use the accelerator-neutral synchronization API when saving rank shards. This keeps the ROCm path compatible with the repository-wide portability checks.

Co-authored-by: Cursor <cursoragent@cursor.com>
Signed-off-by: Markus Hartikainen <markus.hartikainen@amd.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@maeehart
maeehart force-pushed the maeehart/kimi-k3-gfx942-fp8-prefill-vllm branch from a590302 to 2d13454 Compare August 24, 2026 20:27
Co-authored-by: Cursor <cursoragent@cursor.com>
@mergify mergify Bot added cpu Related to CPU backends and removed needs-rebase labels Aug 24, 2026
@mergify

mergify Bot commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

This pull request has merge conflicts that must be resolved before it can be
merged. Please rebase the PR, @maeehart.

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@maeehart

Copy link
Copy Markdown
Contributor Author

I am closing this. It depends on ROCm/aiter#4645, which is now closed.

FMHA v3 BF16 already covers D192/V128 on gfx942. The FP8 kernel was faster only on the non-causal 4K/65K chunk, 3.498 ms versus 4.357 ms on MI325X, and slower on both causal shapes. Those times are in the close comment on ROCm/aiter#4645.

@maeehart maeehart closed this Sep 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cpu Related to CPU backends k3 kimi needs-rebase nvidia rocm Related to AMD ROCm

Projects

Status: Done
Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants