A computation graph represents a mathematical expression as a directed graph: nodes hold operations or variables, and edges show how data flows between them. section 8.2.1
In machine learning, inputs and trainable parameters pass through operations to produce a prediction. Comparing that prediction with a target produces a loss, which connects the graph to training. section 8.2.1 section 8.2
A computation graph makes several training mechanics explicit:
- Operation nodes can represent multiplication, addition, sigmoid activation, or loss calculation. section 8.2.1
- Setting requires_grad=True on parameters allows PyTorch to track the quantities needed for gradient computation. section 8.2.1
- Calling loss.backward() traverses the graph backward and computes how weights and bias contributed to the loss. section 8.2.1
Logistic regression in PyTorch
For an input tensor x, compute z = sum(x * w) + b, apply sigmoid(z), compare the prediction with a target using binary cross-entropy, and call loss.backward() to obtain gradients for w and b. The same graph pattern scales from a single input to molecular activity models using 2,048-bit Morgan fingerprints and predicted EGFR pIC50 values. section 8.2







