Skip to content

[None][feat] DeepSeek-V4.1: CSA2 PrimTS sparse MLA provider, default on SM100/SM103/SM107 - #22659

Open
kris1025 wants to merge 8 commits into
NVIDIA:mainfrom
kris1025:user/linquanh/dsv41-csa2-prims-ts
Open

kris1025 wants to merge 8 commits into
NVIDIA:mainfrom
kris1025:user/linquanh/dsv41-csa2-prims-ts

Conversation

@kris1025

@kris1025 kris1025 commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Dev Engineer Review

  • Default backend change: PrimTS becomes the default on SM100, SM103, and SM107. Auto selection keeps native-only support when packed sparse attention or explicit FP8-staging configuration requires it. Operators who need native compute must set TRTLLM_CSA2_COMPUTE_BACKEND=trtllm. Confirm that this default is intended.
  • Staging selection: Under auto selection, either explicit use_fp8_staging value selects trtllm-gen. Forcing PrimTS rejects False as it rejects True.
  • Changed fp8 meaning: Explicit fp8 now selects swa_fp8 (512-byte unit-scale E4M3, no footer). fp8_ds_mla, auto, and bfloat16 use the 528-byte layout. Existing deployments that rely on fp8 need review.
  • Disaggregated serving: Context and generation instances must use the same SWA layout. Transfers do not convert layouts. A test checks that a mismatched SWA mapping raises a region-size error. No runtime guard is described.
  • API changes: Several public signatures gain keyword-only parameters, including write_layer_rows, store_layer_rows, direct_sparse_decode, and select_csa2_backend. dense_mxfp8_gemm_compiled gains a required rows argument, which breaks existing callers. Check all call sites.
  • Scope: 85 files, +24,311/−2,412 lines. The diff exceeds GitHub's display limit.
  • Dependency pin: The flashinfer-prims-ts vendor entry points to a fork branch and commit, not an upstream release. Vendor promotion requires the source PR to merge.
  • CI status: Failures are reported for pipelines #71458, #71493, and #71553. The PR description attributes them to SM120 test selection and a B300 CSA2-entry timeout, addressed by commits 17 and 18. Current-head results are not available.
  • Performance: New fast paths (keys-as-M decode, weight prefetch, deferred O-B boundary) lack final-state benchmark data. GB300 measurements are in progress.

QA Engineer Review

Changed test files and lists:

  • Unit tests under tests/unittest/_torch/attention/sparse/csa2/ changed. These include test_backend.py, test_cache_manager.py, test_direct_decode.py, test_fused_decode.py, test_indexer.py, test_kernel.py, test_metadata.py, test_module.py, and _utils.py. test_prims_ts_fp8_producer.py and test_prims_ts_fp8_quantization.py are new.
  • Multi-GPU tests test_allreduce.py and test_deepseek_v41_attention_dp.py changed. test_deepseek_v41_snapshots.py and disaggregated/test_csa2_kv_transfer.py also changed.
  • Test-list changes: l0_b200.yml, l0_b300.yml, l0_gb200_multi_gpus.yml, l0_gb300.yml, l0_gr100.yml, and tests/integration/defs/.test_durations.

Test coverage:

  • fp8 and fp8_ds_mla SWA layouts, PrimTS producer and quantization, raw selections, MAIN bank decoding, CUDA Graph replay, and keys-as-M decode are covered.
  • Error paths include format mismatch rejection, invalid slots, mixed-device inputs, and rejected host transforms.
  • l0_b200 and l0_b300 split the aggregate CSA2 entry into three runs. The directory run excludes test_backend.py and the PrimTS FP8 producer test, which run as separate entries. Confirm that no CSA2 file is dropped.
  • New multi-GPU tests are added to the GB200 list. New GB300 and SM107 entries are added.
  • FlashInfer failures are attributed to the dev-branch tip's inability to JIT-build nv_internal sources. This attribution is not verified.

Coverage verdict: needs follow-up. Current-head CI results are not available. The reported failures and pending GB300 measurements are unresolved.

Per-File QA Perspective

  • _prims_ts_*.py, prims_ts.py, direct_decode.py, projection.py, kernel.py: New or changed kernel paths. Verify PrimTS output against native output and FP8 accuracy.
  • backend.py, params.py, module.py: Backend selection changes and the default PrimTS path on SM100/103/107. Verify override behavior and fp8 versus fp8_ds_mla routing.
  • cache_manager.py, quantization.py, metadata.py: Row width depends on the KV dtype. Verify sizing and disaggregated transfer consistency.
  • mhc_* kernels, mhc_lowm.py, hyper_connection.py, modeling_deepseekv41.py: New Blackwell boundary and fusion paths. Verify graph-capture and multi-GPU all-reduce behavior.
  • low_m_gemm.py, query_projection.py, csa2_weight_prefetch.py: Carveout and tile selection changes. Verify performance and correctness on Blackwell.
  • 3rdparty/vendor_patches/flashinfer-prims-ts.patch, vendor_sources.lock.yaml: New compile-cache modes and a fork pin. Verify the pinned commit builds.
  • Docs (kvcache.md, ATTENTION_DEVELOPER_GUIDE.md, CSA2 README.md): Document the new fp8 semantics and the backend override. Verify they match the code.
  • Test-list YAML and .test_durations: Verify all split CSA2 entries run and new tests appear in the correct pre-merge lists.

Description

