Skip to content

[https://nvbugs/5970614][fix] Sync CTA before PDL trigger in quantize_with_block_size - #14668

Merged
pengbowang-nv merged 5 commits into
NVIDIA:mainfrom
tianyuxbear:fix/5970614
Jul 10, 2026
Merged

pengbowang-nv merged 5 commits into
NVIDIA:mainfrom
tianyuxbear:fix/5970614

Conversation

@tianyuxbear

@tianyuxbear tianyuxbear commented May 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes a PDL (Programmatic Dependent Launch) race in quantize_with_block_size that intermittently corrupts NVFP4 GEMM outputs and degrades GSM8K accuracy for DeepSeek-R1 NVFP4 on GB300 + PP=4 + MTP (nvbug 5970614).

cudaTriggerProgrammaticLaunchCompletion() only signals that the CTA has reached the trigger point — it does not flush prior stores to global memory. Memory visibility for the secondary kernel must be provided either by the producer (a fence before the trigger) or by the consumer (wait_on_dependent_grids() before its first dependent load). In the current NVFP4 path neither side does so: the producer lacks a fence, and the sm103 blockscaled GEMM's main_sf_load warp branch is missing the corresponding wait_on_dependent_grids() (tracked separately in NVIDIA/cutlass#3279).

Compounding this, PDL completion is reported per-CTA at-least-once: a single warp reaching the trigger marks its whole CTA as "trigger reached", even if peer warps in the same CTA are still writing sf_out / out. Once every CTA has been marked, the driver launches the secondary kernel, which TMA-loads partial data — NaNs then propagate through the DeepSeek-R1 forward and corrupt output tokens.

Fix: insert __threadfence(); __syncthreads(); immediately before the trigger. Each thread first makes its own stores device-visible; the barrier then guarantees every thread has done so before any thread can signal PDL completion.

In-tree precedent

This mirrors an existing pattern in cpp/tensorrt_llm/kernels/fusedLayernormKernels/ws_layernorm.cuh:865-867, which uses a barrier plus membar.gl (__threadfence() is the CUDA intrinsic for membar.gl) before the same cudaTriggerProgrammaticLaunchCompletion() call. Per review, this PR places the fence before the barrier — the strictly stronger order: barrier release then already implies every thread's stores are device-visible, without relying on post-barrier fence timing.

Evidence

The race was characterized on release/1.2, where the timing window reproduces it deterministically enough to measure. A cache-bypass ld.global.cv.u8 probe on the SF buffer detects 0x7f poison fill (from the cudaMallocAsync pool) as a direct race indicator:

Config GSM8K Poison probe
Baseline (no fix) 91.93 (FAIL, threshold 92.217) 2.31% (~74k / 3.2M samples)
With this fix 95.34 (PASS, ref 95.42) 0 / 2.4M

On main the race is latent: the GSM8K test no longer fails even without this fix (10/10 PASS, mean 94.95 ± 0.25 with autotuner off; with the fix mean 95.14 ± 0.19). Code/scheduler changes since release/1.2 appear to have narrowed the producer-to-consumer window enough that the race no longer trips the GSM8K threshold — but the underlying defect is unchanged, and any future change that widens the window (cutlass bump, scheduler reordering, kernel fusion) can re-expose it.

The full investigation branch — probes, race-rate measurement, per-run logs — lives on my fork at tianyuxbear/TensorRT-LLM:fix/5970614-bak, which is based on release/1.2 (where the race is deterministically reproducible).

The probe code used to measure the race is not part of this PR; it was a one-off diagnostic inside the cutlass consumer.

Test-case waive removed by this PR

On main the affected test case (TestDeepSeekR1::test_nvfp4_multi_gpus[throughput_pp4_mtp]) is waived in tests/integration/test_lists/waives.txt under this very nvbug (5970614). Since this PR fixes the underlying race, it also removes the waive so CI validates the fix end to end on the real reproducer.

Historical note: the deterministic accuracy gap in the Evidence section was measured on release/1.2, where the producer-to-consumer timing window reproduces the race reliably; on main the race is latent for this shape, so the unwaived run primarily guards against future changes re-widening the window.

Companion cutlass fix

The consumer-side fix at NVIDIA/cutlass#3279 addresses the missing wait_on_dependent_grids() in the sm103 blockscaled GEMM main_sf_load warp branch (the other half of the race described in Summary). Either fix alone closes the race; both are correct individually:

  • The cutlass fix protects every PDL producer routed through that GEMM.
  • This producer-side fix protects every PDL consumer downstream of quantize_with_block_size, regardless of which cutlass revision trtllm pulls in.

Follow-up fix: shuffle-mask deadlock exposed by the barrier

The first full CI run of this PR hung 19 test cases on Blackwell stages (B200/B300) — all hangs, no accuracy failures:

Failed cases Failure mode
13x test_fp8_quantize.py::test_mxfp8_quantize_alignment_torch_device[*-1568-*] Deterministic kernel hang (B300 timed out at a_fp8.cpu() after 2400 s; B200 xdist workers mass-crashed)
4x TestGPTOSS::test_w4_1gpu[*] / test_dummy_load_format Hang inside LLM(...) init during the first warmup forward
2x test_indexer_topk.py::test_indexer_topk_prefill[*] Collateral only: no quantize calls inside; they shared the GPU wedged by the hung kernel, and both pass standalone

Root cause. The cvt helpers called from quantize_with_block_size's thread-strided column loop reduce the per-SF absmax with a full-warp __shfl_xor_sync(0xffffffff, ...) — but the shuffle is only reached on the real-data branch of the loop body; lanes that draw padding columns just store zeros and skip it. When the data/padding boundary cuts through a warp, only part of that warp reaches the shuffle: MXFP8 k=1568 / alignment=64 gives blockDim=200 with 196 data-column threads (196 = 6x32+4, splitting warp 6 at lane 4); the GPT-OSS MoE activation quant (hidden=2880, weight alignment 256) gives blockDim=384 with 360 data-column threads (360 = 11x32+8, splitting warp 11 at lane 8). Before this PR that was benign: the padding lanes exited the kernel after their stores, and exited lanes satisfy sync collectives on sm_70+, so the data lanes' full-warp shuffle completed. With the new __syncthreads(), the padding lanes are instead parked alive at the barrier: the shuffle waits for lanes held at the barrier, the barrier waits for lanes held at the shuffle — a deterministic circular wait. The barrier did not create the bug; it removed the exit-semantics cover from a latent over-wide membermask.

Fix. Narrow the shuffle membermask to the 2-/4-lane scale-factor group (new cvt_sf_group_shfl_mask() helper; 5 call sites across cvt_warp_fp16_to_fp4 / cvt_warp_fp8_to_fp4 / cvt_warp_fp16_to_mxfp8). The xor-1/xor-2 butterfly never exchanges data outside the aligned group, so the mask now names exactly the lanes that must converge. Group lanes always share a trip count because blockDim and the column-thread count are both multiples of the group size (guaranteed by the k % sfVecSize == 0 checks at the op layer). This is a strictly weaker convergence precondition with bit-identical numerics — the membermask never selects shuffle sources, so callers of these helpers in other kernels are unaffected.

Local verification (single B200). All 19 failed CI cases rerun after the fix: 19/19 pass, 0 timeouts. The deterministic hang case [64-True-dtype0-1568-1] completes in 0.08 s (previously 2400 s timeout). GPT-OSS 120B GSM8K scores 89.23 vs the 85.0 reference across all three w4_1gpu variants — the mask change preserves quantization numerics end to end.

Why the DeepSeek-R1 e2e never hit this. The deadlock requires the boundary of the shuffle-participation set (which lanes reach the cvt call) to cut through the middle of a warp. DeepSeek-R1 (hidden=7168) has no padding columns at all (7168 is already SF-layout-aligned), and its only boundary is the loop-stride one: blockDim=512 with 896 data-column threads, so the second stride covers threads 0..383 — 384 is an exact multiple of 32, whole warps diverge together, and every warp's full-mask shuffle stayed convergent. Neither the release/1.2 race experiments nor the DeepSeek CI case could ever expose the hazard; it takes shapes like k=1568 (alignment unit tests) or hidden=2880 (GPT-OSS MoE) to land a boundary mid-warp.

Risk

  • Surface: one producer kernel (quantize_with_block_size, NVFP4 / FP8 / MXFP8 paths) plus the shuffle membermasks in the shared cvt helpers (strictly weaker convergence requirement, identical data movement).
  • Per-CTA cost: one __syncthreads() + one __threadfence() at the very end of the kernel (cold path). No effect on PDL launch overlap — the trigger still happens; it just happens after the CTA has drained.
  • No API or behavior change for callers.

@tianyuxbear
tianyuxbear requested a review from a team as a code owner May 28, 2026 04:52
@coderabbitai

coderabbitai Bot commented May 28, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

The PR addresses a CUDA graph execution issue in NVIDIA's TensorRT-LLM by adding memory-ordering synchronization to the quantization kernel and adjusting the DeepSeek-R1 NVFP4 test configuration, then removing the corresponding test waiver.

Changes

NVFP4 DeepSeek-R1 Throughput Stabilization

Layer / File(s) Summary
Kernel synchronization barrier and fence
cpp/tensorrt_llm/kernels/quantization.cuh
CTA-wide barrier and threadfence are inserted in quantize_with_block_size before launch completion to drain stores and ensure visibility to downstream GEMM consumers, fixing nvbug 5970614.
Test configuration adjustment and waiver removal
tests/integration/defs/accuracy/test_llm_api_pytorch.py, tests/integration/test_lists/waives.txt
Batch size reduced to 8 with inline documentation of the cuBLASLt workspace headroom issue; the corresponding SKIP waiver is removed so the test now executes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • NVIDIA/TensorRT-LLM#14504: Also modifies tests/integration/test_lists/waives.txt by changing SKIP/waiver entries for integration tests.

Suggested reviewers

  • mikeiovine
  • dongfengy
  • jieli-matrix
  • xinhe-nv
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
Title check ✅ Passed The title is concise, specific, and matches the main change: synchronizing the CTA before the PDL trigger for the nvbug fix.
Description check ✅ Passed The description is detailed and covers the issue, fix, evidence, related fixes, and risk; it only omits the template's explicit Test Coverage/Checklist sections.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
cpp/tensorrt_llm/kernels/quantization.cuh (1)

2-2: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Update the copyright header year on this modified source file.

This file was modified, but the NVIDIA header still ends at 2023. Please update it to include the latest modification year.

Suggested fix
- * Copyright (c) 2019-2023, NVIDIA CORPORATION.  All rights reserved.
+ * Copyright (c) 2019-2026, NVIDIA CORPORATION.  All rights reserved.

As per coding guidelines: **/*.{cpp,cc,h,hpp,py,cu,cuh}: Include NVIDIA copyright header on ALL new files; update year on modified files.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cpp/tensorrt_llm/kernels/quantization.cuh` at line 2, Update the NVIDIA
copyright header at the top of the modified source file by changing the year
range from "2019-2023" to include the current modification year (e.g.
"2019-2026"); edit the top-of-file header comment in quantization.cuh (the
initial copyright comment block) so the year range reflects the latest
modification year.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@cpp/tensorrt_llm/kernels/quantization.cuh`:
- Line 2: Update the NVIDIA copyright header at the top of the modified source
file by changing the year range from "2019-2023" to include the current
modification year (e.g. "2019-2026"); edit the top-of-file header comment in
quantization.cuh (the initial copyright comment block) so the year range
reflects the latest modification year.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 04887fc1-1f9e-4ec2-8b75-a6af13d6921c

📥 Commits

Reviewing files that changed from the base of the PR and between 59d4369 and f8d3481.

📒 Files selected for processing (3)
  • cpp/tensorrt_llm/kernels/quantization.cuh
  • tests/integration/defs/accuracy/test_llm_api_pytorch.py
  • tests/integration/test_lists/waives.txt
💤 Files with no reviewable changes (1)
  • tests/integration/test_lists/waives.txt

@tianyuxbear

Copy link
Copy Markdown
Contributor Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #53276 [ run ] triggered by Bot. Commit: 43e46dc Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #53276 [ run ] completed with state SUCCESS. Commit: 43e46dc
/LLM/main/L0_MergeRequest_PR pipeline #42466 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

@tianyuxbear

Copy link
Copy Markdown
Contributor Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #53316 [ run ] triggered by Bot. Commit: 8613e8c Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #53316 [ run ] completed with state SUCCESS. Commit: 8613e8c
/LLM/main/L0_MergeRequest_PR pipeline #42502 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

@tianyuxbear

Copy link
Copy Markdown
Contributor Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #53440 [ run ] triggered by Bot. Commit: 40d0115 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #53440 [ run ] completed with state SUCCESS. Commit: 40d0115
/LLM/main/L0_MergeRequest_PR pipeline #42608 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

@tianyuxbear

Copy link
Copy Markdown
Contributor Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #53533 [ run ] triggered by Bot. Commit: fec41f6 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

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

@tianyuxbear

Copy link
Copy Markdown
Contributor Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #53601 [ run ] triggered by Bot. Commit: fec41f6 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

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

@tianyuxbear

Copy link
Copy Markdown
Contributor Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #53784 [ run ] triggered by Bot. Commit: 13363c1 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #53784 [ run ] completed with state SUCCESS. Commit: 13363c1
/LLM/main/L0_MergeRequest_PR pipeline #42902 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

@tianyuxbear

Copy link
Copy Markdown
Contributor Author

/bot run --disable-fail-fast

@tianyuxbear

Copy link
Copy Markdown
Contributor Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #58175 [ run ] triggered by Bot. Commit: e3a5621 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #58175 [ run ] completed with state FAILURE. Commit: e3a5621
/LLM/main/L0_MergeRequest_PR pipeline #46825 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

@tianyuxbear

Copy link
Copy Markdown
Contributor Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #58221 [ run ] triggered by Bot. Commit: e3a5621 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #58221 [ run ] completed with state SUCCESS. Commit: e3a5621
/LLM/main/L0_MergeRequest_PR pipeline #46863 completed with status: 'SUCCESS'

CI Report

Link to invocation

@tianyuxbear

Copy link
Copy Markdown
Contributor Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #58384 [ run ] triggered by Bot. Commit: 52ba9f8 Link to invocation

@tianyuxbear

Copy link
Copy Markdown
Contributor Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #58500 [ run ] triggered by Bot. Commit: 52ba9f8 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #58384 [ run ] completed with state ABORTED. Commit: 52ba9f8
/LLM/main/L0_MergeRequest_PR pipeline #47008 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

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #58500 [ run ] completed with state SUCCESS. Commit: 52ba9f8
/LLM/main/L0_MergeRequest_PR pipeline #47107 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

… SF group

The CTA-wide __syncthreads() added before the PDL trigger in
quantize_with_block_size deadlocks against the full-warp
__shfl_xor_sync(0xffffffff) inside the cvt helpers when the
thread-strided column loop gives warp lanes different trip counts
(e.g. MXFP8 k=1568 alignment=64 -> blockDim=200, GPT-OSS hidden=2880
-> blockDim=360): lanes still in the loop wait on the shuffle for
lanes already parked at the barrier. Narrow the shuffle membermask to
the 2- or 4-lane scale-factor group, which the xor-1/xor-2 butterfly
never crosses and which is always trip-uniform because the block size
and the column-thread count are multiples of the group size.

Signed-off-by: Tianyu Xiong <[email protected]>
…4_mtp test

The PDL race behind this waive is fixed by the producer-side CTA
barrier in quantize_with_block_size; remove the waive so CI validates
the fix end to end.

Signed-off-by: Tianyu Xiong <[email protected]>
…ad of the PDL trigger

Address review: with the previous __syncthreads(); __threadfence()
order, the first thread past the barrier could reach the trigger
before its peers had executed their own fences, so peer stores were
not yet guaranteed device-visible. Fencing before the barrier makes
every thread flush its own stores first; barrier release then implies
all stores are device-visible before any thread triggers. Also bump
the copyright year.

Signed-off-by: Tianyu Xiong <[email protected]>
@tianyuxbear

Copy link
Copy Markdown
Contributor Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #58551 [ run ] triggered by Bot. Commit: 2ad2209 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

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

CI Report

Link to invocation

@pengbowang-nv
pengbowang-nv merged commit c0c1226 into NVIDIA:main Jul 10, 2026
8 checks passed
feih-nv added a commit to flashinfer-ai/flashinfer that referenced this pull request Nov 16, 2026
…e checked (fp4_quantize, mxfp8_quantize) (#9377)

<!-- .github/pull_request_template.md -->

## 📌 Description

Launcher fixes for the TRT-LLM block-scale quantization kernels
(`fp4_quantize`, `mxfp8_quantize`), from upstream TensorRT-LLM: the
launcher hunks of
[NVIDIA/TensorRT-LLM#19727](NVIDIA/TensorRT-LLM#19727)
and
[NVIDIA/TensorRT-LLM#19988](NVIDIA/TensorRT-LLM#19988).
The kernels themselves are main's. The CTA barrier before the PDL
trigger (NVIDIA/TensorRT-LLM#14668) was split out at review into #9445,
gated to SM103, because it guards one consumer (CUTLASS's SM103
block-scaled GEMM, NVIDIA/cutlass#3279) and costs every other
architecture.

- **Zero-sized inputs return early and launches are checked.**
`invokeFP4Quantization` and `invokeMxFP8Quantization` launched a
zero-sized grid for `m == 0`, which fails with `cudaErrorInvalidValue`
that the next CUDA call reports (`fp4_quantize(torch.empty(0, 64))`
followed by any kernel raised `CUDA error: invalid argument` on main;
the Python `mxfp8_quantize` entry already guards this since #8576). The
launchers return before configuring the launch when `b`, `m` or `n` is
0, and the three `cudaLaunchKernelEx` calls are wrapped in
`TLLM_CUDA_CHECK`.

Output is unchanged for non-empty inputs.

## 🔍 Related Issues


[NVIDIA/TensorRT-LLM#19727](NVIDIA/TensorRT-LLM#19727),
[NVIDIA/TensorRT-LLM#19988](NVIDIA/TensorRT-LLM#19988).

## 🚀 Pull Request Checklist

Thank you for contributing to FlashInfer! Before we review your pull
request, please make sure the following items are complete.

### ✅ Pre-commit Checks

- [x] I have installed `pre-commit` by running `pip install pre-commit`
(or used your preferred method).
- [x] I have installed the hooks with `pre-commit install`.
- [x] I have run the hooks manually with `pre-commit run --all-files`
and fixed any reported issues.

> If you are unsure about how to set up `pre-commit`, see [the
pre-commit documentation](https://pre-commit.com/).

## 🧪 Tests

- [x] Tests have been added or updated as needed.
- [x] All tests are passing (`unittest`, etc.).

New: `test_fp4_quantize_zero_rows` (both scale-factor sizes, both
layouts); it fails on main with `CUDA error: invalid argument` and
passes here. `mxfp8_quantize` already returns before the launch for zero
rows on the Python side (#8576, covered by `test_mxfp8_quantize_empty`),
so no new test for it; the launcher's early return and launch check stay
for the other C++ callers. `SHAPES` gains `(8, 4800)`: 600 column
threads, so the 512-thread block finishes the row in a second pass of 88
threads and the scale-factor shuffle runs in a partially active warp; it
is checked against the PyTorch reference like the other shapes and also
exercises #9445's masks on SM103.

Run on B200 (CUDA 13.0 CI container): `tests/utils/test_fp4_quantize.py
-k "test_fp4_quantization or test_scale_swizzling or
test_e2m1_dequantization or zero_rows"` and
`tests/utils/test_fp8_quantize.py -k "test_mxfp8_quantize_torch or
zero_rows"`: 502 passed, 168 skipped (CuTe-DSL / CPU variants), at
FlashInfer `e3ebb9e7dd` + this commit.

## 🔬 Experimental Track

<!-- Only for PRs submitted under the experimental policy
(CONTRIBUTING.md → "Experimental APIs and Backends").
     Leave this section untouched for normal PRs. -->

- [ ] This PR is **experimental**: it adds or changes code under
`flashinfer/experimental/` and/or an `@flashinfer_experimental_api`.
Tracking issue: #
- [ ] The tracking issue names an owner, the reason for the experimental
path, and a graduation plan with a target release.
- [ ] Core changes are limited to a thin entry point (signature, shared
validation, feature-gate check, backend selection, handoff).
- [ ] Tests live in `tests/experimental/` and were validated on the
intended hardware; a runnable example is included.
- [ ] Nothing is registered in `flashinfer/aot.py`, and no experimental
backend is reachable from `backend="auto"` without
`FLASHINFER_ALLOW_EXPERIMENTAL_AUTO_BACKENDS=1`. (Calling an
`@flashinfer_experimental_api` or naming a backend explicitly is itself
the opt-in and needs no environment variable.)
- [ ] **Test scope declared below.** The experimental CI lane runs
exactly these targets, so keep them as narrow as the change allows.

<!-- Required for experimental PRs. Replace the commented lines below
with your targets.
Do not delete the fence or change its `experimental-tests` tag — the
experimental-track
watcher reads it verbatim to decide which targets to ask CI for. -->

```experimental-tests
# One target per line: a directory or a file. (A pytest ::selector is not
# supported -- the sharding runner cannot consume one.) Must be under
# tests/experimental/ and must exist. Delete these comment lines and add yours, e.g.
#
#   tests/experimental/test_my_backend.py
#   tests/experimental/my_backend/
#
# Declaring the whole tree (tests/experimental/) is allowed but means every
# experimental PR pays for every other feature's tests, in every matrix cell.
```

## Reviewer Notes

Kernel code is untouched; no perf effect. Review on the earlier revision
measured its barrier at +14-19% on `fp4_quantize` and the partial mask
at +14-15% on MXFP8 (B200); both now live in #9445 behind an SM103 gate.
kahyunnam pushed a commit to flashinfer-ai/flashinfer that referenced this pull request Nov 17, 2026
…e checked (fp4_quantize, mxfp8_quantize) (#9377)

<!-- .github/pull_request_template.md -->

## 📌 Description

Launcher fixes for the TRT-LLM block-scale quantization kernels
(`fp4_quantize`, `mxfp8_quantize`), from upstream TensorRT-LLM: the
launcher hunks of
[NVIDIA/TensorRT-LLM#19727](NVIDIA/TensorRT-LLM#19727)
and
[NVIDIA/TensorRT-LLM#19988](NVIDIA/TensorRT-LLM#19988).
The kernels themselves are main's. The CTA barrier before the PDL
trigger (NVIDIA/TensorRT-LLM#14668) was split out at review into #9445,
gated to SM103, because it guards one consumer (CUTLASS's SM103
block-scaled GEMM, NVIDIA/cutlass#3279) and costs every other
architecture.

- **Zero-sized inputs return early and launches are checked.**
`invokeFP4Quantization` and `invokeMxFP8Quantization` launched a
zero-sized grid for `m == 0`, which fails with `cudaErrorInvalidValue`
that the next CUDA call reports (`fp4_quantize(torch.empty(0, 64))`
followed by any kernel raised `CUDA error: invalid argument` on main;
the Python `mxfp8_quantize` entry already guards this since #8576). The
launchers return before configuring the launch when `b`, `m` or `n` is
0, and the three `cudaLaunchKernelEx` calls are wrapped in
`TLLM_CUDA_CHECK`.

Output is unchanged for non-empty inputs.

## 🔍 Related Issues

[NVIDIA/TensorRT-LLM#19727](NVIDIA/TensorRT-LLM#19727),
[NVIDIA/TensorRT-LLM#19988](NVIDIA/TensorRT-LLM#19988).

## 🚀 Pull Request Checklist

Thank you for contributing to FlashInfer! Before we review your pull
request, please make sure the following items are complete.

### ✅ Pre-commit Checks

- [x] I have installed `pre-commit` by running `pip install pre-commit`
(or used your preferred method).
- [x] I have installed the hooks with `pre-commit install`.
- [x] I have run the hooks manually with `pre-commit run --all-files`
and fixed any reported issues.

> If you are unsure about how to set up `pre-commit`, see [the
pre-commit documentation](https://pre-commit.com/).

## 🧪 Tests

- [x] Tests have been added or updated as needed.
- [x] All tests are passing (`unittest`, etc.).

New: `test_fp4_quantize_zero_rows` (both scale-factor sizes, both
layouts); it fails on main with `CUDA error: invalid argument` and
passes here. `mxfp8_quantize` already returns before the launch for zero
rows on the Python side (#8576, covered by `test_mxfp8_quantize_empty`),
so no new test for it; the launcher's early return and launch check stay
for the other C++ callers. `SHAPES` gains `(8, 4800)`: 600 column
threads, so the 512-thread block finishes the row in a second pass of 88
threads and the scale-factor shuffle runs in a partially active warp; it
is checked against the PyTorch reference like the other shapes and also
exercises #9445's masks on SM103.

Run on B200 (CUDA 13.0 CI container): `tests/utils/test_fp4_quantize.py
-k "test_fp4_quantization or test_scale_swizzling or
test_e2m1_dequantization or zero_rows"` and
`tests/utils/test_fp8_quantize.py -k "test_mxfp8_quantize_torch or
zero_rows"`: 502 passed, 168 skipped (CuTe-DSL / CPU variants), at
FlashInfer `e3ebb9e7dd` + this commit.

## 🔬 Experimental Track

<!-- Only for PRs submitted under the experimental policy
(CONTRIBUTING.md → "Experimental APIs and Backends").
     Leave this section untouched for normal PRs. -->

- [ ] This PR is **experimental**: it adds or changes code under
`flashinfer/experimental/` and/or an `@flashinfer_experimental_api`.
Tracking issue: #
- [ ] The tracking issue names an owner, the reason for the experimental
path, and a graduation plan with a target release.
- [ ] Core changes are limited to a thin entry point (signature, shared
validation, feature-gate check, backend selection, handoff).
- [ ] Tests live in `tests/experimental/` and were validated on the
intended hardware; a runnable example is included.
- [ ] Nothing is registered in `flashinfer/aot.py`, and no experimental
backend is reachable from `backend="auto"` without
`FLASHINFER_ALLOW_EXPERIMENTAL_AUTO_BACKENDS=1`. (Calling an
`@flashinfer_experimental_api` or naming a backend explicitly is itself
the opt-in and needs no environment variable.)
- [ ] **Test scope declared below.** The experimental CI lane runs
exactly these targets, so keep them as narrow as the change allows.

<!-- Required for experimental PRs. Replace the commented lines below
with your targets.
Do not delete the fence or change its `experimental-tests` tag — the
experimental-track
watcher reads it verbatim to decide which targets to ask CI for. -->

```experimental-tests
# One target per line: a directory or a file. (A pytest ::selector is not
# supported -- the sharding runner cannot consume one.) Must be under
# tests/experimental/ and must exist. Delete these comment lines and add yours, e.g.
#
#   tests/experimental/test_my_backend.py
#   tests/experimental/my_backend/
#
# Declaring the whole tree (tests/experimental/) is allowed but means every
# experimental PR pays for every other feature's tests, in every matrix cell.
```

## Reviewer Notes

Kernel code is untouched; no perf effect. Review on the earlier revision
measured its barrier at +14-19% on `fp4_quantize` and the partial mask
at +14-15% on MXFP8 (B200); both now live in #9445 behind an SM103 gate.

(cherry picked from commit cf8e7ab)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants