Skip to content

[TRTLLM-14616][feat] add VisualGen fp8 row-wise quant + autotuner - #16847

Merged
o-stoner merged 17 commits into
NVIDIA:mainfrom
o-stoner:user/o-stoner/visual-gen-fp8-rowwise
Sep 3, 2026
Merged

o-stoner merged 17 commits into
NVIDIA:mainfrom
o-stoner:user/o-stoner/visual-gen-fp8-rowwise

Conversation

@o-stoner

@o-stoner o-stoner commented Jul 24, 2026 •

Copy link
Copy Markdown
Collaborator

Dev Engineer Review

  • Added FP8 per-channel-per-token quantization for VisualGen.
  • Added row-wise FP8 weight quantization and loading.
  • Added dynamic per-token activation quantization for 3D inputs.
  • Added TRT-LLM and vectorized kernel selection with autotuning.
  • Added TRTLLM_FP8_QUANT_TACTIC overrides.
  • Added validation for CUDA inputs, supported dtypes, tensor dimensions, contiguity, and hidden-size limits.
  • Added configuration and package exports for FP8_PER_CHANNEL_PER_TOKEN.
  • Added vendored CUDA vectorization and FP8 compatibility helpers.
  • Added explicit kernel instantiations for BF16, FP16, and FP32.
  • Forced dynamic activation quantization for the new algorithm.
  • No test-list files were included in the provided changes.
  • Review should confirm coding-guideline compliance, CUDA compatibility, kernel performance, operator registration, and environment-variable behavior.

QA Engineer Review

Test-code changes were added.

  • Added unit tests for vectorized and tunable per-token FP8 quantization.
  • Added tests for output shapes, dtypes, scales, 3D inputs, numerical agreement, tactic overrides, and default tactic selection.
  • Added row-wise quantization tests for multiple shapes, round-trip accuracy, and zero-valued weights.
  • Added model-loader and configuration parser coverage.
  • Extended Cosmos, FLUX, LTX2, Qwen Image, and Wan pipeline coverage to FP8_PER_CHANNEL_PER_TOKEN.
  • Added end-to-end FP8 accuracy coverage for the Wan pipeline.
  • No corresponding test-db/ or qa/ registrations were shown for the modified test functions.

Verdict: needs follow-up.

Description

  • Wires FP8_PER_CHANNEL_PER_TOKEN (rowwise FP8) into VisualGen's quantization plumbing. This was already supported by TRT-LLM's FP8RowwiseLinearMethod but was not reachable from the VisualGen pipeline.
  • Adds quantize_fp8_rowwise to visual_gen/quantization/ops.py: per-output-row weight quantization (bf16 → fp8 e4m3, one scale per output row) applied at model load time
  • Routes FP8_PER_CHANNEL_PER_TOKEN checkpoints through the new weight quantizer in DynamicLinearWeightLoader; pre-quantized fp8 weights pass through unchanged
  • Registers FP8_PER_CHANNEL_PER_TOKEN as a valid quant algo string in DiffusionPipelineConfig
  • Fixes FP8RowwiseLinearMethod.apply to handle 3D activation inputs (batch, seq, hidden); the rowwise GEMM kernel requires 2D; inputs are flattened before the GEMM and unflattened after
  • Adds a vectorized FP8 per-token activation quantization kernel (vendored from vLLM v0.25.0) and an AutoTuner op (tunable_fp8_per_token_quant) that profiles the TRT-LLM kernel (dynamicQuantizeMatrixPerToken) against it at warmup and caches the winner per input shape; VisualGen enables this via FP8RowwiseLinearMethod.use_tunable_quantize; LLM paths leave it disabled; TRTLLM_FP8_QUANT_TACTIC=trtllm|vectorized forces a specific kernel

Perf/quality report example for dynamic FP8 row-wise quant on FLUX.2-dev + Wan 2.2 T2V: https://sc.talos.nvidia.com/view/home/scratch.ostoner_coreai_1/TensorRT-LLM-3/TensorRT-LLM/examples/visual_gen/fp8_rowwise_quant_study.html

Test Coverage

New unit tests:

  • tests/unittest/_torch/visual_gen/test_quant_ops.py: quantize_fp8_rowwise op: output dtype, scale shape (out_features,), round-trip error
  • tests/unittest/_torch/visual_gen/test_model_loader.py: config parse ("FP8_PER_CHANNEL_PER_TOKEN" → QuantAlgo, dynamic_weight_quant=True); weight loading on Wan 1.3B with weight_scale.dim() == 1 assertion
  • tests/unittest/_torch/thop/parallel/test_fp8_per_token_quant_autotuner.py: vectorized kernel: output shape/dtype for bf16/fp16/fp32 inputs, 3D input, scales positive, scale agreement with TRT-LLM kernel; autotuner op: shape/dtype, both tactics numerically equivalent (dequantized), scale dtype normalization to float32, env var forcing (trtllm/vectorized), default tactics include both

Extended existing tests (parametrize additions):

  • tests/unittest/_torch/visual_gen/test_flux_pipeline.py: FP8_PER_CHANNEL_PER_TOKEN added to: FLUX.1/FLUX.2 weight loading, single-layer numerical correctness vs BF16, full transformer e2e cosine similarity vs BF16
  • tests/unittest/_torch/visual_gen/test_ltx2_pipeline.py: weight loading, single-layer correctness, two-stage pipeline loading
  • tests/unittest/_torch/visual_gen/test_cosmos3_transformer.py: transformer weight loading
  • tests/unittest/_torch/visual_gen/test_qwen_image_pipeline_config.py: config parsing

Pre-existing tests covering linear.py change:

  • tests/unittest/_torch/thop/parallel/test_fp8_rowwise_linear.py: FP8RowwiseLinearMethod forward correctness (covers the reshape code path indirectly via the full forward call)
  • tests/unittest/_torch/visual_gen/test_wan21_t2v_pipeline.py: added wan21_t2v_fp8_rowwise fixture and parametrized it into test_fp8_e2e_accuracy (cos_sim > 0.99 vs BF16)
  • tests/unittest/_torch/visual_gen/test_wan22_t2v_pipeline.py: added wan22_t2v_fp8_rowwise fixture covering both transformer stages

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.

Signed-off-by: Olivia Stoner <[email protected]>
@o-stoner

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61636 [ run ] triggered by Bot. Commit: 3e24bd2 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61636 [ run ] completed with state SUCCESS. Commit: 3e24bd2
/LLM/main/L0_MergeRequest_PR pipeline #49843 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

@o-stoner o-stoner changed the title [TRTLLM-14616][feat] add VisualGen fp8 row-wise quant [TRTLLM-14616][feat] add VisualGen fp8 row-wise quant + autotuner Jul 31, 2026
@o-stoner

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #63152 [ run ] triggered by Bot. Commit: 461d69d Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #63152 [ run ] completed with state FAILURE. Commit: 461d69d
/LLM/main/L0_MergeRequest_PR pipeline #51236 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

@o-stoner

o-stoner commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@o-stoner
o-stoner marked this pull request as ready for review August 1, 2026 04:21
@o-stoner
o-stoner requested review from a team as code owners August 1, 2026 04:21
@coderabbitai

coderabbitai Bot commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 3714b36b-00f6-4e4a-97f9-4dd1d0aec3f0

📥 Commits

Reviewing files that changed from the base of the PR and between 6aef5e7 and 228e87a.

📒 Files selected for processing (2)
  • cpp/tensorrt_llm/thop/fp8Op.cpp
  • tensorrt_llm/_torch/custom_ops/torch_custom_ops.py
🚧 Files skipped from review as they are similar to previous changes (2)
  • cpp/tensorrt_llm/thop/fp8Op.cpp
  • tensorrt_llm/_torch/custom_ops/torch_custom_ops.py

Walkthrough

Adds vectorized CUDA per-token FP8 quantization for BF16, FP16, and FP32 inputs. Adds Torch autotuning between TRT-LLM and vectorized tactics. Adds dynamic row-wise FP8 weight quantization and visual-generation integration coverage.

Changes

FP8 quantization integration

