Skip to content

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

Refine readme (#25)

WeiweiZhang14b0a0ba78055
diff --git a/auto_round/calib_dataset.py b/auto_round/calib_dataset.py
index 481b8b922..b1fd535f4 100644
--- a/auto_round/calib_dataset.py
+++ b/auto_round/calib_dataset.py
@@ -12,7 +12,7 @@ def register_dataset(name):
Args:
cls (class): The subclass of register.
- name: A string. Define the pruner type.
+ name: A string. Define the dataset type.
Returns:
cls: The class of register.
diff --git a/examples/language-modeling/README.md b/examples/language-modeling/README.md
index 742783761..9b34185ea 100644
--- a/examples/language-modeling/README.md
+++ b/examples/language-modeling/README.md
@@ -66,7 +66,28 @@ bash run_autoround_on_gaudi.sh
`--enable_minmax_tuning` is strongly recommended
-## 4. Known Issues
+## 4. Evaluation
+The example supports evaluation for various tasks in lm_eval. Moreover, it facilitates separate evaluation through the 'evaluation.py' script, which extends support to three additional tasks (ptb, c4, and wikitext2) beyond the capabilities of the official lm_eval. Additionally, evaluation results will be neatly organized into an Excel file for ease of demonstration.
+
+For large models, GPU memory may be insufficient. Enable multi-GPU evaluation by setting 'CUDA_VISIBLE_DEVICES'.
+
+Due to the large size of the model, the quantization and evaluation processes may be time-consuming. To provide flexibility in the process, two options are offered:
+
+- You can set up multi-GPU cards for the quantization example, which will only use the first card for quantization and then evaluate with all GPU cards.
+```bash
+CUDA_VISIBLE_DEVICES=1,2 python3 main.py --model_name facebook/opt-125m --amp --bits 4 --group_size -1 --deployment_device fake,cpu --output_dir /save_model_path/
+```
+
+- Enable 'disable_eval' for the quantization example, save the qdq model by setting 'deployment_device=fake', and then set up multi-GPU cards for the evaluation script.
+```bash
+CUDA_VISIBLE_DEVICES=0 python3 main.py --model_name facebook/opt-125m --amp --bits 4 --group_size -1 --disable_eval --deployment_device fake --output_dir /save_model_path/
+
+CUDA_VISIBLE_DEVICES=1,2 python3 eval/evaluation.py --model_name /save_model_path/ --eval_bs 8 --tasks mmlu,lambada_openai,ptb --excel_path /result_excel/save_path/
+```
+
+You can also utilize the official lm_eval [link](https://github.com/EleutherAI/lm-evaluation-harness/tree/main?tab=readme-ov-file#basic-usage).
+
+## 5. Known Issues
* Random issues in tuning Qwen models
* ChatGlm-V1 is not supported
@@ -84,3 +105,4 @@ If you find SignRound useful for your research, please cite our paper:
+
diff --git a/examples/language-modeling/eval/evaluation.py b/examples/language-modeling/eval/evaluation.py
index 23055dbf7..9d4824b6b 100644
--- a/examples/language-modeling/eval/evaluation.py
+++ b/examples/language-modeling/eval/evaluation.py
@@ -465,15 +465,27 @@ if __name__ == "__main__":
parser.add_argument(
"--eval_bs", default=1,
)
+ parser.add_argument(
+ "--tasks", default=['wikitext2', 'ptb-new', 'c4-new', 'lambada_openai', 'hellaswag', 'winogrande', 'piqa',
+ "mmlu", "wikitext", "truthfulqa_mc1", "truthfulqa_mc2", "openbookqa", "boolq", "rte",
+ "arc_easy", "arc_challenge"]
+ )
+ parser.add_argument(
+ "--excel_path", default=None,
+ help="The path to save eval results with excel format."
+ )
args = parser.parse_args()
s = time.time()
- test_tasks = ['wikitext2', 'ptb-new', 'c4-new', 'lambada_openai', 'hellaswag', 'winogrande', 'piqa',
- "mmlu", "wikitext", "truthfulqa_mc1", "truthfulqa_mc2", "openbookqa", "boolq", "rte",
- "arc_easy", "arc_challenge"]
+ test_tasks = args.tasks
+ if isinstance(test_tasks, str):
+ test_tasks = test_tasks.split(',')
model_name = args.model_name.rstrip('/')
- excel_name = model_name.split('/')[-1] + ".xlsx"
+ if args.excel_path is None:
+ excel_name = model_name.split('/')[-1] + ".xlsx"
+ else:
+ excel_name = args.excel_path
eval_model(model_path=args.model_name,
tasks=test_tasks,
eval_bs=args.eval_bs, limit=None, excel_file=excel_name)
@@ -482,3 +494,4 @@ if __name__ == "__main__":
+
diff --git a/examples/language-modeling/main.py b/examples/language-modeling/main.py
index d4733402a..db634efef 100644
--- a/examples/language-modeling/main.py
+++ b/examples/language-modeling/main.py
@@ -1,6 +1,5 @@
import argparse
import sys
-
sys.path.insert(0, '../..')
parser = argparse.ArgumentParser()
@@ -38,7 +37,7 @@ if __name__ == '__main__':
parser.add_argument("--device", default=0, type=str,
help="device gpu int number, or 'cpu' ")
-
+
parser.add_argument("--sym", action='store_true',
help=" sym quantization")
@@ -81,14 +80,14 @@ if __name__ == '__main__':
parser.add_argument("--enable_minmax_tuning", action='store_true',
help="whether enable weight minmax tuning")
-
+
parser.add_argument("--deployment_device", default='fake', type=str,
help="targeted inference acceleration platform,The options are 'fake', 'cpu' and 'gpu'."
"default to 'fake', indicating that it only performs fake quantization and won't be exported to any device.")
-
+
parser.add_argument("--scale_dtype", default='fp32',
help="which scale data type to use for quantization, 'fp16', 'fp32' or 'bf16'.")
-
+
parser.add_argument("--tasks",
default=['wikitext2', 'ptb-new', 'c4-new', 'lambada_openai', 'hellaswag', 'winogrande', 'piqa',
"mmlu", "wikitext", "truthfulqa_mc1", "truthfulqa_mc2", "openbookqa", "boolq", "rte",
@@ -101,10 +100,9 @@ if __name__ == '__main__':
parser.add_argument("--eval_legacy", action='store_true',
help="Whether to evaluate with a old lm_eval version(e.g. 0.3.0).")
- parser.add_argument("--disable_lmeval", action='store_true',
+ parser.add_argument("--disable_eval", action='store_true',
help="Whether to do lmeval evaluation.")
-
args = parser.parse_args()
set_seed(args.seed)
@@ -158,12 +156,7 @@ if __name__ == '__main__':
torch_device = torch.device(device_str)
is_glm = bool(re.search("chatglm", model_name.lower()))
- is_llava = bool(re.search("llava", model_name.lower()))
- if is_llava:
- from transformers import LlavaForConditionalGeneration
-
- model = LlavaForConditionalGeneration.from_pretrained(model_name, low_cpu_mem_usage=True, torch_dtype=torch_dtype)
- elif is_glm:
+ if is_glm:
model = AutoModel.from_pretrained(model_name, trust_remote_code=True)
else:
model = AutoModelForCausalLM.from_pretrained(
@@ -264,10 +257,11 @@ if __name__ == '__main__':
model.save_pretrained(output_dir)
tokenizer.save_pretrained(output_dir)
- if not args.disable_lmeval and "fake" in deployment_device: ##support autogptq real eval later
+ if not args.disable_eval and "fake" in deployment_device: ##support autogptq real eval later
excel_name = f"{output_dir}_result.xlsx"
output_dir += "/"
print(excel_name, flush=True)
eval_model(model_path=output_dir, tasks=tasks, dtype=dtype, limit=None,
eval_bs=args.eval_bs, use_accelerate=args.low_gpu_mem_usage,
device=torch_device, excel_file=excel_name)
+