Zero Dependencies
No TensorFlow.js or ONNX Runtime required. Pure WebGPU implementation with only ~58KB bundle size.
A high-performance, zero-dependency deep learning inference engine built with WebGPU and TypeScript
No TensorFlow.js or ONNX Runtime required. Pure WebGPU implementation with only ~58KB bundle size.
Fused Conv2d+Bias+ReLU achieves 3× memory bandwidth reduction. Single kernel launch, zero intermediate tensors.
Every neural network operator implemented from scratch in readable WGSL shader code. Full GPU control.
Efficient tensor views with no GPU overhead. Reshape operations complete in less than 1 microsecond.
134+ tests with property-based testing (100+ iterations each). CPU reference implementations for validation.
Full TypeScript implementation with strict mode. Zero any types. Production-ready error handling.
npm install tiny-dl-inferencepnpm add tiny-dl-inferenceyarn add tiny-dl-inferenceimport { GPUContext, Tensor, ReLUOperator } from 'tiny-dl-inference';
// 1. Initialize GPU context
const context = new GPUContext();
await context.init();
// 2. Create input tensor
const input = Tensor.fromArray(context,
new Float32Array([1.0, -2.0, 3.0, -4.0]),
[1, 4, 1, 1] // [batch, channels, height, width]
);
// 3. Run ReLU activation
const relu = new ReLUOperator(context);
const output = await relu.forward([input]);
// 4. Get results
const result = await output.download();
console.log(result); // Float32Array([1, 0, 3, 0])
// 5. Cleanup resources
input.destroy();
output.destroy();
context.destroy();Without Fusion (6 memory operations):
Read → Conv → Write → Read → Bias → Write → Read → ReLU → Write
With Fusion (2 memory operations):
Read → Conv+Bias+ReLU → Write| Benchmark | Separate Operators | Fused Operator | Improvement |
|---|---|---|---|
| Conv2d 64-channel | 2.34ms | 0.89ms | 2.6× faster |
| Memory Operations | 6 ops | 2 ops | 3× reduction |
| Kernel Launches | 3 | 1 | 66% fewer |
| Intermediate Tensors | 3 allocated | 0 | 100% saved |
| Browser | Minimum Version | Status |
|---|---|---|
| Chrome | 113+ | ✅ Fully Supported |
| Edge | 113+ | ✅ Fully Supported |
| Safari | 18+ (macOS Sonoma+) | ⚠️ Experimental |
| Firefox | Behind flag | 🔧 Enable dom.webgpu.enabled |
Check WebGPU Support
if (navigator.gpu) {
console.log('✅ WebGPU is supported!');
} else {
console.error('❌ WebGPU not supported in this browser');
}