From 054b6013c2de636f14af3c7485f460164ee21e1c Mon Sep 17 00:00:00 2001 From: elishowk Date: Tue, 14 Sep 2021 18:07:36 +0200 Subject: [PATCH] separate model card git push from the rest (#13514) Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com> --- docs/source/model_sharing.rst | 4 ++-- src/transformers/trainer.py | 12 ++++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/docs/source/model_sharing.rst b/docs/source/model_sharing.rst index 1f24e590f8..c951c92c33 100644 --- a/docs/source/model_sharing.rst +++ b/docs/source/model_sharing.rst @@ -341,8 +341,8 @@ Add a model card To make sure everyone knows what your model can do, what its limitations, potential bias or ethical considerations are, please add a README.md model card to your model repo. You can just create it, or there's also a convenient button -titled "Add a README.md" on your model page. A model card template can be found `here -`__ (meta-suggestions are welcome). model card template (meta-suggestions +titled "Add a README.md" on your model page. A model card documentation can be found `here +`__ (meta-suggestions are welcome). model card template (meta-suggestions are welcome). .. note:: diff --git a/src/transformers/trainer.py b/src/transformers/trainer.py index 26431cd86d..e745ff121a 100755 --- a/src/transformers/trainer.py +++ b/src/transformers/trainer.py @@ -2625,7 +2625,6 @@ class Trainer: model_name = Path(self.args.output_dir).name else: model_name = self.args.hub_model_id.split("/")[-1] - self.create_model_card(model_name=model_name, **kwargs) # Needs to be executed on all processes for TPU training, but will only save on the processed determined by # self.args.should_save. self.save_model() @@ -2634,7 +2633,16 @@ class Trainer: if not self.is_world_process_zero(): return - return self.repo.push_to_hub(commit_message=commit_message, blocking=blocking) + git_head_commit_url = self.repo.push_to_hub(commit_message=commit_message, blocking=blocking) + # push separately the model card to be independant from the rest of the model + if self.args.should_save: + self.create_model_card(model_name=model_name, **kwargs) + try: + self.repo.push_to_hub(commit_message="update model card README.md", blocking=blocking) + except EnvironmentError as exc: + logger.error(f"Error pushing update to the model card. Please read logs and retry.\n${exc}") + + return git_head_commit_url # # Deprecated code