Skip to content

Repository files navigation

affon

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.

Quick Start

Install the latest release:

curl -fsSL https://affon.ai/install.sh | bash

This installs affon into ~/.affon/bin and adds that directory to your shell PATH.

Run a script:

affon hello.ts
import { 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());

Public Modules

  • affon:compute is the tensor, autograd, optimizer, schedule, module, and graph-compilation substrate.
  • affon:nn is the model-building layer on top of affon:compute.
  • affon:dataset is the ingest, preprocessing, batching, text-record, and tokenizer surface.
  • affon:checkpoint is 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.

Examples

Features

  • 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

Stability

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.

Platform Notes

  • 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

Docs

License

MPL-2.0

Bundled datasets and tokenizer assets retain their respective third-party terms. See Third-Party Notices.

Releases

Packages

Used by

Contributors

Languages