
    fTh^              $       v   S r SSKrSSKrSSKrSSKrSSKrSSKrSSKJr  SSK	J
r
  SSKJrJr  SSKJr  SSKJr  SSKrSSKrSSKJrJrJrJrJrJrJrJrJrJrJrJrJ r   SS	K!J"r"J#r#  SS
K$J%r%J&r&J'r'J(r(J)r)J*r*J+r+J,r,J-r-J.r.J/r/  SSK0J1r1  SSK2J3r3J4r4  SSK5J6r6  SSK7J8r8J9r9J:r:J;r;J<r<J=r=  Sr>Sr?Sr@\4R                  " \B5      rC\R0                  R                  rES rF\R                  " S\R                  R                  \R                  " SS5      S5      5      rJ\R                  rK\R                  " S\R                  5      rM\R                  " S\M5      rN\R                  " S\N5      rO\R                  " S\R                  R                  \R                  S5      5      rQSrR\" 5       R                  rTS H/  rU\R                  " \U5      c  M  \R                  " S\U S 3\W5        M1     S!rXS"rY\R                  R                  S#S$5      R                  5       \8;   r]\](       a  S%OS&r^\^r_\R                  R                  S'S5      b/  \R                  " S(\W5        \R                  R                  S'S5      r_\R                  R                  S)\_5      r_\_S*-   r`\_S+-   ra S]S,\bS-\bS.\\b\
S4   S/\\b   4S0 jjrcSSS1.S2\bS3\dS/\\b   S.\\b   S4\e\b   4
S5 jjrfS6 rgS7 rhS^S8\\i\bS4   S4\b4S9 jjrjS:\\b   S;\\b   S4\\b   4S< jrkS,\\b\R                  4   S=\bS4\\b   4S> jrm              S_S,\\b\R                  4   S@\e\b   S.\\\b\R                  4      SA\dSB\\d   SC\\i\b\b4      SD\\\d\b4      S/\\b   S3\dSE\bSF\\b   S8\\\b\i\b\b4   4      SG\dSH\dSI\dSJ\\b   S4\\b   4"SK jjrnS^SL jro   S`S?SSSM.SN\\b\R                  4   S=\bS/\\b   SC\\i\b\b4      SD\\\d\b4      S3\dS.\\b\
S4   SF\\b   4SO jjjrp " SP SQ5      rqSRSS.ST jrrSU\\s\b4   4SV jrt          SaSW jru   SbS2\bSX\\e\b      SD\\b   SY\d4SZ jjrv " S[ S\5      rwg)cz?
Hub utilities: utilities related to download and cache models
    N)futures)Path)OptionalUnion)urlparse)uuid4)_CACHED_NO_EXISTCommitOperationAdd	ModelCardModelCardData	constantscreate_branchcreate_commitcreate_repohf_hub_download
hf_hub_urllist_repo_treesnapshot_downloadtry_to_load_from_cache)REGEX_COMMIT_HASHhttp_get)EntryNotFoundErrorGatedRepoErrorHfHubHTTPErrorLocalEntryNotFoundErrorOfflineModeIsEnabledRepositoryNotFoundErrorRevisionNotFoundErrorbuild_hf_headersget_sessionhf_raise_for_statussend_telemetry)	HTTPError   )__version__logging)working_or_temp_dir)ENV_VARS_TRUE_VALUES_tf_version_torch_versionis_tf_availableis_torch_availableis_training_run_on_sagemakerzchat_template.jsonzchat_template.jinjaadditional_chat_templatesc                      [         $ N)_is_offline_mode     N/var/www/auris/envauris/lib/python3.13/site-packages/transformers/utils/hub.pyis_offline_moder5   U   s    r3   
TORCH_HOMEXDG_CACHE_HOMEz~/.cachetorchPYTORCH_PRETRAINED_BERT_CACHEPYTORCH_TRANSFORMERS_CACHETRANSFORMERS_CACHEHF_MODULES_CACHEmodulestransformers_modules)r9   r:   r;   zUsing `zQ` is deprecated and will be removed in v5 of Transformers. Use `HF_HOME` instead.z3https://s3.amazonaws.com/models.huggingface.co/bertzhttps://cdn.huggingface.coHUGGINGFACE_CO_STAGINGNOzhttps://hub-ci.huggingface.cozhttps://huggingface.coHUGGINGFACE_CO_RESOLVE_ENDPOINTzUsing the environment variable `HUGGINGFACE_CO_RESOLVE_ENDPOINT` is deprecated and will be removed in Transformers v5. Use `HF_ENDPOINT` instead.HF_ENDPOINTz)/{model_id}/resolve/{revision}/{filename}z/api/telemetry/examplespath_or_repo_idfull_filename	cache_dirrevisionc                 6    [        XX#S9nUb  U[        :w  a  U$ g )N)rE   rF   )r   r	   )rC   rD   rE   rF   resolved_files        r4   _get_cache_file_to_returnrI      s(     +?U^rM ]6F%Fr3   )rF   rE   repo_idlocal_files_onlyreturnc                   U(       dc   [        X[        SS9 Vs/ s HG  nUR                  R                  S5      (       d  M%  UR                  R	                  [         S35      PMI     sn$  [        XUSS9n[        U[        5      nUR                  5       (       d  / $ UR                  5        Vs/ s HG  oDR                  5       (       d  M  UR                   R                  S5      (       d  M;  UR"                  PMI     sn$ s  snf ! [
        [        [        4 a    e [        [        4 a     Nf = f! [         a    / s $ f = fs  snf )zList template files from a repo.

A template is a jinja file located under the `additional_chat_templates/` folder.
If working in offline mode or if internet is down, the method will list jinja template from the local cache - if any.
F)rJ   rF   path_in_repo	recursivez.jinja/T)rJ   rF   rE   rK   )r   CHAT_TEMPLATE_DIRpathendswithremoveprefixr   r   r   ConnectionErrorr#   r   r   r   is_diriterdiris_filenamestem)rJ   rK   rF   rE   entrysnapshot_dirtemplates_dirs          r4   list_repo_templatesr^      s8    	 ,#EVbgE ::&&x0	 A

''+<*=Q(?@ ()VZ

 '89M!!	$1$9$9$;q$;5}}JSXS]S]SfSfgoSpJEJJ$;qq-  79NO 	+ 		 # 	
 rsL   D $D&D(D ,D1 0EE.ED %D.-D.1E ?E c                 6    [        U 5      nUR                  S;   $ )N)httphttps)r   scheme)url_or_filenameparseds     r4   is_remote_urlre      s    o&F==---r3   c            	      v    [         R                  " [        R                  S   5      R	                  5       n U S   nU S   R                  S5      S   n[        R                  " [        R                  " SS5      5      nSU;   a  SOS	nS
[        R                  ;   a(  [        R                  " S
5      R                  S5      S   OS n[        R                  " SS 5      [        R                  " SS 5      [        R                  " SS5      [        R                  " SS5      UUUUS.nU$ ! [         a    S nS n Nf = f)NECS_CONTAINER_METADATA_URIImage:r$   SM_FRAMEWORK_PARAMSz{}*sagemaker_distributed_dataparallel_enabledTFTRAINING_JOB_ARN   SM_FRAMEWORK_MODULE
AWS_REGIONSM_NUM_GPUSr   SM_NUM_CPUS)sm_framework	sm_regionsm_number_gpusm_number_cpusm_distributed_trainingsm_deep_learning_containersm_deep_learning_container_tagsm_account_id)	requestsgetosenvironjsonsplit	Exceptionloadsgetenv)instance_datadlc_container_useddlc_tagsagemaker_paramsruns_distributed_training
account_idsagemaker_objects          r4   define_sagemaker_informationr      s    RZZ0L%MNSSU*73(..s3A6
 zz")),A4"HI(TXh(hns@RVXV`V`@`-.44S9!<fjJ 		"7>YY|T2=!4=!4#<&8*1#	 %  !s   AD' 'D87D8
user_agentc                    S[          S[        R                  R                  5       S    S[         3n[        5       (       a  US[         3-  n[        5       (       a  US[         3-  n[        R                  (       a  US-   $ [        5       (       a4  USSR                  S	 [        5       R                  5        5       5      -   -  n[        R                   R#                  S
S5      R%                  5       [&        ;   a  US-  n[)        U [*        5      (       a.  USSR                  S U R                  5        5       5      -   -  nU$ [)        U [,        5      (       a  USU -   -  nU$ )z>
Formats a user-agent string with basic info about a request.
ztransformers/z	; python/r   z; session_id/z; torch/z; tensorflow/z; telemetry/offz; c              3   4   #    U  H  u  pU S U 3v   M     g7frP   Nr2   .0kvs      r4   	<genexpr>"http_user_agent.<locals>.<genexpr>   s     ]6\da!AaSz6\   TRANSFORMERS_IS_CI z; is_ci/truec              3   4   #    U  H  u  pU S U 3v   M     g7fr   r2   r   s      r4   r   r      s     I6Hda!AaSz6Hr   )r%   sysversionr   
SESSION_IDr,   r*   r+   r)   r   HF_HUB_DISABLE_TELEMETRYr-   joinr   itemsr|   r}   r{   upperr(   
isinstancedictstr)r   uas     r4   http_user_agentr      s9    Ys{{/@/@/B1/E.FmT^S_	`B
())
k]++))%%%#%%
dTYY]6R6T6Z6Z6\]]]]	zz~~*B/557;OO
n*d##
dTYYIj6F6F6HIIII I 
J	$	$
dZIr3   rH   commit_hashc                     U b  Ub  U$ [        [        U 5      R                  5       5      n [        R                  " SU 5      nUc  gUR                  5       S   n[        R                  " U5      (       a  U$ S$ )zH
Extracts the commit hash from a resolved filename toward a cache file.
Nzsnapshots/([^/]+)/r   )r   r   as_posixresearchgroupsr   match)rH   r   r   s      r4   extract_commit_hashr      sq      7]+4467MYY,m<F~--/!$K+11+>>;HDHr3   filenamec                 :    [        SX/S.UD6nUb  US   nU$ UnU$ )a	  
Tries to locate a file in a local folder and repo, downloads and cache it if necessary.

Args:
    path_or_repo_id (`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:
        Deprecated and ignored. All downloads are now resumed by default when possible.
        Will be removed in v5 of Transformers.
    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.
    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 `huggingface-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.
    subfolder (`str`, *optional*, defaults to `""`):
        In case the relevant files are located inside a subfolder of the model repo on huggingface.co, you can
        specify the folder name here.
    repo_type (`str`, *optional*):
        Specify the repo type (useful when downloading from a space for instance).

<Tip>

Passing `token=True` is required when you want to use a private model.

</Tip>

Returns:
    `Optional[str]`: Returns the resolved file (to the cache folder if downloaded from a repo).

Examples:

```python
# Download a model weight from the Hub and cache it.
model_weights_file = cached_file("google-bert/bert-base-uncased", "pytorch_model.bin")
```
)rC   	filenamesr   r2   )cached_files)rC   r   kwargsfiles       r4   cached_filer      s9    t X:XQWXD&47DK -1DKr3   Fr   force_downloadresume_downloadproxiestoken	subfolder	repo_type _raise_exceptions_for_gated_repo%_raise_exceptions_for_missing_entries'_raise_exceptions_for_connection_errors_commit_hashc                    UR                  SS5      nUb+  [        R                  " S[        5        Ub  [	        S5      eUn[        5       (       a  U(       d  [        R                  S5        SnU	c  Sn	U Vs/ s H#  n[        R                  R                  U	U5      PM%     nn[        U 5      n / nU H  n[        R                  R                  U 5      (       d  M)  [        R                  R                  U U5      n[        R                  R                  U5      (       dK  U(       aB  U[        R                  R                  U	S5      :w  a  Uc  S	OUn[        U  S
U SU  SU S35      e  gUR                  U5        M     [!        U5      [!        U5      :X  a  U$ Uc  ["        n[%        U[&        5      (       a  [        U5      n/ nSnUb`  U(       dY  U HS  n[)        U UX/U
S9nUc  M  U[*        La  US-  nUR                  U5        M5  U(       d  US-  nMC  [        SU SU  S35      e   U[!        U5      :X  a  [!        U5      S:  a  U$ S$ [-        U5      n [!        U5      S:X  a)  [/        U US   [!        U	5      S:X  a  SOU	U
UUUUUUUUS9  O[1        U UU
UUUUUUUUS9   U Vs/ s H  n[?        U UX'5      PM     nn[K        S# U 5       5      (       a  U(       a  [M        UU5       VVs/ s H  u  nnUb  M  UPM     nnn[!        U5      S:X  a(  US   [        R                  R                  U	S5      :X  a  gUc  S	OUn[!        U5      S:X  a  S$US    3OS%/ UQ7 3n[O        U  S&U SU  SU S35      eU Vs/ s H
  nUc  M  UPM     nn[!        U5      S:X  a  SnU$ UnU$ s  snf ! [2         Ga  n[%        U[4        5      (       a$  [%        U[6        5      (       d  [        U  S35      Ue[%        U[8        5      (       a  [        U SU  S35      Ue[%        U[:        5      (       a  [        SUR<                   SU  S35      UeU Vs/ s H  n[?        U UX'5      PM     Os  snf nn[A        S U 5       5      (       a  Us SnA$ [%        U[6        5      (       a'  U(       d   SnAg[        SU  S[        U5       35      Ue[%        U[B        5      (       a-  U(       d   SnAgU(       a  [        S[D         S 35      Ue SnAGNd[%        U[F        5      (       a2  [%        U[H        5      (       d  U(       d   SnAg[        S!U  S"U 35      e[%        U[H        5      (       d  Ue SnAGNSnAff = fs  snf s  snnf s  snf )'a  
Tries to locate several files in a local folder and repo, downloads and cache them if necessary.

Args:
    path_or_repo_id (`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.
    filenames (`List[str]`):
        The name of all the files 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:
        Deprecated and ignored. All downloads are now resumed by default when possible.
        Will be removed in v5 of Transformers.
    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.
    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 `huggingface-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.
    subfolder (`str`, *optional*, defaults to `""`):
        In case the relevant files are located inside a subfolder of the model repo on huggingface.co, you can
        specify the folder name here.
    repo_type (`str`, *optional*):
        Specify the repo type (useful when downloading from a space for instance).

Private args:
    _raise_exceptions_for_gated_repo (`bool`):
        if False, do not raise an exception for gated repo error but return None.
    _raise_exceptions_for_missing_entries (`bool`):
        if False, do not raise an exception for missing entries but return None.
    _raise_exceptions_for_connection_errors (`bool`):
        if False, do not raise an exception for connection errors but return None.
    _commit_hash (`str`, *optional*):
        passed when we are chaining several calls to various files (e.g. when loading a tokenizer or
        a pipeline). If files are cached for this commit hash, avoid calls to head and get from the cache.

<Tip>

Passing `token=True` is required when you want to use a private model.

</Tip>

Returns:
    `Optional[str]`: Returns the resolved file (to the cache folder if downloaded from a repo).

Examples:

```python
# Download a model weight from the Hub and cache it.
model_weights_file = cached_file("google-bert/bert-base-uncased", "pytorch_model.bin")
```
use_auth_tokenNrThe `use_auth_token` argument is deprecated and will be removed in v5 of Transformers. Please use `token` instead.V`token` and `use_auth_token` are both specified. Please set only the argument `token`.z+Offline mode: forcing local_files_only=TrueTr   zconfig.jsonmainz& does not appear to have a file named z#. Checkout 'https://huggingface.co/z/tree/z' for available files.r   )rE   rF   r   r$   zCould not locate z inside .)
r   r   rF   rE   r   r   r   r   r   rK   )
allow_patternsr   rF   rE   r   r   r   r   r   rK   a   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 either by logging in with `huggingface-cli login` or by passing `token=<your_token>` 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/' for available revisions.zPermissionError at z when downloading z. Check cache directory permissions. Common causes: 1) another user is downloading the same model (please wait); 2) a previous download was canceled and the lock file needs manual removal.c              3   (   #    U  H  oS Lv   M
     g 7fr0   r2   r   r   s     r4   r   cached_files.<locals>.<genexpr>  s     ;ND4N   z`You are trying to access a gated repo.
Make sure to have access to it at https://huggingface.co/z.
zWe couldn't connect to 'z' to load the files, and couldn't find them in the cached files.
Checkout your internet connection or see how to run the library in offline mode at 'https://huggingface.co/docs/transformers/installation#offline-mode'.z:There was a specific connection error when trying to load z:
c              3   (   #    U  H  oS L v   M
     g 7fr0   r2   r   s     r4   r   r   3  s     
3ND4<Nr   za file named zfiles named z does not appear to have )(popwarningswarnFutureWarning
ValueErrorr5   loggerinfor|   rR   r   r   isdirisfileOSErrorappendlenr;   r   r   r   r	   r   r   r   r   r   r   r   PermissionErrorr   rI   allr   rA   r#   r   anyzipEnvironmentError)rC   r   rE   r   r   r   r   rF   rK   r   r   r   r   r   r   r   deprecated_kwargsr   r   full_filenamesexisting_filesr   rH   	revision_file_countereresolved_filesoriginalresolvedmissing_entriesmsgs                                  r4   r   r   =  s+   f '**+;TBN! A	
 uvv!1AB	 AJJ	bggll9d3	NJ/*ON"77==))GGLL(CM77>>-008XV_anIo=o*2*:I!*++QRZQ[ \33B2C6)Tjl 
  !!-0 # >c.11&	)T""	N	NL&H2YajM ( (88 A%L"))-8> A%L!$5hZxGXXY"Z[[ ' s>**!$^!4q!8~BdB ,JZ~!#!"%i.A"5$9#!#%- /!1 -#!#%- /!1V cqbpV^!/8YQbp   
3N
3338]>A.R`>av>a(:(em8>av~!#(:bggll9Vc>d(d&.FH	474HA4MmOA./0UabudsbuavSw 	 8=`ap`qqw  yB  xC C$ $
 	
 (6J~td~NJ 0A5TN <JNM Kd  :a011*Q:W:W"# $' '
  011* ++:*;;UW 	
 ?++%ajj\1COCT U^ ^ 	 gu
ftZb%oxUft
 
 ;N;;;!! a((3**9):#c!fXG  233: 7./N.O P] ] 	 7 9%%j<N.O.O:VWfVggjkljmnoo A122G 3s:x
 w Kss   7*N&7N+ N+ 'U3-
U8;U8<U>U>+U06BU+Q$# U+U0	U+*7U+&U+1U+=(U++U0c                     [         R                  " SU  S3[        5        [        R                  " 5       u  p#[
        R                  " US5       n[        XUS9  SSS5        U$ ! , (       d  f       U$ = f)aO  
Downloads a given url in a temporary file. This function is not safe to use in multiple processes. Its only use is
for deprecated behavior allowing to download config/models with a single url instead of using the Hub.

Args:
    url (`str`): The url of the file to download.
    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.

Returns:
    `str`: The location of the temporary file where the url was downloaded.
z5Using `from_pretrained` with the url of a file (here aY  ) is deprecated and won't be possible anymore in v5 of Transformers. You should host your file on the Hub (hf.co) instead and use the repository ID. Note that this is not compatible with the caching system (your file will be downloaded at each execution) or multiple processes (each process will download the file in a different temporary file).wb)r   N)r   r   r   tempfilemkstempr|   fdopenr   )urlr   tmp_fdtmp_filefs        r4   download_urlr   J  sn     MM
?u Ec 	c 	  '')F	64	 A) 
!O 
!	 Os   A##
A2)rK   rE   r   path_or_repoc          	         UR                  SS5      n	U	b+  [        R                  " S[        5        Ub  [	        S5      eU	n[
        R                  R                  U 5      (       a<  [
        R                  R                  [
        R                  R                  X5      5      $ [        U UUUUS9n
[        U
[        5      nU(       a  U$  [        5       R                  [        XX'S9[!        U[#        5       S9SUS	S
9n [3        U5        g! [$        R&                  R(                  [$        R&                  R*                  4 a    e [$        R&                  R,                  [$        R&                  R.                  [0        4 a    Us $ f = f! [4         a,  n[6        R9                  U5        [;        U  SU  S35      UeSnAf[<         a)  n[6        R9                  U5        [;        U  S35      UeSnAf[>         a,  n[6        R9                  U5        [;        U SU  S35      UeSnAf[@         a     g[$        RB                   a    Us $ f = f)a  
Checks if a repo contains a given file without downloading it. Works for remote repos and local folders.

If offline mode is enabled, checks if the file exists in the cache.

<Tip warning={false}>

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.

</Tip>
r   Nr   r   )rJ   r   rF   r   rE   )r   rF   r   )r   r   F
   )headersallow_redirectsr   timeoutTzN is a gated repository. Make sure to request access at https://huggingface.co/z and pass a token having permission to this repo either by logging in with `huggingface-cli login` or by passing `token=<your_token>`.zE is not a local folder or a valid repository name on 'https://hf.co'.r   r   )"r   r   r   r   r   r|   rR   r   r   r   r   r   r   r    headr   r   r   rz   
exceptionsSSLError
ProxyErrorrU   Timeoutr   r!   r   r   errorr   r   r   r   r#   )r   r   rF   r   r   rK   rE   r   r   r   cached_pathhas_file_in_cacheresponser   s                 r4   has_filer  e  s;   0 '**+;TBN! A	
 uvv 
ww}}\""ww~~bggll<BCC )K #;4   !=%%|_$5_=NO! & 
"!H% (((*=*=*H*HI ++## !
 ! !  Qn &&2^ 4ZZ
 		
 # uQ&klmstt  Qj KKW.Xrt
 	   !  !sO   3D <F A7FF
I'F66I$G''I4'HI*IIc                      \ rS rSrSr    SS\S\\   S\\\\4      S\\   S\\   S	\4S
 jjr	S\\\
R                  4   4S jr     SS\\\
R                  4   S\S\\\4   S\\   S\\\\4      S\S\\   S\\   4S jjr          SS\S\\   S\\   S\\   S\\\\4      S\\\\4      S\S\S\\   S\\   S\\\      S	\4S jjrSrg)PushToHubMixini  zO
A Mixin containing the functionality to push a model or tokenizer to the hub.
NrJ   privater   repo_urlorganizationrL   c                 P   Ub=  [         R                  " S5        Ub  [        S5      eUR                  [         S3S5      nUbM  [         R                  " S5        UR                  U5      (       d!  SU;   a  UR                  S5      S   nU SU 3n[        XUSS9nUR                  $ )	zy
Create the repo if needed, cleans up repo_id with deprecated kwargs `repo_url` and `organization`, retrieves
the token.
zgThe `repo_url` argument is deprecated and will be removed in v5 of Transformers. Use `repo_id` instead.zT`repo_id` and `repo_url` are both specified. Please set only the argument `repo_id`.rP   r   zThe `organization` argument is deprecated and will be removed in v5 of Transformers. Set your organization directly in the `repo_id` passed instead (`repo_id={organization}/{model_id}`).T)rJ   r   r  exist_ok)	r   r   r   replacerA   
startswithr   r   rJ   )selfrJ   r  r   r  r  r   s          r4   _create_repoPushToHubMixin._create_repo  s     MM " j  &&*I)J!'LbQG#MMo %%l33'>%mmC04G)N!G95'RVW{{r3   working_dirc           
          [         R                  " U5       Vs0 s H?  o"[         R                  R                  [         R                  R	                  X5      5      _MA     sn$ s  snf )zC
Returns the list of files with their last modification timestamp.
)r|   listdirrR   getmtimer   )r  r  r   s      r4   _get_files_timestamps$PushToHubMixin._get_files_timestamps  sI     LN::VaKbcKba277##BGGLL$@AAKbcccs   AA"files_timestampscommit_message	create_prrF   commit_descriptionc	                    Uc  SU R                   R                  ;   a  SnOSU R                   R                  ;   a  SnOpSU R                   R                  ;   a  SnOSSU R                   R                  ;   a  S	nO6S
U R                   R                  ;   a  SnOSU R                   R                   3n[        R                  " U5       V	s/ s HN  n	X;  dD  [        R                  R                  [        R                  R                  X5      5      X9   :  d  ML  U	PMP     n
n	U
 V	s/ s H  n	[        R                  R                  [        R                  R                  X5      5      (       dC  [        R                  R                  [        R                  R                  X5      5      (       d  M  U	PM     n
n	/ nU
 GH  n[        R                  R                  [        R                  R                  X5      5      (       a  [        R                  " [        R                  R                  X5      5       HW  n	UR                  [        [        R                  R                  XU	5      [        R                  R                  X5      S95        MY     M  UR                  [        [        R                  R                  X5      US95        GM     Ub"  UR                  S5      (       d   [        X'USS9  [         R#                  SU SSR                  U
5       35        [%        UUUUUUUS9$ s  sn	f s  sn	f ! [         a,  nUR                  R                  S:X  a  U(       a   SnANse SnAff = f)zX
Uploads all modified files in `working_dir` to `repo_id`, based on `files_timestamps`.
NModelzUpload modelConfigzUpload config	TokenizerzUpload tokenizerFeatureExtractorzUpload feature extractor	ProcessorzUpload processorzUpload )path_or_fileobjrN   zrefs/prT)rJ   branchr   r	  i  z!Uploading the following files to z: ,)rJ   
operationsr  r  r   r  rF   )	__class____name__r|   r  rR   r  r   r   r   r   r
   r  r   r   r   status_coder   r   r   )r  r  rJ   r  r  r   r  rF   r  r   modified_filesr"  r   r   s                 r4   _upload_modified_files%PushToHubMixin._upload_modified_files  s    !$..111!/T^^444!0 7 77!3#t~~'>'>>!; 7 77!3#*4>>+B+B*C!D ZZ,
,(BGG,<,<RWW\\+=Y,Z]m]p,p , 	 
 $
#ww~~bggll;:;;rww}}RWW\\ZeMi?j # 	 
 
"Dww}}RWW\\+<==BGGLL$CDA%%*,.GGLLA,N]_]d]d]i]ijn]r E !!&rww||K7Veij # (;(;I(F(F	geVZ[ 	7y388NC[B\]^!)1
 	
U

2 " ::))S0Y s8   AL%L%!BL*+L*!L/ /
M%9!M M  M%use_temp_dirmax_shard_sizesafe_serializationtagsc                 Z   UR                  SS5      nUR                  SS5      nUR                  SS5      nUb+  [        R                  " S[        5        Ub  [	        S5      eUnUR                  SS5      nUb  [        R                  " S	[        5        Ub  [	        S
5      e[
        R                  R                  U5      (       a/  UR                  [
        R                  R                  5      S   nUnO+UnUR                  S5      S   nOUR                  S5      S   nUR                  SS5      nUR                  SS5      nU R                  XUUUS9n[        XX^S9nUc$  [
        R                  R                  U5      (       + n[        UUS9 nU R                  U5      nU(       a  U R                  UUUSS9  OU R                  UXhS9  UR                  [
        R                  R!                  US5      5        U R#                  UUUUUUU	U
S9sSSS5        $ ! , (       d  f       g= f)u	  
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 to make the repo private. If `None` (default), the repo will be public unless the organization's default is private. This value is ignored if the repo already exists.
    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("google-bert/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")
```
r   Nignore_metadata_errorsFsave_jinja_filesr   r   repo_path_or_namezpThe `repo_path_or_name` argument is deprecated and will be removed in v5 of Transformers. Use `repo_id` instead.z]`repo_id` and `repo_path_or_name` are both specified. Please set only the argument `repo_id`.r  rP   r  r  )r  r   r  r  r   r.  )r  r)  T)r*  r+  r/  )r*  r+  z	README.md)r  r   r  rF   r  )r   r   r   r   r   r|   rR   r   r   sepr  create_and_tag_model_cardr'   r  save_pretrainedsaver   r'  )r  rJ   r)  r  r  r   r*  r  r+  rF   r  r,  r   r   r.  r/  r0  r  r  r  
model_cardwork_dirr  s                          r4   push_to_hubPushToHubMixin.push_to_hubF  sM   ~ +../?F!2!6!67OQV!W,00
 %MM E   l  #E-112EtL( MM%
 " s  ww}}.//+11"''++>rB% ,%mmC04 "--,R0K %((T:(,,^TB##EHS_ $ 

 /

 !ww}}[99L [|TX`#99(C  $$#1'9%)	 %  $$Xn$t OOBGGLL;?@.. -#!#5 / 	# UTTs   B H
H*r2   )NNNN)NNFNN)
NNNN5GBFTNNN)r$  
__module____qualname____firstlineno____doc__r   r   boolr   r  r|   PathLiker  r   floatr'  intlistr8  __static_attributes__r2   r3   r4   r  r    s    #',0"&&*!! $! dCi()	!
 3-! sm! 
!FdsBKK7G1H d )-,0"&,0M
3+,M
 M
 sEz*	M

 !M
 dCi()M
 M
 3-M
 %SMM
d (,(,"&,049#'"&,0$(RR tnR !	R
 $R dCi()R !sCx1R R !R 3-R %SMR tCy!R 
R Rr3   r  pytorch)	frameworkc                R   [        5       (       a  gXS.nU H  nUR                  R                  5        VVs0 s H$  u  pVUR                  S5      (       a  M  Uc  M"  XV_M&     nnnSU;   a1  US   n[        R
                  R                  U5      (       d  US   US'   SU;   a
  US   US'   M  SU;   d  M  U R                  SS	5      R                  S
S	5      R                  SS	5      n	U	R                  SS	5      n	U	 SUS    3US'   M     [        SS[        [        U5      S9  gs  snnf )a  
Sends telemetry that helps tracking the examples use.

Args:
    example_name (`str`): The name of the example.
    *example_args (dataclasses or `argparse.ArgumentParser`): The arguments to the script. This function will only
        try to extract the model and dataset name from those. Nothing else is tracked.
    framework (`str`, *optional*, defaults to `"pytorch"`): The framework for the example.
N)examplerF  _model_name_or_path
model_namedataset_name	task_nametf_r   flax_run__no_trainer-examplestransformers)topiclibrary_namelibrary_versionr   )r5   __dict__r   r  r|   rR   r   r
  r"   r%   r   )
example_namerF  example_argsdataargsr   r   args_as_dictrK  script_names
             r4   send_example_telemetryr_    s,    #<D)-)<)<)>j)>allSVFW\])>j</%&:;J77==,,%12F%G\"\)#/#?D L(&..ub9AA'2NVVW]_abK%--mR@K&1]!L4M3N#OD    ~{_nos_t ks   D#D#D#sizec                 p   [        U [        5      (       a  U $ U R                  5       R                  S5      (       a  [        U SS 5      S-  $ U R                  5       R                  S5      (       a  [        U SS 5      S-  $ U R                  5       R                  S5      (       a  [        U SS 5      S-  $ U R                  5       R                  S	5      (       a.  [        U SS
 5      S-  nU R                  S5      (       a  US-  $ U$ U R                  5       R                  S5      (       a.  [        U SS
 5      S-  nU R                  S5      (       a  US-  $ U$ U R                  5       R                  S5      (       a.  [        U SS
 5      S-  nU R                  S5      (       a  US-  $ U$ [	        S5      e)a  
Converts a size expressed as a string with digits an unit (like `"5MB"`) to an integer (in bytes).

Args:
    size (`int` or `str`): The size to convert. Will be directly returned if an `int`.

Example:
```py
>>> convert_file_size_to_int("1MiB")
1048576
```
GIBNi   @MIBi   KIBi   GBi ʚ;b   MBi@B KBi  zR`size` is not in a valid format. Use an integer followed by the unit, e.g., '5GB'.)r   rB  r   rS   r   )r`  int_sizes     r4   convert_file_size_to_intrm    s~    $zz|U##49~''zz|U##49~''zz|U##49~''zz|T""tCRy>U+ $c 2 2x1}@@zz|T""tCRy>U+ $c 2 2x1}@@zz|T""tCRy>U+ $c 2 2x1}@@
i
jjr3   c                 (   SSK nUR                  SS5      nUb+  [        R                  " S[        5        Ub  [        S5      eUn[        R                  R                  U5      (       d  [        SU SU  S35      e[        U5       nUR                  " UR                  5       5      nSSS5        [        [        WS	   R                  5       5      5      nUS
   n[        US	   R!                  5       5      US'   US	   R#                  5       US	'   [        R                  R%                  U 5      (       a4  U Vs/ s H#  n[        R                  R'                  X
U5      PM%     nnUU4$ [)        U UUUUUUUUU	U
US9nUU4$ ! , (       d  f       N= fs  snf )a  
For a given model:

- download and cache all the shards of a sharded checkpoint if `pretrained_model_name_or_path` is a model ID on the
  Hub
- returns the list of paths to all the shards, as well as some metadata.

For the description of each arg, see [`PreTrainedModel.from_pretrained`]. `index_filename` is the full path to the
index (downloaded and cached if `pretrained_model_name_or_path` is a model ID on the Hub).
r   Nr   r   r   zCan't find a checkpoint index (z) in r   
weight_mapmetadataall_checkpoint_keys)
rE   r   r   r   rK   r   r   rF   r   r   )r~   r   r   r   r   r   r|   rR   r   openr   readsortedsetvaluesrC  keyscopyr   r   r   )pretrained_model_name_or_pathindex_filenamerE   r   r   r   rK   r   r   rF   r   r   r   r~   r   r   indexshard_filenamessharded_metadatacached_filenamess                       r4   get_checkpoint_shard_filesr    s   2 &**+;TBN! A	
 uvv77>>.)):>:J%PmOnnopqq	n	

1668$ 
 S|!4!;!;!=>?OZ(.253F3K3K3M.N*+%*<%8%=%=%?\" 
ww}}233^mn^mYZ277<<(ERST^mn 000 $%%')! ---= 
	 os   !E>6*F>
Fr,  r.  c                     [         R                  " XUS9nUbq  UR
                  R                  c  / UR
                  l        U HC  nXtR
                  R                  ;  d  M  UR
                  R                  R                  U5        ME     U$ ! [         a(    Sn[        Uc  / OUSS9n[         R                  " XeS9n Nf = f)aW  
Creates or loads an existing model card and tags it.

Args:
    repo_id (`str`):
        The repo_id where to look for the model card.
    tags (`List[str]`, *optional*):
        The list of tags to add in the model card
    token (`str`, *optional*):
        Authentication token, obtained with `huggingface_hub.HfApi.login` method. Will default to the stored token.
    ignore_metadata_errors (`bool`, *optional*, defaults to `False`):
        If True, errors while parsing the metadata section will be ignored. Some information might be lost during
        the process. Use it at your own risk.
r1  u   This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.rT  )r,  rV  )model_description)r   loadr   r   from_templater[  r,  r   )rJ   r,  r   r.  r6  r  	card_data	model_tags           r4   r3  r3  h  s    (]^^GQgh
 ??'#%JOO I 4 44$$++I6    ] e!T\rtR`a	,,Y\
	]s   B /B?>B?c                   ^    \ rS rSrSrSS\\R                     SS4S jjrS r	S r
SS	 jrS
rg)PushInProgressi  zb
Internal class to keep track of a push in progress (which might contain multiple `Future` jobs).
NjobsrL   c                 (    Uc  / U l         g UU l         g r0   r  )r  r  s     r4   __init__PushInProgress.__init__  s    ,B	D	r3   c                 :    [        S U R                   5       5      $ )Nc              3   @   #    U  H  oR                  5       v   M     g 7fr0   )done)r   jobs     r4   r   )PushInProgress.is_done.<locals>.<genexpr>  s     3#88::s   )r   r  r  s    r4   is_donePushInProgress.is_done  s    3333r3   c                 D    [         R                  " U R                  5        g r0   )r   waitr  r  s    r4   wait_until_donePushInProgress.wait_until_done  s    TYYr3   c                     U R                    Vs/ s H3  nUR                  5       (       a  M  UR                  5       (       a  M1  UPM5     snU l         g s  snf r0   )r  cancelr  )r  r  s     r4   r  PushInProgress.cancel  sE     yy
 JJL  %(HHJ  
	 
s   AAAr  r0   )rL   N)r$  r;  r<  r=  r>  r   r   Futurer  r  r  r  rD  r2   r3   r4   r  r    s2    1Xgnn5 1 14 
r3   r  )NNr0   )NFNNNNFr   NNTTTN)NNN)
NFNNFNNNr   N)NNF)xr>  r~   r|   r   r   r   r   
concurrentr   pathlibr   typingr   r   urllib.parser   uuidr   huggingface_hubrz   r	   r
   r   r   r   r   r   r   r   r   r   r   r   huggingface_hub.file_downloadr   r   huggingface_hub.utilsr   r   r   r   r   r   r   r   r    r!   r"   requests.exceptionsr#   r   r%   r&   genericr'   import_utilsr(   r)   r*   r+   r,   r-   #LEGACY_PROCESSOR_CHAT_TEMPLATE_FILECHAT_TEMPLATE_FILErQ   
get_loggerr$  r   HF_HUB_OFFLINEr1   r5   r   rR   r   torch_cache_homedefault_cache_pathHF_HUB_CACHEr9   r:   r;   HF_HOMEr<    TRANSFORMERS_DYNAMIC_MODULE_NAMEhexr   keyr   r   S3_BUCKET_PREFIXCLOUDFRONT_DISTRIB_PREFIXr}   r{   r   _staging_mode_default_endpointrA   HUGGINGFACE_CO_PREFIX!HUGGINGFACE_CO_EXAMPLES_TELEMETRYr   rI   r?  rC  r^   re   r   r   r   r   r@  r   r   r   r  r  r_  rB  rm  r  r3  r  r2   r3   r4   <module>r     s    	 	 
     " !       F    * " (  '; #* /  
		H	%",,;;  99\277<<		BRT^8_ah+ij 11  !#		*I9KaKa b YY'CEbc YY35OP 99/i>O>OQZ1[\ #9  W[[
 aC	yy~!cUkl	
 a I 8 

7>DDFJ^^7D3Jb "3 ::>>3T:FMM	6
 ')jjnn5VX\&]#"$**..@_"` 7:ee $CF_$_ ! sw),9>sD$9Objknbo ##%r%r %r sm	%r
 }%r 
#Y%rP.
4dCo 6 # .Ix} I8C= IU]^aUb I<3+,<< c]	<D 48 &*(,(,""#7;-12648"&!J3+,JCyJ c2;;./0J 	J
 d^J d38n%J E$)$%J smJ J J }J sDcN234J '+J ,0J .2J  3-!J$ c]%JZ< #(,(,a! #(,#a!R[[()a!a! sma! d38n%	a!
 E$)$%a! a! S$_%a! }a!HO Od CL  Fk5c? kH 
F.V !%#(	%%
49
% C=% !	%P
 
r3   