yuccaaa commited on
Commit
91743d3
·
verified ·
1 Parent(s): 5a6aecb

Upload ms-swift/docs/source_en/Instruction/Evaluation.md with huggingface_hub

Browse files
ms-swift/docs/source_en/Instruction/Evaluation.md ADDED
@@ -0,0 +1,270 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Evaluation
2
+
3
+ SWIFT supports eval (evaluation) capabilities to provide standardized evaluation metrics for both raw models and trained models.
4
+
5
+ ## Capability Introduction
6
+
7
+ SWIFT's eval capability utilizes the EvalScope evaluation framework from the Magic Tower community, which has been advanced in its encapsulation to support the evaluation needs of various models.
8
+
9
+ > Note: EvalScope supports many other complex capabilities, such as [model performance evaluation](https://evalscope.readthedocs.io/en/latest/user_guides/stress_test/quick_start.html), so please use the EvalScope framework directly.
10
+
11
+ Currently, we support the evaluation process of **standard evaluation datasets** as well as the evaluation process of **user-defined** evaluation datasets. The **standard evaluation datasets** are supported by three evaluation backends:
12
+
13
+ Below are the names of the supported datasets. For detailed information on the datasets, please refer to [all supported datasets](https://evalscope.readthedocs.io/en/latest/get_started/supported_dataset.html).
14
+
15
+ 1. Native (default):
16
+
17
+ Primarily supports pure text evaluation, while **supporting** visualization of evaluation results.
18
+ ```text
19
+ 'arc', 'bbh', 'ceval', 'cmmlu', 'competition_math',
20
+ 'general_qa', 'gpqa', 'gsm8k', 'hellaswag', 'humaneval',
21
+ 'ifeval', 'iquiz', 'mmlu', 'mmlu_pro',
22
+ 'race', 'trivia_qa', 'truthful_qa'
23
+ ```
24
+
25
+ 2. OpenCompass:
26
+
27
+ Primarily supports pure text evaluation, currently **does not support** visualization of evaluation results.
28
+ ```text
29
+ 'obqa', 'cmb', 'AX_b', 'siqa', 'nq', 'mbpp', 'winogrande', 'mmlu', 'BoolQ', 'cluewsc', 'ocnli', 'lambada',
30
+ 'CMRC', 'ceval', 'csl', 'cmnli', 'bbh', 'ReCoRD', 'math', 'humaneval', 'eprstmt', 'WSC', 'storycloze',
31
+ 'MultiRC', 'RTE', 'chid', 'gsm8k', 'AX_g', 'bustm', 'afqmc', 'piqa', 'lcsts', 'strategyqa', 'Xsum', 'agieval',
32
+ 'ocnli_fc', 'C3', 'tnews', 'race', 'triviaqa', 'CB', 'WiC', 'hellaswag', 'summedits', 'GaokaoBench',
33
+ 'ARC_e', 'COPA', 'ARC_c', 'DRCD'
34
+ ```
35
+
36
+ 3. VLMEvalKit:
37
+
38
+ Primarily supports multimodal evaluation and currently **does not support** visualization of evaluation results.
39
+ ```text
40
+ 'COCO_VAL', 'MME', 'HallusionBench', 'POPE', 'MMBench_DEV_EN', 'MMBench_TEST_EN', 'MMBench_DEV_CN', 'MMBench_TEST_CN',
41
+ 'MMBench', 'MMBench_CN', 'MMBench_DEV_EN_V11', 'MMBench_TEST_EN_V11', 'MMBench_DEV_CN_V11',
42
+ 'MMBench_TEST_CN_V11', 'MMBench_V11', 'MMBench_CN_V11', 'SEEDBench_IMG', 'SEEDBench2',
43
+ 'SEEDBench2_Plus', 'ScienceQA_VAL', 'ScienceQA_TEST', 'MMT-Bench_ALL_MI', 'MMT-Bench_ALL',
44
+ 'MMT-Bench_VAL_MI', 'MMT-Bench_VAL', 'AesBench_VAL', 'AesBench_TEST', 'CCBench', 'AI2D_TEST', 'MMStar',
45
+ 'RealWorldQA', 'MLLMGuard_DS', 'BLINK', 'OCRVQA_TEST', 'OCRVQA_TESTCORE', 'TextVQA_VAL', 'DocVQA_VAL',
46
+ 'DocVQA_TEST', 'InfoVQA_VAL', 'InfoVQA_TEST', 'ChartQA_TEST', 'MathVision', 'MathVision_MINI',
47
+ 'MMMU_DEV_VAL', 'MMMU_TEST', 'OCRBench', 'MathVista_MINI', 'LLaVABench', 'MMVet', 'MTVQA_TEST',
48
+ 'MMLongBench_DOC', 'VCR_EN_EASY_500', 'VCR_EN_EASY_100', 'VCR_EN_EASY_ALL', 'VCR_EN_HARD_500',
49
+ 'VCR_EN_HARD_100', 'VCR_EN_HARD_ALL', 'VCR_ZH_EASY_500', 'VCR_ZH_EASY_100', 'VCR_ZH_EASY_ALL',
50
+ 'VCR_ZH_HARD_500', 'VCR_ZH_HARD_100', 'VCR_ZH_HARD_ALL', 'MMDU', 'MMBench-Video', 'Video-MME'
51
+ ```
52
+
53
+ ## Environment Preparation
54
+
55
+ ```shell
56
+ pip install ms-swift[eval] -U
57
+ ```
58
+
59
+ Or install from source:
60
+
61
+ ```shell
62
+ git clone https://github.com/modelscope/ms-swift.git
63
+ cd ms-swift
64
+ pip install -e '.[eval]'
65
+ ```
66
+
67
+ ## Evaluation
68
+
69
+ Supports four methods of evaluation: pure text evaluation, multimodal evaluation, URL evaluation, and custom dataset evaluation.
70
+
71
+ **Basic Example**
72
+
73
+ ```shell
74
+ CUDA_VISIBLE_DEVICES=0 \
75
+ swift eval \
76
+ --model Qwen/Qwen2.5-0.5B-Instruct \
77
+ --eval_backend Native \
78
+ --infer_backend pt \
79
+ --eval_limit 10 \
80
+ --eval_dataset gsm8k
81
+ ```
82
+ Where:
83
+ - model: Can specify a local model path or a model ID on modelscope
84
+ - eval_backend: Options are Native, OpenCompass, VLMEvalKit; default is Native
85
+ - infer_backend: Options are pt, vllm, lmdeploy; default is pt
86
+ - eval_limit: Sample size for each evaluation set; default is None, which means using all data; can be used for quick validation
87
+ - eval_dataset: Evaluation dataset(s); multiple datasets can be set, separated by spaces
88
+
89
+ For a specific list of evaluation parameters, please refer to [here](./Command-line-parameters.md#evaluation-arguments).
90
+
91
+ ## Evaluation During Training
92
+
93
+ SWIFT supports using EvalScope to evaluate the current model during the training process, allowing for timely understanding of the model's training effectiveness.
94
+
95
+ **Basic Example**
96
+
97
+ ```shell
98
+ CUDA_VISIBLE_DEVICES=0 \
99
+ swift sft \
100
+ --model "Qwen/Qwen2.5-0.5B-Instruct" \
101
+ --train_type "lora" \
102
+ --dataset "AI-ModelScope/alpaca-gpt4-data-zh#100" \
103
+ --torch_dtype "bfloat16" \
104
+ --num_train_epochs "1" \
105
+ --per_device_train_batch_size "1" \
106
+ --learning_rate "1e-4" \
107
+ --lora_rank "8" \
108
+ --lora_alpha "32" \
109
+ --target_modules "all-linear" \
110
+ --gradient_accumulation_steps "16" \
111
+ --save_steps "50" \
112
+ --save_total_limit "5" \
113
+ --logging_steps "5" \
114
+ --max_length "2048" \
115
+ --eval_strategy "steps" \
116
+ --eval_steps "5" \
117
+ --per_device_eval_batch_size "5" \
118
+ --eval_use_evalscope \
119
+ --eval_datasets "gsm8k" \
120
+ --eval_datasets_args '{"gsm8k": {"few_shot_num": 0}}' \
121
+ --eval_limit "10"
122
+ ```
123
+
124
+ Note that the launch command is `sft`, and the evaluation-related parameters include:
125
+ - eval_strategy: Evaluation strategy. Defaults to None, following the `save_strategy` policy
126
+ - eval_steps: Defaults to None. If an evaluation dataset exists, it follows the `save_steps` policy
127
+ - eval_use_evalscope: Whether to use evalscope for evaluation, this parameter needs to be set to enable evaluation
128
+ - eval_datasets: Evaluation datasets, multiple datasets can be set, separated by spaces
129
+ - eval_datasets_args: Evaluation dataset parameters in JSON format, parameters for multiple datasets can be set
130
+ - eval_limit: Number of samples from the evaluation dataset
131
+ - eval_generation_config: Model inference configuration during evaluation, in JSON format, default is `{'max_tokens': 512}`
132
+
133
+ More evaluation examples can be found in [examples](https://github.com/modelscope/ms-swift/tree/main/examples/eval).
134
+
135
+ ## Custom Evaluation Datasets
136
+
137
+ This framework supports two predefined dataset formats: multiple-choice questions (MCQ) and question-and-answer (QA). The usage process is as follows:
138
+
139
+ *Note: When using a custom evaluation, the `eval_backend` parameter must be set to `Native`.*
140
+
141
+ ### Multiple-Choice Question Format (MCQ)
142
+ This format is suitable for scenarios involving multiple-choice questions, and the evaluation metric is accuracy.
143
+
144
+ **Data Preparation**
145
+
146
+ Prepare a CSV file in the multiple-choice question format, structured as follows:
147
+
148
+ ```text
149
+ mcq/
150
+ ├── example_dev.csv # (Optional) The filename should follow the format `{subset_name}_dev.csv` for few-shot evaluation
151
+ └── example_val.csv # The filename should follow the format `{subset_name}_val.csv` for the actual evaluation data
152
+ ```
153
+
154
+ The CSV file should follow this format:
155
+
156
+ ```text
157
+ id,question,A,B,C,D,answer
158
+ 1,Generally speaking, the amino acids that make up animal proteins are____,4 types,22 types,20 types,19 types,C
159
+ 2,Among the substances present in the blood, which is not a metabolic end product?____,Urea,Uric acid,Pyruvate,Carbon dioxide,C
160
+ ```
161
+
162
+ Where:
163
+ - `id` is an optional index
164
+ - `question` is the question
165
+ - `A`, `B`, `C`, `D`, etc. are the options, with a maximum of 10 options
166
+ - `answer` is the correct option
167
+
168
+ **Launching Evaluation**
169
+
170
+ Run the following command:
171
+
172
+ ```bash
173
+ CUDA_VISIBLE_DEVICES=0 \
174
+ swift eval \
175
+ --model Qwen/Qwen2.5-0.5B-Instruct \
176
+ --eval_backend Native \
177
+ --infer_backend pt \
178
+ --eval_dataset general_mcq \
179
+ --dataset_args '{"general_mcq": {"local_path": "/path/to/mcq", "subset_list": ["example"]}}'
180
+ ```
181
+
182
+ Where:
183
+ - `eval_dataset` should be set to `general_mcq`
184
+ - `dataset_args` should be set with:
185
+ - `local_path` as the path to the custom dataset folder
186
+ - `subset_list` as the name of the evaluation dataset, taken from the `*_dev.csv` mentioned above
187
+
188
+ **Running Results**
189
+
190
+ ```text
191
+ +---------------------+-------------+-----------------+----------+-------+---------+---------+
192
+ | Model | Dataset | Metric | Subset | Num | Score | Cat.0 |
193
+ +=====================+=============+=================+==========+=======+=========+=========+
194
+ | Qwen2-0.5B-Instruct | general_mcq | AverageAccuracy | example | 12 | 0.5833 | default |
195
+ +---------------------+-------------+-----------------+----------+-------+---------+---------+
196
+ ```
197
+
198
+ ## Question-and-Answer Format (QA)
199
+ This format is suitable for scenarios involving question-and-answer, and the evaluation metrics are `ROUGE` and `BLEU`.
200
+
201
+ **Data Preparation**
202
+
203
+ Prepare a JSON Lines file in the question-and-answer format, containing one file in the following structure:
204
+
205
+ ```text
206
+ qa/
207
+ └── example.jsonl
208
+ ```
209
+
210
+ The JSON Lines file should follow this format:
211
+
212
+ ```json
213
+ {"query": "What is the capital of China?", "response": "The capital of China is Beijing"}
214
+ {"query": "What is the highest mountain in the world?", "response": "It is Mount Everest"}
215
+ {"query": "Why can't penguins be seen in the Arctic?", "response": "Because most penguins live in Antarctica"}
216
+ ```
217
+
218
+ **Launching Evaluation**
219
+
220
+ Run the following command:
221
+
222
+ ```bash
223
+ CUDA_VISIBLE_DEVICES=0 \
224
+ swift eval \
225
+ --model Qwen/Qwen2.5-0.5B-Instruct \
226
+ --eval_backend Native \
227
+ --infer_backend pt \
228
+ --eval_dataset general_qa \
229
+ --dataset_args '{"general_qa": {"local_path": "/path/to/qa", "subset_list": ["example"]}}'
230
+ ```
231
+
232
+ Where:
233
+ - `eval_dataset` should be set to `general_qa`
234
+ - `dataset_args` is a JSON string that needs to be set with:
235
+ - `local_path` as the path to the custom dataset folder
236
+ - `subset_list` as the name of the evaluation dataset, taken from the `*.jsonl` mentioned above
237
+
238
+ **Running Results**
239
+
240
+ ```text
241
+ +---------------------+-------------+-----------------+----------+-------+---------+---------+
242
+ | Model | Dataset | Metric | Subset | Num | Score | Cat.0 |
243
+ +=====================+=============+=================+==========+=======+=========+=========+
244
+ | Qwen2-0.5B-Instruct | general_qa | bleu-1 | default | 12 | 0.2324 | default |
245
+ +---------------------+-------------+-----------------+----------+-------+---------+---------+
246
+ | Qwen2-0.5B-Instruct | general_qa | bleu-2 | default | 12 | 0.1451 | default |
247
+ +---------------------+-------------+-----------------+----------+-------+---------+---------+
248
+ | Qwen2-0.5B-Instruct | general_qa | bleu-3 | default | 12 | 0.0625 | default |
249
+ +---------------------+-------------+-----------------+----------+-------+---------+---------+
250
+ | Qwen2-0.5B-Instruct | general_qa | bleu-4 | default | 12 | 0.0556 | default |
251
+ +---------------------+-------------+-----------------+----------+-------+---------+---------+
252
+ | Qwen2-0.5B-Instruct | general_qa | rouge-1-f | default | 12 | 0.3441 | default |
253
+ +---------------------+-------------+-----------------+----------+-------+---------+---------+
254
+ | Qwen2-0.5B-Instruct | general_qa | rouge-1-p | default | 12 | 0.2393 | default |
255
+ +---------------------+-------------+-----------------+----------+-------+---------+---------+
256
+ | Qwen2-0.5B-Instruct | general_qa | rouge-1-r | default | 12 | 0.8889 | default |
257
+ +---------------------+-------------+-----------------+----------+-------+---------+---------+
258
+ | Qwen2-0.5B-Instruct | general_qa | rouge-2-f | default | 12 | 0.2062 | default |
259
+ +---------------------+-------------+-----------------+----------+-------+---------+---------+
260
+ | Qwen2-0.5B-Instruct | general_qa | rouge-2-p | default | 12 | 0.1453 | default |
261
+ +---------------------+-------------+-----------------+----------+-------+---------+---------+
262
+ | Qwen2-0.5B-Instruct | general_qa | rouge-2-r | default | 12 | 0.6167 | default |
263
+ +---------------------+-------------+-----------------+----------+-------+---------+---------+
264
+ | Qwen2-0.5B-Instruct | general_qa | rouge-l-f | default | 12 | 0.333 | default |
265
+ +---------------------+-------------+-----------------+----------+-------+---------+---------+
266
+ | Qwen2-0.5B-Instruct | general_qa | rouge-l-p | default | 12 | 0.2324 | default |
267
+ +---------------------+-------------+-----------------+----------+-------+---------+---------+
268
+ | Qwen2-0.5B-Instruct | general_qa | rouge-l-r | default | 12 | 0.8889 | default |
269
+ +---------------------+-------------+-----------------+----------+-------+---------+---------+
270
+ ```