Repository navigation
[PyTorch] Multi-tensor NVFP4 2D master-weight cast - #3869
Open
sraman-rgb wants to merge 8 commits into
Open
sraman-rgb wants to merge 8 commits into
sraman-rgb wants to merge 8 commits into
Conversation
Add NVTE_NVFP4_FUSED_MASTER_WEIGHT_CAST (default 0). With it set, quantize_master_weights casts the master shards of a distributed optimizer to 2D NVFP4 model weights with four new multi-tensor kernels (common/recipe/nvfp4_multi_tensor.cu, C API in recipe.h, pybind nvfp4_2d_multi_tensor_*): - tile amaxes read from the FP32 master shards directly; values are rounded to the model dtype (BF16) in registers instead of materializing master.to(bf16); - per-tensor global amaxes taken as the maximum of the all-reduced tile amaxes, which replaces the per-tensor compute_amax kernels and the second all-reduce; - fused scale and partial cast for all tensors, one thread per 16x16 tile with vector loads and 8-byte stores of whole tiles, using the same mul_cvt_fp32_to_fp4_4x conversion as nvfp4_2d_partial_cast. Each kernel takes up to 24 tensors per launch with the metadata passed as kernel parameters, so the calls are CUDA-graph capturable. The FP4 data, scale-inverses and amaxes are bit-identical to the default path; FSDP sharded weights, mixed dtypes and other unsupported layouts fall back to it. On one VR200, 32 x (4096x7168 | 7168x2048) BF16 NVFP4 weights with FP32 masters: 13.76 ms -> 0.59 ms of kernel time per call. Signed-off-by: Siddhartha Raman S <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Siddhartha Raman S <[email protected]>
Contributor
Confidence Score: 5/5
[Medium impact] The PR appears safe to merge; no actionable defects were found. SummaryThe PR replaces per-tensor NVFP4 master-weight casts with multi-tensor CUDA kernels.
The earlier fallback disagreement is addressed: every rank now follows the same collective path. No new actionable issues were found. Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Master-weight shards] --> B[Multi-tensor tile amax]
B --> C[One MAX all-reduce]
C --> D[Global amax per tensor]
D --> E[Global and tile scales]
E --> F[Multi-tensor partial FP4 cast]
Reviews (4) · Last reviewed commit: "Merge branch 'main' into sraman/nvfp4-pa..." · Reviewed by Greptile |
for more information, see https://pre-commit.ci
The fused path's eligibility used each rank's own master shards (contiguity, start offset, dtype), so one rank could fall back to the default path, which runs two all-reduces, while the others ran the fused path's one, and training would hang. Eligibility now depends only on the model weights, which every rank holds identically. A rank whose own shards the multi-tensor kernels cannot read casts them to the model dtype and computes its tile amaxes and partial cast with the per-tensor kernels, within the fused path's collective schedule. The test adds an odd slice boundary, so one rank takes the per-tensor kernels and the others the multi-tensor ones. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Siddhartha Raman S <[email protected]>
Signed-off-by: Kirthi Shankar Sivamani <[email protected]>
Signed-off-by: Kirthi Shankar Sivamani <[email protected]>
Signed-off-by: Kirthi Shankar Sivamani <[email protected]>
Member
|
/te-ci |
7 of 13 tasks
This branch has not been deployed
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.
Add NVTE_NVFP4_FUSED_MASTER_WEIGHT_CAST (default 0). With it set, quantize_master_weights casts the master shards of a distributed optimizer to 2D NVFP4 model weights with four new multi-tensor kernels (common/recipe/nvfp4_multi_tensor.cu, C API in recipe.h, pybind nvfp4_2d_multi_tensor_*):
Each kernel takes up to 24 tensors per launch with the metadata passed as kernel parameters, so the calls are CUDA-graph capturable. The FP4 data, scale-inverses and amaxes are bit-identical to the default path; FSDP sharded weights, mixed dtypes and other unsupported layouts fall back to it.
On one VR200, 32 x (4096x7168 | 7168x2048) BF16 NVFP4 weights with FP32 masters: 13.76 ms -> 0.59 ms of kernel time per call.
Description
Please include a brief summary of the changes, relevant motivation and context.
Fixes # (issue)
Type of change
Changes
Please list the changes introduced in this PR:
Checklist: