You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
In GRPO special tokens are removed if max_prompt_length is set, else not #2980
I have a question about GRPO and its implementation. This mainly concerns the special tokens.
In the GRPOTrainer, in the _generate_and_score_implementation in lines 1050 and following
def _generate_and_score_completions(
self, inputs: list[dict[str, Union[torch.Tensor, Any]]]
) -> dict[str, Union[torch.Tensor, Any]]:
device = self.accelerator.device
mode = "train" if self.model.training else "eval"
prompts = [x["prompt"] for x in inputs]
prompts_text = [maybe_apply_chat_template(example, self.processing_class)["prompt"] for example in inputs]
prompt_inputs = self.processing_class(
text=prompts_text, return_tensors="pt", padding=True, padding_side="left", add_special_tokens=False
)
prompt_inputs = super()._prepare_inputs(prompt_inputs)
prompt_ids, prompt_mask = prompt_inputs["input_ids"], prompt_inputs["attention_mask"]
if self.max_prompt_length is not None:
prompt_ids = prompt_ids[:, -self.max_prompt_length :]
prompt_mask = prompt_mask[:, -self.max_prompt_length :]
prompts_text = self.processing_class.batch_decode(
prompt_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False
)
From my understanding, the prompts_text have special tokens after the chat template is applied. However if self.max_prompt_length is not None and entering the if-statement, then we truncate the prompts to the left and return override the prompts_text, this time WITHOUT the special tokens.
I therefore believe that we should pass skip_special_tokens=False.
Activity
danielhanchen commentedon Jul 17, 2025
@fanconic You're correct - TRL had a fix in huggingface/trl@7dbf477
I'll add a fix asap
fanconic commentedon Jul 17, 2025
God, it took me an eternity and quite some sanity to figure out what was going wrong. Thank you for the quick fix :)