2024-06-03
To access links or follow on your own device these slides can be found at:
jackatkinson.net/slides
Except where otherwise noted, these presentation materials are licensed under the Creative Commons Attribution-NonCommercial 4.0 International (CC BY-NC 4.0) License.
Vectors and icons by SVG Repo under CC0(1.0) or FontAwesome under SIL OFL 1.1
In ~1916 Lewis Fry Richardson1 attemted2 to compute a 1 day forecast by hand using partial differential equations3.
He went on to publish Weather Prediction by Numerical Process (Richardson 1922)
Images from the Met Office in the UK, Fair Use.
In Weather Prediction by Numerical Process (Richardson 1922) LFR envisaged a “Forecast Factory”.
He lived to see this realised, albeit in a different setting, on ENIAC1 by Charney, the von Neumans et al. in 1950.
ENIAC by US serviceperson, Public Domain.
The Forecast Factory by Stephen Conlin (1986), Fair Use.
Climate models are large, complex, many-part systems.
Subgrid processes are largest source of uncertainty
Microphysics by Sisi Chen Public Domain
Staggered grid by NOAA under Public Domain
Globe grid with box by Caltech under Fair use
Subgrid processes are largest source of uncertainty
Microphysics by Sisi Chen Public Domain
Staggered grid by NOAA under Public Domain
Globe grid with box by Caltech under Fair use
We typically think of Deep Learning as an end-to-end process;
a black box with an input and an output1.
Who’s that Pokémon?
\[\begin{bmatrix}\vdots\\a_{23}\\a_{24}\\a_{25}\\a_{26}\\a_{27}\\\vdots\\\end{bmatrix}=\begin{bmatrix}\vdots\\0\\0\\1\\0\\0\\\vdots\\\end{bmatrix}\] It’s Pikachu!
Neural Net by 3Blue1Brown under fair dealing.
Pikachu © The Pokemon Company, used under fair dealing.
Neural Net by 3Blue1Brown under fair dealing.
Pikachu © The Pokemon Company, used under fair dealing.
Many large scientific models are written in Fortran (or C, or C++).
Much machine learning is conducted in Python.
Mathematical Bridge by cmglee used under CC BY-SA 3.0
PyTorch, the PyTorch logo and any related marks are trademarks of The Linux Foundation.”
TensorFlow, the TensorFlow logo and any related marks are trademarks of Google Inc.
We consider 2 types:
Computational
Developer
At the academic end of research both have an equal effect on ‘time-to-science’.
Especially when extensive research software support is unavailable.
iso_c_binding
.We will:
libtorch
C++libtorch
C++ APIPython
env
Python
runtime
xkcd #1987 by Randall Munroe, used under CC BY-NC 2.5
Build using CMake,
or link via Make like NetCDF (instructions included)
FCFLAGS += -I<path/to/install>/include/ftorch
LDFLAGS += -L<path/to/install>/lib64 -lftorch
Find it on :
pt2ts.py
aids users in saving PyTorch models to TorchscriptFind it on :
Find it on :
Find it on :
use, intrinsic :: iso_fortran_env, only : sp => real32
! Use the FTorch Library
use :: ftorch
implicit none
! Fortran variables
real(sp), dimension(1,3,244,244), target :: in_data
real(sp), dimension(1, 1000), target :: out_data
integer, parameter :: n_inputs = 1
integer :: in_layout(4) = [1,2,3,4]
integer :: out_layout(2) = [1,2]
! Torch Tensors
type(torch_tensor), dimension(1) :: in_tensors
type(torch_tensor) :: out_tensor
! Populate Fortran data
call random_number(in_data)
! Cast Fortran data to Tensors
! Create input/output tensors from the above arrays
in_tensors(1) = torch_tensor_from_array(in_data, in_layout, torch_kCPU)
out_tensor = torch_tensor_from_array(out_data, out_layout, torch_kCPU)
import torch
import torchvision
# Load pre-trained model and put in eval mode
model = torchvision.models.resnet18(weights="IMAGENET1K_V1")
model.eval()
# Create dummmy input
dummy_input = torch.ones(1, 3, 224, 224)
# Trace model and save
traced_model = torch.jit.trace(model, dummy_input)
frozen_model = torch.jit.freeze(traced_model)
frozen_model.save("/path/to/saved_model.pt")
TorchScript
! Define a Torch module
type(torch_module) :: model
! Load in from Torchscript
model = torch_module_load('/path/to/saved_model.pt')
Cast Tensors to GPU in Fortran:
! Load in from Torchscript
model = torch_module_load('/path/to/saved/gpu/model.pt', torch_kCUDA, device_index=0)
! Cast Fortran data to Tensors
in_tensor(1) = torch_tensor_from_array(in_data, in_layout, torch_kCUDA, device_index=0)
out_tensor = torch_tensor_from_array(out_data, out_layout, torch_kCPU)
Effective HPC simulation requires MPI_Gather()
for efficient data transfer.
forpy
in Espinosa et al. (2022)1
libtorch
is included on the software stack on Derecho
Derecho by NCAR
Work by Will Chapman of NCAR/M2LInES
As representations of physics models have inherent, sometimes systematic, biases.
Run CESM for 9 years relaxing hourly to ERA5 observation (data assimilation)
Train CNN to predict anomaly increment at each level
Apply online as part of predictive runs
Gravity waves by NASA/JPL - Public Domain
Deep convection by Hussein Kefel - Creative Commons
Packaging:
When ML components are developed they typically have a:
normalisation routine
neural network architecture
de-normalisation routine
Enforcing of physical constraints
Several constituents to be transferred to host model.
Portability:
A neural net trained on a different model/dataset requires:
to function correctly.
Neural Network model trained in SAM (Yuval and O’Gorman 2020)
To be re-deployed in CAM
Outputs are of the form \(\partial / \partial t\) so need to apply, convert, and difference.
The parameterisation:
The coupling:
ICCS Research Software Engineers:
Previous Members:
FTorch:
MiMA
CESM
Get in touch:
The ICCS received support from
Wilkes3 (CSD3)
Observations:
MPI_gather
to reduce overheadsFollowing the comparisons and MiMA experiments we performed detailed benchmarking to examine the library performance.