class_docstr: An operation which loads a checkpoint during training of an
  OpenAlphaTensor model.
class_docstr_tok: ["An","operation","which","loads","a","checkpoint","during","training","of","an","OpenAlphaTensor","model","."]
docstr: Load a checkpoint from a directory.
  
  Args:
      model: The model to load the checkpoint into.
      optimizer: The optimizer to load the checkpoint into.
      checkpoint_dir: The directory to load the checkpoint from.
docstr_tok: ["Load","a","checkpoint","from","a","directory",".","Args",":","model",":","The","model","to","load","the","checkpoint","into",".","optimizer",":","The","optimizer","to","load","the","checkpoint","into",".","checkpoint_dir",":","The","directory","to","load","the","checkpoint","from","."]
code: def execute(
      self,
      model: AlphaTensorModel,
      optimizer: torch.optim.Optimizer,
      checkpoint_dir: str,
  ):
      """Load a checkpoint from a directory.
  
      Args:
          model: The model to load the checkpoint into.
          optimizer: The optimizer to load the checkpoint into.
          checkpoint_dir: The directory to load the checkpoint from.
      """
      checkpoint_dir = checkpoint_dir or BASE_CHECKPOINT_DIR
      if (
          Path(checkpoint_dir).exists()
          and len(list(Path(checkpoint_dir).glob("*.pt"))) > 0
      ):
  
          def key_func(x):
              return int(x.stem.split("_")[-1])
  
          checkpoint_path = sorted(
              Path(checkpoint_dir).glob("*.pt"), key=key_func
          )[-1]
          print(f"Loading checkpoint from {checkpoint_path}")
          old_device = model.device
          checkpoint = torch.load(checkpoint_path)
          model.load_state_dict(checkpoint["model_state_dict"])
          model.to(old_device)
          print(f"Loaded model to {old_device}")
          optimizer.load_state_dict(checkpoint["optimizer_state_dict"])
          optimizer_to(optimizer, old_device)
          last_epoch = int(checkpoint_path.stem.split("_")[-1])
      else:
          last_epoch = 0
  
      self._last_epoch = last_epoch
      self._model = model
      self._optimizer = optimizer
  
imports: from pathlib import Path
  from typing import Any
  import torch
  from nebullvm.operations.base import Operation
  from open_alpha_tensor.config import BASE_CHECKPOINT_DATA_DIR, BASE_CHECKPOINT_DIR
  from open_alpha_tensor.core.modules.alpha_tensor import AlphaTensorModel
  from open_alpha_tensor.core.training import Trainer
label_desc: Use image node_id 2 for calling the LoadCheckPointOp obj's underlying member method code with example usage: obj.execute(model, optimizer, checkpoint_dir) and returns: int