Skip to content

WIP: GraphCast_small in SQL, with DeepMind's published weights - #270

Draft
alxmrs wants to merge 2 commits into
ml-demosfrom
graphcast-weights
Draft

alxmrs wants to merge 2 commits into
ml-demosfrom
graphcast-weights

Conversation

@alxmrs

@alxmrs alxmrs commented Oct 17, 2026 •

Copy link
Copy Markdown
Member

Stacked on #269. This replaces the miniature 03_graphcast.py with GraphCast_small as DeepMind publishes it:

  • a 1° grid with 13 pressure levels;
  • a mesh refined 5 times;
  • 16 message-passing rounds;
  • 36M weights.

GraphCast is DeepMind's graph neural network for weather forecasting. Here it's written as SQL views over tables registered through xarray-sql, one view per stage.

Status: work in progress. As stored tables, the encoder and one processor round have run end to end on einfold and match DeepMind's model. As views, it doesn't run past the encoder on any engine yet, for the upstream reasons below.

What's here

  • _graphcast.py: everything on DeepMind's side.
    • It fetches the checkpoint, the 1° example from ERA5 (ECMWF's reanalysis of the atmosphere) and the normalization statistics from gs://dm_graphcast, cached in ~/.cache/xarray-sql/graphcast.
    • It builds the three graphs with DeepMind's own code: grid→mesh with 101,892 edges, mesh with 81,900, and mesh→grid with 195,480. It exports them as Datasets.
    • It turns the checkpoint into long-form tables: weights(net, f, g, w), biases, norms and nets(net, name).
    • deepmind_stages() and deepmind_forecast() run DeepMind's model in float32.
    • mirror() is a plain JAX transcription of the model, checked against DeepMind's. It can stop after any processor round, so the SQL can be checked one round at a time.
  • 03_graphcast.py: the model in SQL.
    • Every network is the same mlp(): a matrix product, bias plus swish (x · sigmoid(x)), a second matrix product and bias, then a layer norm through OVER (PARTITION BY id) windows.
    • Each stage is a CREATE VIEW of the stages before it.
    • The checks and the forecast are plain queries of those views.
    • Inputs are normalized and stacked into DeepMind's 183 channels in SQL. The mesh nodes' zero inputs are absent rows.
    • receptive_field() and program(..., regional=True) write an exact regional forecast: the same stages, each limited by semi-joins to what the region needs. It hasn't run yet.
    • --sizes is the number of processor rounds. At 16, the forecast is checked against DeepMind's.
  • Hosts take a memory limit (--memory, in GB), and spill to ~/.cache/xarray-sql/spill.

Measured

Measured on an Intel i7-8700 with einfold 0.1.0rc2, DataFusion 55.0.0, DuckDB 1.5.6 and ddxdb 0.4.6. Details are in #285 and xqlsystems/einfold#36.

Next

  1. Run the views once DataFusion computes each shared read once (DataFusion plans a CTE once per reference, so ML queries grow exponentially with depth #267).
  2. Run the full 16-round forecast and compare it with deepmind_forecast().
  3. Run the exact regional forecast, then an approximate one (ORDER BY distance LIMIT k), and plot its error.

🤖 Generated with Claude Code

https://claude.ai/code/session_01NyN7idACeDMh94qrnFMu6h

@coderabbitai

coderabbitai Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@alxmrs
alxmrs force-pushed the graphcast-weights branch 8 times, most recently from b821fa1 to 644ead4 Compare October 21, 2026 00:23
@alxmrs
alxmrs force-pushed the graphcast-weights branch from 644ead4 to 4f29d2f Compare October 21, 2026 09:17
@alxmrs
alxmrs force-pushed the graphcast-weights branch 2 times, most recently from bdce766 to 8f358fd Compare October 25, 2026 03:25
alxmrs added a commit that referenced this pull request Oct 25, 2026
GraphCast takes about 6 minutes at its default 2 rounds and builds on
WeatherBench 2 data, so it lands with the work on its published weights
(#270). This PR keeps the attention and nanoGPT demos.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NyN7idACeDMh94qrnFMu6h
@alxmrs
alxmrs force-pushed the graphcast-weights branch from 8f358fd to 785c32b Compare October 25, 2026 16:51
@alxmrs
alxmrs force-pushed the graphcast-weights branch from 785c32b to 1721481 Compare October 25, 2026 18:44
@alxmrs
alxmrs force-pushed the graphcast-weights branch from 1721481 to 12e33f5 Compare October 25, 2026 19:24
@alxmrs
alxmrs force-pushed the ml-demos branch 2 times, most recently from 536b005 to 968b41e Compare October 25, 2026 19:25
@alxmrs
alxmrs force-pushed the graphcast-weights branch 3 times, most recently from b0fe9af to e05fae2 Compare October 25, 2026 20:56
@alxmrs alxmrs added the ml Gradients in SQL, the ml extra and its demos label Oct 25, 2026
@alxmrs
alxmrs force-pushed the graphcast-weights branch from e05fae2 to 4bcbbbd Compare October 25, 2026 23:35
alxmrs added a commit that referenced this pull request Oct 25, 2026
GraphCast takes about 6 minutes at its default 2 rounds and builds on
WeatherBench 2 data, so it lands with the work on its published weights
(#270). This PR keeps the attention and nanoGPT demos.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NyN7idACeDMh94qrnFMu6h
@alxmrs
alxmrs force-pushed the graphcast-weights branch from 4bcbbbd to 5c39c17 Compare October 26, 2026 02:11
alxmrs added a commit that referenced this pull request Oct 26, 2026
GraphCast takes about 6 minutes at its default 2 rounds and builds on
WeatherBench 2 data, so it lands with the work on its published weights
(#270). This PR keeps the attention and nanoGPT demos.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NyN7idACeDMh94qrnFMu6h
Each stage of GraphCast_small is now a view of the stages before it,
and the checks and the forecast are plain queries of those views. This
drops Host.store and Host.drop, which kept each stage as a table so no
engine computed a CTE twice: the demos write the SQL a reader would, and
making it fast is the engines' work. The hosts keep their memory limit
and spill directory, which change no SQL.

Rebased onto ml-demos at 6debe24: einfold is a host, with the memory
limit like the others.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NyN7idACeDMh94qrnFMu6h

This branch has not been deployed

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

Labels

ml Gradients in SQL, the ml extra and its demos

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant