Failed to import transformers.pipelines
Author: Rajlaxmi
Pull request: no

### System Info

- `transformers` version: 4.42.4
- Platform: macOS-14.5-arm64-arm-64bit
- Python version: 3.12.4
- Huggingface_hub version: 0.23.4
- Safetensors version: 0.4.3
- Accelerate version: 0.32.1
- Accelerate config: 	not found
- PyTorch version (GPU?): 2.3.1 (False)
- Tensorflow version (GPU?): not installed (NA)
- Flax version (CPU?/GPU?/TPU?): not installed (NA)
- Jax version: not installed
- JaxLib version: not installed
- Using distributed or parallel set-up in script?: No



### Who can help?

@Narsil

### Information

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

### Tasks

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

### Reproduction

from transformers import pipeline

pipe = pipeline("text-generation", ...)

### Expected behavior

No issues with import. It might be failing due to using latest python version.

Comments:
Error:
```
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
File /opt/miniconda3/envs/pybase/lib/python3.12/site-packages/transformers/utils/import_utils.py:1567, in _LazyModule._get_module(self, module_name)
   [1566](https://file+.vscode-resource.vscode-cdn.net/opt/miniconda3/envs/pybase/lib/python3.12/site-packages/transformers/utils/import_utils.py:1566) try:
-> [1567](https://file+.vscode-resource.vscode-cdn.net/opt/miniconda3/envs/pybase/lib/python3.12/site-packages/transformers/utils/import_utils.py:1567)     return importlib.import_module("." + module_name, self.__name__)
   [1568](https://file+.vscode-resource.vscode-cdn.net/opt/miniconda3/envs/pybase/lib/python3.12/site-packages/transformers/utils/import_utils.py:1568) except Exception as e:

File /opt/miniconda3/envs/pybase/lib/python3.12/importlib/__init__.py:90, in import_module(name, package)
     [89](https://file+.vscode-resource.vscode-cdn.net/opt/miniconda3/envs/pybase/lib/python3.12/importlib/__init__.py:89)         level += 1
---> [90](https://file+.vscode-resource.vscode-cdn.net/opt/miniconda3/envs/pybase/lib/python3.12/importlib/__init__.py:90) return _bootstrap._gcd_import(name[level:], package, level)

File <frozen importlib._bootstrap>:1387, in _gcd_import(name, package, level)

File <frozen importlib._bootstrap>:1360, in _find_and_load(name, import_)

File <frozen importlib._bootstrap>:1331, in _find_and_load_unlocked(name, import_)

File <frozen importlib._bootstrap>:935, in _load_unlocked(spec)

File <frozen importlib._bootstrap_external>:995, in exec_module(self, module)

File <frozen importlib._bootstrap>:488, in _call_with_frames_removed(f, *args, **kwds)

File /opt/miniconda3/envs/pybase/lib/python3.12/site-packages/transformers/pipelines/__init__.py:62
     [61](https://file+.vscode-resource.vscode-cdn.net/opt/miniconda3/envs/pybase/lib/python3.12/site-packages/transformers/pipelines/__init__.py:61) from .depth_estimation import DepthEstimationPipeline
---> [62](https://file+.vscode-resource.vscode-cdn.net/opt/miniconda3/envs/pybase/lib/python3.12/site-packages/transformers/pipelines/__init__.py:62) from .document_question_answering import DocumentQuestionAnsweringPipeline
     [63](https://file+.vscode-resource.vscode-cdn.net/opt/miniconda3/envs/pybase/lib/python3.12/site-packages/transformers/pipelines/__init__.py:63) from .feature_extraction import FeatureExtractionPipeline

File /opt/miniconda3/envs/pybase/lib/python3.12/site-packages/transformers/pipelines/document_question_answering.py:29
     [28](https://file+.vscode-resource.vscode-cdn.net/opt/miniconda3/envs/pybase/lib/python3.12/site-packages/transformers/pipelines/document_question_answering.py:28) from .base import ChunkPipeline, build_pipeline_init_args
---> [29](https://file+.vscode-resource.vscode-cdn.net/opt/miniconda3/envs/pybase/lib/python3.12/site-packages/transformers/pipelines/document_question_answering.py:29) from .question_answering import select_starts_ends
     [32](https://file+.vscode-resource.vscode-cdn.net/opt/miniconda3/envs/pybase/lib/python3.12/site-packages/transformers/pipelines/document_question_answering.py:32) if is_vision_available():

File /opt/miniconda3/envs/pybase/lib/python3.12/site-packages/transformers/pipelines/question_answering.py:9
      [7](https://file+.vscode-resource.vscode-cdn.net/opt/miniconda3/envs/pybase/lib/python3.12/site-packages/transformers/pipelines/question_answering.py:7) import numpy as np
----> [9](https://file+.vscode-resource.vscode-cdn.net/opt/miniconda3/envs/pybase/lib/python3.12/site-packages/transformers/pipelines/question_answering.py:9) from ..data import SquadExample, SquadFeatures, squad_convert_examples_to_features
     [10](https://file+.vscode-resource.vscode-cdn.net/opt/miniconda3/envs/pybase/lib/python3.12/site-packages/transformers/pipelines/question_answering.py:10) from ..modelcard import ModelCard

File /opt/miniconda3/envs/pybase/lib/python3.12/site-packages/transformers/data/__init__.py:26
     [15](https://file+.vscode-resource.vscode-cdn.net/opt/miniconda3/envs/pybase/lib/python3.12/site-packages/transformers/data/__init__.py:15) from .data_collator import (
     [16](https://file+.vscode-resource.vscode-cdn.net/opt/miniconda3/envs/pybase/lib/python3.12/site-packages/transformers/data/__init__.py:16)     DataCollatorForLanguageModeling,
     [17](https://file+.vscode-resource.vscode-cdn.net/opt/miniconda3/envs/pybase/lib/python3.12/site-packages/transformers/data/__init__.py:17)     DataCollatorForPermutationLanguageModeling,
   (...)
     [24](https://file+.vscode-resource.vscode-cdn.net/opt/miniconda3/envs/pybase/lib/python3.12/site-packages/transformers/data/__init__.py:24)     default_data_collator,
     [25](https://file+.vscode-resource.vscode-cdn.net/opt/miniconda3/envs/pybase/lib/python3.12/site-packages/transformers/data/__init__.py:25) )
---> [26](https://file+.vscode-resource.vscode-cdn.net/opt/miniconda3/envs/pybase/lib/python3.12/site-packages/transformers/data/__init__.py:26) from .metrics import glue_compute_metrics, xnli_compute_metrics
     [27](https://file+.vscode-resource.vscode-cdn.net/opt/miniconda3/envs/pybase/lib/python3.12/site-packages/transformers/data/__init__.py:27) from .processors import (
     [28](https://file+.vscode-resource.vscode-cdn.net/opt/miniconda3/envs/pybase/lib/python3.12/site-packages/transformers/data/__init__.py:28)     DataProcessor,
     [29](https://file+.vscode-resource.vscode-cdn.net/opt/miniconda3/envs/pybase/lib/python3.12/site-packages/transformers/data/__init__.py:29)     InputExample,
   (...)
     [43](https://file+.vscode-resource.vscode-cdn.net/opt/miniconda3/envs/pybase/lib/python3.12/site-packages/transformers/data/__init__.py:43)     xnli_tasks_num_labels,
     [44](https://file+.vscode-resource.vscode-cdn.net/opt/miniconda3/envs/pybase/lib/python3.12/site-packages/transformers/data/__init__.py:44) )

File /opt/miniconda3/envs/pybase/lib/python3.12/site-packages/transformers/data/metrics/__init__.py:19
     [18](https://file+.vscode-resource.vscode-cdn.net/opt/miniconda3/envs/pybase/lib/python3.12/site-packages/transformers/data/metrics/__init__.py:18) if is_sklearn_available():
---> [19](https://file+.vscode-resource.vscode-cdn.net/opt/miniconda3/envs/pybase/lib/python3.12/site-packages/transformers/data/metrics/__init__.py:19)     from scipy.stats import pearsonr, spearmanr
     [20](https://file+.vscode-resource.vscode-cdn.net/opt/miniconda3/envs/pybase/lib/python3.12/site-packages/transformers/data/metrics/__init__.py:20)     from sklearn.metrics import f1_score, matthews_corrcoef

File /opt/miniconda3/lib/python3.12/site-packages/scipy/stats/__init__.py:610
    [608](https://file+.vscode-resource.vscode-cdn.net/opt/miniconda3/lib/python3.12/site-packages/scipy/stats/__init__.py:608) from ._warnings_errors import (ConstantInputWarning, NearConstantInputWarning,
    [609](https://file+.vscode-resource.vscode-cdn.net/opt/miniconda3/lib/python3.12/site-packages/scipy/stats/__init__.py:609)                                DegenerateDataWarning, FitError)
--> [610](https://file+.vscode-resource.vscode-cdn.net/opt/miniconda3/lib/python3.12/site-packages/scipy/stats/__init__.py:610) from ._stats_py import *
    [611](https://file+.vscode-resource.vscode-cdn.net/opt/miniconda3/lib/python3.12/site-packages/scipy/stats/__init__.py:611) from ._variation import variation

File /opt/miniconda3/lib/python3.12/site-packages/scipy/stats/_stats_py.py:35
     [34](https://file+.vscode-resource.vscode-cdn.net/opt/miniconda3/lib/python3.12/site-packages/scipy/stats/_stats_py.py:34) import numpy as np
---> [35](https://file+.vscode-resource.vscode-cdn.net/opt/miniconda3/lib/python3.12/site-packages/scipy/stats/_stats_py.py:35) from numpy import array, asarray, ma
     [37](https://file+.vscode-resource.vscode-cdn.net/opt/miniconda3/lib/python3.12/site-packages/scipy/stats/_stats_py.py:37) from scipy import sparse

File /opt/miniconda3/lib/python3.12/site-packages/numpy/__init__.py:343, in __getattr__(attr)

ModuleNotFoundError: No module named 'numpy.ma'

The above exception was the direct cause of the following exception:

RuntimeError                              Traceback (most recent call last)
Cell In[11], [line 5](vscode-notebook-cell:?execution_count=11&line=5)
      [2](vscode-notebook-cell:?execution_count=11&line=2) import torch
      [3](vscode-notebook-cell:?execution_count=11&line=3) import transformers
----> [5](vscode-notebook-cell:?execution_count=11&line=5) pipe = transformers.pipeline("text-generation", model="AI-MO/NuminaMath-7B-TIR", torch_dtype=torch.bfloat16, device_map="auto")
      [7](vscode-notebook-cell:?execution_count=11&line=7) messages = [
      [8](vscode-notebook-cell:?execution_count=11&line=8)     {"role": "user", "content": "For how many values of the constant $k$ will the polynomial $x^{2}+kx+36$ have two distinct integer roots?"},
      [9](vscode-notebook-cell:?execution_count=11&line=9) ]
     [10](vscode-notebook-cell:?execution_count=11&line=10) prompt = pipe.tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)

File /opt/miniconda3/envs/pybase/lib/python3.12/site-packages/transformers/utils/import_utils.py:1557, in _LazyModule.__getattr__(self, name)
   [1555](https://file+.vscode-resource.vscode-cdn.net/opt/miniconda3/envs/pybase/lib/python3.12/site-packages/transformers/utils/import_utils.py:1555)     value = self._get_module(name)
   [1556](https://file+.vscode-resource.vscode-cdn.net/opt/miniconda3/envs/pybase/lib/python3.12/site-packages/transformers/utils/import_utils.py:1556) elif name in self._class_to_module.keys():
-> [1557](https://file+.vscode-resource.vscode-cdn.net/opt/miniconda3/envs/pybase/lib/python3.12/site-packages/transformers/utils/import_utils.py:1557)     module = self._get_module(self._class_to_module[name])
   [1558](https://file+.vscode-resource.vscode-cdn.net/opt/miniconda3/envs/pybase/lib/python3.12/site-packages/transformers/utils/import_utils.py:1558)     value = getattr(module, name)
   [1559](https://file+.vscode-resource.vscode-cdn.net/opt/miniconda3/envs/pybase/lib/python3.12/site-packages/transformers/utils/import_utils.py:1559) else:

File /opt/miniconda3/envs/pybase/lib/python3.12/site-packages/transformers/utils/import_utils.py:1569, in _LazyModule._get_module(self, module_name)
   [1567](https://file+.vscode-resource.vscode-cdn.net/opt/miniconda3/envs/pybase/lib/python3.12/site-packages/transformers/utils/import_utils.py:1567)     return importlib.import_module("." + module_name, self.__name__)
   [1568](https://file+.vscode-resource.vscode-cdn.net/opt/miniconda3/envs/pybase/lib/python3.12/site-packages/transformers/utils/import_utils.py:1568) except Exception as e:
-> [1569](https://file+.vscode-resource.vscode-cdn.net/opt/miniconda3/envs/pybase/lib/python3.12/site-packages/transformers/utils/import_utils.py:1569)     raise RuntimeError(
   [1570](https://file+.vscode-resource.vscode-cdn.net/opt/miniconda3/envs/pybase/lib/python3.12/site-packages/transformers/utils/import_utils.py:1570)         f"Failed to import {self.__name__}.{module_name} because of the following error (look up to see its"
   [1571](https://file+.vscode-resource.vscode-cdn.net/opt/miniconda3/envs/pybase/lib/python3.12/site-packages/transformers/utils/import_utils.py:1571)         f" traceback):\n{e}"
   [1572](https://file+.vscode-resource.vscode-cdn.net/opt/miniconda3/envs/pybase/lib/python3.12/site-packages/transformers/utils/import_utils.py:1572)     ) from e

RuntimeError: Failed to import transformers.pipelines because of the following error (look up to see its traceback):
No module named 'numpy.ma'
```


Python library versions:
```
❯ pip list
Package                 Version
----------------------- -----------
accelerate              0.32.1
anaconda-anon-usage     0.4.4
appnope                 0.1.4
archspec                0.2.3
asttokens               2.4.1
boltons                 23.0.0
Brotli                  1.0.9
certifi                 2024.6.2
cffi                    1.16.0
charset-normalizer      2.0.4
comm                    0.2.2
conda                   24.5.0
conda-content-trust     0.2.0
conda-libmamba-solver   24.1.0
conda-package-handling  2.3.0
conda_package_streaming 0.10.0
contourpy               1.2.1
cryptography            42.0.5
cycler                  0.12.1
debugpy                 1.8.2
decorator               5.1.1
distro                  1.9.0
executing               2.0.1
filelock                3.15.4
fonttools               4.53.1
frozendict              2.4.2
fsspec                  2024.6.1
graphviz                0.20.3
huggingface-hub         0.23.4
idna                    3.7
ipykernel               6.29.5
ipython                 8.26.0
jedi                    0.19.1
Jinja2                  3.1.4
joblib                  1.4.2
jsonpatch               1.33
jsonpointer             2.1
jupyter_client          8.6.2
jupyter_core            5.7.2
kiwisolver              1.4.5
libmambapy              1.5.8
MarkupSafe              2.1.5
matplotlib              3.9.1
matplotlib-inline       0.1.7
menuinst                2.1.1
mpmath                  1.3.0
nest-asyncio            1.6.0
networkx                3.3
numpy                   1.26.4
packaging               23.2
pandas                  2.2.2
parso                   0.8.4
pexpect                 4.9.0
pillow                  10.4.0
pip                     24.0
platformdirs            3.10.0
pluggy                  1.0.0
prompt_toolkit          3.0.47
psutil                  6.0.0
ptyprocess              0.7.0
pure-eval               0.2.2
pycosat                 0.6.6
pycparser               2.21
Pygments                2.18.0
pyparsing               3.1.2
PySocks                 1.7.1
python-dateutil         2.9.0.post0
pytz                    2024.1
PyYAML                  6.0.1
pyzmq                   26.0.3
regex                   2024.5.15
requests                2.32.2
ruamel.yaml             0.17.21
ruamel.yaml.clib        0.2.8
safetensors             0.4.3
scikit-learn            1.5.1
scipy                   1.14.0
setuptools              69.5.1
six                     1.16.0
stack-data              0.6.3
sympy                   1.13.0
threadpoolctl           3.5.0
tokenizers              0.19.1
torch                   2.3.1
tornado                 6.4.1
tqdm                    4.66.4
traitlets               5.14.3
transformers            4.42.4
truststore              0.8.0
typing_extensions       4.12.2
tzdata                  2024.1
urllib3                 2.2.2
vastai                  0.2.5
wcwidth                 0.2.13
wheel                   0.43.0
zstandard               0.22.0
```


Hi @Rajlaxmi, thanks for opening an issue! 

It looks like there's a compatibility issue between the libraries in your environment, specifically numpy and scipy. 

Could you try creating a fresh env and new transformers install? I'm unable to replicate the issue with the same scipy and numpy installed versions above. 

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.