Skip to main content
QUICK REVIEW

[论文解读] Proof-of-concept: Using ChatGPT to Translate and Modernize an Earth System Model from Fortran to Python/JAX

Anthony Zhou, Linnia Hawkins|arXiv (Cornell University)|Feb 13, 2024
Computational Physics and Python ApplicationsComputer Science被引用 5
一句话总结

论文展示了一个半自动化工作流,使用 GPT-4 将 Fortran 地球系统模型组件翻译为 Python/JAX,实现 GPU 加速和参数估计的自动微分,重点关注 CESM 的 CLM 中的叶片层光合作用。

ABSTRACT

Earth system models (ESMs) are vital for understanding past, present, and future climate, but they suffer from legacy technical infrastructure. ESMs are primarily implemented in Fortran, a language that poses a high barrier of entry for early career scientists and lacks a GPU runtime, which has become essential for continued advancement as GPU power increases and CPU scaling slows. Fortran also lacks differentiability - the capacity to differentiate through numerical code - which enables hybrid models that integrate machine learning methods. Converting an ESM from Fortran to Python/JAX could resolve these issues. This work presents a semi-automated method for translating individual model components from Fortran to Python/JAX using a large language model (GPT-4). By translating the photosynthesis model from the Community Earth System Model (CESM), we demonstrate that the Python/JAX version results in up to 100x faster runtimes using GPU parallelization, and enables parameter estimation via automatic differentiation. The Python code is also easy to read and run and could be used by instructors in the classroom. This work illustrates a path towards the ultimate goal of making climate models fast, inclusive, and differentiable.

研究动机与目标

  • 推动需要将地球系统模型(ESMs)现代化,使其对 GPU 友好且可微分。
  • 提出一种分而治之的工作流程,利用静态分析和 GPT-4 将 Fortran 代码单元翻译成 Python/JAX。
  • 展示来自 CESM CLM 的叶片级光合作用模块的运行时改进和参数估计能力。
  • 提供开源工具和通往更包容、快速、可微分的气候建模的概念验证路径。

提出的方法

  • 通过静态分析和拓扑排序将 Fortran 代码拆分为按依赖顺序的单元。
  • 使用 GPT-4 将每个单元翻译为 Python/JAX,并通过单元测试引导迭代。
  • 运行多种 Python 变体(NumPy、Numba、SciPy、JAX),并比较 GPU 与 CPU 的运行时。
  • 展示对 Vcmax 的可微分参数估计,使用自动微分和梯度优化。
  • 通过单元测试迭代以提高手译质量和可靠性。
Figure 2: Comparing runtime of leaf-level photosynthesis in several Python translations with the original Fortran version. Runtime was measured on an Amazon EC2 G5.4xlarge instance with one NVIDIA A10G GPU.
Figure 2: Comparing runtime of leaf-level photosynthesis in several Python translations with the original Fortran version. Runtime was measured on an Amazon EC2 G5.4xlarge instance with one NVIDIA A10G GPU.

实验结果

研究问题

  • RQ1以大型语言模型驱动、分而治之的方法是否能够可靠地将 Fortran 气候模型组件翻译为 Python/JAX?
  • RQ2通过 GPU 加速的 Python/JAX 翻译对于所选模型组件是否能显著优于原生 Fortran?
  • RQ3自动微分是否在翻译后的 Python/JAX 代码中实现高效的参数估计?
  • RQ4将此翻译扩展到更大规模的 Fortran 代码库时,实际挑战和局限性有哪些?

主要发现

  • 在 tested Python variants 中,JAX-GPU 翻译实现了最快的运行时,Fortran 慢两个数量级。
  • 同一模块上,GPU并行的 Python/JAX 可以显著超过基于 CPU 的 Fortran。
  • 经 JIT 编译的 Python 方法(JAX、Numba)相比 Fortran 表现相当接近,表明编译显著提升了速度。
  • 自动微分使 Vcmax 的基于梯度的参数估计成为可能,较叶模型中的均匀采样减少了迭代次数。
  • 翻译工作流有效地展示了朝向可微分、GPU 支持的气候模型的路径,并提供课堂就绪的 Python 代码。
Figure 3: Measured (points) and modeled (lines) relationship between the internal partial pressure of CO2 (Pa) and the rate of assimilation (umol/m2/s). The modeled values use the Vcmax parameter value selected using either uniform sampling (orange) or gradient descent (green).
Figure 3: Measured (points) and modeled (lines) relationship between the internal partial pressure of CO2 (Pa) and the rate of assimilation (umol/m2/s). The modeled values use the Vcmax parameter value selected using either uniform sampling (orange) or gradient descent (green).

阅读本论文

在 Nubint 阅读器中打开原文,边读边就任意段落提问。

在 Nubint 中阅读本论文

本解读由 AI 根据论文原文生成,引用前请核对原文。