📊 Computational Graph
Leaf Tensor
Operation
Output
💻 PyTorch Code
import torch
# Create leaf tensors with
requires_grad=True
x = torch.tensor(2.0, requires_grad=True)
w = torch.tensor(3.0, requires_grad=True)
b = torch.tensor(1.0, requires_grad=True)
# Forward pass (builds the graph)
y = w * x # y = 3 * 2 = 6
z = y + b # z = 6 + 1 = 7
# Backward pass (computes
gradients)
z.backward() # ← Click the button!
# Access gradients:
# x.grad = 3 (dz/dx = w)
# w.grad = 2 (dz/dw = x)
# b.grad = 1 (dz/db = 1)
Click backward() to see gradient flow