|
23 | 23 |
|
24 | 24 | logger = RankedLogger(__name__, rank_zero_only=True) |
25 | 25 |
|
| 26 | + |
| 27 | +def _normalize_optional_str(val: Any) -> Optional[str]: |
| 28 | + """Return a non-empty string or None. |
| 29 | +
|
| 30 | + Hydra CLI ``...=null`` / YAML ``null`` sometimes surface as the literal |
| 31 | + string ``\"None\"``; treat those like missing so Hub / fallbacks work. |
| 32 | + """ |
| 33 | + if val is None: |
| 34 | + return None |
| 35 | + try: |
| 36 | + if OmegaConf.is_missing(val): |
| 37 | + return None |
| 38 | + except (ValueError, TypeError, AttributeError): |
| 39 | + pass |
| 40 | + if not isinstance(val, str): |
| 41 | + val = str(val) |
| 42 | + s = val.strip() |
| 43 | + if not s or s.lower() in ("none", "null", "~"): |
| 44 | + return None |
| 45 | + return s |
| 46 | + |
| 47 | + |
26 | 48 | _STR_TO_DTYPE = { |
27 | 49 | "float32": torch.float32, |
28 | 50 | "float16": torch.float16, |
@@ -271,16 +293,18 @@ def _get_full_checkpoint_path( |
271 | 293 | # Build the config path to check |
272 | 294 | if config_prefix: |
273 | 295 | # Try both ckpt_path and checkpoint_path variants |
274 | | - ckpt_path = OmegaConf.select( |
275 | | - cfg, f"{config_prefix}.ckpt_path", default=None |
| 296 | + ckpt_path = _normalize_optional_str( |
| 297 | + OmegaConf.select(cfg, f"{config_prefix}.ckpt_path", default=None) |
276 | 298 | ) |
277 | 299 | if ckpt_path is None: |
278 | | - ckpt_path = OmegaConf.select( |
279 | | - cfg, f"{config_prefix}.checkpoint_path", default=None |
| 300 | + ckpt_path = _normalize_optional_str( |
| 301 | + OmegaConf.select( |
| 302 | + cfg, f"{config_prefix}.checkpoint_path", default=None |
| 303 | + ) |
280 | 304 | ) |
281 | 305 | else: |
282 | 306 | # Top-level: check hub_checkpoint_path |
283 | | - ckpt_path = cfg.get("hub_checkpoint_path", None) |
| 307 | + ckpt_path = _normalize_optional_str(cfg.get("hub_checkpoint_path", None)) |
284 | 308 |
|
285 | 309 | if ckpt_path is not None: |
286 | 310 | if not os.path.isfile(ckpt_path): |
@@ -328,17 +352,23 @@ def _get_model_only_checkpoint_path( |
328 | 352 | """ |
329 | 353 | # Check for model_only_checkpoint_path in config |
330 | 354 | if config_prefix: |
331 | | - model_only_path = OmegaConf.select( |
332 | | - cfg, f"{config_prefix}.model_only_checkpoint_path", default=None |
| 355 | + model_only_path = _normalize_optional_str( |
| 356 | + OmegaConf.select( |
| 357 | + cfg, f"{config_prefix}.model_only_checkpoint_path", default=None |
| 358 | + ) |
333 | 359 | ) |
334 | 360 | else: |
335 | 361 | # Top-level |
336 | | - model_only_path = cfg.get("model_only_checkpoint_path", None) |
| 362 | + model_only_path = _normalize_optional_str( |
| 363 | + cfg.get("model_only_checkpoint_path", None) |
| 364 | + ) |
337 | 365 |
|
338 | 366 | # Check for hub.repo_id if enabled |
339 | 367 | hub_repo_id = None |
340 | 368 | if enable_hub_support: |
341 | | - hub_repo_id = OmegaConf.select(cfg, "hub.repo_id", default=None) |
| 369 | + hub_repo_id = _normalize_optional_str( |
| 370 | + OmegaConf.select(cfg, "hub.repo_id", default=None) |
| 371 | + ) |
342 | 372 |
|
343 | 373 | # Conflict detection |
344 | 374 | if full_ckpt_path is not None: |
|
0 commit comments