Expand description
§Ferrotensor - GPU-Accelerated Machine Learning Library
A PyTorch-style tensor and neural-network API in pure Rust. Tensors live
on a Device: a GPU through wgpu (Metal, Vulkan, DX12) with hand-written
WGSL kernels, or the CPU, which needs no GPU and runs the same ops.
§Features
- Tensors: broadcasting element-wise math, reductions over any dim, batched matmul, softmax/log-softmax, permute, slicing, concatenation, gathers.
- Automatic differentiation: every op records its backward pass; gradients are checked against finite differences on the CPU and against the CPU on the GPU.
nn: Linear, Embedding, LayerNorm, RMSNorm, Dropout, multi-head (causal) attention, activations, Sequential.optim: SGD (momentum, Nesterov), AdamW, gradient clipping, warmup + cosine and other LR schedules.serialize: safetensors save/load and module state dicts.
§Quick Start
use ferrotensor::prelude::*;
let device = Device::cpu(); // or Device::best() for a GPU when present
let model = nn::Sequential::new(&device)
.add(nn::Linear::new(2, 16, &device))
.add(nn::Tanh)
.add(nn::Linear::new(16, 2, &device));
let mut opt = optim::AdamW::new(model.parameters(), 0.05).weight_decay(0.0);
// XOR
let x = Tensor::from_data(&[0., 0., 0., 1., 1., 0., 1., 1.], &[4, 2], &device);
let y = Tensor::from_data(&[0., 1., 1., 0.], &[4], &device);
for _ in 0..200 {
opt.zero_grad();
let loss = F::cross_entropy(&model.forward(&x), &y);
loss.backward();
opt.step();
}The LLM fine-tuning stack (LoRA, LFM2/Llama blocks, the CLI) is built on
ferrotensor-backend, ferrotensor-autograd and ferrotensor-graph.
Re-exports§
Modules§
- backend
- GPU Backend Module
- data
- Datasets and batched loading for the
ferrotensortensor API. - functional
- Functional Module
- nn
- Neural Network Module
- optim
- Optimizers
- prelude
- Prelude module - import everything you need with
use ferrotensor::prelude::* - serialize
- Model Serialization
- tensor
- Tensor Module
Structs§
- Device
- A compute device: the CPU or a GPU.