Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Add api_prompts to GenInferencerOutput #1314

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

xu-song
Copy link
Contributor

@xu-song xu-song commented Jul 12, 2024

Motivation

api_prompts is a list of prompts in opencompass.

def _prompt2api(self,
prompts: Union[List, str],
role_dict: Dict[str, Dict],
for_gen: bool = False) -> Tuple[str, bool]:
"""Convert the prompts to a API-style prompts, given an updated

However, the prediction files confused api_prompts with raw_prompt.

Modification

Before PR:
Here is a prediction example, predictions/ceval-college_physics.json

{
    "0": {
        "origin_prompt": [
            {
                "role": "HUMAN",
                "prompt": "以下是中国关于大学物理考试的单项选择题,请选出其中的正确答案。\n有一劲度系数为k的轻弹簧,竖直放置,下端悬一质量为m的小球,开始时使弹簧为原长而小球恰好与地接触,今将弹簧上端缓慢地>提起,直到小球刚能脱离地面为止,在此过程中外力作功为____\nA. m^2g^2/(4k)\nB. m^2g^2/(3k)\nC. m^2g^2/(2k)\nD. 2m^2g^2/k\n答案: \n"
            },
            {
                "role": "BOT",
                "prompt": "C"
            },
            {
                "role": "HUMAN",
                "prompt": "以下是中国关于大学物理考试的单项选择题,请选出其中的正确答案。\nα粒子在加速器中被加速,当其质量为静止质量的 3 倍时,其动能为静止能量的____\nA. 2倍\nB. 3倍\nC. 4倍\nD. 5倍\n答案: \n"
            }
        ],
        "prediction": "D",
        "gold": "A"
    },
...

The above details fail to reflect SYSTEM role and special tokens, which are very important for prediction and evaluation.

After PR:
The prediction is like this

{
    "0": {

        ### api_prompts is a list of api-style prompt
        "api_prompts": [
            {
                "role": "HUMAN",
                "prompt": "以下是中国关于大学物理考试的单项选择题,请选出其中的正确答案。\n有一劲度系数为k的轻弹簧,竖直放置,下端悬一质量为m的小球,开始时使弹簧为原长而小球恰好与地接触,今将弹簧上端缓慢地>提起,直到小球刚能脱离地面为止,在此过程中外力作功为____\nA. m^2g^2/(4k)\nB. m^2g^2/(3k)\nC. m^2g^2/(2k)\nD. 2m^2g^2/k\n答案: \n"
            },
            {
                "role": "BOT",
                "prompt": "C"
            },
            {
                "role": "HUMAN",
                "prompt": "以下是中国关于大学物理考试的单项选择题,请选出其中的正确答案。\nα粒子在加速器中被加速,当其质量为静止质量的 3 倍时,其动能为静止能量的____\nA. 2倍\nB. 3倍\nC. 4倍\nD. 5倍\n答案: \n"
            }
        ],

        ### origin_prompt is the final input string of model
        "origin_prompt": "<|im_start|>system\nYou are a helpful assistant<|im_end|>\n<|im_start|>user\n以下是中国关于大学物理考试的单项选择题,请选出其中的正确答案。\n有一劲度系数为k的轻弹簧,竖直放置,下端悬一质量为m的小球,开始时使弹簧为原长而小球恰好与地接触,今将弹簧上端缓慢地提起,直到小球刚能脱离地面为止,在此过程中外力作功为____\nA. m^2g^2/(4k)\nB. m^2g^2/(3k)\nC. m^2g^2/(2k)\nD. 2m^2g^2/k\n答案:\n<|im_end|>\n<|im_start|>assistant\nC<|im_end|>\n<|im_start|>user\n以下是中国关于大学物理考试的单项选择题,请选出其中的正确答案。\nα粒子在加速器中被加速,当其质量为静止质量的 3 倍时,其动能为静止能量的____\nA. 2倍\nB. 3倍\nC. 4倍\nD. 5倍\n答案: \n<|im_end|>\n<|im_start|>assistant\n",
        "prediction": "D",
        "gold": "A"
    },
...

Prompt with SYSTEM role and special tokens is helpful for debugging.
According to above origin_prompt, you can easily determine whether the configuration file is correct.

To Reproduce

You can reproduce with any task using VLLMwithChatTemplate or HuggingFacewithChatTemplate

@xu-song xu-song changed the title Add api_prompts to GenInferencerOutput [FEATURE] Add api_prompts to GenInferencerOutput Jul 16, 2024
@xu-song xu-song changed the title [FEATURE] Add api_prompts to GenInferencerOutput [Feature] Add api_prompts to GenInferencerOutput Jul 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants