--- layout: home title: Forma for Effect Torch description: Declarative tensor and model graphs in a typed Lisp prelude targeting @effect-torch/core. Check shapes, dtypes, and canonical IR before a training run starts. sidebar: false aside: false pageClass: forma-index forma-effect-torch ---

Forma for Effect Torch · pre-alpha exploration

Tensor graphs you can check before a weight ever loads.

Most machine learning code hides tensor shapes, dtypes, and layer wiring inside imperative scripts until a forward pass crashes at runtime. @forma/effect-torch is an exploratory Forma prelude that expresses tensors, layers, and models as checked declarations targeting @effect-torch/core. The prelude, typechecker, and canonical IR run in the browser sandbox today; TypeScript emission and live Preview Portal execution are planned.

(tensor input  :shape [64 784] :dtype :f32)
(layer  fc1    :in 784 :out 256 :act :relu)
(model  mlp    :input input :layers [fc1 fc2])
   │
   │  read → project → check → IR
   ▼
Canonical Graph IR  (checked today)
   └─→ @effect-torch/core TS  (planned)

Pre-alpha exploration · editable prelude in the sandbox

00 The problem

Shape errors should not wait for a forward pass.

In Python and TypeScript ML code, tensor dimensions and dtypes are mostly comments or runtime assertions. A mismatched layer width or precision bug compiles cleanly and surfaces only after data loads. Forma treats the model graph as typed vocabulary, so the compiler can validate declarations and project a structured IR before any runtime allocates a buffer.

  1. inputs.tsTensor.zeros([64, 784], "f32")← typed inputtensor
  2. layers.tsLinear.make(784, 256, "relu")← transformlayer
  3. model.tsSequential.pipe(fc1, fc2)← graphmodel

Graph vocabulary

(tensor / layer / model)

Sandbox · Checked prelude

Declarations as data, checked as types.

None of these forms are hardcoded into the Forma compiler. The sandbox mounts @forma/effect-torch as an ordinary prelude package defining tensor, layer, and model with typed slots and canonical IR projections.

Every declaration is checked by Forma's Hindley–Milner typechecker: dtypes come from a closed keyword union, shapes and layer widths are typed integer slots, and model graphs resolve layer references against declared bindings. Because the prelude itself is editable in the sandbox, you can inspect or extend the descriptors directly.

src/mlp.lispexploratory prelude sketch
```lisp fragment (tensor x-in :shape [64 784] :dtype :f32) (layer fc1 :in 784 :out 256 :activation :relu) (layer fc2 :in 256 :out 10 :activation :softmax) (model mnist-mlp :input x-in :layers [fc1 fc2]) ```

Implemented vs. planned

Checked IR today. Target runtime next.

Exploration

Honest scope for a pre-alpha prelude.

Today, @forma/effect-torch demonstrates how a tensor-graph DSL fits into Forma's prelude system without compiler changes. Opening the sandbox gives you live typechecking, hover types, located diagnostics, and copy-on-write editing of both src/mlp.lisp and the mounted prelude package.

What is planned rather than shipped: a dedicated TypeScript emitter targeting @effect-torch/core, symbolic dimension arithmetic across arbitrary layer chains and broadcasting rules, and a live Preview Portal view that renders graph topology and tensor statistics in the browser.

03 Architecture

One prelude, inspectable all the way down.

The goal is a declarative graph layer that compiles cleanly onto Effect's structured resource and error model in @effect-torch/core.

Prelude-defined forms

tensor, layer, and model are declared with form descriptors rather than compiler primitives. Swapping or tightening a constraint is a prelude edit.

Canonical Graph IR

Passing declarations project to structured IR records with explicit shapes, dtypes, and references—ready for static analysis or downstream code generation.

Copy-on-write sandbox

Inspect the mounted @forma/effect-torch package in the browser, modify a form descriptor, and watch diagnostics update live against src/mlp.lisp.

Target: @effect-torch/core

Planned TypeScript generation will emit typed @effect-torch/core modules where device allocation, training steps, and tensor errors stay inside Effect.

04 Limits

What you give up, and what is not built yet.

This is an early exploration of ML vocabulary on a pre-alpha language. Do not expect a training framework.

Trade-offs

  • Declarative graphs only. Dynamic control-flow models and arbitrary Python/JS tensor manipulation do not fit a small static graph prelude.
  • Two layers to maintain. Model structure lives in Forma; kernels, optimizers, datasets, and device drivers live in @effect-torch/core and host TypeScript.
  • Unsettled syntax. Form names, slot keywords, and IR shapes are exploratory and will change as dimension checking matures.

Missing today

  • No TypeScript emitter yet. The sandbox checks the prelude and projects IR; it does not yet emit runnable @effect-torch/core code.
  • No tensor runtime or autograd. Nothing in Forma executes matrix math, allocates GPU buffers, or runs backpropagation.
  • No symbolic shape solver. Static checking covers declared slot types and references; full symbolic broadcasting and matrix-multiply unification are planned.
  • Preview Portal is planned. The sandbox reserves a Preview Portal tab, but live graph visualization and execution are not implemented yet.

05 Fit

When to try it.

Worth trying

  • Exploring how typed Lisp preludes can express model architectures and tensor contracts.
  • Prototyping custom layer descriptors and IR shapes in the browser sandbox.
  • Studying how declarative ML graphs can pair with Effect-based runtimes like @effect-torch/core.

Not yet

  • Training, evaluating, or serving production neural networks.
  • Replacing PyTorch, JAX, or hand-written TypeScript ML pipelines today.
  • Teams that need generated @effect-torch/core code or symbolic shape proofs now.

Inspect the prelude, then edit the graph.

Open the Effect Torch sandbox to read the mounted @forma/effect-torch descriptors alongside src/mlp.lisp and test live diagnostics in your browser.