chenglou
handwired
Turn your regular JavaScript code into a neural net.
Documentation snapshot
README 快照
翻译暂时拿不到。
机器翻译的项目简介,仅供参考。原文在下方,也可以直接用浏览器自带的整页翻译 (Chrome / Edge 点地址栏右侧的翻译图标,或用右键菜单里的「翻译成中文」)。
下面正文是项目自己的英文 README。想读全文就用浏览器自带的整页翻译: Chrome / Edge 点地址栏右侧的翻译图标,或用右键菜单里的「翻译成中文」; 手机浏览器一般在菜单里。
本页保存的是公开项目资料快照,阅读过程不需要连接 GitHub。
Handwired
Turn your regular JavaScript code into a neural net; no training, exact, yet also fully differentiable!
How It Works
A program’s made of if-else, loops, and state. Handwired transforms them into matrix multiplication + reglu over floats. For example:
const a = 5
const result = (a > 4) ? 10 : 12
The above can be expressed as basic arithmetic:
const a = 5
// Math.max(0, x) is ReLU. For an integer a, above4 is 1 if a > 4, and 0 otherwise
const above4 = Math.max(0, a - 4) - Math.max(0, a - 5)
// Both branches compute, and above4 picks one
const result = above4 * 10 + (1 - above4) * 12
You can calculate that by hand and see that both arrive at the same result.
We then collect the + and * and relu into a giant matmul, and either run it on JS or WebGPU, for fun.
Because we basically only use these 2 primitives:
- the full program stays differentiable
- the weights don’t need training since they’re written manually
- existing gpu techniques, such as fusion, sparsity, reordering, have a great time optimizing such minimal primitives
This unlocks lots of funny use-cases, like:
- unfreezing the weights and train them (what does that even do? Let’s find out!)
- attaching a specific frozen program to a generic neural net and train end-to-end (now a nanoGPT can do both Shakespeare and your particular UI?)
- achieving GPU-level of parallelism with JS code that was written in a traditional single-threaded way (see the JSON search demo that runs in milliseconds over 100k documents)
Play With It
Try the demos live: https://chenglou.me/handwired/
git clone && bun install, then bun start to run them locally. Check docs/, src/ and template/ to get started! (lab/ is a bunch of old experiments you can check or ignore)
图片:HandwiredOS
Official distribution
获取与安装
暂未发现可确认的官方软件包地址
当前 README 快照没有出现 npm、PyPI、Crates.io、pub.dev 等官方包页链接。本站不会根据仓库名称猜测下载地址。
本站不托管项目文件;需要安装时,请以项目维护者发布的官方文档为准。
Before installing
使用前核验
本站保存公开资料用于阅读,不代表安全审计或功能背书。安装前请核对许可证、依赖来源和发布签名,不要直接运行来源不明的二进制文件或高权限脚本。