arXiv:2607.13042cs.LGcs.MS2026-07被引 1

详解PyTorch如何在物理信息神经网络中计算双重梯度

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

  • 通过前向构建计算图,反向遍历一次完成22个参数梯度计算
  • 实现对微分残差的正确求导,支持物理约束训练
  • 验证了自动微分与手算结果一致,适合研究者理解底层机制

本文以1-3-3-1多层感知机和初值问题 $y'(t)+y(t)=0$, $y(0)=1$ 为例,详细追踪了PyTorch自动微分(AD)引擎在物理信息神经网络(PINN)训练中的梯度计算过程。该场景需两层求导:一是通过网络计算物理导数 $ ilde{y}'(t) = d ilde{y}/dt$,二是计算依赖于 $ ilde{y}'(t)$ 的损失函数 $ abla_θL$ 的参数梯度。文中完整展示了前向传递构建的计算图、反向传播中单次遍历完成22个参数梯度的计算路径,以及使用 exttt{create_graph=True} 实现图上图机制,确保对物理残差的正确微分。所有伴随值均经由Tahimi (2026)的手动推导验证,将 $P/Q$ 敏感性框架与PyTorch autograd所用的向量-雅可比积联系起来。

原文摘要 · Abstract (English)

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_θ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.

自动微分神经网络梯度计算PINN

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。