forked from LLM-Dev-Open/opencompass_base
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add en docs * update --------- Co-authored-by: gaotongxiao <[email protected]>
- Loading branch information
1 parent
07dfe8c
commit 7f8eee4
Showing
15 changed files
with
193 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,10 +40,8 @@ OpenCompass 是面向大模型评测的一站式平台。其主要特点如下 | |
|
||
我们将陆续提供开源模型和API模型的具体性能榜单,请见 [OpenCompass Leaderbaord](https://opencompass.org.cn/rank) 。如需加入评测,请提供模型仓库地址或标准的 API 接口至邮箱 `[email protected]`. | ||
|
||
|
||
![image](https://github.com/InternLM/OpenCompass/assets/7881589/fddc8ab4-d2bd-429d-89f0-4ca90606599a) | ||
|
||
|
||
## 数据集支持 | ||
|
||
<table align="center"> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,57 @@ | ||
# New Dataset | ||
# Add a dataset | ||
|
||
Coming soon. | ||
Although OpenCompass has already included most commonly used datasets, users need to follow the steps below to support a new dataset if wanted: | ||
|
||
1. Add a dataset script `mydataset.py` to the `opencompass/datasets` folder. This script should include: | ||
|
||
- The dataset and its loading method. Define a `MyDataset` class that implements the data loading method `load` as a static method. This method should return data of type `datasets.Dataset`. We use the Hugging Face dataset as the unified interface for datasets to avoid introducing additional logic. Here's an example: | ||
|
||
```python | ||
import datasets | ||
from .base import BaseDataset | ||
|
||
class MyDataset(BaseDataset): | ||
|
||
@staticmethod | ||
def load(**kwargs) -> datasets.Dataset: | ||
pass | ||
``` | ||
|
||
- (Optional) If the existing evaluators in OpenCompass do not meet your needs, you need to define a `MyDatasetEvaluator` class that implements the scoring method `score`. This method should take `predictions` and `references` as input and return the desired dictionary. Since a dataset may have multiple metrics, the method should return a dictionary containing the metrics and their corresponding scores. Here's an example: | ||
|
||
```python | ||
from opencompass.openicl.icl_evaluator import BaseEvaluator | ||
|
||
class MyDatasetEvaluator(BaseEvaluator): | ||
|
||
def score(self, predictions: List, references: List) -> dict: | ||
pass | ||
``` | ||
|
||
- (Optional) If the existing postprocessors in OpenCompass do not meet your needs, you need to define the `mydataset_postprocess` method. This method takes an input string and returns the corresponding postprocessed result string. Here's an example: | ||
|
||
```python | ||
def mydataset_postprocess(text: str) -> str: | ||
pass | ||
``` | ||
|
||
2. After defining the dataset loading, data postprocessing, and evaluator methods, you need to add the following configurations to the configuration file: | ||
|
||
```python | ||
from opencompass.datasets import MyDataset, MyDatasetEvaluator, mydataset_postprocess | ||
|
||
mydataset_eval_cfg = dict( | ||
evaluator=dict(type=MyDatasetEvaluator), | ||
pred_postprocessor=dict(type=mydataset_postprocess)) | ||
|
||
mydataset_datasets = [ | ||
dict( | ||
type=MyDataset, | ||
..., | ||
reader_cfg=..., | ||
infer_cfg=..., | ||
eval_cfg=mydataset_eval_cfg) | ||
] | ||
``` | ||
|
||
Once the dataset is configured, you can refer to the instructions on [Get started](../get_started.md) for other requirements. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,73 @@ | ||
# New A Model | ||
# Add a Model | ||
|
||
Coming soon. | ||
Currently, we support HF models, some model APIs, and some third-party models. | ||
|
||
## Adding API Models | ||
|
||
To add a new API-based model, you need to create a new file named `mymodel_api.py` under `opencompass/models` directory. In this file, you should inherit from `BaseAPIModel` and implement the `generate` method for inference and the `get_token_len` method to calculate the length of tokens. Once you have defined the model, you can modify the corresponding configuration file. | ||
|
||
```python | ||
from ..base_api import BaseAPIModel | ||
|
||
class MyModelAPI(BaseAPIModel): | ||
|
||
is_api: bool = True | ||
|
||
def __init__(self, | ||
path: str, | ||
max_seq_len: int = 2048, | ||
query_per_second: int = 1, | ||
retry: int = 2, | ||
**kwargs): | ||
super().__init__(path=path, | ||
max_seq_len=max_seq_len, | ||
meta_template=meta_template, | ||
query_per_second=query_per_second, | ||
retry=retry) | ||
... | ||
|
||
def generate( | ||
self, | ||
inputs, | ||
max_out_len: int = 512, | ||
temperature: float = 0.7, | ||
) -> List[str]: | ||
"""Generate results given a list of inputs.""" | ||
pass | ||
|
||
def get_token_len(self, prompt: str) -> int: | ||
"""Get lengths of the tokenized string.""" | ||
pass | ||
``` | ||
|
||
## Adding Third-Party Models | ||
|
||
To add a new third-party model, you need to create a new file named `mymodel.py` under `opencompass/models` directory. In this file, you should inherit from `BaseModel` and implement the `generate` method for generative inference, the `get_ppl` method for discriminative inference, and the `get_token_len` method to calculate the length of tokens. Once you have defined the model, you can modify the corresponding configuration file. | ||
|
||
```python | ||
from ..base import BaseModel | ||
|
||
class MyModel(BaseModel): | ||
|
||
def __init__(self, | ||
pkg_root: str, | ||
ckpt_path: str, | ||
tokenizer_only: bool = False, | ||
meta_template: Optional[Dict] = None, | ||
**kwargs): | ||
... | ||
|
||
def get_token_len(self, prompt: str) -> int: | ||
"""Get lengths of the tokenized strings.""" | ||
pass | ||
|
||
def generate(self, inputs: List[str], max_out_len: int) -> List[str]: | ||
"""Generate results given a list of inputs. """ | ||
pass | ||
|
||
def get_ppl(self, | ||
inputs: List[str], | ||
mask_length: Optional[List[int]] = None) -> List[float]: | ||
"""Get perplexity scores given a list of inputs.""" | ||
pass | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,4 +79,4 @@ Indexes & Tables | |
================== | ||
|
||
* :ref:`genindex` | ||
* :ref:`search` | ||
* :ref:`search` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# 支持新模型 | ||
|
||
目前我们已经支持的模型有 HF 模型、部分模型 API 、自建模型和部分第三方模型。 | ||
目前我们已经支持的模型有 HF 模型、部分模型 API 、部分第三方模型。 | ||
|
||
## 新增API模型 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,4 +79,4 @@ OpenCompass 上手路线 | |
================== | ||
|
||
* :ref:`genindex` | ||
* :ref:`search` | ||
* :ref:`search` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# Prompt 模板 | ||
|
||
Coming soon. | ||
Coming soon. |
Oops, something went wrong.