The tutorial trains image-to-image models on high-resolution fields: the same kind of data used in scientific applications such as weather and climate, fluid dynamics, seismology, cosmology, and experimental imaging. Every run in this repository uses 4096 × 4096 inputs from an example turbulence simulation. We start from a single GPU, speed up data loading and compute, then scale with data parallelism and with model parallelism across tensor and spatial dimensions.
We focus on four architectures that represent the general architecture space of scientific AI models. These are Vision Transformer (ViT) based for global mixing, Local attention based models like Swin Transformer for local mixing, Fourier Neural Operators (FNO) for spectral mixing, and ConvNeXt for convolution based local mixing. Since each architecture class mixes information in different ways, we will see how this affects performance and scaling.
Contents
Tutorial slides: https://drive.google.com/drive/folders/14OJ1mMEzsYa1MC2G2jfXJZpbE_HxoKzh?usp=sharing
Join the Slack workspace: https://join.slack.com/t/nersc-dl-tutorial/shared_invite/zt-4glmxatya-tMbqGiAADXeUMa4owi4k1w
Jobs write a profile on the compute node. Install Nsight Systems on your own machine so you can open the .nsys-rep files.
- Create an account. The download needs a free NVIDIA developer login.
- Download the host build. On the download page, pick macOS, Windows, or the Linux
.rpm,.deb, or.runpackage. - Install it locally. Run that installer. Copy a profile back from
LOGDIRand open it here.
train.py builds whichever serial network the config names. Each one maps the input field to a later field.
| Model | Mixing | Serial code |
|---|---|---|
| ViT | Attention across all patch tokens | networks/vit.py |
| Swin | Attention inside shifted windows | networks/swin.py |
| FNO | Fourier mixing across the field | networks/fno.py |
| ConvNeXt | Convolution over nearby cells, then a channel MLP | networks/convnext.py |
- ViT and Swin.
embed_dim,depth, andpatch_size. The token count is(4096 / patch_size)^2. Swin also takeswindow_size. - FNO.
embed_dimis the hidden width.modes_khandmodes_kware the wavenumbers kept after the FFT.mlp_ratiowidens the channel MLP (0leaves it out).downsampleruns the blocks on a coarser grid. - ConvNeXt.
embed_dim,depth,patch_size, andkernel_sizefor the depthwise convolution.
The data set is comprised of 64 independent trajectories of decaying 2D homogeneous isotropic turbulence. Each trajectory is simulated on a periodic 4096×4096 grid with no forcing and saved as 64 frames, 0.04 time units apart, from t=0 to 2.52. The simulations are initialized using a San-Staples style initialization (https://www.sciencedirect.com/science/article/pii/S0045793012001363) with kp = 32 and a randomized phase for each Fourier mode. Each trajectory is one HDF5 file holding a float32 fields array of shape [64, 2, 4096, 4096] (time, u/v channels, y, x), cell-centered. This data is meant to be a simple example of high resolution data for the purpose of this tutorial. In practices, data sets can be much larger (many more snapshots and / or trajectories) and / or more complex (e.g. 3D, multiphysics, many more variables, etc.) utils/data_loader.py serves them to the training process.
- Input and target. A sample is two snapshots
dtsteps apart. The network sees the first and predicts the second. - Normalization. Channel mean and standard deviation come from
stats_trajectory.h5. Files are split 90 / 10 into training and validation. - The loader.
SynDatasetplus a PyTorchDataLoader.data_loader_config: pytorchselects it.num_data_workers: 0reads the batch in the training process.
train.py then:
- Build the network named in the config, Adam, and a mean-squared-error loss.
- For each batch, copy it to the GPU, run the forward, call
backward(), and update the weights. - Validate, and write TensorBoard scalars: training loss, validation loss, RMSE of the first channel, learning rate, and samples per second.
The learning rate follows a cosine decay over num_iters (CosineAnnealingLR). With warmup greater than 0, the rate rises linearly for that many steps and then follows the cosine.
One YAML file per network. A run is that file plus one named block:
--yaml_config PATH # which file, default ./config/ViT.yaml
--config NAME # which block in that file, default base
- Which network.
networkinside the block. Omitted means the ViT. The others setswin,fno, orconvnext. - Inheritance. Blocks are anchored. A new block starts from another with
<<: *baseand lists only the keys it changes. - What lives in the file. Image size and channel counts,
global_batch_size,lr,num_iters, and the loader keys above.limit_nsamplesandlimit_nsamples_valshorten a run.amp_mode,enable_fused, andenable_jitstay off for the baseline. - Command line.
--run_numtags the output directory.--expdiroverrides the log path for one job.
| File | Baseline block |
|---|---|
config/ViT.yaml |
short (and base for a long run) |
config/swin.yaml |
short (and base) |
config/FNO.yaml |
short (and base). downsample: 4 runs the blocks on a 1024×1024 latent grid. |
config/ConvNeXt.yaml |
short (and base) |
The same files will grow a matching block for the optimized loader, for data parallelism, and for spatial parallelism. The architecture pages point at those blocks as they are filled in.
Copy a block to change a model without editing the baseline:
# in config/ViT.yaml
my_vit:
<<: *base
embed_dim: 768
num_iters: 80Example: submit a single-GPU job. submit.sh starts the tutorial container and runs train.py with one GPU per task. The script mounts the dataset and the log directory. This command is only an example of the submission syntax; we will mark job submission scripts to be submitted explicitly in the later sections.
sbatch -n 1 ./submit.sh --yaml_config ./config/ViT.yaml --config shortThe copied block from above is the same script with a different --config:
sbatch -n 1 ./submit.sh --yaml_config ./config/ViT.yaml --config my_vitArguments after the script name are forwarded to train.py. Slurm writes the job output to <yaml>_<config>[_<split>]_<jobid>.out in the directory you submitted from, for example vit_short_<jobid>.out. The split part names the --tp, --sp1, and --sp2 values above 1, such as _sp4 or _tp4. The job shows up under the same name in squeue. squeue --me shows the job id.
expdir (default /logs) is the log path inside the container. The run is written to <expdir>/<config>/<N>GPU/<run_num>/.
Let us begin. Start by submitting the baseline job; this will take several minutes to complete since it is unoptimized and running on a single GPU.
ENABLE_PROFILING=1 PROFILE_OUTPUT=vit_short \
sbatch -n 1 ./submit.sh --yaml_config ./config/ViT.yaml --config short --run_num shortThe profile of that run, and the optimized runs after it, are on the ViT single-GPU page.
The measured runs are written up per architecture. We have filled in ViT for you. We will go over the other architectures during the tutorial as well.
One GPU, before adding any more.
- Profile the FP32 baseline and see where the GPU waits.
- Turn on workers, BF16, fused Adam, and
torch.compiletogether. - Move the loader to DALI.
More GPUs, each still holding a full copy of the model.
- Hold the local batch fixed while the global batch grows.
- Drop the local batch to 1 as the model gets larger.
- Raise the learning rate with the global batch.
Larger models and inputs, once a local batch of 1 will not fit on the GPU.
- Split one replica across GPUs, with tensor parallelism and spatial parallelism.
- Shard the sequence so the step fits again.

