FTorch
Brief description
It is desirable to be able to run machine learning (ML) models directly in Fortran.
ML models are often trained in some other language (say, Python) using a popular frameworks (say, PyTorch) and saved.
We want to run inference on this model without having to call a Python executable.
To achieve this we use the existing Torch C++ interface, LibTorch.
FTorch provides a library enabling a user to directly couple their PyTorch models to Fortran code.
There are also installation instructions for the library and examples of performing coupling.
We support running on both CPU and GPU, and have tested the library on UNIX and Windows based operating systems
News
Some recent updates about FTorch:
- FTorch developers Jack Atkinson and Joe Wallwork
were recently awarded funding from C2D3-Accelerate
for a project entitled Online training of large-scale Fortran-based hybrid
computational science models, with applications in climate science. This
grant will support development for online training functionality for FTorch,
as well as research visits, FTorch training tutorials, and organisation of a
workshop on hybrid modelling.
- FTorch developer Joe Wallwork will be presenting on FTorch in the
DARC seminar series
at the University of Reading on 15th May 2025.
- FTorch developer Joe Wallwork will be presenting on FTorch in a seminar at
ECMWF, Reading on
15th May 2025.
- FTorch developers Joe Wallwork and Tom Meltzer will be giving an FTorch
tutorial at
Durham HPC Days
on 2nd June 2025. Joe will also be giving a talk on Accelerating UKCA by
predicting timesteps with FTorch in the
HPC in Weather & Climate Research
session.
- FTorch developers Jack Atkinson and Joe Wallwork will be giving an FTorch
tutorial in the
Department of Atmospheric, Oceanic, and Planetary Physics
at the University of Oxford on 2nd July 2025.
- The FTorch developers will be giving an FTorch tutorial at the
ICCS Summer School
on 11th July 2025.
- FTorch developer Jack Atkinson will be presenting FTorch in a SciML seminar at
CEMAC in Leeds on 18th July 2025.
Publications and Presentations
FTorch is published in JOSS. To cite it in your work please refer to:
Atkinson et al., (2025). FTorch: a library for coupling PyTorch models to Fortran.
Journal of Open Source Software, 10(107), 7602, https://doi.org/10.21105/joss.07602
The following presentations contain information about FTorch:
- FTorch: A library to couple PyTorch ML models with Fortran climate models
AI for Climate and Nature Community Day - May 2025
Slides
- Facilitating online training in Fortran-based climate models
EuroAD, Kaiserslautern - April 2025
Slides
- Coupling Machine Learning to Numerical (Climate) Models
Platform for Advanced Scientific Computing, Zurich - June 2024
Slides
- Blending Machine Learning and Numerical Simulation, with Applications to Climate Modelling
Durham HPC days, Durham - May 2024
Slides
- Reducing the overheads for coupling PyTorch machine learning models to Fortran
ML & DL Seminars, LSCE, IPSL, Paris - November 2023
Slides - Recording
- Reducing the Overhead of Coupled Machine Learning Models between Python and Fortran
RSECon23, Swansea - September 2023
Slides - Recording
License
The FTorch source code, related files and documentation are
distributed under an MIT License which can be viewed here.
Projects using FTorch
The following projects make use of FTorch.
If you use our library in your work please let us know.
- DataWave CAM-GW -
Using FTorch to couple neural net parameterisations of gravity waves to the CAM
atmospheric model.
- MiMA Machine Learning -
Implementing a neural net parameterisation of gravity waves in the MiMA atmospheric model.
Demonstrates that nets trained near-identically offline can display greatly varied behaviours when coupled online.
See Mansfield and Sheshadri (2024) - DOI: 10.1029/2024MS004292
- Convection parameterisations in ICON -
Implementing machine-learnt convection parameterisations in the ICON atmospheric model
showing that best online performance occurs when causal relations are eliminated from the net.
See Heuer et al (2024) - DOI: 10.1029/2024MS004398
- In the GloSea6 Seasonal Forecasting Model -
Replacing a BiCGStab bottleneck in the code with a deep learning approach to speed up execution without compromising model accuracy.
See Park and Chung (2025) - DOI: 10.3390/atmos16010060
Developer Info
ICCS Cambridge