Skip to content

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

@willxxy

Description

@willxxy

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions