From 8a1743712a1956e3b6e20d890ee6945faade3668 Mon Sep 17 00:00:00 2001 From: Disty0 Date: Wed, 15 Apr 2026 23:28:20 +0300 Subject: [PATCH] SDNQ disable FP8 MM on dynamic quant with unsupported GPUs --- modules/sdnq/loader.py | 2 +- modules/sdnq/quantizer.py | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/modules/sdnq/loader.py b/modules/sdnq/loader.py index 66fb3f638..8ad8e1530 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, is_fp8_mm_supported, check_torch_compile, conv_types, linear_types +from modules import dtype_dict, is_fp8_mm_supported, use_tensorwise_fp8_matmul, 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 diff --git a/modules/sdnq/quantizer.py b/modules/sdnq/quantizer.py index 4911f4c5b..69bb2149d 100644 --- a/modules/sdnq/quantizer.py +++ b/modules/sdnq/quantizer.py @@ -15,7 +15,7 @@ from diffusers.utils import get_module_from_name from accelerate import init_empty_weights from modules import devices, shared -from .common import sdnq_version, dtype_dict, common_skip_keys, module_skip_keys_dict, accepted_weight_dtypes, accepted_matmul_dtypes, weights_dtype_order, allowed_types, linear_types, embedding_types, conv_types, conv_transpose_types, compile_func, use_tensorwise_fp8_matmul, use_contiguous_mm, check_torch_compile +from .common import sdnq_version, dtype_dict, common_skip_keys, module_skip_keys_dict, accepted_weight_dtypes, accepted_matmul_dtypes, weights_dtype_order, allowed_types, linear_types, embedding_types, conv_types, conv_transpose_types, compile_func, is_fp8_mm_supported, use_tensorwise_fp8_matmul, use_contiguous_mm, check_torch_compile from .dequantizer import SDNQDequantizer, dequantize_sdnq_model from .packed_int import pack_int from .packed_float import pack_float @@ -437,10 +437,16 @@ def sdnq_quantize_layer_weight_dynamic(weight, layer_class_name=None, weights_dt quantization_loss = None svd_is_transposed = False for i in range(weights_dtype_order.index(weights_dtype), len(weights_dtype_order)): + current_weights_dtype = weights_dtype_order[i] + if quantized_matmul_dtype is None and not is_fp8_mm_supported and not dtype_dict[current_weights_dtype]["is_integer"] and dtype_dict[current_weights_dtype]["num_bits"] < 16: + current_use_quantized_matmul = False + else: + current_use_quantized_matmul = use_quantized_matmul + quantized_weight, scale, zero_point, _, _, sdnq_dequantizer = sdnq_quantize_layer_weight( svd_weight, layer_class_name=layer_class_name, - weights_dtype=weights_dtype_order[i], + weights_dtype=current_weights_dtype, quantized_matmul_dtype=quantized_matmul_dtype, torch_dtype=torch_dtype, group_size=group_size, @@ -448,7 +454,7 @@ def sdnq_quantize_layer_weight_dynamic(weight, layer_class_name=None, weights_dt svd_steps=svd_steps, use_svd=False, using_pre_calculated_svd=use_svd, - use_quantized_matmul=use_quantized_matmul, + use_quantized_matmul=current_use_quantized_matmul, use_stochastic_rounding=use_stochastic_rounding, dequantize_fp32=dequantize_fp32, param_name=param_name,