Skip to content

Commit

Permalink
Merge pull request #942 from JohnSnowLabs/fix-checkpoints
Browse files Browse the repository at this point in the history
fix: checkpoint for multi model
  • Loading branch information
ArshaanNazir authored Dec 23, 2023
2 parents ce13bd1 + 611cf01 commit 1c3e32d
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions langtest/utils/checkpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,19 @@


class CheckpointManager:
_instance = None # Class variable to store the singleton instance
def __init__(self, checkpoint_folder="checkpoints"):
"""Initialize the CheckpointManager.
def __new__(cls, checkpoint_folder="checkpoints"):
if cls._instance is None:
cls._instance = super(CheckpointManager, cls).__new__(cls)
# Initialize the instance only if it doesn't exist
cls._instance.checkpoint_folder = checkpoint_folder
cls._instance.complete_folder = os.path.join(checkpoint_folder, "complete")
cls._instance.remaining_folder = os.path.join(checkpoint_folder, "remaining")

os.makedirs(cls._instance.checkpoint_folder, exist_ok=True)
os.makedirs(cls._instance.complete_folder, exist_ok=True)
os.makedirs(cls._instance.remaining_folder, exist_ok=True)
Args:
checkpoint_folder (str): The directory to store checkpoints and batch information.
"""
self.checkpoint_folder = checkpoint_folder
self.complete_folder = os.path.join(checkpoint_folder, "complete")
self.remaining_folder = os.path.join(checkpoint_folder, "remaining")

return cls._instance
os.makedirs(self.checkpoint_folder, exist_ok=True)
os.makedirs(self.complete_folder, exist_ok=True)
os.makedirs(self.remaining_folder, exist_ok=True)

def save_checkpoint(self, check_point_extension: str, results_so_far: List[Sample]):
"""Save a checkpoint with partial results.
Expand Down

0 comments on commit 1c3e32d

Please sign in to comment.