Tensor by Tensor

02.03 · UNIT 01 · PyTorch in One Hour: foundations · Lesson

Computation graphs

A computation graph draws a calculation as nodes and edges. Values flow from inputs to the loss.

PLAIN-LANGUAGE INTRODUCTION

What is this?

A computation graph draws a calculation as nodes and edges. Values flow from inputs to the loss.

One simple example

With x1=1.1, w1=2.2, and b=0, the net input is 2.42, sigmoid gives 0.9183, and the loss is tensor(0.0852).

What goes in?

Input tensors and parameter tensors for one example.

What comes out?

A loss value and a graph that records every step.

Why does it matter?

The same graph gives the path for backpropagation.

What is it not?

The graph does not compute the gradients by itself.

WORK THROUGH THE IDEA

See the idea in more detail

  1. A computation graph is a directed graph. Each node holds a value, and each edge passes a value.
  2. For logistic regression, the forward pass computes z = x1*w1 + b, then a = sigmoid(z), then the loss.
  3. The worked values are z = 2.42, a = 0.9183, and loss tensor(0.0852).
  4. PyTorch builds the graph in the background when a tensor tracks gradients.
  5. Common mistake: reading the graph as the gradient. Backpropagation walks the graph later.
Open the detailed notes ↗