Support tokenization_kwargs override (#29794)

Signed-off-by: piood <2477084691@qq.com>
This commit is contained in:
Yu Jiaqi
2025-12-06 09:12:53 +00:00
committed by GitHub
parent c46b932df2
commit 43e7593031
3 changed files with 49 additions and 8 deletions
+13 -4
View File
@@ -405,6 +405,7 @@ class HfRunner:
images: PromptImageInput | None = None,
videos: PromptVideoInput | None = None,
audios: PromptAudioInput | None = None,
tokenization_kwargs: dict[str, Any] | None = None,
) -> list[BatchFeature | BatchEncoding | dict[str, torch.Tensor]]:
if images is not None:
assert len(prompts) == len(images)
@@ -418,10 +419,18 @@ class HfRunner:
all_inputs: list[BatchFeature | BatchEncoding | dict[str, torch.Tensor]] = []
for i, prompt in enumerate(prompts):
if isinstance(prompt, str):
processor_kwargs: dict[str, Any] = {
"text": prompt,
"return_tensors": "pt",
}
# Create a copy to avoid modifying the original dict
processor_kwargs = (
tokenization_kwargs.copy()
if tokenization_kwargs is not None
else {}
)
processor_kwargs.update(
{
"text": prompt,
"return_tensors": "pt",
}
)
if images is not None and (image := images[i]) is not None:
processor_kwargs["images"] = image
if videos is not None and (video := videos[i]) is not None: