Back to Wire Feed
SHOW RN

Show RN: Tiny scalar-valued autograd engine supporting reverse-mode autodiff in Rust

Varshith ReddyDevScore 870/1000@varshithreddy8•11/5/2026•github.com

Why I built this

I wanted to deeply understand how PyTorch and Micrograd calculate backpropagation gradients on a computational DAG, so I wrote a minimal scalar autograd engine in Rust from scratch without external crates.

Key Features

  • Directed Acyclic Graph (DAG) topological sort implemented using Rc<RefCell<Node>>.
  • Supports basic arithmetic, tanh, relu, and pow.
  • Trains a 2-layer Multi-Layer Perceptron (MLP) on the binary XOR problem to convergence in 180 epochs.
  • rust
    let x = Value::from(2.0);
    let y = Value::from(3.0);
    let mut z = &x * &y + &x;
    z.backward();
    println!("dz/dx = {}", x.grad()); // prints 4.0
    

    Feedback on safe Rust memory management for cyclic graphs appreciated!

    0 Discussions
    Join Technical Discussion
    Threaded Responses (0)
    No replies yet. Be the first to share an engineering perspective.