Skip to content

Commit

Permalink
fix: PBT self-destruct for directories + files
Browse files Browse the repository at this point in the history
  • Loading branch information
becktepe committed Oct 15, 2024
1 parent c559733 commit a592703
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions hydra_plugins/hyper_pbt/hyper_pbt.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

from __future__ import annotations

import os
import shutil

import numpy as np
from ConfigSpace.hyperparameters import (
CategoricalHyperparameter,
NormalIntegerHyperparameter,
OrdinalHyperparameter,
UniformIntegerHyperparameter,
)
from ConfigSpace.hyperparameters import (CategoricalHyperparameter,
NormalIntegerHyperparameter,
OrdinalHyperparameter,
UniformIntegerHyperparameter)

from hydra_plugins.hypersweeper import Info


Expand Down Expand Up @@ -171,12 +173,15 @@ 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}"):
os.remove(os.path.join(self.checkpoint_dir, file))
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):
"""Make a PBT instance for optimization."""
Expand Down

0 comments on commit a592703

Please sign in to comment.