eval_subjective_compassarena.py 3.33 KB
Newer Older
1
2
3
from os import getenv as gv
from opencompass.models import HuggingFaceCausalLM
from mmengine.config import read_base
4

5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
with read_base():
    from .datasets.subjective.compassarena.compassarena_compare import subjective_datasets

from opencompass.models import HuggingFaceCausalLM, HuggingFace, HuggingFaceChatGLM3, OpenAI
from opencompass.models.openai_api import OpenAIAllesAPIN
from opencompass.partitioners import NaivePartitioner, SizePartitioner
from opencompass.partitioners.sub_naive import SubjectiveNaivePartitioner
from opencompass.partitioners.sub_size import SubjectiveSizePartitioner
from opencompass.runners import LocalRunner
from opencompass.runners import SlurmSequentialRunner
from opencompass.tasks import OpenICLInferTask
from opencompass.tasks.subjective_eval import SubjectiveEvalTask
from opencompass.summarizers import CompassArenaSummarizer

api_meta_template = dict(
    round=[
        dict(role='HUMAN', api_role='HUMAN'),
        dict(role='BOT', api_role='BOT', generate=True),
23
24
    ],
    reserved_roles=[dict(role='SYSTEM', api_role='SYSTEM')],
25
26
)

27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# -------------Inference Stage ----------------------------------------

# For subjective evaluation, we often set do sample for models
models = [
    dict(
        type=HuggingFaceChatGLM3,
        abbr='chatglm3-6b-hf',
        path='THUDM/chatglm3-6b',
        tokenizer_path='THUDM/chatglm3-6b',
        model_kwargs=dict(
            device_map='auto',
            trust_remote_code=True,
        ),
        tokenizer_kwargs=dict(
            padding_side='left',
            truncation_side='left',
            trust_remote_code=True,
        ),
        generation_kwargs=dict(
            do_sample=True,
        ),
48
49
50
        meta_template=api_meta_template,
        max_out_len=2048,
        max_seq_len=4096,
51
52
53
54
        batch_size=1,
        run_cfg=dict(num_gpus=1, num_procs=1),
    )
]
55

56
datasets = [*subjective_datasets]
57

58
59
60
61
62
63
64
65
66
67
68
69
70
gpt4 = dict(
    abbr='gpt4-turbo',
    type=OpenAI,
    path='gpt-4-1106-preview',
    key='',  # The key will be obtained from $OPENAI_API_KEY, but you can write down your key here as well
    meta_template=api_meta_template,
    query_per_second=1,
    max_out_len=2048,
    max_seq_len=4096,
    batch_size=4,
    retry=20,
    temperature=1,
)  # Re-inference gpt4's predictions or you can choose to use the pre-commited gpt4's predictions
71

72
# -------------Evalation Stage ----------------------------------------
73

74
## ------------- JudgeLLM Configuration
75
judge_model = dict(
76
77
78
79
80
81
82
83
84
85
86
    abbr='GPT4-Turbo',
    type=OpenAI,
    path='gpt-4-1106-preview',
    key='',  # The key will be obtained from $OPENAI_API_KEY, but you can write down your key here as well
    meta_template=api_meta_template,
    query_per_second=1,
    max_out_len=1024,
    max_seq_len=4096,
    batch_size=2,
    retry=20,
    temperature=0,
87
)
bittersweet1999's avatar
bittersweet1999 committed
88

89
90
91
92
93
94
95
## ------------- Evaluation Configuration
eval = dict(
    partitioner=dict(
        type=SubjectiveSizePartitioner,
        strategy='split',
        max_task_size=10000,
        mode='m2n',
96
97
        base_models=[gpt4],
        compare_models=models,
98
99
100
101
102
103
    ),
    runner=dict(
        type=SlurmSequentialRunner,
        partition='llm_dev2',
        quotatype='auto',
        max_num_workers=32,
104
105
        task=dict(type=SubjectiveEvalTask, judge_cfg=judge_model),
    ),
106
107
)

108
work_dir = 'outputs/compass_arena_debug/'
109

110
summarizer = dict(type=CompassArenaSummarizer, summary_type='half_add')