Hi everyone,
For the last few months (since last year) I've been working on FastNN, a neural network library in Rust and CUDA. It started as a way to understand how autograd really works under the hood, and it slowly grew into something I can train real models with, so I decided to put it out there.
What it has right now:
- Tensors with broadcasting, batched matmul, reductions and views, on CPU or CUDA
- Reverse mode autograd with no tape or global state, plus
no_grad, anomaly detection and grad clipping - Common layers (Linear, conv, pooling, norms, dropout, embedding, LSTM, GRU)
- Transformer encoder/decoder, KV cache, top-k/top-p sampling and beam search
- The usual optimizers (Adam, AdamW, Lion, etc.) and LR schedules
- Checkpoints that save the full training state, so you can stop a run and resume it exactly. It can also read and write safetensors
CPU is the default. CUDA is behind a feature flag: build.rs compiles the kernels with nvcc, matmul goes through cuBLAS, and GPU memory uses a simple size-keyed free list.
cargo add fastnn cargo add fastnn --features cuda [paste the MNIST quick start snippet from your README here]
There are examples for MNIST (MLP and CNN), a small GPT-style char model, a GAN, a VAE, REINFORCE and a few others. Run them with --release, because debug builds are really slow (around 50x).
Things I know aren't great yet:
- Compute is f32 only. F16/BF16 checkpoints get widened on load
- Tensors are always contiguous, so
permuteandexpandcopy - LSTM/GRU are built from regular ops, so they're fine for short sequences but slow for long ones
- CUDA on Windows should build, but I haven't tested it
Where I'd really like feedback:
- The autograd design. Parameters are shared handles between the model and the optimizer. It works, but I'm not sure it's the most idiomatic way to do it in Rust
- Error handling. Most ops panic and there are
try_variants that returnResult. Is that a reasonable split, or would you expectResulteverywhere? - The CUDA FFI side, if anyone has experience with it
Also if you give it a star, I will be really grateful and motivated to work more on this library. I think there is such a beautiful future in this library.
Repo: GitHub - CanReader/FastNN: A high-performance neural network library built with Rust and CUDA for blazing-fast deep learning · GitHub
Docs: fastnn - Rust
1 post - 1 participant
