将训练好的神经网络直接转为原生Fortran代码,提速近20倍且可直接用于核工程仿真。
Native Fortran Implementation of TensorFlow-Trained Deep and Bayesian Neural Networks
- 用Fortran原生实现DNN和贝叶斯神经网络,无需Python或TensorFlow依赖
- 在测试任务中DNN预测误差极小,推理速度提升19.6倍;BNN提升8.0倍
- 已成功集成到核热工代码CTF,适合需高精度与高效计算的工业级应用
过去十年,机器学习在核工程领域的研究显著增长。随着多种方法趋于成熟,下一步是评估其在生产环境中的可行性与实用性。许多反应堆设计与评估代码主要使用Fortran编写,但与基于TensorFlow训练的模型不兼容。本研究提出一种在Fortran中实现深度神经网络(DNN)和贝叶斯神经网络(BNN)的框架,支持原生执行,无需TensorFlow的C API、Python运行时或ONNX转换。该框架设计简洁高效,可嵌入任意Fortran程序,支持迭代求解器及不确定性量化(UQ)的集合或BNN方法。通过一个含噪声正弦波的双输入单输出测试案例验证,DNN预测与TensorFlow结果差异微小,推理速度提升19.6倍;BNN预测存在轻微偏差,可能源于随机数生成差异,推理速度提升8.0倍。进一步在核工程相关问题——临界热流密度(CHF)预测上验证,结果类似并展现显著计算优势。讨论了该框架成功集成至CTF热工水力学代码的实践价值。总体表明,该框架能有效实现DNN与BNN在Fortran中的推理,推动机器学习方法在真实核工程应用中的持续研究。
原文摘要 · Abstract (English)
Over the past decade, the investigation of machine learning (ML) within the field of nuclear engineering has grown significantly. With many approaches reaching maturity, the next phase of investigation will determine the feasibility and usefulness of ML model implementation in a production setting. Several of the codes used for reactor design and assessment are primarily written in the Fortran language, which is not immediately compatible with TensorFlow-trained ML models. This study presents a framework for implementing deep neural networks (DNNs) and Bayesian neural networks (BNNs) in Fortran, allowing for native execution without TensorFlow's C API, Python runtime, or ONNX conversion. Designed for ease of use and computational efficiency, the framework can be implemented in any Fortran code, supporting iterative solvers and UQ via ensembles or BNNs. Verification was performed using a two-input, one-output test case composed of a noisy sinusoid to compare Fortran-based predictions to those from TensorFlow. The DNN predictions showed negligible differences and achieved a 19.6x speedup, whereas the BNN predictions exhibited minor disagreement, plausibly due to differences in random number generation. An 8.0x speedup was noted for BNN inference. The approach was then further verified on a nuclear-relevant problem predicting critical heat flux (CHF), which demonstrated similar behavior along with significant computational gains. Discussion regarding the framework's successful integration into the CTF thermal-hydraulics code is also included, outlining its practical usefulness. Overall, this framework was shown to be effective at implementing both DNN and BNN model inference within Fortran, allowing for the continued study of ML-based methods in real-world nuclear applications.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。