Backpropagation › Computational Graphs
Language AI HandbookAll chapters Backpropagation › Computational GraphsOne section · Sections in this chapter3 / 20 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
Before diving into backpropagation, we need a way to visualize how computations flow through a network. A computational graph represents a mathematical expression as a directed graph where nodes are operations and edges show data flow.
Every neural network computation breaks down into elementary operations: addition, multiplication, matrix products, and activation functions. Consider the simple expression . This decomposes into two operations:
- (addition)
- (multiplication)
where:
- : input variables (leaf nodes in the graph)
- : an intermediate value storing the result of the first operation
- : the final output (the root node)
The graph shows data flowing left to right through intermediate nodes. Each node computes something simple, and the structure of the graph encodes the data dependencies. Each node only needs to know about its immediate inputs and output, not the rest of the network. This locality is what makes the chain rule tractable.
Neural Network as a Computational Graph
A neural network layer performs the computation , where:
- : the input vector
- : the weight matrix
- : the bias vector
- : the activation function
- : the output activations
This breaks into three atomic operations:
- (matrix multiplication)
- (bias addition)
- (nonlinear activation)
Each node has a well-defined local gradient. The power of computational graphs is that they make the structure of computation explicit, which is exactly what backpropagation needs. The forward pass computes values flowing left to right; the backward pass computes gradients flowing right to left.
When we compose multiple layers, we are simply building a larger graph. The loss node at the end is connected to the output layer, which is connected to the layer before it, and so on back to the input. The entire network is one big directed acyclic graph of operations, with parameters as leaf nodes and the loss as the root.
Why Computational Graphs Matter
Computational graphs provide two benefits for gradient computation:
- Modularity: Each node has a well-defined local gradient. We don't need to derive the gradient of the entire network at once, only the gradient of each primitive operation. This is the key insight that makes backprop practical: instead of deriving one giant formula for the gradient of the loss with respect to every parameter, we simply need to know the derivative of each individual operation, and the chain rule handles the composition.
- Efficiency: By storing intermediate values during the forward pass, we reuse them during the backward pass, avoiding redundant computation. Without this storage, we would have to recompute every intermediate value every time we needed it, which would make the backward pass much more expensive.
Deep learning frameworks like PyTorch and TensorFlow build exactly this kind of dynamic computational graph as code runs. Every arithmetic operation on a tensor implicitly creates a node in the graph, recording what inputs were used so the backward pass can reconstruct the gradient computation. You never see this graph directly, but it is being built silently behind every +, @, and activation function call you write.