Rust deep learning framework

When Rust Meets PyTorch: A Student's AI Framework Hits Bit-for-Bit Parity

A CS student built DenseCore, a 2 MB Rust deep learning framework with a PyTorch-like Python API, and matched PyTorch's output bit-for-bit across 50 training steps of Karpathy's nanoGPT.

5 min readMachine Learning

There's a quiet radicalism in what this student built, and it has nothing to do with size or speed. DenseCore is a 2 MB Rust framework that runs nanoGPT unchanged and produces bit-for-bit identical results to PyTorch on Apple Silicon, same weights, same losses, same gradients, dropout included. That is not a happy accident. It's the result of reverse-engineering the undocumented corners of a mature system: flash attention's CPU path, the compiler's tail-loop fusion in Adam, the reciprocal trick hiding inside `clip_grad_norm_`. The project is tiny, but the insight it carries is outsized: exact reproducibility is not a property of PyTorch. It's a property of a very specific machine, a very specific build, and a very specific set of choices made deep inside the stack.

This is the kind of work that feels like a parlor trick until you sit with it. The author found that PyTorch doesn't even match itself across machines, same version, Mac versus Linux x86, only one of 26 ops produced identical bits. That single detail reframes the entire conversation. We chase precision in our models while the tools we build them with quietly drift between platforms. It's a reminder that the spreadsheet era taught us to trust the tool's output without question, and the AI era demands we understand the substrate. This connects to broader efforts to make powerful technology more accessible and controllable, much like Run capable AI models locally on a Mac mini with these five tools. and Discover how ARPL adapts llama.cpp to your device's true capabilities, which both explore how small, focused tools can outperform sprawling frameworks for specific use cases. DenseCore is the same impulse applied at a different layer: not a bigger hammer, but a more precise one.

What makes this project worth attention isn't the parity itself. It's what the parity exposes. The student didn't just reimplement PyTorch's public math; they reverse-engineered its silent decisions, the flash attention kernel that replaces the textbook formula on CPU, the fused tail-loop rounding in Adam, the `reciprocal() * max_norm` trick inside `clip_grad_norm_`. That's the kind of detail most users never see, yet it decides whether two runs produce identical numbers. And the discovery that PyTorch doesn't even match itself across machines, only one of 26 ops matched between macOS and Linux x86, is a reminder that reproducibility is a feature, not a given. For anyone who has chased a ghost through a notebook, this matters.

The practical question isn't whether DenseCore is impressive, it is, as a learning exercise. The real insight is what this reveals about the tools we treat as black boxes. When a student can reverse-engineer the exact arithmetic of a major framework in days, it says something about how much hidden behavior lives inside our daily tools. That's the same spirit driving Unlocking iOS 27 Virtualization for Security Research and Testing and Run capable AI models locally on a Mac mini with these five tools: the willingness to open the black box and see what's actually happening. The author of DenseCore didn't just want a working framework; they wanted to know exactly why it works, down to the last bit. That's the same impulse that drives people to run capable models locally or dig into virtualization for security research, the urge to understand the machinery rather than just trust the output.

But let's be clear about what this project really demonstrates. The headline isn't that a student built a tiny PyTorch clone. It's that PyTorch itself is a stack of undocumented decisions, flash attention kernels, fused tail loops, a hidden `reciprocal() * max_norm` where you'd expect division. DenseCore's achievement is forensic: it reverse-engineered those decisions closely enough to replicate them exactly. That's a meaningful contribution to reproducibility, even if the framework itself never grows beyond a few thousand lines. The fact that PyTorch doesn't even match itself across machines, only one of 26 ops matched between Mac and Linux x86, tells you everything about how much silent variance lives inside the tools we treat as ground truth.

This is where the story gets practical. If you've ever [Run capable AI models locally on a Mac mini with these five tools](/post/run-capable-ai-models-locally-on-a-mac-min

From Machine Learning

hey, CS student here. for the past few days I've been building DenseCore, a small deep learning framework in rust with a pytorch-like python API.

the thing I'm kind of proud of: if you point `import torch` at it and run karpathy's nanoGPT unchanged, you get the exact same numbers as pytorch. same initial weights from manual_seed, same loss, same gradients, same weights, bit for bit, for all 50 steps I tested, even with dropout on. not "close enough", literally identical.

Read the original at Machine Learning