NumPy 2.0 support
Author: lutzroeder
Pull request: no

### System Info

macOS 14.5
transformers 4.42.3
Python 3.12.4

### Who can help?

@amyeroberts @Narsil @ydshieh

### Reproduction

Is there an issue or status for tracking NumPy 2.0 support?

on macOS:

```bash
~: pip install transformers
~: pip install --upgrade numpy
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
transformers 4.42.3 requires numpy<2.0,>=1.17, but you have numpy 2.0.0 which is incompatible.
```

### Expected behavior

Transformers supports NumPy 2.0.

Comments:
There are some minor issues coming from 3rd party libraries.  One example is https://github.com/facebookresearch/faiss/issues/3526#issuecomment-2180252938.

In a pytorch only environment (without tensorflow or jax/flax), `transformers` may work well with numpy 2.0 (other than very few 3rd party lib.). Feel free to install `numpy==2.0.0` manually and see how it goes. Please let us know :-) 🙏 

Also see #31568

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.

Not able to install numpy 2 with transformers 4.44+ 

`mamba install numpy=2  transformers=4.44 -c conda-forge` raises conflict errors. I am using python 3.11

```
Could not solve for environment specs
The following packages are incompatible
├─ numpy 2**  is installable with the potential options
│  ├─ numpy [1.19.2|1.19.4|...|2.0.1] would require
│  │  └─ python >=3.9,<3.10.0a0 , which can be installed;
│  ├─ numpy [1.21.3|1.21.4|...|2.0.1] would require
│  │  └─ python >=3.10,<3.11.0a0 , which can be installed;
│  ├─ numpy [1.26.2|1.26.3|1.26.4|2.0.0|2.0.1] would require
│  │  └─ python >=3.12,<3.13.0a0 , which can be installed;
│  ├─ numpy [2.0.0rc1|2.0.0rc2] would require
│  │  └─ _numpy_rc, which does not exist (perhaps a missing channel);
│  └─ numpy [2.0.0|2.0.1], which can be installed;
└─ transformers 4.44**  is installable and it requires
   └─ numpy >=1.17,<2.0  with the potential options
      ├─ numpy [1.17.0|1.17.1|...|1.19.5] would require
      │  └─ python >=3.6,<3.7.0a0 , which can be installed;
      ├─ numpy [1.17.0|1.17.1|...|1.21.6] would require
      │  └─ python >=3.7,<3.8.0a0 , which can be installed;
      ├─ numpy [1.17.3|1.17.5|...|1.24.4] would require
      │  └─ python >=3.8,<3.9.0a0 , which can be installed;
      ├─ numpy [1.19.2|1.19.4|...|2.0.1], which can be installed (as previously explained);
      ├─ numpy [1.21.3|1.21.4|...|2.0.1], which can be installed (as previously explained);
      ├─ numpy [1.23.4|1.23.5|...|1.26.4] conflicts with any installable versions previously reported;
      ├─ numpy 1.26.0 would require
      │  └─ python >=3.12.0rc3,<3.13.0a0  with the potential options
      │     ├─ python [3.12.0|3.12.1|...|3.12.5], which can be installed;
      │     └─ python 3.12.0rc3 would require
      │        └─ _python_rc, which does not exist (perhaps a missing channel);
      ├─ numpy [1.26.2|1.26.3|1.26.4|2.0.0|2.0.1], which can be installed (as previously explained);
      └─ numpy [2.0.0rc1|2.0.0rc2], which cannot be installed (as previously explained).
```



@LiutongZhou Thanks for sharing! 

I think this issue is coming the conda-forge installation. In the traceback we see that 

```
└─ transformers 4.44**  is installable and it requires
   └─ numpy >=1.17,<2.0  with the potential options
```

However, this isn't in-line with what's in our setup.py for numpy: https://github.com/huggingface/transformers/blob/bd251e4955fee920dc770130da91b2cc802475ba/setup.py#L135



I'm currently having this issue
I currently have an env which was created with np 1.26.4 and python 3.11

Trying to update numpy results in a following trace:

```
├─ numpy 1.26.0 would require
│  │  └─ python >=3.12.0rc3,<3.13.0a0  with the potential options
│  │     ├─ python [3.12.0|3.12.1|...|3.12.5], which can be installed;
│  │     └─ python [3.12.0rc3|3.13.0rc1] would require
│  │        └─ _python_rc, which does not exist (perhaps a missing channel);
│  ├─ numpy [1.26.2|1.26.3|...|2.1.1] would require
│  │  └─ python >=3.12,<3.13.0a0 , which can be installed;
│  ├─ numpy [2.0.0rc1|2.0.0rc2|2.1.0rc1] would require
│  │  └─ _numpy_rc, which does not exist (perhaps a missing channel);
│  └─ numpy [2.1.0|2.1.1] would require
│     └─ python >=3.13.0rc1,<3.14.0a0 , which cannot be installed (as previously explained);
```
(While the error reports np 1.26, specifying any numpy version results in the same error)

```
└─ numpy 2*  is installable with the potential options
   ├─ numpy [2.0.0|2.0.1|2.0.2|2.1.0|2.1.1] would require
   │  └─ numpy-base <0a0 , which conflicts with any installable versions previously reported;
   ├─ numpy [2.0.0|2.0.1|2.0.2|2.1.0|2.1.1] would require
   │  └─ python >=3.10,<3.11.0a0 , which can be installed;
   ├─ numpy [2.0.0|2.0.1|2.0.2|2.1.0|2.1.1] would require
   │  └─ python >=3.12,<3.13.0a0 , which can be installed;
   ├─ numpy [2.0.0|2.0.1|2.0.2] would require
   │  └─ python >=3.9,<3.10.0a0 , which can be installed;
   ├─ numpy [2.0.0rc1|2.0.0rc2|2.1.0rc1] would require
   │  └─ _numpy_rc, which does not exist (perhaps a missing channel);
   └─ numpy [2.1.0|2.1.1] would require
      └─ python >=3.13.0rc1,<3.14.0a0 , which requires
         └─ _python_rc, which does not exist (perhaps a missing channel).
```

@ghylander How are you installing the packages? Are you using conda-forge?

I was, because using the anaconda channel without specifying a version would just reinstall the current version (1.26)

Then, I tried install using the anaconda channel, but specifying version 2.*, and I got a more verbose trace, which may help diagnose the issue:

```
conda install anaconda::numpy=2.*


├─ libblas is installable and it requires
│  └─ mkl 2023.2.0 h6a75c08_50497, which can be installed;
├─ numpy 2*  is installable with the potential options
│  ├─ numpy [1.23.1|1.23.3|...|2.0.0] would require
│  │  └─ python >=3.10,<3.11.0a0 , which can be installed;
│  ├─ numpy [1.23.1|1.23.3|...|2.0.0] would require
│  │  └─ python >=3.9,<3.10.0a0 , which can be installed;
│  ├─ numpy [1.26.0|1.26.2|1.26.3|1.26.4|2.0.0] would require
│  │  └─ python >=3.12,<3.13.0a0 , which can be installed;
│  └─ numpy 2.0.0, which can be installed;
└─ scipy is installable with the potential options
   ├─ scipy [1.11.1|1.11.3|...|1.13.1] would require
   │  └─ numpy [>=1.23.5,<1.28 |>=1.23.5,<1.29 ] with the potential options
   │     ├─ numpy [1.26.0|1.26.2|1.26.3|1.26.4] conflicts with any installable versions previously reported;
   │     ├─ numpy [1.23.1|1.23.3|...|2.0.0], which can be installed (as previously explained);
   │     ├─ numpy [1.23.5|1.24.3] would require
   │     │  └─ mkl >=2021.4.0,<2022.0a0 , which conflicts with any installable versions previously reported;
   │     ├─ numpy [1.23.5|1.24.3|1.25.0|1.25.2] conflicts with any installable versions previously reported;
   │     ├─ numpy [1.23.1|1.23.3|1.23.4|1.23.5|1.24.3] would require
   │     │  └─ python >=3.8,<3.9.0a0 , which can be installed;
   │     ├─ numpy [1.23.1|1.23.3|...|2.0.0], which can be installed (as previously explained);
   │     └─ numpy [1.26.0|1.26.2|1.26.3|1.26.4|2.0.0], which can be installed (as previously explained);
   ├─ scipy [0.19.1|1.0.0|...|1.2.1] would require
   │  └─ python >=2.7,<2.8.0a0 , which can be installed;
   ├─ scipy [0.19.1|1.0.0|1.0.1|1.1.0] would require
   │  └─ python >=3.5,<3.6.0a0 , which can be installed;
   ├─ scipy [0.19.1|1.0.0|...|1.5.2] would require
   │  └─ python >=3.6,<3.7.0a0 , which can be installed;
   ├─ scipy [1.1.0|1.2.0|...|1.7.3] would require
   │  └─ python >=3.7,<3.8.0a0 , which can be installed;
   ├─ scipy [1.10.0|1.10.1|...|1.9.3] would require
   │  └─ python >=3.10,<3.11.0a0 , which can be installed;
   ├─ scipy [1.10.0|1.10.1|1.9.3] would require
   │  └─ mkl >=2021.4.0,<2022.0a0 , which conflicts with any installable versions previously reported;
   ├─ scipy [1.10.0|1.10.1|...|1.9.3] would require
   │  └─ python >=3.8,<3.9.0a0 , which can be installed;
   ├─ scipy [1.10.0|1.10.1|...|1.9.3] would require
   │  └─ python >=3.9,<3.10.0a0 , which can be installed;
   ├─ scipy 1.10.1 would require
   │  └─ numpy >=1.23,<1.27.0  with the potential options
   │     ├─ numpy [1.26.0|1.26.2|1.26.3|1.26.4] conflicts with any installable versions previously reported;
   │     ├─ numpy [1.23.1|1.23.3|...|2.0.0], which can be installed (as previously explained);
   │     ├─ numpy [1.23.5|1.24.3], which cannot be installed (as previously explained);
   │     ├─ numpy [1.23.5|1.24.3|1.25.0|1.25.2] conflicts with any installable versions previously reported;
   │     ├─ numpy [1.23.1|1.23.3|1.23.4|1.23.5|1.24.3], which can be installed (as previously explained);
   │     ├─ numpy [1.23.1|1.23.3|...|2.0.0], which can be installed (as previously explained);
   │     ├─ numpy [1.26.0|1.26.2|1.26.3|1.26.4|2.0.0], which can be installed (as previously explained);
   │     ├─ numpy 1.23.3 would require
   │     │  └─ numpy-base 1.23.3 py310h04254f7_1, which does not exist (perhaps a missing channel);
   │     ├─ numpy 1.23.3 would require
   │     │  └─ numpy-base 1.23.3 py38h4da318b_1, which does not exist (perhaps a missing channel);
   │     └─ numpy 1.23.3 would require
   │        └─ numpy-base 1.23.3 py39h4da318b_1, which does not exist (perhaps a missing channel);
   ├─ scipy [1.11.3|1.12.0|1.13.0|1.13.1] would require
   │  └─ python >=3.12,<3.13.0a0 , which can be installed;
   └─ scipy 1.9.3 would require
      └─ numpy >=1.23,<1.26.0  with the potential options
         ├─ numpy [1.23.1|1.23.3|...|2.0.0], which can be installed (as previously explained);
         ├─ numpy [1.23.5|1.24.3], which cannot be installed (as previously explained);
         ├─ numpy [1.23.5|1.24.3|1.25.0|1.25.2] conflicts with any installable versions previously reported;
         ├─ numpy [1.23.1|1.23.3|1.23.4|1.23.5|1.24.3], which can be installed (as previously explained);
         ├─ numpy [1.23.1|1.23.3|...|2.0.0], which can be installed (as previously explained);
         ├─ numpy 1.23.3, which cannot be installed (as previously explained);
         ├─ numpy 1.23.3, which cannot be installed (as previously explained);
         └─ numpy 1.23.3, which cannot be installed (as previously explained).
```

