$ show mil-tokyo/webdnn
WebDNN is a browser-based neural network inference engine that executes ONNX models directly on the client side. It provides four backendsβCPU, WebAssembly, WebGL (1/2), and WebGPUβallowing models to run on a wide range of hardware. The repository includes a Python graph transpiler for offline model optimization (shader generation, operator fusion, 8-bit quantization) and a TypeScript runtime with a modular operator registration system. While the runtime is application-oriented (library for web ML inference), the Python transpiler contains research-grade optimization passes and weight compression algorithms, giving the project a hybrid character. The codebase is well-structured with clean abstractions for backends and operators, but some backends (WebGPU, WebAssembly) are partially complete and require specific build toolchains.
The LLM identified 4 files worth highlighting for reuse:
Generates parameterized GLSL shader code for n-dimensional tensor operations (read, write, broadcast, output). Used by all WebGL operators. Demonstrates a self-contained shader code generation pattern that could be extracted for any WebGL-based tensor computation library.
Robust image loading and preprocessing utility: decodes image sources (File, Blob, URL, canvas), resizes, converts color spaces, normalizes pixel values, and outputs typed arrays ready for model input. Isolated and reusable for any browser-based image-to-tensor pipeline.
Abstract tensor interface with properties (dims, strides, backend) and methods (getData, setData, sync). Concrete implementations for CPU, WebGL, WebGPU, and WASM provide backend-agnostic tensor operations. This pattern is reusable for any multi-backend tensor library.
Operator registration and instantiation system using OperatorEntry objects with opType, backend, opset range, and factory function. Allows dynamic loading of per-backend operator implementations. The pattern is self-contained and could be extracted for any plugin-based execution engine.