Skip to course content
Free PyTorch course

Advanced Deep Learning with PyTorch

Module 03 Knowledge Check

5 questions. Pass mark 4 out of 5. Answer every question before checking the answer key below, then retry after reading the feedback.

1. Why must a loss be a single scalar?

2. For y = w * x with x = 3 and w tracked, what is w.grad after y.backward()?

3. You call .backward() twice without clearing. What is in .grad?

4. After optimizer.zero_grad() in current PyTorch, what is parameter.grad?

5. You train on data generated by y = 2x0 - 3x1 + 1 and the loss falls steadily. What confirms the loop is correct?

---

Answer Key and Explanations

Check these only after attempting every question.

1. B — Gradients are defined with respect to a scalar

.backward() computes derivatives of one number with respect to the parameters. A loss returning several numbers cannot be backpropagated as-is.

2. C — 3.0

dy/dw = x = 3. Verifying a gradient by hand on a case this small is the fastest way to confirm autograd is doing what you expect.

3. B — The sum of both gradients

Gradients accumulate by design, which supports splitting a large batch. Forgetting to clear means every step uses the sum of all previous ones.

4. B — None

Since 2.0 the default releases the tensor rather than filling it — cheaper. Code reaching for .grad.abs() straight afterwards raises AttributeError. Pass set_to_none=False for the old behaviour.

5. B — The learned weights approaching [2.0, -3.0] and bias 1.0

A falling loss happens for buggy loops too. Recovering the known parameters is a much stronger check.

Practical Check

Apply this module to your own work: complete the module activity for *Autograd, Loss, Backpropagation, and Training Loops*, then write one sentence naming what your result shows and one naming what it does not.

Strong Answer Pattern

A strong answer names the task, the evidence used, the check performed, and the remaining limitation. It avoids "proved", "guaranteed", or "always" unless the evidence genuinely supports it.