@ghylander Is there a reason for using conda specifically? If all you want is to use transformers, installing with `pip` (or even better `uv pip`) should work. 

It was my understanding that one should try to install packages from conda when possible

I met the same problem with both Python 3.11 and Python 3.12 on Linux with the following `environment.yaml` file:

```yaml
# Usage: conda env create -f environment.yaml

name: MyEnv

channels:
  - defaults
  - conda-forge

dependencies:
  - python=3.12
  - transformers>=4.44.2
  - numpy>=2.0
```

The log is listed below.

![image](https://github.com/user-attachments/assets/f27e2625-5c42-48c0-9bab-9ac9f0f9253e)


Same here with minimal environment creation

```
conda create -n myenv python=3.12 
conda activate myenv
conda install numpy=2.1.1
conda install transformers
```

This is OK, but only for `transformers-4.41.2`. 

Once specify the latest version as `conda install transformers=4.44.2`, the issue appears

<img width="424" alt="image" src="https://github.com/user-attachments/assets/78c28b59-1322-42bb-af37-c4888823d6c9">


As tried in huggingface/accelerate#3027, it only works when installing the package from `pypi` with `pip install`

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.

conda / mamba install numpy>=2 with transformers>=4.44 are still not working. 

  

Pretty sure we no longer build `transformers` with conda 😅 

@ArthurZucker Thank you for your response. I think it would be better to mention this information in the [document](https://huggingface.co/docs/transformers/installation#install-with-conda).

![image](https://github.com/user-attachments/assets/04fed64c-f391-4a06-89ef-bd16d0f6ca13)



`transformers` is now built through conda-forge (instead of the hugging face channel, which I referred as we) to install it: 
`conda install conda-forge::transformers` should work!  🤗 


I was installing transformers from the `conda-forge` channel (my default channel). 

> conda / mamba install numpy>=2 with transformers>=4.44 are still not working.

To be specific, this is expected to work but fails with conflict. 
```bash
mamba create -n test python "conda-forge:transformers>=4.44" "numpy>=2" -c conda-forge
```


Same here, using conda to install `transformers`  from the `conda-forge` channel only works if I downgrade numpy to 1.26:

``` 
numpy 2.1.2-py312h58c1407_0 --> 1.26.4-py312heda63a1_0 
```

Which is compatible with the dependencies for the version of `tranformers` in `conda-forge`:  looking at `conda search transformers --info` I see

```
dependencies: 
  - datasets !=2.5.0
  - filelock
  - huggingface_hub >=0.23.0,<1.0
  - numpy >=1.17,<2.0
  - packaging >=20.0
  - python >=3.8
  - pyyaml >=5.1
  - regex !=2019.12.17
  - requests
  - safetensors >=0.4.1
  - tokenizers >=0.20,<0.21
  - tqdm >=4.27
```

which requires `numpy < 2.0`, while it should only be `numpy >= 1.17`

I submitted a [pull request](https://github.com/conda-forge/transformers-feedstock/pull/176) to `conda-forge/transformers-feedstock` and it was merged earlier today, so this should be fixed for people installing `transformers` via `conda`.

Awesome closing this then! Thanks @mbellitti