Core ML Runtime • Project Maximus

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.

MILESTONE 1 VERIFIED PARITY GATE
Reference Baseline: PyTorch 2.4.0 Eager Mode
Max Step Loss Delta
2.38 × 10⁻⁷

200-step 8 → 16 → 8 → 4 MLP under SGD and AdamW.

Gradient Checks
17 / 17 Cross-Checks

Per-operator backward passes verified against ATen.

Native Binary Size
< 12 MB

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.

Crate: darkforest-core

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.

Crate: darkforest-cuda

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.

Module: darkforest-core::cluster

PyO3 Python Bindings

Exposes Dark Forest tensors, layers, and optimizers to Python test suites for head-to-head step parity verification against PyTorch.

Crate: darkforest-py
Verified Example

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(&params);
        println!("step {step}: loss = {:.6}", loss.get(0));
    }
    Ok(())
}
Roadmap

Project Maximus Phases

Phase 01ACTIVE

Parity with PyTorch

PyTorch 2.4+ Eager Mode

Phase 02

Parity with TensorFlow

Static Graph IR & Standalone Export

Phase 03

Parity with JAX

Composable Functional Transformations

Phase 04

Native Compilation & Kernel Optimization

[PENDING — Exit criteria to be defined]