Skip to main content

borch

PyTorch's shape, in a browser tab. Three implementations of one arithmetic — a numpy core (import borch as torch), a TypeScript runtime on WebGPU (borch-ts), and a Python binding over that runtime for Pyodide (borch_webgpu) — held to real PyTorch's values, errors and printed form within the range a curriculum uses.

  • See it run: https://playidea-lab.github.io/borch/site/ — the playground trains on your GPU; ten lessons and ten tutorials run every code block in the page.
  • The long document — how the values are guaranteed, the supported range, what is deliberately absent and why, borch.ts's design, conformance — is docs/BOOK.md. This page is the door; that one is the house.

What it is not

Not PyTorch. CUDA, distributed training, mixed precision and torch.compile are never coming — they cannot exist in a browser, or learning them means leaving it. An absent feature beats a wrong answer, so what is missing is written down as missing: tests/torch_gap.py prints the current count per namespace, and every gap carries a reason.

Thirty seconds

In a browser, nothing installed. Open the playground and press Run. The landing page times its own first run; measured nightly on a real adapter (tests/browser/first_run.py).

Python, on your machine.

uv pip install pyborch
import borch as torch

x = torch.tensor([1.0, 2.0, 3.0], requires_grad=True)
(x * x).sum().backward()
print(x.grad)           # tensor([2., 4., 6.])

TypeScript, in a page.

npm install borch-ts
import { init, Tensor } from "borch-ts";

await init();                          // asks for a WebGPU adapter, refuses a software one
const x = Tensor.from([1, 2, 3], [3]);
console.log(await x.mul(x).sum().toArray());   // Float32Array [14]

Both examples are run as written by the checks (tests/test_document_examples.py, borch-ts/test/readme.ts), so if they stop working the build says so.

How it is guaranteed

4735 golden cases compare all three implementations against the same answers frozen from real torch — values, shapes, gradients, exception types and messages, and repr. The core runs them natively and in Pyodide; the binding and borch.ts run them in a browser on a real GPU, and every number they print carries the adapter's name, because a software adapter answers every WebGPU call correctly and proves nothing about a GPU.

Where this library deliberately parts from torch — a handful of places, each with a measurement beside it — is listed on the landing page and pinned by borch-ts/test/parity.ts. Everything else that differs is a defect, and the ledgers (tests/torch_gap.py, borch-ts/test/run.py) hold zero gaps without a reason.

Or a notebook. %pip install pyborch then import borch_webgpu as torch in any Pyodide — the notebook page is JupyterLite with the wheel already on its shelf, training on the tab's GPU 6 s after opening.

The file leaves as ONNX. onnx.exportOnnx(model, sample) in TypeScript, torch.onnx.export(model, x, path) in Python — traced from one forward, written without a dependency, and checked by ONNX Runtime Web reproducing the forward (3.5e-8; see the book).

Where things are

borch/ the numpy core — the reference implementation
borch-ts/src/ the TypeScript runtime: hand-written WGSL, zero dependencies
borch_webgpu/ the Python binding over borch.ts, for Pyodide
borchvision.py · borch-ts/src/vision.ts torchvision's transforms, ops, datasets
tests/ the golden, the ledgers, and the checks that police these documents
site/ the playground, lessons, tutorials, and the API reference
docs/BOOK.md the long document
ROADMAP.md what conformance means here, and what will not be done

Sister libraries: bimm (a model catalogue, on npm as bimm-ts) and borch-hub (weights by manifest and hash).

Working on it

Every browser check is listed in .github/workflows/gpu.yml and run nightly by tests/browser/nightly.py; CLAUDE.md holds the three rules a session has to know. Native tests: uv run --with pytest --with numpy --with torch --with torchvision --with scipy pytest tests/ -q.

Licence

Apache-2.0. Third-party notices are in THIRD-PARTY.md.

Download files

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

Source Distribution

pyborch-1.6.0.tar.gz (953.8 kB view details)

Uploaded Source

Built Distribution

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

pyborch-1.6.0-py3-none-any.whl (970.1 kB view details)

Uploaded Python 3

File details

Details for the file pyborch-1.6.0.tar.gz.

File metadata

  • Download URL: pyborch-1.6.0.tar.gz
  • Upload date:
  • Size: 953.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.16 {"installer":{"name":"uv","version":"0.9.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for pyborch-1.6.0.tar.gz
Algorithm Hash digest
SHA256 9151d022ec11deb131fdfed0eaac75252e56e1254375258da377f74ca7174413
MD5 3ab1c3a0e2bc0ec0e20d85d44a07c22b
BLAKE2b-256 1e453516031bfbe746d3cfe13c9e570698bbc6c2f3ba5b0f153751c9249e1fa0

See more details on using hashes here.

File details

Details for the file pyborch-1.6.0-py3-none-any.whl.

File metadata

  • Download URL: pyborch-1.6.0-py3-none-any.whl
  • Upload date:
  • Size: 970.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.16 {"installer":{"name":"uv","version":"0.9.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for pyborch-1.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a8495895e1574a395c36d1720048ca2356e493a28875dcf46773af522650d03b
MD5 f70a8e28d03c5376332059e6a1a2cf9e
BLAKE2b-256 214ce3666f43d1c0d5ff5dc2dc085f6c2db37a454b94ccbcf644a4664ade0955

See more details on using hashes here.

Release history Release notifications | RSS feed

1.12.0

1 file

1.11.3

1 file

1.11.2

1 file

1.11.1

1 file

1.11.0

1 file

This release

1.6.0 This release

2 files

1.4.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page