Dark Forest
An open-source deep learning runtime written in Rust and CUDA, combining strided host tensors and iterative tape autograd with pre-allocated static GPU execution graphs and fused CUDA kernels.
200-step 8 → 16 → 8 → 4 MLP under SGD and AdamW.
Per-operator backward passes verified against ATen.
Stripped standalone executable vs >1,800 MB Python + PyTorch stack (excluding shared GPU driver/CUDA toolkit).
Workspace Crate Architecture
The repository splits host tensor math, CUDA kernel execution, Python FFI bindings, and reference model definitions into four Cargo workspace crates.
Strided Tensor & Tape Autograd
64-byte aligned buffers with signed strides enable zero-copy slicing and transpositions, paired with an iterative topological backward worklist and SGD/AdamW optimizers.
Static GPU Arenas & Fused CUDA Kernels
Contiguous startup device allocation eliminates per-step cudaMalloc/cudaFree jitter alongside custom CUDA kernels for online-softmax attention, layer normalization, and matmul.
TCP Ring All-Reduce Collectives
Distributed collective primitives (all_reduce_ring, reduce_scatter, broadcast) over TCP sockets with explicit peer rank handshakes and two-phase barriers.
PyO3 Python Bindings
Exposes Dark Forest tensors, layers, and optimizers to Python test suites for head-to-head step parity verification against PyTorch.
5-Step TapeMLP + AdamW Loop
use darkforest_core::nn::{TapeAdamW, TapeMLP};
use darkforest_core::tensor::Tensor;
fn main() -> anyhow::Result<()> {
let mlp = TapeMLP::new(&[8, 16, 8, 4])?;
let mut opt = TapeAdamW::default_lr(0.02);
let params = mlp.parameters();
let x = Tensor::randn(vec![16, 8], 1.0);
let targets = Tensor::from_slice_i64(
&[0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3],
vec![16],
)?;
for step in 0..5 {
mlp.zero_grad();
let logits = mlp.forward(&x)?;
let loss = logits.cross_entropy(&targets)?;
loss.backward(None, false)?;
opt.step(¶ms);
println!("step {step}: loss = {:.6}", loss.get(0));
}
Ok(())
}Project Maximus Phases
Parity with PyTorch
PyTorch 2.4+ Eager Mode
Parity with TensorFlow
Static Graph IR & Standalone Export
Parity with JAX
Composable Functional Transformations
Native Compilation & Kernel Optimization
[PENDING — Exit criteria to be defined]