Skip to content

[None][feat] Support FP8 KV cache for non-MLA PrimsTS attention - #19396

Open
yuxianq wants to merge 7 commits into
NVIDIA:mainfrom
yuxianq:prims-tsfmha-fp8-non-mla
Open

yuxianq wants to merge 7 commits into
NVIDIA:mainfrom
yuxianq:prims-tsfmha-fp8-non-mla

Conversation

@yuxianq

@yuxianq yuxianq commented Sep 18, 2026 •

Copy link
Copy Markdown
Collaborator

Dev Engineer Review

  • Standard non-MLA PrimsTSFmha adds FP8 E4M3 KV-cache support for context, decode, and mixed batches. MLA remains limited to SM100 and SM103; standard attention adds SM107.
  • Decode supports host-float and float32 device-tensor scales. Compile identity includes the scale argument mode, which separates host- and device-scale plans in memory and persistent caches. Tensor scales remain on the GPU for CUDA graph replay.
  • Kernels produce native BF16/FP16 output. They do not use an intermediate FP8 output or output dequantization pass.
  • The adapter retains its active compiler capability check and depends on CUTLASS DSL 4.8.0. The vendor lock updates the FlashInfer source commit and tree digest.
  • The available information reports successful validation runs, but does not provide independently verified test results for this change. Model-quality and performance benchmarks have not been run.

QA Engineer Review

The changes add coverage for FP8 cache support, scale handling, graph replay, SM107 routing, and block-sparse rejection. Changed test functions are not detailed in the supplied evidence. Whether these tests appear in the CI or manual-QA lists could not be established. Coverage verdict: needs follow-up.

Per-File QA Perspective

  • 3rdparty/vendor_sources.lock.yaml — Verify the pinned FlashInfer commit and tree digest match the intended vendor source. Source attribution and promotion status are not established by this file summary.
  • tensorrt_llm/_torch/attention/backends/fmha/cute_dsl_mla.py — Verify MLA page-size and KV-cache dtype selection uses SUPPORTED_MLA_SMS, so adding SM107 to standard attention does not change MLA routing.
  • tensorrt_llm/_torch/attention/backends/fmha/prims_ts.py — Verify FP8 E4M3 validation, preprocessing scales, decode scale modes, cache-plan identity, and device-scale graph replay. Check standard SM107 routing and confirm MLA remains restricted to SM100 and SM103.
  • tests/unittest/_torch/attention/backend_case.py — Verify metadata uses context query lengths and generation cached-plus-new token counts for self-attention, and sequence lengths for cross-attention. Test-list status was not established.
  • tests/unittest/_torch/attention/sparse/test_prims_ts_block_sparse.py — Covers rejection of FP8 KV cache for paged block-sparse generation. Test-list status was not established.
  • tests/unittest/_torch/attention/test_cute_dsl_mla.py — Covers SM107 page-size exclusivity for 128-token BF16 pages. Test-list status was not established.
  • tests/unittest/_torch/attention/test_prims_ts_attention_backend.py — Covers FP8 MLA preprocessing and graph replay, wrapper metadata and workspace behavior, and FP8 decode with device-resident scales across split-KV modes. Test-list status was not established.
  • tests/unittest/_torch/attention/test_prims_ts_fmha.py — Covers standard-attention FP8 cache support across phases and cache managers, preprocessing scale forwarding, rejection paths, and dtype-dependent decode workspace sizing. Test-list status was not established.

Description

Enable FP8 E4M3 KV cache for standard non-MLA PrimsTSFmha context, decode, and mixed batches. Fused QKV preprocessing quantizes Q using the shared Q/K/V scale. The kernels consume FP8 Q/K/V and write native BF16/FP16 output, without an intermediate FP8 output or output dequantization pass.

Decode reuses bmm1_scale and bmm2_scale for host floats or float32 CUDA tensors. The plan selects the scale argument types before compilation, and _DecodeCompileSpec includes the scale argument mode, so both in-memory and persistent caches distinguish host/device-scale plans. The standalone reducer only merges already-scaled partial states and takes no scale arguments. Tensor scales stay on the GPU and can change in place during CUDA graph replay. The TRT-LLM forward path uses validate=False; optional wrapper metadata validation can read sequence lengths/page IDs on the host, but never reads device scale values.

Standard non-MLA PrimTS supports SM100, SM103, and SM107. The adapter relies on the pinned CUTLASS DSL 4.8.0 dependency and retains the active compiler capability check. MLA keeps its existing SM100/SM103 restriction. The shared KV policy helper retains allow_fp8_kv_cache=False for paged block-sparse attention, which does not support FP8 KV cache; standard PrimTS explicitly opts in.

The paired upstream contribution is FlashInfer #8021, ported to current upstream APIs. The vendor lock pins the FlashInfer scale API changes on top of trtllm-prims-ts-dev-20261012 at aa709061230a, retaining the TensorRT-LLM compatibility patch and original headers on existing FlashInfer files.

Test Coverage

Rebased 7382d0fb5920 onto 78145f88ea03:

  • Range-diff preserved all six original commits. Resolved the GPU availability conflict using the shared SM list, with a follow-up preserving the separate SM100/SM103 MLA page-size routing contract.
  • Pre-commit, targeted Python compilation, diff checks, and vendor verification passed.
  • Local TRT-LLM integration runs could not collect because available CI wheels predate new mainline bindings (build 67023 lacks BuildInfo.check_cuda_architecture_supported; build 67209 lacks kv_cache_manager_v2.ReusePolicy). The requested /bot run --disable-fail-fast CI run builds the matching runtime.
  • The paired upstream FlashInfer port passed 12 B300 GPU cases, a fresh-process cache reload, 17 API/compile-identity checks, and 3 bound-trace checks. Its GPU-generated trace matches the committed JSON.

B300 validation of the compile-spec/reducer cleanup at 540e86299e7d:

  • 260 TRT-LLM checks passed, including the new paged block-sparse FP8 rejection test, standard FP8 decode, and all four native FP8 decode reduction modes.
  • 14 FlashInfer GPU cases passed: 12 native FP8 decode configurations and two prepared sparse-decode cases using the other reducer caller. A fresh-process separate-reducer cache reload also passed.
  • 15 compile-identity/API checks passed. Scale argument mode now changes the compile-spec key without a separate cache-key override.
  • Pre-commit and offline/local/remote vendor verification passed.

B300 validation of the review fixes at 27c01417838f, with PyTorch 26.09 and CUTLASS DSL 4.8.0:

  • 225 adapter checks and 67 non-MLA backend cases passed. Coverage includes native/FP8 KV caches, BF16/FP16 activations, context/decode/mixed batches, cached context, and both cache managers.
  • 12 FlashInfer FP8 decode GPU cases passed with head dimensions 64/128/256 and all four reduction modes. Checks cover native BF16/FP16 output, host/device scales, both validation modes, and graph replay with updated scales. All 12 also passed in a fresh process using the persistent kernel cache.
  • Eager decode runs passed with PyTorch synchronization debugging set to error, and with Tensor.item() and Tensor.__float__() forbidden. CUDA graph capture/replay passed with those scalar-read guards.
  • 14 API/scale-type checks and 1,427 trace/template checks passed. The CPU trace/template run had 244 skips (unsupported CPU initialization, inapplicable paged-KV checks, and GPU requirements). The regenerated GPU trace matches the committed JSON.
  • Pre-commit and offline/local/remote vendor verification passed.

Earlier Rubin validation at ffeb74563528 on Hecate SM107, ARM64, PyTorch 26.09, CUDA 13.4, and CUTLASS DSL 4.8.0 (job 904798, exit 0): 294 tests passed (227 adapter checks and 67 non-MLA backend cases), with zero failures/errors/skips. A separate persistent-cache reload check also passed.

Model-quality and performance benchmarks have not been run.

PR Checklist

