Skip to content

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

Fix group_size issue (#1638)

Wang, Mengni7b0ff4159496
diff --git a/auto_round/__main__.py b/auto_round/__main__.py
index 057641bdf..9da465810 100644
--- a/auto_round/__main__.py
+++ b/auto_round/__main__.py
@@ -299,7 +299,7 @@ class BasicArgumentParser(argparse.ArgumentParser):
scheme.add_argument(
"--group_size",
default=None,
- type=lambda s: int(s) if s.isdigit() else tuple([int(x.strip()) for x in s.split(",")]),
+ type=lambda s: int(s) if s.lstrip("-").isdigit() else tuple([int(x.strip()) for x in s.split(",")]),
help="Group size for weight quantization.",
)
scheme.add_argument("--asym", action="store_true", help="Use asymmetric quantization instead of symmetric.")
diff --git a/test/test_cpu/quantization/test_block_fp.py b/test/test_cpu/quantization/test_block_fp.py
index 19625911e..c703b6232 100644
--- a/test/test_cpu/quantization/test_block_fp.py
+++ b/test/test_cpu/quantization/test_block_fp.py
@@ -1,4 +1,5 @@
import shutil
+import subprocess
from math import ceil
import pytest
@@ -91,3 +92,46 @@ class TestAutoRoundBlockFP:
for j in range(N):
scale_ref[i, j] = data[i * 128 : (i + 1) * 128, j * 128 : (j + 1) * 128].abs().max() / max_val
assert (scale == scale_ref).all()
+
+ def test_group_size_handler(self, tiny_qwen_model_path):
+ scheme = {
+ "data_type": "int",
+ "bits": 4,
+ "group_size": -1,
+ "act_data_type": "int",
+ "act_bits": 4,
+ "act_group_size": -1,
+ }
+ autoround = AutoRound(
+ tiny_qwen_model_path,
+ scheme=scheme,
+ iters=2,
+ seqlen=2,
+ )
+
+ cmd = [
+ "python3",
+ "-m",
+ "auto_round",
+ "--model_name",
+ tiny_qwen_model_path,
+ "--bits",
+ "4",
+ "--group_size",
+ "-1",
+ "--act_bits",
+ "4",
+ "--act_group_size",
+ "-1",
+ "--format",
+ "fake",
+ "--iters",
+ "0",
+ ]
+ subprocess.run(
+ cmd,
+ check=True,
+ text=True,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE,
+ )