Repository navigation
[https://nvbugs/6852473][fix] Skip zero-row launches in fp4_quantize, mxfp8_quantize and noaux_tc_op - #19840
Closed
vsabavat wants to merge 1 commit into
Conversation
… mxfp8_quantize and noaux_tc_op invokeFP4Quantization and invokeMxFP8Quantization launch one block per row (up to an occupancy cap), invokeNoAuxTc one block per token. With no rows the grid has zero blocks: the launch fails with cudaErrorInvalidValue, nothing checks it, and the error stays pending until the next launch that reads the last error raises it, usually an unrelated PyTorch kernel. The three launchers now return before the launch when there are no rows (there is nothing to write; the swizzled scale-factor layout pads zero rows to zero), and their cudaLaunchKernelEx calls are checked. noaux_tc_op still rejects an unsupported configuration at zero tokens. That pending error is what failed the three modeling_v2 catalog tests that run right after a zero-row call in their files; their waivers are removed. Tests: zero-row fp4_quantize (bf16 and fp8 input, both scale-factor layouts) and mxfp8_quantize (linear and swizzled), and zero-token noaux_tc_op (single and multi group), each followed by a normal call that must match the one before it. Signed-off-by: Vasanth Sabavat <[email protected]>
1 task done
Collaborator
Author
|
Superseded by the consolidated draft PR: #19988. Source commits and follow-ups are retained; prior reviews remain historical evidence, not approval of the replacement heads. |
6 of 12 tasks
feih-nv
added a commit
to flashinfer-ai/flashinfer
that referenced
this pull request
Nov 12, 2026
…heck the launch (#9345) <!-- .github/pull_request_template.md --> ## 📌 Description Port of TensorRT-LLM [16df7eaf2](NVIDIA/TensorRT-LLM@16df7ea) (NVIDIA/TensorRT-LLM#19727; only its `noAuxTcKernels.cu` hunk, the rest of that commit is a DeepSeek-V4.1 feature) and [c98b9765d](NVIDIA/TensorRT-LLM@c98b976) (NVIDIA/TensorRT-LLM#19988, which folds in NVIDIA/TensorRT-LLM#19840: "skip zero-row launches in fp4_quantize, mxfp8_quantize, noaux_tc_op" with tests that failed on their main) to the DeepSeek-V3 fused routing launcher (`invokeNoAuxTc`, `csrc/fused_moe/noAuxTcKernels.cu`). - **Bug.** `fused_topk_deepseek` with zero tokens set `gridDim = 0`. `cudaLaunchKernelEx` rejects that with `cudaErrorInvalidValue`; the return value was not checked, so the call returned normally and the error surfaced on the next unrelated CUDA call (`AcceleratorError: CUDA error: invalid argument` from, say, `torch.ones(4).sum()`), on every path and with or without `routing_replay_out`. - **Fix.** Return before the launch when `num_tokens == 0`; otherwise check the launch with `TLLM_CUDA_CHECK`, as upstream does (it throws with the CUDA error string). No change for non-empty inputs. - **Test.** `test_zero_tokens_launch_nothing`: grouped, 256-expert and 128-expert single-group configurations, with and without a replay buffer; asserts the output shapes and that the following CUDA call is clean. 6 of 6 cases failed before the fix. ## 🔍 Related Issues NVIDIA/TensorRT-LLM#19727, 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.). - [x] This PR requires **full-scope** CI, not targeted tests (expensive; justify below). Reason: <!-- e.g. cross-cutting change to shared infrastructure --> Suggested CI test targets (optional; paths under `tests/`, whitespace-separated — a starting point for `@flashinfer-bot run <targets>` / `/bot run <targets>`, reviewers may adjust): `tests/model_optimizations/test_dsv3_fused_routing.py` Run on B200 (SM100) in the CUDA 13.0 CI container at this branch's head: ``` pytest tests/model_optimizations/test_dsv3_fused_routing.py \ -k "zero_tokens_launch_nothing or (backend_correctness and default) or routing_replay_out_extended" 84 passed, 30 skipped ``` `test_zero_tokens_launch_nothing` on the pre-fix kernel: 6 failed. ## 🔬 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 The Cake backend already rejects zero tokens in its contract; this is the default backend only. The new test sits with the other input-contract test (`test_dsv3_fused_routing_rejects_strided_views`). #9344 adds its test elsewhere in the same file; whichever merges second gets rebased. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **Bug Fixes** * Zero-token routing operations now complete without launching unnecessary GPU work across grouped and single-group configurations. Empty outputs retain their expected shapes, and subsequent GPU operations can proceed normally. * GPU kernel launch failures are now checked and reported before stream error synchronization, while successful launches continue through the existing error checks. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
trtllm::fp4_quantize,trtllm::mxfp8_quantizeandtrtllm::noaux_tc_opleave a CUDA error pending when calledwith no rows.
invokeFP4QuantizationandinvokeMxFP8Quantization(cpp/tensorrt_llm/kernels/ quantization.cu) launch one block per row, up to an occupancy cap. For the swizzled scale-factor layout the rowsare padded to 128, which is still 0 at 0 rows.
invokeNoAuxTc(cpp/tensorrt_llm/kernels/noAuxTcKernels.cu)launches one block per token. With no rows every one of these grids has zero blocks, and the launch fails with
cudaErrorInvalidValue.sync_check_cuda_errorafter the noaux launch checks only in debug builds or withCUDA_LAUNCH_BLOCKING=1.error raises it, usually an unrelated PyTorch kernel:
CUDA error: invalid argument, far from its cause.fp4_quantize(bf16 and fp8 input, both scale-factor layouts),mxfp8_quantize(linear and swizzled) and a zero-tokennoaux_tc_opeach left the error pending, with PDL on andoff. One or more rows, and
top_k = 0, did not. The three modeling_v2 catalog tests waived underhttps://nvbugs/6852473 each run right after a zero-row call in their file (
test_zero_rows,test_degenerate_shapes), and fail on that pending error.cudaLaunchKernelExcalls are now wrapped inTLLM_CUDA_CHECK, so a rejected launch raises where it happens.noaux_tc_opstill rejects an unsupported configuration at zero tokens. The three waivers are removed.Test Coverage
New, each running the op on no rows, checking the empty output shapes, then running it again on 4 or 8 rows and
comparing with the same call made before; that comparison's kernel launch is what raises a pending error:
tests/unittest/_torch/thop/parallel/test_fp4_gemm_quantize.py::TestFunctional::test_fp4_quantize_zero_rows: bf16and fp8 input (the two launch paths), both scale-factor layouts.
tests/unittest/_torch/thop/parallel/test_fp8_quantize.py::test_mxfp8_quantize_zero_rows: linear scale factors withalignment 512, swizzled with 32.
tests/unittest/_torch/thop/parallel_hw_agnostic/test_noaux_tc.py::test_noaux_tc_zero_tokens: a single group of 72experts (top-6), and 8 groups of 32 (top-8).
On GB200 the 8 cases fail on main and pass with this PR; the rest of these files has no new failure. The three
unwaived catalog tests fail on main and pass with this PR. CI collects the new tests through
unittest/_torch/thop/parallel(l0_b200,l0_b300,l0_gb300) andunittest/_torch/thop/parallel_hw_agnostic(l0_h100). The catalog tests stay under theunittest/_torch/modeling_v2directory waiver (https://nvbugs/6853741).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-compatibleorapi-breaking. Forapi-breaking, includeBREAKINGin the PR title. (No API change.)Any new dependencies have been scanned for license and vulnerabilities (No new dependencies.)
CODEOWNERS updated if ownership changes (No ownership change.)
Documentation updated as needed (No user-facing change.)
Update tava architecture diagram if there is a significant design change in PR. (No design change.)
The reviewers assigned automatically/manually are appropriate for the PR. (To check once the PR is open.)
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.