Back to Blog
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.

Milestone 1 Passed: 200 Steps of Exact PyTorch Parity

2024-10-14 • By Swasthik Shetty •commit: a8f3b91
What Broke

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

What Was Learned

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.

Today marks the official passage of Milestone 1 in Project Maximus.

The Parity Gate

The gate criteria required running a Multi-Layer Perceptron (MLP) for 200 training steps side-by-side with PyTorch 2.4 on synthetic Gaussian data, verifying loss, gradient vectors, and parameter updates after every step.

code
test_mlp_200_steps_adamw_parity ... PASSED (max loss diff: 2.38e-7)
test_mlp_200_steps_sgd_momentum ... PASSED (max loss diff: 1.14e-7)

What Broke

When we initially ran step 50, the loss difference started growing:

  • Step 1: 0.0
  • Step 20: 3.2e-6
  • Step 50: 1.4e-3 (Divergence!)

We discovered that PyTorch's decoupled weight decay formulation in torch.optim.AdamW performs parameter decay in-place before updating the velocity buffers. In our first implementation, we factored weight decay into the gradient buffer g_t = g_t + lambda * theta_(t-1). That single mathematical discrepancy was causing cumulative drift.

What Was Learned

Never approximate optimizer updates. Every single term in IEEE-754 floating-point operations must be matched in exact topological order to guarantee parity.