# yuangao-yg/oneforecast architecture

> Architecture diagram of the GitHub repository yuangao-yg/oneforecast, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/yuangao-yg/oneforecast
- Repository: https://github.com/yuangao-yg/oneforecast

## Overview

#### Purpose and execution surface
OneForecast is a GPU-oriented deep-learning framework for global and nested regional Earth/weather forecasting. Its primary model is graph-based and supports one-step training, multi-step rollout fine-tuning, global inference, and regional inference driven by a pretrained global forecast.

Entrypoints are `train.py`, `train_nng.py`, `inference.py`, and `inference_nng.py`; shell launchers select standard, fine-tuning, or neural-nested-grid workflows: `train.sh`, `train_finetune.sh`, `train_nng.sh`, `inference.sh`, and `inference_finetune.sh`.

#### Configuration and experiment boundary
YAML model configurations define the global and regional/NNG runs: `config/Model.yaml` and `config/Model_nng.yaml`. Runtime parameters are loaded through `my_utils/YParams.py`.

Experiments are organized under timestamped directories, holding resolved configs and checkpoint trees, e.g. `exp/OneForecast/20241008-171138/config.yaml`, `exp/OneForecast/20241008-171138/training_checkpoints`, and `exp/OneForecast/20241008-171138/NNG/`.

#### Global data pipeline
The global pipeline consumes yearly HDF5 tensors under `data/global/train`, `data/global/valid`, and `data/global/test`; each sample represents 69 atmospheric variables on a global grid. Dataset iteration and batching belong to `my_utils/data_loader.py`.

Normalization is a separate data/model boundary: global mean and standard-deviation arrays live at `data/global/mean.npy` and `data/global/std.npy`, with transforms implemented in `my_utils/norm.py`. Training/inference should preserve the channel ordering and normalized tensor contract.

#### Global forecasting model
`models/OneForecast.py` is the principal OneForecast implementation. It embodies the multiscale graph and adaptive message-passing architecture used to map current global atmospheric fields to forecast fields.

The repository also contains alternative/reference forecasting architectures—`models/GraphCast.py`, `models/Fengwu.py`, and `models/Pangu.py`—but the main launch and experiment layout center on OneForecast.

#### Training and rollout control flow
`train.py` orchestrates supervised global training: load configuration, construct normalized global data, instantiate OneForecast, optimize, validate, log, and write checkpoints. `my_utils/logging_utils.py` supports run logging; `my_utils/darcy_loss.py` provides a specialized loss utility.

Fine-tuning changes the supervisory horizon rather than the core model: `train_finetune.sh` launches the global training path with multi-step settings from `config/Model.yaml`, initializing from prior global checkpoints in `exp/OneForecast/.../training_checkpoints`.

#### Regional neural nested grid flow
Regional forecasting requires both global and regional HDF5 inputs. `train_nng.py` and `inference_nng.py` coordinate this coupled path; `my_utils/data_loader_nng.py` and `my_utils/norm_nng.py` define its distinct input/normalization handling.

`models/NNG.py` implements the neural nested-grid stage. It consumes pretrained global-model forcing plus high-resolution regional fields, producing regional forecasts while addressing regional boundary-information loss. Its configuration is isolated in `config/Model_nng.yaml`, and checkpoints are stored beneath `exp/OneForecast/.../NNG/`.

#### Runtime and external dependencies
The project targets CUDA 11.8 with a Conda environment specified in `environment.yml`, and is designed for multi-node, multi-GPU training. It uses local HDF5 weather datasets and filesystem checkpoints; pretrained weights and complete datasets are distributed externally via Hugging Face. No serving layer or online API is present.

