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

Add auto_insert_empty_system_msg config flag #123

Merged
merged 6 commits into from
Feb 28, 2024
Merged

Add auto_insert_empty_system_msg config flag #123

merged 6 commits into from
Feb 28, 2024

Conversation

BramVanroy
Copy link
Contributor

@BramVanroy BramVanroy commented Feb 22, 2024

Currently there is functionality to automatically insert an empty system message if system occur in the Jinja template.

def maybe_insert_system_message(messages, tokenizer):
if messages[0]["role"] == "system":
return
# chat template can be one of two attributes, we check in order
chat_template = tokenizer.chat_template
if chat_template is None:
chat_template = tokenizer.default_chat_template
# confirm the jinja template refers to a system message before inserting
if "system" in chat_template:
messages.insert(0, {"role": "system", "content": ""})

This is not foolproof method: GEMMA (SFT) for instance has an explicit part in its chat template that says that if the role is "system" that an error must be raised. So this leads to a conflict with the alignment handbook. Therefore I suggest giving all control to the user but doing so in a backwards-compatible manner: by adding a flag that, if True, adds the system message with the same behavior as before, and when False no system message will be added. To this end, auto_insert_empty_system_msg is added as a DataArguments argument (defaulting to True).

Note that there is one small breaking change: the maybe_insert_system_message is currently implemented only for sft, generation and rm, but it was not used for dpo. There, a system message was ALWAYS added if the first message was not system, even if the Jinja template did not mention system. I changed that to be in line with the other tasks so the default behavior will be a litttle bit different when a tokenizer's chat template does not contain 'system' in DPO.

Copy link
Member

@lewtun lewtun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix, this LGTM! I think the small issue about DPO not being 100% consistent with the previous behaviour is fine for now

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@lewtun lewtun merged commit d17fd7c into huggingface:main Feb 28, 2024
3 checks passed
@WeitaoLu
Copy link

WeitaoLu commented Mar 9, 2024

A small bug solution, if you encounter AttributeError: 'DataArguments' object has no attribute 'auto_insert_empty_system_msg'
when running dpo , you can commit line 99 in run_dpo.py to disable this flag
#"auto_insert_empty_system_msg": data_args.auto_insert_empty_system_msg,

@BramVanroy
Copy link
Contributor Author

A small bug solution, if you encounter AttributeError: 'DataArguments' object has no attribute 'auto_insert_empty_system_msg' when running dpo , you can commit line 99 in run_dpo.py to disable this flag #"auto_insert_empty_system_msg": data_args.auto_insert_empty_system_msg,

If you get the attribute error you'll likely just need to update the repo to the newer version.

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.

4 participants