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
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
Some recent updates about FTorch:
We offer training on FTorch in the form of tutorials and workshops. The companion repository https://github.com/Cambridge-ICCS/FTorch-workshop provides a set of exercises and solutions to help users get started with FTorch.
The following presentations contain information about FTorch:
See the presentations page for a full list of presentations on FTorch.
The FTorch source code, related files and documentation are distributed under an MIT License which can be viewed here.
The following projects make use of FTorch.
If you use our library in your work please let us know.