-
Notifications
You must be signed in to change notification settings - Fork 405
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature] Support chat style inferencer.
- Loading branch information
Showing
10 changed files
with
699 additions
and
346 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
from lagent.agents.react import ReActProtocol | ||
from mmengine.config import read_base | ||
|
||
from opencompass.lagent.actions.ipython_interpreter import IPythonInterpreter | ||
from opencompass.lagent.agents.react import CIReAct | ||
from opencompass.models.lagent import CodeAgent | ||
from opencompass.models.openai_api import OpenAI | ||
from opencompass.partitioners import SizePartitioner | ||
from opencompass.runners import LocalRunner | ||
from opencompass.tasks import OpenICLInferTask | ||
|
||
with read_base(): | ||
from .datasets.CIBench.CIBench_gen_eb42f9 import \ | ||
cibench_datasets as datasets | ||
|
||
FORCE_STOP_PROMPT_EN = """You should directly give results based on history information.""" | ||
|
||
FEWSHOT_INSTRUCTION = """\ | ||
You are an assistant who can utilize external tools. | ||
{tool_description} | ||
To use a tool, please response with the following format: | ||
``` | ||
{thought} Think what you need to solve, do you need to use tools? | ||
{action} The tool name, should be one of [{action_names}]. | ||
{action_input} The input to the tool that you want to use. | ||
``` | ||
The tool will give you response after your response using the following format: | ||
``` | ||
{response} the results after call the tool. | ||
``` | ||
Therefore DO NOT generate tool response by yourself. | ||
Also please follow the guidelines: | ||
1. Always use code interpreter to solve the problem. | ||
2. The generated codes should always in a markdown code block format. | ||
3. The generated codes will be executed in an ipython manner and the results will be cached. | ||
4. Your responded code should always be simple and only solves the problem in current step. | ||
Begin! | ||
""" | ||
|
||
IPYTHON_INTERPRETER_DESCRIPTION = '''\ | ||
It can run Python code in a manner as jupyter notebook. The code must be a valid code that contains only python method.''' | ||
|
||
models = [ | ||
dict( | ||
abbr='gpt-3.5-code', | ||
type=CodeAgent, | ||
agent_type=CIReAct, | ||
max_turn=3, | ||
llm=dict( | ||
type=OpenAI, | ||
path='gpt-3.5-turbo', | ||
key='ENV', | ||
query_per_second=1, | ||
max_seq_len=4096, | ||
), | ||
actions=[ | ||
dict(type=IPythonInterpreter, | ||
description=IPYTHON_INTERPRETER_DESCRIPTION) | ||
], | ||
protocol=dict( | ||
type=ReActProtocol, | ||
call_protocol=FEWSHOT_INSTRUCTION, | ||
force_stop=FORCE_STOP_PROMPT_EN, | ||
finish=dict(role='FINISH', begin='Final Answer:', end='\n'), | ||
), | ||
batch_size=1, | ||
), | ||
] | ||
|
||
for dataset in datasets: | ||
# Evaluate on every assistant response | ||
dataset['infer_cfg']['inferencer']['infer_mode'] = 'every' | ||
|
||
infer = dict( | ||
partitioner=dict(type=SizePartitioner, max_task_size=1000), | ||
runner=dict( | ||
type=LocalRunner, | ||
max_num_workers=16, | ||
task=dict(type=OpenICLInferTask)), | ||
) |
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from mmengine.config import read_base | ||
|
||
from opencompass.models.openai_api import OpenAI | ||
from opencompass.openicl import ChatInferencer | ||
from opencompass.partitioners import SizePartitioner | ||
from opencompass.runners import LocalRunner | ||
from opencompass.tasks import OpenICLInferTask | ||
|
||
with read_base(): | ||
from .datasets.gsm8k.gsm8k_gen_1d7fe4 import gsm8k_datasets as datasets | ||
|
||
models = [ | ||
dict( | ||
abbr='gpt-3.5', | ||
type=OpenAI, | ||
path='gpt-3.5-turbo', | ||
key='ENV', | ||
max_out_len=100, | ||
max_seq_len=2048, | ||
batch_size=16, | ||
run_cfg=dict(num_gpus=1, num_procs=1), | ||
) | ||
] | ||
|
||
for dataset in datasets: | ||
# Use ChatInferencer instead of GenInferencer | ||
dataset['infer_cfg']['inferencer'] = dict(type=ChatInferencer) | ||
|
||
infer = dict( | ||
partitioner=dict(type=SizePartitioner, max_task_size=1000), | ||
runner=dict( | ||
type=LocalRunner, | ||
max_num_workers=16, | ||
task=dict(type=OpenICLInferTask)), | ||
) |
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
Oops, something went wrong.