Run Your Own AI Weather Model
misc., misc., 2025
This is a quick intro on how to use run the (Nvidia) fourcastnetv2 and (Huawei) pangu AI model from ecmwf-plugin instructions.
Update 2025-Sep-11: Also added fourcastnet0.1 from ECMWF and (Microsoft) Aurora. (Google) GraphCast is still not working well due to compatibility issues with JAX.
Partial results are used in my final project for MIT Course 12.810 Atm. Dynm. (2025 Spring, taught by Paul O’Gorman) titled:
Are AI Weather Forecasts Respecting Atmosphere Dynamics?
Presentation slides and write-ups are available.
Cover photo generated by ChatGPT-4o
As of April 10th, 2025
For non-commerical usage of ECMWF open accounts, the service/MARS will not be available, which means the most recent 30 day reanalysis will NOT be available, and the configuration of “/.ecmwfapirc” file would thus lead to errors of not being authorized. Issues have been encountered in post and issue…
Instead, the solution is to use copernicus CDS open access data, which requires a “/.cdsapirc” file that you can find api instructions here.
Tutorials on running your own 5-day, 6-hourly AI weather forecast! (on MIT Engaging)
Allocate node and Modules + Conda Env
salloc -N1 -c2 --mem=4G -t 6:00:00 -p mit_normal_gpu --gres=gpu:1
Make sure you see both cuda/12.4.0
and cudnn/9.8.0.87-cuda12
available (via module avail
).
module purge
module load StdEnv gcc/12.2.0 miniforge/24.3.0-0 cuda/12.4.0 cudnn/9.8.0.87-cuda12
conda create -n ai-ml12 python=3.10 -y
conda activate ai-ml12
(IMPORTANT) add the correct cuDNN lib dir
export LD_LIBRARY_PATH="$CUDNN_HOME/lib:$LD_LIBRARY_PATH"
(Optional) keep pip inside env (not ~/.local)
export PYTHONNOUSERSITE=1
Installations
pip install ai-models
pip install ai-models-panguweather
pip install ai-models-fourcastnet
pip install ai-models-graphcast # Install from https://github.com/ecmwf-lab/ai-models-graphcast
pip install ai-models-fourcastnetv2
pip install ai-models-aurora
pip install --extra-index-url https://download.pytorch.org/whl/cu124 torch torchvision torchaudio
pip install tensorflow
# Necessary for Pangu GPU
pip install onnxruntime-gpu --upgrade
pip install "jax[cpu]" dm-haiku
Now you should have CUDA 12.4, cuDNN 9.8, ONNX Runtime 1.22.
Correct MARS to CDS
replace the source “mars” -> “cds” for all load helpers - if installed in conda site-packages not ./local, change dir accordingly
cp -a ~/.local/lib/python3.10/site-packages/ai_models/inputs/mars.py ~/.local/lib/python3.10/site-packages/ai_models/inputs/mars.py.bak
sed -i 's/from_source("mars"/from_source("cds"/g' ~/.local/lib/python3.10/site-packages/ai_models/inputs/mars.py
Download assets for (auto-download has bugs for Aurora)
mkdir -p /pool001/x_yan/ai_model_assets/fourcastnet0.1
mkdir -p /pool001/x_yan/ai_model_assets/fourcastnetv2-small
mkdir -p /pool001/x_yan/ai_model_assets/graphcast
mkdir -p /pool001/x_yan/ai_model_assets/panguweather
mkdir -p /pool001/x_yan/ai_model_assets/aurora
wget -O /pool001/x_yan/ai_model_assets/aurora/aurora-0.1-static.pickle https://huggingface.co/microsoft/aurora/resolve/main/aurora-0.1-static.pickle
It is NORMAL to see messages about MARS when not specifying CDS.
Run Predictions!
Documentation:
ai-models --help
Sample Prediction starting at 2023-Jan-10th 00UTC
fourcastnetv2-small
ai-models --download-assets --assets /pool001/x_yan/ai_model_assets --assets-sub-directory --input cds --date 20230110 --time 0000 --lead-time 120 --output file --path /pool001/x_yan/ai_model_assets/fourcastnetv2-small/fc_20230110T0000_+120h.grib fourcastnetv2-small
Pangu
ai-models --download-assets --assets /pool001/x_yan/ai_model_assets --assets-sub-directory --input cds --date 20230110 --time 0000 --lead-time 120 --output file --path /pool001/x_yan/ai_model_assets/panguweather/fc_20230110T0000_+120h.grib panguweather
fourcastnet
ai-models --download-assets --assets /pool001/x_yan/ai_model_assets --assets-sub-directory --input cds --date 20230110 --time 0000 --lead-time 120 --output file --path /pool001/x_yan/ai_model_assets/fourcastnet0.1/fc_20230110T0000_+120h.grib fourcastnet
Aurora
ai-models --assets /pool001/x_yan/ai_model_assets --assets-sub-directory --input cds --date 20230110 --time 0000 --lead-time 120 --output file --path /pool001/x_yan/ai_model_assets/aurora/fc_20230110T0000_+120h.grib aurora
Customizable input
ai-models --file <some-grib-file> <model-name>
Results
Pangu (0.25 Resolution)
FourCastNetv2 (0.25 Resolution)
FourCastNet (0.25 Resolution)
Aurora (0.1 Resolution)
If you don’t want to redownload assets for each time, simply delete –download-assets command
If you want to download assets first without making predictions, simply do:
format: ai-models –download-assets –assets
ai-models --download-assets --assets /pool001/x_yan/ai_model_assets/panguweather/ panguweather
ai-models --download-assets --assets /pool001/x_yan/ai_model_assets/fourcastnet0.1/ fourcastnet
ai-models --download-assets --assets /pool001/x_yan/ai_model_assets/graphcast/ graphcast
ai-models --download-assets --assets /pool001/x_yan/ai_model_assets/fourcastnetv2-small/ fourcastnetv2-small
Tutorials on running your own 10-day, 6-hourly AI weather forecast! (on MIT Dolma)
Single Model: FourCastNetv2-small
HPC setup and conda env demonstration for MIT Dolma Cluster
- Read ECMWF ai-models documentation
- module load apps/miniconda/3.6
- conda create -n fourcastnetv2 -c conda-forge python=3.10 -y
- source activate fourcastnetv2
- pip install ai-models ai-models-fourcastnetv2
- Dir of model weights and climatology files will be made automactially to: /home/x_yan/fourcastnetv2-small
- Config api - two options: (a. Commercial or ECMWF authorized MARS access), or (b. Open research CDS access)
- (Option a. MARS) Follow link to get MARS access
- Make file .ecmwfapirc, add {“url” : “https://api.ecmwf.int/v1”, \n “key” : “xxxxxxxxxxxxxxxxxxx”, \n “email” : “xxxxxxxxx”}
- (Option b. CDS) Follow link to get CDS access
- Make file .cdsapirc, url: https://cds.climate.copernicus.eu/api \n key: xxxx-xxxx-xxxx-xxxx
- Download data by running: ai-models –download-assets fourcastnetv2-small
- Files of weights.tar, global_means.npy, and global_stds.npy should be seen in path /home/x_yan/fourcastnetv2-small/
- (fourcastnetv2) x_yan@dolma:~$ cd fourcastnetv2-small/
- When using CDS option, modify when using PyTorch > 2.6: (i)cd to your model.py path: cd /home/x_yan/.conda/envs/fourcastnetv2/lib/python3.10/site-packages/ai_models_fourcastnetv2/, (ii) open model.py, (iii) change line 146 checkpoint = torch.load(checkpoint_file, map_location=self.device) into checkpoint = torch.load(checkpoint_file, map_location=self.device, weights_only=False)
- (fourcastnetv2) x_yan@dolma:~/fourcastnetv2-small$ ai-models –input cds –date 20230110 –time 0000 fourcastnetv2-small
- (Optional) Other params - notice lead-time has unit of 1 hour - could be –date 2023-10-01 \ –time 00:00 \ –lead-time 24h \ –path /net/flood/data/users/x_yan/fourcastnetv2 \ –assets-sub-directory \ –input cds \ –output file
- Output forecast file would be in the same folder named fourcastnetv2-small.grib
- Enjoy!
Interpret Results
- Load the jupyter notebook from link.
- The forecast grib file is divided into surface and pressure-level data
- Sample intial, 5day, and 10 day data visualizes as
Multiple Models: FourCastNetv2-small & Panguweather
- module load apps/miniconda/3.6
- conda create -n ai-weather -c conda-forge python=3.10 -y
- source activate ai-weather
- Check your available nvaa cuda version by: conda search -c nvidia cudatoolkit
- conda install -c “nvidia/label/cuda-11.7.0” \ cudatoolkit=11.7.0 \ cudnn=8.9.5
- pip install onnxruntime-gpu==1.17.1
- conda install -c “nvidia/label/cuda-11.7.0” cuda-nvcc
- Check nvcc –version
- pip install ai-models ai-models-fourcastnetv2 ai-models-panguweather
- ai-models –download-assets –assets
- Modify the model.py as above section
- cd to dir to run models (Example: cd /home/x_yan/ai_weather_models/fourcastnetv2-small, or cd /home/x_yan/ai_weather_models/panguweather)
- ai-models –input cds –date 20250110 –time 0000 –lead-time 48 panguweather
- As of April 11, 2025, the panguweather could only be run on CPU due to ONNX issues, such that each step takes around 4 minutes to run on a CPU, rather than seconds on a GPU; see details here. The solution of conda env with cuda-toolkit is not helpful.
Below is a 48-lead time, 6-hourly forecast comparison btwn Pangu (upper row) vs. FourCastNetv2 (lower row), evaluated at init. (same), 24 hr, & 48 hr
- Geopotential Height z500
- Temperature T500
- Zonal wind u500
- Merdional wind v500
Latest Fix for CUDA 12.2 - use MIT Engaging instead (no good)!
1. Load Miniconda module (HPC-specific)
module load miniforge/24.3.0-0
2. Create Conda environment
conda create -n ai-weather -c conda-forge python=3.10 -y
3. Activate environment
conda activate ai-weather
4. Install CUDA 12.1 toolkit + cuDNN 9.1.1.17 (confirmed available via conda search -c nvidia cudnn)
conda install -c nvidia/label/cuda-12.6 cuda-toolkit=12.6 -y
conda install -c nvidia cudnn=9.3.0.75=cuda12.6* -y
5. Install ONNX Runtime with GPU support
pip install
https://huggingface.co/onnxruntime/onnxruntime/releases/download/v1.17.1/onnxruntime_gpu-1.17.1-cp310-cp310-linux_x86_64.whl
6. Install ECMWF AI model packages
pip install cdsapi ai-models ai-models-fourcastnetv2 ai-models-panguweather
7. Download model weights & statistics
ai-models –download-assets –assets /home/x_yan/12.810/ai_models fourcastnetv2-small
ai-models –download-assets –assets /home/x_yan/12.810/ai_models panguweather
modify: /home/x_yan/.local/lib/python3.10/site-packages/ai_models_fourcastnetv2/model.py
8. Verifiation
python -c “import onnxruntime as ort; print(‘ONNX device:’, ort.get_device())”
nvcc –version
9. Request GPU
salloc -N 1 -c 32 –mem=64G –gres=gpu:1 -t 12:00:00 -p mit_preemptable
10. cd to model path
cd /home/x_yan/12.810/ai_models
11. Run job sample
ai-models
–input cds
–date 20241005
–time 0000
–lead-time 144
–output file
–path /home/x_yan/12.810/ai_models/results/000_20241005_panguweather.grib
panguweather
12. Run batch sample
conda activate ai-weather salloc -N 1 -c 32 –mem=64G –gres=gpu:1 -t 12:00:00 -p mit_preemptable load the .sh file here chmod +x run_forecasts.sh ./run_forecasts.sh you should see
Supp: Register the environment as a kernel
pip install ipykernel python -m ipykernel install –user –name=ai-weather