Automatic Differentiation from Scratch: How PyTorch Computes Gradients in Physics-Informed Neural Networks

Abdeladhim Tahimi

arXiv:2607.13042 · 2026-07-16 공개 · arXiv · PDF

physics-informed-neural-networks gradient-computation pytorch adjoint-values reverse-mode vector-jacobian-products pinn-training sensitivity-framework

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.

한국어 요약

한 줄 요약

PyTorch의 자동 미분 엔진이 PINN 학습에서 2단계 미분을 처리하는 방식을 구체적 수치와 모듈명을 통해 분석한다.

핵심 기여도

핵심 아이디어

PINN 학습은 네트워크 출력 $\hat{y}(t)$의 시간 미분 $\hat{y}'(t)$를 계산하고, 이 미분이 포함된 손실 함수 $L$의 파라미터 그래디언트 $\nabla_\theta L$를 구하는 2단계 미분을 요구한다. PyTorch의 자동 미분 엔진은 이 과정을 `torch.autograd.grad`와 `loss.backward()`를 사용하여 처리하지만, 이 중 `create_graph=True` 플래그가 없으면 $\partial \hat{y}'/\partial \theta$ 항이 누락되어 잘못된 그래디언트가 생성된다. 이는 PyTorch의 vector–Jacobian product(VJP)와 P/Q 민감도 프레임워크가 연결되는 핵심 포인트이다.

기술적 접근법

주요 결과

의의 및 한계

실용적 활용