Skip to content

[PyTorch][Common] Add MXFP8 and NVFP4 QDQ - #3633

Open
negvet wants to merge 17 commits into
NVIDIA:mainfrom
negvet:nvfp4_qdq
Open

negvet wants to merge 17 commits into
NVIDIA:mainfrom
negvet:nvfp4_qdq

Conversation

@negvet

@negvet negvet commented Oct 6, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Adds experimental MXFP8 and NVFP4 quantize–dequantize (QDQ) quantizers for emulating low-precision rounding using high-precision GEMMs, similar to radixark/miles#2864.

  • Fuses quantization and dequantization on SM80+, avoiding intermediate quantized data and scale buffers. Native Q+DQ fallback supports additional NVFP4 modes and mixed input/output dtypes.
  • Adds recipes for X[BF16] × W[NVFP4-QDQ] forward with BF16 backward, and X[MXFP8-QDQ] × W[NVFP4-QDQ] forward with MXFP8 backward.
  • Adds custom C++ split dispatch for GroupedLinear, with bulk or individual output allocation and Python fallback.
  • Introduces a shared QDQ quantizer base for custom formats. Includes numerical, distributed, and C++ tests and usage documentation.
def mxfp8_qdq_nvfp4_qdq_fwd_mxfp8_bwd_factory(role):
    if role is None or role.module_type not in ("linear", "grouped_linear"):
        return IdentityQuantizer()

    if role.tensor_type == "input":
        return HybridQuantizer(
            rowwise_quantizer=MXFP8QDQQuantizer(),
            columnwise_quantizer=mxfp8_factory(role),
            columnwise_source="original",
        )

    if role.tensor_type == "weight":
        return HybridQuantizer(
            rowwise_quantizer=NVFP4QDQQuantizer(),
            columnwise_quantizer=mxfp8_factory(role),
            columnwise_source="rowwise_dequantized",
        )

    if role.tensor_type == "grad_output":
        return mxfp8_factory(role)

    return IdentityQuantizer()


recipe = CustomRecipe(
    qfactory=mxfp8_qdq_nvfp4_qdq_fwd_mxfp8_bwd_factory,
)

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

Please list the changes introduced in this PR:

  • Change A
  • Change B

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

@negvet negvet changed the title [PyTorch][Common] Add NVFP4 weight QDQ, enabling X[BF16] x W[NVFP4] [PyTorch][Common] Add MXFP8 and NVFP4 QDQ for mixed-precision GEMM Oct 8, 2026
native.internal = True
q = NVFP4QDQQuantizer(native)
q.amax_reduction_group = dist.group.WORLD
q.with_amax_reduction = True

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.

can it support NVFP4 with per token second scale instead of global amax?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added support

* ``nvfp4_qdq_weight_fwd_bf16_bwd_factory`` models ``X[BF16] x W[NVFP4]``
forward and uses BF16 backward. Backward consumes the original inputs and
the decoded forward QDQ weights.
* ``mxfp8_nvfp4_qdq_fwd_mxfp8_bwd_factory`` models ``X[MXFP8] x W[NVFP4]``

@rybakov rybakov Oct 8, 2026 •

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.

X[MXFP8_QDQ] x W[NVFP4_QDQ] ?
the same comment is applied to all QDQ types used in the code and description

also in function name may be it is better to explicitly name it as
mxfp8_qdq_nvfp4_qdq_fwd_mxfp8_bwd_factory

I would suggest to add QDQ to all names of mxfp8 and nvfp4 when qdq is applied

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, fixed

@rybakov rybakov 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.

looks good, with comment about QDQ naming in the description and function names

Signed-off-by: Evgeny <etsykunov@nvidia.com>
Signed-off-by: Evgeny <etsykunov@nvidia.com>
Signed-off-by: Evgeny <etsykunov@nvidia.com>
@negvet
negvet marked this pull request as ready for review October 13, 2026 16:07
@negvet

negvet commented Oct 13, 2026

Copy link
Copy Markdown
Collaborator Author

/te-ci pytorch

@greptile-apps

greptile-apps Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; the previous grouped-gradient issue is fixed and no new actionable issue was found.

Summary

Adds experimental MXFP8 and NVFP4 QDQ quantizers that store decoded values for high-precision GEMMs.

  • Custom recipes can send MXFP8- or NVFP4-rounded values to high-precision GEMMs.
  • Quantizers keep requested compute precision in high-precision storage.
  • GroupedLinear quantizes expert splits through custom QDQ paths.
  • Distributed gathers preserve precision held by hybrid QDQ tensors.
  • Custom recipes skip the blanket FP8 hardware check.

Review was based on source inspection; GPU tests were not run.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Original input] --> B[QDQ quantizer]
  B --> C[Decoded high-precision storage]
  C --> D[Forward GEMM]
  C --> E[Promoted reconstruction dtype]
  E --> F[Columnwise quantizer]
  F --> G[Backward GEMM]
Loading

Reviews (6) · Last reviewed commit: "Preserve QDQ precision in split and all-..." · Reviewed by Greptile

Signed-off-by: Evgeny <etsykunov@nvidia.com>
@negvet

negvet commented Oct 14, 2026

Copy link
Copy Markdown
Collaborator Author

/te-ci pytorch

Signed-off-by: Evgeny <etsykunov@nvidia.com>
@negvet

negvet commented Oct 16, 2026

Copy link
Copy Markdown
Collaborator Author

/te-ci pytorch

@zhongbozhu zhongbozhu left a comment

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.

Is this PR supposed to work with grouped tensor enabled path or split_quantize only?

high-precision buffer serves both directions).
"""

supports_output_dtype = True

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems we are working around the fact that each quantizer subclass exposes a fake dtype, but not the base quantizer. Somewhere in the QDQ impl we need to programmatically change the fake dtype. Instead of creating the second dtype infrastructure, I think it would be nicer to move the fake dtype logic from the base quantizer to the subclasses.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, fixed. I removed supports_output_dtype and moved dtype resolution into Identity/Hybrid/QDQ.

Signed-off-by: Evgeny <etsykunov@nvidia.com>
Signed-off-by: Evgeny <etsykunov@nvidia.com>
Signed-off-by: Evgeny <etsykunov@nvidia.com>
Signed-off-by: Evgeny <etsykunov@nvidia.com>
@negvet

negvet commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator Author

Is this PR supposed to work with grouped tensor enabled path or split_quantize only?

This PR enables split_quantize_custom path, including QDQ quantizers, see cc3f42d.

The grouped tensor path currently does not support any CustomRecipe, which is too convervative given that e.g. CustomRecipe(base_mxfp8_factory) is the base mxfp8 recipe. But this issue needs to be addressed separately.

Signed-off-by: Evgeny <etsykunov@nvidia.com>
@negvet negvet changed the title [PyTorch][Common] Add MXFP8 and NVFP4 QDQ for mixed-precision GEMM [PyTorch][Common] Add MXFP8 and NVFP4 QDQ Nov 12, 2026
Signed-off-by: Evgeny <etsykunov@nvidia.com>
@negvet

negvet commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator Author

/te-ci pytorch

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants