Skip to content

Prototype NVFP4 with FP8 UE5M3 block scales - #3325

Open
timmoon10 wants to merge 40 commits into
NVIDIA:mainfrom
timmoon10:nvfp4-ue5m3-prototype
Open

Prototype NVFP4 with FP8 UE5M3 block scales#3325
timmoon10 wants to merge 40 commits into
NVIDIA:mainfrom
timmoon10:nvfp4-ue5m3-prototype

Conversation

@timmoon10

@timmoon10 timmoon10 commented Aug 7, 2026

Copy link
Copy Markdown
Member

Description

This is a proof-of-concept for NVFP4 with FP8 UE5M3 block scales. Quantization is supported natively and GEMMs go through the cuDNN Frontend kernels (see NVIDIA/cudnn-frontend#545).

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

  • Support NVFP4 tensors with UE5M3 scales
  • Support UE5M3 scales in NVFP4 quantize/dequantize kernels
  • Support UE5M3 scales in NVFP4 quantizers

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

Co-authored-by: Teddy Do <tdophung@nvidia.com>
Co-authored-by: Varun Thumbe <vthumbe@nvidia.com>
Signed-off-by: Tim Moon <tmoon@nvidia.com>
@timmoon10 timmoon10 added the enhancement New feature or request label Aug 7, 2026
@timmoon10

This comment was marked as outdated.

* [PyTorch] Enable e5m3 fused GEMM kernels from cuDNN

Signed-off-by: Kaining Zhong <kainingz@nvidia.com>

* have to pad to 256 to use cuDNN

Signed-off-by: Kaining Zhong <kainingz@nvidia.com>

* fix: need to pass scale_dtype

Signed-off-by: Kaining Zhong <kainingz@nvidia.com>

* route wgrad to cuDNN's wgrad API

Signed-off-by: Kaining Zhong <kainingz@nvidia.com>

* Support grouped linear with NVFP4-UE5M3

NVFP4-UE5M3 grouped GEMM falls back to dense GEMMs. Generalize usage of wgrad kernel and use when tensors sizes are not 256-aligned. Fix inconsistent m,n,k GEMM notation. Remove ue5m3 hacks in op fuser tests. Add ue5m3 to grouped MLP tests.

Signed-off-by: Tim Moon <tmoon@nvidia.com>

* Fix typos

Co-authored-by: Codex <noreply@openai.com>
Signed-off-by: Tim Moon <tmoon@nvidia.com>

---------

Signed-off-by: Kaining Zhong <kainingz@nvidia.com>
Signed-off-by: Tim Moon <tmoon@nvidia.com>
Co-authored-by: Tim Moon <tmoon@nvidia.com>
Co-authored-by: Codex <noreply@openai.com>
Comment thread transformer_engine/pytorch/cpp_extensions/gemm.py Outdated
Comment thread transformer_engine/common/include/transformer_engine/recipe.h
Signed-off-by: Tim Moon <tmoon@nvidia.com>
Signed-off-by: Tim Moon <tmoon@nvidia.com>
@timmoon10
timmoon10 force-pushed the nvfp4-ue5m3-prototype branch from 0987860 to ab3a9b3 Compare August 14, 2026 12:09
Comment thread transformer_engine/pytorch/cpp_extensions/gemm.py Outdated
timmoon10 and others added 5 commits August 14, 2026 12:44
@timmoon10
timmoon10 marked this pull request as ready for review August 17, 2026 21:35
@greptile-apps

greptile-apps Bot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This proof-of-concept adds UE5M3 block-scale support to NVFP4 quantization and routes compatible GEMMs through cuDNN Frontend.

  • Propagates the scale dtype through native kernels, PyTorch quantizers, tensor storage, reconstruction, and grouped operations.
  • Adds UE5M3-aware scaling, dequantization, GEMM dispatch, and grouped-MLP execution.
  • Extends native and PyTorch numerical coverage for quantization, GEMM, grouped execution, and graph-safe paths.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
transformer_engine/pytorch/ops/fused/grouped_mlp.py Propagates UE5M3 metadata and scaling through grouped-MLP forward and backward kernels while preserving unfused and optional-kernel fallbacks.
transformer_engine/pytorch/tensor/nvfp4_tensor.py Extends NVFP4 quantizer and tensor metadata to retain the selected block-scale dtype.
transformer_engine/pytorch/tensor/storage/nvfp4_tensor_storage.py Updates NVFP4 storage allocation and reconstruction for E4M3 or UE5M3 block scales.
transformer_engine/pytorch/quantization.py Adds UE5M3 capability checks and creates NVFP4 quantizers with recipe-selected scale dtypes.
transformer_engine/common/cast/nvfp4/core_nvfp4.cuh Generalizes native NVFP4 scale calculations and storage handling for UE5M3.
transformer_engine/common/gemm/cublaslt_gemm.cu Updates GEMM dispatch boundaries to account for the new NVFP4 scale representation.
tests/pytorch/test_grouped_mlp.py Expands grouped-MLP coverage for UE5M3 NVFP4 configurations and execution paths.
tests/cpp/operator/test_cast_nvfp4_transpose.cu Adds exact native reference coverage for UE5M3 NVFP4 cast and transpose behavior.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart LR
    R[NVFP4 recipe] --> Q[UE5M3-aware quantizer]
    Q --> T[FP4 data and UE5M3 block scales]
    T --> S[Scale layout preparation]
    S --> G[cuDNN Frontend GEMM]
    G --> O[High-precision or quantized output]
    T --> D[Dequantization]
    D --> H[High-precision tensor]
Loading

Reviews (21): Last reviewed commit: "Avoid redundant amax ptr check in row-sc..." | Re-trigger Greptile

Comment thread transformer_engine/pytorch/ops/fused/grouped_mlp.py
Signed-off-by: Tim Moon <tmoon@nvidia.com>
Signed-off-by: Tim Moon <tmoon@nvidia.com>
Signed-off-by: Tim Moon <tmoon@nvidia.com>
@timmoon10
timmoon10 force-pushed the nvfp4-ue5m3-prototype branch from ef16e25 to 26db2ee Compare August 21, 2026 02:59
timmoon10 and others added 4 commits August 21, 2026 03:45
Signed-off-by: Tim Moon <tmoon@nvidia.com>
Co-authored-by: Codex <noreply@openai.com>
Signed-off-by: Tim Moon <tmoon@nvidia.com>
Signed-off-by: Tim Moon <tmoon@nvidia.com>
Signed-off-by: Tim Moon <tmoon@nvidia.com>
@timmoon10
timmoon10 force-pushed the nvfp4-ue5m3-prototype branch from 4e9d0a4 to 0c2de5e Compare August 21, 2026 07:40
@timmoon10

This comment was marked as outdated.

Signed-off-by: Tim Moon <tmoon@nvidia.com>
Signed-off-by: Tim Moon <tmoon@nvidia.com>
@timmoon10

This comment was marked as outdated.

Signed-off-by: Tim Moon <tmoon@nvidia.com>
@timmoon10

This comment was marked as outdated.

Comment thread transformer_engine/pytorch/ops/fused/grouped_mlp.py
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Signed-off-by: Tim Moon <4406448+timmoon10@users.noreply.github.com>
@timmoon10

This comment was marked as outdated.

timmoon10 and others added 3 commits August 24, 2026 23:45
Signed-off-by: Tim Moon <tmoon@nvidia.com>
Signed-off-by: Tim Moon <tmoon@nvidia.com>
@timmoon10

This comment was marked as outdated.

Signed-off-by: Tim Moon <tmoon@nvidia.com>
Comment thread transformer_engine/common/cast/dispatch/quantize.cuh Outdated
Comment thread transformer_engine/common/cast/dispatch/quantize.cuh Outdated
Comment thread transformer_engine/common/cast/dispatch/quantize.cuh Outdated
Comment thread transformer_engine/common/cast/dispatch/quantize.cuh Outdated
Review suggestion from @ptrendx

Co-authored-by: Tim Moon <4406448+timmoon10@users.noreply.github.com>
Signed-off-by: Tim Moon <4406448+timmoon10@users.noreply.github.com>
@timmoon10

Copy link
Copy Markdown
Member Author

/te-ci L1

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

Labels

2.19 enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants