FastChat icon indicating copy to clipboard operation
FastChat copied to clipboard

Gemma 2: Gemma template won't end with eos token

Open willxxy opened this issue 4 months ago • 0 comments

For the current gemma template, the template is such that the <end_of_turn> marks the end of each turn and the last token in the sequence. However, for Gemma 2 (Table 4), the last token should be the eos token. For a workaround, I modified conversation.py like so

if self.sep_style == SeparatorStyle.GEMMA:
  ret = "<bos>"
  for role, message in self.messages:
      if message:
          ret += "<start_of_turn>" + role + "\n" + message + self.sep
      else:
          ret += "<start_of_turn>" + role + "\n"
  if self.stop_str == "<eos>":
      ret += "<eos>"

and registering it like so:

register_conv_template(
    Conversation(
        name="gemma-2",
        roles=("user", "model"),
        sep_style=SeparatorStyle.GEMMA,
        sep="<end_of_turn>\n",
        stop_str="<eos>",
    ),
)

I hope this helps other people that run into this!

willxxy avatar Oct 02 '25 19:10 willxxy