Skip to content
Glacius
CalculusConcept reference

Forward evaluation

Forward evaluation computes each graph operation after all of its input values are known.

On this page 8 sections
  1. Overview
  2. A forward pass evaluates a computation from known inputs to outputs
  3. Branches may be evaluated in either order if they do not depend on each other
  4. The dependency arrows decide what comes next
  5. A closer look
  6. Key takeaway
  7. Sources & further reading
  8. Concept connections

01A forward pass evaluates a computation from known inputs to outputs#

A forward pass evaluates a computation from known inputs to outputs. At every operation, substitute the values produced by its input nodes. Storing these intermediate results makes a complicated calculation traceable and supplies the values needed to evaluate derivatives later.

A forward pass computes the graph’s values. Start with known inputs; evaluate a node only after every value it uses is available.

A schematic forward pass at x=2. First compute u=x+4=6, then y=u²=36. The values flow from x to u to y. Node position is schematic.A schematic forward pass at x=2. First compute u=x+4=6, then y=u²=36. The values flow from x to u to y. Node position is schematic.
Figure 1A schematic forward pass at x=2. First compute u=x+4=6, then y=u²=36. The values flow from x to u to y. Node position is schematic.
Link to this figure ↗Download SVGDownload PNG

Here x=2x=2, u=x+4u=x+4, and y=u2y=u^2. Compute u=6u=6 first. The square then receives 66, giving y=36y=36.

Squaring the original xx would give 44, which evaluates a different expression.

For a=x+1a=x+1, b=a2b=a^2, and y=b2ay=b-2a at x=2x=2, calculate a=3a=3 before b=9b=9. Then compute y=92(3)=3y=9-2(3)=3. The shared value a=3a=3 is used twice. Replacing the second use with the original input 2 would change the function.

Check your reasoning

u=x+5u=x+5 and y=u2y=u^2. At x=2x=2, find yy.

Show answer and explanation
49

First u=2+5=7u=2+5=7; then y=(7)2=49y=(7)^2=49.

02Branches may be evaluated in either order if they do not depend on each other#

Branches may be evaluated in either order if they do not depend on each other. With x=2x=2, u=x2u=x^2, v=3xv=3x, and y=u+vy=u+v, compute u=4u=4 and v=6v=6 before the join.

y=4+6=10y=4+6=10
Check your reasoning

A score uses u=x2u=x^2, v=2xv=2x, and y=u+vy=u+v. At x=3x=-3, find yy.

Show answer and explanation
3

Compute both branches: u=9u=9 and v=6v=-6. Their sum is 33.

03The dependency arrows decide what comes next#

The dependency arrows decide what comes next. A node needs its immediate inputs, even if the expression contains the same original variable several times.

Keep each intermediate value until all of its consumers have used it.

Check your reasoning

u=x+6u=x+6 and y=u2y=u^2. At x=3x=3, a learner uses y=x2y=x^2. Repair the final value yy.

Show answer and explanation
81

First u=3+6=9u=3+6=9; then y=(9)2=81y=(9)^2=81.

04A closer look#

Before debugging a gradient, check that the forward pass computes the intended prediction and loss. A perfectly implemented derivative of the wrong computation still trains the wrong model. Each stored value belongs to the current input and parameter setting.

Key takeaway

Follow the dependencies and use each computed intermediate value.

  • Evaluate a small computational graph in dependency order.

Sources & further reading

  1. [1]
    Stanford CS231n: BackpropagationStanford CS231n · Article

Reference this concept

Link to this page, a section, or an individual figure.

Glacius. “Forward evaluation.” Math behind ML. /learn/c-forward