Main entry points: [`train.py`](https://github.com/yuangao-yg/oneforecast/blob/main/train.py) (Global training), [`train_nng.py`](https://github.com/yuangao-yg/oneforecast/blob/main/train_nng.py) (NNG training), [`exp/OneForecast/20241008-171138/training_checkpoints`](https://github.com/yuangao-yg/oneforecast/tree/main/exp/OneForecast/20241008-171138/training_checkpoints) (Global checkpoints), [`my_utils/norm.py`](https://github.com/yuangao-yg/oneforecast/blob/main/my_utils/norm.py) (Global normalization)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_global["Global forecasting"]
  node_global_config["Global model config<br/>YAML config<br/>[Model.yaml]"]
  node_params["Runtime parameters<br/>parameter loader<br/>[YParams.py]"]
  node_global_data[("Global HDF5 datasets<br/>weather data")]
  node_global_loader["Global dataset loader<br/>data pipeline<br/>[data_loader.py]"]
  node_global_norm_stats[("Global normalization stats<br/>NumPy arrays<br/>[mean.npy]")]
  node_global_norm["Global normalization<br/>tensor transform<br/>[norm.py]"]
  node_oneforecast{{"OneForecast<br/>graph forecast model<br/>[OneForecast.py]"}}
  node_global_train["Global training<br/>training entrypoint<br/>[train.py]"]
  node_global_inference["Global inference<br/>inference entrypoint<br/>[inference.py]"]
  node_finetune_launcher["Rollout fine-tuning<br/>shell launcher<br/>[train_finetune.sh]"]
end

subgraph group_nng["Neural nested grid"]
  node_nng_config["NNG model config<br/>YAML config<br/>[Model_nng.yaml]"]
  node_regional_data[("Regional HDF5 inputs<br/>weather data")]
  node_nng_loader["NNG data pipeline<br/>[data_loader_nng.py]"]
  node_nng_norm["NNG normalization<br/>tensor transform<br/>[norm_nng.py]"]
  node_nng_model{{"Neural nested grid<br/>regional forecast model<br/>[NNG.py]"}}
  node_nng_train["NNG training<br/>training entrypoint<br/>[train_nng.py]"]
  node_nng_inference["NNG inference<br/>inference entrypoint<br/>[inference_nng.py]"]
end

subgraph group_experiments["Experiment artifacts"]
  node_checkpoints[("Global checkpoints<br/>model artifacts")]
  node_nng_checkpoints[("NNG artifacts<br/>model artifacts")]
  node_run_logging["Run logging<br/>experiment logging<br/>[logging_utils.py]"]
end

node_global_config -->|"loaded by"| node_params
node_params -->|"configures"| node_global_train
node_global_data -->|"iterated and batched"| node_global_loader
node_global_norm_stats -->|"mean/std"| node_global_norm
node_global_loader -->|"tensors"| node_global_norm
node_global_norm -->|"normalized batches"| node_global_train
node_global_train -->|"optimizes"| node_oneforecast
node_oneforecast -->|"forecast model"| node_global_inference
node_global_train -->|"writes"| node_checkpoints
node_checkpoints -->|"initializes from"| node_finetune_launcher
node_finetune_launcher -->|"multi-step settings"| node_global_train
node_global_train -->|"logs runs"| node_run_logging
node_nng_config -->|"configures"| node_nng_train
node_regional_data -->|"regional fields"| node_nng_loader
node_nng_loader -->|"coupled inputs"| node_nng_norm
node_nng_norm -->|"normalized inputs"| node_nng_train
node_checkpoints -->|"pretrained global forcing"| node_nng_model
node_nng_train -->|"trains"| node_nng_model
node_nng_model -->|"regional forecasts"| node_nng_inference
node_nng_train -->|"writes"| node_nng_checkpoints

click node_global_config "https://github.com/yuangao-yg/oneforecast/blob/main/config/Model.yaml"
click node_params "https://github.com/yuangao-yg/oneforecast/blob/main/my_utils/YParams.py"
click node_global_data "https://github.com/yuangao-yg/oneforecast/tree/main/data/global/train"
click node_global_loader "https://github.com/yuangao-yg/oneforecast/blob/main/my_utils/data_loader.py"
click node_global_norm_stats "https://github.com/yuangao-yg/oneforecast/blob/main/data/global/mean.npy"
click node_global_norm "https://github.com/yuangao-yg/oneforecast/blob/main/my_utils/norm.py"
click node_oneforecast "https://github.com/yuangao-yg/oneforecast/blob/main/models/OneForecast.py"
click node_global_train "https://github.com/yuangao-yg/oneforecast/blob/main/train.py"
click node_global_inference "https://github.com/yuangao-yg/oneforecast/blob/main/inference.py"
click node_finetune_launcher "https://github.com/yuangao-yg/oneforecast/blob/main/train_finetune.sh"
click node_nng_config "https://github.com/yuangao-yg/oneforecast/blob/main/config/Model_nng.yaml"
click node_nng_loader "https://github.com/yuangao-yg/oneforecast/blob/main/my_utils/data_loader_nng.py"
click node_nng_norm "https://github.com/yuangao-yg/oneforecast/blob/main/my_utils/norm_nng.py"
click node_nng_model "https://github.com/yuangao-yg/oneforecast/blob/main/models/NNG.py"
click node_nng_train "https://github.com/yuangao-yg/oneforecast/blob/main/train_nng.py"
click node_nng_inference "https://github.com/yuangao-yg/oneforecast/blob/main/inference_nng.py"
click node_checkpoints "https://github.com/yuangao-yg/oneforecast/tree/main/exp/OneForecast/20241008-171138/training_checkpoints"
click node_run_logging "https://github.com/yuangao-yg/oneforecast/blob/main/my_utils/logging_utils.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_global_config,node_params,node_global_data,node_global_loader,node_global_norm_stats,node_global_norm,node_oneforecast,node_global_train,node_global_inference,node_finetune_launcher toneBlue
class node_nng_config,node_regional_data,node_nng_loader,node_nng_norm,node_nng_model,node_nng_train,node_nng_inference toneAmber
class node_checkpoints,node_nng_checkpoints,node_run_logging toneMint
```

## Components

### Global forecasting

- [Global model config](https://github.com/yuangao-yg/oneforecast/blob/main/config/Model.yaml): YAML config · `config/Model.yaml`
- [Runtime parameters](https://github.com/yuangao-yg/oneforecast/blob/main/my_utils/YParams.py): parameter loader · `my_utils/YParams.py`
- [Global HDF5 datasets](https://github.com/yuangao-yg/oneforecast/tree/main/data/global/train): weather data · Yearly 69-channel global atmospheric tensors. · `data/global/train`
- [Global dataset loader](https://github.com/yuangao-yg/oneforecast/blob/main/my_utils/data_loader.py): data pipeline · `my_utils/data_loader.py`
- [Global normalization stats](https://github.com/yuangao-yg/oneforecast/blob/main/data/global/mean.npy): NumPy arrays · `data/global/mean.npy`
- [Global normalization](https://github.com/yuangao-yg/oneforecast/blob/main/my_utils/norm.py): tensor transform · Preserves channel ordering and normalized tensor contract. · `my_utils/norm.py`
- [OneForecast](https://github.com/yuangao-yg/oneforecast/blob/main/models/OneForecast.py): graph forecast model · Multiscale adaptive message-passing global forecaster. · `models/OneForecast.py`
- [Global training](https://github.com/yuangao-yg/oneforecast/blob/main/train.py): training entrypoint · Supervised one-step training and validation orchestration. · `train.py`
- [Global inference](https://github.com/yuangao-yg/oneforecast/blob/main/inference.py): inference entrypoint · `inference.py`
- [Rollout fine-tuning](https://github.com/yuangao-yg/oneforecast/blob/main/train_finetune.sh): shell launcher · Runs the global path with multi-step supervision. · `train_finetune.sh`

### Neural nested grid

- [NNG model config](https://github.com/yuangao-yg/oneforecast/blob/main/config/Model_nng.yaml): YAML config · `config/Model_nng.yaml`
- **Regional HDF5 inputs**: weather data · High-resolution regional fields coupled with global inputs.
- [NNG data pipeline](https://github.com/yuangao-yg/oneforecast/blob/main/my_utils/data_loader_nng.py): data pipeline · `my_utils/data_loader_nng.py`
- [NNG normalization](https://github.com/yuangao-yg/oneforecast/blob/main/my_utils/norm_nng.py): tensor transform · `my_utils/norm_nng.py`
- [Neural nested grid](https://github.com/yuangao-yg/oneforecast/blob/main/models/NNG.py): regional forecast model · Combines pretrained global forcing and regional fields. · `models/NNG.py`
- [NNG training](https://github.com/yuangao-yg/oneforecast/blob/main/train_nng.py): training entrypoint · `train_nng.py`
- [NNG inference](https://github.com/yuangao-yg/oneforecast/blob/main/inference_nng.py): inference entrypoint · `inference_nng.py`

### Experiment artifacts

- [Global checkpoints](https://github.com/yuangao-yg/oneforecast/tree/main/exp/OneForecast/20241008-171138/training_checkpoints): model artifacts · Prior global weights initialize rollout and regional workflows. · `exp/OneForecast/20241008-171138/training_checkpoints`
- **NNG artifacts**: model artifacts
- [Run logging](https://github.com/yuangao-yg/oneforecast/blob/main/my_utils/logging_utils.py): experiment logging · `my_utils/logging_utils.py`

## Connections

- Global model config → Runtime parameters: loaded by
- Runtime parameters → Global training: configures
- Global HDF5 datasets → Global dataset loader: iterated and batched
- Global normalization stats → Global normalization: mean/std
- Global dataset loader → Global normalization: tensors
- Global normalization → Global training: normalized batches
- Global training → OneForecast: optimizes
- OneForecast → Global inference: forecast model
- Global training → Global checkpoints: writes
- Global checkpoints → Rollout fine-tuning: initializes from
- Rollout fine-tuning → Global training: multi-step settings
- Global training → Run logging: logs runs
- NNG model config → NNG training: configures
- Regional HDF5 inputs → NNG data pipeline: regional fields
- NNG data pipeline → NNG normalization: coupled inputs
- NNG normalization → NNG training: normalized inputs
- Global checkpoints → Neural nested grid: pretrained global forcing
- NNG training → Neural nested grid: trains
- Neural nested grid → NNG inference: regional forecasts
- NNG training → NNG artifacts: writes
