Repolode
chenglou

chenglou/handwired

A research project that compiles ordinary JavaScript control flow into a differentiable matrix-multiplication network with manually written weights.

Stars
1,773
Forks
146
Open issues
9
Last commit
3 days ago

What is it?

Handwired converts ordinary JavaScript programs containing if-else branches, loops, and state into a neural network built only from matrix multiplication and ReLU over floating-point numbers. Conditionals are rewritten as arithmetic, for example by computing both branches and selecting one with a ReLU-derived indicator, so the resulting network reproduces the original program's output exactly.

Because the weights are written by hand rather than learned, no training is required, and the whole program stays differentiable. The combined computation can be executed in plain JavaScript or on WebGPU, letting existing GPU optimization techniques apply to these minimal primitives.

The project explores uses such as unfreezing the weights for training, attaching a frozen program to a generic neural net for end-to-end training, and running single-threaded-style JavaScript code with GPU-level parallelism. Demos include a JSON search over 100k documents. The repository is set up with Bun, and the demos are also available online.

Key features

  • 01Converts if-else, loops, and state into matrix multiplication and ReLU
  • 02Requires no training because weights are written manually
  • 03Keeps the full program differentiable
  • 04Runs in plain JavaScript or on WebGPU
  • 05Includes live demos and a JSON search example over 100k documents

Use cases

  • Studying how programs can be represented as neural networks
  • Experimenting with training frozen program logic inside a neural net
  • Exploring GPU-parallel execution of ordinary JavaScript code

Quick start

  1. 1

    Clone the repository

    git clone
  2. 2

    Install dependencies

    bun install
  3. 3

    Run the demos locally

    bun start

Things to know

  • Research project aimed at demonstrating a concept, not a production library.
  • Running the demos requires the Bun runtime, which is not mentioned as optional.

Topics

FAQ

What is handwired?
A research project that compiles ordinary JavaScript control flow into a differentiable matrix-multiplication network with manually written weights. Handwired converts ordinary JavaScript programs containing if-else branches, loops, and state into a neural network built only from matrix multiplication and ReLU over floating-point numbers. Conditionals are rewritten as arithmetic, for example by computing both branches and selecting one with a ReLU-derived indicator, so the resulting network reproduces the original program's output exactly.
Is handwired free to use? What license does it have?
handwired is open source under the MIT license. Check the license terms before using it in commercial products.
Is handwired still maintained?
Actively maintained. The last commit to handwired was on Oct 17, 2026.
What can I use handwired for?
Studying how programs can be represented as neural networks Experimenting with training frozen program logic inside a neural net Exploring GPU-parallel execution of ordinary JavaScript code
How do I install handwired?
Clone the repository: git clone Install dependencies: bun install Run the demos locally: bun start
Where can I get handwired?
The source code and installation instructions are on GitHub: https://github.com/chenglou/handwired

Summary generated by AI from the project's README. GitHub stats refresh daily.

Related projects