Skip to content

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

fix awq cuda CI (#1912)

Weiwei34790de772f7
diff --git a/test/test_cuda/algorithms/test_awq.py b/test/test_cuda/algorithms/test_awq.py
index 5222a98da..11f28b783 100644
--- a/test/test_cuda/algorithms/test_awq.py
+++ b/test/test_cuda/algorithms/test_awq.py
@@ -31,7 +31,7 @@ from transformers import AutoConfig, AutoModelForCausalLM, AutoTokenizer
from auto_round import AutoRound
-from ...helpers import evaluate_accuracy, generate_prompt, get_model_path, opt_name_or_path, save_tiny_model
+from ...helpers import eval_generated_prompt, evaluate_accuracy, generate_prompt, get_model_path, opt_name_or_path
# ---------------------------------------------------------------------------
# Section 1: Normal LLM (OPT-125m) – W4A16 quantize, inference, export args
@@ -64,9 +64,8 @@ class TestAWQLLM:
for name, cfg in layer_config.items():
assert cfg["bits"] == 4, f"Layer {name} expected bits=4, got {cfg['bits']}"
- # CUDA inference
tokenizer = AutoTokenizer.from_pretrained(tiny_opt_model_path)
- output = generate_prompt(model, tokenizer, device="cuda")
+ output = generate_prompt(model, tokenizer)
assert len(output) > 0 and "!!!" not in output, f"Unexpected generation output: {output}"
def test_awq_w4a16_export_auto_round_args(self, tiny_opt_model_path):
@@ -92,22 +91,18 @@ class TestAWQLLM:
assert qconfig["sym"] == sym
assert "auto-round" in qconfig["quant_method"]
- def test_awq_w4a16_load_and_generate(self, tiny_opt_model_path):
+ def test_awq_w4a16_load_and_generate(self):
"""Quantize, save, reload, and generate on CUDA to verify round-trip."""
+ model_name = get_model_path("facebook/opt-125m")
ar = AutoRound(
- tiny_opt_model_path,
+ model_name,
scheme="W4A16",
algorithm="awq",
nsamples=2,
seqlen=32,
- batch_size=2,
)
- _, save_path = ar.quantize_and_save(output_dir=self.save_dir, format="auto_round")
-
- loaded_model = AutoModelForCausalLM.from_pretrained(save_path, device_map="auto")
- tokenizer = AutoTokenizer.from_pretrained(save_path)
- output = generate_prompt(loaded_model, tokenizer, device="cuda")
- assert len(output) > 0 and "!!!" not in output, f"Unexpected generation output: {output}"
+ _, quantized_model_path = ar.quantize_and_save(output_dir=self.save_dir, format="auto_round")
+ eval_generated_prompt(quantized_model_path)
# ---------------------------------------------------------------------------
@@ -253,5 +248,4 @@ class TestAWQEval:
threshold=0.3,
batch_size="auto:8",
limit=50,
- device="cuda",
)