torchtune icon indicating copy to clipboard operation
torchtune copied to clipboard

Add add_end_token to the Gemma Tokenizer

Open pbontrager opened this issue 1 year ago • 6 comments

Llama3 Tokenizer was updated to support add_end_token in tokenize_messages to support correct generation https://github.com/pytorch/torchtune/pull/1494. These changes need to be made for gemma.

Changes:

  • Update tokenize_message to use add_start_tokens and add_end_tokens like in https://github.com/pytorch/torchtune/pull/1494
  • Replace add_eos with add_end_tokens and update tokenize_messages as in https://github.com/pytorch/torchtune/pull/1494
  • In call update tokens, mask = self.tokenize_messages(messages) to tokens, mask = self.tokenize_messages(messages, add_end_tokens=not inference)

pbontrager avatar Mar 11 '25 20:03 pbontrager

/assign

Dev-31 avatar Jun 14 '26 18:06 Dev-31

Hey, I'll try to work on this : )

gabrielfruet avatar Jul 01 '26 18:07 gabrielfruet

I took a look and I think this is already done apparently. But we are using add_eos instead of add_end_tokens. If that's a problem I can raise an issue.

gabrielfruet avatar Jul 01 '26 19:07 gabrielfruet

Hi, I took a look and opened a PR for this: https://github.com/meta-pytorch/torchtune/pull/2969

ofeliacode avatar Jul 09 '26 13:07 ofeliacode

Hi, I'd like to work on this good first issue if it's still available.

The changes needed are clear from the Llama3 tokenizer PR #1494:

  1. Update tokenize_message to use add_start_tokens / add_end_tokens parameters
  2. Replace add_eos with add_end_tokens and update tokenize_messages accordingly
  3. In __call__, update to tokens, mask = self.tokenize_messages(messages, add_end_tokens=not inference)

Could I be assigned? I'll keep the changes consistent with the Llama3 tokenizer pattern and add tests for the inference vs. training paths.

priyanka25aug avatar Jul 26 '26 19:07 priyanka25aug

@pbontrager — I missed that @ofeliacode already has PR #2969 open for this. Withdrawing my earlier comment — I'll review the PR and leave any feedback there instead.

priyanka25aug avatar Jul 26 '26 19:07 priyanka25aug