Skip to content
TypeNN
한국어

A neural network framework built on TypeShade

Define computation in TypeScript. Run compiled kernels.

TypeNN builds deferred Tensor graphs from neural network operations. TypeShade compiles the operation kernels and runs them on CPU and GPU backends.

TypeScript  ·  Tensor Graph  ·  TypeShade Runtime

TypeScript · TypeShade
import * as nn from "typenn";

const device = await nn.device();
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();

console.log(await y.data());
// Float32Array [19, 22, 43, 50]
Output: [19, 22, 43, 50]

Real TypeNN examples and kernel source

Execution model

Tensor graphs execute when their results are requested.

Operation methods build a dependency graph. Requesting a result executes the graph needed for that value. On GPU, TypeNN records kernel dispatches in a TypeShade Frame and submits the frame.

Tensor API and execution notes

01

TypeNN Tensor API

Owns Shape and operation semantics, modules, loss functions, and Tensor graph gradient rules.

02

Lowering through TypeShade

TypeNN kernel sources compile to TypeShade programs and are dispatched to the selected device.

03

CPU or GPU execution

Automatic selection tries WebGPU, then falls back to CPU. WebGL2 is a constrained compute-lowering path.

A Frame can submit several dispatches together. That is distinct from kernel fusion. Graph-wide fusion is outside the current implementation.

Model training

From Module to backward and optimizer.step.

The README's MNIST example shows a user-defined Module, Adam, CrossEntropyLoss, and Tensor-graph backward path. The repository example includes the MNIST data loader and evaluation loop.

MNIST example source
examples/mnistModule · Adam
  1. 01Set training mode and select parameters
  2. 02Build Tensors for a batch
  3. 03Compute logits and CrossEntropyLoss
  4. 04Differentiate the Tensor graph with backward()
  5. 05Update parameters with optimizer.step()
  6. 06Release the operation graph with disposeGraph()
nn.Modulenn.optim.AdamCrossEntropyLossTensor.backward()

Current scope

Check implemented behavior in source.

Tensors and operations

Includes rank-2 MatMul, elementwise arithmetic, activations, reductions, softmax, and logits-based cross entropy.

Operation and shape TODO

Automatic differentiation

Tensor graph gradient rules cover selected operations. TypeShade shadeGrad is a separate API for pure TypeShade functions.

Autograd implementation

Devices and resources

Intermediate Tensors stay resident until disposed or the Device is disposed. disposeGraph() releases an operation graph while preserving parameters.

Runtime implementation

This page does not publish performance figures or GPU measurements. Any future measurements should include the execution environment and reproduction steps.