| 10 | |
| 11 | |
| 12 | def wandb_runid_from_checkpoint(checkpoint_path): |
| 13 | # Python |
| 14 | import os |
| 15 | import re |
| 16 | |
| 17 | # Define the directory to search |
| 18 | dir_path = os.path.join(checkpoint_path, "wandb/latest-run") |
| 19 | # Define the pattern to match |
| 20 | pattern = r"run-(\w+)\.wandb" |
| 21 | |
| 22 | # Iterate over all files in the directory |
| 23 | for filename in os.listdir(dir_path): |
| 24 | # If the filename matches the pattern |
| 25 | if re.match(pattern, filename): |
| 26 | # Extract the desired part of the filename |
| 27 | extracted_part = re.match(pattern, filename).group(1) |
| 28 | logging.info(f"induced run id from ckpt: {extracted_part}") |
| 29 | return extracted_part |
| 30 | raise ValueError("No file found that matches the pattern") |
| 31 | |
| 32 | |
| 33 | def instantiate_from_config(config): |