Skip to main content

PyTorch-compatible module with autograd, interpolate/upsample, pooling 1D, loss modules, gradient clipping, nn.init, ModuleList, and float16/bfloat16 — via Pyodide + WebGPU.

Project description

torch-pyodide

PyTorch-compatible API that runs entirely in the browser. Built on Pyodide and WebGPU.

Try it now

Open the playground — write and run PyTorch code in your browser.

Install

In Pyodide (browser)

import micropip
await micropip.install("torch-pyodide")
import torch

x = torch.randn((3, 4))
w = torch.randn((4, 5))
y = x.matmul(w)
print(y.shape)  # (3, 5)

Important: in browser, the Python wheel alone is not enough.
Load and install the JavaScript runtime (runtime.mjs) first, then import torch.

Official manifest channel:

  • https://celsowm.github.io/torch-pyodide/latest.json

The manifest provides:

  • runtimeUrl
  • wheelUrl
  • runtimeSha256
  • wheelSha256

Locally (with Python + Node.js)

pip install torch-pyodide
# Requires Node.js 20+ and a WebGPU-capable browser/device

What works

  • Tensor creation: tensor(), zeros, ones, rand, randn, arange, full, empty
  • Arithmetic: add, sub, mul, div, pow, matmul, mm, mv, bmm
  • Linear algebra: dot, outer, norm (Frobenius, L1, L2, inf)
  • Unary ops: relu, sigmoid, tanh, gelu, silu, sqrt, exp, log, sin, cos, and 40+ more
  • Comparison: eq, ne, gt, lt, ge, le
  • Reductions: sum, mean, max, min, prod, any, all, cumsum, cumprod
  • Shape ops: reshape, flatten, squeeze, unsqueeze, transpose, permute, cat, stack, expand
  • Indexing: select, slice, index_select, masked_select, masked_fill, where
  • Neural network (torch.nn): Linear, Bilinear, Conv2d, BatchNorm1d/2d, LayerNorm, Dropout, pooling, loss functions, activations
  • CUDA stub: torch.cuda.is_available(), torch.cuda.device_count(), etc.

License

MIT

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

torch_pyodide-0.0.84.tar.gz (86.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

torch_pyodide-0.0.84-py3-none-any.whl (82.5 kB view details)

Uploaded Python 3

File details

Details for the file torch_pyodide-0.0.84.tar.gz.

File metadata

  • Download URL: torch_pyodide-0.0.84.tar.gz
  • Upload date:
  • Size: 86.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for torch_pyodide-0.0.84.tar.gz
Algorithm Hash digest
SHA256 bf6465fad0e1b0e25d3142f495505690f388286afd2452b47cdc95ae733af190
MD5 66ed80d6dc034bc49354d40da1bed54c
BLAKE2b-256 3b88ddb4d291291e21c0ff39eaaa46c5926b07d165919c2f603bfabae4a7d111

See more details on using hashes here.

File details

Details for the file torch_pyodide-0.0.84-py3-none-any.whl.

File metadata

  • Download URL: torch_pyodide-0.0.84-py3-none-any.whl
  • Upload date:
  • Size: 82.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for torch_pyodide-0.0.84-py3-none-any.whl
Algorithm Hash digest
SHA256 e806b605617af79ffb8094ef04c68070799f3e6c6bf919c08f469d54447c3ffa
MD5 a0031604b293489fa715c2e5a249ba2f
BLAKE2b-256 0409d25e2b15939dbcaf15a058b7742badf3b8bf74b98ca1dfaba1d91dae54a8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page