Automatic differentiation computes derivatives of recorded tensor operations according to the chosen objective.
Background
Python programs operate on objects through names. These examples refresh practical reasoning about values, state, interfaces, and scientific calculations. Run them in a disposable local environment and inspect the result.
Automatic differentiation computes derivatives of recorded tensor operations according to the chosen objective.
Work through an example
For a scalar parameter w and loss (w - 3) squared, the derivative is 2 times (w - 3). At w = 1 it is -4, so a small gradient-descent step increases w toward three.
Check the reasoning
Gradients can accumulate across backward calls unless cleared appropriately. Distinguish computing a gradient, applying an optimizer step, and evaluating a model without recording gradients. Tensor shapes still determine whether the intended objective was formed.
Practice independently
Compute the derivative above by hand at two values, compare with autograd, and inspect the gradient before and after a second backward pass.
Write down your prediction before consulting the result or revisiting the passage. Explain which observation supports your answer and which part depends on an assumption. Revise the explanation if the evidence does not fit. A useful study note records both the conclusion and the steps another learner would need to check it.
Reference
For the language or library contract, consult the PyTorch autograd tutorial.
Continue with the course
Explore the curriculum, preparation, and study format for Python Refresher — Course Articles.
Companion article for Python Refresher — Course Articles. Original commentary and examples © 2026 Choral Software. Source literary works retain their own attribution.