Adds PrimTS as a CSA2 sparse MLA compute provider for DeepSeek-V4.1. PrimTS attends the packed SWA and NVFP4 MAIN KV caches directly in the vendored PrimTS MLA decode kernels, instead of staging them for the native kernel.

  • Selection: on SM100/SM103/SM107, auto picks PrimTS for kv_cache_config.dtype: fp8; the other KV dtypes keep the native provider. TRTLLM_CSA2_COMPUTE_BACKEND=trtllm|prims_ts overrides. Where PrimTS cannot run on the fp8 KV cache (CuTe DSL toolchain, vendored internals), auto raises and names the fixes.
  • KV format: fp8 now stores SWA as 512-byte E4M3 rows at one power-of-two scale (TRTLLM_CSA2_SWA_FP8_AMAX; unit by default, saturating at 448). fp8_ds_mla keeps the 528-byte scaled records and the native provider, which is how to keep main's behavior. TRTLLM_CSA2_Q_FP8_AMAX scales PrimTS's E4M3 query the same way. Disaggregated peers must use the same format and scale; registration rejects a mismatch.
  • Performance: on seven GB300 AgentX serving points (one node set per pair, at 14391f2), PrimTS (kv fp8) gives 3.2% to 5.2% higher P90 interactivity than native (kv fp8_ds_mla) on the attention-DP points and matches it on the TEP8 points; output throughput per GPU is within -0.6% to +3.5%. See Performance below.

Commits:

  1. Vendor PrimTS with FlashInfer's DeepSeek-V4.1 decode follow-up (below).
  2. The provider, its perf series and first review fixes.
  3. Power-of-two fp8 scales for the SWA rows and the PrimTS query.
  4. Provider selection: PrimTS by default only on the fp8 KV cache, and raise where it cannot run there.
  5. Review follow-ups: selection-bank reservation, pass-graph direct decode, provider capabilities, code shared by native staging and PrimTS, warmup precompile, MAIN bank reuse, docs.
  6. Disaggregated: reject a CSA2 peer whose SWA rows differ in size or storage scale.
  7. Name CSA2's KV head dimension in the cache manager (review).
  8. Type the compiled producer probes as three-argument calls (test).

Vendored PrimTS

Commit 1 pins tensorrt_llm/_torch/attention/backends/prims_ts to kris1025/flashinfer linquanh/trtllm-prims-ts-dev-ds41-followup-r5 at c3e7d63d13: main's PrimTS pin (bastianhagedorn/flashinfer trtllm-prims-ts-decode-corr-cluster-acquire-20261124b at 9497c8892c, #21852: the dev branch d81912f0b plus flashinfer-ai/flashinfer#9224) plus flashinfer-ai/flashinfer#6988, #9315 and #9375, and #9701 as it merged. -r5 is -r4 (76117c8a60) rebased onto that pin: -r4's cherry-pick of #9224 is already there, so the selected tree is unchanged. -r4 is -r3 (d8c40b52f9) plus #9701's last four commits, cherry-picked unchanged: a WS lane's four MXFP8 block scales stored as one word, the PDL wait moved ahead of TMEM allocation, and two tests. The compatibility patch is main's plus one absolute import. All four upstream PRs have merged.

schema_version: 1
vendors:
  flashinfer-prims-ts:
    upstream_prs:
      - https://github.com/flashinfer-ai/flashinfer/pull/6988
      - https://github.com/flashinfer-ai/flashinfer/pull/9315
      - https://github.com/flashinfer-ai/flashinfer/pull/9375
      - https://github.com/flashinfer-ai/flashinfer/pull/9701
    resolutions:
      b1d5b5ef55dbbe92346a96acd6f74ca3683d9c9a:
        upstream_pr: https://github.com/flashinfer-ai/flashinfer/pull/9701
        reason: >-
          Ruff formatting of #9701's decode schedule changes. #9701 folded it into
          89f39f8c0b91a847c5147bc12ee21449e1224496 before it merged; that commit adds
          all 18 of its lines.
      446b4bf1fa74d3817d7711bfd7c9c48521c8433d:
        upstream_pr: https://github.com/flashinfer-ai/flashinfer/pull/9701
        reason: >-
          Config comment naming the callers that set pdl_wait_after_prologue. #9701
          folded it into 99a6ca309e0eeff2291ad7f4ce45cc487cc194dc before it merged;
          that commit adds all six of its lines.
      9f600a65d1f5638840d6765d386f960c7996befc:
        upstream_pr: https://github.com/flashinfer-ai/flashinfer/pull/9315
        reason: >-
          Dev-branch adaptation with no upstream counterpart: FlashInfer main has no
          CUTLASS DSL 4.9 task_compat layer. Routes the decode-loop bounds and raw K/V
          stage reads that #9315 (and one that #9375) added through the dev branch's
          runtime_domain_end and consumer_work_stage helpers, which return the same
          values on the CuTe DSL 4.7/4.8 task API.

Performance

