Learning goals¶
Contrast finite differences with reverse-mode AD for residual losses
Explain why AD enables physics-informed training
Name practical pitfalls (discontinuous events, stiff residuals)
Reading¶
Automatic differentiation survey Baydin et al., 2015; backpropagation intuition Bishop & Bishop, 2024
Why AD matters for PINNs¶
Physics residuals need (and often parameter sensitivities). Finite differences are noisy and scale poorly. Automatic differentiation gives exact derivatives of the computational graph (up to machine precision) for the operations you coded.
In a typical collocation PINN:
Network maps
AD supplies
Residual enters
Forward vs reverse mode (intuition)¶
Forward mode: efficient with few inputs, many outputs
Reverse mode (backprop): efficient with many inputs (weights), few outputs (scalar loss) — the usual deep-learning case
PINN training almost always uses reverse mode on a scalar total loss.
Gradient scaling¶
AD gives exact gradients, but exact gradients can still point in an unhelpful direction when the loss terms have very different scales.
In the classical SMIB of SMIB dynamics, is in rad/s. It sits near , while its swing is a few rad/s. The angle is of order 1 rad. Unscaled, and the data term can dominate the total loss, so training mostly fits speed and neglects angle. Inverse problems have the same issue in parameter space: and have very different sensitivities.
Practical fixes, in the order to try them:
Non-dimensionalize states. Train on (or ) and , not raw .
Normalize each loss term by a typical magnitude, or report per-term losses so imbalance is visible.
Rescale parameters. Optimize and , or values divided by a nominal, inside stated bounds.
Weight terms explicitly ( and per-state weights) and report the weights used.
Plain words: the optimizer follows whichever number is biggest. Make the numbers comparable before trusting the fit.
Further reading: Thuerey et al. (2021) treat this problem in depth, including scale-invariant physics training and half-inverse gradients demonstrated on coupled oscillators. Those algorithms are beyond this course; the fixes above are enough for the labs.
Worked example¶
Differentiate w.r.t. with AD in PyTorch/torch.autograd and compare to .
Lab¶
Used implicitly in Labs 2–3 when you implement residual losses
Further reading¶
Framework AD docs; course prep notebook on gradients
Maths background (external, link only): gradient descent and convexity in the EECS 245 notes Rampure, 2026 (CC BY-NC-ND 4.0)
Common misconceptions¶
“AD is approximate like finite differences.” — For smooth elementary ops it is not.
Differentiating through discontinuous fault switches without careful event handling
Forgetting
create_graph=Truewhen higher-order derivatives are neededFeeding raw rad/s into a loss next to rad and blaming the optimizer
- Baydin, A. G., Pearlmutter, B. A., Radul, A. A., & Siskind, J. M. (2015). Automatic differentiation in machine learning: a survey. arXiv. 10.48550/arXiv.1502.05767
- Bishop, C. M., & Bishop, H. (2024). Deep Learning: Foundations and Concepts. Springer. 10.1007/978-3-031-45468-4
- Thuerey, N., Holzschuh, B., Holl, P., Kohl, G., Lino, M., Liu, Q., Schnell, P., & Trost, F. (2021). Physics-based Deep Learning. arXiv. 10.48550/arXiv.2109.05237
- Rampure, S. (n.d.). EECS 245 course notes. Retrieved October 14, 2026, from https://notes.eecs245.org/