promptdojo_promptdojo_promptdojo_promptdojo_promptdojo_promptdojo_promptdojo_promptdojo_promptdojo_promptdojo_promptdojo_

Autograd as a dependency graph — step 7 of 7

Checkpoint

One last thing before we move on. pass this to mark the lesson done, or skip and keep moving. hop to the next when you're ready.

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.