ucast-repro-bundle / ucast_params.py
ancs21's picture
U-Cast param-count Modal job
660d32f verified
Raw
History Blame Contribute Delete
1.34 kB
"""Non-blocked U-Cast claim: count parameters from the RELEASED checkpoint
(salv47/u-cast/ucast.ckpt) — weights confirmed present on HF, no ERA5 needed."""
import modal
image = (modal.Image.debian_slim(python_version="3.11")
.pip_install("torch", "huggingface_hub", "safetensors"))
app = modal.App("ucast-params", image=image)
@app.function(timeout=1200)
def count():
import torch, collections
from huggingface_hub import hf_hub_download
p = hf_hub_download("salv47/u-cast", "ucast.ckpt")
ckpt = torch.load(p, map_location="cpu", weights_only=False)
sd = ckpt.get("state_dict", ckpt)
# model weights only (exclude optimizer/EMA duplicates if any obvious prefix)
total = sum(v.numel() for v in sd.values() if hasattr(v, "numel"))
# try to separate EMA / model if both present
groups = collections.Counter()
for k in sd:
groups[k.split(".")[0]] += sd[k].numel() if hasattr(sd[k], "numel") else 0
return {"total_state_dict_params": int(total),
"millions": round(total / 1e6, 1),
"top_level_groups": dict(groups.most_common(8)),
"num_tensors": len(sd)}
@app.local_entrypoint()
def main():
import json
r = count.remote()
print(json.dumps(r, indent=2))
with open("ucast_params.json", "w") as f:
json.dump(r, f, indent=2)