From d4e2cbb826c95d9dbb61d0f3cbc0c9a130b27640 Mon Sep 17 00:00:00 2001 From: Disty0 Date: Mon, 8 Dec 2025 18:15:08 +0300 Subject: [PATCH] SDNQ fix torch.compile always being active --- modules/sdnq/common.py | 7 +++---- modules/sdnq/loader.py | 4 ++-- modules/sdnq/quantizer.py | 4 ++-- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/modules/sdnq/common.py b/modules/sdnq/common.py index 8aa482618..a0bc7ad5e 100644 --- a/modules/sdnq/common.py +++ b/modules/sdnq/common.py @@ -53,11 +53,10 @@ accepted_weight_dtypes = set(dtype_dict.keys()) accepted_matmul_dtypes = {"int8", "fp8", "fp16", "float8_e4m3fnuz", "float16"} is_rdna2 = bool(devices.backend == "rocm" and int(getattr(torch.cuda.get_device_properties(devices.device), "gcnArchName", "gfx0000")[3:]) < 1100) -startup_use_torch_compile = shared.opts.sdnq_dequantize_compile # this setting requires a full restart of the webui to apply +use_torch_compile = shared.opts.sdnq_dequantize_compile # this setting requires a full restart of the webui to apply -@property -def use_torch_compile(): # dynamo can be disabled after startup - return startup_use_torch_compile and not torch._dynamo.config.disable # pylint: disable=protected-access +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_USE_TENSORWISE_FP8_MM", None) is None: diff --git a/modules/sdnq/loader.py b/modules/sdnq/loader.py index 205a99072..e816796ce 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, use_torch_compile +from .common import dtype_dict, use_tensorwise_fp8_matmul, check_torch_compile 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 @@ -212,7 +212,7 @@ def apply_sdnq_options_to_module(model, dtype: torch.dtype = None, dequantize_fp def apply_sdnq_options_to_model(model, dtype: torch.dtype = None, dequantize_fp32: bool = None, use_quantized_matmul: bool = None): - if use_quantized_matmul and not use_torch_compile: + if use_quantized_matmul and not check_torch_compile(): raise RuntimeError("SDNQ Quantized MatMul requires a working Triton install.") model = apply_sdnq_options_to_module(model, dtype=dtype, dequantize_fp32=dequantize_fp32, use_quantized_matmul=use_quantized_matmul) if hasattr(model, "quantization_config"): diff --git a/modules/sdnq/quantizer.py b/modules/sdnq/quantizer.py index bad764271..d12608b24 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, allowed_types, linear_types, conv_types, conv_transpose_types, compile_func, use_tensorwise_fp8_matmul, use_contiguous_mm, use_torch_compile +from .common import sdnq_version, dtype_dict, common_skip_keys, module_skip_keys_dict, accepted_weight_dtypes, accepted_matmul_dtypes, allowed_types, linear_types, conv_types, conv_transpose_types, compile_func, use_tensorwise_fp8_matmul, use_contiguous_mm, check_torch_compile from .dequantizer import SDNQDequantizer, dequantize_sdnq_model from .packed_int import pack_int_symetric, pack_int_asymetric from .forward import get_forward_func @@ -946,7 +946,7 @@ class SDNQConfig(QuantizationConfigMixin): r""" Safety checker that arguments are correct """ - if self.use_quantized_matmul and not use_torch_compile: + if self.use_quantized_matmul and not check_torch_compile(): raise RuntimeError("SDNQ Quantized MatMul requires a working Triton install.") if self.weights_dtype not in accepted_weight_dtypes: raise ValueError(f"SDNQ only support weight dtypes in {accepted_weight_dtypes} but found {self.weights_dtype}")