Image-to-Image
PyTorch
fuxi
transformer
tpys commited on
Commit
64a197e
·
verified ·
1 Parent(s): d21eafa

Fix q unit: kg/kg → g/kg (scaled ×1000 from ERA5); clarify input/output normalization space

Browse files
Files changed (1) hide show
  1. README.md +110 -264
README.md CHANGED
@@ -1,286 +1,132 @@
1
- ---
2
- license: cc-by-4.0
3
- metrics:
4
- - mse
5
- - csi
6
- pipeline_tag: image-to-image
7
- language:
8
- - en
9
- library_name: pytorch
10
- tags:
11
- - weather
12
- - weather-forecasting
13
- - climate
14
- - machine-learning-weather-prediction
15
- - fuxi
16
- - transformer
17
- ---
18
-
19
- # FuXi-2.1
20
-
21
- [![License](https://img.shields.io/badge/license-CC--BY--4.0-blue.svg)](https://creativecommons.org/licenses/by/4.0/)
22
- [![Task](https://img.shields.io/badge/task-Weather%20Forecasting-green)]()
23
- [![Model](https://img.shields.io/badge/model-Transformer-purple)]()
24
-
25
- **FuXi-2.1** is a global, deterministic machine-learning weather forecasting model
26
- developed by **Fudan University** & **[SAIS](https://www.sais.com.cn/)**.
27
- It produces global forecasts at **0.25°** resolution, on **6-hourly** steps, out to
28
- **10 days**.
29
-
30
- FuXi-2.1 targets the defining failure mode of data-driven weather prediction: forecasts
31
- that blur into a smooth spatial average as lead time grows, erasing the small-scale
32
- structure that matters most for extremes. FuXi-2.1 produces markedly **sharper** fields
33
- whose spatial power spectra track observations across the full wavenumber range, while
34
- keeping deterministic skill (RMSE) **comparable to** FuXi-1.0 — and substantially
35
- improving extreme-event detection for heavy precipitation and strong wind.
36
-
37
- This model is released as part of the **FuXi Single** collection.
38
-
39
- ## Table of contents
40
-
41
- - [What's new in 2.1](#whats-new-in-21)
42
- - [Quickstart](#quickstart)
43
- - [Model overview](#model-overview)
44
- - [Data details](#data-details)
45
- - [Evaluation](#evaluation)
46
- - [Known limitations](#known-limitations)
47
- - [Citation](#citation)
48
-
49
- ---
50
-
51
- ## What's new in 2.1
52
-
53
- Relative to FuXi-1.0, FuXi-2.1 introduces:
54
-
55
- - **A flat Transformer backbone** replacing FuXi-1.0's U-Transformer (ResNet
56
- downsample → Swin Transformer → upsample). FuXi-2.1 drops the U-shaped
57
- up/down-sampling in favour of a single full-resolution Transformer trunk.
58
- - **Rotary position embeddings (RoPE)** inside the Swin windowed attention, replacing
59
- the learned relative-position bias used in FuXi-1.0.
60
- - **adaLN time conditioning** that injects time-period information — forecast lead step,
61
- time-of-day and day-of-year phase — into every block, inspired by diffusion
62
- transformers in image generation.
63
- - **A variable-aware multi-head decoder** that gives pressure-level, surface and derived
64
- variables their own specialised output heads.
65
-
66
- The combined effect is sharper, spectrally faithful forecasts with no penalty on
67
- mean-error skill.
68
-
69
- ---
70
-
71
- ## Quickstart
72
-
73
- This repository ships the exported model (`fuxi-2.1.pt2`), normalization statistics
74
- (`mean.nc`, `std.nc`), a sample pre-normalized input (`input.nc`), and minimal inference
75
- code.
76
 
77
  ```bash
78
- # 1. Install dependencies
79
  pip install -r requirements.txt
80
 
81
- # 2. End-to-end demo (inference + plots)
82
- bash run.sh --model_dir . --input input.nc --steps 5
83
 
84
- # Or run inference directly (40 steps = 10-day forecast):
85
  python inference.py \
86
- --model_dir . \
87
- --input input.nc \
88
  --output_dir ./output \
89
  --steps 40 \
90
  --forecast_time 2024092900
91
 
92
- # 3. Plot selected channels
93
  python plot.py --output_dir ./output --channels t2m z500 tp --discrete
94
  ```
95
 
96
- **Input** a NetCDF with a variable `input` of shape `(time=2, channel=85, lat=721,
97
- lon=1440)`, z-score normalized, coordinates `lat` 90→−90 and `lon` 0→359.75. The provided
98
- `input.nc` is a sample for 2024-09-29 00Z.
99
-
100
- **Output** — each step saved as `{output_dir}/{step:03d}.nc`, shape `(channel=85, lat=721,
101
- lon=1440)` in physical units (denormalized), with a `valid_time` attribute. Steps are
102
- 1-based: `001.nc` = +6 h, … `040.nc` = +240 h (10 days).
103
-
104
- > **GPU:** the device is baked into the exported graph; load on CUDA. ~8 GB GPU memory is
105
- > enough (model ~4 GB + recurrent state ~1.4 GB + working memory). Tested on A100, V100,
106
- > RTX 3090/4090. See `variables.py` for the full ordered channel list.
107
-
108
- ---
109
-
110
- ## Model overview
111
-
112
- ### Model description
113
-
114
- FuXi-2.1 is a single Transformer. The global atmospheric state is split into patches and
115
- embedded into tokens, processed by a stack of windowed-attention blocks, and read out by
116
- a variable-aware multi-head decoder. The model is **deterministic** — one forward pass
117
- per step, with no adversarial or diffusion sampling at inference — and is rolled out
118
- **autoregressively** at 6-hourly steps.
119
-
120
- - **Developed by:** Fudan University & [SAIS](https://www.sais.com.cn/)
121
- - **Model type:** Transformer (patch-embed → Swin attention with RoPE + adaLN → multi-head decoder)
122
- - **Forecast type:** Global, deterministic, autoregressive
123
- - **License:** CC BY 4.0
124
- - **Predecessor:** [FuXi-1.0](https://github.com/tpys/FuXi)
125
-
126
- <div align="center">
127
- <img src="assets/arch.png" alt="FuXi-2.1 architecture" style="width: 95%;"/>
128
- </div>
129
-
130
- ### Architecture details
131
-
132
- | Component | Specification |
133
- |---|---|
134
- | Backbone | Single Transformer trunk (no U-Net up/down-sampling) |
135
- | Attention | Swin windowed attention |
136
- | Position encoding | Rotary (RoPE, 1-D) |
137
- | Normalisation / conditioning | adaLN, conditioned on lead step, time-of-day, day-of-year |
138
- | Feed-forward | SwiGLU |
139
- | Decoder | Variable-aware multi-head (pressure / surface / derived) |
140
- | Input frames | 2 (states at t−6h and t₀) |
141
- | Output | State at t+6h, rolled out autoregressively |
142
-
143
- ### Model resolution
144
-
145
- | Model | Horizontal resolution | Vertical resolution [pressure levels] (hPa) |
146
- |:---|:---:|:---|
147
- | FuXi-2.1 | 0.25° (721×1440) | 13: 50, 100, 150, 200, 250, 300, 400, 500, 600, 700, 850, 925, 1000 |
148
-
149
- ---
150
-
151
- ## Data details
152
-
153
- ### Training data
154
-
155
- FuXi-2.1 is trained and evaluated on **ERA5** reanalysis at 0.25° resolution, 6-hourly.
156
-
157
- - **Training period:** 2002–2023
158
- - **Test period:** 2024 (held out)
159
-
160
- ### Data parameters
161
-
162
- FuXi-2.1 operates on **85 channels** per time step: **65 pressure-level** channels
163
- (5 variables × 13 levels) and **20 surface** channels, plus static forcings supplied as
164
- constant inputs. Most channels are **prognostic** — the same channels are input and
165
- output and fed back during roll-out. Radiation fluxes and total precipitation are
166
- **diagnostic** outputs produced through a dedicated decoder head (they are predicted but
167
- not fed back as inputs).
168
-
169
- Channel order (exact): the 65 pressure-level channels first (z, then t, u, v, q, each
170
- over the 13 levels 50→1000 hPa), followed by the 20 surface channels:
171
- `msl, t2m, d2m, sst, ws10m, ws100m, u10m, v10m, u100m, v100m, lcc, mcc, hcc, tcc, ssr,
172
- ssrd, fdir, ttr, tcw, tp`.
173
-
174
- #### Pressure-level parameters (13 levels: 50–1000 hPa)
175
-
176
- | Short name | Name | Units | Input/Output |
177
- |:---:|:---|:---:|:---:|
178
- | z | Geopotential | m²·s⁻² | Both (prognostic) |
179
- | t | Temperature | K | Both (prognostic) |
180
- | u | Eastward wind | m·s⁻¹ | Both (prognostic) |
181
- | v | Northward wind | m·s⁻¹ | Both (prognostic) |
182
- | q | Specific humidity | kg·kg⁻¹ | Both (prognostic) |
183
-
184
- #### Surface parameters (20)
185
-
186
- | Short name | Name | Units | Input/Output |
187
- |:---:|:---|:---:|:---:|
188
- | msl | Mean sea-level pressure | Pa | Both (prognostic) |
189
- | t2m | 2 m temperature | K | Both (prognostic) |
190
- | d2m | 2 m dewpoint temperature | K | Both (prognostic) |
191
- | sst | Sea-surface temperature | K | Both (prognostic) |
192
- | ws10m | 10 m wind speed | m·s⁻¹ | Both (prognostic) |
193
- | ws100m | 100 m wind speed | m·s⁻¹ | Both (prognostic) |
194
- | u10m | 10 m eastward wind | m·s⁻¹ | Both (prognostic) |
195
- | v10m | 10 m northward wind | m·s⁻¹ | Both (prognostic) |
196
- | u100m | 100 m eastward wind | m·s⁻¹ | Both (prognostic) |
197
- | v100m | 100 m northward wind | m·s⁻¹ | Both (prognostic) |
198
- | lcc | Low cloud cover | 0–1 | Both (prognostic) |
199
- | mcc | Medium cloud cover | 0–1 | Both (prognostic) |
200
- | hcc | High cloud cover | 0–1 | Both (prognostic) |
201
- | tcc | Total cloud cover | 0–1 | Both (prognostic) |
202
- | tcw | Total column water | kg·m⁻² | Both (prognostic) |
203
- | ssr | Surface net solar radiation | J·m⁻² | Output (diagnostic) |
204
- | ssrd | Surface solar radiation downwards | J·m⁻² | Output (diagnostic) |
205
- | fdir | Total-sky direct solar radiation at surface | J·m⁻² | Output (diagnostic) |
206
- | ttr | Top net thermal radiation | J·m⁻² | Output (diagnostic) |
207
- | tp | Total precipitation | mm | Output (diagnostic) |
208
-
209
- | Field | Level type | Input/Output |
210
- |---|---|---|
211
- | Land-sea mask, orography/geopotential, latitude/longitude encodings, time-of-day / day-of-year | Surface / static | Input (forcings) |
212
-
213
- ---
214
-
215
- ## Evaluation
216
-
217
- We compare FuXi-2.1 against FuXi-1.0 under an identical protocol: forecasts initialised
218
- from ERA5 and rolled out to 240 h in 6-hour steps. CSI is computed over **land only,
219
- globally**. These numbers come from a **limited set of sample cases**, not a full-year
220
- evaluation — they are indicative, and broader scorecards will follow.
221
-
222
- **Headline:** RMSE stays comparable to FuXi-1.0 across variables, while structural and
223
- extreme-event scores improve substantially.
224
-
225
- <div align="center">
226
- <img src="assets/chart_tp_csi.png" alt="Precipitation CSI" style="width: 49%;"/>
227
- <img src="assets/chart_ws10m_csi.png" alt="Wind-speed CSI" style="width: 49%;"/>
228
- </div>
229
-
230
- ### Precipitation — Critical Success Index (CSI)
231
-
232
- | Threshold | FuXi-1.0 | FuXi-2.1 | Δ |
233
- |:---|---:|---:|---:|
234
- | ≥ 5 mm | 0.265 | 0.284 | +7.3% |
235
- | ≥ 20 mm | 0.131 | 0.146 | +11.4% |
236
- | ≥ 50 mm | 0.074 | 0.084 | +13.4% |
237
- | ≥ 100 mm | 0.014 | 0.024 | **+68.3%** |
238
-
239
- ### 10 m wind speed — Critical Success Index (CSI)
240
-
241
- | Threshold | FuXi-1.0 | FuXi-2.1 | Δ |
242
- |:---|---:|---:|---:|
243
- | ≥ 10.8 m·s⁻¹ | 0.544 | 0.571 | +4.8% |
244
- | ≥ 24.5 m·s⁻¹ | 0.165 | 0.198 | +20.3% |
245
- | ≥ 28.5 m·s⁻¹ | 0.000 | 0.044 | newly resolved |
246
-
247
- The relative gain grows with event intensity, peaking at the extreme tail. At the
248
- 28.5 m·s⁻¹ wind threshold FuXi-1.0 scores zero — it never predicts such winds — whereas
249
- FuXi-2.1 attains a non-zero CSI. Spatial power spectra of FuXi-2.1 track the observed
250
- spectra across the full wavenumber range, in contrast to FuXi-1.0's high-wavenumber
251
- energy deficit.
252
-
253
- ---
254
-
255
- ## Known limitations
256
-
257
- - FuXi-2.1 is a deterministic model; it does not provide a calibrated ensemble spread.
258
- - The CSI numbers reported here are computed on land only, over a limited set of sample
259
- cases rather than a full-year evaluation; treat them as indicative. Comprehensive
260
- global scorecards will be added.
261
- - As with all ERA5-trained models, skill depends on the quality and resolution of the
262
- initial conditions.
263
-
264
- ---
265
 
266
- ## Citation
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
267
 
268
- If you use FuXi-2.1, please cite the FuXi series:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
269
 
270
  ```bibtex
271
  @article{chen2023fuxi,
272
- title = {FuXi: a cascade machine learning forecasting system for 15-day global weather forecast},
273
- author = {Chen, Lei and Zhong, Xiaohui and Zhang, Feng and Cheng, Yuan and Xu, Yimin and Qi, Yan and Li, Hao},
274
- journal = {npj Climate and Atmospheric Science},
275
- year = {2023},
276
- volume = {6},
277
- number = {1},
278
- pages = {190}
279
  }
280
  ```
281
 
282
- ---
283
-
284
- **Code:** FuXi-1.0 — https://github.com/tpys/FuXi
285
 
286
- 2026 Fudan University & [SAIS](https://www.sais.com.cn/) · FuXi Weather.*
 
1
+ # FuXi 2.1 — Global Weather Forecasting Model
2
+
3
+ FuXi 2.1 is a 0.25-degree global weather forecasting model producing 85-channel predictions at 6-hour intervals. This repository provides minimal inference code for autoregressive rollout using the PyTorch PT2 (torch.export) backend.
4
+
5
+ ## Quick Start
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
  ```bash
8
+ # Install dependencies
9
  pip install -r requirements.txt
10
 
11
+ # Run end-to-end (inference + plots)
12
+ bash run.sh --model_dir /path/to/model --input /path/to/input.nc --steps 5
13
 
14
+ # Or run directly:
15
  python inference.py \
16
+ --model_dir /path/to/model \
17
+ --input /path/to/input.nc \
18
  --output_dir ./output \
19
  --steps 40 \
20
  --forecast_time 2024092900
21
 
22
+ # Plot results
23
  python plot.py --output_dir ./output --channels t2m z500 tp --discrete
24
  ```
25
 
26
+ ## Model Details
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
 
28
+ | Property | Value |
29
+ |----------|-------|
30
+ | Resolution | 0.25° (721 × 1440 grid) |
31
+ | Channels | 85 (65 pressure-level + 20 surface) |
32
+ | Time step | 6 hours |
33
+ | Input frames | 2 (t-6h, t) |
34
+ | Architecture | FuXi HR |
35
+ | Format | torch.export (.pth) |
36
+ | Size | ~3.7 GB |
37
+
38
+ ## Input Format
39
+
40
+ The input NetCDF file must contain a variable named `input` with:
41
+ - **Shape**: `(time=2, channel=85, lat=721, lon=1440)`
42
+ - **Normalization**: z-score normalized (already in normalized space)
43
+ - **Coordinates**: `time`, `channel` (C85 names), `lat` (90 to -90), `lon` (0 to 359.75)
44
+
45
+ The provided `input.nc` is a sample input for 2024-09-29 00Z. Both `input.nc` and the model's internal weights operate in normalized space.
46
+
47
+ ## Output Format
48
+
49
+ Each forecast step is saved as `{output_dir}/{step:03d}.nc`:
50
+ - **Shape**: `(channel=85, lat=721, lon=1440)`
51
+ - **Units**: Physical units (denormalized via `output = output * std + mean`)
52
+ - **Coordinates**: `channel`, `lat`, `lon`
53
+ - **Attribute**: `valid_time` — the forecast valid time for this step
54
+
55
+ Step numbering is 1-based: `001.nc` = +6h, `002.nc` = +12h, ..., `040.nc` = +240h (10 days).
56
+
57
+ > **Note:** The `tp` (total precipitation) channel is log1p-transformed during training. Denormalization reverses this with `expm1` and clips to ≥ 0.
58
+
59
+ ## Channel Table (C85)
60
+
61
+ **Pressure-level variables** (5 vars × 13 levels = 65 channels):
62
+ - z (geopotential), t (temperature), u (u-wind), v (v-wind), q (specific humidity, **g/kg** — scaled ×1000 from ERA5's kg/kg)
63
+ - Levels: 50, 100, 150, 200, 250, 300, 400, 500, 600, 700, 850, 925, 1000 hPa
64
+
65
+ **Surface variables** (20 channels):
66
+ | Channel | Variable | Units |
67
+ |---------|----------|-------|
68
+ | msl | Mean sea level pressure | Pa |
69
+ | t2m | 2m temperature | K |
70
+ | d2m | 2m dewpoint temperature | K |
71
+ | sst | Sea surface temperature | K |
72
+ | ws10m | 10m wind speed | m/s |
73
+ | ws100m | 100m wind speed | m/s |
74
+ | u10m / v10m | 10m wind components | m/s |
75
+ | u100m / v100m | 100m wind components | m/s |
76
+ | lcc / mcc / hcc / tcc | Cloud cover | 0-1 |
77
+ | ssr / ssrd / fdir / ttr | Radiation fluxes | J/m² |
78
+ | tcw | Total column water | kg/m² |
79
+ | tp | Total precipitation | m (log1p-transformed, reversed on output) |
80
+
81
+ See `variables.py` for the full ordered list.
82
 
83
+ ## GPU Requirements
84
+
85
+ - **Minimum GPU memory**: ~8 GB (model ~4 GB + state ~1.4 GB + working memory)
86
+ - The model device is baked into the exported graph. It must be loaded on a CUDA device.
87
+ - Tested on: A100, V100, RTX 3090/4090
88
+
89
+ ## File Structure
90
+
91
+ ```
92
+ fuxi-2.1/
93
+ ├── fuxi-2.1.pt2 # Model weights (torch.export)
94
+ ├── mean.nc # Channel means for denormalization
95
+ ├── std.nc # Channel stds for denormalization
96
+ ├── input.nc # Sample input (pre-normalized)
97
+ ├── inference.py # Rollout engine
98
+ ├── data_util.py # Data loading + postprocessing
99
+ ├── variables.py # C85 channel definitions
100
+ ├── plot.py # Visualization (uses fuxi_viz)
101
+ ├── run.sh # End-to-end demo
102
+ ├── requirements.txt # Python dependencies
103
+ └── README.md # This file
104
+ ```
105
+
106
+ ## How It Works
107
+
108
+ 1. **Load** pre-normalized input (2 frames at t-6h and t)
109
+ 2. **Rollout** autoregressively: model outputs next 2-frame state, last frame is the prediction
110
+ 3. **Denormalize** each prediction: `output = output * std + mean`, then `expm1` for precipitation
111
+ 4. **Save** each step as NetCDF with geographic coordinates
112
+
113
+ The recurrence state stays on GPU throughout the rollout (no CPU round-trip per step).
114
+
115
+ ### Note on Specific Humidity (q)
116
+
117
+ The specific humidity `q` is stored and predicted in **g/kg** (grams of water vapor per kg of dry air), not the raw ERA5 kg/kg. During data preparation, ERA5 q values were multiplied by 1000 before normalization. This scaling is baked into the model's normalization statistics (`mean.nc` / `std.nc`), so denormalized output will be in g/kg. Typical near-surface values range from 0–25 g/kg.
118
+
119
+ ## Citation
120
 
121
  ```bibtex
122
  @article{chen2023fuxi,
123
+ title={FuXi: A cascade machine learning forecasting system for 15-day global weather forecast},
124
+ author={Chen, Lei and Zhong, Xiaohui and Zhang, Feng and Cheng, Yuan and Xu, Yinghui and Qi, Yuan and Li, Hao},
125
+ journal={npj Climate and Atmospheric Science},
126
+ year={2023}
 
 
 
127
  }
128
  ```
129
 
130
+ ## License
 
 
131
 
132
+ Please refer to the model license for usage terms.