Skip to content

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

fix alg_ext regression and support mxfp4 in it with slight improvement (#785)

Wenhua Chengca3f733e55fd
diff --git a/auto_round/alg_ext.cpython-310-x86_64-linux-gnu.so b/auto_round/alg_ext.cpython-310-x86_64-linux-gnu.so
index 8cbc74494..8074d84f2 100644
Binary files a/auto_round/alg_ext.cpython-310-x86_64-linux-gnu.so and b/auto_round/alg_ext.cpython-310-x86_64-linux-gnu.so differ
diff --git a/auto_round/autoround.py b/auto_round/autoround.py
index 32213e570..51a64d03f 100644
--- a/auto_round/autoround.py
+++ b/auto_round/autoround.py
@@ -520,9 +520,9 @@ class AutoRound(object):
"Enabling it can reduce tuning cost by 20%, but it might throw an exception."
)
- if self.act_bits <= 8 and self.enable_torch_compile:
- self.enable_torch_compile = False
- logger.warning("reset enable_torch_compile to `False` as activation quantization is enabled")
+ # if self.act_bits <= 8 and self.enable_torch_compile:
+ # self.enable_torch_compile = False
+ # logger.warning("reset enable_torch_compile to `False` as activation quantization is enabled")
if self.low_cpu_mem_usage and self.enable_torch_compile:
self.enable_torch_compile = False
@@ -2811,20 +2811,19 @@ class AutoRound(object):
to_dtype(input_others[key][i], tmp_dtype)
if (
- self.act_bits > 8
- and self.sym
+ self.sym
and self.enable_alg_ext
and self.super_group_size is None
- and self.data_type.startswith("int")
+ and ((self.data_type.startswith("int") and self.act_bits >= 8) or self.data_type.startswith("mx"))
):
try:
from auto_round.alg_ext import quantize_block_ext
AutoRound.quantize_block_ext = quantize_block_ext
- quantize_block = self.quantize_block_ext ##must use self.quantize_block_ext
- if self.bits > 2:
+ quantize_block = self.quantize_block_ext # must use self.quantize_block_ext
+ if self.bits > 2 and not self.data_type.startswith("mx"):
logger.warning(
- "algorithm extension has only undergone limited validation on INT2; use with caution."
+ "algorithm extension has only undergone limited validation on INT2 and mxfp4; use with caution."
)
else:
logger.info("using algorithm extension for quantization.")
diff --git a/auto_round/script/llm.py b/auto_round/script/llm.py
index 0aaadef83..c4d2fb306 100644
--- a/auto_round/script/llm.py
+++ b/auto_round/script/llm.py
@@ -634,12 +634,8 @@ def tune(args):
import time
eval_model_dtype = get_model_dtype(args.eval_model_dtype, "auto")
- tmp_act_bits = infer_bits_by_data_type(args.act_data_type)
- if tmp_act_bits is not None:
- act_bits = tmp_act_bits
- else:
- act_bits = args.act_bits
- if act_bits <= 8 or eval_gguf_model:
+
+ if autoround.act_bits <= 8 or eval_gguf_model:
if eval_gguf_model:
# for file in os.listdir(eval_folder):
# gguf_file = file
diff --git a/test/test_cpu/test_autoround.py b/test/test_cpu/test_autoround.py
index ccdf5b419..ce5a625b2 100644
--- a/test/test_cpu/test_autoround.py
+++ b/test/test_cpu/test_autoround.py
@@ -636,6 +636,11 @@ class TestAutoRound(unittest.TestCase):
):
raise ValueError("mixed bits is not correct")
+ def test_alg_ext(self):
+ model_name = "facebook/opt-125m"
+ ar = AutoRound(model_name, scheme="W2A16", iters=1, nsamples=1, enable_alg_ext=True)
+ ar.quantize()
+
def test_invalid_layer_config(self):
with self.assertRaises(ValueError):
layer_config = {"model.decoder.layers.2.self_attnx": {"bits": 2}}