aff·on / əfˈɒn /
A TypeScript runtime for scientific computing and machine learning
Affon is a TypeScript runtime for scientific computing and machine learning.
It provides compute tensors, autograd, neural-network layers, datasets, checkpointing, first-party ML packages, notebooks, and runnable reference workloads in one runtime-oriented package.
Install the latest release:
curl -fsSL https://affon.ai/install.sh | bashThis installs affon into ~/.affon/bin and adds that directory to your shell
PATH.
Run a script:
affon hello.tsimport { tensor, clear_grad, grad, sgd, relu } from "affon:compute";
import nn from "affon:nn";
const model = nn.Sequential(nn.Linear(1, 4), relu, nn.Linear(4, 1));
const params = model.parameters;
const step = sgd({ lr: 0.01 });
const criterion = nn.MSELoss();
const x = tensor([[1], [2], [3]]);
const target = tensor([[2], [4], [6]]);
clear_grad(params);
const pred = model(x);
const loss = criterion(pred, target);
grad(loss, params);
step(params);
console.log(loss.item());affon:computeis the tensor, autograd, optimizer, schedule, module, and graph-compilation substrate.affon:nnis the model-building layer on top ofaffon:compute.affon:datasetis the ingest, preprocessing, batching, text-record, and tokenizer surface.affon:checkpointis the training-state persistence and restore surface.
Runtime/system modules such as filesystem, process, and telemetry are provided
by the underlying runtime under std:* specifiers.
- Getting Started
- NN Basics: Feed-forward + Recurrent
- RNNs
- Embeddings
- Illustrated Tensors
- Tensor Ops Illustrated
- Illustrated NN
- Illustrated Losses And Metrics
- Illustrated Training And Optimizers
- Compute-first numerics with typed tensors, parameters, modules, gradients, and graph compilation
- CPU and Metal execution with explicit device placement and kernel-capability-aware lowering
- Neural-network layers including linear, recurrent, normalization, embedding, dropout, and batchnorm modules
- Optimizers and schedules including SGD, Adam, AdamW, gradient clipping, and scheduled training loops
- Dataset pipelines for tabular and text workflows, including token windows and tokenizer adapters
- Checkpoint persistence for model and optimizer state
- Runtime diagnostics with
std:telemetry.metrics(), traces, and memory signals - First-party packages for transformers, language-model workflows, tokenizers, CNN, and vision work
- Runnable apps including the decoder language-model reference workload
Affon focuses on a documented scientific-computing and ML surface rather than general Node compatibility.
- module loading supports a focused ESM-oriented subset rather than general Node compatibility
- graph compilation prefers native graph-backed execution when capture and lowering succeed
- incompatible captures or unsupported lowering may fall back to eager execution or surface explicit errors
- Metal acceleration is partial and operation-dependent
- package APIs evolve through the first-party package and app workflow
Use the linked docs as the source of truth for exact supported behavior and edge cases.
- macOS uses Accelerate and includes Metal-backed paths where supported
- Linux uses the configured CPU linear algebra path
- release automation should verify the platform assets attached to a given release
- Getting started: Python to AFFON
- Core numerics: Compute Concepts, Compute Kernel Matrix, Error Handling
- Machine learning: NN Concepts, Metrics Concepts, Optim Concepts, Checkpoints, Text Datasets, ML Glossary
- Runtime: Install, Configuration, Module Loader, Memory Debugging
- Apps: apps/, Decoder LM
- Packages: packages/, Transformers, LM, Tokenizers
- Editor: Affon for VS Code
MPL-2.0
Bundled datasets and tokenizer assets retain their respective third-party terms. See Third-Party Notices.