mirror of
https://github.com/vladmandic/automatic
synced 2026-08-26 15:16:01 +02:00
SDNQ fix torch.compile always being active
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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"):
|
||||
|
||||
@@ -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}")
|
||||
|
||||
Reference in New Issue
Block a user