Neural Networks: From Fundamentals to Modern AI · PyTorch Environment and Tensor Foundations
Autograd: computational graph, backward() and grad_fn
PyTorch Environment and Tensor Foundations
Introduction
Autograd is PyTorch's automatic differentiation engine — it dynamically builds an operation graph during forward and traverses it backwards in backward(), producing .grad on all leaf tensors flagged with requires_grad=True. This lesson breaks down: the trigger of graph construction, the grad_fn attribute, the difference between leaf and non-leaf tensors, gradient accumulation in .grad, the no_grad context, and the pitfalls of in-place operations.