promptdojo_

Autograd as a dependency graph — step 7 of 7

Checkpoint

One last thing before we move on. Same surface as a write step — but the lesson doesn't complete until this passes.

Train on your own autograd. For 3 steps: forward pred = w * x, err = pred - Value(target), loss = err * err; zero w.grad; loss.backward(); update w.data -= lr * w.grad; print f"step {step}: loss={loss.data:.3f} w={w.data:.3f}". Finish with f"final prediction: {(w * x).data:.2f}". This is chapter 39's training loop running on machinery you can read line by line.

full-screen editor opens — close anytime to keep reading.