Please review the following before submitting your PR:

  • PR description clearly explains what and why. If using CodeRabbit's summary, please make sure it makes sense.

  • PR Follows TRT-LLM CODING GUIDELINES to the best of your knowledge.

  • Test cases are provided for new code paths (see test instructions)

  • If PR introduces API changes, an appropriate PR label is added - either api-compatible or api-breaking. For api-breaking, include BREAKING in the PR title.

  • Any new dependencies have been scanned for license and vulnerabilities

  • CODEOWNERS updated if ownership changes

  • Documentation updated as needed

  • Update tava architecture diagram if there is a significant design change in PR.

  • The reviewers assigned automatically/manually are appropriate for the PR.

  • Please check this after reviewing the above items as appropriate for this PR.

GitHub Bot Help

To see a list of available CI bot commands, please comment /bot help.

schema_version: 1
vendors:
  flashinfer-prims-ts:
    upstream_prs:
    - https://github.com/flashinfer-ai/flashinfer/pull/8021
    resolutions:
      39073f3bca4c23df39fe124aa07f383fa4e9052a:
        upstream_pr: https://github.com/flashinfer-ai/flashinfer/pull/8021
        reason: 'Introduces the device-scale implementation on the dated canonical vendor API. FlashInfer
          #8021 ports the same behavior to current main, which already has native FP8-to-BF16 output and
          uses softmax_scale/output_scale instead of bmm1_scale/bmm2_scale.'
      ace9ae803bdff01874bf8dd01e89ba59476dd174:
        upstream_pr: https://github.com/flashinfer-ai/flashinfer/pull/8021
        reason: 'Removes an obsolete overlap-validation helper while adapting the device-scale path to
          the refreshed canonical API. FlashInfer #8021 follows current main''s caller-owned non-overlap
          contract and does not reintroduce that helper; its tests and trace use the current API.'
      ad4b6bc638237f32496b7f7a379a76e28cccb360:
        upstream_pr: https://github.com/flashinfer-ai/flashinfer/pull/8021
        reason: 'Intermediate fix separating persistent host/device-scale kernel signatures. The final
          form in FlashInfer #8021 stores the scale argument mode in _DecodeCompileSpec, preserving the
          same cache-separation guarantee without the intermediate extra-key tuple.'
      2bbeaf3c78b237298ae18e5cbe7b32d09caff562:
        upstream_pr: https://github.com/flashinfer-ai/flashinfer/pull/8021
        reason: 'Reuses the existing scale arguments for floats or CUDA tensors. FlashInfer #8021 applies
          that change under current main''s renamed softmax_scale/output_scale API while retaining its
          runtime length, LSE, and attention-sink interfaces.'
      dd087c6568aa144bb7ceff1306e2568279ec5068:
        upstream_pr: https://github.com/flashinfer-ai/flashinfer/pull/8021
        reason: 'Moves scale mode into compile identity and removes unused reducer scales. FlashInfer
          #8021 carries both changes, adapted to current main''s additional runtime split, length, and
          LSE arguments.'

@yuxianq yuxianq added the api-compatible Accepted LLM API contract change that is backwards-compatible label Sep 18, 2026
@yuxianq

yuxianq commented Oct 9, 2026 •

Copy link
Copy Markdown
Collaborator Author

@yuxianq — vendor promotion needs author action:

The pinned temporary source commit 539197151dd22e751c8e2845fdcad32ccefe7911 does not contain the latest canonical branch tip ae3851ab5f958ba22f154059df5b38321f6369d2.

Fix: Fetch https://github.com/yuxianq/flashinfer.git / trtllm-prims-ts-dev-20261012 and rebase the temporary source branch prims-tsfmha-fp8-non-mla--kernels onto ae3851ab5f958ba22f154059df5b38321f6369d2. Push it, then use scripts/vendor/manage.py to update the consumer lock and vendored snapshot to the rebased SHA. The consumer lock's old pin alone is not a sufficient base; updating only the PR metadata or temporary branch without its lock pin will not fix this.

The bot will recheck automatically on a later poll.

@yuxianq

