multimodalart HF Staff commited on
Commit
1fe46a3
·
verified ·
1 Parent(s): 625311b

Support bare state-dict checkpoint layout

Browse files
Files changed (1) hide show
  1. app.py +29 -5
app.py CHANGED
@@ -96,10 +96,28 @@ print("Fetching MiniWorld-1B (RealEstate10K) ...", flush=True)
96
  ckpt_path = hf_hub_download(MINIWORLD_REPO, MINIWORLD_CKPT)
97
 
98
  _ckpt = torch.load(ckpt_path, map_location="cpu")
99
- _weights = _ckpt.get("ema_model", _ckpt.get("model"))
100
- _meta = _ckpt.get("meta", {}) or {}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
101
  if _weights is None:
102
- raise RuntimeError("MiniWorld checkpoint has neither `ema_model` nor `model`")
 
 
 
103
 
104
 
105
  def _resolve_latent_frames() -> int:
@@ -147,9 +165,15 @@ denoiser = build_denoiser_from_mode(
147
  df_ardiff_step=DF_ARDIFF_STEP,
148
  )
149
  ).eval()
150
- denoiser.load_state_dict(_weights, strict=True)
 
 
 
 
 
 
151
  denoiser.trained_num_frames = TRAINED_NUM_FRAMES
152
- print("[Checkpoint] loaded: all keys matched", flush=True)
153
  del _ckpt, _weights
154
 
155
  denoiser = denoiser.to("cuda")
 
96
  ckpt_path = hf_hub_download(MINIWORLD_REPO, MINIWORLD_CKPT)
97
 
98
  _ckpt = torch.load(ckpt_path, map_location="cpu")
99
+ _meta: dict = {}
100
+ _weights = None
101
+ if isinstance(_ckpt, dict):
102
+ # `miniworld/sample.py` expects a training checkpoint wrapper; the *released*
103
+ # weights are a bare state dict of `net.*` tensors, so support both.
104
+ for _key in ("ema_model", "model", "ema", "state_dict", "module"):
105
+ cand = _ckpt.get(_key)
106
+ if isinstance(cand, dict) and cand:
107
+ _weights = cand
108
+ _meta = _ckpt.get("meta") or {}
109
+ print(f"[Checkpoint] using wrapped weights under {_key!r}", flush=True)
110
+ break
111
+ if _weights is None and any(
112
+ isinstance(k, str) and k.startswith("net.") for k in _ckpt
113
+ ):
114
+ _weights = _ckpt
115
+ print("[Checkpoint] bare state dict (no training wrapper)", flush=True)
116
  if _weights is None:
117
+ raise RuntimeError(
118
+ "Unrecognised MiniWorld checkpoint layout; top-level keys: "
119
+ f"{list(_ckpt)[:8] if isinstance(_ckpt, dict) else type(_ckpt)}"
120
+ )
121
 
122
 
123
  def _resolve_latent_frames() -> int:
 
165
  df_ardiff_step=DF_ARDIFF_STEP,
166
  )
167
  ).eval()
168
+ _missing, _unexpected = denoiser.load_state_dict(_weights, strict=False)
169
+ if _missing or _unexpected:
170
+ raise RuntimeError(
171
+ f"MiniWorld checkpoint does not match the built model.\n"
172
+ f"missing ({len(_missing)}): {_missing[:12]}\n"
173
+ f"unexpected ({len(_unexpected)}): {_unexpected[:12]}"
174
+ )
175
  denoiser.trained_num_frames = TRAINED_NUM_FRAMES
176
+ print(f"[Checkpoint] loaded: all {len(_weights)} keys matched", flush=True)
177
  del _ckpt, _weights
178
 
179
  denoiser = denoiser.to("cuda")