Engineering Blog

Engineering Notes & Build Logs

Technical write-ups from building Dark Forest and Project Maximus: autograd debugging notes, SIMD memory alignment, fuzzing runs, and PyTorch parity post-mortems.

Oct 18, 2024
•By Swasthik Shetty•
commit: c4e1208

Stress-Testing Strided Tensors: 8,187 View Ops Under Miri

Exposing negative strides, transpositions, and multi-axis slicing to randomized mutation fuzzing.

Diagnostic Challenge

Negative strides combined with non-zero byte offsets caused an integer underflow in raw pointer arithmetic during reverse slicing.

Architectural Discovery

Raw pointers must always calculate offsets in signed isize before applying to the base NonNull<T> pointer.

#tensor#fuzzing#miri#memory-safety
Read Post
Oct 14, 2024
•By Swasthik Shetty•
commit: a8f3b91

Milestone 1 Passed: 200 Steps of Exact PyTorch Parity

How we verified Dark Forest autograd and AdamW against PyTorch with a max loss difference of 2.38e-7.

Diagnostic Challenge

Initial AdamW runs drifted by 1e-3 after step 30 due to an order-of-operations difference in weight decay vs gradient moments.

Architectural Discovery

PyTorch AdamW applies weight decay directly to param data before the moment step: p.data.mul_(1 - lr * wd). Once mirrored in Dark Forest, loss converged to 2.38e-7 difference.

#autograd#parity#milestone-1#optimizers
Read Post
Oct 2, 2024
•By Swasthik Shetty•
commit: 3f9011d

Building Ring All-Reduce over TCP Sockets from First Principles

Decentralized distributed gradient aggregation without MPI or InfiniBand dependencies.

Diagnostic Challenge

TCP socket buffering (Nagle algorithm) was batching tiny chunk packets, introducing 40ms transmission latency spikes.

Architectural Discovery

Setting TCP_NODELAY immediately restored line-rate ring transmission throughput.

#distributed#cluster#networking#allreduce
Read Post
Sep 25, 2024
•By Swasthik Shetty•
commit: 98d1a4e

Zero-Copy Python Interop with PyO3 and DLPack

Connecting native Rust tensors to NumPy and PyTorch without copying gigabytes of buffer memory.

Diagnostic Challenge

Holding the Python GIL during backward graph traversals froze the Python interactive interpreter.

Architectural Discovery

Releasing the GIL via py.allow_threads() lets CPU SIMD compute loops run across all physical cores simultaneously.

#python#pyo3#interop#dlpack
Read Post
Sep 20, 2024
•By Swasthik Shetty•
commit: e7192ab

Why 64-Byte Alignment Matters: Designing the Storage Core

Decoupling tensor storage from metadata and enforcing 64-byte cache line alignment.

Diagnostic Challenge

Standard Rust Vec<T> alignment is only 4 bytes for f32, causing AVX-512 unaligned load penalties on CPU.

Architectural Discovery

Using std::alloc::alloc with Layout::from_size_align(size, 64) guarantees single-cycle vector register loading.

#tensor#simd#memory#architecture
Read Post