Resolve run root from a path that may point to: - - /checkpoints - /checkpoints/checkpoint_123 - /checkpoint_123 Returns: Path to
(path_str: str)
| 24 | |
| 25 | |
| 26 | def _resolve_run_root(path_str: str) -> Path: |
| 27 | """ |
| 28 | Resolve run root from a path that may point to: |
| 29 | - <run_root> |
| 30 | - <run_root>/checkpoints |
| 31 | - <run_root>/checkpoints/checkpoint_123 |
| 32 | - <run_root>/checkpoint_123 |
| 33 | |
| 34 | Returns: |
| 35 | Path to <run_root> |
| 36 | """ |
| 37 | p = Path(path_str).expanduser().resolve() |
| 38 | |
| 39 | if p.name.startswith("checkpoint_"): |
| 40 | # .../checkpoints/checkpoint_123 -> run_root is parent of "checkpoints" |
| 41 | if p.parent.name == "checkpoints": |
| 42 | return p.parent.parent |
| 43 | # .../checkpoint_123 -> run_root is parent |
| 44 | return p.parent |
| 45 | |
| 46 | if p.name == "checkpoints": |
| 47 | return p.parent |
| 48 | |
| 49 | return p |
| 50 | |
| 51 | |
| 52 | def _queue_dir(run_root: Path) -> Path: |
no outgoing calls
no test coverage detected