Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ jobs:
python-version: ["3.10", "3.11", "3.12", "3.13"]

steps:
# Allow checkout of Rust dependency snapshots whose paths exceed Windows' default limit.
- name: Enable Git longpaths (Windows)
if: runner.os == 'Windows'
run: git config --global core.longpaths true

- uses: actions/checkout@v4

- name: Set up Python
Expand Down
16 changes: 10 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pywebnn"
version = "0.5.11"
version = "0.5.13"
edition = "2021"
description = "Python bindings for W3C WebNN specification via rustnn"
license = "Apache-2.0"
Expand All @@ -9,28 +9,32 @@ keywords = ["webnn", "python", "machine-learning", "neural-networks", "ai"]
categories = ["api-bindings", "science"]

[lib]
crate-type = ["cdylib"]
crate-type = ["cdylib", "rlib"]
name = "pywebnn"

[features]
default = ["onnx-runtime", "coreml-runtime", "dynamic-inputs"]
default = ["onnx-runtime", "dynamic-inputs"]
onnx-runtime = ["rustnn/onnx-runtime", "ort", "ndarray"]
coreml-runtime = ["rustnn/coreml-runtime", "objc"]
coreml-runtime = ["rustnn/coreml-runtime"]
trtx-runtime = ["rustnn/trtx-runtime"]
trtx-runtime-mock = ["rustnn/trtx-runtime-mock"]
litert-runtime = ["rustnn/litert-runtime"]
cann-runtime = ["rustnn/cann-runtime"]
cann-runtime-mock = ["rustnn/cann-runtime-mock"]
dynamic-inputs = ["rustnn/dynamic-inputs"]

[dependencies]
pyo3 = { version = "0.28", features = ["extension-module"] }
bytemuck = "1.14"
rustnn = { git = "https://github.com/rustnn/rustnn", branch = "main" }
serde_json = "1.0"
webnn-graph = { git = "https://github.com/rustnn/webnn-graph", branch = "main" }
half = "2.4"
regex = "1.11"
pretty_env_logger = "0.5"
# Optional runtime dependencies
ndarray = { version = "0.16", optional = true }
ort = { version = "=2.0.0-rc.11", optional = true, features = ["ndarray", "half", "load-dynamic"] }
objc = { version = "0.2", optional = true }
ort = { version = "=2.0.0-rc.13", optional = true, features = ["ndarray", "half", "load-dynamic"] }

# Make this crate independent from the parent workspace
[workspace]
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@ Python bindings for the W3C WebNN API, powered by `rustnn`.
pip install pywebnn
```

## Development

Install the development dependencies and native extension in editable mode:

```powershell
python -m pip install --upgrade pip
python -m pip install maturin numpy tokenizers
maturin develop
```

Re-run `maturin develop` after changing Rust code. To build with TensorRT RTX
support, use `maturin develop --features trtx-runtime` and ensure the matching
TensorRT runtime DLLs are available on `PATH` before launching Python.

## Docs

Full documentation is published on GitHub Pages:
Expand Down Expand Up @@ -41,6 +55,27 @@ result = context.compute(
print(result["output"])
```

## TensorRT backend

TensorRT is opt-in. Build an editable installation with RustNN's TensorRT feature,
then request it when creating the context:

```bash
maturin develop --features trtx-runtime
```

```python
context = webnn.ML().create_context(backend="trtx")
```

This requires a compatible TensorRT installation and GPU. Use
`context.backend_info()` to inspect the requested backend and compiled features.
On Windows, make the matching TensorRT RTX runtime DLLs available through
`PATH` before starting Python. The DLL version must match the TensorRT headers
used when building the extension.
Other opt-in runtime plugins are `litert-runtime` and `cann-runtime`; select them
with `backend="litert"` and `backend="cann"`, respectively.

## Links

- GitHub: <https://github.com/rustnn/pywebnn>
Expand Down
Loading
Loading