Skip to content

Commit

Permalink
Gemma special case handled
Browse files Browse the repository at this point in the history
Gemma does not support system prompts and FastChat template does not work in the current setup. Fixed by concatenating system and user prompts using double-newline and applying tokenizer's chat template.
  • Loading branch information
ShayekhBinIslam authored Aug 10, 2024
1 parent ace3efc commit be7d733
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions scripts/run_generative.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ def main():
model_modifier = "gemini"
elif "Llama-3.1" in args.model:
model_modifier = "llama-3.1"
elif "gemma" in args.model:
model_modifier = "gemma"
else:
model_modifier = None

Expand Down Expand Up @@ -277,6 +279,12 @@ def format_judgements(batch, optional_chat_template=None):
optional_chat_template.append_message(optional_chat_template.roles[0], user_prompt)
optional_chat_template.append_message(optional_chat_template.roles[1], None)
prompt = optional_chat_template.get_prompt()
elif model_modifier == "gemma":
# Gemma models don't support `system prompt`.
messages = [
{"role": "user", "content": system_prompt + "\n\n" + user_prompt},
]
prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
elif model_modifier:
messages = [
{"role": "system", "content": system_prompt},
Expand Down

0 comments on commit be7d733

Please sign in to comment.