    def save_model_card(self, save_directory_or_file):
        """
        Write model card to the given filepath or directory

        Args:
            save_directory_or_file (`str`):
                file path or directory to write and save model card.
        """
        model_card = f"# {self.model_name}"
        model_card += f"\n\n## Model overview\n{self.model_overview}\n"
        model_card += f"\n\n### Model architecture\n{self.model_architecture}\n"

        model_card += "\n\n## Dataset"
        if self.datasets is None:
            model_card += "\nDataset unknown.\n"
        else:
            if isinstance(self.datasets, str):
                model_card += f"\nUsing the {self.datasets} as dataset.\n"
            elif isinstance(self.dataset, (tuple, list)) and len(self.datasets) == 1:
                model_card += f"\nUsing the {self.datasets} as dataset.\n"
            else:
                model_card += (
                        "\n, ".join(
                            [f"Using the {dataset}" for dataset in self.datasets[:-1]])
                        + f" and the {self.datasets[-1]} dataset.\n"
                )

        model_card += "\n\n## Training configurations\n"
        if self.training_config is not None:
            if self.training_config.optimizer is not None:
                if isinstance(self.training_config.optimizer, str):
                    model_card += f"\nOptimizer is  {self.training_config.optimizer}.\n"
                else:
                    model_card += "\n".join([f"- {name}: "
                                             f"{value}" for name, value in self.training_config.optimizer.items()])
                    model_card += "\n"
            if self.training_config.lr_scheduler_type is not None:
                model_card += f"\nThe scheduler type is {self.training_config.lr_scheduler_type}.\n"
            if self.training_config.warmup_ratio is not None:
                model_card += f"\nThe warmup_ratio is {self.training_config.warmup_ratio}.\n"
            if self.training_config.warmup_steps is not None:
                model_card += f"\nThe warmup_steps is {self.training_config.warmup_steps}.\n"
            if self.training_config.lr is not None:
                model_card += f"\nLearning rate is {self.training_config.lr}.\n"
            else:
                model_card += "\nLearning rate is needed.\n"
            # if self.training_config.weight_decay is not None:
            #     model_card += f"\nWeight decay is {self.training_config.weight_decay}."
            # if self.training_config.adam_beta1 is not None:
            #     model_card += f"\nBeta1 for AdamW optimizer is {self.training_config.adam_beta1}."
            # if self.training_config.adam_beta2 is not None:
            #     model_card += f"\nBeta2 for AdamW optimizer is {self.training_config.adam_beta2}."
            # if self.training_config.adam_epsilon is not None:
            #     model_card += f"\nEpsilon for AdamW optimizer is {self.training_config.adam_epsilon}."
            if self.training_config.metric is not None:
                model_card += f"\nMetric is {self.training_config.metric}.\n"
            #
            # if self.training_config.max_norm_grad is not None:
            #     model_card += f"\nMax gradient norm is {self.training_config.max_norm_grad}."
            if self.training_config.batch_size is not None:
                model_card += f"\nBatch size is {self.training_config.batch_size}.\n"
            if self.training_config.seed is not None:
                model_card += f"\nRandom seed is {self.training_config.seed}.\n"
            if self.training_config.epoch_num is not None:
                model_card += f"\nTraining epochs is {self.training_config.epoch_num}.\n"
            # if self.training_config.n_gpu is not None:
            #     model_card += f"\nNumber of GPUs is {self.training_config.n_gpu}.\n"
        else:
            model_card += "\nTraining configurations is needed.\n"

        model_card += "\n\n## Training summary\n"
        if self.training_summary is not None:
            model_card += "\n"
            model_card += "\n".join([f"- {name}: {value}" for name, value in self.training_summary.items()])
            model_card += "\n"
        else:
            model_card += "\nTraining summary is needed.\n"

        if Path.is_dir(Path(save_directory_or_file)):
            # If we save using the predefined names, we can load using `from_pretrained`
            output_model_card_file = Path(save_directory_or_file).joinpath(MODEL_CARD_NAME)
        else:
            output_model_card_file = save_directory_or_file

        with open(output_model_card_file, "w", encoding="utf-8") as f:
            f.write(model_card)
Write model card to the given filepath or directory

Args:
save_directory_or_file (`str`):
file path or directory to write and save model card.
towhee/trainer/modelcard.py