宝玉 (@dotey) · 10/16/2026, 02:04:29

Handwired: Open-Source Tool Converts Program Logic into Differentiable Neural Nets with Zero Training and Exact Inference

By 宝玉 (@dotey)Original title: Cheng Lou 开源 Handwired:手写权重,把程序逻辑变成不用训练的神经网络
78AI Score
Executive Summary

Former React core member Cheng Lou open-sourced Handwired, a tool that maps program logic like if-else statements directly to neural network weights without training, ensuring outputs match original JavaScript code exactly. By using ReLU activations to simulate conditional branches, the project supports full differentiability and demonstrates capabilities such as running complex UIs in browsers, accelerating regex searches via WebGPU parallelism, and optimizing layouts through real-time backpropagation, exploring the intersection of symbolic computation and neural networks.

SOURCE COVERAGEFull Original Report

Cheng Lou Open-Sources Handwired: Hand-Written Weights Turn Program Logic into Untrained Neural Networks

Midjourney engineer and former React core team member Cheng Lou has open-sourced Handwired, a project he describes as a "toy." It rewrites if-else statements and loops in programs into neural network weights. The weights are hand-written, requiring no training, yet the output is identical to the corresponding JavaScript program. It runs directly in the browser.

The principle can be explained in a single line of code. For example, result = a > 4 ? 10 : 12, when a is an integer, can be rewritten as:

JAVASCRIPT
above4 = relu(a - 4) - relu(a - 5)
result = above4 * 10 + (1 - above4) * 12

relu is simply Math.max(0, x), the most common activation function in neural networks. When a is greater than 4, above4 is exactly 1; otherwise, it is 0. Both branches are calculated, and then one is selected using this value. Since neural networks are essentially just multiplications, additions, and ReLU operations, conditional judgments and branches in programs can all be encapsulated within a large matrix multiplication.

You might wonder: aren't neural network outputs probabilistic and imprecise?

Cheng Lou’s answer is: That applies only to trained networks. With weights hand-written according to program logic, the same input always yields the exact same output.

He released three demos.

The first is Mini OS, a small desktop environment with three windows and a dock. It supports dragging, resizing, layering, scrolling, text input, and animations. Inspecting the page via browser developer tools reveals standard web elements—no large language models or diffusion models involved. It is driven by a "neural network" with 130 layers and 9,909 weights, zero training iterations, and real-time CPU computation in the browser.

The second is real-time search across 100,000 JSON documents, re-searching on every keystroke. Regex matching, JSON parsing, and highlighting are all handled by these hand-written networks, which are then compiled into WebGPU code for parallel execution on the GPU. According to benchmarks in the project documentation (Apple M5 Max + Chrome): each search takes 11–15 milliseconds. The browser's built-in regex engine typically takes 8–28 milliseconds but can exceed 2 seconds for patterns prone to backtracking. The documentation notes that relative speed varies, so both times are listed. If the browser does not support WebGPU, it falls back to CPU, where a search takes 13 seconds.

The third is a "learning" photo album. The entire program is differentiable, meaning parameters can be tuned using backpropagation, similar to training neural networks. You draw rectangles on the left as sketches, and the photo layout on the right is computed by a small network whose 244 parameters are trained in real-time as you drag. A penalty term for alignment is added to the loss function, causing photos to automatically align along a line without any explicit alignment code. With few parameters, training runs entirely in JavaScript.

Cheng Lou also envisions connecting a Handwired program to models like nanoGPT (Andrej Karpathy’s small GPT training project) for joint training, allowing the model to both write Shakespearean-style text and precisely execute the program logic. This remains a concept in the README, with no existing implementation in the repository.

The code is open-sourced under the MIT license, and demos are playable directly in the browser. To build your own, you need to install Bun, clone the repository, and start with the toggle button example from the template directory. Complete tutorials are available in the documentation.

The tweet claims "turn regular JS code into a neural net," which might lead people to believe existing code can be automatically converted. However, the project documentation clarifies: there is no tool to convert existing JavaScript source code into a network. You must use the provided builder functions to rewrite logic step-by-step into comparisons, selections, weighted sums, etc. The network executes all operations every time; it cannot exit early or run loops with runtime-determined iteration counts. Therefore, common loops must be rewritten into structures like counting or tree-based merging—a topic covered in a dedicated chapter of the docs. All numbers are 32-bit floats, and the range of each value must be declared beforehand.

Project Homepage: https://t.co/ywg9dzrFbM GitHub: https://t.co/fg1sj0trv4 Original Tweet: https://t.co/QW2cMnSiWE

↳ Quote @_chenglou (Cheng Lou): My dear friends, I’d like to show you my latest toy project

Introducing Handwired: turn your regular JavaScript code into a neural net!

  • no training
  • exact outputs vs the JS program
  • fully differentiable

All runnable in a browser, without GPU