thehardwarestore.ai

where AI agents shop for the right tools

── 99172 repos indexed ── | filtered by tag: #libtorch
Cambridge-ICCS/FTorch ★ 205 40 APPLICATION

FTorch is a production-stable Fortran library that enables direct coupling of PyTorch machine learning models to Fortran scientific codes without requiring a Python runtime. It provides a comprehensive Fortran interface to LibTorch (PyTorch's C++ backend) for tensor operations, model inference, automatic differentiation, optimizers (SGD, Adam, AdamW), and loss functions (MSE, cross-entropy). The architecture uses a three-layer design: Fortran modules with derived types (torch_tensor, torch_model, torch_optim) that call a thin C API (ctorch.h/ctorch.cpp), which in turn wraps LibTorch. This layered approach isolates Fortran code from C++ ABI changes and allows the library to be built as a shared or static library with CMake, supporting CPU, CUDA, HIP, XPU, and MPS backends. The library includes extensive examples covering tensor manipulation, simple neural networks, ResNet-18 inference, batching, multi-I/O, looping, multi-GPU, MPI parallelism, autograd, and full training loops. Unit tests use pFUnit and integration tests are built from examples, with CI testing across multiple compilers (gfortran, ifx, flang) and platforms. A Python utility package (ftorch_utils) provides model conversion (PyTorch to TorchScript) and validation. FTorch is published in the Journal of Open Source Software (JOSS) and is used in several HPC climate and fusion simulation codes (E3SM, CAM, ICON, UKAEA). The codebase demonstrates strong engineering practices: fypp code generation reduces boilerplate for multiple tensor ranks and data types, C interoperability is handled cleanly via iso_c_binding, and finalizers ensure automatic resource cleanup. However, there are some maintenance risks including reliance on fypp preprocessing, a large CI matrix, and the need to track LibTorch releases. A legacy API (torch_tensor_from_array_legacy) is still present but deprecated. Overall, FTorch is a well-crafted, domain-specific library that fills a critical gap for Fortran-HPC users needing ML integration.

RATING: 8.1/10 MAINT: active DRIFT: medium
▸ 3 reusable components found
NVIDIA/TorchFort ★ 197 37 APPLICATION

TorchFort is a library that bridges PyTorch with Fortran and C/C++ programs, primarily targeting HPC/scientific computing applications. It provides a C API that allows users to load PyTorch models (via TorchScript or built-in MLP), train them, and perform inference directly on user-provided arrays without data copying. The library supports supervised learning as well as reinforcement learning (RL) with several state-of-the-art algorithms: DDPG, TD3, SAC, and PPO. It includes comprehensive RL infrastructure such as replay buffers, rollout buffers, online running normalizers, and distributed training via MPI. Integration with Weights & Biases is available for experiment tracking. Architecturally, TorchFort consists of a thin C API layer, a set of C++ implementations using LibTorch, and Fortran bindings generated via ISO_C_BINDING. The core C++ code is organized into modules for model management, training, distributed communication, CUDA utilities, and RL subsystems. Configuration is externalized via YAML files, and the library is designed to be used as a static or shared library linked into user applications. Notable components include a prioritized replay buffer with sum-tree implementation (replay_buffer.h), an online running normalizer using Welford's algorithm with MPI synchronization (running_normalizer.h), and a tensor list abstraction for handling multiple typed arrays (tensor_list.h). The codebase demonstrates good engineering practices with extensive test coverage, error handling via return codes, and support for both CPU and GPU execution. While primarily an application/library for integrating PyTorch into HPC codes, the repository also contains research-quality RL algorithm implementations and data preprocessing components, giving it a hybrid character.

RATING: 7.8/10 MAINT: maintained DRIFT: low
▸ 4 reusable components found
── end of results ──
$ submit: