Skip to content

Add WeatherNext 2 weather forecasting model - #47874

Open
kashif wants to merge 10 commits into
huggingface:mainfrom
kashif:add-weathernext2
Open

Add WeatherNext 2 weather forecasting model#47874
kashif wants to merge 10 commits into
huggingface:mainfrom
kashif:add-weathernext2

Conversation

@kashif

@kashif kashif commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

CI

Adds WeatherNext 2 (FGN), Google DeepMind's global medium-range weather model. This is the first weather model in the library, so it also adds a weather-forecasting task and AutoModelForWeatherForecasting.

The model is an encode-process-decode graph network: the lat/lon grid is encoded, projected onto an icosahedral mesh, processed by a transformer with attention restricted to a k-hop neighbourhood on that mesh, and projected back. It's made probabilistic in an unusual way — one 32-dim noise vector per ensemble member modulates the scale and offset of every norm layer, so an ensemble is just several noise draws (the batch dimension here).

Two things worth a look during review:

  • The mesh, both grid↔mesh graphs and the attention mask are deterministic functions of the config, so they're built at init into non-persistent buffers and cached on disk rather than shipped in the checkpoint. Mesh, RCM permutation, k-hop mask and ball-query edges are bit-identical to the original.
  • After the RCM ordering the attention mask is banded, so attention runs over three block-diagonals instead of the full node set. That keeps a mask that would be 1.7 GB dense at 0.25° down to 1.2 GB and avoids materializing the scores. eager, sdpa and flex_attention agree to 3e-8; Flash Attention can't express this mask.

Checked against the original JAX/Haiku implementation with fixed noise on the published sample data — normalized inputs match to 1e-6 and predictions correlate at 0.999+, though there's still a ~0.04% output difference I haven't tracked down yet.

Converted checkpoints run end-to-end and beat 6h persistence comfortably (0.25°, verified against the HRES analysis):

field model persistence
2m_temperature 0.796 K 2.622 K
mean_sea_level_pressure 47.3 Pa 260 Pa
geopotential @500hPa 25.4 m²/s² 224.5 m²/s²

Still to do: push the converted weights to the Hub, and add slow integration tests pinned to them.

kashif added 4 commits August 10, 2026 11:03
Ports Google DeepMind's WeatherNext 2 (FGN) to PyTorch: encode-process-decode
graph network over an icosahedral mesh, made probabilistic by a single global
noise vector that modulates every norm layer.

Adds a weather-forecasting task and AutoModelForWeatherForecasting, since this
is the first weather model in the library.
The fiddle configs store it as an int, which tripped the strict float|None
validation. Only the 0.25 degree checkpoints set it, so the mini model never
hit this.
scipy is only needed to build the mesh at init, so importing it at module
level broke the doc build. Also swaps @DataClass below @auto_docstring, and
points the paper link at hf.co/papers.
Adds PipelineTesterMixin, a create_and_check_model on the tester, and a slow
integration test against the released checkpoint.
@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

kashif added 6 commits August 10, 2026 12:07
It imports scipy at module level, so exporting it made `from transformers
import *` require scipy.
check_repo wants every public object in the docs, and every model in at least
one auto mapping.
Adds a checkpoint link to the config docstring, which check_config_docstrings
requires, and switches the examples and the slow test to the 1 degree Mini so
they run on modest hardware.
They are read through the channel-layout properties rather than directly in
the modeling file, which is what check_config_attributes scans for.
- Fix base_model_tp_plan: the paths were copied from Llama and matched nothing,
  which is what the test I had skipped was telling me.
- Wire output capturing the way the library does it, so output_attentions
  works, and let the head propagate what the base model recorded.
- Rename WeatherNext2Processor to WeatherNext2FeatureExtractor: it subclasses
  FeatureExtractionMixin, and it was the only such class named Processor.
- Override test_attention_outputs instead of skipping it, and give every
  remaining skip a precise reason.
@github-actions

Copy link
Copy Markdown
Contributor

[For maintainers] Suggested jobs to run (before merge)

run-slow: auto, weathernext2

@github-actions

Copy link
Copy Markdown
Contributor

CI recap

Dashboard: View test results in Grafana
Latest run: 31407283156:1
Result: success | Jobs: 16 | Tests: 181,132 | Failures: 0 | Duration: 13h 57m

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants