Skip to content
All projects
Personal project

Rust Ai Examples

A set of self-contained Rust programs covering deep learning with Candle and classical ML with Linfa, written as a decision aid for putting AI workloads in Rust.

Rust Ai Examples project preview

Overview

Rust AI Examples is a collection of small, runnable programs that put real ML workloads in Rust — deep learning through Candle and classical ML through Linfa. Most of my AI work lives in Python, so the point of this repo was to answer a practical question rather than a theoretical one: where does the Rust ecosystem actually hold up for ML, and where does it still cost you more than it returns?

The answer is more interesting than “not ready yet,” which is why the examples are kept small and separate instead of bundled into one showcase project.

The brief

  • One example per concept, each runnable on its own with no shared scaffolding to hide behind.
  • Cover both ends of the stack: tensor-level deep learning and classical algorithms.
  • Keep every example short enough to read in a single sitting.
  • Record the friction honestly — this is a decision aid, not a benchmark suite.

Approach

Each example stands alone: its own Cargo manifest, its own entry point, and its own dependencies, so a reader can lift one into another project without dragging the rest of the repo along. That constraint is deliberate. A shared common crate would have made the code tidier and the examples less useful.

Candle carries the deep learning side. It is where Rust’s argument is strongest: model inference as a single deployable binary, no Python runtime, no environment to reconcile on the target machine. Linfa carries the classical side — the problems that do not need a GPU or a framework, just a correct implementation and a fast build.

I kept conventions consistent across examples even though they share no code: the same input and output shapes, errors returned as Result rather than panicking on bad input, and no hidden global state. Notes alongside each example compare against the Python equivalent where one exists — the goal is to show the ergonomic gap honestly, not to transliterate a notebook into Rust.

Stack

Rust throughout, with Candle for deep learning and Linfa for classical ML.

Outcome

The repo is a set of compact, runnable references plus a clearer sense of when Rust is the right call for an ML component: inference at the edge, ML embedded inside a service that is already Rust, replacing a Python sidecar in a deployment pipeline. Candle is genuinely production-viable for inference. Linfa is comfortable for classical work. Training at scale is still where Python and its ecosystem win, and the examples make that boundary visible rather than arguing about it.

View the website →