Skip to content

[Core][PyTorch] NVFP4 recipe - #2177

Merged
ksivaman merged 48 commits into
NVIDIA:mainfrom
ksivaman:nvfp4_recipe
Sep 29, 2025
Merged

[Core][PyTorch] NVFP4 recipe#2177
ksivaman merged 48 commits into
NVIDIA:mainfrom
ksivaman:nvfp4_recipe

Conversation

@ksivaman

Copy link
Copy Markdown
Member

Description

Add support for the NVFP4 training recipe.

Type of change

  • Documentation change (change only to the documentation, either a fix or a new content)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Infra/Build change
  • Code refactoring

Changes

  • Adds support for NVFP4 block scaling training recipe, including the required kernels and framework infrastructure.

Checklist:

  • I have read and followed the contributing guidelines
  • The functionality is complete
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Signed-off-by: Kirthi Shankar Sivamani <ksivamani@nvidia.com>
Co-authored-by: Frank Sun <frsun@nvidia.com>
Co-authored-by: Oleg Goncharov <ogoncharov@nvidia.com>
Co-authored-by: Zhongbo Zhu <zhongboz@nvidia.com>
Co-authored-by: Evgeny Tsykunov <etsykunov@nvidia.com>
Co-authored-by: Tim Moon <tmoon@nvidia.com>
Co-authored-by: Teddy Do <tdophung@nvidia.com>
@ksivamanksivaman self-assigned this Sep 16, 2025

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

Pull Request Overview

This PR adds support for NVFP4 (4-bit floating point) training recipe, implementing a complete quantization infrastructure for NVFP4 block scaling training. The implementation includes quantization kernels, tensor classes, distributed operations, and integration with the existing transformer engine framework.

Key changes:

  • Implements NVFP4 tensor class and quantizer with block scaling support
  • Adds NVFP4-specific CUDA kernels for quantization and transpose operations
  • Integrates NVFP4 support into distributed operations (all-gather)
  • Updates module infrastructure to support NVFP4 quantization

Reviewed Changes

Copilot reviewed 82 out of 82 changed files in this pull request and generated 10 comments.

Show a summary per file
FileDescription
transformer_engine/pytorch/tensor/nvfp4_tensor.pyCore NVFP4 tensor implementation with quantization logic
transformer_engine/pytorch/fp8.pyNVFP4 recipe state management and quantizer creation
transformer_engine/pytorch/distributed.pyNVFP4 all-gather operations for distributed training
transformer_engine/pytorch/csrc/quantizer.cppC++ NVFP4 quantizer implementation
transformer_engine/common/util/nvfp4_transpose.cuhCUDA kernels for NVFP4 quantization and transpose
transformer_engine/pytorch/experimental/Experimental middleware for NVFP4 reference implementations
Comments suppressed due to low confidence (1)

transformer_engine/pytorch/tensor/nvfp4_tensor.py:1

  • The TODO comment indicates missing documentation. Please add a comprehensive module docstring that explains the NVFP4 tensor implementation, its purpose, and usage patterns.
# Copyright (c) 2022-2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment threadtransformer_engine/pytorch/tensor/_internal/nvfp4_tensor_base.py Outdated
Comment threadtransformer_engine/pytorch/tensor/_internal/nvfp4_tensor_base.py Outdated
Comment threadtransformer_engine/pytorch/tensor/nvfp4_tensor.py Outdated
Comment threadtransformer_engine/pytorch/tensor/nvfp4_tensor.py
Comment threadtransformer_engine/common/util/nvfp4_transpose.cuh Outdated
Comment threadtransformer_engine/pytorch/csrc/quantizer.cpp
Comment threadtransformer_engine/pytorch/csrc/quantizer.cpp
phu0ngng
phu0ngng previously requested changes Sep 17, 2025
Comment threadtransformer_engine/common/common.h Outdated
if (use_2d_quantization && !return_identity) {
return;
}

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.

This function is missing shape checks on the input tensors

Signed-off-by: Tim Moon <tmoon@nvidia.com>
Signed-off-by: Tim Moon <tmoon@nvidia.com>
Signed-off-by: Tim Moon <tmoon@nvidia.com>
Comment threadtransformer_engine/pytorch/csrc/quantizer.cpp
ptrendx
ptrendx previously requested changes Sep 17, 2025
Comment threadtransformer_engine/common/common.h Outdated
ksivamanand others added 4 commits September 18, 2025 02:18
Signed-off-by: Kirthi Shankar Sivamani <ksivamani@nvidia.com>
Signed-off-by: Tim Moon <tmoon@nvidia.com>
Signed-off-by: Tim Moon <tmoon@nvidia.com>
Comment threadbuild_tools/utils.py Outdated
Signed-off-by: Tim Moon <4406448+timmoon10@users.noreply.github.com>
Comment threadbuild_tools/utils.py Outdated
Signed-off-by: Tim Moon <4406448+timmoon10@users.noreply.github.com>
@timmoon10

Copy link
Copy Markdown
Member

/te-ci L1

This reverts commit f8b2a2d.
Signed-off-by: Tim Moon <tmoon@nvidia.com>
@timmoon10

Copy link
Copy Markdown
Member

/te-ci L1

ptrendxand others added 5 commits September 26, 2025 16:56
Signed-off-by: Przemek Tredak <ptredak@nvidia.com>
Signed-off-by: Tim Moon <tmoon@nvidia.com>
Signed-off-by: Tim Moon <tmoon@nvidia.com>
@timmoon10

Copy link
Copy Markdown
Member

/te-ci L1

@ksivaman

Copy link
Copy Markdown
MemberAuthor

/te-ci L1

@ksivaman
ksivaman merged commit 3f5b475 into NVIDIA:mainSep 29, 2025
11 of 13 checks passed
KshitijLakhani pushed a commit that referenced this pull request Sep 29, 2025
* Add NVFP4 recipe
Signed-off-by: Kirthi Shankar Sivamani <ksivamani@nvidia.com>
Co-authored-by: Frank Sun <frsun@nvidia.com>
Co-authored-by: Oleg Goncharov <ogoncharov@nvidia.com>
Co-authored-by: Zhongbo Zhu <zhongboz@nvidia.com>
Co-authored-by: Evgeny Tsykunov <etsykunov@nvidia.com>
Co-authored-by: Tim Moon <tmoon@nvidia.com>
Co-authored-by: Teddy Do <tdophung@nvidia.com>
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Add MathDx dependency to GitHub builds
Signed-off-by: Tim Moon <tmoon@nvidia.com>
* Suggestions from GitHub Copilot
Signed-off-by: Tim Moon <tmoon@nvidia.com>
* Move 2x shape logic from core to PyTorch
Signed-off-by: Kirthi Shankar Sivamani <ksivamani@nvidia.com>
* Fix compilation errors with CUDA 12.1
Signed-off-by: Tim Moon <tmoon@nvidia.com>
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* SM 70 is not supported in CUDA 13
Signed-off-by: Tim Moon <4406448+timmoon10@users.noreply.github.com>
* Typo
Signed-off-by: Tim Moon <4406448+timmoon10@users.noreply.github.com>
* Revert "Move 2x shape logic from core to PyTorch"
This reverts commit f8b2a2d.
Signed-off-by: Tim Moon <tmoon@nvidia.com>
* Added dequantize kernel for FP4
Signed-off-by: Przemek Tredak <ptredak@nvidia.com>
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Fix linter warning
Signed-off-by: Tim Moon <tmoon@nvidia.com>
* Add NVFP4 support with fusible ops
Use logical tensor dims for PyTorch NVFP4 tensors. Temporarily add unfused dequantize impl. Fix bug where NVFP4 recipe was not configurable.
Signed-off-by: Tim Moon <tmoon@nvidia.com>
* Fix logic for 2x shapes and move to PyTorch
Signed-off-by: Kirthi Shankar Sivamani <ksivamani@nvidia.com>
* Fix CG test model config
Signed-off-by: Kirthi Shankar Sivamani <ksivamani@nvidia.com>
* Debug NVFP4 tensor size function
Signed-off-by: Tim Moon <tmoon@nvidia.com>
* Proper handling of the RNG state
Signed-off-by: Przemek Tredak <ptredak@nvidia.com>
* Test SR properly
Signed-off-by: Przemek Tredak <ptredak@nvidia.com>
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Fix workspace size for GEMM heuristic.
Signed-off-by: Kirthi Shankar Sivamani <ksivamani@nvidia.com>
* Fix compile error in C++ NVFP4 test
Some some numeric errors when blocks are all zero.
Signed-off-by: Tim Moon <tmoon@nvidia.com>
* fix distrbuted test problem shape
Signed-off-by: zhongboz <zhongboz@nvidia.com>
* proper assert dim for low precision AG TP
Signed-off-by: zhongboz <zhongboz@nvidia.com>
* clean up duplicated code in nvfp4_utils.cuh
Signed-off-by: zhongboz <zhongboz@nvidia.com>
* lint
Signed-off-by: zhongboz <zhongboz@nvidia.com>
* pylint: disable=unused-argument
Signed-off-by: zhongboz <zhongboz@nvidia.com>
* `nvte_cublas_gemm_v2` to take alpha pointer (#12)
* make nvte_cublas_gemm_v2 to take alpha/beta pointers
Signed-off-by: Phuong Nguyen <phuonguyen@nvidia.com>
* users are expected to pass a valid C_tensor
Signed-off-by: Phuong Nguyen <phuonguyen@nvidia.com>
* typos
Signed-off-by: Phuong Nguyen <phuonguyen@nvidia.com>
* API to have const float* alpha
Signed-off-by: Phuong Nguyen <phuonguyen@nvidia.com>
* Minor tweaks
Support arbitrary beta scales. Increase workspace to be aligned to 128 bytes.
Signed-off-by: Tim Moon <tmoon@nvidia.com>
* Debug IMA with alpha pointer
Signed-off-by: Tim Moon <tmoon@nvidia.com>
---------
Signed-off-by: Phuong Nguyen <phuonguyen@nvidia.com>
Signed-off-by: Tim Moon <tmoon@nvidia.com>
Co-authored-by: Tim Moon <tmoon@nvidia.com>
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Support fused amax kernels with NVFP4 quantization
Signed-off-by: Tim Moon <tmoon@nvidia.com>
* Disable fused amax with cuDNN LayerNorm kernel
Signed-off-by: Tim Moon <tmoon@nvidia.com>
* Add NVFP4 cases to distributed tests for TE ops
Signed-off-by: Tim Moon <tmoon@nvidia.com>
* Change assert to NVTE_CHECK in the hadamard cast fusion
Signed-off-by: Przemek Tredak <ptredak@nvidia.com>
* Fix compile error
Signed-off-by: Tim Moon <tmoon@nvidia.com>
* Use global thread IDs for Philox subsequences
Signed-off-by: Tim Moon <tmoon@nvidia.com>
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Add shape checks for NVFP4 cast kernels
Signed-off-by: Tim Moon <tmoon@nvidia.com>
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Do not fuse amax if cuDNN normalization is forced by envvar
Signed-off-by: Przemek Tredak <ptredak@nvidia.com>
---------
Signed-off-by: Kirthi Shankar Sivamani <ksivamani@nvidia.com>
Signed-off-by: Tim Moon <tmoon@nvidia.com>
Signed-off-by: Tim Moon <4406448+timmoon10@users.noreply.github.com>
Signed-off-by: Przemek Tredak <ptredak@nvidia.com>
Signed-off-by: zhongboz <zhongboz@nvidia.com>
Signed-off-by: Phuong Nguyen <phuonguyen@nvidia.com>
Co-authored-by: Frank Sun <frsun@nvidia.com>
Co-authored-by: Oleg Goncharov <ogoncharov@nvidia.com>
Co-authored-by: Zhongbo Zhu <zhongboz@nvidia.com>
Co-authored-by: Evgeny Tsykunov <etsykunov@nvidia.com>
Co-authored-by: Tim Moon <tmoon@nvidia.com>
Co-authored-by: Teddy Do <tdophung@nvidia.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Tim Moon <4406448+timmoon10@users.noreply.github.com>
Co-authored-by: Przemek Tredak <ptredak@nvidia.com>
Co-authored-by: Phuong Nguyen <phuonguyen@nvidia.com>
@ksivamanksivaman mentioned this pull request Sep 30, 2025
13 tasks
@yash3056

Copy link
Copy Markdown

does nvfp4 only work with sm100 or all arch above sm100?

@kooshikooshi mentioned this pull request Oct 13, 2025
sbhavani added a commit to sbhavani/TransformerEngine that referenced this pull request Oct 15, 2025
- Adds NVFP4 pretraining research paper with PR NVIDIA#2177 reference
Signed-off-by: Santosh Bhavani <santosh.bhavani@live.com>
ksivaman added a commit that referenced this pull request Oct 15, 2025
* Enhance Latest News section with recent TE and FP8 developments
- Adds NVFP4 pretraining research paper with PR #2177 reference
Signed-off-by: Santosh Bhavani <santosh.bhavani@live.com>
* update nvfp4 reference
Signed-off-by: Santosh Bhavani <santosh.bhavani@live.com>
* Update README.rst
Signed-off-by: Kirthi Shankar Sivamani <ksivamani@nvidia.com>
---------
Signed-off-by: Santosh Bhavani <santosh.bhavani@live.com>
Signed-off-by: Kirthi Shankar Sivamani <ksivamani@nvidia.com>
Co-authored-by: Kirthi Shankar Sivamani <ksivamani@nvidia.com>
@ksivamanksivaman mentioned this pull request Oct 16, 2025
13 tasks
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

12 participants

@ksivaman@timmoon10@charmin161@qijiaxing@muse-coder@zhongbozhu@yash3056@ptrendx@tsengalb99@phu0ngng@jberchtold-nvidia