Please support numpy 2.0
Author: MonolithFoundation
Pull request: no
Labels: name: Feature request

### Feature request

As numpy 2.0 comes out, it brings impressive speed up, please consider add numpy 2.0 support.

Besides, numpy is so foundamental, I think all libs should force to align with it rather than force users with lower numpy version/

Currently support numpy 2.0 libs:

- torch


Thoese don't:

- tensorflow
- transformers

So, please just ignore tensorflow, nowadays we don't use it any longer,

### Motivation

At least make us have an option.

### Your contribution

don't force to lower version, just keep up to date.

Comments:
cc @ydshieh 

Hi.

Our internal check indeed shows that `transformers` works (quite) well with `numpy==2.0.0` in a `torch-only` environment (with a few exception).

However, at this moment, we would prefer users to install `numpy==2.0.0` manually and see how it goes with `transformers` in their daily usage.

We are, of course, happy to remove the pin of numpy version after a period of time of waiting.

Related
#31568 
https://github.com/kyamagu/faiss-wheels/issues/104

No it's  just can not import



---- Replied Message ----
| From | ***@***.***> |
| Date | 07/05/2024 17:51 |
| To | ***@***.***> |
| Cc | ***@***.***>***@***.***> |
| Subject | Re: [huggingface/transformers] Please support numpy 2.0 (Issue #31802) |

Hi.

Our internal check indeed shows that transformers works (quite) well with numpy==2.0.0 in a torch-only environment (with a few exception).

However, at this moment, we would prefer users to install numpy==2.0.0 manually and see how it goes with transformers in their daily usage.

We are, of course, happy to remove the pin of numpy version after a period of time of waiting.

Related
#31568
kyamagu/faiss-wheels#104

—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.Message ID: ***@***.***>

@MonolithFoundation 

I don't understand well. Could you describe the situation in a bit more detail? Ideally something that we can reproduce.

I think I know the situation now. I will check 🤗 

Same here. 

"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.4 requires numpy<2.0,>=1.17, but you have numpy 2.0.0 which is incompatible."

Hi @MonolithFoundation @Fred-Wu

We now remove the pin 

https://github.com/huggingface/transformers/commit/765732e92c17a17682a5efd4aa4323e5ab01fe07

You should be able to install and use numpy 2.0 with `transformers`.

Let us know if there is any issue (other than the 3rd party libraries)


Still not working. The installation of transformers automatically uninstalls numpy 2.0, and installs numpy 1.26.4. And the error message still shows up when I try to install numpy 2.0

```
transformers 4.42.4 requires numpy<2.0,>=1.17, but you have numpy 2.0.0 which is incompatible.
```

@ydshieh You really know situation?

It's not unable to install, it's import error.

> Still not working. The installation of transformers automatically uninstalls numpy 2.0, and installs numpy 1.26.4. And the error message still shows up when I try to install numpy 2.0
> 
> ```
> transformers 4.42.4 requires numpy<2.0,>=1.17, but you have numpy 2.0.0 which is incompatible.
> ```

Hi @Fred-Wu  

Try to uninstall `numpy` then  install the dev version by `pip install -e .` (or  v4.43).
(make sure you have python >= 3.9)


(we don't propagate the changes back to  v4.42.4)

@MonolithFoundation I don't see you provide a reproduction code snippet regarding import error.
And I tried it on my own side, previously there was import error but after the above PR, it doesn't.

If you can provide more information (make sure you install with the latest dev version or v4.43, and if the issue persists), let me know.



(I think you can access to the run page below?)

If you check the `pip show numpy` step, it shows `2.0.1`.
The next step `import transformers` is passing.
 

https://app.circleci.com/pipelines/github/huggingface/transformers/99196/workflows/a3bfd102-3d0d-46dc-af50-f857568b2684/jobs/1318762

> > Still not working. The installation of transformers automatically uninstalls numpy 2.0, and installs numpy 1.26.4. And the error message still shows up when I try to install numpy 2.0
> > ```

Same issue.

Installing `numpy` 2.0 works fine.

But when I try to install `accelerate` and/or `transformers` , `numpy` gets automatically downgraded to v 1.26.4.

It seems like you need to modify your `setup.py` if you want to allow users to use `transformers` in combination with `numpy` v2.0

![image](https://github.com/user-attachments/assets/eb6fe5e7-32bb-42a7-883c-e24a49779272)


@jslegers The shared screenshot with `numpy>=1.17` will allow for higher versions of numpy to be installed. If one is installing accelerate, then numpy will be downgraded: https://github.com/huggingface/accelerate/blob/589fddd317f008e704073c133bc2cb8958f287e6/setup.py#L73

You can open an issue in accelerate to request support for numpy >= 2.0

> You can open an issue in accelerate to request support for numpy >= 2.0

No need for that, it seems.

In `accelerate 0.34.0.dev0` @ https://github.com/huggingface/accelerate, they already changed their `numpy` dependency to `numpy>=1.17,<3.0.0`

See https://github.com/huggingface/accelerate/issues/3027

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`.