Skip to content

Fix text-generation pipeline not forwarding tokenizer to generate - #47702

Open
alwaysprince05 wants to merge 1 commit into
huggingface:mainfrom
alwaysprince05:fix/text-generation-stop-strings-tokenizer
Open

Fix text-generation pipeline not forwarding tokenizer to generate#47702
alwaysprince05 wants to merge 1 commit into
huggingface:mainfrom
alwaysprince05:fix/text-generation-stop-strings-tokenizer

Conversation

@alwaysprince05

@alwaysprince05 alwaysprince05 commented Aug 1, 2026

Copy link
Copy Markdown

CI

What

When stop_strings is set on the pipeline's generation config, generate needs the tokenizer to decode the stop strings. The text-generation pipeline wasn't forwarding its tokenizer, so this raised a ValueError.

This adds generate_kwargs.setdefault("tokenizer", self.tokenizer) before the generate call, so the pipeline's tokenizer is forwarded while explicit user-passed tokenizers still win.

This covers the pipeline half of #34571, as suggested by @qgallouedec.

Test

Added test_stop_strings_from_generation_config, which sets stop_strings on the pipeline's generation config and checks the output stops correctly. It fails without the fix and passes with it.

make style and make fix-repo pass. The only local test failures in this file are pre-existing ones that need access to the gated google/gemma-3-270m-it model.

When stop_strings is set on the pipeline's generation config, generate
needs the tokenizer to decode the stop strings. Forward the pipeline's
tokenizer via generate_kwargs.setdefault so explicit user-passed
tokenizers still win.

Covers the pipeline half of huggingface#34571.
@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

CI recap

Dashboard: View test results in Grafana
Latest run: 30699178145:2
Result: success | Jobs: 16 | Tests: 164,078 | Failures: 0 | Duration: 16h 30m

@Rocketknight1 Rocketknight1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense, but can you check if self.tokenizer is always defined in that pipeline, and it doesn't sometimes have self.processor or something like that? I think that one always uses tokenizer, but just in case

@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants