pipeline import fails with torchvision::nms operator mismatch
Author: paytonison
Pull request: no
Labels: name: bug

### System Info
```bash
Traceback (most recent call last):
  File "/usr/local/bin/transformers", line 5, in <module>
    from transformers.commands.transformers_cli import main
  File "/usr/local/lib/python3.11/dist-packages/transformers/commands/transformers_cli.py", line 19, in <module>
    from transformers.commands.add_new_model_like import AddNewModelLikeCommand
  File "/usr/local/lib/python3.11/dist-packages/transformers/commands/add_new_model_like.py", line 26, in <module>
    from ..models.auto.image_processing_auto import IMAGE_PROCESSOR_MAPPING_NAMES
  File "/usr/local/lib/python3.11/dist-packages/transformers/models/auto/image_processing_auto.py", line 27, in <module>
    from ...image_processing_utils import ImageProcessingMixin
  File "/usr/local/lib/python3.11/dist-packages/transformers/image_processing_utils.py", line 21, in <module>
    from .image_processing_base import BatchFeature, ImageProcessingMixin
  File "/usr/local/lib/python3.11/dist-packages/transformers/image_processing_base.py", line 26, in <module>
    from .image_utils import is_valid_image, load_image
  File "/usr/local/lib/python3.11/dist-packages/transformers/image_utils.py", line 60, in <module>
    from torchvision.transforms import InterpolationMode
  File "/usr/local/lib/python3.11/dist-packages/torchvision/__init__.py", line 10, in <module>
    from torchvision import _meta_registrations, datasets, io, models, ops, transforms, utils  # usort:skip
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/torchvision/_meta_registrations.py", line 163, in <module>
    @torch.library.register_fake("torchvision::nms")
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/torch/library.py", line 1069, in register
    use_lib._register_fake(
  File "/usr/local/lib/python3.11/dist-packages/torch/library.py", line 219, in _register_fake
    handle = entry.fake_impl.register(
             ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/torch/_library/fake_impl.py", line 50, in register
    if torch._C._dispatch_has_kernel_for_dispatch_key(self.qualname, "Meta"):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: operator torchvision::nms does not exist
```
### Who can help?

@Rocketknight1 @ArthurZucker 

### Information

- [x] The official example scripts
- [x] My own modified scripts

### Tasks

- [ ] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)
- [x] My own task or dataset (give details below)

### Reproduction
```py
from transformers import pipeline

pipe = pipeline("text-generation", model="google/gemma-3-270m")
```
### Expected behavior

For text-only pipelines, transformers should not crash due to torchvision import issues. 

Either:
* Skip torchvision imports unless required (e.g., when instantiating image/audio pipelines), or
* Provide a clearer error message pointing to the Torch ↔︎ Torchvision version mismatch.

Workarounds:
* Uninstalling torchvision resolves the issue for text-only models.
* Alternatively, pinning matching torch / torchvision builds (e.g., torch==2.4.1, torchvision==0.19.1) avoids the error.

Comments:
Hi @paytonison, you're right that we should probably guard torchvision in some cases! However, errors like these are usually caused by environment incompatibilities between torch / torchvision versions, or between torchvision and CUDA.

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the [contributing guidelines](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md) are likely to be ignored.