Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Numpy v2.0 #21063

Closed
gnought opened this issue Jun 17, 2024 · 23 comments · Fixed by #21085
Closed

Support Numpy v2.0 #21063

gnought opened this issue Jun 17, 2024 · 23 comments · Fixed by #21085
Assignees

Comments

@gnought
Copy link

gnought commented Jun 17, 2024

Describe the issue

I am using Numpy v2.0.
onnxruntime gives an incompatible error

A module that was compiled using NumPy 1.x cannot be run in
NumPy 2.0.0 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.

Is it possible to upgrade pybind 11>=2.12 in

pybind11;https://github.com/pybind/pybind11/archive/refs/tags/v2.10.1.zip;769b6aa67a77f17a770960f604b727645b6f6a13

to

pybind11;https://github.com/pybind/pybind11/archive/refs/tags/v2.12.0.zip;8482f57ed55c7b100672815a311d5450858723fb

To reproduce

a simple python imports

import onnxruntime as ort
import numpy as np

Urgency

No response

Platform

Mac

OS Version

14.5

ONNX Runtime Installation

Released Package

ONNX Runtime Version or Commit ID

1.18.0

ONNX Runtime API

Python

Architecture

ARM64

Execution Provider

Default CPU

Execution Provider Library Version

No response

HammadB added a commit to chroma-core/chroma that referenced this issue Jun 17, 2024
## Description of changes

*Summarize the changes made by this PR.*
 - Improvements & Bug fixes
