PyTorch .backward() is just a graph traversal in disguise PyTorch's .backward() method performs a graph traversal that applies the chain rule node-by-node rather than deriving a global formula, according to a technical explainer. The article uses the example z = 2x^2 + 1 with x=3, where the backward pass multiplies local slopes (1, 2, and 6) to yield a gradient of 12 stored in x.grad. This mechanism underpins parameter updates in neural networks and large language models without handwritten derivatives. PyTorch .backward is just a graph traversal in disguise requires grad and .backward at you, plug them into a training loop, and leave you wondering what actually happened under the hood. It feels like magic until you realize that PyTorch is essentially just keeping a meticulous receipt of every operation you perform. If you can do a derivative by hand on a scrap of paper, you've already done the work PyTorch does—you were just slower at it. The logic of the gradient Before hitting the code, remember that a gradient is simply the slope of the ground under your feet. If you're on a hillside in thick fog, the gradient tells you which way is "down." In a model, the horizontal axis is a parameter and the vertical axis is the loss. If the slope is positive, you move left to lower the loss; if it's negative, you move right. Take $y = x^2$. The derivative is $2x$. If $x = 3$, the slope is $6$. PyTorch handles this without needing the explicit formula: python import torch x = torch.tensor 3.0, requires grad=True y = x 2 y.backward print x.grad tensor 6. The "Tape" and the Computation Graph Tensors don't track gradients by default because doing so for every single input would be a massive waste of memory. You opt-in using requires grad=True . Once you do, PyTorch starts recording. This "recording" is the computation graph. It's a directed chain where nodes are operations and edges are tensors. When you run a forward pass, PyTorch computes the result and simultaneously builds this graph. x = torch.tensor 3.0, requires grad=True y = x 2 node: power z = 2 y + 1 nodes: multiply, then add In this scenario, x is a leaf node because it was created directly. Every subsequent result node like y and z stores a grad fn . This isn't the operation itself, but the specific instruction on how to reverse that operation during the backward pass. print z.grad fn