mirror of
https://github.com/vladmandic/automatic
synced 2026-09-19 09:14:35 +02:00
SDNQ add dequantize model
This commit is contained in:
@@ -103,6 +103,23 @@ def re_quantize_matmul_packed_int_symmetric(weight: torch.ByteTensor, scale: tor
|
||||
return re_quantize_matmul_symmetric(unpack_int_symetric(weight, shape, weights_dtype, dtype=scale.dtype), scale, result_shape, svd_up=svd_up, svd_down=svd_down)
|
||||
|
||||
|
||||
def dequantize_sdnq_model(model):
|
||||
if hasattr(model, "sdnq_dequantizer"):
|
||||
model.weight = torch.nn.Parameter(model.sdnq_dequantizer(model.weight, model.scale, model.zero_point, model.svd_up, model.svd_down))
|
||||
del model.sdnq_dequantizer, model.scale, model.zero_point, model.svd_up, model.svd_down
|
||||
return model
|
||||
has_children = list(model.children())
|
||||
if not has_children:
|
||||
return model
|
||||
for module in model.children():
|
||||
if hasattr(module, "sdnq_dequantizer"):
|
||||
module.weight = torch.nn.Parameter(module.sdnq_dequantizer(module.weight, module.scale, module.zero_point, module.svd_up, module.svd_down))
|
||||
del module.sdnq_dequantizer, module.scale, module.zero_point, module.svd_up, module.svd_down
|
||||
else:
|
||||
module = dequantize_sdnq_model(module)
|
||||
return model
|
||||
|
||||
|
||||
class AsymmetricWeightsDequantizer(torch.nn.Module):
|
||||
def __init__(
|
||||
self,
|
||||
|
||||
@@ -13,7 +13,7 @@ from diffusers.utils import get_module_from_name
|
||||
from modules import devices, shared
|
||||
|
||||
from .common import dtype_dict, use_tensorwise_fp8_matmul, allowed_types, conv_types, conv_transpose_types, use_contiguous_mm
|
||||
from .dequantizer import dequantizer_dict
|
||||
from .dequantizer import dequantizer_dict, dequantize_sdnq_model
|
||||
from .forward import get_forward_func
|
||||
|
||||
|
||||
@@ -713,6 +713,16 @@ class SDNQQuantizer(DiffusersQuantizer, HfQuantizer):
|
||||
"""
|
||||
return dtype
|
||||
|
||||
def _dequantize(self, model):
|
||||
model = dequantize_sdnq_model(model)
|
||||
if hasattr(model, "quantization_method"):
|
||||
del model.quantization_method
|
||||
if hasattr(model, "quantization_config"):
|
||||
del model.quantization_config
|
||||
if hasattr(model, "config") and hasattr(model.config, "quantization_config"):
|
||||
del model.config.quantization_config
|
||||
return model
|
||||
|
||||
def is_serializable(self, *args, **kwargs) -> bool: # pylint: disable=unused-argument, invalid-overridden-method
|
||||
return True
|
||||
|
||||
|
||||
Reference in New Issue
Block a user