Feedgarden

Browse

Rust framework DenseCore matches PyTorch's nanoGPT training bit for bit

https://www.reddit.com/r/MachineLearning/comments/1x7ojxo/p_my_rust_framework_trains_nanogpt_with_the_exact/

A computer-science student has built DenseCore, a small deep-learning framework in Rust with a PyTorch-like Python API, and reports that Karpathy's nanoGPT produces bit-for-bit identical results when its import torch line is pointed at DenseCore. The comparison used the same initial weights from manual_seed and matched loss, gradients and weights for all 50 tested steps, including with dropout enabled.

Getting there required reproducing several non-obvious PyTorch behaviors: its CPU attention uses a flash-attention kernel and switches paths when dropout is on; Adam rounds differently on the tail elements of each thread's chunk because of compiler tail-loop fusion; and clip_grad_norm_ multiplies by reciprocal() * max_norm rather than dividing. The author also found PyTorch does not match itself across machines: with the same version on macOS versus Linux x86, only 1 of 26 tested ops produced identical bits. DenseCore therefore matches only on Apple Silicon Macs. It is about 2 MB versus roughly 580 MB for PyTorch.

The student asks whether the project is useful or just a learning exercise, and floats three directions: continue copying PyTorch until most of it works, become a lightweight drop-in for small CPU workloads such as serverless and CI, or become a tool that explains why two PyTorch runs diverge.

Search this site

The index loads when search opens.

    Image