GB300 NVL72 (OCI JHB), AgentX disaggregated serving of DeepSeek-V4.1-Flash NVFP4 with DSpark, at 14391f2 (the head before the rebase onto 86f778c; that rebase brings in only main's changes). Both providers run the same wheel and image and differ only in kv_cache_config.dtype: PrimTS is fp8 (auto selects PrimTS), native is fp8_ds_mla with TRTLLM_CSA2_COMPUTE_BACKEND=trtllm. Each pair ran on one node set, PrimTS first and native after it, with a 45-minute measurement window, scored with the AgentX harness's metric code; no request failed. Values are PrimTS vs native.

Point Layout GPUs P90 interactivity (TPS/user) Output tok/s/GPU ITL P50 (ms) TTFT P50 / P90 (s) GEN step (ms)
c7000 5xDEP2+1xDEP8, b320 18 95.06 vs 90.33 (+5.2%) 12,198 vs 11,784 (+3.5%) 10.30 vs 10.87 (-5.2%) 6.79 / 13.97 vs 7.59 / 13.92 58.4 vs 62.1 (-6.0%)
c7900 7xDEP2+1xDEP16, b128 30 182.48 vs 174.22 (+4.7%) 10,752 vs 10,636 (+1.1%) 5.30 vs 5.61 (-5.5%) 1.34 / 7.71 vs 1.64 / 7.21 30.0 vs 31.7 (-5.4%)
c5100 5xDEP2+1xDEP16 26 253.16 vs 243.90 (+3.8%) 8,629 vs 8,573 (+0.7%) 3.86 vs 4.01 (-3.7%) 1.00 / 5.10 vs 1.10 / 4.98 21.8 vs 22.7 (-3.9%)
c7600 7xDEP2+1xDEP32, b25 46 353.36 vs 342.47 (+3.2%) 5,494 vs 5,530 (-0.6%) 2.64 vs 2.72 (-2.9%) 14.50 / 16.81 vs 14.22 / 16.04 18.1 vs 18.4 (-1.8%)
c240 1xDEP2+4xTEP8 34 694.44 vs 694.44 (+0.0%) 292 vs 292 (-0.2%) 1.37 vs 1.38 (-0.7%) 7.54 / 12.72 vs 7.53 / 12.77 7.6 vs 7.6 (-0.3%)
c140 1xDEP2+4xTEP8, b2 34 980.39 vs 980.39 (+0.0%) 208 vs 208 (+0.3%) 0.96 vs 0.96 (+0.0%) 3.00 / 8.58 vs 2.95 / 8.90 6.4 vs 6.4 (-0.1%)
c84 1xDEP2+4xTEP8 34 1,428.57 vs 1,408.45 (+1.4%) 139 vs 139 (-0.2%) 0.67 vs 0.67 (+0.0%) 2.09 / 8.60 vs 2.02 / 8.38 4.4 vs 4.4 (-0.4%)
  • On the attention-DP points PrimTS shortens the GEN step by 1.8% to 6.0%, which gives 3.2% to 5.2% higher P90 interactivity; output throughput per GPU moves -0.6% to +3.5%. The c5100 gap matches three earlier same-node pairs on the bring-up branch (+3.4% to +3.9%).
  • The TEP8 points are level; c84's +1.4% is the rounding of a 0.70 vs 0.71 ms P90 ITL.
  • Absolute values depend on the node set, so only same-node pairs are compared: PrimTS measured 144.5 TPS/user and 9,279 output tok/s/GPU at c7900 on another node set, against 182.5 and 10,752 here. c7600's node set was prefill-bound (TTFT P50 about 14 s on both providers).
  • A 45-minute window reads somewhat lower than a 60-minute one, which includes less of the client's ramp-up.

Test Coverage

  • Unit tests: tests/unittest/_torch/attention/sparse/csa2/ (PrimTS backend, module, metadata, producer and quantization tests), tests/unittest/disaggregated/test_peer.py, test_rank_info.py and test_csa2_kv_transfer.py.
  • Test lists: CSA2 PrimTS entries in l0_b200, l0_b300, l0_gb300 and l0_gr100; the decoder pass-graph test for both providers in l0_gb200_multi_gpus and l0_gb300_multi_gpus.
  • On B200 at an earlier head: the CSA2 test directory and the disaggregated transfer tests pass (1,495 passed, 28 skipped).
  • CI: every single-GPU stage passed on an earlier base (#87262); the current head has not run yet. Multi-GPU stages need the ci: full pre-merge approved label.

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.

🤖 Generated with Claude Code

@kris1025

Copy link
Copy Markdown
Collaborator Author

/bot run

@yuxianq

yuxianq commented Nov 20, 2026

Copy link
Copy Markdown
Collaborator

Vendor validation: flashinfer-prims-ts

@kris1025 — Vendor promotion needs author action:

Missing vendor-promotion markers in the PR description: <!-- vendor-promotion:start -->, <!-- vendor-promotion:end -->.

Fix: Edit this PR's description—not a comment—and insert the complete block below. Replace the example upstream PR URL with your actual PR URL. If there is genuinely no paired upstream PR, replace upstream_prs with a nonempty unpaired_reason explaining why.

<!-- vendor-promotion:start -->
```yaml
schema_version: 1
vendors:
  flashinfer-prims-ts:
    upstream_prs:
      - https://github.com/flashinfer-ai/flashinfer/pull/123
```
<!-- vendor-promotion:end -->

The bot will recheck automatically on a later poll.

Checked PR revision: a934a3b19ecf. This is a snapshot; newer results are posted as new comments. Observed dev/upstream tip SHAs may be stale: tip movement alone does not post a new comment when the result is unchanged. Fetch the live branch before rebasing or choosing a new pin.

Checked source: https://github.com/kris1025/flashinfer.git / linquanh/deepseek-v41-prims-ts-decode-followup, pin 86f85c6c23dce9e2336ee703f24c2b39c2ca7c05.

@yuxianq yuxianq 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.

Vendor validation result: needs maintainer action.

Latest vendor validation and step-by-step fix.

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #86253 [ run ] triggered by Bot. Commit: a934a3b Link to invocation

@yuxianq

yuxianq commented Nov 20, 2026

Copy link
Copy Markdown
Collaborator

Vendor validation: flashinfer-prims-ts

@kris1025 — 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-20261107, and rebase the temporary source branch linquanh/deepseek-v41-prims-ts-decode-followup onto its latest tip without merge commits, not just the consumer lock's pin 31fe2dbd6b65cca758c1318f177b315be0c33778. 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: a934a3b19ecf. This is a snapshot; newer results are posted as new comments. Observed dev/upstream tip SHAs may be stale: tip movement alone does not post a new comment when the result is unchanged. Fetch the live branch before rebasing or choosing a new pin.

Checked source: https://github.com/kris1025/flashinfer.git / linquanh/deepseek-v41-prims-ts-decode-followup, pin 86f85c6c23dce9e2336ee703f24c2b39c2ca7c05.

Supersedes previous vendor validation.

@kris1025
kris1025 force-pushed the user/linquanh/dsv41-csa2-prims-ts branch from a062deb to 3ebb708 Compare December 2, 2026 05:12
@kris1025

kris1025 commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #88614 [ run ] triggered by Bot. Commit: 3ebb708 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #88614 [ run ] completed with state FAILURE. Commit: 3ebb708
/LLM/main/L0_MergeRequest_PR pipeline #73597 completed with status: 'ABORTED'

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

Link to invocation

@kris1025

kris1025 commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #88622 [ run ] triggered by Bot. Commit: 3ebb708 Link to invocation

@kris1025
kris1025 force-pushed the user/linquanh/dsv41-csa2-prims-ts branch from 3ebb708 to 14391f2 Compare December 2, 2026 07:12
@kris1025

kris1025 commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #88630 [ run ] triggered by Bot. Commit: 14391f2 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #88622 [ run ] completed with state ABORTED. Commit: 3ebb708

Link to invocation

@trtllm-agent-review trtllm-agent-review 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.

Thanks for the PR. Adds a PrimTS sparse MLA provider for DeepSeek-V4.1's CSA2 attention that reads the fp8 SWA and NVFP4 MAIN caches directly and becomes the default for kv_cache_config.dtype: fp8 on SM100/SM103/SM107.

Reviewed at commit 14391f2621 (85 files, +24,312/−2,412).

Re-review of the slice of the changes since the earlier review at 81a32d2 that touches lines this PR adds (params.py, _prims_ts_quantization.py, most of _prims_ts_packed.py, one prims_ts.py hunk, and the mHC file the PR no longer carries); it rechecks that review's seven Blockers and posts only Blockers and possible blockers.

This re-review covered the most important 999 of the 5,020 lines the PR changed since 81a32d29d0, the commit the bot last reviewed (3,039 of source code, 1,862 of tests, 119 of docs and data): the files of its earlier Blockers first, then source code, tests, docs and data. It did not review the other 4,021 (2,040 of source code, 1,862 of tests, 119 of docs and data), in 67 files, which need a code owner's review: trt-llm-torch-attention-devs (42 files), trt-llm-oss-compliance (15 files), trt-llm-doc-owners (3 files), trt-llm-kv-cache-manager-devs (1 file), trt-llm-disagg-devs (7 files), trt-llm-kernels-devs (1 file), trt-llm-models-devs (3 files), trt-llm-moe-devs (1 file), trt-llm-runtime-devs (3 files), trt-llm-devs (5 files), trt-llm-qa-function (1 file), trt-llm-infra-devs (3 files), trt-llm-multi-gpu-ci-review (2 files).

Re-review: request changes: 2 Blockers need fixing before merge.

Blockers (2)

  • (B1: Correctness) dtype: fp8 still stores SWA as 512-byte E4M3 rows that clip at ±448 by default on every CSA2 provider; the reply defers accuracy evidence without a tracking ticket. (params.py:31)
  • (B1: Correctness) PrimTS, the dtype: fp8 default on SM100/SM103/SM107, still saturates Q, SWA and decoded MAIN at ±448 by default, and the new scales cap or skip MAIN depending on the kernel route. (_prims_ts_quantization.py:37)
What this review checked
  • The earlier Blockers A1, A2, A3, A7 and A13 are fixed at 14391f2: plan constants sit first in each arena (_prims_ts_packed.py:684-702), SWA slots resolve before _selection_start is recorded (module.py:1857-1861), owner tags keep the epoch below the sign bit (_prims_ts_bank.py:522-526), any explicit use_fp8_staging keeps the native provider (params.py:265-268), and the PDL test's writer is the attention's direct predecessor.
  • The Q and SWA scale folding is arithmetically consistent on each PrimTS route: the gather and producer routes scale Q.K and the output by 2**e for MAIN decoded into the SWA rows' domain, the NVFP4 MAIN route takes 2**e as the SWA pool's tensor scale (_prims_ts_packed.py:1815-1917), every E4M3 Q handed to run() is at the plan's Q scale, and the scale exponents and the PDL setting are part of the in-process and persistent kernel cache keys.
  • The workspace reservation and the layers resolve the same provider (both read kv_cache_dtype from extra_attrs and the lowered use_fp8_staging), and nothing in the tree still references the removed mhc_ob_boundary.py.
  • Not covered: No GPU run; the probe, the scale folds and the kernel routes were traced from code.
  • Not covered: Only the 999-line slice of the changes since 81a32d2 was reviewed; the other 4021 changed lines of new code were read only where the slice reaches them.
  • Not covered: No CI result for the reviewed head.

Automated review by trtllm-agent-review. If a point is wrong, reply in its thread. Once you have pushed code changes and replied in every Blocker thread, the bot re-checks the Blockers within a few hours. A Blocker you think should not be fixed needs no code change: reply in its thread with the reason and the evidence.

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #88630 [ run ] completed with state SUCCESS. Commit: 14391f2
/LLM/main/L0_MergeRequest_PR pipeline #73613 completed with status: 'UNSTABLE'

CI Report

⚠️ Multi-GPU Label Required:
Multi-GPU tests require the ci: full pre-merge approved label on this PR. Either:

  • Wait for the PR to be fully approved — the label is added automatically once approval is complete. Having unresolved open comments is fine, or
  • If needed, ask a member of NVIDIA/trt-llm-ci-approvers to add the label manually.
    Then re-trigger CI with the same bot command (no rebase needed).

⚠️ 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

Link to invocation

@trtllm-agent-review trtllm-agent-review 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.

Reply check: the code has not changed, and the Blockers of the earlier review are resolved.

  • [Blocker] (B1: Correctness) answered (deferred to a follow-up): kv_cache_config.dtype: fp8, which on main meant 528-byte SWA records with a UE8M0 scale per 32 channels, now stores SWA for every CSA2 provider as 512-byte E4M3 rows at one process-wide scale that defaults to unit, so SWA values above +-448 saturate without error. (formats.py:27)
  • [Blocker] (B1: Correctness) answered (deferred to a follow-up): PrimTS, the default for dtype: fp8 on SM100/SM103/SM107, still rounds Q and decodes SWA and MAIN to E4M3 at a unit scale by default, so magnitudes above 448 saturate silently; the opt-in power-of-two scales are fixed per process, never reach MAIN on the NVFP4 MAIN kernel route, and an amax below 448 makes the bank and producer routes clip decoded MAIN at 448*2^e. (_prims_ts_quantization.py:41)

…llow-up on the dev tip

Pin tensorrt_llm/_torch/attention/backends/prims_ts to kris1025/flashinfer
linquanh/trtllm-prims-ts-dev-ds41-followup-r5 at c3e7d63d13. That branch is the PrimTS source
main pins (bastianhagedorn/flashinfer trtllm-prims-ts-decode-corr-cluster-acquire-20261124b at
9497c8892c, NVIDIA#21852: the dev branch trtllm-prims-ts-dev-20261107 plus the cluster-scope acquire
of flashinfer-ai/flashinfer#9224) plus:
- the FlashInfer main PrimTS changes the dev branch lacks, in order:
  flashinfer-ai/flashinfer#6988, NVIDIA#9315 and NVIDIA#9375 (NVIDIA#9087, NVIDIA#9222, NVIDIA#5489, NVIDIA#8549 and NVIDIA#9224 are
  already on it). Where they meet the dev branch's CUTLASS DSL 4.9 task-API changes
  (runtime_domain_end, consumer_work_stage, _resolve_domain, ContextTask), the conflict
  resolutions keep the upstream logic in the dev branch's form;
- the DeepSeek-V4.1 sparse MLA decode of flashinfer-ai/flashinfer#9701 as it merged: the
  FP8+NVFP4 one-CTA Keep-AB decode, PDL after the prologue with the wait ahead of TMEM
  allocation, FP8 tiles TMA-gathered into the retained K/V tile, the TMA-staged Q slot
  released after the last QK, a WS lane's four MXFP8 block scales stored as one word, and
  their tests;
- one commit that puts the loops and stage reads NVIDIA#9315 and NVIDIA#9375 added in that same form; on
  the CuTe DSL 4.7/4.8 task API it changes nothing.

The compatibility patch is main's, regenerated for the new pin, plus one adaptation:
_hardware.py's SM107 check imports flashinfer.cute_dsl.availability absolutely, since its
relative import would leave the vendored package. The vendored tree differs from main's
only in the 29 files the follow-up commits change, and main's PrimTS users run on it
unchanged.

Signed-off-by: linquanh <linquanh@nvidia.com>
… on SM100/SM103/SM107

Add CSA2PrimsTS, a CSA2 compute provider that runs the vendored PrimTS sparse MLA kernels
directly on the persistent packed caches, FP8 SWA and NVFP4 MAIN, through the kernel's
kv_producer extension, for context and generation tiles.

- Selection: CSA2Params.compute_backend="auto" picks PrimTS on SM100, SM103 and SM107
  unless packed attention or explicit FP8 staging asks for the native provider.
  TRTLLM_CSA2_COMPUTE_BACKEND=trtllm selects native.
- KV cache: the SWA encoding follows KvCacheConfig.dtype: 512-byte unit-scale E4M3 rows
  for "fp8", the 528-byte scaled rows otherwise. Context and generation instances must use
  the same encoding.
- Generation: selections are prepared beside the layer projections, on a side stream where
  they are final before them. The compaction kernel claims one epoch-tagged owner slot per
  selected MAIN row, so the selection bank decodes each owned row once to E4M3 (outputs
  bitwise identical); a Reuse layer of a generation-only forward decodes its bank beside its
  projections. Layers of one staging group share one compact metadata buffer and one bank.
  64-head tiles over E4M3 SWA rows run the vendored FP8+NVFP4 one-CTA Keep-AB kernel, which
  decodes each selected NVFP4 MAIN record itself; persistent grids of it use the static
  scheduler. Tiles of at most 32 heads that would run the packed producer read the
  selections as published (raw selections). Every generation step the backend admits takes
  the direct decode, which now also reads the 512-byte E4M3 SWA records. Packed attention
  and the compaction launch with PDL when TRTLLM_ENABLE_PDL is on. The MLA decode launches
  pass context-parallel rank 0, and MXFP8OutputQuant declares stages_ws_sw128_rows.
- Context: the warp-specialized schedule writes the MXFP8 O-A input itself. On the fp8 KV
  cache, 64-head eager context phases whose rows share one converted-KV bank run the fused
  sparse context kernel (csa2_sparse_context), as the native provider does. The context
  MAIN bank grows past its reserved 64 MiB on demand, up to 1 GiB, and prefill pass graphs
  dispatch attend_rows to PrimTS. Context chunks of a new length reuse their kernels
  (about 0.2 instead of 2.6 ms of host time per layer), and a tile whose Q projection made
  the unit-scale E4M3 Q, or whose plan writes the MXFP8 O-A input, gets no BF16 buffer for
  it.
- O-A/O-B: from 4K rows the grouped MXFP8 O-A, and from 128 MiB of input the dense MXFP8
  O-B, walk each 256-row input block's output columns first (same bits); the O-B of a
  prequantized O-A input writes into the layer output. dense_mxfp8_gemm_compiled takes the
  rows a graph capture would run.
- Plans precompile every kernel variant at the first plan, before CUDA Graph capture, and
  new batch shapes no longer recompile the Triton helpers. Arena plans keep their plan-time
  constants at fixed offsets, owner claims keep the selection in 24 bits below the epoch,
  SWA-only tiles take the gather kernel, a tile-memo hit restores the layer's MAIN bank, and
  an overlapped SWA or Reuse decode resolves its SWA slots before its early compaction.

GB300 AgentX, 60-minute windows, token throughput per GPU, PrimTS (kv fp8) against native
(kv fp8_ds_mla), as the generation changes landed: the DEP points went from -13.0%, -13.5%
and -12.4% (c7000, c7900, c5100) to +0.8%, +2.0% and +1.9%, and c7600 stays within its 5%
run-to-run spread of native; the TEP8 points c240, c140 and c84 measured +3.2%, +0.1% and
0.0%, and with every admitted step on the direct decode their generation step matches
native's. The NVFP4 MAIN kernel takes 15.8 / 27.1 / 51.4 / 106.4 us at
152 / 252 / 504 / 1252 rows against native csa2_sparse_decode's 19.2 / 33.1 / 71.8 / 140.8 us
(64 heads, 128 SWA + 512 MAIN selections, CUDA-graph replay). On c7900 the PrimTS context
KV cache is within 1% of native's, with an equal prefix-cache hit rate. These were measured
on the bring-up branch's vendored PrimTS.

Tests: the CSA2 PrimTS backend, module, metadata, producer and quantization suites; PrimTS
and native prefills compared bit for bit on every row whose selections match (an exact
Top-K score tie may pick either row); the native-provider module tests pinned to trtllm-gen
only on SM100-family GPUs; and the B300 and B200 CSA2 entries split into three to fit the
per-entry timeout. The CSA2 README documents the provider and its override.

Signed-off-by: linquanh <linquanh@nvidia.com>
…rimTS query

kv_cache_config.dtype="fp8" stores SWA rows as 512-byte unit-scale E4M3, and PrimTS reads
Q as unit-scale E4M3, both clipping every magnitude above 448. Each can now hold
E4M3(x / 2**e) at one process-wide power-of-two scale:

- TRTLLM_CSA2_SWA_FP8_AMAX names the largest SWA magnitude (default 448, so e = 0 and every
  row keeps its bytes); e is the smallest exponent with 448 * 2**e >= amax, from -8 to 3,
  the three binades native context staging can spend. Writers (both quantize kernels and
  pack_rows) divide by 2**e before rounding, which is exact; QuantizeJobSpec carries e.
  Native readers (gather dequant, PackedAttention, the direct decode, and staging, where a
  swa_fp8 row acts as a scaled SWA row whose every group byte is 127 + e) multiply it back
  exactly. PrimTS's NVFP4 MAIN kernel takes 2**e as its FP8 SWA pool's tensor scale; the
  gather and producer kernels fold it into Q.K and the output instead, so the MAIN rows they
  read decode into the same domain (decode_main_bank, decode_main_records and
  dedup_main_records take scale_exponent; PackedKvProducer.main_scale_exponent descales
  NVFP4 records). The scaled E2M1-to-E4M3 conversion passes its factor in a .b32 register.
- TRTLLM_CSA2_Q_FP8_AMAX names the largest query magnitude (default 448, so e_q = 0; from -8
  to 8). PrimTS's Q rounding (UnitScaleQuery) and the small-step RoPE multiply by 2**-e_q
  before rounding, and the gather, producer and NVFP4 MAIN kernels scale Q.K back. The
  fused prefill and FP8 decode Q projections still emit unit-scale E4M3 Q, so with
  e_q != 0 a PrimTS module rounds its BF16 Q itself; a context batch the fused context
  kernel serves keeps its unit-scale Q, which native staging scales.

Each plan records the scales it was built for. MAIN rows the NVFP4 MAIN kernel decodes still
saturate at 448. Every process that shares a cache, including the context and generation
workers of a disaggregated deployment, must use the same SWA amax; KV transfers copy the
bytes.

Tests: the amax parsing; pack_rows and unpack_rows, both quantize kernels and the gather at
several scales; selection-bank decode against the reference conversion; UnitScaleQuery and
the small-step RoPE against independent references; the PrimTS gather, producer and NVFP4
MAIN kernels at e = 2 and e_q = 2 against unit-scale runs of the same bytes, bit for bit;
and test_prims_ts_scales_keep_image_token_magnitudes, which feeds Q, SWA and MAIN about 600
times unit-normal through PrimTS on the fp8 KV cache: with both amax variables at 3584 it
stays within the native x600 staging test's bound, and its error at unit scales must be
over three times larger.

Signed-off-by: linquanh <linquanh@nvidia.com>
…se where it cannot run there

- An explicit use_fp8_staging keeps the native provider. Only True kept it on SM100, SM103
  and SM107, so an explicit False, which the public field documents as pinning BF16
  staging, selected PrimTS and attended in unit-scale E4M3. Either explicit value now
  selects trtllm-gen under auto, and a forced PrimTS provider rejects False as it rejects
  True; the backend tests pin BF16 staging only on the native provider.
- auto selects PrimTS only for swa_fp8. PrimTS reads the 512-byte unit-scale E4M3 SWA rows
  of kv_cache_config.dtype="fp8" directly; the other KV dtypes (auto, bfloat16,
  fp8_ds_mla) store the 528-byte scaled records, for which the native fused decode serves
  64-head generation tiles about twice as fast. select_csa2_backend takes the persistent
  SWA encoding; the backend passes its own, and the workspace reservation resolves it from
  the KV dtype the model loader records, so a native deployment reserves no PrimTS
  workspace. An explicit provider is not limited by the encoding.
- auto raises where PrimTS cannot run on the fp8 KV cache. csa2_prims_ts_unsupported_reason()
  checks, per device and without compiling or allocating, the CuTe DSL toolchain
  (get_prims_ts_toolchain_unsupported_reason), the import of _prims_ts_packed with the
  vendored internals it builds on, and a host-side plan of its smallest launch. The native
  provider would read those SWA rows without its fused or direct decode and stage every
  generation step, so selection raises with the reason and the ways out (the
  requirements.txt toolchain, kv_cache_config.dtype=fp8_ds_mla, or
  TRTLLM_CSA2_COMPUTE_BACKEND=trtllm). The workspace reservation selects first, so it
  fails before any layer is built.

test_hf_factory_auto_backend_and_staging, test_unsupported_prims_ts_default_raises,
test_prims_ts_support_probe and the reservation test cover it; CPU-only tests, which model
GPUs they do not run on, take PrimTS as supported (conftest). The README states the rules.

Signed-off-by: linquanh <linquanh@nvidia.com>
…ities, shared code, warmup, docs

- Size and reserve the selection bank for one generation step: only tiles of up to the
  step's query capacity take a selection bank, allocated at that capacity, and every plan
  views one pair of index arrays of the same capacity, which the reservation charges (512
  MAIN selections, 128 one-token requests, max_num_tokens 4096: 64 MiB instead of 1 GiB;
  test_prims_ts_selection_bank_fits_its_reservation). A large plan sets up its Q rounding
  only eagerly, and an MXFP8 output plan rejects output buffers on another device.
- A decoder pass graph attends small generation steps with the direct decode: attend_rows
  and the eager forward both ask _direct_decode, so a padded one-row step no longer runs the
  unit-scale E4M3 packed kernel in the graph and the BF16 direct decode eagerly (6 of 1024
  logits beyond 2**-4 on two B200s; now at most 0.039 on that step and bitwise equal on every
  other). The attention-DP pass-graph test runs both providers. The PDL test writes its
  selections directly before the attention, with a control dependent that must read stale
  ones.
- compute.py gives each provider a capability set (CSA2PrimsTS, CSA2FlashMLA,
  CSA2FlashInfer, NATIVE_COMPUTE) that the module asks instead of compute_backend names, and
  every MXFP8 O-A writer, gen_fmha and the fused decode included, sets output_mxfp8_written
  on the module's state, which alone decides whether the module projects the MXFP8 input.
  test_module_provider_predicates pins the module's choices before and after.
- Native staging and PrimTS share selection_forward_key and the scaled E2M1-to-E4M3
  conversion (_fp8_codec.py, inline asm under both CuTe DSL frontends), and byte-level tests
  require them to decode the same MAIN and SWA bytes; PrimTS's own context attention stays
  within 1.25x the native fused kernel's error to BF16 staging.
- During the executor's warmup, a PrimTS arena variant's first plan sends the kernels the
  persistent CuTe DSL cache lacks to the shared PrimTS precompile pool ("csa2_packed"
  payloads); formats.py lets the workers import the CSA2 kernels' host code without
  TensorRT-LLM's runtime. Without a pool, outside the warmup, or where it fails, the plan
  compiles them itself.
- In an eager context phase a layer that publishes no MAIN rows reads the bank its KV
  owner's Full layer decoded when the bank's key matches (forward, pool, plan tensors, bank
  storage, scale) instead of decoding again; one decode of 250K MAIN rows takes 34 us on
  B200.
- sparse-attention.md, kvcache.md, the CSA2 README and the 1.4 release notes give fp8 (512-
  byte E4M3 rows at one power-of-two scale, PrimTS under auto) and fp8_ds_mla (528-byte
  scaled records, the native provider with its fused and direct decodes) as different SWA
  formats, and fp8_ds_mla as the way to keep main's behavior. l0_gr100 runs the PrimTS CSA2
  tests.

On B200, test_prims_ts_fp8_producer.py (137 passed), test_kernel.py (257), test_backend.py
(242), the DeepSeek-V4 precompile tests and the decoder warmup tests pass.

Signed-off-by: linquanh <linquanh@nvidia.com>
…n size or storage scale

PeerRegistrar validated head geometry only for head-sharded paged views, so a peer whose
replicated regions differed in size registered, accepted requests and then failed every
transfer in ReplicatedMapper. CSA2 workers with kv_cache_config.dtype fp8 and fp8_ds_mla
are such a pair: their SWA records are 512 and 528 bytes. Registration now compares the
bytes per layer of each replicated paged view, or the slot size of a ring view, whose slot
count may differ, and names the view and kv_cache_config.dtype in its error.

swa_fp8 rows also carry no scale: they hold E4M3(x / 2**e) at one process-wide exponent
(TRTLLM_CSA2_SWA_FP8_AMAX), so two peers at different exponents registered and the receiver
read the rows at its own scale. RankInfo now carries the CSA2 cache's exponent
(CSA2CacheManager.swa_fp8_scale_exponent; omitted from the wire for caches without swa_fp8
rows), and both the sender's registrar and the receiver reject a peer at another exponent,
naming the variable.

The CSA2 mismatch test expects the rejection at registration;
test_peer_registrar_requires_one_csa2_swa_fp8_scale and
test_rank_info_carries_csa2_swa_fp8_scale_exponent cover the scale; test_peer.py,
test_rank_info.py, test_csa2_kv_transfer.py and test_deepseek_v4_kv_transfer.py (310) pass.

Signed-off-by: linquanh <linquanh@nvidia.com>
The cache sizing, the constructor's head_dim default and its check spelled
CSA2's one latent KV head as a bare 512. _HEAD_DIM names it, as the other
CSA2 modules do, and says which SWA row sizes it gives.

Signed-off-by: linquanh <linquanh@nvidia.com>
…argument calls

The producer probes are compiled with TVM-FFI's environment stream, so each call
takes the pool, the indices and the output; the _Probe alias listed a fourth tensor
argument that no call passes.

Signed-off-by: linquanh <linquanh@nvidia.com>
@kris1025
kris1025 force-pushed the user/linquanh/dsv41-csa2-prims-ts branch from 14391f2 to ed0e0bb Compare December 3, 2026 10:56
@kris1025

kris1025 commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #88910 [ run ] triggered by Bot. Commit: ed0e0bb Link to invocation

@kris1025
kris1025 requested a review from yuxianq December 3, 2026 12:16
@kris1025
kris1025 enabled auto-merge December 3, 2026 13:04
@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #88910 [ run ] completed with state SUCCESS. Commit: ed0e0bb
/LLM/main/L0_MergeRequest_PR pipeline #73860 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

@bo-nv bo-nv 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.

Two issues need fixes before approval: generation can change the numerical value of the same MAIN record across batch sizes, and the generation worker can cache an incompatible SWA layout as a successful handshake. The inline comments include regression conditions for both and a separate workspace accounting follow-up.

native_main = (
main if main.shape[0] else state.buffers["dummy_main"].view(-1)[:main_bytes].view(1, -1)
)
if nvfp4 is not None and _dense_rows(swa_cache) and _dense_rows(native_main, main_bytes):

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.

[High] [Blocking] Please make the two generation paths agree on the decoded MAIN value before enabling this dispatch. With TRTLLM_CSA2_SWA_FP8_AMAX=112 (scale ¼), consider a GB300 REUSE layer with 64 local heads, early selection, 128 SWA slots and 512 MAIN slots. With sufficient capacity, 252 generation rows take the selection bank and 1,252 take this native NVFP4 path. A valid MAIN element of 256 (E2M1 4 × group scale 64) becomes 112 in the bank: 256 / ¼ saturates to 448 and is scaled back. The native path preserves 256. A request can therefore get a different attention output solely because other requests joined the batch. The earlier scale discussion identified clipping; the batch switch also affects values below 448. Please use a common MAIN quantization domain or gate the differing path for non-unit scales. A regression can hold one request’s Q, selected rows and sinks fixed, pad the batch across the dispatch boundary, and compare its output with a nonzero weight on that MAIN row.

@@ -4686,6 +4686,7 @@ def _get_sender_info(self, params: DisaggregatedParams) -> RankInfo:
sender_info = RankInfo.from_bytes(message[0])
validate_protocol_version(sender_info)
self._registrar.validate_bounded_replay_compatible(sender_info)
self._registrar.validate_swa_scale_compatible(sender_info)

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.

[Medium] [Blocking] Please check replicated region sizes here before the generation worker caches the context peer as compatible. The earlier fix rejects a 512/528-byte mismatch in sender-side PeerRegistrar.register(). On the receiver, fp8 paired with fp8_ds_mla passes the exponent check because one exponent is absent, and validate_view_head_geometry() skips replicated SWA views. The receiver sends REGISTER_RANK_INFO without an acknowledgement and caches success, while the sender logs its registration error. A request can then wait for the transfer timeout, and subsequent requests reuse the incompatible peer. Both dtypes used 528-byte rows at the base. Please exercise prepare_rank_info() in both dtype directions and assert an immediate, cached PeerIncompatibleError naming the dtype, with no registration sent.

"Run a PrimTS plan of more than _Q8_ARENA_ROWS rows once before CUDA Graph "
"capture with the Q dtype it captures"
)
self._q8 = torch.empty(

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.

[Medium] [Non-blocking] Please include this plan-owned Q8 allocation in workspace reporting and sizing. An 8,192-row prefill with 16 local heads and TRTLLM_CSA2_Q_FP8_AMAX=896 supplies BF16 Q and retains 64 MiB here in addition to the shared arena. _get_plan() snapshots wrapper.workspace_tensors before the first run, and that property only returns arena buffers. get_workspace_bytes() consequently misses the live allocation; the fixed reservation also excludes it. This can be followed up because ordinary eager tiles are replaced and we have not observed an OOM. The existing large-plan BF16-Q test could assert the extra storage is counted exactly once after the first run and again after plan reuse.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.