Skip to content

Commit

Permalink
GenerationConfig: warn if pad token is negative (#30187)
Browse files Browse the repository at this point in the history
* warn if pad token is negative

* Update src/transformers/generation/configuration_utils.py

Co-authored-by: amyeroberts <[email protected]>

* Update src/transformers/generation/configuration_utils.py

Co-authored-by: Joao Gante <[email protected]>

* Update src/transformers/generation/configuration_utils.py

Co-authored-by: Joao Gante <[email protected]>

---------

Co-authored-by: amyeroberts <[email protected]>
Co-authored-by: Joao Gante <[email protected]>
  • Loading branch information
3 people authored Apr 22, 2024
1 parent 8b02bb6 commit 9138935
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/transformers/generation/configuration_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
Expand Down

0 comments on commit 9138935

Please sign in to comment.