Practical overview
When it fits
Use it when machine-learning or numerical code needs tensor operations and automatic differentiation within a Rust project, or when assembling neural-network training code from low-level building blocks.
Who it is for
- Rust developers implementing differentiable computations or gradient-based machine-learning code.
- Developers building neural-network training examples with tensor computation graphs.
Documented uses
- Define tensor operations and calculate gradients, including differentiating a gradient again.
- Build low-level neural-network code with matrix multiplication, loss calculations and parameter gradients.
- Follow the documented MNIST multilayer-perceptron pattern when designing a small classifier training example.
Requirements & limits
- The library is written in Rust and its tensors are backed by ndarray.
- The README describes gradients for scalar expressions, placeholder-fed evaluation, and second derivatives.
- The MNIST MLP example shows weights, biases, matrix multiplication, sparse softmax cross-entropy and gradient construction; the feeder and Adam update lines are commented out.
- For basic linear algebra, especially matrix multiplication, the README recommends considering the BLAS feature and lists Accelerate, Intel MKL and OpenBLAS choices.
- The repository metadata identifies the license as MIT.
Check current requirements in the official documentation. Source-based guidance does not mean OpenViST has run or independently tested this project.
Compute a derivative with Rust Autograd
Build a scalar computation graph and evaluate a first or second derivative.
Before you start
- Rust project with the
autogradcrate available as a dependency.
Steps
Import
autogradasagand importag::tensor_ops::*.Inside
ag::run, create scalar placeholders withctx.placeholder, then define the scalar expression using tensor operations.Use
grad(&[output], &[input])[0]to construct a derivative.Evaluate the derivative with
eval(ctx); when the derivative depends on an unfilled placeholder, feed it throughctx.evaluator().push(...).feed(...).run(). For a second derivative, applygradto the first derivative.
Expected outcome
Evaluated scalar derivatives; the documented example computes values 3, 8, and 4 for derivatives of `2x² + 3y + 1` at the stated feed.
Guide limitations
- The example feeds
xwith the scalar value 2 to evaluatedz/dx; derivatives requiring unfilled placeholders need input feeds.
Sources & review
Source record details
- Source availability
- Active
- Sources checked
- 11 November 2026
- Original website title
- raskr/rust-autograd · Official homepage title · retained in its source language

