get_started.md 11.2 KB
Newer Older
gaotongxiao's avatar
gaotongxiao committed
1
2
# Installation

Ezra-Yu's avatar
Ezra-Yu committed
3
1. Set up the OpenCompass environment:
gaotongxiao's avatar
gaotongxiao committed
4
5

```bash
Ma Zerun's avatar
Ma Zerun committed
6
conda create --name opencompass python=3.10 pytorch torchvision pytorch-cuda -c nvidia -c pytorch -y
gaotongxiao's avatar
gaotongxiao committed
7
8
9
conda activate opencompass
```

Ma Zerun's avatar
Ma Zerun committed
10
11
If you want to customize the PyTorch version or related CUDA version, please refer to the [official documentation](https://pytorch.org/get-started/locally/) to set up the PyTorch environment. Note that OpenCompass requires `pytorch>=1.13`.

gaotongxiao's avatar
gaotongxiao committed
12
13
14
2. Install OpenCompass:

```bash
Ezra-Yu's avatar
Ezra-Yu committed
15
git clone https://github.com/InternLM/opencompass.git
gaotongxiao's avatar
gaotongxiao committed
16
17
18
19
cd opencompass
pip install -e .
```

Ma Zerun's avatar
Ma Zerun committed
20
3. Install humaneval (Optional)
gaotongxiao's avatar
gaotongxiao committed
21

Ezra-Yu's avatar
Ezra-Yu committed
22
23
24
25
If you want to **evaluate your models coding ability on the humaneval dataset**, execute this step otherwise skip it.

<details>
<summary><b>click to show the details</b></summary>
gaotongxiao's avatar
gaotongxiao committed
26

Ezra-Yu's avatar
Ezra-Yu committed
27
```bash
gaotongxiao's avatar
gaotongxiao committed
28
29
git clone https://github.com/openai/human-eval.git
cd human-eval
Leymore's avatar
Leymore committed
30
pip install -r requirements.txt
gaotongxiao's avatar
gaotongxiao committed
31
pip install -e .
Ma Zerun's avatar
Ma Zerun committed
32
cd ..
gaotongxiao's avatar
gaotongxiao committed
33
34
```

Ma Zerun's avatar
Ma Zerun committed
35
36
Please read the comments in `human_eval/execution.py` **lines 48-57** to understand the potential risks of executing the model generation code. If you accept these risks, uncomment **line 58** to enable code execution evaluation.

Ezra-Yu's avatar
Ezra-Yu committed
37
</details>
Ma Zerun's avatar
Ma Zerun committed
38

Ezra-Yu's avatar
Ezra-Yu committed
39
# Dataset Preparation
Ma Zerun's avatar
Ma Zerun committed
40

Ezra-Yu's avatar
Ezra-Yu committed
41
The datasets supported by OpenCompass mainly include two parts:
Ma Zerun's avatar
Ma Zerun committed
42

Ezra-Yu's avatar
Ezra-Yu committed
43
44
1. Huggingface datasets: The [Huggingface Datasets](https://huggingface.co/datasets) provide a large number of datasets, which will **automatically download** when running with this option.
2. Custom dataset: OpenCompass also provides some Chinese custom **self-built** datasets. Please run the following command to **manually download and extract** them.
Ezra-Yu's avatar
Ezra-Yu committed
45

Tong Gao's avatar
Tong Gao committed
46
Run the following commands to download and place the datasets in the `${OpenCompass}/data` directory can complete dataset preparation.
Ezra-Yu's avatar
Ezra-Yu committed
47

Ezra-Yu's avatar
Ezra-Yu committed
48
49
50
51
52
```bash
# Run in the OpenCompass directory
wget https://github.com/InternLM/opencompass/releases/download/0.1.0/OpenCompassData.zip
unzip OpenCompassData.zip
```
Ezra-Yu's avatar
Ezra-Yu committed
53

Ezra-Yu's avatar
Ezra-Yu committed
54
55
56
57
58
59
60
61
62
63
64
65
OpenCompass has supported most of the datasets commonly used for performance comparison, please refer to `configs/dataset` for the specific list of supported datasets.

# Quick Start

The evaluation of OpenCompass relies on configuration files which must contain fields **`datasets`** and **`models`**.
The configurations specify the models and datasets to evaluate using **"run.py"**.

We will demonstrate some basic features of OpenCompass through evaluating pretrained models [OPT-125M](https://huggingface.co/facebook/opt-125m) and [OPT-350M](https://huggingface.co/facebook/opt-350m) on both [SIQA](https://huggingface.co/datasets/social_i_qa) and [Winograd](https://huggingface.co/datasets/winogrande) benchmark tasks with their config file located at [configs/eval_demo.py](https://github.com/InternLM/opencompass/blob/main/configs/eval_demo.py).

Before running this experiment, please make sure you have installed OpenCompass locally and it should run successfully under one _GTX-1660-6G_ GPU.
For larger parameterized models like Llama-7B, refer to other examples provided in the [configs directory](https://github.com/InternLM/opencompass/tree/main/configs).

Tong Gao's avatar
Tong Gao committed
66
Since OpenCompass launches evaluation processes in parallel by default, we can start the evaluation for the first run and check if there is any prblem. In debugging mode, the tasks will be executed sequentially and the status will be printed in real time.
Ezra-Yu's avatar
Ezra-Yu committed
67
68

```bash
Tong Gao's avatar
Tong Gao committed
69
python run.py configs/eval_demo.py -w outputs/demo --debug
Ezra-Yu's avatar
Ezra-Yu committed
70
71
```

Tong Gao's avatar
Tong Gao committed
72
73
74
75
76
If everything is fine, you should see "Starting inference process" on screen:

```bash
[2023-07-12 18:23:55,076] [opencompass.openicl.icl_inferencer.icl_gen_inferencer] [INFO] Starting inference process...
```
Ezra-Yu's avatar
Ezra-Yu committed
77

Tong Gao's avatar
Tong Gao committed
78
Then you can press `ctrl+c` to interrupt the program, and then run the following command to start the parallel evaluation:
Ezra-Yu's avatar
Ezra-Yu committed
79

Tong Gao's avatar
Tong Gao committed
80
81
82
83
84
85
86
87
88
89
90
```bash
python run.py configs/eval_demo.py -w outputs/demo
```

Now let's go over the configuration file and the launch options used in this case.

## Explanations

### Dataset list - `datasets`

Below is the configuration snippet related to datasets in `configs/eval_demo.py`:
Ma Zerun's avatar
Ma Zerun committed
91
92

```python
Tong Gao's avatar
Tong Gao committed
93
from mmengine.config import read_base  # Use mmengine.read_base() to load base configs
Ma Zerun's avatar
Ma Zerun committed
94
95
96

with read_base():
    # Read the required dataset configurations directly from the preset dataset configurations
Tong Gao's avatar
Tong Gao committed
97
98
    from .datasets.winograd.winograd_ppl import winograd_datasets   # Load Winograd's configuration, which uses perplexity-based inference
    from .datasets.siqa.siqa_gen import siqa_datasets               # Load SIQA's configuration, which uses generation-based inference
Ma Zerun's avatar
Ma Zerun committed
99

Ezra-Yu's avatar
Ezra-Yu committed
100
datasets = [*siqa_datasets, *winograd_datasets]   # Concatenate the datasets to be evaluated into the datasets field
Ezra-Yu's avatar
Ezra-Yu committed
101
102
```

Ezra-Yu's avatar
Ezra-Yu committed
103
Various dataset configurations are available in [configs/datasets](https://github.com/InternLM/OpenCompass/blob/main/configs/datasets).
Tong Gao's avatar
Tong Gao committed
104
Some datasets have two types of configuration files within their folders named `ppl` and `gen`, representing different evaluation methods. Specifically, `ppl` represents discriminative evaluation, while `gen` stands for generative evaluation.
Ezra-Yu's avatar
Ezra-Yu committed
105
106
107

[configs/datasets/collections](https://github.com/InternLM/OpenCompass/blob/main/configs/datasets/collections) contains various collections of datasets for comprehensive evaluation purposes.

Tong Gao's avatar
Tong Gao committed
108
You can find more information from [Dataset Preparation](./user_guides/dataset_prepare.md).
Ezra-Yu's avatar
Ezra-Yu committed
109

Tong Gao's avatar
Tong Gao committed
110
### Model list - `models`
Ma Zerun's avatar
Ma Zerun committed
111

Tong Gao's avatar
Tong Gao committed
112
OpenCompass supports directly specifying the list of models to be tested in the configuration. For HuggingFace models, users usually do not need to modify the code. The following is the relevant configuration snippet:
Ezra-Yu's avatar
Ezra-Yu committed
113
114

```python
Ma Zerun's avatar
Ma Zerun committed
115
116
117
# Evaluate models supported by HuggingFace's `AutoModelForCausalLM` using `HuggingFaceCausalLM`
from opencompass.models import HuggingFaceCausalLM

Ezra-Yu's avatar
Ezra-Yu committed
118
119
120
121
122
123
124
125
126
127
128
129
# OPT-350M
opt350m = dict(
       type=HuggingFaceCausalLM,
       # Initialization parameters for `HuggingFaceCausalLM`
       path='facebook/opt-350m',
       tokenizer_path='facebook/opt-350m',
       tokenizer_kwargs=dict(
           padding_side='left',
           truncation_side='left',
           proxies=None,
           trust_remote_code=True),
       model_kwargs=dict(device_map='auto'),
Tong Gao's avatar
Tong Gao committed
130
131
132
133
134
135
       # Below are common parameters for all models, not specific to HuggingFaceCausalLM
       abbr='opt350m',               # Model abbreviation for result display
       max_seq_len=2048,             # The maximum length of the entire sequence
       max_out_len=100,              # Maximum number of generated tokens
       batch_size=64,                # batchsize
       run_cfg=dict(num_gpus=1),     # Run configuration for specifying resource requirements
Ma Zerun's avatar
Ma Zerun committed
136
    )
Ezra-Yu's avatar
Ezra-Yu committed
137

Ezra-Yu's avatar
Ezra-Yu committed
138
139
140
141
142
143
144
145
146
147
148
149
# OPT-125M
opt125m = dict(
       type=HuggingFaceCausalLM,
       # Initialization parameters for `HuggingFaceCausalLM`
       path='facebook/opt-125m',
       tokenizer_path='facebook/opt-125m',
       tokenizer_kwargs=dict(
           padding_side='left',
           truncation_side='left',
           proxies=None,
           trust_remote_code=True),
       model_kwargs=dict(device_map='auto'),
Tong Gao's avatar
Tong Gao committed
150
       # Below are common parameters for all models, not specific to HuggingFaceCausalLM
Ezra-Yu's avatar
Ezra-Yu committed
151
       abbr='opt125m',                # Model abbreviation for result display
Tong Gao's avatar
Tong Gao committed
152
       max_seq_len=2048,              # The maximum length of the entire sequence
Ezra-Yu's avatar
Ezra-Yu committed
153
154
155
156
157
158
       max_out_len=100,               # Maximum number of generated tokens
       batch_size=128,                # batchsize
       run_cfg=dict(num_gpus=1),      # Run configuration for specifying resource requirements
    )

models = [opt350m, opt125m]
Ma Zerun's avatar
Ma Zerun committed
159
```
gaotongxiao's avatar
gaotongxiao committed
160

Tong Gao's avatar
Tong Gao committed
161
The pretrained models 'facebook/opt-350m' and 'facebook/opt-125m' will be automatically downloaded from HuggingFace during the first run.
Ezra-Yu's avatar
Ezra-Yu committed
162

Tong Gao's avatar
Tong Gao committed
163
More information about model configuration can be found in [Prepare Models](./user_guides/models.md).
gaotongxiao's avatar
gaotongxiao committed
164

Tong Gao's avatar
Tong Gao committed
165
166
167
### Launch Evaluation

When the config file is ready, we can start the task in **debug mode** to check for any exceptions in model loading, dataset reading, or incorrect cache usage.
Ma Zerun's avatar
Ma Zerun committed
168
169

```shell
Ezra-Yu's avatar
Ezra-Yu committed
170
python run.py configs/eval_demo.py -w outputs/demo --debug
Ma Zerun's avatar
Ma Zerun committed
171
172
173
174
175
176
```

However, in `--debug` mode, tasks are executed sequentially. After confirming that everything is correct, you
can disable the `--debug` mode to fully utilize multiple GPUs.

```shell
Ezra-Yu's avatar
Ezra-Yu committed
177
python run.py configs/eval_demo.py -w outputs/demo
Ma Zerun's avatar
Ma Zerun committed
178
179
180
181
```

Here are some parameters related to evaluation that can help you configure more efficient inference tasks based on your environment:

Ezra-Yu's avatar
Ezra-Yu committed
182
- `-w outputs/demo`: Directory to save evaluation logs and results.
Ma Zerun's avatar
Ma Zerun committed
183
184
185
186
187
188
189
190
191
192
193
194
- `-r`: Restart the previous (interrupted) evaluation.
- `--mode all`: Specify a specific stage of the task.
  - all: Perform a complete evaluation, including inference and evaluation.
  - infer: Perform inference on each dataset.
  - eval: Perform evaluation based on the inference results.
  - viz: Display evaluation results only.
- `--max-partition-size 2000`: Dataset partition size. Some datasets may be large, and using this parameter can split them into multiple sub-tasks to efficiently utilize resources. However, if the partition is too fine, the overall speed may be slower due to longer model loading times.
- `--max-num-workers 32`: Maximum number of parallel tasks. In distributed environments such as Slurm, this parameter specifies the maximum number of submitted tasks. In a local environment, it specifies the maximum number of tasks executed in parallel. Note that the actual number of parallel tasks depends on the available GPU resources and may not be equal to this number.

If you are not performing the evaluation on your local machine but using a Slurm cluster, you can specify the following parameters:

- `--slurm`: Submit tasks using Slurm on the cluster.
Ezra-Yu's avatar
Ezra-Yu committed
195
- `--partition(-p) my_part`: Slurm cluster partition.
Ma Zerun's avatar
Ma Zerun committed
196
197
- `--retry 2`: Number of retries for failed tasks.

Ezra-Yu's avatar
Ezra-Yu committed
198
199
200
201
```{tip}
The entry also supports submitting tasks to Alibaba Deep Learning Center (DLC), and more customized evaluation strategies. Please refer to [Launching an Evaluation Task](./user_guides/experimentation.md#launching-an-evaluation-task) for details.
```

Ma Zerun's avatar
Ma Zerun committed
202
203
204
205
206
## Obtaining Evaluation Results

After the evaluation is complete, the evaluation results table will be printed as follows:

```text
Ezra-Yu's avatar
Ezra-Yu committed
207
208
209
210
dataset    version    metric    mode      opt350m    opt125m
---------  ---------  --------  ------  ---------  ---------
siqa       e78df3     accuracy  gen         21.55      12.44
winograd   b6c7ed     accuracy  ppl         51.23      49.82
Ma Zerun's avatar
Ma Zerun committed
211
```
gaotongxiao's avatar
gaotongxiao committed
212

Tong Gao's avatar
Tong Gao committed
213
All run outputs will be directed to `outputs/demo/` directory with following structure:
Ezra-Yu's avatar
Ezra-Yu committed
214

Ezra-Yu's avatar
Ezra-Yu committed
215
```text
Ezra-Yu's avatar
Ezra-Yu committed
216
217
outputs/default/
├── 20200220_120000
Ezra-Yu's avatar
Ezra-Yu committed
218
├── 20230220_183030     # one experiment pre folder
Tong Gao's avatar
Tong Gao committed
219
│   ├── configs         # Dumped config files for record. Multiple configs may be kept if different experiments have been re-run on the same experiment folder
Ezra-Yu's avatar
Ezra-Yu committed
220
│   ├── logs            # log files for both inference and evaluation stages
Ezra-Yu's avatar
Ezra-Yu committed
221
222
│   │   ├── eval
│   │   └── infer
Tong Gao's avatar
Tong Gao committed
223
224
225
│   ├── predictions   # Prediction results for each task
│   ├── results       # Evaluation results for each task
│   └── summary       # Summarized evaluation results for a single experiment
Ezra-Yu's avatar
Ezra-Yu committed
226
├── ...
Ezra-Yu's avatar
Ezra-Yu committed
227
228
```

Ezra-Yu's avatar
Ezra-Yu committed
229
230
231
## Additional Tutorials

To learn more about using OpenCompass, explore the following tutorials:
Ezra-Yu's avatar
Ezra-Yu committed
232

Tong Gao's avatar
Tong Gao committed
233
234
235
236
237
- [Prepare Datasets](./user_guides/dataset_prepare.md)
- [Prepare Models](./user_guides/models.md)
- [Task Execution and Monitoring](./user_guides/experimentation.md)
- [Understand Prompts](./prompt/overview.md)
- [Learn about Config](./user_guides/config.md)