Deep Learning · Module 5
Answers and explanations · Give each training-loop line a job
Compare these references after your own attempt. You can read them at any time; they do not record a live model or vendor run.
Deep Learning · Module 5
Compare these references after your own attempt. You can read them at any time; they do not record a live model or vendor run.
05A. Clearing after backward removes the gradients the optimizer needs. For an ordinary batch: zero_grad, forward, loss, backward, step. Deliberate gradient accumulation uses a different explicitly scaled schedule.
05B. Correct mean=(4×0.5+4×1+2×3)/10=1.2. Unweighted mean=(0.5+1+3)/3=1.5, over-weighting the smallest batch.
05C. Eval-mode Linear still produces a gradient-tracked output because parameters require gradients and recording is on. Inside no_grad, the computed output is not tracked. Module behavior and graph recording are separate controls.