arXiv:2602.22631cs.MScs.LG2026-02被引 7

用形式化方法在Lean4中统一验证神经网络的计算与推理过程。

TorchLean: Formalizing Neural Networks in Lean

  • 将神经网络作为可执行程序与数学对象,共享同一语义
  • 支持精确与有限精度计算,可验证反向传播与证书检查
  • 适合需要高可靠性验证的科研与安全关键场景

神经网络广泛应用于科学、安全关键和任务关键系统,但其验证常脱离运行环境,导致执行与分析之间的语义鸿沟。这种鸿沟依赖于操作符语义、张量布局、预处理、浮点行为、图变换、加速内核和外部证书等隐含约定。我们提出TorchLean,一个在Lean 4中统一建模、执行与验证神经网络的框架。TorchLean将学习模型视为具有共同计算、验证与定理证明语义的可执行程序与数学对象。该框架提供类似PyTorch的类型化张量、层、目标函数、优化器、自动微分与图程序接口,支持急切与编译执行路径,均下压至统一计算图表示。它支持精确与有限精度张量语义、经验证的反向模式微分、区间与仿射边界传播、类似CROWN/LiRPA的证书检查、导入导出流程,以及通过显式FFI边界的CUDA执行。还包含注意力与FlashAttention、状态空间序列模型、扩散与采样过程、概率核、强化学习目标与马尔可夫决策过程、自监督目标(如掩码自编码、JEPA式预测视图、方差/相关性反坍塌损失)的语义层。这些组件共同构建了可验证机器学习的语义基础,使可执行的神经网络实体、验证过程、运行时边界与数学命题可在同一定理证明环境中陈述与关联。

原文摘要 · Abstract (English)

Neural networks are increasingly deployed in scientific, safety critical, and mission critical pipelines, yet verification and analysis are often performed outside the programming environment that defines and runs the model. This creates a semantic gap between the executed network and the analyzed artifact: guarantees can depend on implicit conventions about operator semantics, tensor layouts, preprocessing, floating-point behavior, graph transformations, accelerated kernels, and external certificates. We present TorchLean, a unified framework for formalizing, executing, and verifying neural networks in Lean 4. TorchLean treats learned models as executable programs and mathematical objects with a shared semantics for computation, verification, and theorem proving. The framework provides a PyTorch style API for typed tensors, layers, objectives, optimizers, automatic differentiation, and graph programs, with eager and compiled execution paths that lower to a common computation-graph representation. TorchLean supports exact and finite-precision tensor semantics, verified reverse-mode differentiation, interval and affine bound propagation, CROWN/LiRPA style certificate checking, import/export workflows, and CUDA-backed execution through explicit FFI boundaries. It also includes semantic layers for attention and FlashAttention, state-space sequence models, diffusion and sampling processes, probability kernels, reinforcement-learning objectives and Markov decision processes, and self-supervised objectives such as masked autoencoding, JEPA-style predictive views, and variance/correlation-based anti-collapse losses. Together, these components provide a semantic foundation for verified machine learning, where executable neural network artifacts, verification procedures, runtime boundaries, and mathematical claims can be stated and related inside one theorem-proving environment.

形式化验证神经网络Lean4可验证机器学习

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