From 202f12ea6c0951e87a57c4769e8aa328897be52d Mon Sep 17 00:00:00 2001 From: Disty0 Date: Wed, 15 Apr 2026 23:12:46 +0300 Subject: [PATCH] SDNQ disable fp8 mm with pre-quants on unsupported gpus --- modules/sdnq/common.py | 13 ++++++++++++- modules/sdnq/loader.py | 6 +++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/modules/sdnq/common.py b/modules/sdnq/common.py index b91cef9c1..30c678da0 100644 --- a/modules/sdnq/common.py +++ b/modules/sdnq/common.py @@ -6,7 +6,7 @@ import torch from modules import shared, devices -sdnq_version = "0.1.7" +sdnq_version = "0.1.8" dtype_dict = { ### Integers @@ -335,6 +335,17 @@ def check_torch_compile(): # dynamo can be disabled after startup return use_torch_compile and not torch._dynamo.config.disable # pylint: disable=protected-access +if os.environ.get("SDNQ_ALLOW_FP8_MM", None) is None: + if devices.backend == "cuda": + is_fp8_mm_supported = bool(torch.cuda.get_device_capability(devices.device) >= (8,9)) + elif devices.backend == "rocm": + gfx_version = devices.get_hip_agent().gfx_version + is_fp8_mm_supported = bool(gfx_version >= 0x1200 or (gfx_version >= 0x940 and gfx_version < 0x1000)) + else: + is_fp8_mm_supported = False +else: + is_fp8_mm_supported = os.environ.get("SDNQ_ALLOW_FP8_MM", "0").lower() not in {"0", "false", "no"} + if os.environ.get("SDNQ_USE_TENSORWISE_FP8_MM", None) is None: # row-wise FP8 only exist on H100 hardware, sdnq will use software row-wise with tensorwise hardware with this setting use_tensorwise_fp8_matmul = bool(devices.backend != "cuda" or (devices.backend == "cuda" and torch.cuda.get_device_capability(devices.device) < (9,0))) diff --git a/modules/sdnq/loader.py b/modules/sdnq/loader.py index 1b3c5ae3e..66fb3f638 100644 --- a/modules/sdnq/loader.py +++ b/modules/sdnq/loader.py @@ -3,7 +3,7 @@ import json import torch from diffusers.models.modeling_utils import ModelMixin -from .common import dtype_dict, use_tensorwise_fp8_matmul, check_torch_compile, conv_types, linear_types +from .common import dtype_dict, use_tensorwise_fp8_matmul, is_fp8_mm_supported, check_torch_compile, conv_types, linear_types from .quantizer import SDNQConfig, sdnq_post_load_quant, prepare_weight_for_matmul, prepare_svd_for_matmul, get_quant_args_from_config from .forward import get_forward_func from .file_loader import load_files @@ -172,6 +172,10 @@ def apply_sdnq_options_to_module(model, dtype: torch.dtype | None = None, dequan if hasattr(module, "sdnq_dequantizer"): layer_class_name = module.original_class.__name__ current_use_quantized_matmul = use_quantized_matmul + + if not is_fp8_mm_supported and module.sdnq_dequantizer.quantized_matmul_dtype in {"fp8", "float8_e4m3fn"}: + current_use_quantized_matmul = False + if current_use_quantized_matmul: if layer_class_name in conv_types: output_channel_size, channel_size = module.sdnq_dequantizer.original_shape[:2]