bytecodealliance / bytecodealliance/componentize-py

Pytorch support

Open
#141 6 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
277
Forks
51
Avg merge
12h 10m
Merged PRs (30d)
10

Description

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
sys.exit(script())

AssertionError: Traceback (most recent call last):
File "/0/my_server.py", line 4, in
from strategy import get_strategy_result
File "/0/strategy.py", line 1, in
from torch import tensor
File "/1/torch/__init__.py", line 14, in
import ctypes
File "/python/ctypes/__init__.py", line 8, in
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

Contributor guide

Open the contributing guide

Research direction

Start with the componentize-py 0.16.0 compilation command and the provided strategy.py, then reproduce the import failure on Python 3.11.10 on macOS. Trace why importing torch reaches ctypes without _ctypes; done means the reported PyTorch module can compile successfully or the supported limitation and required setup are clearly documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch, wasm
Domain
build-system, machine-learning, tooling
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.