Automatic Differentiation from Scratch: How PyTorch Computes Gradients in Physics-Informed Neural Networks
Abstract
This paper traces, with explicit numerical values, how PyTorch's automatic differentiation (AD) engine computes gradients for Physics-Informed Neural Network (PINN) training -- a setting that requires two levels of differentiation: computing the physics derivative through the network, and computing parameter gradients of a loss that itself depends on . Using a 1-3-3-1 multilayer perceptron and the initial value problem , , we trace the complete pipeline at every node: the computational graph built during the forward pass, the reverse-mode backward traversal that computes all 22 parameter gradients in a single pass, and the graph-on-graph mechanism by which \texttt{create\_graph=True} enables correct differentiation through the physics-informed residual. Every adjoint value is verified against the hand derivations of Tahimi (2026), connecting the sensitivity framework to the vector--Jacobian products used by PyTorch's autograd engine.
Cite
@article{arxiv.2607.13042,
title = {Automatic Differentiation from Scratch: How PyTorch Computes Gradients in Physics-Informed Neural Networks},
author = {Abdeladhim Tahimi},
journal= {arXiv preprint arXiv:2607.13042},
year = {2026}
}
Comments
25 pages, 9 figures. Educational tutorial on automatic differentiation for Physics-Informed Neural Networks (PINNs) using PyTorch. Includes complete numerical derivations and computational graph analysis