| 29 | |
| 30 | |
| 31 | def get_max_ckpt_from_dir(dir_path): |
| 32 | dir_path = os.path.join(dir_path, "checkpoints") |
| 33 | # Define the pattern to match |
| 34 | pattern = r"(\d+)\.pt" |
| 35 | |
| 36 | # Initialize the maximum step number and corresponding file name |
| 37 | max_step = -1 |
| 38 | max_step_file = None |
| 39 | |
| 40 | # Iterate over all files in the directory |
| 41 | for filename in os.listdir(dir_path): |
| 42 | # If the filename matches the pattern |
| 43 | match = re.match(pattern, filename) |
| 44 | if match: |
| 45 | # Extract the step number from the filename |
| 46 | step = int(match.group(1)) |
| 47 | # If this step number is larger than the current maximum |
| 48 | if step > max_step: |
| 49 | # Update the maximum step number and corresponding file name |
| 50 | max_step = step |
| 51 | max_step_file = filename |
| 52 | |
| 53 | if max_step_file is None: |
| 54 | raise ValueError(f"No checkpoint files found in {dir_path}") |
| 55 | else: |
| 56 | print( |
| 57 | f"Found checkpoint file {max_step_file} with step {max_step} from {dir_path}" |
| 58 | ) |
| 59 | return os.path.join(dir_path, max_step_file) |
| 60 | |
| 61 | |
| 62 | def generate_run_id(exp_name): |