Pytorch support
I introduced the pytorch module. When executing the compilation, the following error was reported. How should I solve this problem?
Building component my-server with `componentize-py -w spin-http componentize my_server -o target/app/my_server.wasm`
Traceback (most recent call last):
File "/Users/ken/Work/Workspace/spin/myenv/bin/componentize-py", line 8, in <module>
sys.exit(script())
AssertionError: Traceback (most recent call last):
File "/0/my_server.py", line 4, in <module>
from strategy import get_strategy_result
File "/0/strategy.py", line 1, in <module>
from torch import tensor
File "/1/torch/__init__.py", line 14, in <module>
import ctypes
File "/python/ctypes/__init__.py", line 8, in <module>
from _ctypes import Union, Structure, Array
ModuleNotFoundError: No module named '_ctypes'
the strategy.py is:
from torch import tensor
def get_strategy_result():
# Create a tensor
x = tensor([1.0, 2.0, 3.0])
# Perform a simple operation
y = x * 2
return y
if __name__ == "__main__":
print(get_strategy_result())
The version of componentize-py is 0.16.0 my plantform is MacBook Pro the version of Python is 3.11.10
Hi @looksgood since pytorch is a native extension, it requires extra support, specifically being compiled for a WASI target.
Without a wheel for WASI, there won't be a way to load this as the wheel on your computer is built for another target architecture.
@benbrandt thanks for your reply. Is there a schedule to solve this issue? There are still many requirements for Pthon that rely on external libraries.
Hi @looksgood since pytorch is a native extension, it requires extra support, specifically being compiled for a WASI target.
Without a wheel for WASI, there won't be a way to load this as the wheel on your computer is built for another target architecture.
There are ongoing efforts to make this easier for sure. Python only dependencies should be mostly fine, it's the packages backed by C/C++/Rust the cause more challenges.
And pytorch is an interesting one because it may need extra support for GPU access as well
@looksgood If you haven't seen it yet, I created this repo to enable cross-compilation of various Python packages which have native extensions to WASI. @benbrandt has also been doing great work refactoring that repo and adding support for auto-publishing WASI wheels.
AFAIK nobody has tried building Pytorch for WASI yet, and it looks like the Pyodide folks have not ported Pytorch to Wasm yet either, so I'm guessing it's non-trivial.
@dicej got it. Thanks for all your great works.
I noticed torch project has uploaded the wheel archives on python wheels . @benbrandt How can I use wasi-wheels and componentize-py to build my project?
@looksgood the readme shows the commands you need. However, most packages have wheels on PyPI, the issue is what kind.
They don't have a wheel with the wasi target which is what we were referring to. So wasi-wheels won't help you unless we have a custom build for torch, unfortunately.