ancs21 commited on
Commit
a9ceba1
·
verified ·
1 Parent(s): 305e081

add ERA5 inference

Browse files
Files changed (1) hide show
  1. ucast_inference.py +44 -0
ucast_inference.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """U-Cast (#10467) rescue: run the REAL ERA5 forecasting benchmark on Modal.
2
+
3
+ Uses the paper's standalone inference script with the released checkpoint,
4
+ streams ERA5 from public WeatherBench2 GCS, computes RMSE + CRPS (--score).
5
+ This targets U-Cast's actual performance claim, not just its param count.
6
+ """
7
+ import modal
8
+
9
+ REPO = "u-cast"
10
+ image = (modal.Image.debian_slim(python_version="3.11")
11
+ .pip_install("torch", "xarray", "netCDF4", "zarr<3", "einops", "tqdm",
12
+ "pyyaml", "huggingface_hub", "gcsfs", "numpy", "scipy", "dask")
13
+ .add_local_dir(REPO, f"/root/{REPO}", copy=True))
14
+ app = modal.App("ucast-inference", image=image)
15
+
16
+
17
+ @app.function(gpu="A10G", timeout=3600)
18
+ def run_infer(ic_date="2020-01-01", ensemble=5, horizon=10):
19
+ import subprocess, os, re
20
+ os.chdir(f"/root/{REPO}")
21
+ cmd = [
22
+ "python", "run_inference_standalone.py",
23
+ "--ckpt-path", "hf:salv47/u-cast/ucast.ckpt",
24
+ "--data-dir", "gs://weatherbench2/datasets/era5",
25
+ "--config-path", "configs/config_inference.yaml",
26
+ "--ic-start-dates", ic_date,
27
+ "--ensemble-size", str(ensemble),
28
+ "--prediction-horizon", str(horizon),
29
+ "--score",
30
+ ]
31
+ p = subprocess.run(cmd, capture_output=True, text=True, timeout=3200)
32
+ out = p.stdout + "\n" + p.stderr
33
+ # capture score lines (RMSE / CRPS)
34
+ scores = [l for l in out.splitlines() if re.search(r"RMSE|CRPS|crps|rmse|score", l, re.I)]
35
+ return {"returncode": p.returncode, "score_lines": scores[-40:], "tail": out.splitlines()[-40:]}
36
+
37
+
38
+ @app.local_entrypoint()
39
+ def main():
40
+ import json
41
+ r = run_infer.remote()
42
+ print(json.dumps(r, indent=2))
43
+ with open("ucast_inference_results.json", "w") as f:
44
+ json.dump(r, f, indent=2)