Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
rustnn / PyWebNN
A Rust implementation of WebNN graph handling with Python bindings that implement the W3C WebNN API specification.
[WARNING] EXPERIMENTAL - DO NOT USE IN PRODUCTION
This is an early-stage experimental implementation for research and exploration. Many features are incomplete, untested, or may change significantly.
What is rustnn?
rustnn provides:
- Rust Library: Validates WebNN graphs and converts to ONNX/CoreML formats
- Python API: Complete W3C WebNN API implementation via PyO3 bindings
- Runtime Backends: Execute on CPU, GPU, or Neural Engine with backend selection at context creation
- Real Examples: Complete MobileNetV2 (99.60% accuracy) and Transformer text generation
Installation
Python Package (PyWebNN)
PyPI Package (v0.4.0+):
# Install with bundled ONNX Runtime - no additional dependencies needed
# Works immediately with actual execution (no zeros)
Build from Source (For Development):
Requirements: Python 3.11+, NumPy 1.20+
Note: Version 0.4.0+ includes bundled ONNX Runtime. Earlier versions (0.3.0 and below) had no backends and returned zeros.
Rust Library
[]
= "0.1"
Quick Start
# Create ML context with device hints
=
= # CPU execution
=
# Build a simple graph: output = relu(x + y)
=
=
=
=
# Compile the graph
=
# Execute with real data
=
=
=
# [[0. 0. 0.] [0. 0. 0.]]
# Optional: Export to ONNX
Backend Selection
Following the W3C WebNN Device Selection spec, backends are selected via hints:
# CPU-only execution
=
# Request GPU/NPU (platform selects best available)
=
# Request high-performance (prefers GPU)
=
# Request low-power (prefers NPU/Neural Engine)
=
Platform-Specific Backends:
- NPU: CoreML Neural Engine (Apple Silicon macOS only)
- GPU: ONNX Runtime GPU (cross-platform) or CoreML GPU (macOS)
- CPU: ONNX Runtime CPU (cross-platform)
Examples
Complete MobileNetV2 Image Classification
# Download pretrained weights (first time only)
# Run on different backends
Output:
Top 5 Predictions (Real ImageNet Labels):
1. lesser panda 99.60%
2. polecat 0.20%
3. weasel 0.09%
Performance: 74.41ms (CPU) / 77.14ms (GPU) / 51.93ms (CoreML)
Text Generation with Transformer Attention
# Run generation with attention
# Train on custom text
# Generate with trained weights
See examples/ for more samples.
Documentation
- Getting Started - Installation and first steps
- API Reference - Complete Python API documentation
- Examples - Code examples and tutorials
- Architecture - Design principles and structure
- Development Guide - Building and contributing
Implementation Status
- 85 of ~95 WebNN operations (89% spec coverage)
- Shape inference: 85/85 (100%)
- Python API: 85/85 (100%)
- ONNX Backend: 85/85 (100%)
- CoreML MLProgram: 85/85 (100%)
- 1350+ WPT conformance tests passing
See docs/development/implementation-status.md for complete details.
Rust CLI Usage
# Validate a graph
# Visualize a graph (requires graphviz)
# Convert to ONNX
# Execute with ONNX Runtime
See make help for all available targets.
Contributing
Contributions welcome! Please see:
- AGENTS.md - Project architecture and conventions
- docs/development/contributing.md - How to add features
- TODO.txt - Feature requests and known issues
Quick Contribution Guide:
- Fork and create feature branch:
git checkout -b feature/my-feature - Install hooks (optional):
./scripts/install-git-hooks.sh - Make changes and test:
make test && make python-test - Format code:
make fmt - Commit and push
License
Licensed under the Apache License, Version 2.0. See LICENSE for details.
Links
- GitHub: https://github.com/tarekziade/rustnn
- PyPI: https://pypi.org/project/pywebnn/
- Documentation: https://tarekziade.github.io/rustnn/
- W3C WebNN Spec: https://www.w3.org/TR/webnn/
Acknowledgments
- W3C WebNN Community Group for the specification
- Chromium WebNN implementation for reference
- PyO3 and Maturin projects for excellent Python-Rust integration
Made with Rust by Tarek Ziade