/usr/local/lib/python3.6/site-packages/transformers/utils/__pycache__
NameSizeModeActions
doc.cpython-36.pyc345520644editdlrm
dummy_detectron2_objects.cpython-36.pyc7650644editdlrm
dummy_flax_objects.cpython-36.pyc476390644editdlrm
dummy_pt_objects.cpython-36.pyc2099100644editdlrm
dummy_pytorch_quantization_and_torch_objects.cpython-36.pyc38530644editdlrm
dummy_scatter_objects.cpython-36.pyc20440644editdlrm
dummy_sentencepiece_and_speech_objects.cpython-36.pyc6410644editdlrm
dummy_sentencepiece_and_tokenizers_objects.cpython-36.pyc4580644editdlrm
dummy_sentencepiece_objects.cpython-36.pyc76300644editdlrm
dummy_speech_objects.cpython-36.pyc6130644editdlrm
dummy_tf_objects.cpython-36.pyc985960644editdlrm
dummy_timm_and_vision_objects.cpython-36.pyc16240644editdlrm
dummy_timm_objects.cpython-36.pyc16470644editdlrm
dummy_tokenizers_objects.cpython-36.pyc147460644editdlrm
dummy_vision_objects.cpython-36.pyc65940644editdlrm
fx.cpython-36.pyc179760644editdlrm
fx_transformations.cpython-36.pyc95630644editdlrm
generic.cpython-36.pyc104930644editdlrm
hp_naming.cpython-36.pyc37510644editdlrm
hub.cpython-36.pyc316490644editdlrm
import_utils.cpython-36.pyc227740644editdlrm
logging.cpython-36.pyc95570644editdlrm
model_parallel_utils.cpython-36.pyc19760644editdlrm
notebook.cpython-36.pyc121900644editdlrm
sentencepiece_model_pb2.cpython-36.pyc128230644editdlrm
versions.cpython-36.pyc30620644editdlrm
__init__.cpython-36.pyc46450644editdlrm
Edit: /usr/local/lib/python3.6/site-packages/transformers/utils/__pycache__/hub.cpython-36.pyc (31649B)
3 Eg @sBdZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl m Z ddlmZddlmZddlmZddlmZmZmZmZmZmZddlmZdd lmZdd lm Z m!Z!ddl"Z"dd l#m$Z$dd l%m&Z&m'Z'm(Z(m)Z)m*Z*dd l+m,Z,ddl-m.Z.ddl/m0Z0m1Z1ddl2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8e1j9e:Z;eje3krrdndZ?ddZ@ejAdejBjCejAdddZDejBjCeDdZEejBjFejAdejBjCejAdddZGejBjCeGdZHejBjIeEr6ejBjIeH r6deje3kZVeVrd+nd,ZWeWZXejd?d@ZcdAdBZddjeee]dfe]dCdDdEZeGdFdGdGe,ZfGdHdIdIe,ZgGdJdKdKe,ZhdLdMZidke]eeee]e]fdNdOdPZjdle]eee]dfeebe]dfee]dRdSdTZkdmee]ejlfe]eee]ejlfebebeee]e]feeebe]fee]ebdU dVdWZmdnee]ejlfe]ee]ee]eee]e]feeebe]fdXdYdZZndoee]ejlfee]eeebe]febee]d[d\d]Zod^d_ZpGd`dadaZqdpe]ee]ee]dbdcddZrdS)qz? Hub utilities: utilities related to download and cache models N)contextmanager)partial)sha256)Path)BinaryIODictListOptionalTupleUnion)urlparse)uuid4)ZipFile is_zipfile)FileLock)HfFolder Repository create_repolist_repo_fileswhoami) HTTPError)tqdm) __version__logging)ENV_VARS_TRUE_VALUES _tf_version_torch_versionis_tf_availableis_torch_availableis_training_run_on_sagemakerZTRANSFORMERS_OFFLINE0TFcCstS)N)_is_offline_moder#r#@/usr/local/lib/python3.6/site-packages/transformers/utils/hub.pyis_offline_mode;sr%Z TORCH_HOMEXDG_CACHE_HOMEz~/.cacheZtorchZ transformersZHF_HOMEZ huggingfacePYTORCH_PRETRAINED_BERT_CACHEPYTORCH_TRANSFORMERS_CACHETRANSFORMERS_CACHEaIn Transformers v4.0.0, the default path to cache downloaded models changed from '~/.cache/torch/transformers' to '~/.cache/huggingface/transformers'. Since you don't seem to have overridden and '~/.cache/torch/transformers' is a directory that exists, we're moving it to '~/.cache/huggingface/transformers' to avoid redownloading models you have already in the cache. You should only see this message once.HF_MODULES_CACHEmodulesZtransformers_modulesDISABLE_TELEMETRYz3https://s3.amazonaws.com/models.huggingface.co/bertzhttps://cdn.huggingface.coZHUGGINGFACE_CO_STAGINGNOz#https://moon-staging.huggingface.cozhttps://huggingface.coHUGGINGFACE_CO_RESOLVE_ENDPOINTzUsing the environment variable `HUGGINGFACE_CO_RESOLVE_ENDPOINT` is deprecated and will be removed in Transformers v5. Use `HF_ENDPOINT` instead.Z HF_ENDPOINTz)/{model_id}/resolve/{revision}/{filename}cCst|}|jdkS)Nhttphttps)r/r0)r scheme)url_or_filenameparsedr#r#r$ is_remote_urlrsr4)model_idfilename subfolderrevisionreturncCsz|dk r|d|}|r^|d kr*tdd|k}|rJ|d|d|S|d|d|S|dkrjd}tj|||dS) a# Resolve a model identifier, a file name, and an optional revision id, to a huggingface.co-hosted url, redirecting to Cloudfront (a Content Delivery Network, or CDN) for large files. Cloudfront is replicated over the globe so downloads are way faster for the end user (and it also lowers our bandwidth costs). Cloudfront aggressively caches files by default (default TTL is 24 hours), however this is not an issue here because we migrated to a git-based versioning system on huggingface.co, so we now store the files on S3/Cloudfront in a content-addressable way (i.e., the file name is its hash). Using content-addressable filenames means cache can't ever be stale. In terms of client-side caching from this library, we base our caching on the objects' ETag. An object' ETag is: its sha1 if stored in git, or its sha256 if stored in git-lfs. Files cached locally from transformers before v3.5.0 are not shared with those new files, because the cached file's name contains a hash of the url (which changed). N/tunabfsuzTThe Tuna and BFSU mirrors are no longer available. Try removing the mirror argument.-main)r5r8r6)r;r<) ValueErrorHUGGINGFACE_CO_PREFIXformat)r5r6r7r8mirrorZ legacy_formatr#r#r$ hf_bucket_urlwsrC)urletagr9cCsN|jd}t|j}|r8|jd}|dt|j7}|jdrJ|d7}|S)a Convert `url` into a hashed filename in a repeatable way. If `etag` is specified, append its hash to the url's, delimited by a period. If the url ends with .h5 (Keras HDF5 weights) adds '.h5' to the name so that TF 2.0 can identify it as a HDF5 file (see https://github.com/tensorflow/tensorflow/blob/00fad90125b18b80fe054de1055770cfb8fe4ba3/tensorflow/python/keras/engine/network.py#L1380) zutf-8.z.h5)encoder hexdigestendswith)rDrEZ url_bytesr6Z etag_bytesr#r#r$url_to_filenames    rJc Cs|dkr t}t|trt|}tjj||}tjj|sHtd|d|d}tjj|sltd|dt |dd}t j |}WdQRX|d}|d}||fS) z Return the url and etag (which may be `None`) stored for *filename*. Raise `EnvironmentError` if *filename* or its stored metadata do not exist. Nzfile z not foundz.jsonzutf-8)encodingrDrE) r) isinstancerstrospathjoinexistsEnvironmentErroropenjsonload)r6 cache_dir cache_path meta_path meta_filemetadatarDrEr#r#r$filename_to_urls   r[)rVr9c Cs|dkrt}nt|tr t|}g}xtj|D]~}|jdr0tjj||}t |ddP}t j |}|d}|d}|jdrtjj |j dd}|j|||fWdQRXq0W|S) a  Returns a list of tuples representing model binaries that are cached locally. Each tuple has shape `(model_url, etag, size_MB)`. Filenames in `cache_dir` are use to get the metadata for each model, only urls ending with *.bin* are added. Args: cache_dir (`Union[str, Path]`, *optional*): The cache directory to search for models within. Will default to the transformers cache if unset. Returns: List[Tuple]: List of tuples each with shape `(model_url, etag, size_MB)` Nz.jsonzutf-8)rKrDrEz.bing.A)r)rLrrMrNlistdirrIrOrPrSrTrUgetsizestripappend) rVZ cached_modelsfilerXrYrZrDrEZsize_MBr#r#r$get_cached_modelss     ra) user_agentuse_auth_tokenr9c Cs|dkr t}t|trt|}t|tr0t|}trJ| rJtjdd} t|rlt|||||||| d} nBt j j |r~|} n0t |j dkrtd|dntd|d |rt|  rtj|  r| St j j| \} } | jd d d } t j j| | }t j j|r"t j|r"| r"|S| d }t|tj|ddt j|t| rt| d}|j||jWdQRXn:tj| rtj| }|j||jntd| dWdQRX|S| S)aj Given something that might be a URL (or might be a local path), determine which. If it's a URL, download the file and cache it, and return the path to the cached file. If it's already a local path, make sure the file exists and then return the path Args: cache_dir: specify a cache directory to save the file to (overwrite the default cache dir). force_download: if True, re-download the file even if it's already cached in the cache dir. resume_download: if True, resume the download if incompletely received file is found. user_agent: Optional string or dict that will be appended to the user-agent on remote requests. use_auth_token: Optional string or boolean to use as Bearer token for remote files. If True, will get token from ~/.huggingface. extract_compressed_file: if True and the path point to a zip or tar file, extract the compressed file in a folder along the archive. force_extract: if True when extract_compressed_file is True and the archive was already extracted, re-extract the archive and override the folder where it was extracted. Return: Local path (string) of file or if networking is off, last version of file cached on disk. Raises: In case of non-recoverable file (non-existent or inaccessible url + no cache on disk). Nz+Offline mode: forcing local_files_only=TrueT)rVforce_downloadproxiesresume_downloadrbrclocal_files_onlyzfile z not foundzunable to parse z as a URL or as a local pathrFr=z -extractedz.lock) ignore_errorsrzArchive format of z could not be identified) r)rLrrMr%loggerinfor4get_from_cacherNrOrQr r1rRr?rtarfile is_tarfilesplitreplacerPisdirr\rshutilrmtreemakedirsr extractallcloserS)r2rVrdrerfrbZextract_compressed_fileZ force_extractrcrgZ output_path output_dirZ output_fileZoutput_extract_dir_nameZoutput_path_extracted lock_pathzip_fileZtar_filer#r#r$ cached_paths^#      "         r{cCsy2tjtjdj}|d}|djdd}Wntk rNd}d}YnXtjtjdd}d|krndnd }d tjkrtjd jdd nd}tjd dtjd dtjddtjdd||||d}|S)NZECS_CONTAINER_METADATA_URIZImage:rZSM_FRAMEWORK_PARAMSz{}Z*sagemaker_distributed_dataparallel_enabledTFZTRAINING_JOB_ARNZSM_FRAMEWORK_MODULEZ AWS_REGIONZ SM_NUM_GPUSrZ SM_NUM_CPUS)Z sm_frameworkZ sm_regionZ sm_number_gpuZ sm_number_cpuZsm_distributed_trainingZsm_deep_learning_containerZsm_deep_learning_container_tagZ sm_account_id) requestsgetrNenvironrTrp Exceptionloadsgetenv)Z instance_dataZdlc_container_usedZdlc_tagZsagemaker_paramsZruns_distributed_trainingZ account_idZsagemaker_objectr#r#r$define_sagemaker_informationPs& "    r)rbr9cCsdtdtjjddt}tr4|dt7}trH|dt7}t rT|dSt r||ddj d d t j D7}tjjd d jtkr|d 7}t|tr|ddj dd |j D7}nt|tr|d|7}|S)zF Formats a user-agent string with basic info about a request. z transformers/z ; python/rz ; session_id/z; torch/z ; tensorflow/z; telemetry/offz; css |]\}}|d|VqdS)r:Nr#).0kvr#r#r$ vsz"http_user_agent..ZTRANSFORMERS_IS_CIrhz ; is_ci/truecss |]\}}|d|VqdS)r:Nr#)rrrr#r#r$r{s)rsysversionrp SESSION_IDrrrrr,r rPritemsrNrrupperrrLdictrM)rbZuar#r#r$http_user_agentjs  " "  rc@seZdZdZdS)RepositoryNotFoundErrorz Raised when trying to access a hf.co URL with an invalid repository name, or with a private repo name the user does not have access to. N)__name__ __module__ __qualname____doc__r#r#r#r$rsrc@seZdZdZdS)EntryNotFoundErrorzfRaised when trying to access a hf.co URL with a valid repository and revision but an invalid filename.N)rrrrr#r#r#r$rsrc@seZdZdZdS)RevisionNotFoundErrorzYRaised when trying to access a hf.co URL with a valid repository but an invalid revision.N)rrrrr#r#r#r$rsrcCsld|jkr`|jd}|dkr.td|jn2|dkrHtd|jn|dkr`td|j|jdS) zb Internal version of `request.raise_for_status()` that will refine a potential HTTPError. z X-Error-CodeZ RepoNotFoundz0404 Client Error: Repository Not Found for url: Z EntryNotFoundz+404 Client Error: Entry Not Found for url: ZRevisionNotFoundz.404 Client Error: Revision Not Found for url: N)headersrrDrrraise_for_status)requestZ error_coder#r#r$_raise_for_statuss  r)rD temp_filerc Cstj|}|dkr"d|d|d<tj|d||d}t||jjd}|dk r\|t|nd}td dd ||d d }x0|jd d D] } | r|j t | |j | qW|j dS)z8 Download remote file. Do not gobble up errors. rzbytes=r=RangeT)streamrerzContent-LengthNBiZ Downloading)unitZ unit_scaleZ unit_divisortotalinitialdesc) chunk_size) copydeepcopyr~rrrintr iter_contentupdatelenwriterw) rDrre resume_sizerrjcontent_lengthrprogresschunkr#r#r$http_gets&  r )rDrbrcr9c  sX|dkr t}t|trt|}tj|dddt|i} t|trRd|| d<n*|r|tj} | dkrnt dd| | d<|} d} |sDylt j || d||d } t | | j jd p| j jd } | dkrtd d | jkodknr| j d} WnLt jjt jjtttfk r Yn$tt jjt jjfk rBYnXt|| }tjj||}| dkrtjj|rx|Sddtjtj ||j!dddD}t"|dkrtjj||d)S|rt#dnt$dtjj|r| r|S|d}t%|Htjj|r"| r"|S|rl|dt&ddfdd }|}tjjrftj'j(}nd}nt)t*j+d|dd}d}|.}t,j-|d |j.t/| |||| d!WdQRXt,j-d"|d#|tj0|j.|tj1d$}tj1|tj2|d$|@t,j-d%||| d&}|d'}t3|d(}t4j5||WdQRXWdQRX|S)*ar Given a URL, look for the corresponding file in the local cache. If it's not there, download it. Then return the path to the cached file. Return: Local path (string) of file or if networking is off, last version of file cached on disk. Raises: In case of non-recoverable file (non-existent or inaccessible url + no cache on disk). NT)exist_okz user-agentzBearer authorizationzIYou specified use_auth_token=True, but a huggingface token was not found.F)rallow_redirectsretimeoutz X-Linked-EtagETagz\Distant resource does not have an ETag, we won't be able to reliably ensure reproducibility.i,iZLocationcSs(g|] }|jd r|jd r|qS)z.jsonz.lock)rI)rr`r#r#r$ sz"get_from_cache..rFrz.*rzCannot find the requested files in the cached path and outgoing traffic has been disabled. To enable model look-ups and downloads online, set 'local_files_only' to False.zConnection error, and we cannot find the requested files in the cached path. Please try again or make sure your Internet connection is on.z.lockz .incompletezio.BufferedWriter)r9c 3s td }|VWdQRXdS)Nab)rS)f)incomplete_pathr#r$_resumable_file_manager6s z/get_from_cache.._resumable_file_managerwb)modedirdeletezB not found in cache or force_download set to True, downloading to )rerrzstoring z in cache at izcreating metadata file for )rDrEz.jsonw)6r)rLrrMrNrurr get_tokenrRr~headrrrOSError status_code exceptionsSSLError ProxyErrorrrrrConnectionErrorTimeoutrJrOrPrQfnmatchfilterr\rprFileNotFoundErrorr?rrstatst_sizertempfileNamedTemporaryFilerkrlnamerrqumaskchmodrSrTdump)rDrVrdreZ etag_timeoutrfrbrcrgrtokenZurl_to_downloadrErjr6rWZmatching_filesryrZtemp_file_managerrrrmetarXrYr#)rr$rms     $      rm) path_or_repor6rVrdrfrercr8rgc Cstr| rtjdd}t|}tjj|rPtjj||} tjj| rL| SdSt |||dd} yt | ||||||d} WnZt k rt |dYn:t k rt |d|dYnt k rdSX| S) a@ Tries to locate a file in a local folder and repo, downloads and cache it if necessary. Args: path_or_repo (`str` or `os.PathLike`): This can be either: - a string, the *model id* of a model repo on huggingface.co. - a path to a *directory* potentially containing the file. filename (`str`): The name of the file to locate in `path_or_repo`. cache_dir (`str` or `os.PathLike`, *optional*): Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used. force_download (`bool`, *optional*, defaults to `False`): Whether or not to force to (re-)download the configuration files and override the cached versions if they exist. resume_download (`bool`, *optional*, defaults to `False`): Whether or not to delete incompletely received file. Attempts to resume the download if such a file exists. proxies (`Dict[str, str]`, *optional*): A dictionary of proxy servers to use by protocol or endpoint, e.g., `{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}.` The proxies are used on each request. use_auth_token (`str` or *bool*, *optional*): The token to use as HTTP bearer authorization for remote files. If `True`, will use the token generated when running `transformers-cli login` (stored in `~/.huggingface`). revision (`str`, *optional*, defaults to `"main"`): The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a git-based system for storing models and other artifacts on huggingface.co, so `revision` can be any identifier allowed by git. local_files_only (`bool`, *optional*, defaults to `False`): If `True`, will only try to load the tokenizer configuration from local files. Passing `use_auth_token=True` is required when you want to use a private model. Returns: `Optional[str]`: Returns the resolved file (to the cache folder if downloaded from a repo) or `None` if the file does not exist. Examples: ```python # Download a tokenizer configuration from huggingface.co and cache. tokenizer_config = get_file_from_repo("bert-base-uncased", "tokenizer_config.json") # This model does not have a tokenizer config so the result will be None. tokenizer_config = get_file_from_repo("xlm-roberta-base", "tokenizer_config.json") ```z+Offline mode: forcing local_files_only=TrueTN)r6r8rB)rVrdrerfrgrca is not a local folder and is not a valid model identifier listed on 'https://huggingface.co/models' If this is a private repository, make sure to pass a token having permission to this repo with `use_auth_token` or log in with `huggingface-cli login` and pass `use_auth_token=True`.z is not a valid git identifier (branch name, tag name or commit id) that exists for this model name. Check the model page at 'https://huggingface.co/z' for available revisions.)r%rkrlrMrNrOrrrPisfilerCr{rrRr) rr6rVrdrfrercr8rgZ resolved_filer#r#r$get_file_from_repo\s4=    r)rr6r8rBrercc Cs0tjj|r"tjjtjj||St||||d}dti}t|trVd||d<n*|rt j }|dkrrt dd||d<t j ||d|dd } y t| d Stk r} ztj| t |d WYdd} ~ XnRtk r} ztj| t |d WYdd} ~ Xnt jk r*dSXdS) aV Checks if a repo contains a given file wihtout downloading it. Works for remote repos and local folders. This function will raise an error if the repository `path_or_repo` is not valid or if `revision` does not exist for this repo, but will return False for regular connection errors. )r6r8rBz user-agentzBearer rNzIYou specified use_auth_token=True, but a huggingface token was not found.Fr)rrrerTzE is not a local folder or a valid repository name on 'https://hf.co'.z is not a valid git identifier (branch name, tag name or commit id) that exists for this model name. Check the model page at 'https://huggingface.co/{path_or_repo}' for available revisions.)rNrOrrrrPrCrrLrMrrrRr~rrrrkerrorrr) rr6r8rBrercrDrrrjer#r#r$has_files0     r)rr8rcrgr9c st|}tjj|rNg}x0tj|D]"\}}|jfdd|Dq$W|StsX|r\gSt|trl|}n|dkr~tj }nd}yt |||dSt k r}zt |d|WYdd}~XnXdS)a| Gets the list of files inside `path_or_repo`. Args: path_or_repo (`str` or `os.PathLike`): Can be either the id of a repo on huggingface.co or a path to a *directory*. revision (`str`, *optional*, defaults to `"main"`): The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a git-based system for storing models and other artifacts on huggingface.co, so `revision` can be any identifier allowed by git. use_auth_token (`str` or *bool*, *optional*): The token to use as HTTP bearer authorization for remote files. If `True`, will use the token generated when running `transformers-cli login` (stored in `~/.huggingface`). local_files_only (`bool`, *optional*, defaults to `False`): Whether or not to only rely on local files and not to attempt to download any files. This API is not optimized, so calling it a lot may result in connection errors. Returns: `List[str]`: The list of files available in `path_or_repo`. csg|]}tjj|qSr#)rNrOrP)rr)rOr#r$rsz%get_list_of_files..TN)r8rzQ is not a local path or a model identifier on the model Hub. Did you make a typo?) rMrNrOrrwalkextendr%rLrrrrr?) rr8rcrgZ list_of_filesZ dir_namesZ file_namesrrr#)rOr$get_list_of_filess&     rcCsftjjtjj|dsdStjdj|d}|jdkr:dStjdjtjtjdd|d j }||jkS) zM Checks if the folder in `repo_path` is a local clone of `repo_url`. z.gitFz git branch)cwdrz git remote -vTzutf-8)stderrstdoutcheckrKr) rNrOrQrP subprocessrunrp returncodePIPEr) repo_pathrepo_urlZtest_gitremotesr#r#r$is_local_clone1s  rc @seZdZdZdeeeeeeeeeeeeeeefedddZe deeeeeeeefeddd Z e deeeeeeeeeeefe d d d Z e de eeed ddZdS)PushToHubMixinzW A Mixin containing the functionality to push a model or tokenizer to the hub. NF)repo_path_or_namer use_temp_dircommit_message organizationprivatercr9c Ks|r<|dkr4|dkrd}t|j} |j| |||d}tj}|j|||||d} |j|t|drt|dr|t|jd} | j||j f| |j | |d} |rt j || S) u Upload the {object_files} to the 🤗 Model Hub while synchronizing a local clone of the repo in `repo_path_or_name`. Parameters: repo_path_or_name (`str`, *optional*): Can either be a repository name for your {object} in the Hub or a path to a local folder (in which case the repository will have the name of that local folder). If not specified, will default to the name given by `repo_url` and a local directory with that name will be created. repo_url (`str`, *optional*): Specify this in case you want to push to an existing repository in the hub. If unspecified, a new repository will be created in your namespace (unless you specify an `organization`) with `repo_name`. use_temp_dir (`bool`, *optional*, defaults to `False`): Whether or not to clone the distant repo in a temporary directory or in `repo_path_or_name` inside the current working directory. This will slow things down if you are making changes in an existing repo since you will need to clone the repo before every push. commit_message (`str`, *optional*): Message to commit while pushing. Will default to `"add {object}"`. organization (`str`, *optional*): Organization in which you want to push your {object} (you must be a member of this organization). private (`bool`, *optional*): Whether or not the repository created should be private (requires a paying subscription). use_auth_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 `transformers-cli login` (stored in `~/.huggingface`). Will default to `True` if `repo_url` is not specified. Returns: `str`: The url of the commit of your {object} in the given repository. 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" and have a local clone in the # *my-finetuned-bert* folder. {object}.push_to_hub("my-finetuned-bert") # Push the {object} to your namespace with the name "my-finetuned-bert" with no local clone. {object}.push_to_hub("my-finetuned-bert", use_temp_dir=True) # Push the {object} to an organization with the name "my-finetuned-bert" and have a local clone in the # *my-finetuned-bert* folder. {object}.push_to_hub("my-finetuned-bert", organization="huggingface") # Make a change to an existing repo that has been cloned locally in *my-finetuned-bert*. {object}.push_to_hub("my-finetuned-bert", repo_url="https://huggingface.co/sgugger/my-finetuned-bert") ``` NT)rrrc)rrrrrchistorycreate_model_card)rxZ model_name)r) rr_get_repo_url_from_namermkdtemp_create_or_get_repoZsave_pretrainedhasattrrr _push_to_hubrsrt) selfrrrrrrrcZmodel_card_kwargs repo_namerepoZbase_model_card_argsrDr#r#r$ push_to_hubNs0@     zPushToHubMixin.push_to_hub)rrrrcr9cCsFt|tr|}n"|r.tj}|dkr2tdnd}t||||dddS)NzYou must login to the Hugging Face hub on this computer by typing `transformers-cli login` and entering your credentials to use `use_auth_token=True`. Alternatively, you can pass your own token as the `use_auth_token` argument.T)rrZ repo_typer)rLrMrrr?r)rrrrcrr#r#r$rs z&PushToHubMixin._get_repo_url_from_name)rrrrrcr9cCs|dkr|dkrtd|dkr,|dkr,d}|dkrB|jdd}|dkrttjj| rtt|j}|j||||d}tjj|stj|t |||d}|j |S)Nz:You need to specify a `repo_path_or_name` or a `repo_url`.Tr:r)rrrc)Z clone_fromrcr) r?rprNrOrQrrrrurZgit_pull)clsrrrrrcrrr#r#r$rs    z"PushToHubMixin._create_or_get_repo)rrr9cCs8|dkr,d|jkrd}nd|jkr(d}nd}|j|dS)N Tokenizerz add tokenizerZConfigz add configz add model)r)rr)rrrr#r#r$rs  zPushToHubMixin._push_to_hub)NNFNNNN)NNN)NNNNN)N)rrrrr rMboolr r staticmethodr classmethodrrrr#r#r#r$rIs.0\$r)r5rrcCsD|dkrtj}|dkr2t|d}|d|S|d|SdS)Nrr:)rrr)r5rrusernamer#r#r$get_full_repo_names  r)NNN)N)N)N) NFNFNFFNF)N)NrN)NFNrFNNF)NFFNNNF)NNNN)NNF)NN)srrriorTrNrsrrrnrwarnings contextlibr functoolsrhashlibrpathlibrtypingrrrr r r urllib.parser uuidr zipfilerrr~ZfilelockrZhuggingface_hubrrrrrZrequests.exceptionsrZtransformers.utils.loggingrrhrrZ import_utilsrrrrrr get_loggerrrkrrrr"r%rrOrPZtorch_cache_homeZold_default_cache_path expanduserZ hf_cache_homeZdefault_cache_pathrrwarningmover'r(r)r*Z TRANSFORMERS_DYNAMIC_MODULE_NAMEhexrr,ZS3_BUCKET_PREFIXZCLOUDFRONT_DISTRIB_PREFIXZ _staging_modeZ_default_endpointr.warn FutureWarningr@r4rMrCrJr[rarr{rrrrrrrrmPathLikerrrrrrr#r#r#r$s                    " #[ TbD.$67