PTQ-Level Efficiency, QAT-Level Accuracy | 训练后量化的效率,量化感知训练的精度
revert awq dtype change for vllm inference limitation (#1613)
Weiwei72d5c4dd895b
diff --git a/auto_round/export/export_to_autoround/export.py b/auto_round/export/export_to_autoround/export.pyindex ba5f4d897..372638e99 100644--- a/auto_round/export/export_to_autoround/export.py+++ b/auto_round/export/export_to_autoround/export.py@@ -349,6 +349,8 @@ def save_quantized_as_autoround(image_processor.save_pretrained(processor_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 vllm kernel only supports float16 on cudaelse:dtype = Nonesave_model(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 1903a2dfc..1fedf3c60 100644--- a/auto_round/export/export_to_awq/export.py+++ b/auto_round/export/export_to_awq/export.py@@ -221,6 +221,9 @@ def save_quantized_as_autoawq(if hasattr(compressed_model, "config"):compressed_model.config.quantization_config = quantization_configsafe_serialization = kwargs.get("safe_serialization", True)- save_model(compressed_model, output_dir, safe_serialization=safe_serialization, dtype=None)+ # Force torch_dtype in the saved config to fp16 for vLLM CUDA kernel compatibility;+ # this does not change in-memory model weights.+ dtype = torch.float16+ save_model(compressed_model, output_dir, safe_serialization=safe_serialization, dtype=dtype)return compressed_modeldiff --git a/auto_round/export/utils.py b/auto_round/export/utils.pyindex 55f0b0a22..fa01e1da4 100644--- a/auto_round/export/utils.py+++ b/auto_round/export/utils.py@@ -208,7 +208,11 @@ def save_model(if dtype is not None and dtype != model.dtype and os.path.exists(os.path.join(save_dir, "config.json")):with open(config_path, "r") as file:data = json.load(file)- data["torch_dtype"] = str(dtype).split(".")[-1]+ dtype_str = str(dtype).split(".")[-1]+ data["torch_dtype"] = dtype_str+ # Also update 'dtype' field if present (transformers >= 4.57) for consistency+ if "dtype" in data:+ data["dtype"] = dtype_strwith open(config_path, "w") as file:json.dump(data, file, indent=2)diff --git a/auto_round/inference/backend.py b/auto_round/inference/backend.pyindex a858f5597..00e2950b3 100644--- a/auto_round/inference/backend.py+++ b/auto_round/inference/backend.py@@ -431,7 +431,7 @@ BackendInfos["gptqmodel:awq_exllamav2"] = BackendInfo(packing_format=AWQ_FORMAT,bits=[4],group_size=[-1, 32, 64, 128],- priority=6,+ priority=5,compute_dtype=["float16", "bfloat16"],data_type=["int"],act_bits=WOQ_DEFAULT_ACT_BITS,@@ -446,7 +446,7 @@ BackendInfos["gptqmodel:awq_marlin"] = BackendInfo(packing_format=AWQ_FORMAT,bits=[4, 8],group_size=[-1, 32, 64, 128],- priority=5,+ priority=6,compute_dtype=["float16"],data_type=["int"],act_bits=WOQ_DEFAULT_ACT_BITS,diff --git a/test/test_cuda/integrations/test_vllm.py b/test/test_cuda/integrations/test_vllm.pyindex 895e3c9c3..3cef719e5 100644--- a/test/test_cuda/integrations/test_vllm.py+++ b/test/test_cuda/integrations/test_vllm.py@@ -166,17 +166,10 @@ def test_auto_round_awq_format_vllm():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",- )+ llm = LLM(model=save_dir, trust_remote_code=True, tensor_parallel_size=1, gpu_memory_utilization=0.7)outputs = llm.generate(["The capital of France is"], sampling_params)generated_text = outputs[0].outputs[0].textprint(generated_text)assert len(generated_text.strip()) > 0, "vLLM AWQ inference produced empty output"+ shutil.rmtree("./saved", ignore_errors=True)