Skip to content

nvfp4_gemm produces incorrect numerical results on SM120 (Blackwell consumer) #14154

Open

Description

@QilinWan

Title: nvfp4_gemm produces incorrect numerical results on SM120 (Blackwell consumer)

GPU: RTX 5060 Ti (SM 120, Blackwell, 16 GB)
TRT-LLM: main@7021547 (2025-05-15)
CUDA: 13.2 / Driver 595.58.03
Model: Qwen3-8B-NVFP4 (ModelOpt-quantized)
Reproducer: https://github.com/QilinWan/TensorRT-LLM/tree/feat/blackwell-sm120-nvfp4-fallback


Summary

torch.ops.trtllm.nvfp4_gemm produces numerically incorrect results on SM120 (Blackwell consumer GPUs). All backends (CUTLASS, cuBLASLt, CuteDSL) are affected identically.

Evidence

Comparing nvfp4_gemm output to a BF16 dequant reference on the same layer:

Metric BF16 reference nvfp4_gemm Verdict
Correlation 1.000 0.113 Near-zero correlation
Relative error 0% 99% Complete mismatch
Output range -6.4 ~ +6.3 -3.2 ~ +4.7 Wrong magnitude

Correlation and relative error were identical across all backends (cutlass, cublaslt, cutedsl), confirming it is not a single-kernel regression.

Verified not the issue

  1. Weight dequant is correct — E2M1 lookup + scale expansion verified numerically: range -0.54~+0.54, mean 0.000002, no NaN/Inf.
  2. Input fp4_quantize is correct — torch.ops.trtllm.fp4_quantize produces valid FP4 tensors.
  3. SM120 architecture is compiled — cuobjdump confirms sm_120 cubins in all relevant .so files.
  4. Fixed dtype mismatch — weight_scale dtype is float8_e4m3fn in safetensors; nvfp4_gemm expects uint8. Conversion path exists in model loading but the kernel itself still produces wrong results.

Impact

Model initializes and generates without crashes, but output is degenerate (single-token repetition: [d。。。。22222...] or [甲方<<<...]). The model cannot produce coherent text when using nvfp4_gemm on SM120.

Workaround

An architecture-aware fallback is implemented at the Python level:

  • Detect torch.cuda.get_device_capability() == (12, 0)
  • Dequantize NVFP4 weights to BF16 on-the-fly using E2M1 lookup + scale expansion
  • Use torch.matmul instead of nvfp4_gemm
  • Disable Fp4QuantizedTensor activation wrapping to avoid NaN in activation dequant

Branch: feat/blackwell-sm120-nvfp4-fallback
Performance: ~0.6 tok/s (Python dequant bottleneck, acceptable for validation)
Output: diverse tokens (real Chinese + English words), semi-gibberish due to numerical accumulation

Discussion

This appears to be a kernel-level SM120 compatibility issue. The expected fix in PR #4821 (TRT-LLM v1.4) should resolve it. This issue provides real-hardware validation data for that fix.

Full Diagnostic Script

See /tmp/test_precise_gemm.py in the feature branch for the step-by-step layer-level diagnostic that produced the correlation data above.

