RuntimeError: Failed to import transformers.pipelines because of the following error (look up to see its traceback):
Author: KaifAhmad1
Pull request: no
Labels: name: bug

### System Info

Cuda: 12.1 
Python: 3.10.10 
OS: Windows 11x64
transformers: 4.43.2
torch: 2.4.0
torchvision: 0.19.0

### Who can help?

Hey, @ArthurZucker @amyeroberts @Narsil getting this error 

### Information

- [ ] 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

```  Python 
import kuzu
from langchain.document_loaders import WebBaseLoader
from langchain.text_splitter import CharacterTextSplitter
from langchain.vectorstores import FAISS
from langchain.embeddings import HuggingFaceEmbeddings
from langchain.llms import HuggingFacePipeline
from langchain.prompts import PromptTemplate
from langchain.chains import LLMChain
from transformers import pipeline
import networkx as nx
import plotly.graph_objects as go
import plotly.express as px
from sklearn.manifold import TSNE
import numpy as np
import pandas as pd
```

``` 
WARNING:langchain_community.utils.user_agent:USER_AGENT environment variable not set, consider setting it to identify your requests.
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
/usr/local/lib/python3.10/dist-packages/transformers/utils/import_utils.py in _get_module(self, module_name)
   1585         try:
-> 1586             return importlib.import_module("." + module_name, self.__name__)
   1587         except Exception as e:

/usr/lib/python3.10/importlib/__init__.py in import_module(name, package)
    125             level += 1
--> 126     return _bootstrap._gcd_import(name[level:], package, level)
    127 

/usr/lib/python3.10/importlib/_bootstrap.py in _gcd_import(name, package, level)

/usr/lib/python3.10/importlib/_bootstrap.py in _find_and_load(name, import_)

/usr/lib/python3.10/importlib/_bootstrap.py in _find_and_load_unlocked(name, import_)

/usr/lib/python3.10/importlib/_bootstrap.py in _load_unlocked(spec)

/usr/lib/python3.10/importlib/_bootstrap_external.py in exec_module(self, module)

/usr/lib/python3.10/importlib/_bootstrap.py in _call_with_frames_removed(f, *args, **kwds)

/usr/local/lib/python3.10/dist-packages/transformers/pipelines/__init__.py in <module>
     25 from ..feature_extraction_utils import PreTrainedFeatureExtractor
---> 26 from ..image_processing_utils import BaseImageProcessor
     27 from ..models.auto.configuration_auto import AutoConfig

/usr/local/lib/python3.10/dist-packages/transformers/image_processing_utils.py in <module>
     20 from .image_processing_base import BatchFeature, ImageProcessingMixin
---> 21 from .image_transforms import center_crop, normalize, rescale
     22 from .image_utils import ChannelDimension

/usr/local/lib/python3.10/dist-packages/transformers/image_transforms.py in <module>
     21 
---> 22 from .image_utils import (
     23     ChannelDimension,

/usr/local/lib/python3.10/dist-packages/transformers/image_utils.py in <module>
     57     if is_torchvision_available():
---> 58         from torchvision.transforms import InterpolationMode
     59 

/usr/local/lib/python3.10/dist-packages/torchvision/__init__.py in <module>
      5 import torch
----> 6 from torchvision import _meta_registrations, datasets, io, models, ops, transforms, utils
      7 

/usr/local/lib/python3.10/dist-packages/torchvision/_meta_registrations.py in <module>
    163 @torch._custom_ops.impl_abstract("torchvision::nms")
--> 164 def meta_nms(dets, scores, iou_threshold):
    165     torch._check(dets.dim() == 2, lambda: f"boxes should be a 2d tensor, got {dets.dim()}D")

/usr/local/lib/python3.10/dist-packages/torch/library.py in register(func)
    653             use_lib = lib
--> 654         use_lib._register_fake(op_name, func, _stacklevel=stacklevel + 1)
    655         return func

/usr/local/lib/python3.10/dist-packages/torch/library.py in _register_fake(self, op_name, fn, _stacklevel)
    153 
--> 154         handle = entry.abstract_impl.register(func_to_register, source)
    155         self._registration_handles.append(handle)

/usr/local/lib/python3.10/dist-packages/torch/_library/abstract_impl.py in register(self, func, source)
     30             )
---> 31         if torch._C._dispatch_has_kernel_for_dispatch_key(self.qualname, "Meta"):
     32             raise RuntimeError(

RuntimeError: operator torchvision::nms does not exist

The above exception was the direct cause of the following exception:

RuntimeError                              Traceback (most recent call last)
<ipython-input-5-f1ff51b39f19> in <cell line: 9>()
      7 from langchain.prompts import PromptTemplate
      8 from langchain.chains import LLMChain
----> 9 from transformers import pipeline
     10 import networkx as nx
     11 import plotly.graph_objects as go

/usr/lib/python3.10/importlib/_bootstrap.py in _handle_fromlist(module, fromlist, import_, recursive)

/usr/local/lib/python3.10/dist-packages/transformers/utils/import_utils.py in __getattr__(self, name)
   1574             value = self._get_module(name)
   1575         elif name in self._class_to_module.keys():
-> 1576             module = self._get_module(self._class_to_module[name])
   1577             value = getattr(module, name)
   1578         else:

/usr/local/lib/python3.10/dist-packages/transformers/utils/import_utils.py in _get_module(self, module_name)
   1586             return importlib.import_module("." + module_name, self.__name__)
   1587         except Exception as e:
-> 1588             raise RuntimeError(
   1589                 f"Failed to import {self.__name__}.{module_name} because of the following error (look up to see its"
   1590                 f" traceback):\n{e}"

RuntimeError: Failed to import transformers.pipelines because of the following error (look up to see its traceback):
operator torchvision::nms does not exist
```

### Expected behavior

Will run without any exception!

Comments:
If you have the bandwidth @qubvel it might be nice to check this!

Hi @KaifAhmad1 thanks for reporting the issue!

I was not able to reproduce this error with cuda and cpu torch 2.4.0 + torchvision 0.19.0 versions and the latest transformers 4.43.2.

The issue might be related to the mismatch between torch and torchvision versions, please refer to similar issues
https://discuss.pytorch.org/t/runtimeerror-operator-torchvision-nms-does-not-exist/192829?u=serser
https://github.com/pytorch/pytorch/issues/122494

Let me know if that helps!

Hi there, I faced the same issue. I realized it was because I was using a non-supported CUDA version for my graphics card drivers. Just mentioning it in case someone else is dumb as I am.



this versions helped me 

`Successfully installed tokenizers-0.19.1 transformers-4.43.0`

Reinstall the torch and torchvision. This will definitely work:

For CPU:
`pip install torch torchvision --index-url https://download.pytorch.org/whl/cpu`

For GPU:
`pip install torch torchvision --index-url https://download.pytorch.org/whl/cu118`