Automatic Differentiation from Scratch: How PyTorch Computes Gradients in Physics-Informed Neural Networks
This paper traces, with explicit numerical values, how PyTorch's automatic differentiation engine computes gradients for Physics-Informed Neural Network training, including physics derivative computation and parameter gradients. Using a 1-3-3-1 multilayer perceptron and a simple ODE, it details the computational graph, reverse-mode backward traversal, and the graph-on-graph mechanism for correct differentiation through physics-informed residuals.
-->
[Submitted on 13 Jun 2026]
Title:Automatic Differentiation from Scratch: How PyTorch Computes Gradients in Physics-Informed Neural Networks
View a PDF of the paper titled Automatic Differentiation from Scratch: How PyTorch Computes Gradients in Physics-Informed Neural Networks, by Abdeladhim Tahimi
View PDF HTML (experimental)
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 $\hat{y}'(t)=d\hat{y}/dt$ through the network, and computing parameter gradients $\nabla_\theta L$ of a loss that itself depends on $\hat{y}'(t)$. Using a 1-3-3-1 multilayer perceptron and the initial value problem $y'(t)+y(t)=0$, $y(0)=1$, 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 $P/Q$ sensitivity framework to the vector--Jacobian products used by PyTorch's autograd engine.
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
Subjects:
Machine Learning (cs.LG); Mathematical Software (cs.MS); Numerical Analysis (math.NA)
MSC classes: 65D25, 65-01, 68T07, 65L05
ACM classes: G.1.0; I.6.8
Cite as: arXiv:2607.13042 [cs.LG]
(or arXiv:2607.13042v1 [cs.LG] for this version)
https://doi.org/10.48550/arXiv.2607.13042
arXiv-issued DOI via DataCite
Submission history
From: Abdeladhim Tahimi [view email] [v1] Sat, 13 Jun 2026 11:24:13 UTC (609 KB)
Full-text links:
Access Paper:
View a PDF of the paper titled Automatic Differentiation from Scratch: How PyTorch Computes Gradients in Physics-Informed Neural Networks, by Abdeladhim Tahimi
View PDF
HTML (experimental)
TeX Source
view license
Current browse context:
cs.LG
new | recent | 2026-07
Change to browse by:
cs cs.MS cs.NA math math.NA
References & Citations
NASA ADS
Google Scholar
Semantic Scholar
Loading...
Data provided by:
Bibliographic Tools
Bibliographic and Citation Tools
Bibliographic Explorer Toggle
Bibliographic Explorer (What is the Explorer?)
Connected Papers Toggle
Connected Papers (What is Connected Papers?)
Litmaps Toggle
Litmaps (What is Litmaps?)
scite.ai Toggle
scite Smart Citations (What are Smart Citations?)
Code, Data, Media
Code, Data and Media Associated with this Article
alphaXiv Toggle
alphaXiv (What is alphaXiv?)
Links to Code Toggle
CatalyzeX Code Finder for Papers (What is CatalyzeX?)
DagsHub Toggle
DagsHub (What is DagsHub?)
GotitPub Toggle
Gotit.pub (What is GotitPub?)
Huggingface Toggle
Hugging Face (What is Huggingface?)
ScienceCast Toggle
ScienceCast (What is ScienceCast?)
Demos
Demos
Replicate Toggle
Replicate (What is Replicate?)
Spaces Toggle
Hugging Face Spaces (What is Spaces?)
Spaces Toggle
TXYZ.AI (What is TXYZ.AI?)
Related Papers
Recommenders and Search Tools
Link to Influence Flower
Influence Flower (What are Influence Flowers?)
Core recommender toggle
CORE Recommender (What is CORE?)
IArxiv recommender toggle
IArxiv Recommender (What is IArxiv?)
Author
Venue
Institution
Topic
About arXivLabs
arXivLabs: experimental projects with community collaborators
arXivLabs is a framework that allows collaborators to develop and share new arXiv features directly on our website.
Both individuals and organizations that work with arXivLabs have embraced and accepted our values of openness, community, excellence, and user data privacy. arXiv is committed to these values and only works with partners that adhere to them.
Have an idea for a project that will add value for arXiv's community? Learn more about arXivLabs.
Which authors of this paper are endorsers? | Disable MathJax (What is MathJax?)