Models numpy version and version installed after running `pip install transformers[sentencepiece]`
Author: vpapaioannou
Pull request: no
Labels: name: bug

### System Info

MacOs Sequoia 15.0.1, Python 3.10

```
Package                   Version
------------------------- --------------
accelerate                1.2.0
aiohappyeyeballs          2.4.4
aiohttp                   3.11.9
aiosignal                 1.3.1
anyio                     4.6.2.post1
appnope                   0.1.4
argon2-cffi               23.1.0
argon2-cffi-bindings      21.2.0
arrow                     1.3.0
asttokens                 3.0.0
async-lru                 2.0.4
async-timeout             5.0.1
attrs                     24.2.0
babel                     2.16.0
beautifulsoup4            4.12.3
bleach                    6.2.0
certifi                   2024.8.30
cffi                      1.17.1
charset-normalizer        3.4.0
comm                      0.2.2
datasets                  3.1.0
debugpy                   1.8.9
decorator                 5.1.1
defusedxml                0.7.1
dill                      0.3.8
evaluate                  0.4.3
exceptiongroup            1.2.2
executing                 2.1.0
fastjsonschema            2.21.1
filelock                  3.16.1
fqdn                      1.5.1
frozenlist                1.5.0
fsspec                    2024.9.0
h11                       0.14.0
httpcore                  1.0.7
httpx                     0.28.0
huggingface-hub           0.26.3
idna                      3.10
ipykernel                 6.29.5
ipython                   8.30.0
ipywidgets                8.1.5
isoduration               20.11.0
jedi                      0.19.2
Jinja2                    3.1.4
json5                     0.10.0
jsonpointer               3.0.0
jsonschema                4.23.0
jsonschema-specifications 2024.10.1
jupyter                   1.1.1
jupyter_client            8.6.3
jupyter-console           6.6.3
jupyter_core              5.7.2
jupyter-events            0.10.0
jupyter-lsp               2.2.5
jupyter_server            2.14.2
jupyter_server_terminals  0.5.3
jupyterlab                4.3.2
jupyterlab_pygments       0.3.0
jupyterlab_server         2.27.3
jupyterlab_widgets        3.0.13
MarkupSafe                3.0.2
matplotlib-inline         0.1.7
mistune                   3.0.2
mpmath                    1.3.0
multidict                 6.1.0
multiprocess              0.70.16
nbclient                  0.10.1
nbconvert                 7.16.4
nbformat                  5.10.4
nest-asyncio              1.6.0
networkx                  3.4.2
notebook                  7.3.0
notebook_shim             0.2.4
numpy                     2.1.3
overrides                 7.7.0
packaging                 24.2
pandas                    2.2.3
pandocfilters             1.5.1
parso                     0.8.4
pexpect                   4.9.0
pillow                    11.0.0
pip                       24.2
platformdirs              4.3.6
prometheus_client         0.21.1
prompt_toolkit            3.0.48
propcache                 0.2.1
protobuf                  5.29.0
psutil                    6.1.0
ptyprocess                0.7.0
pure_eval                 0.2.3
pyarrow                   18.1.0
pycparser                 2.22
Pygments                  2.18.0
python-dateutil           2.9.0.post0
python-json-logger        2.0.7
pytz                      2024.2
PyYAML                    6.0.2
pyzmq                     26.2.0
referencing               0.35.1
regex                     2024.11.6
requests                  2.32.3
rfc3339-validator         0.1.4
rfc3986-validator         0.1.1
rpds-py                   0.22.3
safetensors               0.4.5
Send2Trash                1.8.3
sentencepiece             0.2.0
setuptools                75.1.0
six                       1.16.0
sniffio                   1.3.1
soupsieve                 2.6
stack-data                0.6.3
sympy                     1.13.3
terminado                 0.18.1
tinycss2                  1.4.0
tokenizers                0.20.3
tomli                     2.2.1
torch                     2.2.2
torchvision               0.17.2
tornado                   6.4.2
tqdm                      4.67.1
traitlets                 5.14.3
transformers              4.46.3
types-python-dateutil     2.9.0.20241003
typing_extensions         4.12.2
tzdata                    2024.2
uri-template              1.3.0
urllib3                   2.2.3
wcwidth                   0.2.13
webcolors                 24.11.1
webencodings              0.5.1
websocket-client          1.8.0
wheel                     0.44.0
widgetsnbextension        4.0.13
xxhash                    3.5.0
yarl                      1.18.3
```

### Who can help?

_No response_

### 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 https://huggingface.co/learn/nlp-course/chapter3/3#training I run this code,

```
from transformers import AutoModelForSequenceClassification

model = AutoModelForSequenceClassification.from_pretrained(checkpoint, num_labels=2)
```

This is the output

```

A module that was compiled using NumPy 1.x cannot be run in
NumPy 2.1.3 as it may crash. To support both 1.x and 2.x
versions of NumPy, modules must be compiled with NumPy 2.0.
Some module may need to rebuild instead e.g. with 'pybind11>=2.12'.

If you are a user of the module, the easiest solution will be to
downgrade to 'numpy<2' or try to upgrade the affected module.
We expect that some modules will need time to support NumPy 2.

Traceback (most recent call last):  File "/Users/bill/anaconda3/envs/py10hugface/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/Users/bill/anaconda3/envs/py10hugface/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/Users/bill/anaconda3/envs/py10hugface/lib/python3.10/site-packages/ipykernel_launcher.py", line 18, in <module>
    app.launch_new_instance()
  File "/Users/bill/anaconda3/envs/py10hugface/lib/python3.10/site-packages/traitlets/config/application.py", line 1075, in launch_instance
    app.start()
  File "/Users/bill/anaconda3/envs/py10hugface/lib/python3.10/site-packages/ipykernel/kernelapp.py", line 739, in start
    self.io_loop.start()
  File "/Users/bill/anaconda3/envs/py10hugface/lib/python3.10/site-packages/tornado/platform/asyncio.py", line 205, in start
    self.asyncio_loop.run_forever()
  File "/Users/bill/anaconda3/envs/py10hugface/lib/python3.10/asyncio/base_events.py", line 603, in run_forever
    self._run_once()
  File "/Users/bill/anaconda3/envs/py10hugface/lib/python3.10/asyncio/base_events.py", line 1909, in _run_once
    handle._run()
  File "/Users/bill/anaconda3/envs/py10hugface/lib/python3.10/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/Users/bill/anaconda3/envs/py10hugface/lib/python3.10/site-packages/ipykernel/kernelbase.py", line 545, in dispatch_queue
    await self.process_one()
  File "/Users/bill/anaconda3/envs/py10hugface/lib/python3.10/site-packages/ipykernel/kernelbase.py", line 534, in process_one
    await dispatch(*args)
  File "/Users/bill/anaconda3/envs/py10hugface/lib/python3.10/site-packages/ipykernel/kernelbase.py", line 437, in dispatch_shell
    await result
  File "/Users/bill/anaconda3/envs/py10hugface/lib/python3.10/site-packages/ipykernel/ipkernel.py", line 362, in execute_request
    await super().execute_request(stream, ident, parent)
  File "/Users/bill/anaconda3/envs/py10hugface/lib/python3.10/site-packages/ipykernel/kernelbase.py", line 778, in execute_request
    reply_content = await reply_content
  File "/Users/bill/anaconda3/envs/py10hugface/lib/python3.10/site-packages/ipykernel/ipkernel.py", line 449, in do_execute
    res = shell.run_cell(
  File "/Users/bill/anaconda3/envs/py10hugface/lib/python3.10/site-packages/ipykernel/zmqshell.py", line 549, in run_cell
    return super().run_cell(*args, **kwargs)
  File "/Users/bill/anaconda3/envs/py10hugface/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 3075, in run_cell
    result = self._run_cell(
  File "/Users/bill/anaconda3/envs/py10hugface/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 3130, in _run_cell
    result = runner(coro)
  File "/Users/bill/anaconda3/envs/py10hugface/lib/python3.10/site-packages/IPython/core/async_helpers.py", line 128, in _pseudo_sync_runner
    coro.send(None)
  File "/Users/bill/anaconda3/envs/py10hugface/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 3334, in run_cell_async
    has_raised = await self.run_ast_nodes(code_ast.body, cell_name,
  File "/Users/bill/anaconda3/envs/py10hugface/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 3517, in run_ast_nodes
    if await self.run_code(code, result, async_=asy):
  File "/Users/bill/anaconda3/envs/py10hugface/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 3577, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "/var/folders/pf/m0zg4n_x68b83v_2xzrpj1380000gn/T/ipykernel_29244/165625158.py", line 2, in <module>
    from transformers import AutoTokenizer, DataCollatorWithPadding
  File "/Users/bill/anaconda3/envs/py10hugface/lib/python3.10/site-packages/transformers/__init__.py", line 26, in <module>
    from . import dependency_versions_check
  File "/Users/bill/anaconda3/envs/py10hugface/lib/python3.10/site-packages/transformers/dependency_versions_check.py", line 16, in <module>
    from .utils.versions import require_version, require_version_core
  File "/Users/bill/anaconda3/envs/py10hugface/lib/python3.10/site-packages/transformers/utils/__init__.py", line 27, in <module>
    from .chat_template_utils import DocstringParsingException, TypeHintParsingException, get_json_schema
  File "/Users/bill/anaconda3/envs/py10hugface/lib/python3.10/site-packages/transformers/utils/chat_template_utils.py", line 39, in <module>
    from torch import Tensor
  File "/Users/bill/anaconda3/envs/py10hugface/lib/python3.10/site-packages/torch/__init__.py", line 1477, in <module>
    from .functional import *  # noqa: F403
  File "/Users/bill/anaconda3/envs/py10hugface/lib/python3.10/site-packages/torch/functional.py", line 9, in <module>
    import torch.nn.functional as F
  File "/Users/bill/anaconda3/envs/py10hugface/lib/python3.10/site-packages/torch/nn/__init__.py", line 1, in <module>
    from .modules import *  # noqa: F403
  File "/Users/bill/anaconda3/envs/py10hugface/lib/python3.10/site-packages/torch/nn/modules/__init__.py", line 35, in <module>
    from .transformer import TransformerEncoder, TransformerDecoder, \
  File "/Users/bill/anaconda3/envs/py10hugface/lib/python3.10/site-packages/torch/nn/modules/transformer.py", line 20, in <module>
    device: torch.device = torch.device(torch._C._get_default_device()),  # torch.device('cpu'),
/Users/bill/anaconda3/envs/py10hugface/lib/python3.10/site-packages/torch/nn/modules/transformer.py:20: UserWarning: Failed to initialize NumPy: _ARRAY_API not found (Triggered internally at /Users/runner/work/pytorch/pytorch/pytorch/torch/csrc/utils/tensor_numpy.cpp:84.)
  device: torch.device = torch.device(torch._C._get_default_device()),  # torch.device('cpu'),
```
If I run the code again, the error doesn't show up again.
I have seen this earlier in the hugging face class, but instead of burying I wanted to let you know. I am not sure if it is a bug, but it would be user friendly to have a requirements.txt file with all necessary packages and version so there is no issue alike.

### Expected behavior

I would expect not to see the error. If I see the error I would like to be given step-by-step instructions how to resolve it.

Comments:
Hi @vpapaioannou, this is an environment issue that is caused by some libraries compiling using the existing version of `numpy`, and then upgrading `numpy`. The transition to Numpy 2.x broke compatibility in these cases.

The simplest solution is to make a new environment, and you should stop seeing these errors! I don't think it's really related to `transformers`, because the issue isn't specific package versions, it's **what version of Numpy you had when those packages were built and installed**. Closing for now, but feel free to reopen if you think there's anything we can change in `transformers`!