class_docstr: A Mixin containing the functionality to push a model or tokenizer to the hub.
docstr: Upload the {object_files} to the 🤗 Model Hub.
  
  Parameters:
      repo_id (`str`):
          The name of the repository you want to push your {object} to. It should contain your organization name
          when pushing to a given organization.
      use_temp_dir (`bool`, *optional*):
          Whether or not to use a temporary directory to store the files saved before they are pushed to the Hub.
          Will default to `True` if there is no directory named like `repo_id`, `False` otherwise.
      commit_message (`str`, *optional*):
          Message to commit while pushing. Will default to `"Upload {object}"`.
      private (`bool`, *optional*):
          Whether or not the repository created should be private.
      token (`bool` or `str`, *optional*):
          The token to use as HTTP bearer authorization for remote files. If `True`, will use the token generated
          when running `huggingface-cli login` (stored in `~/.huggingface`). Will default to `True` if `repo_url`
          is not specified.
      max_shard_size (`int` or `str`, *optional*, defaults to `"5GB"`):
          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"`). We default it to `"5GB"` so that users can easily load models on free-tier
          Google Colab instances without any CPU OOM issues.
      create_pr (`bool`, *optional*, defaults to `False`):
          Whether or not to create a PR with the uploaded files or directly commit.
      safe_serialization (`bool`, *optional*, defaults to `True`):
          Whether or not to convert the model weights in safetensors format for safer serialization.
      revision (`str`, *optional*):
          Branch to push the uploaded files to.
      commit_description (`str`, *optional*):
          The description of the commit that will be created
      tags (`List[str]`, *optional*):
          List of tags to push on the Hub.
  
  Examples:
  
  ```python
  from transformers import {object_class}
  
  {object} = {object_class}.from_pretrained("bert-base-cased")
  
  # Push the {object} to your namespace with the name "my-finetuned-bert".
  {object}.push_to_hub("my-finetuned-bert")
  
  # Push the {object} to an organization with the name "my-finetuned-bert".
  {object}.push_to_hub("huggingface/my-finetuned-bert")
  ```
docstr_tok: ["Upload","the","{","object_files","}","to","the","\ud83e\udd17","Model","Hub",".","Parameters",":","repo_id","(","`","str","`",")",":","The","name","of","the","repository","you","want","to","push","your","{","object","}","to",".","It","should","contain","your","organization","name","when","pushing","to","a","given","organization",".","use_temp_dir","(","`","bool","`",",","*","optional","*",")",":","Whether","or","not","to","use","a","temporary","directory","to","store","the","files","saved","before","they","are","pushed","to","the","Hub",".","Will","default","to","`","True","`","if","there","is","no","directory","named","like","`","repo_id","`",",","`","False","`","otherwise",".","commit_message","(","`","str","`",",","*","optional","*",")",":","Message","to","commit","while","pushing",".","Will","default","to","`","``","Upload","{","object","}","''","`",".","private","(","`","bool","`",",","*","optional","*",")",":","Whether","or","not","the","repository","created","should","be","private",".","token","(","`","bool","`","or","`","str","`",",","*","optional","*",")",":","The","token","to","use","as","HTTP","bearer","authorization","for","remote","files",".","If","`","True","`",",","will","use","the","token","generated","when","running","`","huggingface-cli","login","`","(","stored","in","`","~\/.huggingface","`",")",".","Will","default","to","`","True","`","if","`","repo_url","`","is","not","specified",".","max_shard_size","(","`","int","`","or","`","str","`",",","*","optional","*",",","defaults","to","`","``","5GB","''","`",")",":","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","''","`",")",".","We","default","it","to","`","``","5GB","''","`","so","that","users","can","easily","load","models","on","free-tier","Google","Colab","instances","without","any","CPU","OOM","issues",".","create_pr","(","`","bool","`",",","*","optional","*",",","defaults","to","`","False","`",")",":","Whether","or","not","to","create","a","PR","with","the","uploaded","files","or","directly","commit",".","safe_serialization","(","`","bool","`",",","*","optional","*",",","defaults","to","`","True","`",")",":","Whether","or","not","to","convert","the","model","weights","in","safetensors","format","for","safer","serialization",".","revision","(","`","str","`",",","*","optional","*",")",":","Branch","to","push","the","uploaded","files","to",".","commit_description","(","`","str","`",",","*","optional","*",")",":","The","description","of","the","commit","that","will","be","created","tags","(","`","List","[","str","]","`",",","*","optional","*",")",":","List","of","tags","to","push","on","the","Hub",".","Examples",":","``","`","python","from","transformers","import","{","object_class","}","{","object","}","=","{","object_class","}",".from_pretrained","(","``","bert-base-cased","''",")","#","Push","the","{","object","}","to","your","namespace","with","the","name","``","my-finetuned-bert","''",".","{","object","}",".push_to_hub","(","``","my-finetuned-bert","''",")","#","Push","the","{","object","}","to","an","organization","with","the","name","``","my-finetuned-bert","''",".","{","object","}",".push_to_hub","(","``","huggingface\/my-finetuned-bert","''",")","``","`"]
code: def push_to_hub(
      self,
      repo_id: str,
      use_temp_dir: Optional[bool] = None,
      commit_message: Optional[str] = None,
      private: Optional[bool] = None,
      token: Optional[Union[bool, str]] = None,
      max_shard_size: Optional[Union[int, str]] = "5GB",
      create_pr: bool = False,
      safe_serialization: bool = True,
      revision: str = None,
      commit_description: str = None,
      tags: Optional[List[str]] = None,
      **deprecated_kwargs,
  ) -> str:
      """
      Upload the {object_files} to the 🤗 Model Hub.
  
      Parameters:
          repo_id (`str`):
              The name of the repository you want to push your {object} to. It should contain your organization name
              when pushing to a given organization.
          use_temp_dir (`bool`, *optional*):
              Whether or not to use a temporary directory to store the files saved before they are pushed to the Hub.
              Will default to `True` if there is no directory named like `repo_id`, `False` otherwise.
          commit_message (`str`, *optional*):
              Message to commit while pushing. Will default to `"Upload {object}"`.
          private (`bool`, *optional*):
              Whether or not the repository created should be private.
          token (`bool` or `str`, *optional*):
              The token to use as HTTP bearer authorization for remote files. If `True`, will use the token generated
              when running `huggingface-cli login` (stored in `~/.huggingface`). Will default to `True` if `repo_url`
              is not specified.
          max_shard_size (`int` or `str`, *optional*, defaults to `"5GB"`):
              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"`). We default it to `"5GB"` so that users can easily load models on free-tier
              Google Colab instances without any CPU OOM issues.
          create_pr (`bool`, *optional*, defaults to `False`):
              Whether or not to create a PR with the uploaded files or directly commit.
          safe_serialization (`bool`, *optional*, defaults to `True`):
              Whether or not to convert the model weights in safetensors format for safer serialization.
          revision (`str`, *optional*):
              Branch to push the uploaded files to.
          commit_description (`str`, *optional*):
              The description of the commit that will be created
          tags (`List[str]`, *optional*):
              List of tags to push on the Hub.
  
      Examples:
  
      ```python
      from transformers import {object_class}
  
      {object} = {object_class}.from_pretrained("bert-base-cased")
  
      # Push the {object} to your namespace with the name "my-finetuned-bert".
      {object}.push_to_hub("my-finetuned-bert")
  
      # Push the {object} to an organization with the name "my-finetuned-bert".
      {object}.push_to_hub("huggingface/my-finetuned-bert")
      ```
      """
      use_auth_token = deprecated_kwargs.pop("use_auth_token", None)
      ignore_metadata_errors = deprecated_kwargs.pop(
          "ignore_metadata_errors", False
      )
      if use_auth_token is not None:
          warnings.warn(
              "The `use_auth_token` argument is deprecated and will be removed in v5 of Transformers. Please use `token` instead.",
              FutureWarning,
          )
          if token is not None:
              raise ValueError(
                  "`token` and `use_auth_token` are both specified. Please set only the argument `token`."
              )
          token = use_auth_token
  
      repo_path_or_name = deprecated_kwargs.pop(
          "repo_path_or_name", None
      )
      if repo_path_or_name is not None:
          # Should use `repo_id` instead of `repo_path_or_name`. When using `repo_path_or_name`, we try to infer
          # repo_id from the folder path, if it exists.
          warnings.warn(
              "The `repo_path_or_name` argument is deprecated and will be removed in v5 of Transformers. Use "
              "`repo_id` instead.",
              FutureWarning,
          )
          if repo_id is not None:
              raise ValueError(
                  "`repo_id` and `repo_path_or_name` are both specified. Please set only the argument `repo_id`."
              )
          if os.path.isdir(repo_path_or_name):
              # repo_path: infer repo_id from the path
              repo_id = repo_id.split(os.path.sep)[-1]
              working_dir = repo_id
          else:
              # repo_name: use it as repo_id
              repo_id = repo_path_or_name
              working_dir = repo_id.split("/")[-1]
      else:
          # Repo_id is passed correctly: infer working_dir from it
          working_dir = repo_id.split("/")[-1]
  
      # Deprecation warning will be sent after for repo_url and organization
      repo_url = deprecated_kwargs.pop("repo_url", None)
      organization = deprecated_kwargs.pop("organization", None)
  
      repo_id = self._create_repo(
          repo_id,
          private=private,
          token=token,
          repo_url=repo_url,
          organization=organization,
      )
  
      # Create a new empty model card and eventually tag it
      model_card = create_and_tag_model_card(
          repo_id,
          tags,
          token=token,
          ignore_metadata_errors=ignore_metadata_errors,
      )
  
      if use_temp_dir is None:
          use_temp_dir = not os.path.isdir(working_dir)
  
      with working_or_temp_dir(
          working_dir=working_dir, use_temp_dir=use_temp_dir
      ) as work_dir:
          files_timestamps = self._get_files_timestamps(work_dir)
  
          # Save all files.
          self.save_pretrained(
              work_dir,
              max_shard_size=max_shard_size,
              safe_serialization=safe_serialization,
          )
  
          # Update model card if needed:
          model_card.save(os.path.join(work_dir, "README.md"))
  
          return self._upload_modified_files(
              work_dir,
              repo_id,
              files_timestamps,
              commit_message=commit_message,
              token=token,
              create_pr=create_pr,
              revision=revision,
              commit_description=commit_description,
          )
  
imports: import json
  import os
  import re
  import shutil
  import sys
  import tempfile
  import traceback
  import warnings
  from concurrent import futures
  from pathlib import Path
  from typing import Dict, List, Optional, Tuple, Union
  from urllib.parse import urlparse
  from uuid import uuid4
  import huggingface_hub
  import requests
  from huggingface_hub import _CACHED_NO_EXIST, CommitOperationAdd, ModelCard, ModelCardData, constants, create_branch, create_commit, create_repo, get_hf_file_metadata, hf_hub_download, hf_hub_url, try_to_load_from_cache
  from huggingface_hub.file_download import REGEX_COMMIT_HASH, http_get
  from huggingface_hub.utils import EntryNotFoundError, GatedRepoError, HFValidationError, LocalEntryNotFoundError, RepositoryNotFoundError, RevisionNotFoundError, build_hf_headers, hf_raise_for_status, send_telemetry
  from huggingface_hub.utils._deprecation import _deprecate_method
  from requests.exceptions import HTTPError
  from .None import __version__, logging
  from .generic import working_or_temp_dir
  from .import_utils import ENV_VARS_TRUE_VALUES, _tf_version, _torch_version, is_tf_available, is_torch_available, is_training_run_on_sagemaker
  from .logging import tqdm
label_desc: Use image node_id 4 for calling the PushToHubMixin obj's underlying member method code with example usage: obj.push_to_hub(repo_id, use_temp_dir, commit_message, private, token, max_shard_size, create_pr, safe_serialization, revision, commit_description, tags) and returns: self