Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent TextGenerationPipeline._sanitize_parameters from overriding previously provided parameters #30362

Merged
merged 3 commits into from
May 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions src/transformers/pipelines/text_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,19 +128,25 @@ def _sanitize_parameters(
prefix=None,
handle_long_generation=None,
stop_sequence=None,
add_special_tokens=False,
truncation=None,
padding=False,
max_length=None,
**generate_kwargs,
):
preprocess_params = {
"add_special_tokens": add_special_tokens,
"truncation": truncation,
"padding": padding,
"max_length": max_length,
}
preprocess_params = {}

add_special_tokens = False
if "add_special_tokens" in generate_kwargs:
preprocess_params["add_special_tokens"] = generate_kwargs["add_special_tokens"]
add_special_tokens = generate_kwargs["add_special_tokens"]

if "padding" in generate_kwargs:
preprocess_params["padding"] = generate_kwargs["padding"]

if truncation is not None:
preprocess_params["truncation"] = truncation

if max_length is not None:
preprocess_params["max_length"] = max_length
generate_kwargs["max_length"] = max_length

if prefix is not None:
Expand Down