# Handwired

> Transforms regular JavaScript code into an exact, differentiable neural net of matrix multiplications and ReLU, with no training required.

Handwired is an open-source project by Cheng Lou that turns ordinary JavaScript programs into neural networks whose weights are written by hand rather than trained. The resulting network is exact and fully differentiable, and it can run in JavaScript or on WebGPU in a browser.

## What It Is

Handwired compiles program logic such as if-else branches, loops, and state into matrix multiplication plus ReLU-style operations over floats. For example, a conditional like `a > 4 ? 10 : 12` becomes basic arithmetic in which both branches compute and a ReLU-based selector picks one. The additions, multiplications, and ReLUs are then collected into a large matmul and run on JS or WebGPU.

## Why the Approach Matters

Because the program reduces to only two primitives, the README says the whole program stays differentiable and the weights need no training. It also says existing GPU techniques such as fusion, sparsity, and reordering can optimize such minimal primitives. The README lists some uses: unfreezing the weights and training them, attaching a frozen program to a generic neural net and training end-to-end, and getting GPU-level parallelism from code written in a single-threaded style.

## Demos and Setup

The project site includes a Mini OS, a small desktop written in JS and transformed with Handwired, rendering to regular DOM. It also has a Learned gallery, where a compiled program's weights are unfrozen and trained in real time, and a JSON search demo covering 100,000 documents with regex matching, parsing, and highlighting turned into WebGPU kernels. To run locally, clone the repo, run `bun install`, then `bun start`. The repo includes docs, src, and template folders to get started, and a tutorial is available.

## Features
- Transforms JavaScript control flow and state into matrix multiplication plus ReLU
- Exact, fully differentiable output with no training
- Runs on JavaScript or WebGPU
- Runs in a browser without a GPU
- Weights can be unfrozen and trained
- Frozen programs can be attached to generic neural nets for end-to-end training
- Live demos: Mini OS, Learned gallery, JSON search over 100k documents

## Integrations
WebGPU, Bun

## Platforms
WINDOWS, WEB, API, DEVELOPER_SDK

## Pricing
Open Source

## Links
- Website: https://chenglou.me/handwired/
- Documentation: https://github.com/chenglou/handwired/blob/main/docs/tutorial.md
- Repository: https://github.com/chenglou/handwired
- EveryDev.ai: https://www.everydev.ai/tools/handwired
