Skip to content

Commit

Permalink
Merge pull request #24 from becktepe/main
Browse files Browse the repository at this point in the history
[Fix] Add support for directory checkpoints in PBT that can be removed using self-destruct
  • Loading branch information
TheEimer authored Dec 20, 2024
2 parents eca6700 + 16ee565 commit fb79522
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions hydra_plugins/hyper_pbt/hyper_pbt.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

from __future__ import annotations

from pathlib import Path
import os
import shutil

import numpy as np
from ConfigSpace.hyperparameters import (CategoricalHyperparameter,
Expand Down Expand Up @@ -172,12 +173,14 @@ def tell(self, info, value):

def remove_checkpoints(self, iteration: int) -> None:
"""Remove checkpoints."""
import os

# Delete all files in checkpoints dir starting with iteration_{iteration}
for file in os.listdir(self.checkpoint_dir):
if file.startswith(f"iteration_{iteration}"):
(Path(self.checkpoint_dir) / file).unlink()
file_path = os.path.join(self.checkpoint_dir, file)
if os.path.isfile(file_path):
os.remove(file_path)
else:
shutil.rmtree(file_path)


def make_pbt(configspace, pbt_args):
Expand Down

0 comments on commit fb79522

Please sign in to comment.