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
Upgrade numpy version to 1.20+ #1827
Comments
Thanks for looking into this @leopsidom!
Yeah, if you do manage to update any of these a PR is quite welcome. See also: |
I'd be glad to take a look. But I have minimum knowledge of numpy source code and emscrypten, so not sure how I should estimate the effort. |
Just to add some update, I did some bisect analysis on different numpy versions. The latest numpy that can build is 1.18.5. Since 1.19.0, we had some issues. For 1.20+ build, I'm currently getting this issue:
I think it has something to do with numpy adding support for avx512 architecture since 1.19.0: numpy/numpy@5562a8c but not sure how to resolve it yet. I cut an issue to numpy here: numpy/numpy#19892 |
Adding a +1 for updating the There are several nice new features in v1.2 and v1.3 (including table visualizations and exporting to LaTeX). |
Pandas was updated in #1922: just bumping the version worked . The numpy update is indeed a bit more challenging. @leopsidom As far as I understand we could indeed build SIMD code with emscripten however it's currently still not supported by Safari, so I think we would need to a wait a bit more before enabling it. Meanwhile, I think we would could skip the numpy SIMD backend. In particular, we probably shouldn't build anything under
and use the baseline implementation instead. As far as I understand it's possible to disable those at build time via the |
Hmm, no that's at runtime. For build time the option is |
@rth Yeah emscripten only supports up to 128-bit AVX, which means we can build up to
That makes sense. I thought we were always building numpy with SIMD enabled, so I was trying to find way to get it working. I got function signature mismatch when trying to build with cpu baseline as avx: numpy/numpy#20079 (comment). It seems some lapack-lite type definition is not correct here.
I tried
Cool, great to know that. It might be better to make the change there instead of making another numpy patch. |
Ahh, even if I disable optimization here. I still got the following error:
So it seems this error is not related to SIMD but some changes between 0.18.5 and 0.19.0. Wonder if there's a way we can build on a specific commit so we can do bisect analysis and find out which commit caused the issue. |
We do get some number of those in numpy and scipy. It seems that there are some mismatched signatures in general (particularly when f2c is involved). When dynamically linking it would still work for x86_64 apparently, however that fails in WASM with emscripten which is more strict. So the solution is often to patch the incorrect signature (also worth checking if there is anything similar in existing numpy patches).
Yes, you should be able to indicate |
Good idea. Let me double check the existing patches.
Nice. Let me try that later today. I tried to manually check all the commits between the two versions. But there are too many of them, and it's hard to pinpoint which commit caused the issue. |
Using git bisect could be faster if you want to find it by testing. |
Nice, great to know |
Ahh, found the commit that caused the problem: numpy/numpy@0159b84. It's trying to build lapack-lite in 64 bit integer mode based on the system information. |
But now I'm getting this error, hmm:
|
You could try filtering out |
@hoodmane Wow, nice that worked. The latest numpy builds! Let me create a PR for this. Currently I'm still building with |
Created a PR here: #1934 |
Couldn't we just dynamically pick which module to load depending on whether or not the browser supports WASM-SIMD? Numpy is a pretty core library and the lack of the SIMD support is one of the primary slowdowns I have encountered between Pyodide and CPython. |
It should be possible. Numpy already has some runtime SIMD detection so it would be a matter of compiling numpy SIMD modules with Emscripten SIMD support then patch numpy runtime detection to take into account the browser. Though a more impactful change IMO would be to use a better BLAS (#227) for numpy. That's what determines the performance of all linear algebra in numpy including the dot product. Related benchmarks in https://twitter.com/ethanhs/status/1381500487334162432 |
I only want to make WeChat App (an chat app with webkit x5 embaded), Is that mean I can compile an simd release? |
Can you please clarify what the current situation is with Numpy and SIMD? If I import and use the builtin numpy package https://pyodide.org/en/stable/usage/packages-in-pyodide.html and run Pyodide v0.22.1 https://www.npmjs.com/package/pyodide in NodeJS does that mean it will use the WASM SIMD instructions? We are trying to write an app that uses SIMD for computing the Mandelbrot set. |
The current situation is that simd is disabled. Our current minimum Safari version is 14.2 (I think, it would be good if we tested our target minimum browser versions). Per this chart, Safari added support for SIMD in version 16.4 released two weeks ago. So as @rth said we would need to build two different numpy wheels and then pick which one at runtime by feature detecting simd. This is entirely doable but someone would need to do it. |
In the meantime, you can build your own numpy wheel with simd enabled. |
Thanks for the reply, if possible can you point me in the right direction?
|
https://github.com/numpy/numpy/blob/main/.github/workflows/emscripten.yml
In Node you can load it with |
Thanks,
I am not sure what this means, in my python script I only have
|
I just mean that if you do e.g.,: await pyodide.loadPackage(scipy);
await pyodide.loadPackage("path/to/custom/numpy"); it won't work. |
Sorry, don't mean to bother you but running that workflow to build and test seems to fail https://github.com/HarikrishnanBalagopal/numpy/actions/runs/4323405620/jobs/7546973464#step:9:50
UpdateSo using the wheel from the Github workflow, we are able to use it to generate the Mandelbrot set. await pyodide.loadPackage('./numpy-0.1.0_alpha.1.mybuild-cp310-cp310-emscripten_3_1_27_wasm32.whl'); @hoodmane Is there some way to verify if the wheel actually has any SIMD instructions? |
Currently pyodide has numpy at version 1.17.5 compared to latest numpy release @ 1.21.2. Pandas at version 1.0.5 while the latest release is 1.3.2. Should we bump the versions for these packages ?
PS: I tried to have a build on the latest numpy. It seems we are able to remove 2 patches with the upgrade due to upstream fix:
I was able to fix some patches, and got it start building. But still getting some issues:
The text was updated successfully, but these errors were encountered: