Forward Pass
Computing the output of a neural network from input to prediction
A forward pass is the process of feeding input data through a neural network layer by layer to produce an output (prediction). Each layer applies its weights and activation functions in sequence.
Example
import torch
import torch.nn as nn
model = nn.Sequential(
nn.Linear(784, 256),
nn.ReLU(),
nn.Linear(256, 10),
)
model = model.cuda()
x = torch.randn(32, 784, device="cuda") # batch of 32
output = model(x) # forward pass → shape [32, 10]
Key Points
- Computes predictions from input data
- Each layer's intermediate outputs are called activations
- Activations are stored in memory during training (needed for backpropagation)