Skip to content

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

switch to transformers API in cpu ut (#580)

Wenhua Cheng6ceaa8af9f38
diff --git a/test/test_act_quantization.py b/test/test_act_quantization.py
index 57fde6396..63544aca5 100644
--- a/test/test_act_quantization.py
+++ b/test/test_act_quantization.py
@@ -5,7 +5,6 @@ import unittest
sys.path.insert(0, "..")
import torch
-import transformers
from transformers import AutoModelForCausalLM, AutoTokenizer
from auto_round import AutoRound
diff --git a/test/test_autoround.py b/test/test_autoround.py
index 0fb7feed1..d8d2efed5 100644
--- a/test/test_autoround.py
+++ b/test/test_autoround.py
@@ -7,8 +7,7 @@ from auto_round.eval.evaluation import simple_evaluate_user_model
sys.path.insert(0, "..")
import torch
-import transformers
-from transformers import AutoModelForCausalLM, AutoTokenizer
+from transformers import AutoModelForCausalLM, AutoTokenizer, AutoRoundConfig
from auto_round import AutoRound
from _test_helpers import model_infer
@@ -358,7 +357,6 @@ class TestAutoRound(unittest.TestCase):
)
quantized_model_path = self.save_folder
autoround.quantize_and_save(output_dir=quantized_model_path, format="auto_round")
- from auto_round import AutoRoundConfig
model = AutoModelForCausalLM.from_pretrained(
self.save_folder,
torch_dtype=torch.float16,
@@ -391,7 +389,6 @@ class TestAutoRound(unittest.TestCase):
quantized_model_path = self.save_folder
autoround.save_quantized(output_dir=quantized_model_path, format="auto_round", inplace=True)
- from auto_round import AutoRoundConfig
quantization_config = AutoRoundConfig(
backend="ipex"
)
@@ -408,7 +405,6 @@ class TestAutoRound(unittest.TestCase):
import requests
from PIL import Image
from transformers import Qwen2VLForConditionalGeneration, AutoProcessor
- from auto_round import AutoRoundConfig
from auto_round_extension.ipex.qlinear_ipex_awq import QuantLinear
model_name = "Qwen/Qwen2-VL-2B-Instruct-AWQ"
quantization_config = AutoRoundConfig()
@@ -480,7 +476,6 @@ class TestAutoRound(unittest.TestCase):
quantized_model_path = self.save_folder
autoround.save_quantized(output_dir=quantized_model_path, format="auto_awq", inplace=True)
- from auto_round import AutoRoundConfig
quantization_config = AutoRoundConfig()
model = AutoModelForCausalLM.from_pretrained(quantized_model_path,
@@ -515,7 +510,6 @@ class TestAutoRound(unittest.TestCase):
quantized_model_path = self.save_folder
autoround.save_quantized(output_dir=quantized_model_path, format="auto_gptq", inplace=True)
- from auto_round import AutoRoundConfig
quantization_config = AutoRoundConfig()
model = AutoModelForCausalLM.from_pretrained(quantized_model_path,
@@ -550,7 +544,6 @@ class TestAutoRound(unittest.TestCase):
quantized_model_path = self.save_folder
autoround.save_quantized(output_dir=quantized_model_path, format="auto_round", inplace=True)
- from auto_round import AutoRoundConfig
quantization_config = AutoRoundConfig()
model = AutoModelForCausalLM.from_pretrained(quantized_model_path,
diff --git a/test/test_block_names.py b/test/test_block_names.py
index e1e70742e..fce253cee 100644
--- a/test/test_block_names.py
+++ b/test/test_block_names.py
@@ -163,7 +163,7 @@ class TestQuantizationBlocks(unittest.TestCase):
quantized_model_path = "./saved"
autoround.save_quantized(quantized_model_path, inplace=False, safe_serialization=False, format="auto_round")
- from auto_round import AutoRoundConfig
+
model = AutoModelForCausalLM.from_pretrained(quantized_model_path, device_map="auto")
tokenizer = AutoTokenizer.from_pretrained(quantized_model_path)
text = "There is a girl who likes adventure,"
diff --git a/test/test_conv1d.py b/test/test_conv1d.py
index 4f45fcbdb..17503cfd2 100644
--- a/test/test_conv1d.py
+++ b/test/test_conv1d.py
@@ -34,7 +34,6 @@ class TestQuantizationConv1d(unittest.TestCase):
def test_quant(self):
self.model = AutoModelForCausalLM.from_pretrained(self.model_name, torch_dtype="auto", trust_remote_code=True)
bits, group_size, sym = 4, 128, True
- from auto_round import AutoRoundConfig
autoround = AutoRound(
self.model,
self.tokenizer,
diff --git a/test/test_export.py b/test/test_export.py
index 55cecd37b..75c75c024 100644
--- a/test/test_export.py
+++ b/test/test_export.py
@@ -4,7 +4,7 @@ import unittest
sys.path.insert(0, "..")
import torch
-from transformers import AutoModelForCausalLM, AutoTokenizer
+from transformers import AutoModelForCausalLM, AutoTokenizer, AutoRoundConfig
from auto_round import AutoRound
@@ -75,7 +75,6 @@ class TestAutoRound(unittest.TestCase):
device = "auto" ##cpu, hpu, cuda
- from auto_round import AutoRoundConfig
quantization_config = AutoRoundConfig(
backend=device
)
@@ -104,7 +103,6 @@ class TestAutoRound(unittest.TestCase):
autoround.save_quantized(output_dir=quantized_model_path, inplace=False, format="auto_round:awq")
- from auto_round import AutoRoundConfig
quantization_config = AutoRoundConfig(
backend="cpu"
)
diff --git a/test/test_generation.py b/test/test_generation.py
index e2a140970..d76f66970 100644
--- a/test/test_generation.py
+++ b/test/test_generation.py
@@ -5,8 +5,7 @@ import unittest
sys.path.insert(0, "..")
import torch
-import transformers
-from transformers import AutoModelForCausalLM, AutoTokenizer
+from transformers import AutoModelForCausalLM, AutoTokenizer, AutoRoundConfig
from auto_round import AutoRound
@@ -52,7 +51,6 @@ class TestAutoRoundFormatGeneration(unittest.TestCase):
autoround.quantize_and_save(output_dir=quantized_model_path, format="auto_round", inplace=False)
- from auto_round import AutoRoundConfig
quantization_config = AutoRoundConfig(
backend="ipex"
)
diff --git a/test/test_load_awq_gptq.py b/test/test_load_awq_gptq.py
index 6db06c03a..9266c8ee9 100644
--- a/test/test_load_awq_gptq.py
+++ b/test/test_load_awq_gptq.py
@@ -6,7 +6,7 @@ sys.path.insert(0, "..")
from transformers import AutoModelForCausalLM, AutoTokenizer
-from auto_round import AutoRoundConfig
+from transformers import AutoRoundConfig
class TestAutoRound(unittest.TestCase):
diff --git a/test/test_mllm.py b/test/test_mllm.py
index f92cdf0d7..2e247796d 100644
--- a/test/test_mllm.py
+++ b/test/test_mllm.py
@@ -131,8 +131,6 @@ class TestAutoRoundMLLM(unittest.TestCase):
autoround.quantize()
quantized_model_path = "./saved"
autoround.save_quantized(quantized_model_path, format="auto_round", inplace=False)
-
- from auto_round import AutoRoundConfig
import requests
from PIL import Image