
    g4             
          d Z ddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZ ddlmZ ddlmZ ddlmZ ddlmZmZmZmZmZmZmZ ddlmZ d	d
lmZ  ej        e           Z!dQde"de#deee#e"f         e#f         fdZ$h dZ%e%&                    dh          Z'ej(        )                    dd          *                                Z+ej(        )                    dd          *                                Z,ej(        )                    dd          *                                Z-ej(        )                    dd          *                                Z.ej(        )                    dd          *                                Z/ ej0        d          Z1dZ2dZ3dZ4dZ5dZ6 e$dd           \  Z7Z8 e$d!          Z9 e$d"          Z:ej;        <                    d#          duZ= e$d$          Z> e$d%          Z? e$d&          Z@ e$d'          ZA e$d(          ZB e$d)          ZC e$d*          ZDej;        <                    d+          duZE e$d,          ZFej;        <                    d-          duZG e$d.          ZH e$d/          ZIej;        <                    d0          duZJ	 ejK                            d0          ZLe!M                    d1eL            n`# ejK        jN        $ rN 	 ejK                            d2          ZLe!M                    d1eL            n# ejK        jN        $ r dZJY nw xY wY nw xY w e$d3          ZO e$d4          ZP e$d5d           \  ZQZR e$d6          ZS e$d7          ZT e$d8          ZU e$d9          ZV e$d:          ZW e$d;          ZX e$d<          ZY e$d=          ZZ e$d>          Z[ e$d?          Z\ e$d@          Z] e$dA          Z^ej;        <                    dB          duZ_ e$dC          Z`dZa	 ejK                            dD           dZan# ejK        jN        $ r dZaY nw xY wej;        <                    dE          duZb e$dF          Zc e$dG          Zd e$dH          Ze e$dI          Zf e$dJ          Zg e$dK          Zh e$dL          Zi e$dM          Zj e$dN          Zk e$dO          Zl e$dP          Zm e$dQ          Zn e$dR          Zo e$dS          Zp e$dT          Zq e$dU          Zr e$dV          Zs e$dWd           \  ZtZuej;        <                    dX          duZvevr3	 ejK                            dY           n# ejK        jN        $ r dZvY nw xY wej;        <                    dZ          duZw e$d[          Zx e$d\          Zy e$d]d           \  ZzZ{ e$d^          Z| e$d_          Z} e$d`          Z~ e$da          Z e$db          Z e$dc          Z e$dd          Z e$de          Z e$dfd           \  ZZ e$dg          Z e$dhd           \  ZZ e$di          Z e$dj          Z e$dk          ZdlZdZe,e'v re+e%vr e$dmd           \  ZZne!                    dn           dZdlZdZe/e%v rdZne+e'v re,e%vrej;        <                    do          duZer>dpZdZeD ]3Z	 ejK                            e          Z n# ejK        jN        $ r Y 0w xY weduZer= ej0        e           ej0        dq          k     re!                    dre ds           dZne!                    dt           ej;        <                    du          duZ	 ejK                            du          Ze!M                    dve            n# ejK        jN        $ r dZY nw xY wej;        <                    dw          duZ	 ejK                            dw          Ze!M                    dxe            n# ejK        jN        $ r dZY nw xY wdlZej;        <                    dy          dupej;        <                    dz          duZ	 ejK                            d{          Ze!M                    d|e            n# ejK        jN        $ r dZY nw xY wdZe-e'v rI e$d}d           \  ZZer7 e$d~d           \  ZZere!                    de de d           ndxZZdlxZZdZer. ej0        e          Zej        ej        fe1j        e1j        fk    ZdZe.e%v r+ e$dd           \  ZZere!                    de d           d Zd Zd Ze2fde"fdZd Ze6fde"fdZd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd ZdRdee"         fdZd Zd Zd Z e            d             Z e            d             Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z e            dSd            ZedTd            Z e            dSd            Z e            dQd            Z e            dQd            Z e            dQd            Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd ZdÄ ZedQdĄ            Z e            dń             Zde#fdƄZdǄ ZdȄ Z e            de"fdʄ            Zd˄ Zd̄ Zd̈́ Zd΄ Zdτ ZdЄ Ze4fde"fdфZd҄ Ze3fde"fdӄZdԄ ZdՄ Zdք Zdׄ Zd؄ Zdل Zdڄ Zdۄ Zd܄ Zd݄ Zdބ Zd߄ Zed             Zd Zd Zd Z d Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd  Zd ZdZdZ dZ!dZ"dZ#dZ$dZ%d	Z&d
Z'dZ(dZ)dZ*dZ+dZ,dZ-dZ.dZ/dZ0dZ1dZ2dZ3dZ4dZ5dZ6dZ7dZ8dZ9dZ:dZ;dZ<d Z=d!Z>d"Z?d#Z@d$ZAd%ZBd&ZCd'ZDd(ZEd)ZFd*ZGd+ZHd,ZId-ZJd.ZK eg d#eߐeffd+eĐe*ffd-ee ffd.eאe!ffd/eؐe-ffdueeEffd0ee%ffd}eʐe.ffd3eːe/ffd4e̐e1ffdFee6ffdHee7ffdIee8ffdweeGffd/ee0ffd;eeFffd0ee$ffdLeeBffdNeeAffdReܐe9ffdPee2ffdUee#ffdXee+ffd1ee;ffd^ee3ffd2eŐe,ffd_ee4ffdaee<ffdcee5ffd<ee=ffd=ee?ffdbee"ffdmee&ffdfee'ffd3ee@ffdTee:ffdeeCffd{eeDffd4eeHffd6eeIffdGeÐeJffd5eeKff          ZLd6 ZM G d7 d8eN          ZOd9 ZPee"         ZQeeQee"ee"         f         f         ZR G d: d;e          ZS G d< d=eT          ZUdUd?e"defd@ZVdAdBdCZWdD dEdF dGdH dIdJ dKiZXdL ZY e            dM             ZZdN Z[dOe"deRfdPZ\dS (V  zD
Import utilities: Utilities related to imports and our lazy inits.
    N)OrderedDict)	lru_cache)chain)
ModuleType)AnyDict	FrozenSetOptionalSetTupleUnion)version   )loggingFpkg_namereturn_versionreturnc                    t           j                            |           d u}d}|r	 t           j                            |           }nf# t           j        j        $ rO | dk    rD	 t          j        |           }t          |dd          }d|v r|}d}nd}n# t          $ r d}Y nw xY wd}Y nw xY wt          
                    d|  d|            |r||fS |S )	NN/Atorch__version__devTFz	Detected z
 version: )	importlibutil	find_specmetadatar   PackageNotFoundErrorimport_modulegetattrImportErrorloggerdebug)r   r   package_existspackage_versionpackagetemp_versions         [/var/www/html/ai-engine/env/lib/python3.11/site-packages/transformers/utils/import_utils.py_is_package_availabler(   *   s!   ^--h77tCNO H	''088BBOO!6 	' 	' 	'7""+'5h??G#*7M5#I#IL,,*6)-)." + + +%*NNN+
 "'#	'$ 	FFF_FFGGG ..s5   A B*"0BB*B"B*!B""B*)B*>   1ONYESTRUEAUTOUSE_TF	USE_TORCHUSE_FLAXUSE_TORCH_XLAr)   FORCE_TF_AVAILABLEz1.10z0.26.0z1.12.0z0.10.0z2.2.0z0.2.1
accelerateT)r   apexaqlmavbitsandbyteseetq
fbgemm_gpugalore_torch
lomo_optim	grokadamwschedulefreebs4coloredlogscv2datasets
detectron2faissz$Successfully imported faiss version z	faiss-cpuftfyg2p_enintel_extension_for_pytorchjiebajinja2kenlm	keras_nlpLevenshteinlibrosanattennltkonnxopenaioptimum	auto_gptqawqquantooptimum_quantocompressed_tensorspandaspeft
phonemizeruromanpsutilpy3nvmlpyctcdecodepygmentspytesseractpytestpytorch_quantizationrjieba
sacremosessafetensorsscipysentencepieceseqioggufsklearnzscikit-learnsmdistributed	soundfilespacy	sudachipytensorflow_probabilitytensorflow_texttf2onnxtimm
tokenizers
torchaudiotorchao
torchdistxtorchvisionmlxhqqtiktokenblobfileliger_kernelr   r   z'Disabling PyTorch because USE_TF is set
tensorflow)r|   ztensorflow-cpuztensorflow-gpuz
tf-nightlyztf-nightly-cpuztf-nightly-gpuztf-nightly-rocmzintel-tensorflowzintel-tensorflow-avx512ztensorflow-rocmztensorflow-macosztensorflow-aarch642z"TensorFlow found but with version z*. Transformers requires version 2 minimum.z-Disabling Tensorflow because USE_TORCH is setessentiaz'Successfully imported essentia version pretty_midiz*Successfully imported pretty_midi version 	torch_ccloneccl_bindings_for_pytorchoneccl_bind_ptz Detected oneccl_bind_pt version flaxjaxzJAX version z, Flax version z available.	torch_xlazTorch XLA version c                      t           S N)_kenlm_available     r'   is_kenlm_availabler   1      r   c                      t           S r   )_cv2_availabler   r   r'   is_cv2_availabler   5      r   c                      t           S r   )_torch_availabler   r   r'   is_torch_availabler   9  r   r   min_versionc                 n    t           o.t          j        t                    t          j        |           k    S r   )_accelerate_availabler   parse_accelerate_versionr   s    r'   is_accelerate_availabler   =  s(     eW]3F%G%G7=YdKeKe%eer   c                  B    ddl } |                                 dk    rdS dS )z
    Check whether pytorch uses deterministic algorithms by looking if torch.set_deterministic_debug_mode() is set to 1 or 2"
    r   NFT)r   get_deterministic_debug_moder   s    r'   is_torch_deterministicr   A  s.     LLL))++q00utr   c                 n    t           o.t          j        t                    t          j        |           k    S r   )_hqq_availabler   r   _hqq_versionr   s    r'   is_hqq_availabler   M  s&    WgmL99W];=W=WWWr   c                      t           S r   )_pygments_availabler   r   r'   is_pygments_availabler   Q      r   c                      t           S r   )_torch_versionr   r   r'   get_torch_versionr   U  r   r   c                     t                      sdS t          dk    rdS t                      r/t          j        t                    t          j        d          k    S t          j        t                    t          j        d          k    S )NFr   2.1.0z2.1.1)r   r   is_torch_mlu_availabler   r   r   r   r'   is_torch_sdpa_availabler   Y  st     u	5	 	 u  G}^,,g0F0FFF=((GM',B,BBBr   c                      t           S r   )_torchvision_availabler   r   r'   is_torchvision_availabler   i      !!r   c                      t                      sdS t          j        t                    t          j        d          k    S )NFz0.15)r   r   r   _torchvision_versionr   r   r'   is_torchvision_v2_availabler   m  s7    #%% u =-..'-2G2GGGr   c                      t           S r   )_galore_torch_availabler   r   r'   is_galore_torch_availabler   u      ""r   c                      t           S r   )_lomo_availabler   r   r'   is_lomo_availabler   y      r   c                      t           S r   )_grokadamw_availabler   r   r'   is_grokadamw_availabler   }      r   c                      t           S r   )_schedulefree_availabler   r   r'   is_schedulefree_availabler     r   r   c                      t           S r   )_pyctcdecode_availabler   r   r'   is_pyctcdecode_availabler     r   r   c                      t           S r   )_librosa_availabler   r   r'   is_librosa_availabler         r   c                      t           S r   )_essentia_availabler   r   r'   is_essentia_availabler     r   r   c                      t           S r   )_pretty_midi_availabler   r   r'   is_pretty_midi_availabler     r   r   c                  \    t                      rdd l} | j                                        S dS Nr   F)r   r   cudais_availabler   s    r'   is_torch_cuda_availabler     s2     z&&(((ur   c                  ~    t                      r.dd l} | j                                        sdS t	          d          S dS )Nr   F	mamba_ssmr   r   r   r   r(   r   s    r'   is_mamba_ssm_availabler     sG     6z&&(( 	65(5555r   c                      t                      rcdd l} | j                                        sdS t	          d          r5dd l}t          j        |j                  t          j        d          k    rdS dS )Nr   Fr   2.0.4T)	r   r   r   r   r(   r   r   r   r   )r   r   s     r'   is_mamba_2_ssm_availabler     s|     
 z&&(( 	 5$[11      =!6777=;Q;QQQ45r   c                  ~    t                      r.dd l} | j                                        sdS t	          d          S dS )Nr   Fcausal_conv1dr   r   s    r'   is_causal_conv1d_availabler     sG     6z&&(( 	5$_5555r   c                  @    t                      rt          d          S dS )NmambapyF)r   r(   r   r   r'   is_mambapy_availabler     s#     0$Y///5r   c                 :   t                      rdd l}t          |j        d          rs|j        j                                        o|j        j                                        }| 3t          j        t                    t          j        |           k    }|o|}|S dS )Nr   mpsF)
r   r   hasattrbackendsr   r   is_builtr   r   r   )r   r   backend_availableflags       r'   is_torch_mps_availabler     s     %5>5)) 	% % 2 ? ? A A cenFXFaFaFcFc&}^44k8R8RR$5$>$!$$5r   c                      t                      sdS dd l} | j                                        o| j                                        S NFr   )r   r   r   r   is_bf16_supportedr   s    r'   is_torch_bf16_gpu_availabler     sE     uLLL:""$$G)E)E)G)GGr   c                  v    t                      sdS dd l} 	 | j        j        j        }n# t
          $ r Y dS w xY wdS )NFr   T)r   r   cpuampautocastAttributeError)r   _s     r'   is_torch_bf16_cpu_availabler     sZ     uLLLIM"   uu 4s   ( 
66c                  R    t          j        dt                     t                      S )NzThe util is_torch_bf16_available is deprecated, please use is_torch_bf16_gpu_available or is_torch_bf16_cpu_available instead according to whether it's used with cpu or gpu)warningswarnFutureWarningr   r   r   r'   is_torch_bf16_availabler     s/     M	`  
 '(((r   c                 P   t                      sdS dd l}	 |                    dd|j                                      |           }||z  }d\  }}}|                    ||||j        |           }|j                            ||j        |           } ||          }n#  Y dS xY wdS )NFr      dtype)         )r   deviceT)r   r   zerosfloat16torandnnn	LayerNorm)	r  r   xr   batchsentence_lengthembedding_dim	embedding
layer_norms	            r'   !is_torch_fp16_available_on_devicer    s     uLLLKK1EMK2255f==E 18-KKU]ciKjj	X''U]SY'ZZ
Jy!! uu4s   BB B#c                     t                      sdS dd l}| dk    rt                      S 	 |                    dd|j                                      |           }||z  }n#  Y dS xY wdS )NFr   r   r   r   T)r   r   r   r  bfloat16r  )r  r   r	  r   s       r'   !is_torch_bf16_available_on_devicer    s     uLLL*,,,KK1ENK3366v>>E uu4s   5A   A%c                     t                      sdS dd l} | j                                        r| j        j        dS | j                            | j                                                  j        dk     rdS t          | j        j        	                    d          d                   dk     rdS t	          j
        t	          j
        | j                  j                  t	          j
        d          k     rdS dS )NFr      .   z1.7T)r   r   r   r   r   get_device_propertiescurrent_devicemajorintsplitr   r   base_versionr   s    r'   is_torch_tf32_availabler  '  s     uLLL:""$$ (:(Buz''
(A(A(C(CDDJQNNu
5=##C((+,,r11u}W]5#455BCCgmTYFZFZZZu4r   c                      t           S r   )_torch_fx_availabler   r   r'   is_torch_fx_availabler   9  r   r   c                      t           S r   )_peft_availabler   r   r'   is_peft_availabler#  =  r   r   c                      t           S r   )_bs4_availabler   r   r'   is_bs4_availabler&  A  r   r   c                      t           S r   )_tf_availabler   r   r'   is_tf_availabler)  E      r   c                      t           S r   )_coloredlogs_availabler   r   r'   is_coloredlogs_availabler-  I  r   r   c                      t           S r   )_tf2onnx_availabler   r   r'   is_tf2onnx_availabler0  M  r   r   c                      t           S r   )_onnx_availabler   r   r'   is_onnx_availabler3  Q  r   r   c                      t           S r   )_openai_availabler   r   r'   is_openai_availabler6  U      r   c                      t           S r   )_flax_availabler   r   r'   is_flax_availabler:  Y  r   r   c                      t           S r   )_ftfy_availabler   r   r'   is_ftfy_availabler=  ]  r   r   c                      t           S r   )_g2p_en_availabler   r   r'   is_g2p_en_availabler@  a  r7  r   c                     t          j        dt                     t          sdS t          j                            d          5| r1	 ddlmc m	} |
                                }dS # t          $ r Y dS w xY wdS dS )zQChecks if `torch_xla` is installed and potentially if a TPU is in the environmentzv`is_torch_tpu_available` is deprecated and will be removed in 4.41.0. Please use the `is_torch_xla_available` instead.Fr   Nr   T)r   r   r   r   r   r   r   torch_xla.core.xla_modelcore	xla_model
xla_deviceRuntimeError)check_devicexmr   s      r'   is_torch_tpu_availablerI  e  s     M	;    u~,,8 	555555555MMOOt   uut5s   A% %
A32A3c                     | r|r
J d            t           sdS ddl}|r|j                                        dv S | r|j                                        dk    S dS )z
    Check if `torch_xla` is available. To train a native pytorch job in an environment with torch xla installed, set
    the USE_TORCH_XLA to false.
    z6The check_is_tpu and check_is_gpu cannot both be true.Fr   N)GPUCUDATPUT)_torch_xla_availabler   runtimedevice_type)check_is_tpucheck_is_gpur   s      r'   is_torch_xla_availablerS  ~  s     hhh0hhhh u 8 ,,../AA	 8 ,,..%774r   c                 `    t           j                            d          t                      S dS )Ntorch_neuronxF)r   r   r   rS  )rG  s    r'   is_torch_neuroncore_availablerV    s)    ~00<%'''5r   c                 @   t           rt          j                            d          dS ddl}ddl}| rD	 |j                                        }|j                                        S # t          $ r Y dS w xY wt          |d          o|j                                        S )zQChecks if `torch_npu` is installed and potentially if a NPU is in the environment	torch_npuNFr   npu)r   r   r   r   r   rX  rY  device_countr   rF  r   )rG  r   rX  r   s       r'   is_torch_npu_availabler[    s      y~77DDLuLLL 		&&((A9))+++ 	 	 	55	5%  =UY%;%;%=%==s   1A& &
A43A4c                 V   t           rt          j                            d          dS ddl}ddl}ddlm} d|d<   | rD	 |j        	                                }|j        
                                S # t          $ r Y dS w xY wt          |d	          o|j        
                                S )
zQChecks if `torch_mlu` is installed and potentially if a MLU is in the environment	torch_mluNFr   r   )depszdeepspeed-mlu>=0.10.1	deepspeedmlu)r   r   r   r   r   r]  dependency_versions_tabler^  r`  rZ  r   rF  r   )rG  r   r]  r^  r   s        r'   r   r     s      y~77DDLuLLL000000/D 		&&((A9))+++ 	 	 	55	5%  =UY%;%;%=%==s   1A1 1
A?>A?c                    t           rt          j                            d          dS ddl}ddl}d}t          r1t          j        t                    t          j        |          k     rdS | rD	 |j
                                        }|j
                                        S # t          $ r Y dS w xY wt          |d          o|j
                                        S )zSChecks if `torch_musa` is installed and potentially if a MUSA is in the environment
torch_musaNFr   z0.33.0musa)r   r   r   r   r   rc  r   r   r   r   rd  rZ  r   rF  r   )rG  r   rc  torch_musa_min_versionr   s        r'   is_torch_musa_availablerf    s      y~77EEMuLLL% /B!C!CgmTjFkFk!k!ku 	
''))A:**,,, 	 	 	55	5&!!?ej&=&=&?&??s   .1B   
B.-B.c                      t                      sdS t          j        t                    t          j        d          k    S )NFz2.0.0r   r   r   r   r   r   r'   is_torchdynamo_availableri    s4     u=((GM',B,BBBr   c                  J    t                      sdS dd l} t          | d          S )NFr   compile)r   r   r   r   s    r'   is_torch_compile_availablerl    s0     uLLL 5)$$$r   c                      t                      sdS 	 dd l} | j                                        S # t          $ r0 	 dd lm} |                                cY S # t          $ r Y Y dS w xY ww xY wr   )r   r   compileris_compiling	Exceptiontorch._dynamo_dynamo)r   dynamos     r'   is_torchdynamo_compilingrt    s     u
~**,,,   	******&&((((( 	 	 	555	s,   / 
A)AA)
A% A)$A%%A)c                      t           j                            d          dS t           j                            d          d uS )Ntorch_tensorrtFztorch_tensorrt.fxr   r   r   r   r   r'   is_torch_tensorrt_fx_availablerx     s:    ~ 0119u>##$788DDr   c                      t           S r   )_datasets_availabler   r   r'   is_datasets_availabler{    r   r   c                      t           S r   )_detectron2_availabler   r   r'   is_detectron2_availabler~  
        r   c                      t           S r   )_rjieba_availabler   r   r'   is_rjieba_availabler    r7  r   c                      t           S r   )_psutil_availabler   r   r'   is_psutil_availabler    r7  r   c                      t           S r   )_py3nvml_availabler   r   r'   is_py3nvml_availabler    r   r   c                      t           S r   )_sacremoses_availabler   r   r'   is_sacremoses_availabler    r  r   c                      t           S r   )_apex_availabler   r   r'   is_apex_availabler    r   r   c                      t           S r   )_aqlm_availabler   r   r'   is_aqlm_availabler  "  r   r   c                      t           S r   )_av_availabler   r   r'   is_av_availabler  &  r*  r   c                  v    	 t          j        d                                           dS # t          $ r Y dS w xY w)z
    Code comes from *torch.utils.cpp_extension.is_ninja_available()*. Returns `True` if the
    [ninja](https://ninja-build.org/) build system is available on the system, `False` otherwise.
    zninja --versionTF)
subprocesscheck_outputr  rp  r   r   r'   is_ninja_availabler  *  sP    
 1 7 7 9 9::: t    uus   &* 
88c            	          d } t                      rt          sdS  | t                    } | t                    }||k    r+t                              d| d| dt           d           dS dS )Nc                     t          t          j        |           j                  dz   t          t          j        |           j                  z   S Nr  )strr   r   r  minor)full_versions    r'    get_major_and_minor_from_versionz;is_ipex_available.<locals>.get_major_and_minor_from_version8  s=    7=..455;c'-P\B]B]Bc>d>dddr   FzIntel Extension for PyTorch z needs to work with PyTorch z.*, but PyTorch z? is found. Please switch to the matching version and run again.T)r   _ipex_availabler   _ipex_versionr!   warning)r  torch_major_and_minoripex_major_and_minors      r'   is_ipex_availabler  7  s    e e e   u<<^LL;;MJJ 444l+? l l]q l l*l l l	
 	
 	
 u4r   c                    t                      sdS t          j        t                    }t	                      rddl}n#|j        dk     s|j        dk    r|j        dk     rdS ddl}| rD	 |j	        
                                }|j	                                        S # t          $ r Y dS w xY wt          |d          o|j	                                        S )z
    Checks if XPU acceleration is available either via `intel_extension_for_pytorch` or
    via stock PyTorch (>=2.4) and potentially if a XPU is in the environment
    Fr   Nr   r   xpu)r   r   r   r   r  rF   r  r  r   r  rZ  r   rF  r   )rG  torch_versionrF   r   r   s        r'   is_torch_xpu_availabler  I  s      uM.11M *****		q	 	 ]%8A%=%=-BUXYBYBYuLLL 		&&((A9))+++ 	 	 	55	5%  =UY%;%;%=%==s   '1B 
B'&B'c                      t                      rt          sdS dd l} t          j        t
          j                            d                    t          j        d          k     r| j                                        S dS )NFr   r7   z0.43.1T)	r   _bitsandbytes_availabler   r   r   r   r   r   r   r   s    r'   is_bitsandbytes_availabler  d  st     '> uLLL }Y'//??@@7=QYCZCZZZz&&((( 4r   c                  h    t                      sdS dd l} dt          | dt                                v S )NFr   multi_backendfeatures)r  r7   r   set)bnbs    r'   'is_bitsandbytes_multi_backend_availabler  t  s<    $&& ugc:suu====r   c                     t                      sdS t          d          sdS dd l} | j                                        st                      sdS | j        j        rGt          j        t          j	                            d                    t          j        d          k    S | j        j
        rGt          j        t          j	                            d                    t          j        d          k    S t                      rGt          j        t          j	                            d                    t          j        d          k    S dS )NF
flash_attnr   r   r   z2.3.3)r   r(   r   r   r   r   r   r   r   r   hipr   s    r'   is_flash_attn_2_availabler  }  s    u .. u LLLJ##%% )?)A)A u} }Y/77EEFF'-X_J`J```		 }Y/77EEFF'-X_J`J```		!	! }Y/77EEFF'-X_J`J```ur   c                      t          d          sdS t          j        t          j                            d                    t          j        d          k    S )Nr  Fr   r(   r   r   r   r   r   r   r'   #is_flash_attn_greater_or_equal_2_10r    sH     .. u=+33LAABBgmT[F\F\\\r   library_versionc                     t          d          sdS t          j        t          j                            d                    t          j        |           k    S )Nr  Fr  )r  s    r'   is_flash_attn_greater_or_equalr    sH     .. u=+33LAABBgmTcFdFdddr   c                      t           S r   )_torchdistx_availabler   r   r'   is_torchdistx_availabler    r  r   c                      t           S r   )_faiss_availabler   r   r'   is_faiss_availabler    r   r   c                      t           S r   )_scipy_availabler   r   r'   is_scipy_availabler    r   r   c                      t           S r   )_sklearn_availabler   r   r'   is_sklearn_availabler    r   r   c                      t           S r   )_sentencepiece_availabler   r   r'   is_sentencepiece_availabler    s    ##r   c                      t           S r   )_is_seqio_availabler   r   r'   is_seqio_availabler    r   r   c                 n    t           o.t          j        t                    t          j        |           k    S r   )_is_gguf_availabler   r   _gguf_versionr   s    r'   is_gguf_availabler    s'    \'-">">'-P[B\B\"\\r   c                      t           j                            d          dS t           j                            d          d uS )NgoogleFzgoogle.protobufrw  r   r   r'   is_protobuf_availabler    s9    ~))1u>##$566dBBr   c                 |    t                      o.t          j        t                    t          j        |           k    S r   rh  r   s    r'   is_fsdp_availabler    s-    _GM.$A$AW]S^E_E_$__r   c                      t           S r   )_optimum_availabler   r   r'   is_optimum_availabler    r   r   c                      t           S r   )_auto_awq_availabler   r   r'   is_auto_awq_availabler    r   r   c                  D    t                               d           t          S )NzuImporting from quanto will be deprecated in v4.47. Please install optimum-quanto instrad `pip install optimum-quanto`)r!   warning_once_quanto_availabler   r   r'   is_quanto_availabler    s%    
   r   c                      t           S r   )_is_optimum_quanto_availabler   r   r'   is_optimum_quanto_availabler    s    ''r   c                      t           S r   )_compressed_tensors_availabler   r   r'   is_compressed_tensors_availabler    s    ((r   c                      t           S r   )_auto_gptq_availabler   r   r'   is_auto_gptq_availabler    r   r   c                      t           S r   )_eetq_availabler   r   r'   is_eetq_availabler    r   r   c                      t           S r   )_fbgemm_gpu_availabler   r   r'   is_fbgemm_gpu_availabler    r  r   c                      t           S r   )_levenshtein_availabler   r   r'   is_levenshtein_availabler    r   r   c                  .    t           ot          d          S )Nzoptimum.neuron)r  r(   r   r   r'   is_optimum_neuron_availabler    s    I"78H"I"IIr   c                      t           S r   )_safetensors_availabler   r   r'   is_safetensors_availabler    r   r   c                      t           S r   )_tokenizers_availabler   r   r'   is_tokenizers_availabler    r  r   c                  v   t           j                            d          d u} | r	 t           j                            d          }nW# t           j        j        $ r@ 	 t           j                            d          }n# t           j        j        $ r Y Y dS w xY wY nw xY wt                              d|            | S )NPILPillowzPillow-SIMDFzDetected PIL version )r   r   r   r   r   r   r!   r"   )_pil_availabler$   s     r'   is_vision_availabler     s    ^--e44D@N @	'088BBOO!6 	 	 	"+"4"<"<]"K"K%:   uuu  	
 	>_>>???s5   A BA:9B:BBBBBc                      t           S r   )_pytesseract_availabler   r   r'   is_pytesseract_availabler    r   r   c                      t           S r   )_pytest_availabler   r   r'   is_pytest_availabler    r7  r   c                      t           S r   )_spacy_availabler   r   r'   is_spacy_availabler	    r   r   c                  ,    t                      ot          S r   )r)  _tensorflow_text_availabler   r   r'   is_tensorflow_text_availabler    s    ;!;;r   c                  ,    t                      ot          S r   )r  _keras_nlp_availabler   r   r'   is_keras_nlp_availabler    s    '))B.BBr   c                     	 t           j        d         j        } d |             j        vrt	          d          dt
          j        v rt	          d          dt
          j        v r%t
          j        d         dk     rt	          d          t          j        	                    d          d uS # t          t          t          f$ r Y d	S w xY w)
NIPythonIPKernelAppconsole
VSCODE_PIDvscodeDATABRICKS_RUNTIME_VERSIONz11.0
databricksF)sysmodulesget_ipythonconfigr    osenvironr   r   r   r   KeyError)r  s    r'   is_in_notebookr  !  s    k),8 444i(((2:%%h''''2:55"*Ea:bek:k:k l+++~''	22$>>K2   uus   B'B* *CCc                      t           S r   )_pytorch_quantization_availabler   r   r'   !is_pytorch_quantization_availabler"  3  s    **r   c                      t           S r   )!_tensorflow_probability_availabler   r   r'   #is_tensorflow_probability_availabler%  7  s    ,,r   c                      t           S r   )_pandas_availabler   r   r'   is_pandas_availabler(  ;  r7  r   c                      t          j        dd          } 	 t          j        |           } |                     dd          sdS n# t          j        $ r Y dS w xY wt          S )NSM_FRAMEWORK_PARAMS{}*sagemaker_distributed_dataparallel_enabledF)r  getenvjsonloadsgetJSONDecodeError_smdistributed_available)sagemaker_paramss    r'   is_sagemaker_dp_enabledr4  ?  s|    y!6==:&677##$PRWXX 	5	   uu $#s   *A AAc                  P   t          j        dd          } 	 t          j        |           } d| vrdS n# t          j        $ r Y dS w xY wt          j        dd          }	 t          j        |          }|                    dd          sdS n# t          j        $ r Y dS w xY wt          S )NSM_HP_MP_PARAMETERSr+  
partitionsFr*  sagemaker_mpi_enabled)r  r-  r.  r/  r1  r0  r2  )smp_optionsmpi_optionss     r'   is_sagemaker_mp_enabledr;  M  s    )1488Kj--{**5 +   uu )1488Kj--6>> 	5	   uu $#s!   2 AA*B BBc                      dt           j        v S )NSAGEMAKER_JOB_NAME)r  r  r   r   r'   is_training_run_on_sagemakerr>  e  s    2:--r   c                      t           S r   )_soundfile_availabler   r   r'   is_soundfile_availblerA  i  r   r   c                      t           S r   )_timm_availabler   r   r'   is_timm_availablerD  m  r   r   c                      t           S r   )_natten_availabler   r   r'   is_natten_availablerG  q  r7  r   c                      t           S r   )_nltk_availabler   r   r'   is_nltk_availablerJ  u  r   r   c                      t           S r   _torchaudio_availabler   r   r'   is_torchaudio_availablerN  y  r  r   c                      t           S r   )_torchao_availabler   r   r'   is_torchao_availablerQ  }  r   r   c                      t           S r   rL  r   r   r'   is_speech_availablerS    s      r   c                      t           S r   )_phonemizer_availabler   r   r'   is_phonemizer_availablerV    r  r   c                      t           S r   )_uroman_availabler   r   r'   is_uroman_availablerY    r7  r   c                       fd}|S )Nc                  @    t           st          d           | i |S )Nz|You need to install pytorch to use this method or class, or activate it with environment variables USE_TORCH=1 and USE_TF=0.)r   r    )argskwargsfns     r'   wrapperz"torch_only_method.<locals>.wrapper  s:     	'V  
 2t&v&&&r   r   )r^  r_  s   ` r'   torch_only_methodr`    s#    ' ' ' ' ' Nr   c                      t           S r   )_is_ccl_availabler   r   r'   is_ccl_availablerc    r7  r   c                      t           S r   )_sudachipy_availabler   r   r'   is_sudachi_availablerf    r   r   c                      t           S r   )_sudachipy_versionr   r   r'   get_sudachi_versionri    r   r   c                      t                      sdS t          j        t                    t          j        d          k    S )NFz0.6.8)rf  r   r   rh  r   r   r'   is_sudachi_projection_availablerk    s7    !! u =+,,g0F0FFFr   c                  p    t           j                            d          d uot          j        d          d uS )Nrhoknpjumanpp)r   r   r   shutilwhichr   r   r'   is_jumanpp_availablerq    s2    N$$X..d:eiAXAX`dAder   c                  D    t           j                            d          d uS )N	pyximportrw  r   r   r'   is_cython_availablert    s    >##K00<<r   c                      t           S r   )_jieba_availabler   r   r'   is_jieba_availablerw    r   r   c                      t           S r   )_jinja_availabler   r   r'   is_jinja_availablerz    r   r   c                      t           S r   )_mlx_availabler   r   r'   is_mlx_availabler}    r   r   c                      t           ot          S r   )_tiktoken_available_blobfile_availabler   r   r'   is_tiktoken_availabler    s    6#66r   c                      t           sdS t          j        t          j                            d                    t          j        d          k    S )NFr{   z0.3.0)_liger_kernel_availabler   r   r   r   r   r   r'   is_liger_kernel_availabler    s@    " u=+33NCCDDV]H^H^^^r   z
{0} requires the PyAv library but it was not found in your environment. You can install it with:
```
pip install av
```
Please note that you may need to restart your runtime after installation.
z
{0} requires the OpenCV library but it was not found in your environment. You can install it with:
```
pip install opencv-python
```
Please note that you may need to restart your runtime after installation.
ub  
{0} requires the 🤗 Datasets library but it was not found in your environment. You can install it with:
```
pip install datasets
```
In a notebook or a colab, you can install it by executing a cell with
```
!pip install datasets
```
then restarting your kernel.

Note that if you have a local folder named `datasets` or a local python file named `datasets.py` in your current
working directory, python may try to import this instead of the 🤗 Datasets library. You should rename this folder or
that python file if that's the case. Please note that you may need to restart your runtime after installation.
u<  
{0} requires the 🤗 Tokenizers library but it was not found in your environment. You can install it with:
```
pip install tokenizers
```
In a notebook or a colab, you can install it by executing a cell with
```
!pip install tokenizers
```
Please note that you may need to restart your runtime after installation.
aB  
{0} requires the SentencePiece library but it was not found in your environment. Checkout the instructions on the
installation page of its repo: https://github.com/google/sentencepiece#installation and follow the ones
that match your environment. Please note that you may need to restart your runtime after installation.
aT  
{0} requires the protobuf library but it was not found in your environment. Checkout the instructions on the
installation page of its repo: https://github.com/protocolbuffers/protobuf/tree/master/python#installation and follow the ones
that match your environment. Please note that you may need to restart your runtime after installation.
aF  
{0} requires the faiss library but it was not found in your environment. Checkout the instructions on the
installation page of its repo: https://github.com/facebookresearch/faiss/blob/master/INSTALL.md and follow the ones
that match your environment. Please note that you may need to restart your runtime after installation.
a$  
{0} requires the PyTorch library but it was not found in your environment. Checkout the instructions on the
installation page: https://pytorch.org/get-started/locally/ and follow the ones that match your environment.
Please note that you may need to restart your runtime after installation.
a(  
{0} requires the Torchvision library but it was not found in your environment. Checkout the instructions on the
installation page: https://pytorch.org/get-started/locally/ and follow the ones that match your environment.
Please note that you may need to restart your runtime after installation.
a  
{0} requires the PyTorch library but it was not found in your environment.
However, we were able to find a TensorFlow installation. TensorFlow classes begin
with "TF", but are otherwise identically named to our PyTorch classes. This
means that the TF equivalent of the class you tried to import would be "TF{0}".
If you want to use TensorFlow, please use TF classes instead!

If you really do want to use PyTorch please go to
https://pytorch.org/get-started/locally/ and follow the instructions that
match your environment.
a  
{0} requires the TensorFlow library but it was not found in your environment.
However, we were able to find a PyTorch installation. PyTorch classes do not begin
with "TF", but are otherwise identically named to our TF classes.
If you want to use PyTorch, please use those classes instead!

If you really do want to use TensorFlow, please follow the instructions on the
installation page https://www.tensorflow.org/install that match your environment.
z
{0} requires the Beautiful Soup library but it was not found in your environment. You can install it with pip:
`pip install beautifulsoup4`. Please note that you may need to restart your runtime after installation.
aC  
{0} requires the scikit-learn library but it was not found in your environment. You can install it with:
```
pip install -U scikit-learn
```
In a notebook or a colab, you can install it by executing a cell with
```
!pip install -U scikit-learn
```
Please note that you may need to restart your runtime after installation.
a!  
{0} requires the TensorFlow library but it was not found in your environment. Checkout the instructions on the
installation page: https://www.tensorflow.org/install and follow the ones that match your environment.
Please note that you may need to restart your runtime after installation.
aD  
{0} requires the detectron2 library but it was not found in your environment. Checkout the instructions on the
installation page: https://github.com/facebookresearch/detectron2/blob/master/INSTALL.md and follow the ones
that match your environment. Please note that you may need to restart your runtime after installation.
a  
{0} requires the FLAX library but it was not found in your environment. Checkout the instructions on the
installation page: https://github.com/google/flax and follow the ones that match your environment.
Please note that you may need to restart your runtime after installation.
a8  
{0} requires the ftfy library but it was not found in your environment. Checkout the instructions on the
installation section: https://github.com/rspeer/python-ftfy/tree/master#installing and follow the ones
that match your environment. Please note that you may need to restart your runtime after installation.
z
{0} requires the python-Levenshtein library but it was not found in your environment. You can install it with pip: `pip
install python-Levenshtein`. Please note that you may need to restart your runtime after installation.
z
{0} requires the g2p-en library but it was not found in your environment. You can install it with pip:
`pip install g2p-en`. Please note that you may need to restart your runtime after installation.
a  
{0} requires the pytorch-quantization library but it was not found in your environment. You can install it with pip:
`pip install pytorch-quantization --extra-index-url https://pypi.ngc.nvidia.com`
Please note that you may need to restart your runtime after installation.
z
{0} requires the tensorflow_probability library but it was not found in your environment. You can install it with pip as
explained here: https://github.com/tensorflow/probability. Please note that you may need to restart your runtime after installation.
a  
{0} requires the tensorflow_text library but it was not found in your environment. You can install it with pip as
explained here: https://www.tensorflow.org/text/guide/tf_text_intro.
Please note that you may need to restart your runtime after installation.
z{
{0} requires the torchaudio library but it was not found in your environment. Please install it and restart your
runtime.
a  
{0} requires the pandas library but it was not found in your environment. You can install it with pip as
explained here: https://pandas.pydata.org/pandas-docs/stable/getting_started/install.html.
Please note that you may need to restart your runtime after installation.
z
{0} requires the phonemizer library but it was not found in your environment. You can install it with pip:
`pip install phonemizer`. Please note that you may need to restart your runtime after installation.
z
{0} requires the uroman library but it was not found in your environment. You can install it with pip:
`pip install uroman`. Please note that you may need to restart your runtime after installation.
z
{0} requires the sacremoses library but it was not found in your environment. You can install it with pip:
`pip install sacremoses`. Please note that you may need to restart your runtime after installation.
z
{0} requires the scipy library but it was not found in your environment. You can install it with pip:
`pip install scipy`. Please note that you may need to restart your runtime after installation.
z
{0} requires the torchaudio library but it was not found in your environment. You can install it with pip:
`pip install torchaudio`. Please note that you may need to restart your runtime after installation.
z
{0} requires the timm library but it was not found in your environment. You can install it with pip:
`pip install timm`. Please note that you may need to restart your runtime after installation.
a"  
{0} requires the natten library but it was not found in your environment. You can install it by referring to:
shi-labs.com/natten . You can also install it with pip (may take longer to build):
`pip install natten`. Please note that you may need to restart your runtime after installation.
z
{0} requires the numexpr library but it was not found in your environment. You can install it by referring to:
https://numexpr.readthedocs.io/en/latest/index.html.
z
{0} requires the NLTK library but it was not found in your environment. You can install it by referring to:
https://www.nltk.org/install.html. Please note that you may need to restart your runtime after installation.
z
{0} requires the PIL library but it was not found in your environment. You can install it with pip:
`pip install pillow`. Please note that you may need to restart your runtime after installation.
z
{0} requires the PyTesseract library but it was not found in your environment. You can install it with pip:
`pip install pytesseract`. Please note that you may need to restart your runtime after installation.
z
{0} requires the pyctcdecode library but it was not found in your environment. You can install it with pip:
`pip install pyctcdecode`. Please note that you may need to restart your runtime after installation.
z
{0} requires the accelerate library >= {ACCELERATE_MIN_VERSION} it was not found in your environment.
You can install or update it with pip: `pip install --upgrade accelerate`. Please note that you may need to restart your
runtime after installation.
a  
{0} requires the torch ccl library but it was not found in your environment. You can install it with pip:
`pip install oneccl_bind_pt -f https://developer.intel.com/ipex-whl-stable`
Please note that you may need to restart your runtime after installation.
z
{0} requires essentia library. But that was not found in your environment. You can install them with pip:
`pip install essentia==2.1b6.dev1034`
Please note that you may need to restart your runtime after installation.
z
{0} requires thes librosa library. But that was not found in your environment. You can install them with pip:
`pip install librosa`
Please note that you may need to restart your runtime after installation.
z
{0} requires thes pretty_midi library. But that was not found in your environment. You can install them with pip:
`pip install pretty_midi`
Please note that you may need to restart your runtime after installation.
z
{0} requires the Cython library but it was not found in your environment. You can install it with pip: `pip install
Cython`. Please note that you may need to restart your runtime after installation.
z
{0} requires the jieba library but it was not found in your environment. You can install it with pip: `pip install
jieba`. Please note that you may need to restart your runtime after installation.
z
{0} requires the peft library but it was not found in your environment. You can install it with pip: `pip install
peft`. Please note that you may need to restart your runtime after installation.
z
{0} requires the jinja library but it was not found in your environment. You can install it with pip: `pip install
jinja2`. Please note that you may need to restart your runtime after installation.
levenshteinprotobufspeechtfvisioncythonjinjac                 4   t          |t          t          f          s|g}t          | d          r| j        n| j        j        d|v rGd|vrCt                      s5t                      r't          t          
                                        d|v rGd|vrCt                      r5t                      s't          t          
                                        d |D             }fd|D             }|r"t          d                    |                    d S )N__name__r   r  c              3   0   K   | ]}t           |         V  d S r   )BACKENDS_MAPPING.0backends     r'   	<genexpr>z$requires_backends.<locals>.<genexpr>d  s(      @@Gw'@@@@@@r   c                 T    g | ]$\  }} |            |                               %S r   )format)r  	availablemsgnames      r'   
<listcomp>z%requires_backends.<locals>.<listcomp>e  s4    OOO>9c99;;OcjjOOOr    )
isinstancelisttupler   r  	__class__r   r)  r    PYTORCH_IMPORT_ERROR_WITH_TFr  TF_IMPORT_ERROR_WITH_PYTORCHjoin)objr   checksfailedr  s       @r'   requires_backendsr  V  s-   hu.. :"3
33O3<<9OD (t833<N<P<P3UdUfUf36==dCCDDD xG8338J8L8L3UdUfUf36==dCCDDD@@x@@@FOOOOVOOOF +"''&//***+ +r   c                   "     e Zd ZdZ fdZ xZS )DummyObjectz
    Metaclass for the dummy objects. Any class inheriting from it will return the ImportError generated by
    `requires_backend` each time a user tries to access any method of that class.
    c                     |                     d          r'|dk    r!t                                          |          S t          | | j                   d S )Nr   _from_config)
startswithsuper__getattribute__r  	_backends)clskeyr  s     r'   r  zDummyObject.__getattribute__p  sQ    >># 	13.#8#877++C000#s}-----r   )r  
__module____qualname____doc__r  __classcell__r  s   @r'   r  r  j  sB         
. . . . . . . . .r   r  c                 ^    t                      rdd l}t          | |j        j                  S dS r   )r   torch.fxr  fxProxy)r	  r   s     r'   is_torch_fx_proxyr  v  s2     -!UX^,,,5r   c                        e Zd ZdZ	 	 ddedededej        j        de	ee
f         f
 fdZ fd	Zded
efdZdefdZd Z xZS )_LazyModulezu
    Module class that surfaces all objects but only performs associated imports when the objects are requested.
    Nr  module_fileimport_structuremodule_specextra_objectsc           
         t                                          |           i | _        t          d |                                D                       rt                      | _        i | _        g | _        i }|	                                D ]\  }}g }	|D ]P}
|
t          vrt          d|
 d| d          t          |
         \  }} |            s|	                    |
           Q| j                            t          |                                                    | _        |	                                D ]o\  }}t          |	          r
|	| j        |<   |D ]%}|| j        |<   t          |	          r
|	| j        |<   &|                    |g                               |           p| j                            t#          |                                          t#          t%          |                                           z              || _        || _        t,          j                            |          g| _        |i n|| _        || _        || _        d S t          |                                          | _        i | _        |	                                D ]\  }}|D ]}|| j        |<   t#          |                                          t#          t%          |                                           z   | _        || _        || _        t,          j                            |          g| _        |i n|| _        || _        || _        d S )Nc              3   @   K   | ]}t          |t                    V  d S r   r  	frozenset)r  r  s     r'   r  z'_LazyModule.__init__.<locals>.<genexpr>  s,      MMcz#y))MMMMMMr   zError: the following backend: 'z' was specified around object z- but isn't specified in the backends mapping.)r  __init___object_missing_backendanykeysr  _modules_class_to_module__all__itemsr  
ValueErrorappendunionlen
setdefaultextendr  r   values__file____spec__r  pathdirname__path___objects_name_import_structure)selfr  r  r  r  r  r  r   modulemissing_backendsr  callableerrorr  r  valuer  s                   r'   r  z_LazyModule.__init__  sk    	')$MM5E5J5J5L5LMMMMM 5	6EEDM$&D!DL "$4$:$:$<$< Y Y &#% ' 9 9G&666( [g  [  [ek  [  [  [   '7w&?OHe#8:: 9(//888 $ 3 3C4F4F G G#)<<>> I IKC+,, M<L4S9!' S S7:-e4/00 SBRD8?%00b99@@HHHH ##D$7$7$ufmmoo?V:W:W$WXXXX'DM'DMW__[99:DM"/"7BB]DMDJ%6D"""   0 5 5 7 788DM$&D!/5577 7 7V# 7 7E36D)%007   0 5 5 7 7884GWG^G^G`G`@a;b;bbDL'DM'DMW__[99:DM"/"7BB]DMDJ%5D"""r   c                     t                                                      }| j        D ]}||vr|                    |           |S r   )r  __dir__r  r  )r  resultattrr  s      r'   r  z_LazyModule.__dir__  sL    "" L 	$ 	$D6!!d###r   r   c                    || j         v r| j         |         S || j                                        v r9| j        |          G fddt                    }||_        | j        |_        |}n|| j                                        v r1|                     | j        |                   }t          ||          }n9|| j
        v r|                     |          }nt          d| j         d|           t          | ||           |S )Nc                       e Zd Z Z fdZdS ),_LazyModule.__getattr__.<locals>.Placeholderc                 (    t          |            d S r   )r  )r  r\  r]  r  s      r'   r  z5_LazyModule.__getattr__.<locals>.Placeholder.__init__  s    %d,<=====r   N)r  r  r  r  r  )r  s   r'   Placeholderr    s3        ,	> > > > > > >r   r  )	metaclasszmodule z has no attribute )r  r  r  r  r  r  r  r  _get_moduler   r  r   setattr)r  r  r  r  r  r  s        @r'   __getattr__z_LazyModule.__getattr__  s9   4=  =&&4/446666#;DA> > > > > > > > > > > $(K %)]K"EET*//1111%%d&;D&ABBFFD))EET]""$$T**EE !R4=!R!RD!R!RSSSdE"""r   module_namec           	          	 t          j        d|z   | j                  S # t          $ r#}t	          d| j         d| d|           |d }~ww xY w)Nr  zFailed to import z@ because of the following error (look up to see its traceback):
)r   r   r  rp  rF  )r  r  es      r'   r  z_LazyModule._get_module  s    	*3+<dmLLL 	 	 	%DM % %K % %!"% %  	s    
AAAc                 8    | j         | j        | j        | j        ffS r   )r  r  r  r  )r  s    r'   
__reduce__z_LazyModule.__reduce__  s    T]D<R STTr   )NN)r  r  r  r  r  IMPORT_STRUCTURE_Tr   	machinery
ModuleSpecr   objectr  r  r   r  r  r  r  r  s   @r'   r  r    s         7;+/@6 @6@6 @6 -	@6
 (3@6 CK(@6 @6 @6 @6 @6 @6F         6s    U U U U U U Ur   r  c                       e Zd ZdZdS )OptionalDependencyNotAvailablezPInternally used error class for signalling an optional dependency was not found.N)r  r  r  r  r   r   r'   r  r    s        ZZZZr   r  __init__.pyr  c                 &   d}t           j                            | |          }t          j                            ||| g          }t          j                            |          }|j                            |           t          j
        |         }|S )zImports transformers directly

    Args:
        path (`str`): The path to the source file
        file (`str`, *optional*): The file to join with the path. Defaults to "__init__.py".

    Returns:
        `ModuleType`: The resulting imported module
    transformers)submodule_search_locations)r  r  r  r   r   spec_from_file_locationmodule_from_specloaderexec_moduler  r  )r  filer  locationspecr  s         r'   direct_transformers_importr    sz     Dw||D$''H>11$^b]c1ddD^,,T22FKF###[FMr   r   )r   c                       D ]}|t           vrt          d|           t           t                    st          d           fd}|S )a  
    This decorator enables two things:
    - Attaching a `__backends` tuple to an object to see what are the necessary backends for it
      to execute correctly without instantiating it
    - The '@export' string is used to dynamically import objects
    zFBackend should be defined in the BACKENDS_MAPPING. Offending backend: zBackends should be a tuple.c                     | _         | S r   )
__backends)funr   s    r'   inner_fnzexport.<locals>.inner_fn"  s    !
r   )r  r  r  r  )r   r  r	  s   `  r'   exportr
    s      q q***ofmooppp + h&& 86777     Or   c                 
    d| v S )Nmodeling_tf_r   r  s    r'   <lambda>r  *  s    n! r   )r  c                 
    d| v S )Nmodeling_flax_r   r  s    r'   r  r  +  s    !# r   )r   c                 
    d| v S )N	modeling_r   r  s    r'   r  r  ,  s    kQ r   r   c                 V    |                      d          o|                     d          S )Ntokenization__fast)r  endswithr  s    r'   r  r  -  s#    all?++C

70C0C r   )rr   c                    d| vrg S |                                  }t          |          D ]\  }}|                    d          r|}||d         }|d                             d          st          d          |d                             d          rQd |d                             d          d                             d	                              d
          D             S g }t          dt          |                    D ]R}||                                         dk    r|c S |	                    ||                             d                     S|S )z
    Returns the content of the __all__ variable in the file content.
    Returns None if not defined, otherwise returns a list of strings.
    r  Nr   z`fetch__all__ accepts a list of lines, with the first line being the __all__ variable declaration]c                 8    g | ]}|                     d           S )z"' strip)r  r  s     r'   r  z fetch__all__.<locals>.<listcomp>H  s$    \\\c		&!!\\\r   =r   z [],z"', )

splitlines	enumerater  r  r  r  r  ranger  r  )file_contentlinesindexlinestart_index_all__all__line_indexs          r'   fetch__all__r(  1  sv    $$	##%%E ''    t??9%% 	 K+,,E8y)) 
n
 
 	

 Qx \\U1X^^C-@-@-C-I-I%-P-P-V-VWZ-[-[\\\\ !&q#e**!5!5 	E 	E&'--//366E"34::7CCDDDDr   c           
      
   i }t           j                            |           r| g }t          j        |           D ]}|dk    rnt           j                            t           j                            | |                    r1t          t           j                            | |                    ||<   vt           j                            t           j                            |                    s|                    |           n?t           j                            |           fdt          j                  D             }d|v r|                    d           d } |d|          r |d|          rd |D             }i }|D ]}|	                    d          st          t           j                            |          d	
          5 }|                                }ddd           n# 1 swxY w Y   |dd         }d}d}	d}
t                                          D ]\  }} ||          r|}
 nt                      }d|v r|                    d          }t!          |          D ]\  }}|                    d          r|                    d          s1d}d|v rId}d|v r|                    d          d                             d          d                             d          d         }t%          t'          d |                    d          D                                 }nd||	dz            v rg }||	|         D ]}d|v r|                    d          d         }d|v sd|v r_d|v r3|                    d |                    d          D                        n(|                    |                    d                     |                                dk    r nt%          |          }nd}t-          ||
z             }||vri ||<   |||         vrt                      ||         |<   |                    d           s|                    d!          sd"}n|                    d           rd#nd$}||d                             d          d                             d%          }||         |                             |           |                    |           |s|}|}	d&|v rpt1          |          D ]`}||vrZt-          |
          }||vri ||<   |||         vrt                      ||         |<   ||         |                             |           ai ||}|S )'a	  
    This method takes the path to a file/a folder and returns the import structure.
    If a file is given, it will return the import structure of the parent folder.

    Import structures are designed to be digestible by `_LazyModule` objects. They are
    created from the __all__ definitions in each files as well as the `@export` decorators
    above methods and objects.

    The import structure allows explicit display of the required backends for a given object.
    These backends are specified in two ways:

    1. Through their `@export`, if they are exported with that decorator. This `@export` decorator
       accepts a `backend` tuple kwarg mentioning which backends are required to run this object.

    2. If an object is defined in a file with "default" backends, it will have, at a minimum, this
       backend specified. The default backends are defined according to the filename:

       - If a file is named like `modeling_*.py`, it will have a `torch` backend
       - If a file is named like `modeling_tf_*.py`, it will have a `tf` backend
       - If a file is named like `modeling_flax_*.py`, it will have a `flax` backend
       - If a file is named like `tokenization_*_fast.py`, it will have a `tokenizers` backend

    Backends serve the purpose of displaying a clear error message to the user in case the backends are not installed.
    Should an object be imported without its required backends being in the environment, any attempt to use the
    object will raise an error mentioning which backend(s) should be added to the environment in order to use
    that object.

    Here's an example of an input import structure at the src.transformers.models level:

    {
        'albert': {
            frozenset(): {
                'configuration_albert': {'AlbertConfig', 'AlbertOnnxConfig'}
            },
            frozenset({'tokenizers'}): {
                'tokenization_albert_fast': {'AlbertTokenizerFast'}
            },
        },
        'align': {
            frozenset(): {
                'configuration_align': {'AlignConfig', 'AlignTextConfig', 'AlignVisionConfig'},
                'processing_align': {'AlignProcessor'}
            },
        },
        'altclip': {
            frozenset(): {
                'configuration_altclip': {'AltCLIPConfig', 'AltCLIPTextConfig', 'AltCLIPVisionConfig'},
                'processing_altclip': {'AltCLIPProcessor'},
            }
        }
    }
    __pycache__c                     g | ]A}t           j                            t           j                            |                    ?|BS r   )r  r  isdirr  )r  f	directorys     r'   r  z5create_import_structure_from_path.<locals>.<listcomp>  sB    nnn!BGMMRTRYR^R^_hjkRlRlDmDmnAnnnr   r  c                 :     t           fd|D                       S )Nc              3       K   | ]}|v V  	d S r   r   )r  r	  	substrings     r'   r  zLcreate_import_structure_from_path.<locals>.find_substring.<locals>.<genexpr>  s'      11a9>111111r   )r  )r1  list_s   ` r'   find_substringz9create_import_structure_from_path.<locals>.find_substring  s&    11115111111r   modular_r  c                     g | ]}d |v|	S )r4  r   )r  r  s     r'   r  z5create_import_structure_from_path.<locals>.<listcomp>  s#    ^^^vZW]E]E]FE]E]E]r   z.pyzutf-8)encodingNr  r   r   z@export
) 	@)Fr   z	backends=r   (r<  c                 <    g | ]}||                     d           S )z'",r  )r  bs     r'   r  z5create_import_structure_from_path.<locals>.<listcomp>  s(    0k0k0kQij0k0k0k0kr   z, r  "'c              3   @   K   | ]}|                     d           V  dS )()"', Nr  r  s     r'   r  z4create_import_structure_from_path.<locals>.<genexpr>  s/      3u3uQXGMM)4L4L3u3u3u3u3u3ur   rC  classdefT   r   :r  )r  r  r,  listdirr  !create_import_structure_from_pathr  r  remover  openreadBASE_FILE_REQUIREMENTSr  r  r  r  r  r  sortedr  r  r  addr(  )module_pathr  adjacent_modulesr-  r3  module_requirementsr  r!  previous_lineprevious_indexbase_requirementsstring_checkrequirementsexported_objectsr"  r#  r$  	skip_linebackends_stringr   backend_liner%  object_name_all_objectr.  s                           @r'   rI  rI  V  ss   l 	w}}[!! o	K(( 	+ 	+AM!!bgmmBGLLa4P4P&Q&Q!&GU`bcHdHd&e&e ##W]]27<<	1#=#=>> + ''***	+ GOOK00	nnnnrz)'<'<nnn
 (((...2 2 2 ~j"233 _{Td8e8e _^^1A^^^' pP pP##E** 	"',,y+66III 	$Q6688L	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ "#2#&
 *@*F*F*H*H 	 	&L,|K(( $0! 55$$ &&t,,E(// G+ G+t ??#899 $//R[B\B\ 
 "	-- %I "]22*7*=*=k*J*J1*M*S*STW*X*XYZ*[*a*abe*f*fgh*i#(0k0k/J_J_`dJeJe0k0k0k)l)l#m#m$ $u^a-?'@@@#%,1.2F,G & &L)\99/;/A/A#/F/Fq/I"l22c\6I6I#'<#7#7$,OO3u3u\h\n\nos\t\t3u3u3u$u$u$u$u$,OOL4F4Fy4Q4Q$R$R$R  ,1133s:: %  ;#(?? $&(4E)EFFH':::8:+H5"*=h*GGGEHUU+H5kB??733 :DOOE<R<R :$(		+/??7+C+C&Jaa&*;<<&8&>&>s&C&CA&F&L&LS&Q&Q+H5kBFF{SSS(,,[999  +$(M%*N $$+L99 P P&666():;;H':::8:+H5"*=h*GGGEHUU+H5kB'1+>BB;OOOB-B1ABs   G11G5	8G5	c                    fddfd	| }t          d          D ]} |          }i }|                                                                D ],\  }}t          |t                    r||=  |          ||<   -|S )a  
    This method takes as input an unordered import structure and brings the required backends at the top-level,
    aggregating modules and objects under their required backends.

    Here's an example of an input import structure at the src.transformers.models level:

    {
        'albert': {
            frozenset(): {
                'configuration_albert': {'AlbertConfig', 'AlbertOnnxConfig'}
            },
            frozenset({'tokenizers'}): {
                'tokenization_albert_fast': {'AlbertTokenizerFast'}
            },
        },
        'align': {
            frozenset(): {
                'configuration_align': {'AlignConfig', 'AlignTextConfig', 'AlignVisionConfig'},
                'processing_align': {'AlignProcessor'}
            },
        },
        'altclip': {
            frozenset(): {
                'configuration_altclip': {'AltCLIPConfig', 'AltCLIPTextConfig', 'AltCLIPVisionConfig'},
                'processing_altclip': {'AltCLIPProcessor'},
            }
        }
    }

    Here's an example of an output import structure at the src.transformers.models level:

    {
        frozenset({'tokenizers'}): {
            'albert.tokenization_albert_fast': {'AlbertTokenizerFast'}
        },
        frozenset(): {
            'albert.configuration_albert': {'AlbertConfig', 'AlbertOnnxConfig'},
            'align.processing_align': {'AlignProcessor'},
            'align.configuration_align': {'AlignConfig', 'AlignTextConfig', 'AlignVisionConfig'},
            'altclip.configuration_altclip': {'AltCLIPConfig', 'AltCLIPTextConfig', 'AltCLIPVisionConfig'},
            'altclip.processing_altclip': {'AltCLIPProcessor'}
        }
    }

    c                 p   i }|                                  D ]\  }}t          |t                    s|||<    t          d |                                D                       rD|                                 D ].\  }}t          |t
                    r||vri ||<   |||         |<   / |          ||<   |S )Nc              3   @   K   | ]}t          |t                    V  d S r   r  )r  vs     r'   r  zGspread_import_structure.<locals>.propagate_frozenset.<locals>.<genexpr>U  s,      EE!Z9--EEEEEEr   )r  r  dictr  r  r  )unordered_import_structuretuple_first_import_structure_key_valuekra  propagate_frozensets         r'   rh  z4spread_import_structure.<locals>.propagate_frozensetO  s    ')$6<<>> 	Q 	QLD&fd++ Q5;,T22EEv{{}}EEEEE 	Q"LLNN B BDAq!!Y// B$@@@>@8;@A4Q7=	B 6I5H5P5P,T22++r   Nc                 ,   g }|                                  D ]n\  }}|| d| n|}t          |t                    r2|                     ||                                                      W|                    ||f           ot          |          S r  )r  r  rb  r  r  )_dictprevious_keyr  re  rf  flatten_dicts        r'   rl  z-spread_import_structure.<locals>.flatten_dictb  s    !KKMM 	- 	-LD&/;/Gl++T+++TD&$'' -\\&$77==??@@@@dF^,,,,E{{r   rF  r   )r   copyr  r  r  )nested_import_structureordered_import_structureiflattened_import_structurer  r  rl  rh  s         @@r'   spread_import_structurerr     s    ^, , , , ,&       7 1XX Q Q#6#67O#P#P   "$.3355;;== B B
Uc3 	B(--.:l5.A.A&s++%%r   rP  c                 >    t          |           }t          |          S )au  
    This method takes a module_path as input and creates an import structure digestible by a _LazyModule.

    Here's an example of an output import structure at the src.transformers.models level:

    {
        frozenset({'tokenizers'}): {
            'albert.tokenization_albert_fast': {'AlbertTokenizerFast'}
        },
        frozenset(): {
            'albert.configuration_albert': {'AlbertConfig', 'AlbertOnnxConfig'},
            'align.processing_align': {'AlignProcessor'},
            'align.configuration_align': {'AlignConfig', 'AlignTextConfig', 'AlignVisionConfig'},
            'altclip.configuration_altclip': {'AltCLIPConfig', 'AltCLIPTextConfig', 'AltCLIPVisionConfig'},
            'altclip.processing_altclip': {'AltCLIPProcessor'}
        }
    }

    The import structure is a dict defined with frozensets as keys, and dicts of strings to sets of objects.
    )rI  rr  )rP  r  s     r'   define_import_structurert    s!    * 9EE"#3444r   )Fr   )T)FF)r  (]  r  importlib.machineryr   importlib.metadataimportlib.utilr.  r  ro  r  r  r   collectionsr   	functoolsr   	itertoolsr   typesr   typingr   r   r	   r
   r   r   r   	packagingr   r  r   
get_loggerr  r!   r  boolr(   ENV_VARS_TRUE_VALUESr  ENV_VARS_TRUE_AND_AUTO_VALUESr  r0  upperr.   r/   USE_JAXr1   r2   r   TORCH_FX_REQUIRED_VERSIONACCELERATE_MIN_VERSIONFSDP_MIN_VERSIONGGUF_MIN_VERSIONXLA_FSDPV2_MIN_VERSIONHQQ_MIN_VERSIONr   r   r  r  r   r   r  r  r  r  r   r   r   r   r%  r,  r   rz  r}  r  r   _faiss_versionr"   r   r<  r?  r  r  rv  ry  r   r  r  r   rF  rI  r2  r5  r  r  r  r  r  r  r'  r"  rU  rX  r  r  r   r   r  r  r!  r  r  r  r  r  r  r  r  r  r2  r@  r  re  rh  r$  r  r/  rC  r  rM  rP  r  r   r   r|  r   r   r  r  r  r   r   info_tf_versionr(  
candidatespkgr   _essentia_versionr   _pretty_midi_versionccl_versionrb  r9  _flax_version_jax_available_jax_versionr  r  r  r  rN  _torch_xla_versionr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r   r#  r&  r)  r-  r0  r3  r6  r:  r=  r@  rI  rS  rV  r[  r   rf  ri  rl  rt  rx  r{  r~  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r  r  r	  r  r  r  r"  r%  r(  r4  r;  r>  rA  rD  rG  rJ  rN  rQ  rS  rV  rY  r`  rc  rf  ri  rk  rq  rt  rw  rz  r}  r  r  AV_IMPORT_ERRORCV2_IMPORT_ERRORDATASETS_IMPORT_ERRORTOKENIZERS_IMPORT_ERRORSENTENCEPIECE_IMPORT_ERRORPROTOBUF_IMPORT_ERRORFAISS_IMPORT_ERRORPYTORCH_IMPORT_ERRORTORCHVISION_IMPORT_ERRORr  r  BS4_IMPORT_ERRORSKLEARN_IMPORT_ERRORTENSORFLOW_IMPORT_ERRORDETECTRON2_IMPORT_ERRORFLAX_IMPORT_ERRORFTFY_IMPORT_ERRORLEVENSHTEIN_IMPORT_ERRORG2P_EN_IMPORT_ERROR!PYTORCH_QUANTIZATION_IMPORT_ERROR#TENSORFLOW_PROBABILITY_IMPORT_ERRORTENSORFLOW_TEXT_IMPORT_ERRORTORCHAUDIO_IMPORT_ERRORPANDAS_IMPORT_ERRORPHONEMIZER_IMPORT_ERRORUROMAN_IMPORT_ERRORSACREMOSES_IMPORT_ERRORSCIPY_IMPORT_ERRORSPEECH_IMPORT_ERRORTIMM_IMPORT_ERRORNATTEN_IMPORT_ERRORNUMEXPR_IMPORT_ERRORNLTK_IMPORT_ERRORVISION_IMPORT_ERRORPYTESSERACT_IMPORT_ERRORPYCTCDECODE_IMPORT_ERRORACCELERATE_IMPORT_ERRORCCL_IMPORT_ERRORESSENTIA_IMPORT_ERRORLIBROSA_IMPORT_ERRORPRETTY_MIDI_IMPORT_ERRORCYTHON_IMPORT_ERRORJIEBA_IMPORT_ERRORPEFT_IMPORT_ERRORJINJA_IMPORT_ERRORr  r  typer  r  
BACKENDS_Tr  r  BaseExceptionr  r  r
  rM  r(  rI  rr  rt  r   r   r'   <module>r     s                 				      



  # # # # # #                   D D D D D D D D D D D D D D D D D D             
	H	%	% C  %PUVZ\_V_P`bfPfJg    B 211  4 : :F8 D D 	&	)	)	/	/	1	1JNN;//5577	
*..V
,
,
2
2
4
4 
44::<<Z^^$8&AAGGII  *GM&11 !      .C-B<`d-e-e-e * *''//''//((..d://?? ''//--l;; //?? ''55,,[99 //?? ))%00<..}== ))%00<++J77 --l;; >++G44D@ !'//88N
LLHHHIIII. ! ! !!"+33K@@LNLLMMMM2 ! ! ! !	! ('//))(33 !6!67Tei!j!j!j ((11 ((22 ((11 ,,[99 ..}== **955 ))(33 ''//''//))(33 **955 ,,[99 n..u55TA ))(33 $ )/000#'  . ) ) )#(   ) !* 8 89M N NVZ Z ))(33 ''//--l;; ))(33 ))(33 **955 ..}== ++J77 ..}== ))(33 "7"78N"O"O ))(33 --l;; ..}== ((11 00AA ++G44 $9$9&QU$V$V$V ! M^--i88D  ##"">22222 # # #"#$>33ODDDP ,,[99 ((11 +@+@]a+b+b+b ( ($9$9:R$S$S !223DEE **955 ''//--l;; --l;; **955 --l;; /D/D]cg/h/h/h , ,&&u--44U4PPP ++J77 ++J77 //??   ---&@T2T2T'<'<WUY'Z'Z'Z$nn
KK9::: ---MM...9DX3X3X "00>>dJ 	4J K!  "+"4"<"<S"A"AKE )>   D't3M 	&w}[))MGM#,>,>>>pppp   !&CDDD  n..z::$F !*22:>>
LLN;LNNOOOO.    #11-@@L #$-55mDD
LLT>RTTUUUU. # # #"# N[))5 K~ =>>dJ $,,-=>>K
LLAKAABBBB.    
+++%:%:6RV%W%W%W"O] 1'<'<USW'X'X'X$ 	1KK^|^^M^^^____/44On+00L=   !GM.11M(.0CD!'!'I   (((/D/D[ae/f/f/f,, JH);HHHIII       0F f f f f f f	 	 	 )8 X X# X X X X    C C C " " "H H H# # #       # # #" " "    " " "          
 
 
 
 
 
H H H  ) ) )   2   (  $        " " "                0    (     > > > >$ > > > >, @ @ @ @,C C C% % %  &E E E  ! ! !      ! ! !      
 
 
  $ > > > >4   > > > > >  0] ] ] eC e e e e! ! !      $ $ $   *: ] ]3 ] ] ] ]C C C *: ` `3 ` ` ` `      ( ( (
) ) )       ! ! !" " "J J J" " "! ! !   " " "    < < <C C C  $+ + +- - -  $ $ $$ $ $0. . .           ! ! !  ! ! !
! ! !  
 
 
         G G Gf f f= = =      7 7 7_ _ _  $
      
     
       % !' #     
                 
 
 
 
 ;+	12+	!#345+ 
!#345+ 
+-BCD	+
 
/1HIJ+ 
+-BCD+ 
%'9:;+ 
#%678+ 
#%678+ 
')<=>+ 
')<=>+ 
/1HIJ+ 
')<=>+ 
13KLM+ 
13KLM+  
)+?@A!+" 
+-BCD#+$ 
13KLM%+& 
13KLM'+( 
/1HIJ)+* 
 "CEf!gh++, 
57QRS-+. 
)+?@A/+0 
')<=>1+2 
"$GIl#mn3+4 
!89:5+6 
9;WXY7+8 
#%6789+: 
/1HIJ;+< 
')<=>=+> 
#%678?+@ 
/1HIJA+B 
%';<=C+D 
13KLME+F 
')<=>G+H 
%'9:;I+J 
/1HIJK+L 
,.>?@M+N 
')<=>O+P 
%'9:;Q+R 
#%678S+T 
%'9:;U+- - `+ + +(	. 	. 	. 	. 	.$ 	. 	. 	.   s^
*d3C=&99: xU xU xU xU xU* xU xU xUv[ [ [ [ [] [ [ [ S     &      , "!7##Y
CC_	 " " "J F F FR]& ]& ]&@5 51C 5 5 5 5 5 5s   #2K L3&2LL3L-*L3,L--L32L3
P' 'P;:P;U U32U3
[&&[87[812^$ $^87^82` ``2b b$#b$