Skip to content

Commit 1faa7f9

Browse files
🧸 Fix unset tokenizer pad_token (#3290)
Co-authored-by: Quentin Gallouédec <45557362+qgallouedec@users.noreply.github.com> Co-authored-by: Quentin Gallouédec <gallouedec.quentin@gmail.com>
1 parent 66e6eab commit 1faa7f9

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

trl/trainer/grpo_trainer.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,9 @@ def reward_func(completions, **kwargs):
330330
Dataset to use for evaluation. It must meet the same requirements as `train_dataset`.
331331
processing_class ([`~transformers.PreTrainedTokenizerBase`], *optional*, defaults to `None`):
332332
Processing class used to process the data. The padding side must be set to "left". If `None`, the
333-
processing class is loaded from the model's name with [`~transformers.AutoTokenizer.from_pretrained`].
333+
processing class is loaded from the model's name with [`~transformers.AutoTokenizer.from_pretrained`]. A
334+
padding token, `processing_class.pad_token`, must be set. If the processing class has not set a padding
335+
token, `processing_class.eos_token` will be used as the default.
334336
reward_processing_classes (`Union[PreTrainedTokenizerBase, list[PreTrainedTokenizerBase]]`, *optional*, defaults to `None`):
335337
Processing classes corresponding to the reward functions specified in `reward_funcs`. Can be either:
336338
@@ -436,6 +438,8 @@ def __init__(
436438
# Processing class
437439
if processing_class is None:
438440
processing_class = AutoTokenizer.from_pretrained(model.config._name_or_path, padding_side="left")
441+
if processing_class.pad_token is None:
442+
processing_class.pad_token = processing_class.eos_token
439443

440444
# Reward functions
441445
if not isinstance(reward_funcs, list):

0 commit comments

Comments
 (0)