What is Computational graph?

A representation of a model's computation with operations as nodes and tensor flows as edges, underpinning automatic differentiation and AI compiler optimization.

Field: AI Hardware & Software Stack

Japanese name: 計算グラフ

Nodes, edges and what they carry

A computational graph is usually a directed acyclic graph. Nodes are operations such as matrix multiplication, convolution, addition or an activation function; edges are tensors, each with a known shape and data type, flowing from the operation that produces them to the ones that consume them. Inputs and trainable weights appear as source nodes. Because dependencies are explicit, the graph shows at a glance which operations can run in parallel and which must wait, and it gives software a complete, analyzable description of the model independent of the Python code that created it.

Graphs and automatic differentiation

Training needs the gradient of the loss with respect to every weight. During the forward pass a framework records the graph; reverse-mode automatic differentiation then walks it backward from the loss, applying each operation's local derivative rule and the chain rule to accumulate gradients, which is backpropagation. This requires the intermediate outputs (activations) saved from the forward pass, which is why training uses far more memory than inference. Activation checkpointing trades compute for memory by discarding some activations and recomputing them during the backward pass.

Static vs. dynamic graphs

In a static, define-and-run style, the whole graph is built first and then executed, which makes global optimization easy but complicates data-dependent control flow and debugging. In a dynamic, define-by-run or eager style, operations execute immediately as the program runs and the graph is recorded on the fly, which is flexible but leaves little room for optimization across operations. Many frameworks mix the two: code is written eagerly, and a compile step traces or captures the graph so that a compiler can optimize it before execution.

What compilers and runtimes do with it

AI compilers rewrite the graph before generating code. Operator fusion merges chains such as matrix multiply, bias add and activation into one kernel so intermediate tensors stay in on-chip memory instead of making a round trip to DRAM. Other passes include constant folding, removal of unused nodes, choice of tensor memory layout, tiling to fit caches or scratchpads, and memory planning that reuses buffers whose lifetimes do not overlap. Exchange formats such as ONNX (Open Neural Network Exchange) serialize the graph and weights so different runtimes and hardware toolchains can execute the same model.

Try it: questions about Computational graph

Which describes the computational graph used by AI frameworks and compilers?

  1. AA line chart of AI performance by year
  2. BA chart showing how the training loss changes
  3. CA representation of a model's computation with operations as nodes and tensor flows as edges
Show answer and explanation

Answer: C. A representation of a model's computation with operations as nodes and tensor flows as edges

A computational graph is a blueprint of a model's computation, with operations such as matrix products, additions and activations as nodes and the tensors flowing between them as edges. Frameworks traverse it backward to compute backpropagation gradients automatically, and compilers optimize it as a whole through fusion and reordering. The graph also shows which operations are independent and can run in parallel.

FAQ

What is a computational graph in deep learning?

It is a representation of a model as operations (nodes) connected by the tensors they pass to each other (edges). Frameworks use it to compute gradients automatically and compilers use it to optimize execution.

Why does operator fusion speed up neural networks?

Many operations, such as activations and normalization, are memory-bound, so writing their outputs to DRAM and reading them back dominates the time. Fusing them into one kernel keeps intermediates on chip and cuts memory traffic.

What is the difference between eager execution and graph mode?

Eager execution runs each operation immediately as Python reaches it, while graph mode builds or captures the whole graph first and then optimizes and runs it. Eager is easier to debug; graph mode allows fusion and other whole-model optimizations.

Questions that mention Computational graph (3)

Computational graph appears in 4 practice questions across 1 topic, including AI Hardware & Software Stack.

  1. What do AI compilers such as XLA, TVM or PyTorch's compile feature mainly do?
  2. Which describes ONNX?
  3. Which orders the AI software stack from the layer closest to users down to the layer closest to hardware?

Books on AI Hardware & Software Stack Ad

As an Amazon Associate I earn from qualifying purchases.

This page was drafted with AI and fact-checked by a separate AI review before publication. Our Editorial policy explains how we write and check content. If you spot an error, please tell us on our Contact page.

Back to the glossary