Support tokenization_kwargs override (#29794)
Signed-off-by: piood <2477084691@qq.com>
This commit is contained in:
+13
-4
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user