yuxianq commented Oct 13, 2026

Copy link
Copy Markdown
Collaborator Author

@yuxianq — the PrimTS upstream refresh #20155 has merged. Please update this source-update PR before merging it.

The new canonical source branch is yuxianq/flashinfer:trtllm-prims-ts-dev-20261012, initially pinned at ae312f7cc1723b06fda5168105ade0f328ee47d8.

  1. Rebase your temporary FlashInfer branch onto the new canonical branch; retain only changes not already included upstream, resolving any API differences.
  2. Rebase this TRT-LLM PR onto latest main, including the refreshed compatibility patch and integration changes.
  3. Keep vendors.flashinfer-prims-ts in 3rdparty/vendor_sources.lock.yaml pointing to your temporary source branch, update its immutable commit, and regenerate the selected vendored files and digests. Do not restore the old canonical branch/pin while resolving conflicts.
  4. Add the required <!-- vendor-promotion:start --> / <!-- vendor-promotion:end --> block to the PR description, listing upstream PRs for the remaining source changes (or a justified unpaired_reason). The vendor bot provides a copyable template.
  5. Verify the vendored snapshot and rerun the relevant tests and CI.

The publishing bot now targets the new dated canonical branch. After this source-update PR merges, its lock-only promotion will target that branch. The old trtllm-prims-ts-dev branch is intentionally unchanged.

@yuxianq
yuxianq force-pushed the prims-tsfmha-fp8-non-mla branch from 44788c6 to a29bcb6 Compare October 13, 2026 09:19
@yuxianq

yuxianq commented Oct 13, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #77487 [ run ] triggered by Bot. Commit: a29bcb6 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #77487 [ run ] completed with state SUCCESS. Commit: a29bcb6
/LLM/main/L0_MergeRequest_PR pipeline #63875 completed with status: 'SUCCESS'
Pipeline passed with automatic retried tests. Check the rerun report for details.

CI Report

Link to invocation

@yuxianq

yuxianq commented Oct 22, 2026

Copy link
Copy Markdown
Collaborator Author

Vendor validation: flashinfer-prims-ts

@yuxianq — Vendor promotion needs author action:

The pinned temporary source commit 539197151dd22e751c8e2845fdcad32ccefe7911 does not contain the latest canonical branch tip ae3851ab5f958ba22f154059df5b38321f6369d2.

Fix: Fetch https://github.com/yuxianq/flashinfer.git / trtllm-prims-ts-dev-20261012 and rebase the temporary source branch prims-tsfmha-fp8-non-mla--kernels onto its latest tip (observed ae3851ab5f958ba22f154059df5b38321f6369d2). Push it, then use scripts/vendor/manage.py to update the consumer lock and vendored snapshot to the rebased SHA. The consumer lock's old pin alone is not a sufficient base; updating only the PR metadata or temporary branch without its lock pin will not fix this.

The bot will recheck automatically on a later poll.

Checked PR revision: a29bcb6b922b. This is a snapshot; newer results are posted as new comments.

Checked source: https://github.com/yuxianq/flashinfer.git / prims-tsfmha-fp8-non-mla--kernels, pin 539197151dd22e751c8e2845fdcad32ccefe7911.

Supersedes previous vendor validation.

@yuxianq

yuxianq commented Oct 23, 2026

Copy link
Copy Markdown
Collaborator Author

Vendor validation: flashinfer-prims-ts

@yuxianq — Vendor promotion needs maintainer action:

Waiting for the preceding vendor promotion: the base lock still points to repository https://github.com/heyuhhh/flashinfer.git, branch trtllm-prims-ts-dev.

Fix: A maintainer must finish the preceding lock-only promotion back to yuxianq/flashinfer / trtllm-prims-ts-dev-20261012. After it merges, the author should rebase this consumer PR onto the latest base branch and rebase its temporary source branch onto the new canonical pin, then update the lock/vendor snapshot. No metadata edit can unblock the preceding promotion.

The bot will recheck automatically on a later poll.

