Skip to content

Commit 054b601

Browse files
elishowksgugger
elishowk
andauthored
separate model card git push from the rest (#13514)
Co-authored-by: Sylvain Gugger <[email protected]>
1 parent 9f318be commit 054b601

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

docs/source/model_sharing.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,8 @@ Add a model card
341341

342342
To make sure everyone knows what your model can do, what its limitations, potential bias or ethical considerations are,
343343
please add a README.md model card to your model repo. You can just create it, or there's also a convenient button
344-
titled "Add a README.md" on your model page. A model card template can be found `here
345-
<https://github.com/huggingface/model_card>`__ (meta-suggestions are welcome). model card template (meta-suggestions
344+
titled "Add a README.md" on your model page. A model card documentation can be found `here
345+
<https://huggingface.co/docs/hub/model-repos>`__ (meta-suggestions are welcome). model card template (meta-suggestions
346346
are welcome).
347347

348348
.. note::

src/transformers/trainer.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -2625,7 +2625,6 @@ def push_to_hub(self, commit_message: Optional[str] = "End of training", blockin
26252625
model_name = Path(self.args.output_dir).name
26262626
else:
26272627
model_name = self.args.hub_model_id.split("/")[-1]
2628-
self.create_model_card(model_name=model_name, **kwargs)
26292628
# Needs to be executed on all processes for TPU training, but will only save on the processed determined by
26302629
# self.args.should_save.
26312630
self.save_model()
@@ -2634,7 +2633,16 @@ def push_to_hub(self, commit_message: Optional[str] = "End of training", blockin
26342633
if not self.is_world_process_zero():
26352634
return
26362635

2637-
return self.repo.push_to_hub(commit_message=commit_message, blocking=blocking)
2636+
git_head_commit_url = self.repo.push_to_hub(commit_message=commit_message, blocking=blocking)
2637+
# push separately the model card to be independant from the rest of the model
2638+
if self.args.should_save:
2639+
self.create_model_card(model_name=model_name, **kwargs)
2640+
try:
2641+
self.repo.push_to_hub(commit_message="update model card README.md", blocking=blocking)
2642+
except EnvironmentError as exc:
2643+
logger.error(f"Error pushing update to the model card. Please read logs and retry.\n${exc}")
2644+
2645+
return git_head_commit_url
26382646

26392647
#
26402648
# Deprecated code

0 commit comments

Comments
 (0)