You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
RuntimeError: cuBLAS error code=15 in fp8_nn_dev (sm_89) #21
In gemm_runner.cu there are several FP8 GEMM functions:
Function
Used ?
TRANSB
fp8_gemm
No
CUBLAS_OP_T
fp8_run
No
CUBLAS_OP_T
fp8_run_dev
No
CUBLAS_OP_T
fp8_nn_dev
Yes (via pipeline_rtx.py)
CUBLAS_OP_N
The three unused functions all set TRANSB = CUBLAS_OP_T, but the production path fp8_nn_dev uses CUBLAS_OP_N.
Meanwhile, the BF16_NN branch uses the same cuBLAS descriptor layout (CUBLAS_OP_N + row-major B(K, N)) and works without issues.
My Understanding
In pi05_rtx.py → convert_pi05_safetensors, all linear layer weights are transposed before storage ((N, K) → .t() → (K, N)). So weights are stored as row-major (K, N) on GPU.
cuBLAS assumes column-major. The three unused FP8 functions use CUBLAS_OP_T to account for this transposed layout, while fp8_nn_dev does not.
Since BF16_NN (same layout, no CUBLAS_OP_T) works fine, I suspect the code=15 may be caused by FP8 Tensor Cores having stricter requirements for matrix layout contiguity compared to BF16.
Could you help clarify what's causing this discrepancy? Is the TRANSB difference between fp8_nn_dev and the unused functions intentional, or is there a layout issue on sm_89 that needs to be addressed?
Your understanding of the stored weight layout is correct: in the Pi0.5 RTX path,
linear weights are converted from the original HF layout (N, K) into row-major (K, N) before being stored on GPU.
The TRANSB difference is intentional, though. The older fp8_gemm, fp8_run, and fp8_run_dev helpers use a different/legacy operand convention,
where the weight is treated as (N, K) and the GEMM computes A @ B^T, so those
paths set TRANSB = CUBLAS_OP_T.
The production fp8_nn_dev path is the no-transpose path:
A(M, K) @ B(K, N) -> D(M, N)
so TRANSB = CUBLAS_OP_N matches the current stored (K, N) weight layout.
Changing fp8_nn_dev to TRANSB = CUBLAS_OP_T would not be correct for the
current Pi0.5 RTX weights.
The L40 failure is more likely caused by cuBLASLt FP8 algorithm/layout support on
Ada sm_89, rather than by a simple missing transpose. BF16 GEMM is more
permissive here, while FP8 Tensor Core kernels can reject descriptor/layout
combinations that work for BF16, and may also behave differently from the
Blackwell sm_120 path.
There is already another FP8 GEMM path in the core library, fp8_gemm_descale_fp16 / fp8_gemm_descale_bf16out, which uses the
cuBLASLt operand-swap/column-major convention and is intended to work on SM89+.
So the likely fix is not to rewrite the FP8 kernel or flip TRANSB in fp8_nn_dev, but to route the Pi0.5 RTX sm_89 pipeline through that existing
SM89-compatible FP8 path.
Separately, another tester is helping validate the SM89
FP8 pipeline locally, and I should be able to update this soon with the proper
SM89 FP8 routing once that test is confirmed.
Thanks for the clarification. I also tested fp8_gemm_descale_bf16out on SM89 following your suggestion.
The results are as follows:
[fp8_gemm_descale_bf16out] Heuristic FAILED for [64,64,32]
tensor([ 9.9945e-04, -7.3242e-03, -3.6316e-03, -1.2939e-02, -6.5918e-03,
-1.3733e-03, 3.3379e-05, -6.1340e-03, 4.5776e-05, -7.6294e-03],
device='cuda:0', dtype=torch.bfloat16)
tensor([0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], device='cuda:0',
dtype=torch.bfloat16)
Max diff: 0.021606
Mean diff: 0.004419
Cos sim: 0.000000
For reference, I compared against a standard BF16 torch.matmul result.
It seems that due to the heuristic failure, the kernel does not produce valid FP8 GEMM results (likely skipping the actual computation path), which leads to all-zero outputs.
I’m not sure whether this is related to my specific device setup (NVIDIA L40 / SM89) or if it indicates an issue in the current implementation or unsupported path in the FP8 routing.
importtorchimportflash_rt.flash_rt_kernelsasfvktorch.manual_seed(42)
M, N, K=64, 64, 32A=torch.randn(M, K, device="cuda", dtype=torch.bfloat16) /KB=torch.randn(K, N, device="cuda", dtype=torch.bfloat16) /KA_fp8=A.to(torch.float8_e4m3fn)
B_fp8=B.to(torch.float8_e4m3fn)
D_cublas=torch.empty(M, N, device="cuda", dtype=torch.bfloat16)
scale_a=torch.ones(1, device="cuda", dtype=torch.float32)
scale_b=torch.ones(1, device="cuda", dtype=torch.float32)
stream=torch.cuda.current_stream().cuda_streamfvk.fp8_gemm_descale_bf16out(
A_fp8.data_ptr(), B_fp8.data_ptr(), D_cublas.data_ptr(),
M, N, K,
scale_a.data_ptr(), scale_b.data_ptr(),
stream
)
torch.cuda.synchronize()
A_ref=A.to(torch.bfloat16)
B_ref=B.to(torch.bfloat16)
D_ref=torch.matmul(A_ref, B_ref)
diff=torch.abs(D_cublas.float() -D_ref.float())
print(D_ref[0][:10])
print(D_cublas[0][:10])
cos_sim=torch.nn.functional.cosine_similarity(
D_cublas.flatten().float(), D_ref.flatten().float(), dim=0
).item()
print(f"Max diff: {diff.max().item():.6f}")
print(f"Mean diff: {diff.mean().item():.6f}")
print(f"Cos sim: {cos_sim:.6f}")
Thanks for the detailed test. I think there are two separate issues here.
First, the TRANSB difference is intentional. The legacy helpers and the current production path use different operand conventions.
The older fp8_gemm / fp8_run / fp8_run_dev helpers treat the weight as [N, K] and compute:
A[M, K] @ B[N, K]^T -> D[M, N]
so those paths use TRANSB = CUBLAS_OP_T.
The production fp8_nn_dev path treats the weight as already stored in row-major [K, N] and computes:
A[M, K] @ B[K, N] -> D[M, N]
so TRANSB = CUBLAS_OP_N is correct for the current Pi0.5 RTX weights. Flipping fp8_nn_dev to TRANSB=T would make the math/layout wrong.
The BF16_NN path working with the same [K, N] logical layout is a good sanity check that the layout convention is not simply transposed incorrectly. It does not imply the same descriptor combination must be supported for FP8. The failure is more likely that cuBLASLt on L40 / sm_89 does not support this particular FP8 descriptor/layout/output combination, while BF16 is more permissive.
Second, your fp8_gemm_descale_bf16out test exposed a real implementation issue. If cuBLASLt returns no heuristic, that helper currently only prints a warning and continues, instead of returning an error or throwing. In that case the output should be treated as undefined. The all-zero output is not a valid FP8 GEMM result.
So the summary is:
The TRANSB reasoning is a misunderstanding of the two different operand conventions.
The L40 failure is real, but it is an SM89 FP8 cuBLASLt support/routing issue, not a missing transpose.
fp8_gemm_descale_bf16out also needs better failure handling before it can be used as a reliable fallback.
Suggested next steps:
Do not change fp8_nn_dev to TRANSB=T.
Add hard error handling to the descale FP8 helpers, especially fp8_gemm_descale_bf16out, when heuristic returns no algorithm or cublasLtMatmul fails.
Build a small SM89 probe matrix for:
fp8_nn_dev
fp8_gemm_descale_fp16
fp8_gemm_descale_bf16out
relevant Pi0.5 shapes, not only [64,64,32]
Route SM89 separately only after a path is confirmed to produce valid numerical output.
And I will also fix the silent-failure behavior. In particular, the descale FP8 helpers should not continue after cuBLASLt returns no heuristic or after cublasLtMatmul returns a non-success status. I will update these paths to raise a clear runtime error instead of leaving the output undefined. That will not make the SM89 path supported by itself, but it will prevent invalid all-zero outputs from being mistaken for valid GEMM results.
The current implementation of fp8_gemm_descale_bf16out sets both TRANSA and TRANSB to opN, resulting in an NN layout for FP8 GEMM. However, according to cuBLASLt documentation and runtime behavior, FP8 GEMM only supports TN layout, and NN configuration leads to CUBLAS_STATUS_NOT_SUPPORTED during heuristic selection.
This causes runtime failure in cublasLtMatmulAlgoGetHeuristic using CUBLASLT_LOG_LEVEL=5.
[cublasLt][234782][Error][cublasLtMatmulAlgoGetHeuristic] FP8 matrix multiplications support only TN input layout. Got NN
So it looks like this is not an issue with my environment or configuration, but rather a problem in the code, right?
Thanks again for digging into this and for pointing out the cuBLASLt FP8 layout requirement.
I pushed a tentative SM89 fix to this branch:
Add-SM89-compatible-FP8-GEMM-layout
The change keeps the existing SM120 path unchanged, and adds a separate SM89 FP8 GEMM route. For SM89, Pi0.5 now stores FP8 weights as [N, K] and dispatches through a new fp8_nt_dev path, so the GEMM is computed as:
A[M, K] @ B[N, K]^T -> D[M, N]
This matches the FP8 TN-style layout requirement from cuBLASLt, while avoiding changing the existing fp8_nn_dev path used by the current Blackwell route.
Your test worked because it manually prepared B as B.t().contiguous(), which effectively matched the [N, K] weight layout expected by the transpose-B FP8 path. The previous production path still used the [K, N] no-transpose layout, which cuBLASLt rejects for FP8 on SM89.
Thanks for the clarification and for pushing the SM89 fix.
I’ve tested the updated branch. The FP8 pipeline now runs correctly and the numerical results are also reasonable. Compared to BF16 reference outputs, the FP8 inference results are very close, with only minor deviations expected from FP8 quantization.
Thanks again for your help and the quick turnaround on this fix.
Update benchmark result on L40(2 views using FP8). Pretty good.
Benchmark (20 iter, warmup=500):
P50: 26.6 ms (38 Hz)
min: 26.2, mean: 26.7, max: 27.3 ms
============================================================
RESULTS: libero_spatial (server)
============================================================
Task 0: 50/50 = 100.0% pick up the black bowl between the plate and the ramekin and place it on the plate
Task 1: 50/50 = 100.0% pick up the black bowl next to the ramekin and place it on the plate
Task 2: 50/50 = 100.0% pick up the black bowl from table center and place it on the plate
Task 3: 49/50 = 98.0% pick up the black bowl on the cookie box and place it on the plate
Task 4: 49/50 = 98.0% pick up the black bowl in the top drawer of the wooden cabinet and place it on the plate
Task 5: 45/50 = 90.0% pick up the black bowl on the ramekin and place it on the plate
Task 6: 50/50 = 100.0% pick up the black bowl next to the cookie box and place it on the plate
Task 7: 50/50 = 100.0% pick up the black bowl on the stove and place it on the plate
Task 8: 50/50 = 100.0% pick up the black bowl next to the plate and place it on the plate
Task 9: 49/50 = 98.0% pick up the black bowl on the wooden cabinet and place it on the plate
============================================================
Overall: 492/500 = 98.4%
============================================================
Activity
LiangSu8899 commentedon May 11, 2026
Thanks for the detailed report and analysis.
Your understanding of the stored weight layout is correct: in the Pi0.5 RTX path,
linear weights are converted from the original HF layout
(N, K)into row-major(K, N)before being stored on GPU.The
TRANSBdifference is intentional, though. The olderfp8_gemm,fp8_run, andfp8_run_devhelpers use a different/legacy operand convention,where the weight is treated as
(N, K)and the GEMM computesA @ B^T, so thosepaths set
TRANSB = CUBLAS_OP_T.The production
fp8_nn_devpath is the no-transpose path:A(M, K) @ B(K, N) -> D(M, N)so
TRANSB = CUBLAS_OP_Nmatches the current stored(K, N)weight layout.Changing
fp8_nn_devtoTRANSB = CUBLAS_OP_Twould not be correct for thecurrent Pi0.5 RTX weights.
The L40 failure is more likely caused by cuBLASLt FP8 algorithm/layout support on
Ada
sm_89, rather than by a simple missing transpose. BF16 GEMM is morepermissive here, while FP8 Tensor Core kernels can reject descriptor/layout
combinations that work for BF16, and may also behave differently from the
Blackwell
sm_120path.There is already another FP8 GEMM path in the core library,
fp8_gemm_descale_fp16/fp8_gemm_descale_bf16out, which uses thecuBLASLt operand-swap/column-major convention and is intended to work on SM89+.
So the likely fix is not to rewrite the FP8 kernel or flip
TRANSBinfp8_nn_dev, but to route the Pi0.5 RTXsm_89pipeline through that existingSM89-compatible FP8 path.
Separately, another tester is helping validate the SM89
FP8 pipeline locally, and I should be able to update this soon with the proper
SM89 FP8 routing once that test is confirmed.
wangerforcs commentedon May 11, 2026
Thanks for the clarification. I also tested
fp8_gemm_descale_bf16outon SM89 following your suggestion.The results are as follows:
For reference, I compared against a standard BF16
torch.matmulresult.It seems that due to the heuristic failure, the kernel does not produce valid FP8 GEMM results (likely skipping the actual computation path), which leads to all-zero outputs.
I’m not sure whether this is related to my specific device setup (NVIDIA L40 / SM89) or if it indicates an issue in the current implementation or unsupported path in the FP8 routing.
LiangSu8899 commentedon May 11, 2026
Thanks for the detailed test. I think there are two separate issues here.
First, the TRANSB difference is intentional. The legacy helpers and the current production path use different operand conventions.
The older fp8_gemm / fp8_run / fp8_run_dev helpers treat the weight as [N, K] and compute:
so those paths use TRANSB = CUBLAS_OP_T.
The production fp8_nn_dev path treats the weight as already stored in row-major [K, N] and computes:
so TRANSB = CUBLAS_OP_N is correct for the current Pi0.5 RTX weights. Flipping fp8_nn_dev to TRANSB=T would make the math/layout wrong.
The BF16_NN path working with the same [K, N] logical layout is a good sanity check that the layout convention is not simply transposed incorrectly. It does not imply the same descriptor combination must be supported for FP8. The failure is more likely that cuBLASLt on L40 / sm_89 does not support this particular FP8 descriptor/layout/output combination, while BF16 is more permissive.
Second, your fp8_gemm_descale_bf16out test exposed a real implementation issue. If cuBLASLt returns no heuristic, that helper currently only prints a warning and continues, instead of returning an error or throwing. In that case the output should be treated as undefined. The all-zero output is not a valid FP8 GEMM result.
So the summary is:
Suggested next steps:
And I will also fix the silent-failure behavior. In particular, the descale FP8 helpers should not continue after cuBLASLt returns no heuristic or after cublasLtMatmul returns a non-success status. I will update these paths to raise a clear runtime error instead of leaving the output undefined. That will not make the SM89 path supported by itself, but it will prevent invalid all-zero outputs from being mistaken for valid GEMM results.
Thx!!
wangerforcs commentedon May 12, 2026
The current implementation of fp8_gemm_descale_bf16out sets both TRANSA and TRANSB to opN, resulting in an NN layout for FP8 GEMM. However, according to cuBLASLt documentation and runtime behavior, FP8 GEMM only supports TN layout, and NN configuration leads to CUBLAS_STATUS_NOT_SUPPORTED during heuristic selection.
This causes runtime failure in cublasLtMatmulAlgoGetHeuristic using CUBLASLT_LOG_LEVEL=5.
So it looks like this is not an issue with my environment or configuration, but rather a problem in the code, right?
Scripts below seem correct.
LiangSu8899 commentedon May 12, 2026
Thanks again for digging into this and for pointing out the cuBLASLt FP8 layout requirement.
I pushed a tentative SM89 fix to this branch:
Add-SM89-compatible-FP8-GEMM-layout
The change keeps the existing SM120 path unchanged, and adds a separate SM89 FP8 GEMM route. For SM89, Pi0.5 now stores FP8 weights as [N, K] and dispatches through a new fp8_nt_dev path, so the GEMM is computed as:
A[M, K] @ B[N, K]^T -> D[M, N]
This matches the FP8 TN-style layout requirement from cuBLASLt, while avoiding changing the existing fp8_nn_dev path used by the current Blackwell route.
Your test worked because it manually prepared B as B.t().contiguous(), which effectively matched the [N, K] weight layout expected by the transpose-B FP8 path. The previous production path still used the [K, N] no-transpose layout, which cuBLASLt rejects for FP8 on SM89.
Could you try this branch on your L40 setup and check whether Pi0.5 FP8 now runs correctly?
https://github.com/LiangSu8899/FlashRT/tree/Add-SM89-compatible-FP8-GEMM-layout
wangerforcs commentedon May 13, 2026
Thanks for the clarification and for pushing the SM89 fix.
I’ve tested the updated branch. The FP8 pipeline now runs correctly and the numerical results are also reasonable. Compared to BF16 reference outputs, the FP8 inference results are very close, with only minor deviations expected from FP8 quantization.
Thanks again for your help and the quick turnaround on this fix.
Update benchmark result on L40(2 views using FP8). Pretty good.
============================================================ RESULTS: libero_spatial (server) ============================================================ Task 0: 50/50 = 100.0% pick up the black bowl between the plate and the ramekin and place it on the plate Task 1: 50/50 = 100.0% pick up the black bowl next to the ramekin and place it on the plate Task 2: 50/50 = 100.0% pick up the black bowl from table center and place it on the plate Task 3: 49/50 = 98.0% pick up the black bowl on the cookie box and place it on the plate Task 4: 49/50 = 98.0% pick up the black bowl in the top drawer of the wooden cabinet and place it on the plate Task 5: 45/50 = 90.0% pick up the black bowl on the ramekin and place it on the plate Task 6: 50/50 = 100.0% pick up the black bowl next to the cookie box and place it on the plate Task 7: 50/50 = 100.0% pick up the black bowl on the stove and place it on the plate Task 8: 50/50 = 100.0% pick up the black bowl next to the plate and place it on the plate Task 9: 49/50 = 98.0% pick up the black bowl on the wooden cabinet and place it on the plate ============================================================ Overall: 492/500 = 98.4% ============================================================Summary page: restate the real problem with Chenwei's measured 27B co…
Summary page: restate the real problem with Chenwei's measured 27B co…