Shortcuts

Quick Start

image

Overview

OpenCompass provides a streamlined workflow for evaluating a model, which consists of the following stages: Configure -> Inference -> Evaluation -> Visualization.

Configure: This is your starting point. Here, you’ll set up the entire evaluation process, choosing the model(s) and dataset(s) to assess. You also have the option to select an evaluation strategy, the computation backend, and define how you’d like the results displayed.

Inference & Evaluation: OpenCompass efficiently manages the heavy lifting, conducting parallel inference and evaluation on your chosen model(s) and dataset(s). The Inference phase is all about producing outputs from your datasets, whereas the Evaluation phase measures how well these outputs align with the gold standard answers. While this procedure is broken down into multiple “tasks” that run concurrently for greater efficiency, be aware that working with limited computational resources might introduce some unexpected overheads, and resulting in generally slower evaluation. To understand this issue and know how to solve it, check out FAQ: Efficiency.

Visualization: Once the evaluation is done, OpenCompass collates the results into an easy-to-read table and saves them as both CSV and TXT files. If you need real-time updates, you can activate lark reporting and get immediate status reports in your Lark clients.

Coming up, we’ll walk you through the basics of OpenCompass, showcasing evaluations of pretrained models OPT-125M and OPT-350M on the SIQA and Winograd benchmark tasks. Their configuration files can be found at 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.

Configuring an Evaluation Task

In OpenCompass, each evaluation task consists of the model to be evaluated and the dataset. The entry point for evaluation is run.py. Users can select the model and dataset to be tested either via command line or configuration files.

Users can combine the models and datasets they want to test using --models and --datasets.

python run.py --models hf_opt_125m hf_opt_350m --datasets siqa_gen winograd_ppl

The models and datasets are pre-stored in the form of configuration files in configs/models and configs/datasets. Users can view or filter the currently available model and dataset configurations using tools/list_configs.py.

# List all configurations
python tools/list_configs.py
# List all configurations related to llama and mmlu
python tools/list_configs.py llama mmlu
More about list_configs

Running python tools/list_configs.py llama mmlu gives the output like:

+-----------------+-----------------------------------+
| Model           | Config Path                       |
|-----------------+-----------------------------------|
| hf_llama2_13b   | configs/models/hf_llama2_13b.py   |
| hf_llama2_70b   | configs/models/hf_llama2_70b.py   |
| ...             | ...                               |
+-----------------+-----------------------------------+
+-------------------+---------------------------------------------------+
| Dataset           | Config Path                                       |
|-------------------+---------------------------------------------------|
| cmmlu_gen         | configs/datasets/cmmlu/cmmlu_gen.py               |
| cmmlu_gen_ffe7c0  | configs/datasets/cmmlu/cmmlu_gen_ffe7c0.py        |
| ...               | ...                                               |
+-------------------+---------------------------------------------------+

Users can use the names in the first column as input parameters for --models and --datasets in python run.py. For datasets, the same name with different suffixes generally indicates that its prompts or evaluation methods are different.

Model not on the list?

If you want to evaluate other models, please check out the “Command Line (Custom HF Model)” tab for the way to construct a custom HF model without a configuration file, or “Configuration File” tab to learn the general way to prepare your model configurations.

Warning

OpenCompass usually assumes network is available. If you encounter network issues or wish to run OpenCompass in an offline environment, please refer to FAQ - Network - Q1 for solutions.

The following sections will use configuration-based method as an example to explain the other features.

Launching Evaluation

Since OpenCompass launches evaluation processes in parallel by default, we can start the evaluation in --debug mode for the first run and check if there is any problem. In --debug mode, the tasks will be executed sequentially and output will be printed in real time.

python run.py configs/eval_demo.py -w outputs/demo --debug

The pretrained models ‘facebook/opt-350m’ and ‘facebook/opt-125m’ will be automatically downloaded from HuggingFace during the first run. If everything is fine, you should see “Starting inference process” on screen:

[2023-07-12 18:23:55,076] [opencompass.openicl.icl_inferencer.icl_gen_inferencer] [INFO] Starting inference process...

Then you can press ctrl+c to interrupt the program, and run the following command in normal mode:

python run.py configs/eval_demo.py -w outputs/demo

In normal mode, the evaluation tasks will be executed parallelly in the background, and their output will be redirected to the output directory outputs/demo/{TIMESTAMP}. The progress bar on the frontend only indicates the number of completed tasks, regardless of their success or failure. Any backend task failures will only trigger a warning message in the terminal.

More parameters in run.py

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

  • -w outputs/demo: Work directory to save evaluation logs and results. In this case, the experiment result will be saved to outputs/demo/{TIMESTAMP}.

  • -r: Reuse existing inference results, and skip the finished tasks. If followed by a timestamp, the result under that timestamp in the workspace path will be reused; otherwise, the latest result in the specified workspace path will be reused.

  • --mode all: Specify a specific stage of the task.

    • all: (Default) 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.

  • --partition(-p) my_part: Slurm cluster partition.

  • --retry 2: Number of retries for failed tasks.

See also

The entry also supports submitting tasks to Alibaba Deep Learning Center (DLC), and more customized evaluation strategies. Please refer to Launching an Evaluation Task for details.

Visualizing Evaluation Results

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

dataset    version    metric    mode      opt350m    opt125m
---------  ---------  --------  ------  ---------  ---------
siqa       e78df3     accuracy  gen         21.55      12.44
winograd   b6c7ed     accuracy  ppl         51.23      49.82

All run outputs will be directed to outputs/demo/ directory with following structure:

outputs/default/
├── 20200220_120000
├── 20230220_183030     # one experiment pre folder
│   ├── configs         # Dumped config files for record. Multiple configs may be kept if different experiments have been re-run on the same experiment folder
│   ├── logs            # log files for both inference and evaluation stages
│   │   ├── eval
│   │   └── infer
│   ├── predictions   # Prediction results for each task
│   ├── results       # Evaluation results for each task
│   └── summary       # Summarized evaluation results for a single experiment
├── ...

The summarization process can be further customized in configuration and output the averaged score of some benchmarks (MMLU, C-Eval, etc.).

More information about obtaining evaluation results can be found in Results Summary.

Additional Tutorials

To learn more about using OpenCompass, explore the following tutorials:

Read the Docs v: latest
Versions
latest
stable
Downloads
epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.
@沪ICP备2021009351号-23 OpenCompass Open Platform Service Agreement