Top AI Repos — open-source AI, indexed and scored
Top AI Repos tracks AI repositories on GitHub and answers two different questions about each one: is it moving right now, and would you bet a product on it.
Top AI Repos tracks AI repositories on GitHub and answers two different questions about each one: is it moving right now, and would you bet a product on it.
Deep learning in Rust, with shape checked tensors and neural networks
| Date | Stars |
|---|---|
| 2026-07-24 | 1922 |
| 2026-07-25 | 1922 |
| 2026-07-28 | 1922 |
| 2026-07-30 | 1922 |
| 2026-07-31 | 1924 |
| 2026-08-06 | 1925 |
Today
+1 stars today
This week
+3 stars this week
This month
— stars this month
Momentum
0.0
growth rate 0.16%/day
# dfdx: shape checked deep learning in rust
[](https://discord.gg/AtUhGqBDP5)
[](https://crates.io/crates/dfdx)
[](https://docs.rs/dfdx)
Ergonomics & safety focused deep learning in Rust.
**Still in pre-alpha state. The next few releases are planned to be breaking releases.**
Features at a glance:
1. :fire: GPU accelerated tensor library with shapes up to 6d!
2. Shapes with both compile and runtime sized dimensions. (e.g. `Tensor<(usize, Const<10>)>` and `Tensor<Rank2<5, 10>>`)
3. A large library of tensor operations (including `matmul`, `conv2d`, and much more).
1. All tensor operations shape and type checked at compile time!!
4. Ergonomic neural network building blocks (like `Linear`, `Conv2D`, and `Transformer`).
5. Standard deep learning optimizers such as `Sgd`, `Adam`, `AdamW`, `RMSprop`, and more.
`dfdx` is on [crates.io](https://crates.io/crates/dfdx)! Use by adding this to your `Cargo.toml`:
```toml
dfdx = "0.13.0"
```
See the documentation at [docs.rs/dfdx](https://docs.rs/dfdx).
[1] https://en.wikipedia.org/wiki/Automatic_differentiation#Reverse_accumulation
## Design Goals
1. Ergonomics the whole way down (both frontend interface & internals).
2. Check as much at compile time as possible (i.e. don't compile if something is not correct).
3. Maximize performance.
4. Minimize unsafe code[1]
5. Minimize Rc<RefCell<T>> used in internal code[2]
[1] Currently the only unsafe calls are for matrix multiplication.
[2] The only things that use `Arc` are tensors to store their data. `Arc` is used instead of `Box` to reduce
allocations when tensors are cloned.
## GPU acceleration with CUDA
Enable the `cuda` feature to start using the `Cuda` device! Requires the installation of nvidia's cuda toolkit. See [feature flags docs](https://docs.rs/dfdx/latest/dfdx/feature_flags/index.html) for more info.
## API Preview
Check [examples/](examples/) for more details.
1. 👌 Simple Neural Networks API, completely shape checked at compile time.
```rust
type Mlp = (
(Linear<10, 32>, ReLU),
(Linear<32, 32>, ReLU),
(Linear<32, 2>, Tanh),
);
fn main() {
let dev: Cuda = Default::default(); // or `Cpu`
let mlp = dev.build_module::<Mlp, f32>();
let x: Tensor<Rank1<10>, f32, Cpu> = dev.zeros();
let y: Tensor<Rank1<2>, f32, Cpu> = mlp.forward(x);
mlp.save("checkpoint.npz")?;
}
```
2. 📈 Ergonomic Optimizer API
```rust
type Model = ...
let mut model = dev.build_module::<Model, f32>();
let mut grads = model.alloc_grads();
let mut sgd = Sgd::new(&model, SgdConfig {
lr: 1e-2,
momentum: Some(Momentum::Nesterov(0.9))
});
let loss = ...
grads = loss.backward();
sgd.update(&mut model, &grads);
```
3. 💡 Const tensors can be converted to and from normal rust arrays
```rust
let t0: Tensor<Rank0, f32, _> = dev.tensor(0.0);
assert_eq!(t0.array(), &0.0);
let t1 /*: Tensor<Rank1<3>, f32, _>*/ = dev.tensor([1.0, 2.0, 3.0]);
assert_eq!(t1.array(), [1.0, 2.0, 3.0]);
let t2: Tensor<Rank2<2, 3>, f32, _> = dev.sample_normal();
assert_ne!(t2.array(), [[0.0; 3]; 2]);
```
## Fun/notable implementation details
### Module
```rust
pub trait Module<Input> {
type Output;
fn forward(&self, input: Input) -> Self::Output;
}
```
From this flexible trait we get:
1. Single & batched inputs (just have multiple impls!)
2. Multiple inputs/outputs (multi-headed modules, or rnns)
3. Behavior different when tape is present or not (**not** the .train()/.eval() behavior present in other libraries!).
### Tuples represent feedforward (a.k.a sequential) modules
Since we can implement traits for tuples, which is *not possible in other languages* AFAIK, they provide a very nice frontend
for sequentially executing modules.
```rust
// no idea why you would do this, but you could!
type Model = (ReLU, Sigmoid,Excerpt of 6,820 characters
Read on GitHub483
253
35
25
18
Nicolas Patry · @huggingface
9
Viliam Vadocz · Slovakia
6
5
Vasanthakumar Vijayasekaran
4
Periwink
3
3
3
3
2
2
2
2
chris m
2
1
Tristan F.-R. · Reed College · United States
1
Would you bet a product on this? Bounded 0–100 and slow moving.
matched fp:b7efab37ac68b52a, topic:deep-learning, topic:neural-network, readme:automatic differentiation
matched fp:b7efab37ac68b52a, topic:cuda-kernels
matched fp:b7efab37ac68b52a, topic:gpu, topic:cuda