    def save(self, path, overwrite=True):
        """
        Save the checkpoint information in a folder.

        Args:
            path (`Any`):
                The folder path containing the model's checkpoints.
            overwrite (`bool`):
                If True, it will overwrite the same name path when existing.

        Raises:
            (`FileExistsError`)
                If `overwrite` is False, when there already exists a path, it will raise Error.
        """
        if is_main_process():
            if not overwrite:
                if Path(path).exists():
                    raise FileExistsError("File already exists: ", str(Path(path).resolve()))
            Path(path).mkdir(exist_ok=True)
            state_path = Path(path).joinpath(STATE_CHECKPOINT_NAME)
            model_path = Path(path).joinpath(MODEL_NAME)
            modelcard_path = Path(path).joinpath(MODEL_CARD_NAME)
            trainer_log.info("save model_path: %s", model_path)
            optimizer_state_dict = None
            lr_scheduler_state_dict = None
            if isinstance(self.optimizer, Optimizer):  # if created
                optimizer_state_dict = self.optimizer.state_dict()
            if self.lr_scheduler is not None:
                lr_scheduler_state_dict = self.lr_scheduler.state_dict()
            torch.save({
                "epoch": self.epoch,
                "optimizer_state_dict": optimizer_state_dict,
                "lr_scheduler_state_dict": lr_scheduler_state_dict,
                "loss_value": self.loss_value,
                "metric_value": self.metric_value,
                "end_lr": self.lr_value
            }, state_path)
            torch.save(unwrap_model(self.model).state_dict(), model_path)
            if isinstance(self.model_card, ModelCard):
                self.model_card.save_model_card(modelcard_path)
            else:
                trainer_log.warning("model card is None.")
Save the checkpoint information in a folder.

Args:
path (`Any`):
The folder path containing the model's checkpoints.
overwrite (`bool`):
If True, it will overwrite the same name path when existing.

Raises:
(`FileExistsError`)
If `overwrite` is False, when there already exists a path, it will raise Error.
towhee/trainer/trainer.py