Layer / File(s) Summary
CUDA kernel and vectorization primitives
cpp/tensorrt_llm/kernels/fp8PerTokenQuant/*
Adds aligned vector helpers, FP8 conversion utilities, a strided per-token kernel, and typed CUDA launchers.
Torch operator and autotuned execution
cpp/tensorrt_llm/thop/fp8Op.*, tensorrt_llm/_torch/custom_ops/torch_custom_ops.py, tensorrt_llm/_torch/modules/linear.py
Registers the CUDA operator, selects between TRT-LLM and vectorized tactics, normalizes scales, and handles multidimensional activations.
Visual-generation FP8 configuration and weights
tensorrt_llm/_torch/visual_gen/config.py, tensorrt_llm/_torch/visual_gen/quantization/*
Adds FP8_PER_CHANNEL_PER_TOKEN, dynamic activation quantization, and row-wise FP8 weight quantization.
Kernel and autotuner validation
tests/unittest/_torch/thop/parallel/test_fp8_per_token_quant_autotuner.py
Tests output contracts, numerical equivalence, scale normalization, tactic overrides, and tactic availability.
Visual-generation integration coverage
tests/unittest/_torch/visual_gen/*
Extends configuration, loader, row-wise operation, pipeline, and accuracy tests for dynamic per-channel/per-token FP8 quantization.

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

Merge Risk: ⚪ Minimal · up to 228e8

The PR adds VisualGen FP8 row-wise quantization and autotuning with associated tests; no actionable merge-blocking risk remains based on the supplied current-head evidence.

Sequence Diagram(s)

sequenceDiagram
  participant FP8RowwiseLinearMethod
  participant tunable_fp8_per_token_quant
  participant Fp8PerTokenQuantRunner
  participant vectorized_per_token_fp8_quant
  FP8RowwiseLinearMethod->>tunable_fp8_per_token_quant: quantize activation rows
  tunable_fp8_per_token_quant->>Fp8PerTokenQuantRunner: select TRT-LLM or vectorized tactic
  Fp8PerTokenQuantRunner->>vectorized_per_token_fp8_quant: launch vectorized CUDA quantization
  vectorized_per_token_fp8_quant-->>Fp8PerTokenQuantRunner: return FP8 values and scales
  Fp8PerTokenQuantRunner-->>FP8RowwiseLinearMethod: return quantized activations and float32 scales
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 55.93% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the VisualGen FP8 row-wise quantization and autotuner changes.
Description check ✅ Passed The description follows the required template and clearly documents the changes, test coverage, and checklist status.
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.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 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.

Actionable comments posted: 7

🧹 Nitpick comments (6)
cpp/tensorrt_llm/kernels/fp8PerTokenQuant/vectorization.cuh (1)

12-44: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Add #include <type_traits> for std::is_same_v.

q8_n_t uses std::is_same_v at Line 34. The file includes only the two c10 FP8 headers. The build currently works through transitive includes. An explicit include makes the header self-contained.

♻️ Proposed include addition
 `#include` <c10/util/Float8_e4m3fn.h>
 `#include` <c10/util/Float8_e4m3fnuz.h>
+#include <type_traits>
🤖 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/fp8PerTokenQuant/vectorization.cuh` around lines 12
- 44, Add an explicit <type_traits> include to vectorization.cuh so q8_n_t can
use std::is_same_v without relying on transitive includes; leave the
vectorization types and static assertion unchanged.
cpp/tensorrt_llm/kernels/fp8PerTokenQuant/vectorized_fp8_quant_compat.cuh (1)

64-68: 🎯 Functional Correctness | 🔵 Trivial | 💤 Low value

Constrain the fallback vec_conversion template.

The primary template returns x unchanged for any Tout/Tin pair. A call with an unsupported type pair compiles and silently returns the wrong type or an implicit conversion instead of failing. Only the float → c10::Float8_e4m3fn specialization is intended here. Consider replacing the primary template body with a static_assert(sizeof(Tin) == 0, ...) style hard error, or delete the primary definition and keep only the declaration.

🤖 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/fp8PerTokenQuant/vectorized_fp8_quant_compat.cuh`
around lines 64 - 68, Constrain the fallback vec_conversion template so
unsupported Tout/Tin pairs fail at compile time instead of returning x through
implicit conversion. Replace its current return body with a dependent static
assertion or remove the primary definition while retaining the intended
float-to-c10::Float8_e4m3fn specialization.
tests/unittest/_torch/thop/parallel/test_fp8_per_token_quant_autotuner.py (2)

122-128: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Justify or tighten the absolute tolerance on the dequantized comparison.

atol=0.5 with rtol=0.0 is an absolute bound applied to dequantized activations of arbitrary magnitude. For a standard normal input the values stay near ±4, where one FP8 E4M3 step is roughly 0.25, so the test passes. The tolerance does not scale with the input distribution, so this assertion would not catch a real regression on a larger-magnitude input. Use a relative tolerance based on the FP8 step, or state the input range assumption in the docstring.

🤖 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 `@tests/unittest/_torch/thop/parallel/test_fp8_per_token_quant_autotuner.py`
around lines 122 - 128, Update the dequantized comparison in the test around
recon_trt and recon_vec to use a relative tolerance tied to the expected FP8
quantization step, or explicitly document the standard-normal input range
assumption if retaining atol=0.5. Ensure the assertion remains strict enough to
detect regressions on larger-magnitude activations.

18-73: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Add a case with a hidden size that is not a multiple of the vector width.

Every test uses a hidden size of 3072, 4096, or 2048. All are multiples of 16. vectorize_read_with_alignment and vectorize_with_alignment in cpp/tensorrt_llm/kernels/fp8PerTokenQuant/vectorized_vectorization_utils.cuh take the fast vectorized branch only when len % VEC_SIZE == 0 and both pointers are aligned. The scalar prefix path, the output-misalignment fallback, and the tail loop are therefore never executed by these tests. Those branches carry the highest risk of an off-by-one error in this kernel.

Add a case with a hidden size such as 3079, and compare the result against torch.ops.tensorrt_llm.quantize_e4m3_activation.

As per path instructions: "Act as a QA engineer reviewing test changes and coverage for TensorRT-LLM."

🤖 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 `@tests/unittest/_torch/thop/parallel/test_fp8_per_token_quant_autotuner.py`
around lines 18 - 73, Add a test near test_scale_matches_trtllm_kernel using a
hidden size that is not divisible by 16, such as 3079, and invoke both
vectorized_per_token_fp8_quant and quantize_e4m3_activation on the same CUDA
input. Validate matching output shapes and compare the vectorized scales with
the TRT-LLM scales using the existing dtype conversion and numerical tolerance
pattern, covering scalar-prefix, misalignment, and tail handling.

Source: Path instructions

tensorrt_llm/_torch/modules/linear.py (1)

962-965: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Mark use_tunable_quantize as ClassVar and note the process-global effect.

Line 960 declares supports_nccl_symmetric_memory_window_output as ClassVar[bool]. use_tunable_quantize is a plain annotated class attribute, so a type checker treats it as an instance field while Line 1005 reads it from the class. Add ClassVar[bool] for consistency.

The flag is also process-global. A visual generation pipeline that sets FP8RowwiseLinearMethod.use_tunable_quantize = True changes the activation quantization path for every other FP8RowwiseLinearMethod instance in the same process, including LLM models. Prefer carrying this switch on the module or the quantization config. If the global switch is intentional for now, record that constraint in the comment.

♻️ Proposed change
-    # When True, use tunable_fp8_per_token_quant (AutoTuner selects TRT-LLM vs
-    # vectorized kernel). Visual gen pipelines set this to True before model
-    # construction; LLM paths leave it False.
-    use_tunable_quantize: bool = False
+    # When True, use tunable_fp8_per_token_quant (AutoTuner selects TRT-LLM vs
+    # vectorized kernel). Visual gen pipelines set this to True before model
+    # construction; LLM paths leave it False. Note: this is process-global and
+    # applies to every FP8RowwiseLinearMethod instance.
+    use_tunable_quantize: ClassVar[bool] = False
🤖 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 `@tensorrt_llm/_torch/modules/linear.py` around lines 962 - 965, Declare
FP8RowwiseLinearMethod.use_tunable_quantize as ClassVar[bool] to match its
class-level access and prevent type checkers from treating it as an instance
field. Update the surrounding comment to explicitly state that this flag is
process-global and affects every FP8RowwiseLinearMethod instance; retain the
current behavior if the global switch remains intentional.
cpp/tensorrt_llm/kernels/fp8PerTokenQuant/vectorized_cub_helpers.h (1)

12-22: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Namespace the aliases and include <cuda/functional>.

Place CubAddOp and CubMaxOp in namespace vllm to avoid global-scope declarations. Include <cuda/functional> when CUB_VERSION >= 200800; it defines cuda::maximum<>.

🤖 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/fp8PerTokenQuant/vectorized_cub_helpers.h` around
lines 12 - 22, Update the CUB alias declarations in the header by including
<cuda/functional> for CUB_VERSION >= 200800, then place both CubAddOp and
CubMaxOp inside namespace vllm while preserving their existing version-specific
type mappings.
🤖 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.

Inline comments:
In
`@cpp/tensorrt_llm/kernels/fp8PerTokenQuant/vectorized_fp8_per_token_quant_kernel.cuh`:
- Around line 42-44: The kernel and launcher duplicate the 256-thread block size
without enforcing consistency. In vectorized_fp8_per_token_quant_kernel.cuh,
update dynamic_per_token_scaled_fp8_quant_kernel_strided to use a shared named
block-size constant or template parameter for BlockReduce and assert blockDim.x
matches; in cpp/tensorrt_llm/kernels/fp8PerTokenQuant/fp8_per_token_quant.cu
lines 32-38, use that same constant or template parameter for dim3 block instead
of the literal 256.

In `@tensorrt_llm/_torch/custom_ops/torch_custom_ops.py`:
- Around line 2890-2898: Update the return annotation of Fp8PerTokenQuantTactic
forward to represent the two-tensor tuple returned by both underlying
quantization operators, using the project’s preferred built-in generic type
syntax. Leave the operator calls and tactic branching unchanged.

In `@tensorrt_llm/_torch/visual_gen/config.py`:
- Around line 619-622: Remove the process-global assignment to
FP8RowwiseLinearMethod.use_tunable_quantize in the VisualGen configuration flow.
Store the tuner setting on the VisualGen model or relevant linear module, then
propagate it explicitly into the quantization call so VisualGen behavior is
enabled without affecting later LLM row-wise linear operations.

In `@tests/unittest/_torch/thop/parallel/test_fp8_per_token_quant_autotuner.py`:
- Around line 10-16: Add a class-level CUDA availability skip to both test
classes, TestVectorizedPerTokenFP8Quant and the second test class referenced in
the diff, so the suites are skipped when torch.cuda.is_available() is false.
Keep the existing setup and test behavior unchanged when CUDA is available.

In `@tests/unittest/_torch/visual_gen/test_quant_ops.py`:
- Around line 148-154: In test_fp8_rowwise_zero_weight, replace the unused scale
binding returned by quantize_fp8_rowwise with the conventional ignored binding
_, leaving the qweight assertions unchanged.

In `@tests/unittest/_torch/visual_gen/test_qwen_image_pipeline_config.py`:
- Around line 173-179: Update the expected force_dynamic_quantization value in
the dynamic-fp8-rowwise pytest.param case within
test_qwen_pipeline_quant_config_parses_from_args from False to True, matching
the value assigned by DiffusionPipelineConfig.from_pretrained() for
FP8_PER_CHANNEL_PER_TOKEN.

In `@tests/unittest/_torch/visual_gen/test_wan22_t2v_pipeline.py`:
- Around line 311-321: Add a test in test_wan22_t2v_pipeline.py that consumes
the existing wan22_t2v_fp8_rowwise fixture and exercises the corresponding
text-to-video generation path, ensuring the FP8_PER_CHANNEL_PER_TOKEN
configuration is actually covered.

---

Nitpick comments:
In `@cpp/tensorrt_llm/kernels/fp8PerTokenQuant/vectorization.cuh`:
- Around line 12-44: Add an explicit <type_traits> include to vectorization.cuh
so q8_n_t can use std::is_same_v without relying on transitive includes; leave
the vectorization types and static assertion unchanged.

In `@cpp/tensorrt_llm/kernels/fp8PerTokenQuant/vectorized_cub_helpers.h`:
- Around line 12-22: Update the CUB alias declarations in the header by
including <cuda/functional> for CUB_VERSION >= 200800, then place both CubAddOp
and CubMaxOp inside namespace vllm while preserving their existing
version-specific type mappings.

In `@cpp/tensorrt_llm/kernels/fp8PerTokenQuant/vectorized_fp8_quant_compat.cuh`:
- Around line 64-68: Constrain the fallback vec_conversion template so
unsupported Tout/Tin pairs fail at compile time instead of returning x through
implicit conversion. Replace its current return body with a dependent static
assertion or remove the primary definition while retaining the intended
float-to-c10::Float8_e4m3fn specialization.

In `@tensorrt_llm/_torch/modules/linear.py`:
- Around line 962-965: Declare FP8RowwiseLinearMethod.use_tunable_quantize as
ClassVar[bool] to match its class-level access and prevent type checkers from
treating it as an instance field. Update the surrounding comment to explicitly
state that this flag is process-global and affects every FP8RowwiseLinearMethod
instance; retain the current behavior if the global switch remains intentional.

In `@tests/unittest/_torch/thop/parallel/test_fp8_per_token_quant_autotuner.py`:
- Around line 122-128: Update the dequantized comparison in the test around
recon_trt and recon_vec to use a relative tolerance tied to the expected FP8
quantization step, or explicitly document the standard-normal input range
assumption if retaining atol=0.5. Ensure the assertion remains strict enough to
detect regressions on larger-magnitude activations.
- Around line 18-73: Add a test near test_scale_matches_trtllm_kernel using a
hidden size that is not divisible by 16, such as 3079, and invoke both
vectorized_per_token_fp8_quant and quantize_e4m3_activation on the same CUDA
input. Validate matching output shapes and compare the vectorized scales with
the TRT-LLM scales using the existing dtype conversion and numerical tolerance
pattern, covering scalar-prefix, misalignment, and tail handling.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: c6645bec-64db-424d-879e-98fb6d1228af

📥 Commits

Reviewing files that changed from the base of the PR and between f5c2a07 and 461d69d.

📒 Files selected for processing (24)
  • cpp/tensorrt_llm/kernels/fp8PerTokenQuant/fp8_per_token_quant.cu
  • cpp/tensorrt_llm/kernels/fp8PerTokenQuant/fp8_per_token_quant.cuh
  • cpp/tensorrt_llm/kernels/fp8PerTokenQuant/vectorization.cuh
  • cpp/tensorrt_llm/kernels/fp8PerTokenQuant/vectorized_cub_helpers.h
  • cpp/tensorrt_llm/kernels/fp8PerTokenQuant/vectorized_fp8_per_token_quant_kernel.cuh
  • cpp/tensorrt_llm/kernels/fp8PerTokenQuant/vectorized_fp8_quant_compat.cuh
  • cpp/tensorrt_llm/kernels/fp8PerTokenQuant/vectorized_vectorization_utils.cuh
  • cpp/tensorrt_llm/thop/fp8Op.cpp
  • cpp/tensorrt_llm/thop/fp8Op.h
  • tensorrt_llm/_torch/custom_ops/torch_custom_ops.py
  • tensorrt_llm/_torch/modules/linear.py
  • tensorrt_llm/_torch/visual_gen/config.py
  • tensorrt_llm/_torch/visual_gen/quantization/__init__.py
  • tensorrt_llm/_torch/visual_gen/quantization/loader.py
  • tensorrt_llm/_torch/visual_gen/quantization/ops.py
  • tests/unittest/_torch/thop/parallel/test_fp8_per_token_quant_autotuner.py
  • tests/unittest/_torch/visual_gen/test_cosmos3_transformer.py
  • tests/unittest/_torch/visual_gen/test_flux_pipeline.py
  • tests/unittest/_torch/visual_gen/test_ltx2_pipeline.py
  • tests/unittest/_torch/visual_gen/test_model_loader.py
  • tests/unittest/_torch/visual_gen/test_quant_ops.py
  • tests/unittest/_torch/visual_gen/test_qwen_image_pipeline_config.py
  • tests/unittest/_torch/visual_gen/test_wan21_t2v_pipeline.py
  • tests/unittest/_torch/visual_gen/test_wan22_t2v_pipeline.py

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #63180 [ run ] triggered by Bot. Commit: 461d69d Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #63180 [ run ] completed with state FAILURE. Commit: 461d69d
/LLM/main/L0_MergeRequest_PR pipeline #51264 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

Signed-off-by: Olivia Stoner <[email protected]>
@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@o-stoner

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
tensorrt_llm/_torch/custom_ops/torch_custom_ops.py (1)

2872-2896: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Complete the type annotations for Fp8PerTokenQuantRunner.

Annotate unique_id() with -> tuple[()] and replace the List and Tuple aliases in get_valid_tactics() and forward() with Python 3.10 built-in generics.

🤖 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 `@tensorrt_llm/_torch/custom_ops/torch_custom_ops.py` around lines 2872 - 2896,
Complete the annotations in Fp8PerTokenQuantRunner: change unique_id() to return
tuple[()], update get_valid_tactics() to use list[torch.Tensor] for inputs and
list[int] for its return type, and update forward() to use list[torch.Tensor]
for inputs and tuple[torch.Tensor, torch.Tensor] for its return type.

Source: Coding guidelines

🤖 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.

Inline comments:
In `@tensorrt_llm/_torch/modules/linear.py`:
- Around line 984-987: The class-level use_tunable_quantize setting in
FP8RowwiseLinearMethod must not be shared across instances. Move this selection
to per-instance state or pipeline configuration, update the logic around
tunable_fp8_per_token_quant to read that state, and add coverage for
constructing VisualGen followed by LLM in one process so the LLM path retains
its default.

---

Nitpick comments:
In `@tensorrt_llm/_torch/custom_ops/torch_custom_ops.py`:
- Around line 2872-2896: Complete the annotations in Fp8PerTokenQuantRunner:
change unique_id() to return tuple[()], update get_valid_tactics() to use
list[torch.Tensor] for inputs and list[int] for its return type, and update
forward() to use list[torch.Tensor] for inputs and tuple[torch.Tensor,
torch.Tensor] for its return type.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 1cc5574f-a5aa-427e-85d8-6592d7b47b4d

📥 Commits

Reviewing files that changed from the base of the PR and between 5f905ea and 680f941.

📒 Files selected for processing (23)
  • cpp/tensorrt_llm/kernels/fp8PerTokenQuant/fp8_per_token_quant.cu
  • cpp/tensorrt_llm/kernels/fp8PerTokenQuant/fp8_per_token_quant.cuh
  • cpp/tensorrt_llm/kernels/fp8PerTokenQuant/vectorization.cuh
  • cpp/tensorrt_llm/kernels/fp8PerTokenQuant/vectorized_cub_helpers.h
  • cpp/tensorrt_llm/kernels/fp8PerTokenQuant/vectorized_fp8_per_token_quant_kernel.cuh
  • cpp/tensorrt_llm/kernels/fp8PerTokenQuant/vectorized_fp8_quant_compat.cuh
  • cpp/tensorrt_llm/kernels/fp8PerTokenQuant/vectorized_vectorization_utils.cuh
  • cpp/tensorrt_llm/thop/fp8Op.cpp
  • cpp/tensorrt_llm/thop/fp8Op.h
  • tensorrt_llm/_torch/custom_ops/torch_custom_ops.py
  • tensorrt_llm/_torch/modules/linear.py
  • tensorrt_llm/_torch/visual_gen/config.py
  • tensorrt_llm/_torch/visual_gen/quantization/__init__.py
  • tensorrt_llm/_torch/visual_gen/quantization/loader.py
  • tensorrt_llm/_torch/visual_gen/quantization/ops.py
  • tests/unittest/_torch/thop/parallel/test_fp8_per_token_quant_autotuner.py
  • tests/unittest/_torch/visual_gen/test_cosmos3_transformer.py
  • tests/unittest/_torch/visual_gen/test_flux_pipeline.py
  • tests/unittest/_torch/visual_gen/test_ltx2_pipeline.py
  • tests/unittest/_torch/visual_gen/test_model_loader.py
  • tests/unittest/_torch/visual_gen/test_quant_ops.py
  • tests/unittest/_torch/visual_gen/test_qwen_image_pipeline_config.py
  • tests/unittest/_torch/visual_gen/test_wan21_t2v_pipeline.py
🚧 Files skipped from review as they are similar to previous changes (19)
  • cpp/tensorrt_llm/kernels/fp8PerTokenQuant/fp8_per_token_quant.cu
  • tests/unittest/_torch/visual_gen/test_qwen_image_pipeline_config.py
  • cpp/tensorrt_llm/kernels/fp8PerTokenQuant/vectorized_cub_helpers.h
  • tests/unittest/_torch/visual_gen/test_model_loader.py
  • cpp/tensorrt_llm/kernels/fp8PerTokenQuant/vectorized_fp8_quant_compat.cuh
  • tests/unittest/_torch/visual_gen/test_flux_pipeline.py
  • cpp/tensorrt_llm/kernels/fp8PerTokenQuant/fp8_per_token_quant.cuh
  • tensorrt_llm/_torch/visual_gen/quantization/ops.py
  • cpp/tensorrt_llm/kernels/fp8PerTokenQuant/vectorization.cuh
  • cpp/tensorrt_llm/thop/fp8Op.h
  • tests/unittest/_torch/visual_gen/test_cosmos3_transformer.py
  • tensorrt_llm/_torch/visual_gen/quantization/loader.py
  • tests/unittest/_torch/visual_gen/test_ltx2_pipeline.py
  • cpp/tensorrt_llm/kernels/fp8PerTokenQuant/vectorized_fp8_per_token_quant_kernel.cuh
  • cpp/tensorrt_llm/thop/fp8Op.cpp
  • tensorrt_llm/_torch/visual_gen/quantization/init.py
  • tests/unittest/_torch/thop/parallel/test_fp8_per_token_quant_autotuner.py
  • tensorrt_llm/_torch/visual_gen/config.py
  • cpp/tensorrt_llm/kernels/fp8PerTokenQuant/vectorized_vectorization_utils.cuh

Comment thread tensorrt_llm/_torch/modules/linear.py Resolved
@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #65159 [ run ] triggered by Bot. Commit: 680f941 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #69597 [ run ] triggered by Bot. Commit: a561618 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

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

@o-stoner

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #69763 [ run ] triggered by Bot. Commit: a561618 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #69763 [ run ] completed with state SUCCESS. Commit: a561618
/LLM/main/L0_MergeRequest_PR pipeline #57061 completed with status: 'UNSTABLE'

CI Report

⚠️ Multi-GPU Label Required:
Multi-GPU tests require the ci: full pre-merge approved label on this PR. Ask a member of NVIDIA/trt-llm-ci-approvers to add the label, 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

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

LGTM from the infra side.

@o-stoner

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #70399 [ run ] triggered by Bot. Commit: a561618 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #70399 [ run ] completed with state FAILURE. Commit: a561618
/LLM/main/L0_MergeRequest_PR pipeline #57634 completed with status: 'UNSTABLE'

CI Report

⚠️ Multi-GPU Label Required:
Multi-GPU tests require the ci: full pre-merge approved label on this PR. Ask a member of NVIDIA/trt-llm-ci-approvers to add the label, 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

@o-stoner

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #70412 [ run ] triggered by Bot. Commit: a561618 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

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

@o-stoner

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #70457 [ run ] triggered by Bot. Commit: a561618 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

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

@o-stoner

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #70482 [ run ] triggered by Bot. Commit: ad7264b Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

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

@o-stoner

o-stoner commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #70749 [ run ] triggered by Bot. Commit: ad7264b Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

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

@o-stoner

o-stoner commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #71029 [ run ] triggered by Bot. Commit: ad7264b Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #71029 [ run ] completed with state SUCCESS. Commit: ad7264b
/LLM/main/L0_MergeRequest_PR pipeline #58186 completed with status: 'SUCCESS'

CI Report

Link to invocation

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

LGTM

@o-stoner
o-stoner merged commit 999acb6 into NVIDIA:main Sep 3, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants