Skip to content

fix(quantization): fix nvfp4 availability check - #2331

Open
Lee-YNU wants to merge 1 commit into
NVIDIA:mainfrom
Lee-YNU:fix_nvfp4_check
Open

fix(quantization): fix nvfp4 availability check#2331
Lee-YNU wants to merge 1 commit into
NVIDIA:mainfrom
Lee-YNU:fix_nvfp4_check

Conversation

@Lee-YNU

@Lee-YNU Lee-YNU commented Sep 4, 2026

Copy link
Copy Markdown

What does this PR do?

Type of change: Bug fix

As described in #2330, _nvfp4_availability_check does not account for attributes prefixed with an underscore when checking quantizer attributes, resulting in a failed check. Consequently, after applying compression to an NVFP4-quantized model, the corresponding GEMM implementation cannot be located during inference, and the warning "RealQuantLinear: No real-quant GEMM found" is raised.

Usage

import modelopt
import torch

import modelopt.torch.quantization as mtq

from torch import nn

K_DTYPE = torch.bfloat16
K_BATCH = 128
K_DIM = 512


class Model(nn.Module):
    def __init__(self, dim: int) -> None:
        super().__init__()

        self.fc = nn.Linear(dim, dim)

    def forward(self, x: torch.Tensor) -> torch.Tensor:
        out = self.fc(x)

        return out


def main():
    device = torch.device("cuda:0")

    model = Model(K_DIM).to(K_DTYPE)
    model.to(device)

    inp = torch.randn(K_BATCH, K_DIM, dtype=K_DTYPE, device=device)

    qmodel = mtq.quantize(model, mtq.NVFP4_DEFAULT_CFG, lambda quantized_model: quantized_model(inp))
    mtq.compress(qmodel)

    qout = qmodel(inp)


if __name__ == "__main__":
    main()

Testing

Before your PR is "Ready for review"

Make sure you read and follow Contributor guidelines and your commits are signed (git commit -s -S).

Make sure you read and follow the Security Best Practices (e.g. avoiding hardcoded trust_remote_code=True, torch.load(..., weights_only=False), pickle, etc.).

  • Is this change backward compatible?: ✅
  • If you copied code from any other sources or added a new PIP dependency, did you follow guidance in CONTRIBUTING.md: N/A
  • Did you write any new necessary tests?: N/A
  • Did you update Changelog?: N/A
  • Did you get Claude approval on this PR?: N/A

Additional Information

Related issue: #2330

Summary by CodeRabbit

  • Bug Fixes
    • Improved validation of quantization settings for NVFP4 operations.
    • Ensured configuration checks recognize both standard and internal attribute forms consistently.
    • Preserved validation behavior for unsupported or mismatched settings.

@Lee-YNU
Lee-YNU requested a review from a team as a code owner September 4, 2026 04:33
@copy-pr-bot

copy-pr-bot Bot commented Sep 4, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@coderabbitai

coderabbitai Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 9d8b4c79-6431-4c8a-8074-df35e33f3ca5

📥 Commits

Reviewing files that changed from the base of the PR and between c56959c and b570391.

📒 Files selected for processing (2)
  • modelopt/torch/quantization/backends/nvfp4_gemm.py
  • modelopt/torch/quantization/backends/utils.py

Included review availability: Your plan provides up to 12 included reviews per hour; 11 remain after this review.


📝 Walkthrough

Walkthrough

The change adds a shared attribute validation helper and replaces duplicated checks in NVFP4 availability validation for input and weight quantizers.

Changes

Quantizer Validation

Layer / File(s) Summary
Shared attribute-checking utility
modelopt/torch/quantization/backends/utils.py
Adds check_attributes to compare public and underscored attributes with an expected value.
NVFP4 availability validation
modelopt/torch/quantization/backends/nvfp4_gemm.py
Uses check_attributes for input and weight quantizer checks. The enable key remains excluded, and mismatches return False.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to b5703

NVFP4 availability checks now recognize underscored quantizer attributes after compression, allowing the compatible GEMM path to be selected without changing mismatch handling. The change is ready to merge.

🚥 Pre-merge checks | ✅ 6
✅ Passed checks (6 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: fixing the NVFP4 availability check in quantization.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Security Anti-Patterns ✅ Passed PASS. The commit changes only two Python files under modelopt; it adds no example changes and no pyproject.toml or requirements*.txt changes. The added code only imports check_attributes, call…
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

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.

1 participant