Fix batch-dependent text output in image-text-to-text and any-to-any pipelines (#51073)
Left-pad decoder-only models in image-text-to-text and any-to-any pipelines
The tokenizers of several vision-language checkpoints pad on the right by
default. With batch_size > 1 the shorter prompt then got right padding
before generation, and its output differed from a single call. When the
pipeline is created, switch a right-padding tokenizer to left padding, as
the text-generation pipeline already does since #44021. This changes the
tokenizer object the caller passed in.
Encoder-decoder models keep their padding, and so do processors with
another component that sets its own padding side (feature extractor, image
or audio processor, or the Q-Former tokenizer of InstructBLIP), because the
collator pads all inputs on one side.
Left padding in the collator sliced with -len(row), which is -0 for an empty
prompt and selected the whole row. Slice from max_length - len(row) instead.
Assisted-by: Claude Opus 5.5 <noreply@anthropic.com>