Skip to content

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

add shell and acc data for several models, fixed some issues

wenhuach214ae7d455870c
diff --git a/docs/Mistral-7B-v0.1-acc.md b/docs/Mistral-7B-v0.1-acc.md
new file mode 100644
index 000000000..c142f0896
--- /dev/null
+++ b/docs/Mistral-7B-v0.1-acc.md
@@ -0,0 +1,23 @@
+Install [lm-eval-harness](https://github.com/EleutherAI/lm-evaluation-harness.git) from source, we used the git id f3b7917091afba325af3980a35d8a6dcba03dc3f
+
+```bash
+lm_eval --model hf --model_args pretrained="Intel/Mixtral-8x7B-Instruct-v0.1-int4-inc",autogptq=True,gptq_use_triton=True --device cuda:0 --tasks lambada_openai,hellaswag,piqa,winogrande,truthfulqa_mc1,openbookqa,boolq,rte,arc_easy,arc_challenge,mmlu --batch_size 32
+```
+
+
+
+| Metric | FP16 | INT4 |
+| -------------- | ------ | ------ |
+| Avg. | 0.6306 | 0.6308 |
+| mmlu | 0.5961 | 0.5880 |
+| lambada_openai | 0.7561 | 0.7551 |
+| hellaswag | 0.6128 | 0.6079 |
+| winogrande | 0.7443 | 0.7451 |
+| piqa | 0.8079 | 0.8014 |
+| truthfulqa_mc1 | 0.2803 | 0.2889 |
+| openbookqa | 0.3280 | 0.3300 |
+| boolq | 0.8373 | 0.8278 |
+| rte | 0.6643 | 0.6968 |
+| arc_easy | 0.8085 | 0.8060 |
+| arc_challenge | 0.5009 | 0.4915 |
+
diff --git a/docs/Mixtral-8x7B-Instruct-v0.1-acc.md b/docs/Mixtral-8x7B-Instruct-v0.1-acc.md
new file mode 100644
index 000000000..82a9e39dc
--- /dev/null
+++ b/docs/Mixtral-8x7B-Instruct-v0.1-acc.md
@@ -0,0 +1,22 @@
+Install [lm-eval-harness](https://github.com/EleutherAI/lm-evaluation-harness.git) from source, and the git id f3b7917091afba325af3980a35d8a6dcba03dc3f is used
+
+Download the model from hf(coming soon) or follow examples/language-modeling/scripts/Mixtral-8x7B-Instruct-v0.1.sh to generate the model
+
+```bash
+lm_eval --model hf --model_args pretrained="Intel/Mixtral-8x7B-Instruct-v0.1-int4-inc",autogptq=True,gptq_use_triton=True --device cuda:0 --tasks lambada_openai,hellaswag,piqa,winogrande,truthfulqa_mc1,openbookqa,boolq,rte,arc_easy,arc_challenge,mmlu --batch_size 32
+```
+
+| Metric | FP16 | INT4 |
+| -------------- | ------ | ------ |
+| Avg. | 0.7000 | 0.6977 |
+| mmlu | 0.6885 | 0.6824 |
+| lambada_openai | 0.7718 | 0.7790 |
+| hellaswag | 0.6767 | 0.6745 |
+| winogrande | 0.7687 | 0.7719 |
+| piqa | 0.8351 | 0.8335 |
+| truthfulqa_mc1 | 0.4969 | 0.4884 |
+| openbookqa | 0.3680 | 0.3720 |
+| boolq | 0.8850 | 0.8783 |
+| rte | 0.7184 | 0.7004 |
+| arc_easy | 0.8699 | 0.8712 |
+| arc_challenge | 0.6220 | 0.6229 |
\ No newline at end of file
diff --git a/docs/Mixtral-8x7B-v0.1-acc.md b/docs/Mixtral-8x7B-v0.1-acc.md
new file mode 100644
index 000000000..5caf717e4
--- /dev/null
+++ b/docs/Mixtral-8x7B-v0.1-acc.md
@@ -0,0 +1,24 @@
+### Evaluate the model
+Install [lm-eval-harness](https://github.com/EleutherAI/lm-evaluation-harness.git) from source, we used the git id f3b7917091afba325af3980a35d8a6dcba03dc3f
+
+Download the model from hf(coming soon) or follow examples/language-modeling/scripts/Mixtral-8x7B-v0.1.sh to generate the model
+
+~~~bash
+lm_eval --model hf --model_args pretrained="Intel/Mixtral-8x7B-v0.1-int4-inc",autogptq=True,gptq_use_triton=True --device cuda:0 --tasks lambada_openai,hellaswag,piqa,winogrande,truthfulqa_mc1,openbookqa,boolq,rte,arc_easy,arc_challenge,mmlu --batch_size 32
+~~~
+
+| Metric | FP16 | INT4 | 2e-3 |
+| -------------- | ------ | ------ | ------ |
+| Avg. | 0.6698 | 0.6633 | |
+| mmlu | 0.6802 | 0.6693 | 0.6713 |
+| lambada_openai | 0.7827 | 0.7825 | 0.7819 |
+| hellaswag | 0.6490 | 0.6459 | 0.6447 |
+| winogrande | 0.7648 | 0.7514 | 0.7569 |
+| piqa | 0.8248 | 0.8210 | 0.8210 |
+| truthfulqa_mc1 | 0.3427 | 0.3219 | 0.3121 |
+| openbookqa | 0.3540 | 0.3560 | 0.3380 |
+| boolq | 0.8523 | 0.8474 | 0.8465 |
+| rte | 0.7076 | 0.6931 | 0.7112 |
+| arc_easy | 0.8430 | 0.8430 | 0.8333 |
+| arc_challenge | 0.5666 | 0.5648 | 0.5469 |
+
diff --git a/docs/neural-chat-7b-v3-1-acc.md b/docs/neural-chat-7b-v3-1-acc.md
new file mode 100644
index 000000000..a55017d2d
--- /dev/null
+++ b/docs/neural-chat-7b-v3-1-acc.md
@@ -0,0 +1,20 @@
+Install [lm-eval-harness](https://github.com/EleutherAI/lm-evaluation-harness.git) from source, we used the git id f3b7917091afba325af3980a35d8a6dcba03dc3f
+
+~~~bash
+lm_eval --model hf --model_args pretrained="Intel/neural-chat-v3-1-int4-inc",autogptq=True,gptq_use_triton=True --device cuda:0 --tasks lambada_openai,hellaswag,piqa,winogrande,truthfulqa_mc1,openbookqa,boolq,rte,arc_easy,arc_challenge,mmlu --batch_size 128
+~~~
+
+| Metric | FP16 | INT4 |
+| -------------- | ------ | ------ |
+| Avg. | 0.6769 | 0.6721 |
+| mmlu | 0.5919 | 0.5862 |
+| lambada_openai | 0.7394 | 0.7337 |
+| hellaswag | 0.6323 | 0.6272 |
+| winogrande | 0.7687 | 0.7577 |
+| piqa | 0.8161 | 0.8150 |
+| truthfulqa_mc1 | 0.4431 | 0.4394 |
+| openbookqa | 0.3760 | 0.3700 |
+| boolq | 0.8783 | 0.8743 |
+| rte | 0.7690 | 0.7726 |
+| arc_easy | 0.8413 | 0.8384 |
+| arc_challenge | 0.5896 | 0.5785 |
\ No newline at end of file
diff --git a/docs/neural-chat-7b-v3-3-acc.md b/docs/neural-chat-7b-v3-3-acc.md
new file mode 100644
index 000000000..abc220436
--- /dev/null
+++ b/docs/neural-chat-7b-v3-3-acc.md
@@ -0,0 +1,20 @@
+Install [lm-eval-harness](https://github.com/EleutherAI/lm-evaluation-harness.git) from source, we used the git id f3b7917091afba325af3980a35d8a6dcba03dc3f
+
+~~~bash
+lm_eval --model hf --model_args pretrained="Intel/neural-chat-v3-3-int4-inc",autogptq=True,gptq_use_triton=True --device cuda:0 --tasks lambada_openai,hellaswag,piqa,winogrande,truthfulqa_mc1,openbookqa,boolq,rte,arc_easy,arc_challenge,mmlu --batch_size 128
+~~~
+
+| Metric | FP16 | INT4 |
+| -------------- | ------ | ------ |
+| Avg. | 0.6778 | 0.6748 |
+| mmlu | 0.5993 | 0.5926 |
+| lambada_openai | 0.7303 | 0.7370 |
+| hellaswag | 0.6639 | 0.6559 |
+| winogrande | 0.7632 | 0.7735 |
+| piqa | 0.8101 | 0.8074 |
+| truthfulqa_mc1 | 0.4737 | 0.4737 |
+| openbookqa | 0.3880 | 0.3680 |
+| boolq | 0.8694 | 0.8694 |
+| rte | 0.7581 | 0.7509 |
+| arc_easy | 0.8266 | 0.8249 |
+| arc_challenge | 0.5734 | 0.5691 |
\ No newline at end of file
diff --git a/docs/phi-2-acc.md b/docs/phi-2-acc.md
new file mode 100644
index 000000000..a2c612ae7
--- /dev/null
+++ b/docs/phi-2-acc.md
@@ -0,0 +1,22 @@
+Install [lm-eval-harness](https://github.com/EleutherAI/lm-evaluation-harness.git) from source, and the git id f3b7917091afba325af3980a35d8a6dcba03dc3f is used
+
+Download the model from hf(coming soon) or follow examples/language-modeling/scripts/phi-2.sh to generate the model
+
+Since we encountered an issue evaluating this model with lm-eval, we opted to evaluate the qdq model instead. In our assessment, we found that its accuracy closely matches that of the real quantized model in most cases except for some small models like opt-125m.
+
+
+
+| Metric | FP16 | INT4 qdq |
+| -------------- | ------ | -------- |
+| Avg. | 0.6155 | 0.6163 |
+| mmlu | 0.5448 | 0.5417 |
+| lambada_openai | 0.6268 | 0.6225 |
+| hellaswag | 0.5585 | 0.5498 |
+| winogrande | 0.7530 | 0.7545 |
+| piqa | 0.7867 | 0.7824 |
+| truthfulqa_mc1 | 0.3133 | 0.3060 |
+| openbookqa | 0.4000 | 0.4100 |
+| boolq | 0.8339 | 0.8327 |
+| rte | 0.6245 | 0.6643 |
+| arc_easy | 0.7997 | 0.7955 |
+| arc_challenge | 0.5290 | 0.5196 |
\ No newline at end of file
diff --git a/examples/language-modeling/eval/evaluation.py b/examples/language-modeling/eval/evaluation.py
index 000e12c4b..3fef08105 100644
--- a/examples/language-modeling/eval/evaluation.py
+++ b/examples/language-modeling/eval/evaluation.py
@@ -11,7 +11,6 @@ import transformers
if __name__ == "__main__":
import sys
sys.path.insert(0, './')
-from eval.parse_results import result_parser
import time
EXT_TASKS = ['wikitext2', 'ptb', 'c4', 'ptb-new', 'c4-new']
fewshots_dict = {}
diff --git a/examples/language-modeling/main.py b/examples/language-modeling/main.py
index 4fa9bace4..47b51ffe6 100644
--- a/examples/language-modeling/main.py
+++ b/examples/language-modeling/main.py
@@ -7,7 +7,7 @@ from auto_round import (AutoRound,
parser = argparse.ArgumentParser()
import torch
import os
-
+import transformers
os.environ["CUBLAS_WORKSPACE_CONFIG"] = ":4096:8"
torch.use_deterministic_algorithms(True, warn_only=True)
from transformers import AutoModelForCausalLM, AutoTokenizer, AutoModel
diff --git a/examples/language-modeling/scripts/Mistral-7B-v0.1.sh b/examples/language-modeling/scripts/Mistral-7B-v0.1.sh
new file mode 100644
index 000000000..226b042c8
--- /dev/null
+++ b/examples/language-modeling/scripts/Mistral-7B-v0.1.sh
@@ -0,0 +1,13 @@
+python3 main.py \
+--model_name mistralai/Mistral-7B-v0.1 \
+--device 0 \
+--group_size 128 \
+--bits 4 \
+--iters 1000 \
+--enable_minmax_tuning \
+--use_quant_input \
+--deployment_device 'gpu' \
+--scale_dtype 'fp32' \
+--eval_bs 32 \
+--output_dir "./tmp_autoround" \
+--amp
\ No newline at end of file
diff --git a/examples/language-modeling/scripts/Mixtral-8x7B-Instruct-v0.1.sh b/examples/language-modeling/scripts/Mixtral-8x7B-Instruct-v0.1.sh
new file mode 100644
index 000000000..175368630
--- /dev/null
+++ b/examples/language-modeling/scripts/Mixtral-8x7B-Instruct-v0.1.sh
@@ -0,0 +1,14 @@
+python3 main.py \
+--model_name mistralai/Mixtral-8x7B-Instruct-v0.1 \
+--device 0 \
+--group_size 128 \
+--bits 4 \
+--iters 1000 \
+--enable_minmax_tuning \
+--use_quant_input \
+--low_gpu_mem_usage \
+--deployment_device 'gpu' \
+--scale_dtype 'fp32' \
+--eval_bs 32 \
+--output_dir "./tmp_autoround" \
+--amp
\ No newline at end of file
diff --git a/examples/language-modeling/scripts/Mixtral-8x7B-v0.1.sh b/examples/language-modeling/scripts/Mixtral-8x7B-v0.1.sh
new file mode 100644
index 000000000..f488beae2
--- /dev/null
+++ b/examples/language-modeling/scripts/Mixtral-8x7B-v0.1.sh
@@ -0,0 +1,13 @@
+python3 main.py \
+--model_name mistralai/Mixtral-8x7B-v0.1 \
+--device 0 \
+--group_size 128 \
+--bits 4 \
+--iters 1000 \
+--enable_minmax_tuning \
+--low_gpu_mem_usage \
+--deployment_device 'gpu' \
+--scale_dtype 'fp32' \
+--eval_bs 32 \
+--output_dir "./tmp_autoround" \
+--amp
\ No newline at end of file
diff --git a/examples/language-modeling/scripts/neural-chat-7b-v3-1.sh b/examples/language-modeling/scripts/neural-chat-7b-v3-1.sh
new file mode 100644
index 000000000..e3751eed2
--- /dev/null
+++ b/examples/language-modeling/scripts/neural-chat-7b-v3-1.sh
@@ -0,0 +1,14 @@
+## enter to language-modeling fold
+python3 main.py \
+--model_name /models/neural-chat-7b-v3-1 \
+--device 0 \
+--group_size 128 \
+--bits 4 \
+--iters 1000 \
+--enable_minmax_tuning \
+--minmax_lr 0.0002 \
+--deployment_device 'gpu' \
+--scale_dtype 'fp32' \
+--eval_bs 32 \
+--output_dir "./tmp_autoround" \
+--amp
\ No newline at end of file
diff --git a/examples/language-modeling/scripts/neural-chat-7b-v3-3.sh b/examples/language-modeling/scripts/neural-chat-7b-v3-3.sh
new file mode 100644
index 000000000..a87fbef27
--- /dev/null
+++ b/examples/language-modeling/scripts/neural-chat-7b-v3-3.sh
@@ -0,0 +1,13 @@
+python3 main.py \
+--model_name Intel/neural-chat-7b-v3-3 \
+--device 0 \
+--group_size 128 \
+--bits 4 \
+--iters 1000 \
+--enable_minmax_tuning \
+--minmax_lr 0.0002 \
+--deployment_device 'gpu' \
+--scale_dtype 'fp32' \
+--eval_bs 32 \
+--output_dir "./tmp_autoround" \
+--amp
diff --git a/examples/language-modeling/scripts/phi-2.sh b/examples/language-modeling/scripts/phi-2.sh
new file mode 100644
index 000000000..3763573c2
--- /dev/null
+++ b/examples/language-modeling/scripts/phi-2.sh
@@ -0,0 +1,12 @@
+python3 main.py \
+--model_name microsoft/phi-2 \
+--device 0 \
+--group_size 128 \
+--bits 4 \
+--iters 1000 \
+--enable_minmax_tuning \
+--deployment_device 'gpu' \
+--scale_dtype 'fp32' \
+--eval_bs 32 \
+--output_dir "./tmp_autoround" \
+--amp
\ No newline at end of file