PyTorch Automatic Differentiation for Physics-Informed Neural Networks Explained

Abdeladhim Tahimi· July 16, 2026 View original

Summary

This paper provides a detailed, numerical trace of how PyTorch's automatic differentiation engine computes gradients for Physics-Informed Neural Networks (PINNs). It explicitly demonstrates the computational graph, reverse-mode backward traversal, and the graph-on-graph mechanism for two levels of differentiation required in PINN training.

This research offers an in-depth, step-by-step explanation of PyTorch's automatic differentiation (AD) engine, specifically focusing on its application within Physics-Informed Neural Networks (PINNs). PINN training uniquely requires two distinct levels of differentiation: first, computing physics derivatives through the neural network itself, and second, calculating parameter gradients for a loss function that depends on these physics derivatives. The paper meticulously traces the entire computational pipeline using a simple 1-3-3-1 multilayer perceptron and an initial value problem as an example. The explanation covers the construction of the computational graph during the forward pass, followed by the reverse-mode backward traversal, which efficiently computes all parameter gradients in a single pass. A key aspect highlighted is the "graph-on-graph" mechanism enabled by `create_graph=True`, which is essential for correctly differentiating through the physics-informed residual term. Every adjoint value in the process is verified against hand derivations, establishing a clear connection between the P/Q sensitivity framework and the vector-Jacobian products utilized by PyTorch's autograd engine. This detailed breakdown provides a foundational understanding of how complex gradient computations are handled in such specialized neural network architectures.

Why it matters

For AI engineers and researchers working with PINNs or custom differentiation requirements, this paper offers a fundamental understanding of PyTorch's autograd, enabling more effective debugging, optimization, and development of advanced models.

How to implement this in your domain

  1. 1Review the paper's numerical examples to deepen understanding of PyTorch's AD mechanics.
  2. 2Apply the insights to debug gradient computation issues in custom neural network architectures.
  3. 3Utilize `create_graph=True` effectively when implementing higher-order derivatives in PINNs or similar models.
  4. 4Develop custom autograd functions with a clearer understanding of vector-Jacobian products.
  5. 5Educate team members on the intricacies of automatic differentiation for specialized AI tasks.

Who benefits

Scientific ComputingEngineering SimulationAI ResearchMaterials ScienceClimate Modeling

Key takeaways

  • The paper details PyTorch's AD for Physics-Informed Neural Networks (PINNs).
  • It explains the computational graph and reverse-mode backward traversal.
  • The "graph-on-graph" mechanism for higher-order differentiation is clarified.
  • Understanding AD is crucial for debugging and optimizing complex AI models.

Original post by Abdeladhim Tahimi

"arXiv:2607.13042v1 Announce Type: new 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:…"

View on X

Originally posted by Abdeladhim Tahimi on X · view source

Want to go deeper?

Turn these trends into skills with Learnijoy's hands-on AI & tech courses.

Explore courses