"...git@developer.sourcefind.cn:chenpangpang/transformers.git" did not exist on "a492aec82dd11887125c6086d3e1582cb472022e"
Unverified Commit 58c36bea authored by Joe Mifsud's avatar Joe Mifsud Committed by GitHub
Browse files

Support specifying revision in push_to_hub (#25578)

Support revision in push_to_hub
parent 450a181d
...@@ -32,6 +32,7 @@ import huggingface_hub ...@@ -32,6 +32,7 @@ import huggingface_hub
import requests import requests
from huggingface_hub import ( from huggingface_hub import (
CommitOperationAdd, CommitOperationAdd,
create_branch,
create_commit, create_commit,
create_repo, create_repo,
get_hf_file_metadata, get_hf_file_metadata,
...@@ -722,6 +723,7 @@ class PushToHubMixin: ...@@ -722,6 +723,7 @@ class PushToHubMixin:
commit_message: Optional[str] = None, commit_message: Optional[str] = None,
token: Optional[Union[bool, str]] = None, token: Optional[Union[bool, str]] = None,
create_pr: bool = False, create_pr: bool = False,
revision: str = None,
): ):
""" """
Uploads all modified files in `working_dir` to `repo_id`, based on `files_timestamps`. Uploads all modified files in `working_dir` to `repo_id`, based on `files_timestamps`.
...@@ -768,9 +770,17 @@ class PushToHubMixin: ...@@ -768,9 +770,17 @@ class PushToHubMixin:
CommitOperationAdd(path_or_fileobj=os.path.join(working_dir, file), path_in_repo=file) CommitOperationAdd(path_or_fileobj=os.path.join(working_dir, file), path_in_repo=file)
) )
if revision is not None:
create_branch(repo_id=repo_id, branch=revision, token=token, exist_ok=True)
logger.info(f"Uploading the following files to {repo_id}: {','.join(modified_files)}") logger.info(f"Uploading the following files to {repo_id}: {','.join(modified_files)}")
return create_commit( return create_commit(
repo_id=repo_id, operations=operations, commit_message=commit_message, token=token, create_pr=create_pr repo_id=repo_id,
operations=operations,
commit_message=commit_message,
token=token,
create_pr=create_pr,
revision=revision,
) )
def push_to_hub( def push_to_hub(
...@@ -783,6 +793,7 @@ class PushToHubMixin: ...@@ -783,6 +793,7 @@ class PushToHubMixin:
max_shard_size: Optional[Union[int, str]] = "10GB", max_shard_size: Optional[Union[int, str]] = "10GB",
create_pr: bool = False, create_pr: bool = False,
safe_serialization: bool = False, safe_serialization: bool = False,
revision: str = None,
**deprecated_kwargs, **deprecated_kwargs,
) -> str: ) -> str:
""" """
...@@ -811,6 +822,8 @@ class PushToHubMixin: ...@@ -811,6 +822,8 @@ class PushToHubMixin:
Whether or not to create a PR with the uploaded files or directly commit. Whether or not to create a PR with the uploaded files or directly commit.
safe_serialization (`bool`, *optional*, defaults to `False`): safe_serialization (`bool`, *optional*, defaults to `False`):
Whether or not to convert the model weights in safetensors format for safer serialization. Whether or not to convert the model weights in safetensors format for safer serialization.
revision (`str`, *optional*):
Branch to push the uploaded files to.
Examples: Examples:
...@@ -886,6 +899,7 @@ class PushToHubMixin: ...@@ -886,6 +899,7 @@ class PushToHubMixin:
commit_message=commit_message, commit_message=commit_message,
token=token, token=token,
create_pr=create_pr, create_pr=create_pr,
revision=revision,
) )
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment