今日已更新 412 条资讯 | 累计 19972 条内容
关于我们

I Built a Neural Network from Scratch in Rust — Then Compiled It to WebAssembly

Thomas Cherickal 2026年05月29日 17:56 3 次阅读 来源:Dev.to

A complete ML pipeline: engine, backprop, binary format, and a live browser demo. Zero dependencies. Under 200 KB total. If you have built machine-learning projects before, you have probably done it by importing PyTorch, TensorFlow, or scikit-learn and calling .fit() . Those are excellent libraries. This article is about what happens when you deliberately do not use them — when you build every piece of the pipeline yourself, in a language that compiles to WebAssembly, and the result runs live in the browser with no server, no Python, and no cloud bill. Here is the live demo: move four sliders, watch the predicted Iris species update in real time. The model is running entirely inside your browser tab, loaded from a 1.1 KB binary file, powered by ~100 KB of WebAssembly compiled from pure Rust. This is the story of how I built it and why the engineering choices made it work. Why Rust? Why WebAssembly? Why zero dependencies? Three constraints drove every design decision. WASM requires no_std or a carefully limited std . The wasm32-unknown-unknown target has no operating system, no file system, and no libc. A crate that links against rand , ndarray , or any library that makes OS calls will not compile to it without significant plumbing. An engine built from nothing but the Rust standard library compiles cleanly to every target, including WASM. A zero-dependency std -only crate is uniquely auditable. There are no transitive dependency trees to vet, no supply-chain risks, no version conflicts. Every line of code that runs in the user's browser lives in this repository. The deployment story becomes the technical story. A 100 KB WASM blob that runs locally in the browser is not just a cost optimisation — it is a privacy guarantee (user inputs never leave the machine) and a latency guarantee (inference is microseconds, not a round trip to a cloud API). That story is only possible because the engine has no external dependencies that would bloat the binary. The architecture: ei

本文内容来源于互联网,版权归原作者所有
查看原文