Activity

  1. added
    Customized kernels
    on May 14, 2026
  2. karljang commented on May 19, 2026

    @karljang
    Collaborator

    @QilinWan,

    Thank you for bringing this to our attention. Could you please check the PR link mentioned in the description? It seems that #4821 is not related to the issue.

  3. added
    bug
    on May 22, 2026
  4. tbraun96 commented on Jun 3, 2026

    @tbraun96

    Disclosure: I maintain Atlas, so consider me biased, but "nvfp4_gemm produces numerically wrong output on SM120" is a class we spent real time on during GB10 bring-up and the root cause was sneaky.

    The thing to check first: consumer Blackwell (SM_120 and GB10 SM_121) does not expose the hardware E2M1 conversion PTX (cvt.rn.satfinite.e2m1x2.f32) that the FP4 GEMM path assumes. On the data-center Blackwell parts it is there, on the desktop/Spark parts it is not. If a kernel emits that instruction anyway, depending on the toolchain you either get a launch failure or, worse, a silently wrong result. We saw the silent-wrong case, and the fix was to swap the hardware cvt for a software E2M1 conversion done with bit manipulation (__float_as_uint, shift, mask) so the FP4 pack/unpack does not depend on the missing instruction.

    The other half is the scale convention. compressed-tensors / ModelOpt store the per-tensor global scale as a divisor (1/scale), and if the GEMM consumes it as a multiplier without re-inverting, you get byte-identical garbage rather than noise. There is a parallel writeup of that exact scale bug on another stack at modular/modular#6600 that is worth a read since the symptom is identical.

    # quick triage on the reproducer:
    # is the wrong output deterministic (byte-identical across runs) or noisy?
    #   deterministic  -> scale handling / E2M1 convert (math bug)
    #   noisy/varies    -> race or uninitialized scratch
    

    @QilinWan is the garbage from your Qwen3-8B-NVFP4 repro byte-identical run to run, or does it vary? And if you have a way to check, is the kernel taking the hardware E2M1 cvt path on that RTX 5060 Ti? Those two answers split this cleanly between the convert-instruction gap and the scale-inversion bug.

  5. QilinWan commented on Jun 7, 2026

    @QilinWan
    Author
  6. waynehacking8 commented on Jun 9, 2026

    @waynehacking8

    I triaged this on an RTX PRO 6000 Blackwell (sm_120 / cc 12.0, driver 580) — a workstation SM120 part — by running the exact op this issue reports.

    torch.ops.trtllm.nvfp4_gemm is numerically correct on the RTX PRO 6000; I could not reproduce the incorrect results here. (tensorrt_llm 1.2.1, torch 2.9.1)

    Test This issue (RTX 5060 Ti) RTX PRO 6000
    Lossless operands (A, B roundtrip NVFP4 exactly → A@B must equal K) — bit-exact, rel-err 0.00000
    Random bf16, correlation vs fp32 0.113 0.9915
    nvfp4_gemm_cutlass / nvfp4_gemm_cublaslt 0.113 0.9915 / 0.9910

    The ~0.99 correlation is the expected 4-bit NVFP4 quantization error (a plain dequant-then-bf16 baseline lands at the same 0.99); the lossless test confirms the kernel itself is bit-exact. Both SM120 runners (CUTLASS, cuBLASLt) agree.

    Note CuteDSL isn't a factor on SM120 — cute_dsl_nvfp4_gemm_blackwell explicitly rejects SM120 (requires SM 100 (B200) or SM 103 (B300), but got SM 120), so on any SM120 GPU only the CUTLASS/cuBLASLt runners execute.

    This points to the problem being specific to consumer Blackwell (RTX 5060 Ti / 5080) rather than universal to SM120 — consistent with the green l0_rtx_pro_6000 NVFP4 CI. Happy to run a specific failing shape/checkpoint on the PRO 6000 if you can share one.

  7. github-actions commented on Jun 24, 2026

    @github-actions

    Issue has not received an update in over 14 days. Adding stale label.

  8. waynehacking8 commented on Jun 24, 2026

    @waynehacking8

    A data point to help isolate this. torch.ops.trtllm.nvfp4_gemm is numerically correct for me on an RTX PRO 6000 (also sm_120) — but I should flag that my build was tensorrt_llm 1.2.1 (released 2026-04-20), which is actually older than the main@7021547 (2026-05-14) reported here. So this isn't a "a later PR fixed it" situation, and SM120 already has a dedicated dispatch path (genericFp4GemmKernelLauncherSm120 in fp4_gemm/fp4_gemm_template.h), not an SM100 fallback — i.e. the SM120 source routing itself isn't the bug.

    Since both cards are sm_120 (same ISA), the working/broken split most likely tracks the environment (CUDA toolchain / driver) rather than TRT-LLM source — consistent with @tbraun96's E2M1/toolchain point. (Separately, on CUDA 13 I did hit ptxas ... Unexpected instruction types specified for 'cvt' while building an unrelated sm_120 low-precision kernel — but to be precise that was a different instruction, FP8 cvt...e4m3x2.bf16x2, not the FP4 e2m1 in question, so it's only thematically related. It does hint that sm_120 + CUDA-13 low-precision codegen is worth ruling out.)

    Suggested isolation: retest the RTX 5060 Ti on identical TRT-LLM with an older/matched CUDA (12.x or 13.0 vs the 13.2 here); if the numbers go correct, this points to a CUDA-13 sm_120 codegen issue for the compiler team rather than a TRT-LLM bug.

  9. tbraun96 commented on Jul 18, 2026

    @tbraun96

    Coming back with a data point that I think reconciles the conflicting results in this thread, and un-stales it, because the divergence is the interesting part.

    @waynehacking8 your RTX PRO 6000 result (numerically correct) and the original GB10 result (silently wrong) are not actually in conflict. The RTX PRO 6000 is sm_120. The GB10 is sm_121. The E2M1 conversion path splits exactly on that line: sm_120 workstation and GeForce Blackwell parts expose the cvt.rn.satfinite.e2m1x2.f32 PTX instruction, while sm_121 (GB10) does not. Kernels that gate the hardware FP4 convert on a "SM 12x" family check compile fine on both but only produce correct numbers where the instruction actually exists. That yields precisely the pattern this thread has collected: correct on sm_120, deterministic garbage on sm_121, no crash anywhere.

    sm_120 (RTX PRO 6000, GeForce Blackwell): cvt.rn.satfinite.e2m1x2.f32 present, hardware FP4 convert, correct results
    sm_121 (GB10 / DGX Spark):               instruction absent, family-gated kernels compile but corrupt silently
    

    The version confound (your 1.2.1 build vs main@7021547) is real but I would bet on the arch split being the controlling variable, since we have reproduced the same class of silent corruption on GB10 across several releases with kernels that assume the E2M1 convert is present.

    For reference, the workaround we carry in Atlas is a software E2M1 conversion (bit manipulation instead of the PTX instruction), which is what let NVFP4 run correctly on sm_121: https://github.com/Avarok-Cybersecurity/atlas/blob/main/docker/gb10/fix_flashinfer_e2m1_sm121.py. The same approach would apply to the nvfp4_gemm path here.

    @waynehacking8 do you have access to a GB10 or another sm_121 part to rerun your exact 1.2.1 repro on? A same-build, both-arches run would cleanly separate the arch hypothesis from the version hypothesis in one experiment.

  10. waynehacking8 commented on Jul 18, 2026

    @waynehacking8

    No GB10 here I'm afraid, the PRO 6000 is my only Blackwell part. But the instruction-presence half of the hypothesis is checkable without one, and it doesn't hold up. CUDA 13.0 ptxas accepts cvt.rn.satfinite.e2m1x2.f32 for sm_121a exactly as it does for sm_120a, and both cubins carry the same hardware convert with the same encoding:

    nvcc -arch=sm_120a -cubin:  F2FP.SATFINITE.E2M1.F32.PACK_AB_MERGE_C R0, R0, R9, RZ   /* 0x...723e */
    nvcc -arch=sm_121a -cubin:  F2FP.SATFINITE.E2M1.F32.PACK_AB_MERGE_C R0, R0, R9, RZ   /* same encoding, "code for sm_121a" */
    

    The rejection side is symmetric too: plain sm_120 and plain sm_121 both fail with Instruction 'cvt with .e2m1x2' not supported on .target, since it's arch-specific (a/f-gated) on both, and the PTX ISA target notes list the e2m1x2 convert as supported on "sm_120f or higher in the same family", i.e. the sm_12x family including GB10. To be precise about scope: this is compile-level evidence, I can't execute on sm_121 silicon. But if kernels silently corrupt on GB10, the mechanism would have to be build/dispatch gating (an sm_120a cubin meeting an sm_121 device, f-vs-a target mixups, runtime cc checks), not an absent instruction.

    Separately, the arch split can't reconcile this particular thread either way: the original report here is an RTX 5060 Ti, which is sm_120, same ISA as my correct PRO 6000 result. So whatever hit the 5060 Ti happened within sm_120, which is why I still think the toolchain/env axis is the live hypothesis for this issue. Last thing: your Atlas link 404s for me and I couldn't find fix_flashinfer_e2m1_sm121.py anywhere in the repo tree; if you can point me at the current path I'd like to read what the workaround actually changes.

  11. Kalex14566 commented on Oct 6, 2026

    @Kalex14566

    Hi @QilinWan @karljang — I read through the original numerical evidence and the follow-up SM120 results in this thread.

    The fact that the NVFP4 GEMM is reported as silently incorrect on one SM120 environment while another SM120 system produces numerically correct results makes this a particularly useful cross-environment verification case.

    We’re building an independent verification system for this class of problem: controlled paired execution, numerical comparison against a reference, reproducible replay, environment capture, and divergence localization.

    If this issue is still useful to investigate, we’d be happy to independently verify the working vs failing configurations at no cost.

    The goal would not be to propose another root-cause hypothesis, but to produce a reproducible evidence matrix that isolates whether the divergence follows the GPU, TensorRT-LLM revision, CUDA/toolchain, driver, or quantization/scale path.

    We’d return the full reproduction and PASS / FAIL / UNPROVEN evidence back to the project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Customized kernelsInvestigatingbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions