From 737601bcec152eb3e8bf030bea0d9203eb4f93ef Mon Sep 17 00:00:00 2001 From: Arthur Zucker Date: Mon, 6 Mar 2023 14:32:34 +0000 Subject: [PATCH 1/7] add create pr arg --- src/transformers/modeling_tf_utils.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/transformers/modeling_tf_utils.py b/src/transformers/modeling_tf_utils.py index 29c4d67510c3..4f507224e940 100644 --- a/src/transformers/modeling_tf_utils.py +++ b/src/transformers/modeling_tf_utils.py @@ -2907,6 +2907,7 @@ def push_to_hub( private: Optional[bool] = None, use_auth_token: Optional[Union[bool, str]] = None, max_shard_size: Optional[Union[int, str]] = "10GB", + create_pr: bool = False, **model_card_kwargs, ) -> str: """ @@ -2933,7 +2934,8 @@ def push_to_hub( by a unit (like `"5MB"`). model_card_kwargs: Additional keyword arguments passed along to the [`~TFPreTrainedModel.create_model_card`] method. - + create_pr (`bool`, *optional*, defaults to `False`): + Whether or not to create a PR with the uploaded files or directly commit. Examples: ```python @@ -2986,7 +2988,7 @@ def push_to_hub( self.create_model_card(**base_model_card_args) self._upload_modified_files( - work_dir, repo_id, files_timestamps, commit_message=commit_message, token=use_auth_token + work_dir, repo_id, files_timestamps, commit_message=commit_message, token=use_auth_token, create_pr = create_pr, ) @classmethod From 032f7ff9eefd3766a24e2dcbb7e999595f07159b Mon Sep 17 00:00:00 2001 From: Arthur Zucker Date: Mon, 6 Mar 2023 14:34:20 +0000 Subject: [PATCH 2/7] style --- src/transformers/modeling_tf_utils.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/transformers/modeling_tf_utils.py b/src/transformers/modeling_tf_utils.py index 4f507224e940..78aa0a1f2b8a 100644 --- a/src/transformers/modeling_tf_utils.py +++ b/src/transformers/modeling_tf_utils.py @@ -2988,7 +2988,12 @@ def push_to_hub( self.create_model_card(**base_model_card_args) self._upload_modified_files( - work_dir, repo_id, files_timestamps, commit_message=commit_message, token=use_auth_token, create_pr = create_pr, + work_dir, + repo_id, + files_timestamps, + commit_message=commit_message, + token=use_auth_token, + create_pr=create_pr, ) @classmethod From 35d37d5b9849f803e4bdb4b4c538098ee9dc08ef Mon Sep 17 00:00:00 2001 From: Arthur Zucker Date: Mon, 6 Mar 2023 15:56:22 +0000 Subject: [PATCH 3/7] add test --- tests/test_modeling_tf_common.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/test_modeling_tf_common.py b/tests/test_modeling_tf_common.py index 9cfd314dfcbf..7be6159a4a81 100644 --- a/tests/test_modeling_tf_common.py +++ b/tests/test_modeling_tf_common.py @@ -94,6 +94,8 @@ TFBertModel, TFRagModel, TFSharedEmbeddings, + TFPreTrainedModel, + PreTrainedModel, ) from transformers.generation import ( TFBeamSampleDecoderOnlyOutput, @@ -2466,6 +2468,7 @@ def test_push_to_hub(self): break self.assertTrue(models_equal) + def test_push_to_hub_callback(self): config = BertConfig( vocab_size=99, hidden_size=32, num_hidden_layers=5, num_attention_heads=4, intermediate_size=37 @@ -2489,6 +2492,10 @@ def test_push_to_hub_callback(self): break self.assertTrue(models_equal) + tf_push_to_hub_params = dict(inspect.signature(TFPreTrainedModel.push_to_hub).parameters) + pt_push_to_hub_params = dict(inspect.signature(PreTrainedModel.push_to_hub).parameters) + self.assertDictEaual(tf_push_to_hub_params, pt_push_to_hub_params) + def test_push_to_hub_in_organization(self): config = BertConfig( vocab_size=99, hidden_size=32, num_hidden_layers=5, num_attention_heads=4, intermediate_size=37 From 9d3a14f259d2729f76fb2982d2f688787d5e3323 Mon Sep 17 00:00:00 2001 From: Arthur Zucker Date: Mon, 6 Mar 2023 16:06:31 +0000 Subject: [PATCH 4/7] ficup --- tests/test_modeling_tf_common.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/test_modeling_tf_common.py b/tests/test_modeling_tf_common.py index 7be6159a4a81..c435b3c5aa28 100644 --- a/tests/test_modeling_tf_common.py +++ b/tests/test_modeling_tf_common.py @@ -85,6 +85,7 @@ TF_MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING, TF_MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING, BertConfig, + PreTrainedModel, PushToHubCallback, RagRetriever, TFAutoModel, @@ -92,10 +93,9 @@ TFBertForMaskedLM, TFBertForSequenceClassification, TFBertModel, + TFPreTrainedModel, TFRagModel, TFSharedEmbeddings, - TFPreTrainedModel, - PreTrainedModel, ) from transformers.generation import ( TFBeamSampleDecoderOnlyOutput, @@ -2468,7 +2468,6 @@ def test_push_to_hub(self): break self.assertTrue(models_equal) - def test_push_to_hub_callback(self): config = BertConfig( vocab_size=99, hidden_size=32, num_hidden_layers=5, num_attention_heads=4, intermediate_size=37 From c26ffffdcfe1faba40ddff852835a6d552859481 Mon Sep 17 00:00:00 2001 From: Arthur Zucker Date: Mon, 6 Mar 2023 16:23:24 +0000 Subject: [PATCH 5/7] update test --- src/transformers/modeling_tf_utils.py | 17 ++++++++--------- tests/test_modeling_tf_common.py | 2 ++ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/transformers/modeling_tf_utils.py b/src/transformers/modeling_tf_utils.py index 78aa0a1f2b8a..2a60c7514412 100644 --- a/src/transformers/modeling_tf_utils.py +++ b/src/transformers/modeling_tf_utils.py @@ -2905,10 +2905,10 @@ def push_to_hub( use_temp_dir: Optional[bool] = None, commit_message: Optional[str] = None, private: Optional[bool] = None, - use_auth_token: Optional[Union[bool, str]] = None, max_shard_size: Optional[Union[int, str]] = "10GB", + use_auth_token: Optional[Union[bool, str]] = None, create_pr: bool = False, - **model_card_kwargs, + **base_model_card_args, ) -> str: """ Upload the model files to the 🤗 Model Hub while synchronizing a local clone of the repo in `repo_path_or_name`. @@ -2932,10 +2932,9 @@ def push_to_hub( Only applicable for models. The maximum size for a checkpoint before being sharded. Checkpoints shard will then be each of size lower than this size. If expressed as a string, needs to be digits followed by a unit (like `"5MB"`). - model_card_kwargs: - Additional keyword arguments passed along to the [`~TFPreTrainedModel.create_model_card`] method. create_pr (`bool`, *optional*, defaults to `False`): Whether or not to create a PR with the uploaded files or directly commit. + Examples: ```python @@ -2950,15 +2949,15 @@ def push_to_hub( model.push_to_hub("huggingface/my-finetuned-bert") ``` """ - if "repo_path_or_name" in model_card_kwargs: + if "repo_path_or_name" in base_model_card_args: warnings.warn( "The `repo_path_or_name` argument is deprecated and will be removed in v5 of Transformers. Use " "`repo_id` instead." ) - repo_id = model_card_kwargs.pop("repo_path_or_name") + repo_id = base_model_card_args.pop("repo_path_or_name") # Deprecation warning will be sent after for repo_url and organization - repo_url = model_card_kwargs.pop("repo_url", None) - organization = model_card_kwargs.pop("organization", None) + repo_url = base_model_card_args.pop("repo_url", None) + organization = base_model_card_args.pop("organization", None) if os.path.isdir(repo_id): working_dir = repo_id @@ -2984,7 +2983,7 @@ def push_to_hub( "output_dir": work_dir, "model_name": Path(repo_id).name, } - base_model_card_args.update(model_card_kwargs) + base_model_card_args.update(deprecated_kwargs) self.create_model_card(**base_model_card_args) self._upload_modified_files( diff --git a/tests/test_modeling_tf_common.py b/tests/test_modeling_tf_common.py index c435b3c5aa28..3a79820360cc 100644 --- a/tests/test_modeling_tf_common.py +++ b/tests/test_modeling_tf_common.py @@ -2492,7 +2492,9 @@ def test_push_to_hub_callback(self): self.assertTrue(models_equal) tf_push_to_hub_params = dict(inspect.signature(TFPreTrainedModel.push_to_hub).parameters) + tf_push_to_hub_params.pop("base_model_card_args") pt_push_to_hub_params = dict(inspect.signature(PreTrainedModel.push_to_hub).parameters) + pt_push_to_hub_params.pop("deprecated_kwargs") self.assertDictEaual(tf_push_to_hub_params, pt_push_to_hub_params) def test_push_to_hub_in_organization(self): From 708278799c10a58a1af164859aab5a72c13d08f7 Mon Sep 17 00:00:00 2001 From: Arthur Zucker Date: Mon, 6 Mar 2023 16:35:10 +0000 Subject: [PATCH 6/7] last nit fix typo --- src/transformers/modeling_tf_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/transformers/modeling_tf_utils.py b/src/transformers/modeling_tf_utils.py index 2a60c7514412..dcedd2946b85 100644 --- a/src/transformers/modeling_tf_utils.py +++ b/src/transformers/modeling_tf_utils.py @@ -2983,7 +2983,7 @@ def push_to_hub( "output_dir": work_dir, "model_name": Path(repo_id).name, } - base_model_card_args.update(deprecated_kwargs) + base_model_card_args.update(base_model_card_args) self.create_model_card(**base_model_card_args) self._upload_modified_files( From 9edea7a04d996879cb1169129adb89574f7b4c86 Mon Sep 17 00:00:00 2001 From: "arthur.zucker@gmail.com" Date: Tue, 7 Mar 2023 08:27:14 +0000 Subject: [PATCH 7/7] add `is_pt_tf_cross_test` marker for the tsts --- tests/test_modeling_tf_common.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_modeling_tf_common.py b/tests/test_modeling_tf_common.py index 3a79820360cc..42db9aea2698 100644 --- a/tests/test_modeling_tf_common.py +++ b/tests/test_modeling_tf_common.py @@ -2468,6 +2468,7 @@ def test_push_to_hub(self): break self.assertTrue(models_equal) + @is_pt_tf_cross_test def test_push_to_hub_callback(self): config = BertConfig( vocab_size=99, hidden_size=32, num_hidden_layers=5, num_attention_heads=4, intermediate_size=37