Skip to content

PTQ-Level Efficiency, QAT-Level Accuracy | 训练后量化的效率,量化感知训练的精度

support GPTQ_FORMAT for "gptqmodel:exllamav2" backend (#1434)

Xin He8a3d79371ad2
diff --git a/auto_round/inference/backend.py b/auto_round/inference/backend.py
index f1955b769..94b1f04da 100644
--- a/auto_round/inference/backend.py
+++ b/auto_round/inference/backend.py
@@ -417,7 +417,7 @@ BackendInfos["gptqmodel:marlin_zp"] = BackendInfo(
BackendInfos["gptqmodel:exllamav2"] = BackendInfo(
device=["cuda"],
sym=[True, False],
- packing_format=GPTQ_FORMAT_NO_ZP,
+ packing_format=GPTQ_FORMAT + GPTQ_FORMAT_NO_ZP,
bits=[4],
group_size=[-1, 32, 64, 128], ##16 seems has accuracy issue
compute_dtype=["float16", "bfloat16"],
diff --git a/auto_round/inference/convert_model.py b/auto_round/inference/convert_model.py
index 3f4acd1bf..e660ef762 100644
--- a/auto_round/inference/convert_model.py
+++ b/auto_round/inference/convert_model.py
@@ -469,6 +469,17 @@ def infer_target_device(device_map: Union[dict, int, str, None] = None) -> str:
return get_available_devices()[0]
+def process_gptq_qzero(model: nn.Module):
+ """Convert gptq v1 to v2 format to ensure compatible with gptqmodel:exllamav2 backend."""
+ from gptqmodel.nn_modules.qlinear.exllamav2 import ExllamaV2QuantLinear # pylint: disable=E0401
+
+ for n, m in model.named_modules():
+ if isinstance(m, ExllamaV2QuantLinear):
+ if hasattr(m, "qzeros") and m.qzeros is not None and m.qzeros.dtype == torch.int32 and m.bits == 4:
+ m.qzeros += 0b00010001000100010001000100010001
+ logger.warning_once("Converting gptq v1 to v2 format")
+
+
def post_init(model: torch.nn.Module, used_backends: list[str]) -> None:
"""Performs post-initialization for different quantization backends.
@@ -508,6 +519,7 @@ def post_init(model: torch.nn.Module, used_backends: list[str]) -> None:
from gptqmodel.utils.model import hf_gptqmodel_post_init as gptq_post_init # pylint: disable=E0401
from packaging import version
+ process_gptq_qzero(model) # Handle qzero layers if present
if version.parse(gptqmodel_version) <= version.parse("5.6.0"):
model = gptq_post_init(model, use_act_order=False)
else: