docsgetting startedquickstart
Getting Started

Quickstart Guide

Add darkforest-core to Cargo.toml or run verified workspace targets from a clean clone.

Quickstart Guide

Compile and run a multi-step neural network training loop in Rust, or run the built-in verification binaries from a clean repository clone.

1. Add darkforest-core to Cargo.toml

toml
[dependencies]
anyhow = "1"
darkforest-core = { git = "https://github.com/hallow-mk3/Dark-Forest.git" }

2. Run a 5-Step TapeMLP + AdamW Training Loop (src/main.rs)

rust
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(())
}

3. Run Workspace Verification Targets from a Clone

bash
git clone https://github.com/hallow-mk3/Dark-Forest.git
cd Dark-Forest

# Run the 200-step SGD & AdamW MLP convergence test suite (CPU)
cargo test -p darkforest-core --test milestone1_mlp_test

# Run analytical vs finite-difference gradient check binary
cargo run --release -p darkforest-core --bin grad_check

# Run isolated CUDA attention kernel scaling benchmark (requires CUDA toolkit)
cargo run --release -p darkforest-core --bin bench_sequence_limit --features cuda