-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Importing a new package that doesn't exist in Pyodide
#85
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
Comments
Pyodide
Pyodide
hi, i am excited to see your interest in this project. :) i have been working on getting torch into Pyodide. it's pretty challenging. we do have a alpha workflow to get non-pure python packages with c/c++/cython extensions into the pyscript/Pyodide ecosystem, but torch is extra complicated. i plan on posting the build process for non-pure python packages as soon as i can |
hi, what about tensorflow as it has the javacript package in it. will it be able to work with pyscript. |
currently, you should be able to use all the packages here https://github.com/pyodide/pyodide/tree/main/packages you can build your own packages and add them into pyscript. but some packages are very difficult to build. torch and tensorflow are hard to build into WASM and the WASM compiler tooling. i am working on porting torch now and tensorflow after that. i hope to make some new posts as i progress on this task. |
i see more clearly now, sorry. i expect TensorFlow.js will work yes. good idea. i will try that out |
@verhulstm I'm super excited to hear about the progress you make on torch and tensorflow. Even more exciting from my perspective would be JAX. Are you working on this in a public repo? I'd love to follow along and help where I can. |
@verhulstm I would suggest you take a look at |
There was a discussion about JAX in pyodide/pyodide#2198, tensorflow in pyodide/pyodide#50 and torch in pyodide/pyodide#1625.
For ML wrapping JS libraries (such as ONNX Runtime Web, Tensorflow.js etc) from Python via the Pyodide's FFI is indeed another solution. Though your API is then not going to be exactly the same as when using e.g. Tensorflow from Python, so one cannot reuse code without changes. |
Yep, ONNX web runtime, tfjs-tflite, etc. are fine for inference - but JAX/torch/tensorflow can do much more than model inference. It would be a dream come true to be able to play with JAX's auto-differentiation in the browser! |
@verhulstm Are there any examples of how you would do this? I'd love to experiment with using this with some pure python libraries that aren't on pypi. I'm assuming you'd follow the steps on how to build a Pyodide package but I'm not clear on how you'd add them into pyscript. Thanks! |
i am prepping a better guide for this, but until that is ready. get a pyodide dev env ready. in docker or vagrant git clone https://github.com/pyodide/pyodide.git then follow https://pyodide.org/en/stable/development/new-packages.html |
i did this in ubuntu 20.04 with these packages apt install -y build-essential and https://repo.anaconda.com/miniconda/Miniconda3-py39_4.11.0-Linux-x86_64.sh |
if you have a pure python file that should already work. include a link to the file in your "py-env" tag |
You can link import asyncio
import micropip
await micropip.install(URL) I don't know if |
Thanks @verhulstm and @sudomaze! |
@verhulstm let me know if I can help, I will be happy to contribute. The PyTorch team is aware of your contribution to import PyTorch into Pyodide, so they should be in contact with you cc: @msaroufim |
great, i would love to chat in the next few days. email me :) |
Joining late to the party... a bunch of the questions in the original post was already addressed so I'll focus on the ones that I think were left out:
Currently, you can't. Opened #172 to address this
I think the question here means to load a packaged "bundle" with pyodide and all (and only) applications require packages once. Right? If so, no, this is not possible today. This is actually an upstream issue that we recently discussed with the pyodide team and we have some ideas on.. but not in the short term. /cc @rth
Not entirely sure I understand question but, in any way I could interpret it, it is an upstream question. @rth @hoodmane do you want to chime in? From looking into the logs, it seems that every time the page has loaded the packages listed to be used get installed by micropip, is this correct? If yes, why can't we store already installed packages to load them? If the packages are already included in Pyodide, it will only load them and not fetch them from PyPI and install them. I'd think it's to optimize size and performance (the more you load/add the bigger and slower it is). Why PyScript is super slow? I am assuming this because of the installation of packages from scratch (if my assumption is true). We are trying to investigate in the next few days but it's very very likely to be an upstream issue. Thank you for the questions! As we roll out better documentation, we'll add some of these to the FAQ. 👍 |
Packages that don't have pure Python wheels,
We have added a FAQ entry recently on what to do when a package fails to install https://pyodide.org/en/latest/usage/faq.html#micropip-can-t-find-a-pure-python-wheel
Yes, they will be re-installed each time. However the browser would cache them, so they don't have to be re-downloaded and it's mostly a matter of unzipping them to the virtual file system (which is fast) and pre-loading dynamic libraries contained in the package (see below).
Yes, in particular for packages included in Pyodide we unvendor tests, so they are a bit smaller. Otherwise, for pure Python packages, there is little difference from where to install them.
If you profile a typical Python application say that loads pandas results would be roughly the following:
A large part of the time would be spent compiling .wasm code objects by the browser. This situation is made worse by the fact that we cannot load dynamic libraries synchronously on demand when Python modules are imported and have to-preload/compile all the libraries in a package when the package is loaded. Libraries such as numpy, pandas etc have a lot of binary extensions which take a while to compile (the same goes for CPython itself). Some browsers would cache WASM compilation https://v8.dev/blog/wasm-code-caching but it's a step that takes a while the first time. There is active work happening on how to reduce load time in Pyodide but it's still a challenging topic. |
closing as upstream, seems that questions have been answered and there's not much else to do. Happy to be convinced otherwise :) |
Would you like to ask if it supports loading torch models now? |
I have been trying to look into ways to import
torch
but I couldn't manage to do so because it isn't inPyodide
's list of supported packages.From my research on this, there are two ways to have any new package be utilized:
pure Python 3 wheel
which means the package could be installed without the need of hard specifications.torch
and its dependencies toPyodide
's list of support packages. This will require doing the following:Pyodide
from the source.Pyodide
's list of supported packages by following the documentationPyodide
toPyscript
I don't know how this can be doneQuestions:
Pyodide
which was built locally toPyscript
?pure Python 3 wheel
(aka needs to be compiled on all hardware)? Is it because it is actually being compiled on the browser-side which should be able to run all hardware?micropip
, is this correct? If yes, why can't we store already installed packages to load them?Relevant resource:
Pyodide
pyenv
tag is just wrapper tomicropip
Pyodide
issuePyodide
issueThe text was updated successfully, but these errors were encountered: