From 9138935784583203fb5f61e8f581cdfdcd887e0f Mon Sep 17 00:00:00 2001 From: Raushan Turganbay Date: Mon, 22 Apr 2024 15:31:38 +0500 Subject: [PATCH] GenerationConfig: warn if pad token is negative (#30187) * warn if pad token is negative * Update src/transformers/generation/configuration_utils.py Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com> * Update src/transformers/generation/configuration_utils.py Co-authored-by: Joao Gante * Update src/transformers/generation/configuration_utils.py Co-authored-by: Joao Gante --------- Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com> Co-authored-by: Joao Gante --- src/transformers/generation/configuration_utils.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/transformers/generation/configuration_utils.py b/src/transformers/generation/configuration_utils.py index f40960c213ea67..873f8bdf800d8f 100644 --- a/src/transformers/generation/configuration_utils.py +++ b/src/transformers/generation/configuration_utils.py @@ -472,6 +472,11 @@ def validate(self, is_init=False): raise ValueError(f"`early_stopping` must be a boolean or 'never', but is {self.early_stopping}.") if self.max_new_tokens is not None and self.max_new_tokens <= 0: raise ValueError(f"`max_new_tokens` must be greater than 0, but is {self.max_new_tokens}.") + if self.pad_token_id is not None and self.pad_token_id < 0: + warnings.warn( + f"`pad_token_id` should be positive but got {self.pad_token_id}. This will cause errors when batch generating, if there is padding. " + "Please set `pas_token_id` explicitly by `model.generation_config.pad_token_id=PAD_TOKEN_ID` to avoid errors in generation, and ensure your `input_ids` input does not have negative values." + ) # Validation of attribute relations: fix_location = ""