A TypeScript neural network framework

Write the graph.
Compile the work.

TypeNN gives Tensor and Module code a deferred graph. TypeShade compiles its kernels and executes them on CPU and supported GPU backends.

Pre-release · source and examples are the current usage reference.

Tensor APIexample.ts
import * as nn from "typenn";

const device = await nn.device();
const input = device.tensor([1, 2, 3, 4], { shape: [2, 2] });
const weight = device.tensor([5, 6, 7, 8], { shape: [2, 2] });
const output = input.matmul(weight).relu();

console.log(await output.data());
// Float32Array [19, 22, 43, 50]
await output.disposeGraph();
await device.dispose();
Float32Array[19, 22, 43, 50]Example output

From TypeScript to execution

Three layers, one visible path.

How execution works
01

Define

Tensor calls describe shapes and operations. TypeNN records them as graph nodes.

tensor.matmul(weight).relu()
02

Lower

Each node holds a TypeShade kernel function that TypeNN calls on resident arrays.

Tensor graph → kernel functions
03

Run

One fuse scope runs the reachable kernels on the selected execution tier.

CPU · WebGPU · WebGL2*

* WebGL2 and the CPU tier run the same kernel functions apart. Only WebGPU fuses an elementwise chain into one dispatch.

Explore TypeNN

Start with a runnable operation. Continue into the system.

Try matrix operations in the browser, then follow the guide into graph execution, automatic differentiation, and model training.

Current implementation

Every op is a kernel function. Training is not tuned yet.

Each data() runs as one TypeShade fuse scope, and device.lastReport shows its plan. Optimizers still update host arrays, so Adam is not a device kernel and tiled MatMul remains future work.

Read implementation status