Allow callers to pass tokenizer_options in Text2TextGenerationPipeline#1675
Allow callers to pass tokenizer_options in Text2TextGenerationPipeline#1675Suh0161 wants to merge 1 commit into
Conversation
The tokenizer call inside _call() previously used hardcoded options with no way to override them. Now callers can pass tokenizer_options alongside generation kwargs to control things like max_length and truncation_side. tokenizer_options is extracted from generate_kwargs before model.generate() is called so it never leaks into GenerationFunctionParameters. Pipeline defaults (padding: true, truncation: true) still apply and caller values take precedence. Closes huggingface#1096.
| const tokenizer = this.tokenizer; | ||
|
|
||
| // Callers may pass tokenizer_options as a top-level key inside generate_kwargs to | ||
| // control tokenization (e.g. max_length, truncation side) without touching generation |
There was a problem hiding this comment.
The comment says callers can control truncation side, and the PR description also mentions truncation_side. That key would be passed inside tokenizer_options, but the tokenizer implementation does not appear to use it. PreTrainedTokenizer._call() only reads truncation and max_length, and truncateHelper(...) always truncates from the right by shortening the array.
So tokenizer_options: { truncation_side: 'left' } would be silently ignored.
There was a problem hiding this comment.
The public callback type still describes options only as generation parameters:
@param {Partial<import('../generation/parameters.js').GenerationFunctionParameters>} [options]If tokenizer_options remains part of the pipeline API, it should get its own typedef, similar to how TextGenerationPipeline defines text-generation-specific params.
| // the model should still run without error and return a string result. | ||
| // tokenizer_options is extracted before generate() is called so it | ||
| // never leaks into GenerationFunctionParameters. | ||
| const output = await pipe(text, { |
There was a problem hiding this comment.
This test would still pass if tokenizer_options were ignored, because it only checks that generation returns an array with a string. To protect this feature, please assert a visible effect of the tokenizer option, or spy/mock the tokenizer call and verify it receives { truncation: true, max_length: 3 } while model.generate() does not receive tokenizer_options.
Closes #1096
Feature:
tokenizer_optionspassthrough inText2TextGenerationPipelineThe tokenizer call inside
_call()previously used hardcoded options with no way to override them. Callers can now passtokenizer_optionsalongside generation kwargs to control things likemax_lengthandtruncation_side.tokenizer_optionsis extracted fromgenerate_kwargsbeforemodel.generate()is called so it never leaks intoGenerationFunctionParameters. Pipeline defaults (padding: true,truncation: true) still apply and caller values take precedence.