AnyToAnyPipeline blocks media-only inference across multiple model architectures
System Info
- Transformers:
5.24.0.dev0 - Upstream SHA:
44a7a2090208be1f8b10d3db27a430b52887365d - OS: Linux 6.18.55+ (x86_64)
- Python: 3.13.16
- PyTorch: 2.11.0+cu130 (CUDA, NVIDIA Tesla T4)
- huggingface_hub: 1.33.0
- Accelerate: 1.15.0
- Safetensors: 0.8.0
Reproduction
AnyToAnyPipeline requires text even when the underlying processor supports image-only or audio-only generation. The defect affects a shared pipeline API across multiple independent model architectures.
import numpy as np
import torch
from PIL import Image
from transformers import AutoProcessor, AutoModelForMultimodalLM
from transformers.pipelines import AnyToAnyPipeline
model_id = "tiny-random/gemma-3n"
processor = AutoProcessor.from_pretrained(model_id)
model = AutoModelForMultimodalLM.from_pretrained(
model_id, dtype=torch.float32
)
pipe = AnyToAnyPipeline(
model=model, processor=processor, task="any-to-any"
)
image = Image.new("RGB", (64, 64), "white")
audio = np.zeros(
processor.feature_extractor.sampling_rate,
dtype=np.float32,
)
pipe(images=image, max_new_tokens=1)
# TypeError: missing required positional argument: 'text'
pipe(text=None, audio=audio, max_new_tokens=1)
# ValueError: You must at least provide either text or images.
pipe({"audio": audio}, max_new_tokens=1)
# KeyError: 'text'
The Gemma3n processor accepts media-only inputs directly.
Root causes in src/transformers/pipelines/any_to_any.py:
__call__requires positionaltext.- Input validation ignores audio/video.
preprocessassumes the"text"key exists.postprocesscannot handleprompt_text=None.
Cross-Architecture Evidence
| Model | Verified media-only inference |
|---|---|
| Gemma3 | Image PASS |
| Gemma3n | Image + Audio PASS |
| Gemma4 | Image PASS |
| GOT-OCR2 | Image PASS |
| Pix2Struct | Image PASS |
| BLIP | Image PASS |
6 model implementations, 4 architecture families, 7 successful modality/model combinations.
All tests used actual tiny checkpoints rather than mocked generation.
Regression verification:
| Validation | Result |
|---|---|
| Original behavioral suite | 4/13 → 13/13 passed |
| Added regression methods | 6/6 RED upstream → GREEN patched |
| Full non-slow AnyToAnyPipeline suite | 10 passed + 8 subtests passed |
| Ruff lint / format | PASS |
git diff --check |
PASS |
Expected Behavior
AnyToAnyPipeline should accept media-only requests when supported by the underlying processor:
pipe(images=image)pipe(audio=audio)pipe(text=None, audio=audio)pipe({"audio": audio})
It should preserve input_text=None, reject completely empty requests with a clear ValueError, and retain existing text, chat, and batching behavior. Unsupported modalities should remain subject to processor validation.
Proposed fix: Make text optional, validate all four modalities, accept media-only dictionaries, and safely postprocess None prompts.
No model-specific branches or architectural refactoring are required for the verified cases.
cc @Rocketknight1 @zucchini-nlp