- Numpy 2.0 has some type changes which break our code. This was flagged
by @itayB in #2352 (Thank you!). We need to extend that PR a bit to
include other requirements for the thin client, as well as the
pyproject.toml.
- Note: We could fix these type issues but Onnxruntime does not yet
support python 2.0 - which we depend on
(microsoft/onnxruntime#21063)
 - New functionality
	 - None

## Test plan
*How are these changes tested?*
- [x] Tests pass locally with `pytest` for python, `yarn test` for js,
`cargo test` for rust

## Documentation Changes
We may want to update our docs? I am not sure what makes sense here -
input solicited.
@aquitzia
Copy link

I got the same error:

A module that was compiled using NumPy 1.x cannot be run in
NumPy 2.0.0 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.

The error is from this line. The compiler never evaluates the code.
from onnxruntime import InferenceSession
I'm not using numpy.

I'm running a Docker container built on an AWS Lambda image with --platform linux/amd64. I'm running it on MacOS 13.4 and requirements.txt lists:
onnxruntime>=1.18.0

I'm guessing things are being changed right now because I could not build for a while, but now it's building and I'm getting the same error.

@snnn snnn mentioned this issue Jun 17, 2024
snnn added a commit that referenced this issue Jun 18, 2024
### Description
Upgrade pybind11 to the latest as suggested by @gnought in #21063

### Motivation and Context
Recently numpy released a new version, which caused compatibility issue
between the latest numpy version and the latest ONNX Runtime version.
@gnought gnought closed this as completed Jun 18, 2024
@snnn snnn reopened this Jun 18, 2024
@snnn
Copy link
Member

snnn commented Jun 18, 2024

It is not enough. After this change we still see the error:

To support both 1.x and 2.x
versions of NumPy, modules must be compiled with NumPy 2.0

I am trying to understand the sentence. How to support NumPy 1.x while we use NumPy 2.0 at compile time? It sounds like there is a compile time macro we should use.

@snnn
Copy link
Member

snnn commented Jun 18, 2024

@mszhanyi, please help take a look

@aquitzia
Copy link

I'm also still getting the same error. Here's the stack trace:

A module that was compiled using NumPy 1.x cannot be run in
NumPy 2.0.0 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.

from onnxruntime import InferenceSession
File "/var/task/onnxruntime/__init__.py", line 23, in <module>
from onnxruntime.capi._pybind_state import ExecutionMode  # noqa: F401
File "/var/task/onnxruntime/capi/_pybind_state.py", line 32, in <module>
from .onnxruntime_pybind11_state import *  # noqa
AttributeError: _ARRAY_API not found

gyagp pushed a commit to gyagp/onnxruntime that referenced this issue Jun 18, 2024
### Description
Upgrade pybind11 to the latest as suggested by @gnought in microsoft#21063

### Motivation and Context
Recently numpy released a new version, which caused compatibility issue
between the latest numpy version and the latest ONNX Runtime version.
@snnn snnn linked a pull request Jun 18, 2024 that will close this issue
@snnn
Copy link
Member

snnn commented Jun 19, 2024

I published the new packages to our nightly feed. It would be great if you can help me do some tests.
You may install the package by running the following commands:

python -m pip install coloredlogs flatbuffers numpy packaging protobuf sympy
python -m pip install -i https://aiinfra.pkgs.visualstudio.com/PublicPackages/_packaging/ORT-Nightly/pypi/simple/ ort_nightly==1.19.0.dev20240619002

image

Please note the version number should be 1.19.0.dev20240619002

@snnn snnn assigned snnn and unassigned mszhanyi Jun 19, 2024
marovira added a commit to marovira/helios-ml that referenced this issue Jun 20, 2024
[detailed]
- This is to avoid an error coming from ONNXRuntime due to incompatible
  NumPY versions. Should be reverted once microsoft/onnxruntime#21063 is
  fixed.
@johnnynunez
Copy link

how is it going?

@snnn
Copy link
Member

snnn commented Jun 20, 2024

We are discussing whether the upcoming 1.18.1 release should be built with Numpy 2.0 or staying with numpy 1.x and mark the package as incompatible with numpy 2.0 in its requirements.txt.

@snnn
Copy link
Member

snnn commented Jun 20, 2024

I anticipate the problem will be addressed in our nightly build in a few days. There is an open PR for this: #21085

@johnnynunez
Copy link

I anticipate the problem will be addressed in our nightly build in a few days. There is an open PR for this: #21085

But if I compile it manually, is it compatible?

Anush008 pushed a commit to Anush008/chroma that referenced this issue Jun 27, 2024
…a-core#2360)

## Description of changes

*Summarize the changes made by this PR.*
 - Improvements & Bug fixes
- Numpy 2.0 has some type changes which break our code. This was flagged
by @itayB in chroma-core#2352 (Thank you!). We need to extend that PR a bit to
include other requirements for the thin client, as well as the
pyproject.toml.
- Note: We could fix these type issues but Onnxruntime does not yet
support python 2.0 - which we depend on
(microsoft/onnxruntime#21063)
 - New functionality
	 - None

## Test plan
*How are these changes tested?*
- [x] Tests pass locally with `pytest` for python, `yarn test` for js,
`cargo test` for rust

## Documentation Changes
We may want to update our docs? I am not sure what makes sense here -
input solicited.
@snnn
Copy link
Member

snnn commented Jun 28, 2024

onnxruntime 1.18.1 is published.
If you need to use it with NumPy 2.0, please get a nightly package by using the following commands:

python -m pip install coloredlogs flatbuffers numpy packaging protobuf sympy
python -m pip install -i https://aiinfra.pkgs.visualstudio.com/PublicPackages/_packaging/ORT-Nightly/pypi/simple/ ort_nightly

@snnn
Copy link
Member

snnn commented Jun 28, 2024

But if I compile it manually, is it compatible?

Yes.

@maximilian22x
Copy link

Why this problem still apear, if I use numpy in the sql server maschine Learning.

@johnnynunez
Copy link

But if I compile it manually, is it compatible?

Yes.

done! Compiled and working, thank you

@snnn
Copy link
Member

snnn commented Jun 28, 2024

Why this problem still apear, if I use numpy in the sql server maschine Learning.

If you need to use ONNX Runtime with NumPy 2.0, please get a nightly package by using the following commands:

python -m pip install coloredlogs flatbuffers numpy packaging protobuf sympy
python -m pip install -i https://aiinfra.pkgs.visualstudio.com/PublicPackages/_packaging/ORT-Nightly/pypi/simple/ ort_nightly

@maximilian22x
Copy link

I use Python and numpy inside the SQL Server. Put I got this error if I use the newest Numpy

@vlasov01
Copy link

vlasov01 commented Jul 3, 2024

Hi,
I've got the same issue. I've installed the nightly package. And now I'm getting the following error:
C:\Users\serge\anaconda3\envs\ryzenai-1.1-20240702-230249\lib\site-packages\onnxruntime\capi\onnxruntime_inference_collection.py:69: UserWarning: Specified provider 'VitisAIExecutionProvider' is not in available provider names.Available providers: 'AzureExecutionProvider, CPUExecutionProvider'

@dkbarn
Copy link

dkbarn commented Jul 5, 2024

It's a little confusing that this issue was closed as complete before the version of ONNX Runtime that supports NumPy 2.0 has actually made its way to PyPI. Currently it is only available as a nightly package. How are we to track the progress of it being released officially, and what is the expected ETA?

@johnnynunez
Copy link

It's a little confusing that this issue was closed as complete before the version of ONNX Runtime that supports NumPy 2.0 has actually made its way to PyPI. Currently it is only available as a nightly package. How are we to track the progress of it being released officially, and what is the expected ETA?

you can compile from the main using the documents on the page web

@maximilian22x
Copy link

I used this and still get the error on the sql server if i try to use Python on it.
python -m pip install coloredlogs flatbuffers numpy packaging protobuf sympy
python -m pip install -i https://aiinfra.pkgs.visualstudio.com/PublicPackages/_packaging/ORT-Nightly/pypi/simple/ ort_nightly

image

@snnn
Copy link
Member

snnn commented Jul 18, 2024

Which ONNX Runtime did you install? Can you run "python3 -m pip list | grep ^o" and give us the output?

@maximilian22x
Copy link

No it works, thanks man.

@ogencoglu
Copy link

Any updates here? Having numpy==2.0.1 and onnxruntime==1.18.1 in requirements throws a pip install error.

@joshuacwnewton
Copy link

It's a little confusing that this issue was closed as complete before the version of ONNX Runtime that supports NumPy 2.0 has actually made its way to PyPI. Currently it is only available as a nightly package. How are we to track the progress of it being released officially, and what is the expected ETA?

Any updates here? Having numpy==2.0.1 and onnxruntime==1.18.1 in requirements throws a pip install error.

I think this issue can be closed now, as onnxruntime>=1.19.0 (released August 2024) is compatible with numpy>=2.0.0.

@snnn snnn closed this as completed Oct 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants