Hong Kong Baptist University · FACULTY OF COMPUTER SCIENCE

MATH7005 Chap.6 Backpropagation Through Layers

- one subject, every graph, every model, every mark
6 Chapters3-page Bible
Our own words - no uploaded lecturer files
Updated for this semester
Chapter 6 of 10 · MATH7005

Backpropagation Through Layers

Influence traced in reverse

Backpropagation reuses the forward computation graph to organise the chain rule. An upstream gradient arrives from the loss, each operation contributes a local derivative and shared paths add their contributions.

The chapter begins with a scalar graph before restoring matrix shapes and automatic differentiation.

What to verify

Store forward intermediates, label derivative directions and compare a selected analytic or automatic gradient with a centred finite difference.

Layerwise gradient norms then show where signals vanish, explode or disappear from the graph.

Paths multiply and branches add

A valid chain links neighbouring derivatives through a shared intermediate variable. When one value influences the loss through several later operations, calculate every path contribution and sum them at the branch point.

Residual connections create a direct identity route alongside a transformed route, and omitting either produces an incomplete gradient.

Batch reductions affect magnitude

Every record contributes to parameter gradients. A summed loss adds those contributions, while a mean loss divides by batch size. The two objectives have the same minimiser under fixed conditions but produce differently scaled updates.

Match the backward interpretation to the reduction used by the loss function before comparing learning rates.

Automatic differentiation still needs tests

A framework follows the graph it was given, including accidental detachments, in-place modifications and hard decisions. Check for missing and non-finite gradients, clear accumulation buffers at the intended time and finite-difference a small parameter.

Layerwise norms locate where a problem begins more effectively than one global gradient statistic.

In this chapter

What this chapter covers

  • 01

    Computation graph

  • 02

    Upstream gradient

  • 03

    Local derivative

  • 04

    Chain-rule product

  • 05

    Branch accumulation

  • 06

    Finite-difference check

Worked example · free

Differentiate a short scalar chain

Q [7 marks]. Let z = 3x, a = z squared and L = a + 2. Find dL/dx at x = 2. The problem was written for AskSia study; the marks here are not a University mark allocation.
The computation graph is traversed twice.The computation graph is traversed twice. Forward values establish where derivatives are evaluated; the reverse pass combines an upstream gradient with each local slope.Forward values move right; gradients reuse the graph in reversexz¹,a¹z²,a²Lmultiply upstream gradient by each local derivativeStore forward intermediates once; accumulate gradients where paths meet.
The computation graph is traversed twice. Forward values establish where derivatives are evaluated; the reverse pass combines an upstream gradient with each local slope.
  • 2Evaluate the forward values.
  • 3Write each local derivative.
  • 2Multiply along the connected path.
At x = 2, z = 6. The local derivatives are dL/da = 1, da/dz = 2z = 12 and dz/dx = 3. Their product gives dL/dx = 36.
Sia tip — Each neighbouring derivative must share the variable that cancels in the chain.
Glossary

Key terms

Computation Graph
A directed record of operations and intermediate values linking inputs to a final result.
Upstream Gradient
The sensitivity of the final loss to the current operation output.
Local Derivative
The derivative of one operation output with respect to its direct input.
Gradient Check
A comparison between a computed derivative and a small finite-difference approximation.
Vanishing Gradient
A gradient signal that becomes extremely small as it passes through earlier layers.
FAQ

Backpropagation Through Layers FAQ

What does backpropagation add to the chain rule?

It organises and reuses intermediate derivatives across a computation graph, avoiding repeated calculation of the same subexpressions. The mathematics remains the chain rule, applied efficiently in reverse order.

Why store pre-activations during the forward pass?

Activation derivatives are evaluated at those pre-activation values. Discarding them forces recomputation or makes the backward result depend on an incorrect value, especially for gates such as ReLU.

Why perform a finite-difference check?

It offers an independent numerical approximation for a selected parameter. Close agreement supports the backward implementation, while disagreement exposes a sign, graph or stale-value error before a full training run.

What happens when a value feeds two later operations?

The loss depends on that value through both paths, so backpropagation computes each path contribution and adds them at the shared node. Overwriting one branch gives an incomplete gradient even when every local derivative is correct.

Why can gradients double between identical batches?

Many frameworks accumulate into existing gradient buffers. If those buffers are not cleared at the intended time, a repeated batch adds another contribution. Deliberate accumulation is valid, but its reduction and update schedule must be documented.

What does a layerwise gradient norm reveal?

It locates where the backward signal becomes tiny, explosive or absent. Compare successive layers and several batches rather than one global value, then connect the pattern to activation saturation, disconnected paths or unstable updates.

Why use a centred finite difference?

Evaluating the loss on both sides of a parameter cancels more first-order approximation error than a one-sided check. Choose a small but representable step and compare only a few coordinates because numerical checking is expensive.

Study strategy

Assessment move

Draw a scalar graph with one branch and one shared parameter. Place forward values above the nodes, derivative labels on edges and accumulated gradients below the nodes. Work backward from the loss without skipping variables, then perturb one parameter in both directions to obtain a centred finite-difference check. Extend the ledger to a dense layer by writing activation, weight and delta shapes.

In code, verify that gradient buffers are cleared, print missing or non-finite values and compare layerwise norms. Add a residual route and explain why its identity contribution is summed with the transformed contribution. Keep one tiny gradient-check case in the project tests so later refactoring cannot silently break the computation graph.

Working through Backpropagation Through Layers in MATH7005? Sia is AskSia’s AI Computer Science tutor — ask any MATH7005 Backpropagation Through Layers question and get a clear, step-by-step explanation grounded in how MATH7005 is taught and assessed. Read this chapter free, then take your hardest questions to Sia.

A+Everything unlocked
Unlocks this Bible + all 12 of your Hong Kong Baptist University subjects - and 1,000+ Bibles across every Australian university.
Sia - your MATH7005 tutor, unlimited, worked the way the exam marks it
The full 3-page Bible + practice bank with worked solutions
Chrome extension - sync your LMS so Sia knows your deadlines
Bilingual EN / Chinese on every Bible and every Sia answer
$0.99 Trial
30-day money-back · cancel in one tap · how it works