Repository navigation
cuBLASMp NVFP4 support - #3634
almogsegal wants to merge 8 commits into
Conversation
1f3d589 to
97a4cd4
Compare
[High impact] Adds NVFP4 quantization support to distributed training. The PR still needs the two previously reported test-version compatibility issues addressed before merging. Findings
SummaryAdds NVFP4 inputs to the cuBLASMp backend and extends distributed overlap tests.
Reviews (7) · Last reviewed commit: "Merge branch 'main' into cublasmp-nvfp4" · Reviewed by Greptile |
| if (nvfp4 && init_matrices_fn != AgGemmInitMatrices && | ||
| (algo_attr == CUBLASMP_MATMUL_ALGO_TYPE_SPLIT_P2P || | ||
| algo_attr == CUBLASMP_MATMUL_ALGO_TYPE_SPLIT_MULTICAST) && | ||
| (n % ctx->nranks != 0 || (n / ctx->nranks) % 128 != 0)) { |
There was a problem hiding this comment.
Aligned AllReduce loses overlap. The AllReduce output descriptor gives each rank
n columns, but this check tests n / nranks for 128-column alignment. For example, with n=128 and eight ranks, it replaces an aligned split algorithm with the default algorithm. Results remain correct, but the operation loses communication overlap and emits a misleading warning.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
|
|
||
|
|
||
| # NVFP4 with cuBLASMp applies the global scales through a device-side alpha (cuBLASMp 0.11.0+) | ||
| cublasmp_nvfp4_available = _loaded_cublasmp_version() >= 1100 |
| return 0 | ||
| try: | ||
| version = ctypes.c_int(0) | ||
| ctypes.CDLL("libcublasmp.so.0").cublasMpGetVersion(ctypes.byref(version)) |
There was a problem hiding this comment.
Version probe can crash collection. If an older supported cuBLASMp library uses the version getter that takes a handle and a version pointer, this one-argument call uses the wrong signature. Because it runs when the test module is imported, it can crash collection even for tests that do not use NVFP4.
|
Pipeline 73310509 |
NVFP4 GEMMs apply the tensors' global scales through alpha, which TE computes on the GPU from the amaxes (nvte_nvfp4_compute_per_tensor_scale). Without a host sync this needs device pointer mode for alpha and beta, which cuBLASMp added in 0.11.0 (CUBLASMP_MATMUL_DESCRIPTOR_ATTRIBUTE_POINTER_MODE), so the cuBLASMp backend rejected NVFP4 until now. The cuBLASMp GEMM now mirrors the cuBLASLt NVFP4 path: it uses the TN layout (the transposed column-wise data and its amax replace the row-wise data where needed), passes the FP4 data with VEC16_UE4M3 block scales, and computes alpha on the stream into a small per-context device buffer that also holds the betas 0 and 1. Row-scaled NVFP4, UE5M3 block scales and quantized outputs are rejected with an error. NVFP4 needs cuBLASMp 0.11.0 or newer both at build time and at run time; the run-time check uses cublasMpGetVersion(), so an older loaded library reports an error instead of misreading the device pointers. When n / tp_size is not a multiple of 128, NVFP4 GEMM + ReduceScatter and GEMM + AllReduce use cuBLASMp's default algorithm and warn once, since the explicitly selected split algorithms need a separate B scale tensor for each output-column chunk. With cuBLASMp, the wgrad GEMM after the dgrad AllGather + GEMM all-gathers grad_output again. An NVFP4 grad output is now quantized once, with both usages, before the dgrad GEMM, which uses the row-wise data, and the wgrad all-gather takes the column-wise data, as the non-overlapped all-gather does. Quantizing it a second time would also draw different stochastic-rounding numbers than the non-overlapped path. Signed-off-by: Almog Segal <asegal@nvidia.com>
Add NVFP4 to the cuBLASMp AllGather + GEMM and GEMM + ReduceScatter cases and to the layer overlap tests. Userbuffers does not support NVFP4, so those layer cases are skipped. The layer runner creates BF16 inputs for NVFP4, since the NVFP4 random Hadamard transform supports only BF16 input. The GEMM overlap check compares NVFP4 with the GEMM of its dequantized operands, since NVFP4 quantization error would dominate a comparison with the unquantized operands; this also checks the global scales applied through alpha. The all-gathered input reduces its amax across ranks, as TE's sequence-parallel layers do, while the reduce-scatter inputs keep per-rank global scales. Signed-off-by: Almog Segal <asegal@nvidia.com>
NVFP4 with cuBLASMp needs cuBLASMp 0.11.0 or newer, and the GEMM reports an error with an older library. The GEMM and layer overlap tests now read the version of the cuBLASMp library that TE loaded (cublasMpGetVersion()) and skip their NVFP4 cuBLASMp cases when it is older, as they skip on GPUs without NVFP4 support. Signed-off-by: Almog Segal <asegal@nvidia.com>
…ands The GEMM overlap test compared FP8 and MXFP8 outputs with a GEMM of the unquantized operands, so quantization error set its tolerances. For every quantized format, compute the reference from the dequantized test operands instead, as was already done for NVFP4. Quantization then cancels out, the test checks only the distributed GEMM, and it uses the unquantized tolerances unless the GEMM output itself is quantized. Signed-off-by: Almog Segal <asegal@nvidia.com>
11ee632 to
9949b9f
Compare
Apply consistent quant-dequant pattern for reference tensors. Remove dead FP8 logic. Signed-off-by: Tim Moon <tmoon@nvidia.com>
Signed-off-by: Tim Moon <4406448+timmoon10@users.noreply.github.com>
|
Pipeline 73930633 |
for more information, see https://pre-commit.ci
Signed-off-by: Tim Moon <4406448+timmoon10@users.noreply.github.com>
|
Pipeline 75062152 |
Description
This PR adds NVFP4 support using the cuBLASMp backend
Fixes # (issue)
Type of change
Changes
Please list the changes introduced in this PR:
Checklist: