L i1ndZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZddlmZddlmZddlmZmZmZddlmZddlmZdd lmZmZmZmZm Z m!Z!dd l"m#Z#m$Z$e!jJe&Z'd e(d e(fd Z)e jTZ+dZ,d ee(ejZfd dfdZ.dee(ejZfd e/e(fdZ0dee(ejZfd e/e(fdZ1dee(ejZfd e/e(fdZ2dee(ejZfd e/e(fdZ3ddde(dee(ejZfde4d e5fdZ6 d2dee(ejZfde(deee(ejZfde4dee4d ee7e(e(fd!eee4e(fd"ee(d#e4d$ee(d%ee(d e(fd&Z8 d2d'e(dee(ejZfdeee(ejZfde4dee4d ee7e(e(fd!eee4e(fd"ee(d#e4d$ee(d(ee(d e5fd)Z9d3d*ed+ee(ejZfd,ee7d e/e(fd-Z:d.Z;d/Z< d4d0Z=d5d1Z>y)6z3Utilities to dynamically load objects from the Hub.N)Path) ModuleType)AnyOptionalUnion)try_to_load_from_cache)version)HF_MODULES_CACHE TRANSFORMERS_DYNAMIC_MODULE_NAME cached_fileextract_commit_hashis_offline_modelogging)VersionComparisonsplit_package_versionnamereturnc<|jddjdd}|r|djrd|}tj|rtj d|d|d |S|j stj d|d|d |S) a Tries to sanitize a module name so that it can be used as a Python module. The following transformations are applied: 1. Replace `.` in module names with `_dot_`. 2. Replace `-` in module names with `_hyphen_`. 3. If the module name starts with a digit, prepend it with `_`. 4. Warn if the sanitized name is a Python reserved keyword or not a valid identifier. If the input name is already a valid identifier, it is returned unchanged. ._dot_-_hyphen_r_zThe module name z (originally z\) is a reserved keyword in Python. Please rename the original module to avoid import issues.z]) is not a valid Python identifier. Please rename the original module to avoid import issues.)replaceisdigitkeyword iskeywordloggerwarning isidentifier)rnew_names g/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/transformers/dynamic_module_utils.py_sanitize_module_namer$3s"||C)11#zBHHQK'')xj>"xj dV.recursive_look_for_importssW dCGG $  cff %99D"%((4. nchh7%,^-@-@$%KN&// <*55oF"<#5#5#B#BNS cjj ) 5"ZZ--c215 $((4 5cnn -zzQ4;;![[..s3A6 $((4))$/ .E &u - .r%)r@rArFtransformers.utilsr`parsesorted)rXrGrHtreer{r|r}s @@@r# get_importsrsg h )Q&&(u.B 99W Dt$ " ##Us A''A0ct|}g}|D]} tj|t|dkDr0tddj|dd j|d t|S#t$rE}tj d|d|dt |vr|j|nYd}~d}~wwxYw) a. Check if the current Python environment contains all the libraries that are imported in a file. Will raise if a library is missing. Args: filename (`str` or `os.PathLike`): The module file to check. Returns: `list[str]`: The list of relative imports in the file. z&Encountered exception while importing z: zNo module namedNrz\This modeling file requires the following packages that were not found in your environment: z, z. Run `pip install  `) rr1 import_module ImportErrorrr rNr,rOjoinrJ)rXimportsmissing_packagesimp exceptions r# check_importsrs(#G    # #C (  q  jyy)*++>sxxHX?Y>ZZ[ ]   ))!  NNCC59+V W!C N2 '',-  sA44 C=;B==CF force_reload class_namerTrc tjj|}|jd}|j tjj d}t t|z }t5|r4tjj|dtjtjj|}tjj!||}|gt#t%t t'|z}t)j*dj-d|Dj/}|3tjj1|} | tj|<n|} t3| dd|k7r"|j4j7| || _t3| |cdddS#1swYyxYw) a Import a module on the cache directory for modules and extract a class from it. Args: class_name (`str`): The name of the class to import. module_path (`str` or `os.PathLike`): The path to the module to import. force_reload (`bool`, *optional*, defaults to `False`): Whether to reload the dynamic module from file if it already exists in `sys.modules`. Otherwise, the module is only reloaded if the file has changed. Returns: `typing.Type`: The class looked for. rLrN)locationr%c3TK|] }t||jz"ywN)bytes read_bytes).0rGs r# z&get_class_in_module..,s 2cQR58alln3L2cs&(__transformers_module_hash__r\)r-r+normpath removesuffixrseprr _HF_REMOTE_CODE_LOCKr*modulespopr1r2getutilspec_from_file_locationrmaprWhashlibsha256r hexdigestmodule_from_specrfloader exec_moduler) rrTrrr: cached_module module_spec module_files module_hashrss r#get_class_in_moduler sc& 77  K (D   U #D << S )D-.>#((2cVb2c*cdnnp   ^^44[AF &CKK "F 692 >+ M    * *6 22=F /vz*-+++s 3E GGpretrained_model_name_or_path cache_dirforce_downloadresume_downloadproxiestokenrevisionlocal_files_only repo_type _commit_hashc N | jdd} | )tjdt| t d| }t r|st jdd}t|}tjj|} | r)ttjj|}nVtjjjt!t|j#d}t%|||| | }g} t'|||||||||| | }| s|k7r|j)|t-|}t.tjjz|z}t1|t3t4|z }|ttjj|k(r)||z j7r"t9j:|t||z sM||z j<j?dd tAjB|||z tEjF|D]}t3|j<|dz }tjj||}||z j7r#t9j:|t||z rttAjB|||z tEjFntI|| }||z }|tjjz|z}tjj||}t1t3|j<||z j7s-tAjB|||z tEjF|D]h}||z j<|dz j7r'tK|t3|j<|z d|||||||| |j)|djtM|dkDrP|Ndj|Dcgc]}d| c}}| dn| d}d||}t jOd|d|dtjj||S#t*$rt jd |d |d wxYwcc}w)a Prepares Downloads a module from a local folder or a distant repo and returns its path inside the cached Transformers module. Args: pretrained_model_name_or_path (`str` or `os.PathLike`): This can be either: - a string, the *model id* of a pretrained model configuration hosted inside a model repo on huggingface.co. - a path to a *directory* containing a configuration file saved using the [`~PreTrainedTokenizer.save_pretrained`] method, e.g., `./my_model_directory/`. module_file (`str`): The name of the module file containing the class to look for. 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 `hf auth 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. repo_type (`str`, *optional*): Specify the repo type (useful when downloading from a space for instance). Passing `token=True` is required when you want to use a private model. Returns: `str`: The path to the module inside the cache. 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=TrueT/)rrr) rrrrrrrrrzCould not locate the z inside r)parentsr(rL)rrrrrrrrr z- r\zs/zhttps://huggingface.co/z9A new version of the following files was downloaded from z: z . Make sure to double-check they do not contain any added malicious code. To avoid downloading new versions of the code file, you can pin a revision.)(rwarningswarn FutureWarning ValueErrorrrinforNr-r+isdirr$basenamerrrrorr r,OSErrorrr r8rr r/filecmpcmpr7mkdirshutilcopyr1r2rget_cached_module_filerOr )rr:rrrrrrrrrdeprecated_kwargsris_local submoduler new_filesresolved_module_filemodules_neededfull_submodulesubmodule_path module_neededmodule_needed_file commit_hashfull_submodule_module_file_pathrG repo_type_strurls r#rr<su|'**+;TBN!  A    uv v!1 AB%((E$F!ww}}:;H)"''*:*:;X*YZ GGKK$$S)>@]@c@cdg@h%ij . );)Vbnw I* ) )+-% M-AA   [ )##78N6 CiON.)*+n M (+5'"''++5 C*,'',,~{*S'd#BCJJK,446 KK,n{.J K  ' ' )+ 8M#k199}oS Calling this function will execute the code in the module file found locally or downloaded from the Hub. It should therefore only be called on trusted repos. Args: class_reference (`str`): The full name of the class to load, including its module and optionally its repo. pretrained_model_name_or_path (`str` or `os.PathLike`): This can be either: - a string, the *model id* of a pretrained model configuration hosted inside a model repo on huggingface.co. - a path to a *directory* containing a configuration file saved using the [`~PreTrainedTokenizer.save_pretrained`] method, e.g., `./my_model_directory/`. This is used when `class_reference` does not specify another repo. module_file (`str`): The name of the module file containing the class to look for. class_name (`str`): The name of the class to import in the module. 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 `hf auth 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. repo_type (`str`, *optional*): Specify the repo type (useful when downloading from a space for instance). code_revision (`str`, *optional*, defaults to `"main"`): The specific revision to use for the code on the Hub, if the code leaves in a different repository than the rest of the model. 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. Passing `token=True` is required when you want to use a private model. Returns: `typing.Type`: The class, dynamically imported from the module. Examples: ```python # Download module `modeling.py` from huggingface.co and cache then extract the class `MyBertModel` from this # module. cls = get_class_from_dynamic_module("modeling.MyBertModel", "sgugger/my-bert-model") # Download module `modeling.py` from a given repo and cache then extract the class `MyBertModel` from this # module. cls = get_class_from_dynamic_module("sgugger/my-bert-model--modeling.MyBertModel", "sgugger/another-bert-model") ```rNrrz--rrL)rrrrrrrrr)rrrrrrorr)rrrrrrrrrrrkwargsrrepo_idr:r final_modules r#get_class_from_dynamic_modulerstZZ 0$7N!  A    uv v #2#8#8#> /-33C8K!>'!I )e%') L z._set_auto_map_in_configsqmm.. !'',R0 "m1S]]%;%;$<= ) ##' #' }}%%..v6*5a 8N8N7O'P$3 6=I%,S2H%IN+9+D+D(+?+E+Ec+J2+N(.B-C1^E\E\D]+^(+6a 8N8N7O'P$-/CDI gt ${{:r2H(1HS__ %"*GJ  Wj$ / ;09G  S__ - #;G r%)rrr r_rEtupler*r__file__rrrrr,rW) rrrrcfgresult object_file dest_file needed_files ` r#custom_object_saverks ~~#.se4x@  <@&4-( )C #C ( )  ' F++cnn-66KV [ 1 6 67I KK Y' MM)1=! LD$5$:$:;  K+ i ! Mr%ctd)NzLoading this model requires you to execute custom code contained in the model repository on your local machine. Please set the option `trust_remote_code=True` to permit loading of this model.)r)signumframes r#_raise_timeout_errorrs  c r%c|^| d|d|d|d}nOtjj|r'd|dtjj|d}n d|d|d}||rd}n|rtd kDrd} t j t j t}t jt|=t|d |d }|jd vrd }n|jdvrd}|=t jd  |Ht j t j |t jd n|r tdd|r|s|st|d |d|S#t$rt|d |dwxYw#|:t j t j |t jd wwxYw)a Resolves the `trust_remote_code` argument. If there is remote code to be loaded, the user must opt-in to loading it. Args: trust_remote_code (`bool` or `None`): User-defined `trust_remote_code` value. model_name (`str`): The name of the model repository in huggingface.co. has_local_code (`bool`): Whether the model has local code. has_remote_code (`bool`): Whether the model has remote code. error_message (`str`, *optional*): Custom error message to display if there is remote code to load and the user didn't opt-in. If unset, the error message will be regarding loading a model with custom code. Returns: The resolved `trust_remote_code` value. NzThe repository z% references custom code contained in zm which must be executed to correctly load the model. You can inspect the repository content at https://hf.co/z . zt contains custom code which must be executed to correctly load the model. You can inspect the repository content at z contains custom code which must be executed to correctly load the model. You can inspect the repository content at https://hf.co/Frz9 You can inspect the repository content at https://hf.co/z. You can avoid this prompt in future by passing the argument `trust_remote_code=True`. Do you wish to run the custom code? [y/N] )yesy1T)non0r\zS. Please pass the argument `trust_remote_code=True` to allow custom code to be run.) r-r+rabspathTIME_OUT_REMOTE_CODEsignalSIGALRMralarminputlower Exceptionr)trust_remote_code model_namehas_local_codehas_remote_code error_message upstream_repoprev_sig_handleranswers r#resolve_trust_remote_coder s.  $!*-RS`Rab,,9?$@  WW]]: &!*. ggooj9:$@ "*.,,6G c g} td ||d|}t|d5}|j}ddd|D]}|j}|r|j dr' t |\}}} tjj|} |E| Ctj|tj| tj| } nd} | r|j|d| d  |r!t!d |d d j#|zy#1swYxYw#t $r |}d\}} YwxYw#tjj$r|j|dY7wxYw#t$rYwxYw)a Tries to locate `requirements_file` in a local folder or repo, and confirms that the environment has all the python dependencies installed. 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. kwargs (`dict[str, Any]`, *optional*): Additional arguments to pass to `cached_file`. )path_or_repo_idrXrN#NNz (installed: None)Tz (installed: )z4Missing requirements in your local environment for `z`: r)r r@ readlinesstriprirrr1metadatar PackageNotFoundErrorr,r from_stringrrrr) r"requirements_filerfailed requirementsrG requirement package_name delimiterversion_numberlocal_package_version is_satisfieds r#check_python_requirementsr6sF" "i?M^ibhi , $ );;=L )( UK%++-K+"8"8"= 7:OP[:\7 i  (1(:(:(B(B<(P% $)CG0<B?BSSW X[_[d[dek[l l  E ) ) 7* ,6) > 7 %%::   -?@A     spE4D1E4!D&1D<A E4E4D#E4&D96E48D99E4<1E1-E40E11E44 F?F) NFNNNNFNNrr%)zrequirements.txt)?__doc__r`rrr1importlib.metadataimportlib.utilrr-rBrrr* threadingrpathlibrtypesrtypingrrrhuggingface_hubr packagingr rkr r r rrrutils.import_utilsrr get_loggerrrrNr$Lockrr4PathLiker8rErJrWrrbooltyperrrrrrrr r6r'r%r#rFs:  ''2I   H %B&y~~' & &c2;;&6 7&D&,'eC,<&='$s)'* 5bkk1A+B tCy @4$%R[[ 014$d3i4$n *E#r{{"23 *S *N -+-+sBKK'(-+ -+  -+f48 &*(,(,""#"&o5#(bkk)9#:o5o5c2;;./0o5 o5 d^ o5 d38n % o5 E$)$ %o5smo5o5}o53-o5 o5j48 &*(,(,""##'zVzV#(bkk)9#:zVc2;;./0zV zV d^ zV d38n % zV E$)$ %zVsmzVzV}zVC=zV zVzICIsBKK/?)@I(SW.IdhildmIXgkRj5 r%