PTQ-Level Efficiency, QAT-Level Accuracy | 训练后量化的效率,量化感知训练的精度
add gptqmodel:awq backend support and keep autoawq WQLinear_GEMM for compatibility (#1545)
Weiwei8444896517b9
diff --git a/auto_round/export/export_to_autoround/export.py b/auto_round/export/export_to_autoround/export.pyindex c57bf452c..fa669c065 100644--- a/auto_round/export/export_to_autoround/export.py+++ b/auto_round/export/export_to_autoround/export.py@@ -343,8 +343,6 @@ def save_quantized_as_autoround(image_processor.save_pretrained(output_dir)if quantization_config.get("act_bits", 16) <= 8:dtype = torch.bfloat16- elif "awq" in quantization_config.get("packing_format", "auto_round:auto_gptq"):- dtype = torch.float16 ## awq kernel only supports float16 on cudaelse:dtype = Nonesave_model(model, output_dir, safe_serialization=safe_serialization, dtype=dtype)diff --git a/auto_round/export/export_to_awq/export.py b/auto_round/export/export_to_awq/export.pyindex 32d99fd8a..1903a2dfc 100644--- a/auto_round/export/export_to_awq/export.py+++ b/auto_round/export/export_to_awq/export.py@@ -221,7 +221,6 @@ def save_quantized_as_autoawq(if hasattr(compressed_model, "config"):compressed_model.config.quantization_config = quantization_configsafe_serialization = kwargs.get("safe_serialization", True)- dtype = torch.float16 ##force dtype to fp16- save_model(compressed_model, output_dir, safe_serialization=safe_serialization, dtype=dtype)+ save_model(compressed_model, output_dir, safe_serialization=safe_serialization, dtype=None)return compressed_modeldiff --git a/auto_round/inference/backend.py b/auto_round/inference/backend.pyindex 4cf49d2c2..fb347d34d 100644--- a/auto_round/inference/backend.py+++ b/auto_round/inference/backend.py@@ -11,12 +11,12 @@# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.# See the License for the specific language governing permissions and# limitations under the License.-import functoolsimport platformfrom dataclasses import dataclass, fieldfrom typing import TYPE_CHECKING, Any, Optional+import torchfrom transformers.utils.versions import require_versionimport auto_round_extension.cuda.gptqmodel_marlin@@ -425,19 +425,79 @@ BackendInfos["gptqmodel:exllamav2"] = BackendInfo(requirements=["gptqmodel>=2.0"],)+BackendInfos["gptqmodel:awq_exllamav2"] = BackendInfo(+ device=["cuda"],+ sym=[True, False],+ packing_format=AWQ_FORMAT,+ bits=[4],+ group_size=[-1, 32, 64, 128],+ priority=6,+ compute_dtype=["float16", "bfloat16"],+ data_type=["int"],+ act_bits=WOQ_DEFAULT_ACT_BITS,+ checkers=[exllamav2_feature_checker],+ alias=["gptqmodel:awq", "gptqmodel:autoawq", "gptqmodel_awq", "exllamav2"],+ requirements=["gptqmodel>=5.6.0"],+)++BackendInfos["gptqmodel:awq_marlin"] = BackendInfo(+ device=["cuda"],+ sym=[True],+ packing_format=AWQ_FORMAT,+ bits=[4, 8],+ group_size=[-1, 32, 64, 128],+ priority=5,+ compute_dtype=["float16"],+ data_type=["int"],+ act_bits=WOQ_DEFAULT_ACT_BITS,+ checkers=[gptqmodel_marlin_feature_checker],+ alias=["gptqmodel:autoawq_marlin", "gptqmodel_awq_marlin", "marlin"],+ requirements=["gptqmodel>=5.6.0"],+)++BackendInfos["gptqmodel:awq_gemm"] = BackendInfo(+ device=["cuda"],+ sym=[True, False],+ packing_format=AWQ_FORMAT,+ bits=[4],+ group_size=[-1, 16, 32, 64, 128],+ priority=3,+ compute_dtype=["float16"],+ data_type=["int"],+ act_bits=WOQ_DEFAULT_ACT_BITS,+ checkers=[feature_multiply_checker_16],+ alias=["gptqmodel:autoawq_gemm", "gptqmodel_awq_gemm"],+ requirements=["gptqmodel>=5.6.0"],+)++BackendInfos["gptqmodel:awq_torch"] = BackendInfo(+ device=["cuda", "cpu"],+ sym=[True, False],+ packing_format=AWQ_FORMAT,+ bits=[4],+ group_size=[-1, 16, 32, 64, 128],+ priority=2,+ compute_dtype=["float16"],+ data_type=["int"],+ act_bits=WOQ_DEFAULT_ACT_BITS,+ checkers=[feature_multiply_checker_16],+ alias=["gptqmodel:autoawq_torch", "gptqmodel_awq_torch", "torch"],+ requirements=["gptqmodel>=5.6.0"],+)++# autoawq backend - deprecated, kept for backward compatibilityBackendInfos["auto_awq:gemm"] = BackendInfo(device=["cuda"],sym=[True, False], # Actually it is GEMMpacking_format=AWQ_FORMAT,bits=[4],group_size=None,- priority=5,+ priority=4,compute_dtype=["float16"],data_type=["int"],act_bits=WOQ_DEFAULT_ACT_BITS,alias=["auto_awq:gemm", "awq", "awq:gemm", "auto_awq"],- # requirements=["autoawq", "transformers<4.57.0"],- requirements=["autoawq", "transformers"],+ requirements=["autoawq"],)BackendInfos["auto_round_kernel"] = BackendInfo(@@ -575,7 +635,6 @@ BackendInfos["ipex_awq_cpu"] = BackendInfo(requirements=["torch<2.9", "intel-extension-for-pytorch>=2.5"],)-BackendInfos["ipex_awq"] = BackendInfo(device=["xpu"],sym=[True, False],@@ -590,6 +649,7 @@ BackendInfos["ipex_awq"] = BackendInfo(alias=["ipex"],requirements=["intel-extension-for-pytorch>=2.5"],)+BackendInfos["hpu"] = BackendInfo(device=["hpu"],sym=[True, False],@@ -710,7 +770,6 @@ def dynamic_import_inference_linear(backend, config):If required modules are missing for a backend (e.g., ark, GPTQ, auto_awq)."""bits, group_size, sym = config["bits"], config["group_size"], config["sym"]-if "torch_fp8_static" in backend:return ar_qmodules.WeightFP8ActFP8StaticQuantLinearif "torch_mxfp8" in backend:@@ -758,20 +817,22 @@ def dynamic_import_inference_linear(backend, config):from auto_round_extension.hpu.qlinear_hpu import QuantLinearreturn QuantLinear- if "gptqmodel" in backend:++ # Handle gptqmodel GPTQ backends+ if "gptqmodel" in backend and "awq" not in backend:return get_gptqmodel_infer_linear(backend, bits, group_size, sym)if "gptq" in backend and "gptqmodel" not in backend:return get_autogptq_infer_linear(backend, bits, group_size, sym)if "awq" in backend:- try:+ if "gptqmodel" in backend:+ return get_gptqmodel_awq_infer_linear(backend)+ else:+ # Fallback to autoawq for backward compatibilityfrom awq.modules.linear import WQLinear_GEMM # pylint: disable=E0401- except ImportError:- raise ImportError(- "autoawq is required. Please install it by 'pip install autoawq' to support auto_awq format."- )- return WQLinear_GEMM++ return WQLinear_GEMMif backend == "auto_round:tritonv2":from auto_round_extension.triton.qlinear_tritonv2 import QuantLinear@@ -796,15 +857,47 @@ def dynamic_import_inference_linear(backend, config):raise ValueError(f"unsupported backend {backend}, please set it to `auto` and retry")-def get_gptqmodel_infer_linear(backend, bits=4, group_size=128, sym=False):- import torch+def get_gptqmodel_awq_infer_linear(backend):+ """Returns the appropriate gptqmodel AWQ QuantLinear class for inference."""++ dtype = torch.get_default_dtype()+ if dtype != torch.float32:+ torch.set_default_dtype(torch.float32)+ try:+ import gptqmodel # pylint: disable=E0401+ finally:+ torch.set_default_dtype(dtype)++ # Select AWQ kernel based on the BackendInfos key+ if "marlin" in backend:+ from gptqmodel.nn_modules.qlinear.marlin_awq import AwqMarlinQuantLinear # pylint: disable=E0401++ return AwqMarlinQuantLinear+ elif "exllamav2" in backend:+ from gptqmodel.nn_modules.qlinear.exllamav2_awq import AwqExllamaV2QuantLinear # pylint: disable=E0401+ return AwqExllamaV2QuantLinear+ elif "gemm" in backend:+ from gptqmodel.nn_modules.qlinear.gemm_awq import AwqGEMMQuantLinear # pylint: disable=E0401++ return AwqGEMMQuantLinear+ elif "torch" in backend:+ from gptqmodel.nn_modules.qlinear.torch_awq import AwqTorchQuantLinear # pylint: disable=E0401++ return AwqTorchQuantLinear+ else:+ raise ValueError(f"Unsupported {backend}")+++def get_gptqmodel_infer_linear(backend, bits=4, group_size=128, sym=False):dtype = torch.get_default_dtype()if dtype != torch.float32:torch.set_default_dtype(torch.float32)- import gptqmodel # pylint: disable=E0401- torch.set_default_dtype(dtype)+ try:+ import gptqmodel # pylint: disable=E0401+ finally:+ torch.set_default_dtype(dtype)if "marlin" in backend:return auto_round_extension.cuda.gptqmodel_marlin.get_marlin_layer()diff --git a/auto_round/inference/convert_model.py b/auto_round/inference/convert_model.pyindex ba746e1c7..901b71dd3 100644--- a/auto_round/inference/convert_model.py+++ b/auto_round/inference/convert_model.py@@ -396,7 +396,7 @@ def _create_quant_layer(layer, layer_backend, config, in_features, out_features)QuantLinear = dynamic_import_inference_linear(layer_backend, config)bias = layer.bias is not None- # Special handling for AWQ layers+ # Special handling for auto-round-lib AWQ layersfrom auto_round_extension.ark.qlinear import QuantLinearAWQif "auto_round_kernel" in layer_backend:@@ -413,7 +413,21 @@ def _create_quant_layer(layer, layer_backend, config, in_features, out_features)return QuantLinear.from_linear(layer, config["bits"], config["group_size"], init_only=True, has_zero_points=not config["sym"])+ elif "awq" in layer_backend and "gptqmodel" in layer_backend:+ # gptqmodel AWQ QuantLinear — This matches the approach used+ # by transformers' replace_with_awq_linear().+ return QuantLinear(+ bits=config["bits"],+ group_size=config["group_size"],+ desc_act=False,+ sym=config["sym"],+ in_features=in_features,+ out_features=out_features,+ bias=bias,+ register_buffers=True,+ )elif "awq" in layer_backend:+ # autoawq WQLinear_GEMMreturn QuantLinear.from_linear(layer, config["bits"], config["group_size"], init_only=True)elif "gptqmodel" in layer_backend:return QuantLinear(@@ -587,7 +601,7 @@ def disable_moe_conversion_mapping(model):if model_type is not None:conversions = get_checkpoint_conversion_mapping(model_type)if conversions is not None:- # 只保留 WeightRenaming,跳过 WeightConverter(MoE merge 操作)+ # Keep only WeightRenaming, skip WeightConverter (MoE merge operations)filtered = [c for c in conversions if isinstance(c, WeightRenaming)]register_checkpoint_conversion_mapping(model_type, mapping=filtered, overwrite=True)diff --git a/test/envs.py b/test/envs.pyindex d9685e604..f998fd4a3 100644--- a/test/envs.py+++ b/test/envs.py@@ -53,7 +53,7 @@ def is_flash_attn_available():def is_gptqmodel_available():try:- require_version("gptqmodel>=2.0")+ require_version("gptqmodel>=5.7.0")return Trueexcept ImportError:return Falsediff --git a/test/test_cuda/backends/test_exllamav2_backend.py b/test/test_cuda/backends/test_exllamav2_backend.pyindex 618917df8..06a3cbec2 100644--- a/test/test_cuda/backends/test_exllamav2_backend.py+++ b/test/test_cuda/backends/test_exllamav2_backend.py@@ -4,12 +4,10 @@ import pytestimport torchfrom transformers import AutoModelForCausalLM, AutoRoundConfig, AutoTokenizer-from auto_round import (- AutoRound,-)+from auto_round import AutoRoundfrom ...envs import require_autogptq, require_gptqmodel, require_package_version_ut-from ...helpers import evaluate_accuracy, get_model_path, model_infer+from ...helpers import evaluate_accuracy, generate_prompt, get_model_path, model_inferclass TestAutoRoundexllamaBackend:@@ -116,3 +114,58 @@ class TestAutoRoundexllamaBackend:evaluate_accuracy(model, tokenizer, threshold=0.15, batch_size=64)torch.cuda.empty_cache()shutil.rmtree(self.save_dir, ignore_errors=True)++ @require_gptqmodel+ def test_gptqmodel_awq_exllamav2_4bits_asym(self, dataloader):+ """Test AWQ quantization with gptqmodel:awq_exllamav2 backend (bfloat16 inference)."""+ model_path = get_model_path("facebook/opt-125m")+ bits, group_size, sym = 4, 128, False+ autoround = AutoRound(+ model_path, bits=bits, group_size=group_size, sym=sym, iters=1, seqlen=2, dataset=dataloader+ )+ quantized_model_path = self.save_dir+ autoround.quantize_and_save(output_dir=quantized_model_path, format="auto_round:auto_awq")+ quantization_config = AutoRoundConfig(backend="gptqmodel:awq_exllamav2")+ # test awq bfloat16 inference+ model = AutoModelForCausalLM.from_pretrained(+ self.save_dir, torch_dtype=torch.bfloat16, device_map="auto", quantization_config=quantization_config+ )+ assert model.dtype == torch.bfloat16, f"Expected model dtype bfloat16, got {model.dtype}"++ tokenizer = AutoTokenizer.from_pretrained(self.save_dir)+ # Inference generation check+ output = model_infer(model, tokenizer)+ assert isinstance(output, str) and len(output.strip()) > 0, "Model failed to generate non-empty output"+ generated = generate_prompt(model, tokenizer, "There is a girl who likes adventure,")+ assert len(generated) > len("There is a girl who likes adventure,"), "Generation did not produce new tokens"+ # Accuracy check+ evaluate_accuracy(model, tokenizer, threshold=0.35, batch_size=16)+ torch.cuda.empty_cache()+ shutil.rmtree("./saved", ignore_errors=True)++ @require_gptqmodel+ def test_gptqmodel_awq_exllamav2_4bits_sym(self, dataloader):+ """Test AWQ quantization with gptqmodel:awq_exllamav2 backend (bfloat16 inference, symmetric)."""+ model_path = get_model_path("facebook/opt-125m")+ bits, group_size, sym = 4, 128, True+ autoround = AutoRound(+ model_path, bits=bits, group_size=group_size, sym=sym, iters=1, seqlen=2, dataset=dataloader+ )+ quantized_model_path = self.save_dir+ autoround.quantize_and_save(output_dir=quantized_model_path, format="auto_round:auto_awq")++ quantization_config = AutoRoundConfig(backend="gptqmodel:awq_exllamav2")+ model = AutoModelForCausalLM.from_pretrained( # test awq bfloat16 inference+ self.save_dir, torch_dtype=torch.bfloat16, device_map="auto", quantization_config=quantization_config+ )++ tokenizer = AutoTokenizer.from_pretrained(self.save_dir)+ # Inference generation check+ output = model_infer(model, tokenizer)+ assert isinstance(output, str) and len(output.strip()) > 0, "Model failed to generate non-empty output"+ generated = generate_prompt(model, tokenizer, "There is a girl who likes adventure,")+ assert len(generated) > len("There is a girl who likes adventure,"), "Generation did not produce new tokens"+ # Accuracy check+ evaluate_accuracy(model, tokenizer, threshold=0.2, batch_size=16)+ torch.cuda.empty_cache()+ shutil.rmtree("./saved", ignore_errors=True)diff --git a/test/test_cuda/backends/test_marlin_backend.py b/test/test_cuda/backends/test_marlin_backend.pyindex 19dc277e0..8cb24ee44 100644--- a/test/test_cuda/backends/test_marlin_backend.py+++ b/test/test_cuda/backends/test_marlin_backend.py@@ -6,7 +6,8 @@ from transformers import AutoModelForCausalLM, AutoRoundConfig, AutoTokenizerfrom auto_round import AutoRound-from ...helpers import evaluate_accuracy, get_model_path, model_infer+from ...envs import require_gptqmodel+from ...helpers import evaluate_accuracy, generate_prompt, get_model_path, model_inferclass TestAutoRoundMarlinBackend:@@ -164,3 +165,69 @@ class TestAutoRoundMarlinBackend:# assert result['results']['lambada_openai']['acc,none'] > 0.27# torch.cuda.empty_cache()# shutil.rmtree("./saved", ignore_errors=True)++ @require_gptqmodel+ def test_gptqmodel_awq_marlin_4bits_sym(self, dataloader):+ """Test AWQ quantization with gptqmodel:awq_marlin backend (sym-only, float16)."""+ model_path = get_model_path("facebook/opt-125m")+ bits, group_size, sym = 4, 128, True+ autoround = AutoRound(+ model_path, bits=bits, group_size=group_size, sym=sym, iters=1, seqlen=2, dataset=dataloader+ )+ quantized_model_path = self.save_dir+ autoround.quantize_and_save(output_dir=quantized_model_path, format="auto_round:auto_awq")++ quantization_config = AutoRoundConfig(backend="gptqmodel:awq_marlin")+ model = AutoModelForCausalLM.from_pretrained(+ self.save_dir, torch_dtype="auto", device_map="auto", quantization_config=quantization_config+ )++ tokenizer = AutoTokenizer.from_pretrained(self.save_dir)+ # Inference generation check+ output = model_infer(model, tokenizer)+ assert isinstance(output, str) and len(output.strip()) > 0, "Model failed to generate non-empty output"+ generated = generate_prompt(model, tokenizer, "There is a girl who likes adventure,")+ assert len(generated) > len("There is a girl who likes adventure,"), "Generation did not produce new tokens"+ # Accuracy check+ evaluate_accuracy(model, tokenizer, threshold=0.2, batch_size=16)+ torch.cuda.empty_cache()+ shutil.rmtree("./saved", ignore_errors=True)++ @require_gptqmodel+ def test_gptqmodel_awq_marlin_group_size(self, dataloader):+ """Test AWQ marlin backend with different group sizes."""+ for group_size in [32, 64, 128]:+ print(f"!!!!!!!!!!!!!!!!!{group_size}!!!!!!!!!!!!!!!!!")+ model_path = get_model_path("facebook/opt-125m")+ bits, sym = 4, True+ autoround = AutoRound(+ model_path,+ bits=bits,+ group_size=group_size,+ sym=sym,+ iters=1,+ seqlen=2,+ dataset=dataloader,+ )+ quantized_model_path = self.save_dir+ autoround.quantize_and_save(output_dir=quantized_model_path, format="auto_round:auto_awq")++ quantization_config = AutoRoundConfig(backend="gptqmodel:awq_marlin")+ model = AutoModelForCausalLM.from_pretrained(+ self.save_dir, torch_dtype="auto", device_map="auto", quantization_config=quantization_config+ )++ tokenizer = AutoTokenizer.from_pretrained(self.save_dir)+ # Inference generation check+ output = model_infer(model, tokenizer)+ assert (+ isinstance(output, str) and len(output.strip()) > 0+ ), f"Model failed to generate non-empty output for group_size={group_size}"+ generated = generate_prompt(model, tokenizer, "There is a girl who likes adventure,")+ assert len(generated) > len(+ "There is a girl who likes adventure,"+ ), f"Generation did not produce new tokens for group_size={group_size}"+ # Accuracy check+ evaluate_accuracy(model, tokenizer, threshold=0.2, batch_size=16)+ torch.cuda.empty_cache()+ shutil.rmtree("./saved", ignore_errors=True)diff --git a/test/test_cuda/backends/test_torch_backend.py b/test/test_cuda/backends/test_torch_backend.pyindex d175f80a7..649cbcd2c 100644--- a/test/test_cuda/backends/test_torch_backend.py+++ b/test/test_cuda/backends/test_torch_backend.py@@ -7,7 +7,7 @@ from transformers import AutoModelForCausalLM, AutoRoundConfig, AutoTokenizerfrom auto_round import AutoRoundfrom ...envs import require_autogptq, require_gptqmodel-from ...helpers import evaluate_accuracy, get_model_path, model_infer+from ...helpers import evaluate_accuracy, generate_prompt, get_model_path, model_inferclass TestAutoRoundTorchBackend:@@ -93,3 +93,30 @@ class TestAutoRoundTorchBackend:evaluate_accuracy(model, tokenizer, threshold=0.28, batch_size=16)torch.cuda.empty_cache()shutil.rmtree(self.save_dir, ignore_errors=True)++ @require_gptqmodel+ def test_gptqmodel_awq_torch_4bits_group_size_16(self, dataloader):+ """Test AWQ quantization with gptqmodel:awq_torch backend (group_size=16, float16)."""+ model_path = get_model_path("facebook/opt-125m")+ bits, group_size, sym = 4, 16, True+ autoround = AutoRound(+ model_path, bits=bits, group_size=group_size, sym=sym, iters=1, seqlen=2, dataset=dataloader+ )+ quantized_model_path = self.save_dir+ autoround.quantize_and_save(output_dir=quantized_model_path, format="auto_round:auto_awq")++ quantization_config = AutoRoundConfig(backend="gptqmodel:awq_torch")+ model = AutoModelForCausalLM.from_pretrained(+ self.save_dir, torch_dtype=torch.float16, device_map="auto", quantization_config=quantization_config+ )++ tokenizer = AutoTokenizer.from_pretrained(self.save_dir)+ # Inference generation check+ output = model_infer(model, tokenizer)+ assert isinstance(output, str) and len(output.strip()) > 0, "Model failed to generate non-empty output"+ generated = generate_prompt(model, tokenizer, "There is a girl who likes adventure,")+ assert len(generated) > len("There is a girl who likes adventure,"), "Generation did not produce new tokens"+ # Accuracy check+ evaluate_accuracy(model, tokenizer, threshold=0.2, batch_size=16)+ torch.cuda.empty_cache()+ shutil.rmtree("./saved", ignore_errors=True)diff --git a/test/test_cuda/core/test_main_func.py b/test/test_cuda/core/test_main_func.pyindex f39458451..0e2d11b68 100644--- a/test/test_cuda/core/test_main_func.py+++ b/test/test_cuda/core/test_main_func.py@@ -10,7 +10,7 @@ from transformers.utils.versions import require_versionfrom auto_round import AutoRound, AutoRoundAdam-from ...envs import require_awq, require_gptqmodel, require_optimum, require_package_version_ut+from ...envs import require_awq, require_gptqmodel, require_optimumfrom ...helpers import evaluate_accuracy, get_model_path@@ -31,7 +31,6 @@ class TestMainFunc:shutil.rmtree("runs", ignore_errors=True)@require_gptqmodel- @require_optimumdef test_backend(self):model_name = get_model_path("facebook/opt-125m")model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.float16, device_map="auto")@@ -49,9 +48,7 @@ class TestMainFunc:evaluate_accuracy(self.save_dir, threshold=0.35, batch_size="auto")shutil.rmtree("./saved", ignore_errors=True)- @require_optimum- @require_awq- @require_package_version_ut("transformers", "<4.57.0")+ @require_gptqmodeldef test_backend_awq(self):model_name = get_model_path("facebook/opt-125m")model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.float16, device_map="auto")@@ -85,8 +82,7 @@ class TestMainFunc:shutil.rmtree("./saved", ignore_errors=True)@pytest.mark.skipif(not torch.cuda.is_available(), reason="CUDA not available")- @require_awq- @require_package_version_ut("transformers", "<4.57.0")+ @require_gptqmodeldef test_ignore_layers_awq(self):model_name = get_model_path("facebook/opt-125m")model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.float16, device_map="auto")diff --git a/test/test_cuda/export/test_auto_round_format.py b/test/test_cuda/export/test_auto_round_format.pyindex e5600a98b..155aca37c 100644--- a/test/test_cuda/export/test_auto_round_format.py+++ b/test/test_cuda/export/test_auto_round_format.py@@ -11,9 +11,9 @@ from auto_round import AutoRoundfrom ...envs import (require_autogptq,require_awq,+ require_gptqmodel,require_greater_than_050,require_ipex,- require_package_version_ut,)from ...helpers import evaluate_accuracy, get_model_path, get_tiny_model, model_infer@@ -35,7 +35,6 @@ class TestAutoRound:shutil.rmtree("runs", ignore_errors=True)@require_greater_than_050- @require_package_version_ut("transformers", "<4.57.0")def test_autoround_asym(self, tiny_opt_model_path, dataloader):for bits in [2, 3, 4, 8]:# model_name = get_model_path("facebook/opt-125m")@@ -89,8 +88,7 @@ class TestAutoRound:evaluate_accuracy(model, tokenizer, threshold=0.32, batch_size=16)shutil.rmtree(self.save_dir, ignore_errors=True)- @require_awq- @require_package_version_ut("transformers", "<4.57.0")+ @require_gptqmodeldef test_awq_backend(self):model_name = get_model_path("facebook/opt-125m")bits, group_size, sym = 4, 128, True@@ -188,7 +186,6 @@ class TestAutoRound:@require_awq@require_ipex- @require_package_version_ut("transformers", "<4.57.0")def test_autoround_awq_sym_format(self, tiny_opt_model_path, dataloader):bits, group_size, sym = 4, 128, Trueautoround = AutoRound(diff --git a/test/test_cuda/export/test_export.py b/test/test_cuda/export/test_export.pyindex f5e2e1af0..b3810e152 100644--- a/test/test_cuda/export/test_export.py+++ b/test/test_cuda/export/test_export.py@@ -9,7 +9,7 @@ from transformers import AutoConfig, AutoModelForCausalLM, AutoRoundConfig, Autofrom auto_round import AutoRound-from ...envs import require_awq, require_optimum, require_package_version_ut+from ...envs import require_gptqmodel, require_optimumfrom ...helpers import get_model_path, get_tiny_model, transformers_version@@ -167,8 +167,7 @@ class TestAutoRound:# "she is a great artist, she is a great artist, she is a great artist, she is")shutil.rmtree("./saved", ignore_errors=True)- @require_awq- @require_package_version_ut("transformers", "<4.57.0")+ @require_gptqmodeldef test_autoawq_format(self, dataloader):model_path = get_model_path("facebook/opt-125m")bits, group_size, sym = 4, 128, False@@ -247,9 +246,7 @@ class TestAutoRound:assert "!!!" not in generated_textshutil.rmtree("./saved", ignore_errors=True)- @require_optimum- @require_awq- @require_package_version_ut("transformers", "<4.57.0")+ @require_gptqmodeldef test_autoawq_format_fp_qsave_layers(self, dataloader):model_path = get_model_path("facebook/opt-125m")layer_config = {@@ -271,9 +268,7 @@ class TestAutoRound:autoround.quantize_and_save(output_dir=quantized_model_path, format="auto_awq")from transformers import AutoRoundConfig- model = AutoModelForCausalLM.from_pretrained(- quantized_model_path, device_map="auto", quantization_config=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,"inputs = tokenizer(text, return_tensors="pt").to(model.device)diff --git a/test/test_cuda/integrations/test_sglang.py b/test/test_cuda/integrations/test_sglang.pyindex 9e7bcfa6e..a063ebfe1 100644--- a/test/test_cuda/integrations/test_sglang.py+++ b/test/test_cuda/integrations/test_sglang.py@@ -97,3 +97,25 @@ class TestAutoRound:assert "!!!" not in generated_textshutil.rmtree(self.save_dir, ignore_errors=True)++ def test_awq_format_sglang(self, dataloader):+ autoround = AutoRound(+ self.model_name,+ scheme="W4A16",+ iters=2,+ seqlen=2,+ dataset=dataloader,+ )++ autoround.quantize_and_save(+ output_dir=self.save_dir,+ inplace=True,+ format="auto_round:auto_awq",+ )++ generated_text = self._run_sglang_inference(self.save_dir)+ print(generated_text)++ assert "!!!" not in generated_text++ shutil.rmtree(self.save_dir, ignore_errors=True)diff --git a/test/test_cuda/integrations/test_vllm.py b/test/test_cuda/integrations/test_vllm.pyindex 99ed5fc05..eafdda617 100644--- a/test/test_cuda/integrations/test_vllm.py+++ b/test/test_cuda/integrations/test_vllm.py@@ -8,11 +8,16 @@ Run `pytest test/test_cuda/test_vllm.py`."""import os+import shutilimport pytestfrom vllm import LLM, SamplingParamsfrom vllm.platforms import current_platform+from auto_round import AutoRound++from ...helpers import get_model_path+os.environ["VLLM_WORKER_MULTIPROC_METHOD"] = "spawn"MODELS = [@@ -27,7 +32,7 @@ MODELS = [)@pytest.mark.parametrize("model", MODELS)def test_auto_round(model):- # Sample prompts.+ # offline inference loading testprompts = ["The capital of France is","The future of AI is",@@ -53,3 +58,36 @@ def test_auto_round(model):generated_text = output.outputs[0].textif "France" in prompt:assert "Paris" in generated_text+++ not current_platform.is_cuda(),+ reason="only supports CUDA backend.",+)+def test_auto_round_awq_format_vllm():+ # quantization and inference test+ model_path = get_model_path("facebook/opt-125m")+ save_dir = "./saved"++ autoround = AutoRound(+ model=model_path,+ scheme="W4A16",+ iters=1,+ seqlen=2,+ )+ autoround.quantize_and_save(output_dir=save_dir, format="auto_round:auto_awq")++ sampling_params = SamplingParams(temperature=0.8, top_p=0.95, max_tokens=32)+ llm = LLM(+ model=save_dir,+ # quantization="awq",+ trust_remote_code=True,+ tensor_parallel_size=1,+ # allow_deprecated_quantization=True,+ # dtype="auto",+ )+ outputs = llm.generate(["The capital of France is"], sampling_params)+ generated_text = outputs[0].outputs[0].text+ print(generated_text)+ assert len(generated_text.strip()) > 0, "vLLM AWQ inference produced empty output"+ shutil.rmtree(save_dir, ignore_errors=True)diff --git a/test/test_cuda/models/test_support_vlms.py b/test/test_cuda/models/test_support_vlms.pyindex 7b4e89177..b4ffd2284 100644--- a/test/test_cuda/models/test_support_vlms.py+++ b/test/test_cuda/models/test_support_vlms.py@@ -130,7 +130,6 @@ class TestSupportVLMS:shutil.rmtree(quantized_model_path, ignore_errors=True)@require_vlm_env- @require_package_version_ut("transformers", "<4.57.0")def test_phi3_vision_awq(self):model_path = "/models/Phi-3.5-vision-instruct/"## test tunediff --git a/test/test_cuda/quantization/test_mix_bits.py b/test/test_cuda/quantization/test_mix_bits.pyindex 5f7175173..68180c5b8 100644--- a/test/test_cuda/quantization/test_mix_bits.py+++ b/test/test_cuda/quantization/test_mix_bits.py@@ -10,9 +10,7 @@ from transformers import AutoModelForCausalLM, AutoRoundConfig, AutoTokenizerfrom auto_round import AutoRoundfrom ...envs import (- require_awq,require_gptqmodel,- require_package_version_ut,)from ...helpers import get_model_path@@ -129,8 +127,7 @@ class TestAutoRound:print(tokenizer.decode(model.generate(**inputs, max_new_tokens=50)[0]))shutil.rmtree(quantized_model_path, ignore_errors=True)- @require_awq- @require_package_version_ut("transformers", "<4.57.0")+ @require_gptqmodeldef test_fallback_regex_for_awq_format(self, tiny_opt_model_path, dataloader):layer_config = {"lm_head": {"bits": 16},