一、环境准备
1.创建并激活conda环境
conda create -n opencompass python=3.10
conda activate opencompass
2.克隆opencompass仓库
cd /root
git clone -b 0.3.3 https://github.com/open-compass/opencompass
cd opencompass
3.安装环境
pip install -e .
pip install -r requirements.txt
pip install huggingface_hub==0.25.2
pip install importlib-metadata
二、准备测评脚本
1.在线模型脚本
cd /root/opencompass/
vim opencompass/configs/models/openai/puyu_api.py
粘贴以下内容:
import os
from opencompass.models import OpenAISDK
internlm_url = 'https://internlm-chat.intern-ai.org.cn/puyu/api/v1/' # 你前面获得的 api 服务地址
internlm_api_key = os.getenv('INTERNLM_API_KEY')
models = [
dict(
# abbr='internlm2.5-latest',
type=OpenAISDK,
path='internlm2.5-latest', # 请求服务时的 model name
# 换成自己申请的APIkey
key=internlm_api_key, # API key
openai_api_base=internlm_url, # 服务地址
rpm_verbose=True, # 是否打印请求速率
query_per_second=0.16, # 服务请求速率
max_out_len=1024, # 最大输出长度
max_seq_len=4096, # 最大输入长度
temperature=0.01, # 生成温度
batch_size=1, # 批处理大小
retry=3, # 重试次数
)
]
2.数据集脚本
cd /root/opencompass/
vim opencompass/configs/datasets/demo/demo_cmmlu_chat_gen.py
粘贴以下内容:
from mmengine import read_base
with read_base():
from ..cmmlu.cmmlu_gen_c13365 import cmmlu_datasets
# 每个数据集只取前2个样本进行评测
for d in cmmlu_datasets:
d['abbr'] = 'demo_' + d['abbr']
d['reader_cfg']['test_range'] = '[0:1]' # 这里每个数据集只取1个样本, 方便快速评测.
三、开始测评
1.获取浦语在线模型的API token
打开书生·浦语
2.启动测评
export INTERNLM_API_KEY=xxxxxxxxxxxxxxxxxxxxxxx # 填入你申请的 API Key
python run.py --models puyu_api.py --datasets demo_cmmlu_chat_gen.py --debug