Checked PR revision: a29bcb6b922b. This is a snapshot; newer results are posted as new comments.

Supersedes previous vendor validation.

@yuxianq

yuxianq commented Oct 23, 2026

Copy link
Copy Markdown
Collaborator Author

Vendor validation: flashinfer-prims-ts

@yuxianq — Vendor promotion needs author action:

Source update is not a fast-forward.

Fix: Fetch canonical repository https://github.com/yuxianq/flashinfer.git, branch trtllm-prims-ts-dev-20261012, and rebase the temporary source branch prims-tsfmha-fp8-non-mla--kernels onto its latest tip without merge commits, not just the consumer lock's pin 0e0761ef5ef10cb0762cc1b890a5c1a329bb49bf. Then use scripts/vendor/manage.py to update 3rdparty/vendor_sources.lock.yaml and the vendored snapshot to the rebased SHA, and push the source branch and consumer PR. Editing metadata alone will not fix this.

The bot will recheck automatically on a later poll.

Checked PR revision: a29bcb6b922b. This is a snapshot; newer results are posted as new comments.

Checked source: https://github.com/yuxianq/flashinfer.git / prims-tsfmha-fp8-non-mla--kernels, pin 539197151dd22e751c8e2845fdcad32ccefe7911.

Supersedes previous vendor validation.

@yuxianq

yuxianq commented Oct 26, 2026

Copy link
Copy Markdown
Collaborator Author

Vendor validation: flashinfer-prims-ts

@yuxianq — Vendor promotion needs maintainer action:

Waiting for the preceding vendor promotion: the base lock still points to repository https://github.com/yunruis/flashinfer.git, branch trtllm-prims-ts-dev-20261023.

Fix: A maintainer must finish the preceding lock-only promotion back to yuxianq/flashinfer / trtllm-prims-ts-dev-20261012. After it merges, the author should rebase this consumer PR onto the latest base branch and rebase its temporary source branch onto the new canonical pin, then update the lock/vendor snapshot. No metadata edit can unblock the preceding promotion.

The bot will recheck automatically on a later poll.

Checked PR revision: a29bcb6b922b. This is a snapshot; newer results are posted as new comments.

Supersedes previous vendor validation.

@yuxianq

yuxianq commented Oct 26, 2026

Copy link
Copy Markdown
Collaborator Author

Vendor validation: flashinfer-prims-ts

@yuxianq — Vendor promotion needs author action:

Source update is not a fast-forward.

Fix: Fetch canonical repository https://github.com/yuxianq/flashinfer.git, branch trtllm-prims-ts-dev-20261012, and rebase the temporary source branch prims-tsfmha-fp8-non-mla--kernels onto its latest tip without merge commits, not just the consumer lock's pin aa709061230a58858375c513056e7733fa74294a. Then use scripts/vendor/manage.py to update 3rdparty/vendor_sources.lock.yaml and the vendored snapshot to the rebased SHA, and push the source branch and consumer PR. Editing metadata alone will not fix this.

The bot will recheck automatically on a later poll.

Checked PR revision: a29bcb6b922b. This is a snapshot; newer results are posted as new comments.

Checked source: https://github.com/yuxianq/flashinfer.git / prims-tsfmha-fp8-non-mla--kernels, pin 539197151dd22e751c8e2845fdcad32ccefe7911.

Supersedes previous vendor validation.

@yuxianq
yuxianq force-pushed the prims-tsfmha-fp8-non-mla branch from a29bcb6 to 50de5d1 Compare October 29, 2026 07:20
@yuxianq

yuxianq commented Oct 29, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run

@yuxianq

yuxianq commented Oct 29, 2026

Copy link
Copy Markdown
Collaborator Author

Vendor validation: flashinfer-prims-ts

@yuxianq — Vendor promotion metadata and source attribution are valid. This is not a code-review approval. Promotion still requires the source PR to merge.

Checked PR revision: 50de5d1e9ad4. This is a snapshot; newer results are posted as new comments.

