Start here

Get started

Create a device, describe work with Tensor operations, then materialize the value you need.

Project status

TypeNN is pre-release. The npm package metadata still describes a placeholder package, so use the repository source and examples as the reference while the release path is prepared.

Open the TypeNN repository ↗

Run your first operation

device() selects WebGPU when available and falls back to the TypeShade CPU tier. You can request "cpu", "webgpu", or "webgl2" explicitly. WebGL2 is a constrained path.

MatMul followed by ReLUfirst-operation.ts
import * as nn from "typenn";

const device = await nn.device({ device: "auto" });
const a = device.tensor([1, 2, 3, 4], { shape: [2, 2] });
const b = device.tensor([5, 6, 7, 8], { shape: [2, 2] });
const y = a.matmul(b).relu();

const values = await y.data();
console.log(values);
await y.disposeGraph();
await device.dispose();

Understand when work runs

Tensor methods construct a deferred graph. They do not immediately read values back to JavaScript. Calling data() executes the reachable graph and returns a Float32Array to the host.

Keep the graph alive until execution finishes.After you consume the result, call disposeGraph() to release intermediate tensors. Dispose the Device when its work is finished.

Continue with a guide