Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions modelopt/torch/quantization/backends/nvfp4_gemm.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import modelopt.torch.quantization as mtq
from modelopt.torch.quantization.backends.gemm_registry import gemm_registry
from modelopt.torch.quantization.backends.utils import fp4_compatible
from modelopt.torch.quantization.backends.utils import check_attributes, fp4_compatible
from modelopt.torch.quantization.qtensor import NVFP4QTensor, QTensorWrapper
from modelopt.torch.quantization.utils import reduce_amax

Expand Down Expand Up @@ -234,20 +234,14 @@ def _nvfp4_availability_check(module, input, args, kwargs):
for key, value in input_cfg.items():
if key == "enable":
continue
if (
not hasattr(module.input_quantizer, key)
or getattr(module.input_quantizer, key) != value
):
if not check_attributes(module.input_quantizer, key, value):
return False

# Check weight quantizer config
for key, value in weight_cfg.items():
if key == "enable":
continue
if (
not hasattr(module.weight_quantizer, key)
or getattr(module.weight_quantizer, key) != value
):
if not check_attributes(module.weight_quantizer, key, value):
return False

# When the input.shape[1] is not the multiple of 64, GEMM will sometimes output NaN.
Expand Down
12 changes: 12 additions & 0 deletions modelopt/torch/quantization/backends/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,15 @@ def fp4_compatible():
if not torch.cuda.is_available():
return False
return torch.cuda.get_device_capability(0) >= (10, 0)


def check_attributes(obj: object, key: str, value: object) -> bool:
"""Check the attributes of objects such as quantizers."""
_key = f"_{key}"

if hasattr(obj, key):
return getattr(obj, key) == value
elif hasattr(obj, _key):
return getattr(obj, _key) == value

return False