Checked source: https://github.com/yuxianq/flashinfer.git / prims-tsfmha-fp8-non-mla--kernels, pin ad4b6bc638237f32496b7f7a379a76e28cccb360.

Supersedes previous vendor validation.

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #81384 [ run ] triggered by Bot. Commit: 50de5d1 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #81384 [ run ] completed with state FAILURE. Commit: 50de5d1
/LLM/main/L0_MergeRequest_PR pipeline #67060 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@yuxianq

yuxianq commented Oct 30, 2026

Copy link
Copy Markdown
Collaborator Author

Vendor validation: flashinfer-prims-ts

@yuxianq — Vendor promotion metadata and source attribution are valid. This is not a code-review approval. Promotion still requires the source PR to merge.

Checked PR revision: 27c01417838f. This is a snapshot; newer results are posted as new comments.

Checked source: https://github.com/yuxianq/flashinfer.git / prims-tsfmha-fp8-non-mla--kernels, pin 2bbeaf3c78b237298ae18e5cbe7b32d09caff562.

Supersedes previous vendor validation.

@yuxianq

yuxianq commented Oct 30, 2026

Copy link
Copy Markdown
Collaborator Author

Vendor validation: flashinfer-prims-ts

@yuxianq — Vendor promotion metadata and source attribution are valid. This is not a code-review approval. Promotion still requires the source PR to merge.

Checked PR revision: 540e86299e7d. This is a snapshot; newer results are posted as new comments.

Checked source: https://github.com/yuxianq/flashinfer.git / prims-tsfmha-fp8-non-mla--kernels, pin dd087c6568aa144bb7ceff1306e2568279ec5068.

Supersedes previous vendor validation.

Signed-off-by: Yuxian Qiu <142763828+yuxianq@users.noreply.github.com>
Signed-off-by: Yuxian Qiu <142763828+yuxianq@users.noreply.github.com>
Signed-off-by: Yuxian Qiu <142763828+yuxianq@users.noreply.github.com>
Signed-off-by: Yuxian Qiu <142763828+yuxianq@users.noreply.github.com>
Signed-off-by: Yuxian Qiu <142763828+yuxianq@users.noreply.github.com>
…rguments

Signed-off-by: Yuxian Qiu <142763828+yuxianq@users.noreply.github.com>
Signed-off-by: Yuxian Qiu <142763828+yuxianq@users.noreply.github.com>
@yuxianq
yuxianq force-pushed the prims-tsfmha-fp8-non-mla branch from 540e862 to 7382d0f Compare October 30, 2026 14:52
@yuxianq
yuxianq marked this pull request as ready for review October 30, 2026 14:53
@yuxianq

yuxianq commented Oct 30, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #81702 [ run ] triggered by Bot. Commit: 7382d0f Link to invocation

@coderabbitai

coderabbitai Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 78145f8 and 7382d0f.

Files ignored due to path filters: 3
  • tensorrt_llm/_torch/attention/backends/prims_ts/decode.py is excluded by !tensorrt_llm/_torch/attention/backends/prims_ts/**
  • tensorrt_llm/_torch/attention/backends/prims_ts/kernels/fmha_decode/fmha_decode_kernel.py is excluded by !tensorrt_llm/_torch/attention/backends/prims_ts/**
  • tensorrt_llm/_torch/attention/backends/prims_ts/kernels/fmha_decode/reduction.py is excluded by !tensorrt_llm/_torch/attention/backends/prims_ts/**
Files selected for processing: 8
  • 3rdparty/vendor_sources.lock.yaml
  • tensorrt_llm/_torch/attention/backends/fmha/cute_dsl_mla.py
  • tensorrt_llm/_torch/attention/backends/fmha/prims_ts.py
  • tests/unittest/_torch/attention/backend_case.py
  • tests/unittest/_torch/attention/sparse/test_prims_ts_block_sparse.py
  • tests/unittest/_torch/attention/test_cute_dsl_mla.py
  • tests/unittest/_torch/attention/test_prims_ts_attention_backend.py
  • tests/unittest/_torch/attention/test_prims_ts_fmha.py

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 11 remain after this review.

Walkthrough

PrimsTS FMHA now includes SM107 for standard attention and supports FP8 E4M3 KV caches for standard attention. MLA remains limited to SM100 and SM103. The changes update validation, preprocessing, scale handling, decode planning, and related tests.

Changes

PrimsTS FMHA

Layer / File(s) Summary
Architecture and KV-cache support policy
3rdparty/vendor_sources.lock.yaml, tensorrt_llm/_torch/attention/backends/fmha/prims_ts.py, tensorrt_llm/_torch/attention/backends/fmha/cute_dsl_mla.py, tests/unittest/_torch/attention/test_prims_ts_fmha.py, tests/unittest/_torch/attention/test_cute_dsl_mla.py, tests/unittest/_torch/attention/sparse/test_prims_ts_block_sparse.py
The vendor pin changes. PrimsTS availability adds SM107 for standard attention, while MLA remains limited to SM100 and SM103. Paged-cache validation permits supported FP8 E4M3 requests and checks their scales. Tests cover availability, cache modes, and page-size eligibility.
FP8 preprocessing and wrapper execution
tensorrt_llm/_torch/attention/backends/fmha/prims_ts.py, tests/unittest/_torch/attention/test_prims_ts_fmha.py, tests/unittest/_torch/attention/test_prims_ts_attention_backend.py
Context and generation wrappers pass FP8 flags and preprocessing scales, reinterpret processed queries as FP8, and use FP8 dtype for decode planning and workspace sizing. Tests cover wrapper inputs, scales, decode output, and graph replay.
Backend integration coverage
tests/unittest/_torch/attention/backend_case.py, tests/unittest/_torch/attention/test_prims_ts_attention_backend.py
Backend test metadata now uses phase-specific prompt lengths. Integration tests add native and FP8 KV-cache cases and apply separate architecture gates for general attention and MLA.

Priority: Normal

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant PrimsTSFmha
  participant FP8Preprocessing
  participant PrimTSFMHA
  PrimsTSFmha->>FP8Preprocessing: Preprocess queries and return BMM1 and BMM2 scales
  PrimsTSFmha->>PrimTSFMHA: Submit FP8 query and preprocessing scales
  PrimTSFMHA-->>PrimsTSFmha: Return attention output
Loading

Suggested reviewers: heyuhhh, yuanjingx87

Merge Risk: Minimal · up to 7382d

No actionable merge-blocking issue remains after normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 27.27% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title names the main change: FP8 KV cache support for the non-MLA PrimsTS attention backend. The changeset matches this. It adds FP8 E4M3 KV-cache handling for standard PrimsTSFmha context, decode…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The pull request includes the required Description, Test Coverage, and PR Checklist sections. It clearly explains the FP8 KV-cache changes, implementation scope, vendor updates, validation results, an…
Full details: Title check

Explanation

The title names the main change: FP8 KV cache support for the non-MLA PrimsTS attention backend. The changeset matches this. It adds FP8 E4M3 KV-cache handling for standard PrimsTSFmha context, decode, and mixed batches, extends SM107 support for standard FMHA, and keeps MLA on SM100/SM103. The title follows the required [None][feat] format and is concise.

Full details: Description check

Explanation

The pull request includes the required Description, Test Coverage, and PR Checklist sections. It clearly explains the FP8 KV-cache changes, implementation scope, vendor updates, validation results, and known benchmark limitations. The checklist is present and marked as reviewed.

Full details: Docstring Coverage

Explanation

Docstring coverage is 27.27% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 22 functions across 7 files. (1 skipped: 1 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@yuxianq

yuxianq commented Oct 30, 2026 •

Copy link
Copy Markdown
Collaborator Author

@farazkh80, could you help to review this PR as trt-llm-torch-attention-devs? Thanks~

Assignment explanation
Componentsfmha/prims-ts (40%); kernels/prims-ts (35%); integration/attention-tests (20%); fmha/cute-dsl-mla (3%); integration/dependencies (2%)
Tagsalgorithm:dense (100%); representation:gqa (90%); representation:mla (10%); phase:prefill (35%); phase:decode (65%); features:quantization (80%); features:paged-kv (20%); context:llm (100%)
PR effort8 points — Requires deep tracing of FP8 scale handling across adapter policy, wrapper compilation, kernel execution and split-KV reduction, plus architecture-specific routing. This is a substantial attention contract change; no new model architecture is introduced.
ImportanceImportant — Sensitive numerical and compilation contracts change: device scales require GPU loading and log2 conversion, scale mode enters compile identity, and the reducer loses scale parameters. Incorrect coordination could silently corrupt FP8 attention results.
Affinity (0–1)0.525 component/tag match; 0.394 after PIC preference
Outstanding points at selection25 → 33 (+8)
Points already reserved on this PR0
Effective weight1
Completed review points (preceding 168 hours)27
Combined points after assignment60
Demand-derived target52.00 points (soft share)
Additional fair share before assignment0.00 points
Share explanationWhole PR / qualification or coverage constraint exceeds a soft share; assignment is allowed.
Selection ruleaffinity with 0.3-share guard
Assignment scope (farazkh80)all

Affinity and workload are snapshots at selection, not live counters. Existing reservations on this PR are counted once.

@yuxianq
yuxianq requested review from farazkh80 and removed request for PerkzZheng and pengbowang-nv October 30, 2026 15:11
@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #81702 [ run ] completed with state SUCCESS. Commit: 7382d0f
/LLM/main/L0_MergeRequest_PR pipeline #67363 completed with status: 'SUCCESS'
Pipeline passed with automatic retried tests. Check the rerun report for details.

CI Report

Link to invocation

@farazkh80 farazkh80 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed from attention perspective. One high item (H1, FP8 V-tail), the rest are questions.

params.sequence_lengths,
params.batch_size,
)
use_fp8 = QuantMode(attn.quant_mode).has_fp8_kv_cache()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

zeroPagedVCacheTail only runs when T == TCache, so FP8 caches never get a zeroed V tail, but _get_or_plan_context_wrapper still sets paged_v_tail_is_zero=True and skips the kernel's own clear. A stale NaN byte in the tail would then leak through P·V.

Should that be False for FP8 caches, plus an fp8-kv case in test_prims_ts_context_receives_zeroed_v_tail?

if mask_type not in (AttentionMaskType.causal, AttentionMaskType.padding):
return False, f"attention mask type {mask_type} is not supported."
policy_reason = get_paged_kv_policy_unsupported_reason(attn, meta)
policy_reason = get_paged_kv_policy_unsupported_reason(attn, meta, allow_fp8_kv_cache=True)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

FP8 KV non-MLA layers used to fall through to flashinfer_trtllm_gen (fallback on SM107); with +prims_ts they now run PrimTS, and the description says no perf benchmarks were run.

Do you have decode latency numbers against trtllm-gen FP8 at small and large batch?

],
)
@pytest.mark.parametrize("dtype", ["bfloat16", "float16"], ids=["bf16", "fp16"])
@pytest.mark.parametrize("kv_dtype", [None, "fp8"], ids=["native-kv", "fp8-kv"])

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The FP8 backend cases use a 0.4–0.43 atol against an unquantized golden, loose enough to hide drift from E4M3 Q and P, and test_prims_ts_bfloat16 only covers BF16 KV.

Could we add an FP8-KV variant of that accuracy test to l0_b200?

supports_per_tensor_fp8 = True

SUPPORTED_SMS = frozenset({100, 103})
SUPPORTED_SMS = frozenset({100, 103, 107})

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

PrimsTSBlockSparseFmha inherits SUPPORTED_SMS and isn't opt-in, so this also enables block-sparse PrimTS on SM107, moving VisualGen VSA off its dense fine stage onto kernels whose tests skip SM107.

Intended, or should block-sparse keep {100, 103}?

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

api-compatible Accepted LLM API contract change that is backwards-compatible

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants