
    7i             
          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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 ddlmZ dd	lmZ ddlZdd
lmZ ddlmZ  ej>                  e       Z!ejD                  jG                         Z$dFde%de&de'e&e%f   e&z  fdZ(de%de&fdZ)de%de&fdZ*h dZ+e+jY                  dh      Z-ej\                  j_                  dd      ja                         Z1dZ2dZ3dZ4dZ5dZ6dZ7dZ8dZ9d Z:d!Z;d"Z<d#Z=ede&fd$       Z>ede%fd%       Z?edFd&e%d'e&de&fd(       Z@edFd&e%d'e&de&fd)       ZAede&fd*       ZBede&fd+       ZCede&fd,       ZDede&fd-       ZEede&fd.       ZFedGd/e%dz  de&fd0       ZGedFde&fd1       ZHedFd2e&de&fd3       ZIede&fd4       ZJedFde&fd5       ZKedHde&fd6       ZLede&fd7       ZMede&fd8       ZNed9e%de&fd:       ZOed9e%de&fd;       ZPede&fd<       ZQed=e&ddfd>       ZRede&fd?       ZSede&fd@       ZTede&fdA       ZUee=fdBe%de&fdC       ZVede&fdD       ZWede&fdE       ZXede&fdF       ZYee2fd/e%de&fdG       ZZee<fd/e%de&fdH       Z[ede&fdI       Z\ee8fd/e%de&fdJ       Z]ede&fdK       Z^ede&fdL       Z_ede&fdM       Z`ede&fdN       Zaede&fdO       Zbede&fdP       Zcede&fdQ       Zdede&fdR       Zeee4fd/e%de&fdS       Zfede&fdT       Zgede&fdU       Zhede&fdV       Ziede&fdW       Zjede&fdX       Zkede&fdY       Zlede&fdZ       Zmede&fd[       Znede&fd\       Zoede&fd]       Zped^        Zqede&fd_       Zrede&fd`       Zsede&fda       Ztede&fdb       Zuede&fdc       Zvede&fdd       Zwede&fde       Zxede&fdf       Zyede&fdg       ZzedIde&fdh       Z{ede&fdi       Z|ede&fdj       Z}ede&fdk       Z~ede&fdl       Zede&fdm       Zede&fdn       Zede&fdo       Zede&fdp       Zede&fdq       Zee9fd/e%de&fdr       Zede&fds       Zede&fdt       Zede&fdu       Zede&fdv       Zee3fd/e%de&fdw       Zede&fdx       Zede&fdy       Zede&fdz       Zed&e%de&fd{       ZedFd&e%d'e&de&fd|       ZedFd&e%d'e&de&fd}       Zed~        Zede&fd       Zede&fd       Zede&fd       Zede&fd       Zede&fd       Zee6fd/e%de&fd       Zede&fd       Zee5fd/e%de&fd       Zede&fd       Zede&fd       Zee;fd/e%de&fd       Zed        Zede&fd       Zed        Zed        Zede&fd       Zede&fd       Zede&fd       Zede&fd       Zede&fd       Zede&fd       Zede&fd       Zede&fd       Zede&fd       Zede&fd       Zede&fd       Zede&fd       Zede&fd       Zede&fd       Zede&fd       Zede&fd       Zede&fd       Zede&fd       Zede&fd       Zede&fd       Zee:fd/e%de&fd       Zede&fd       Zede&fd       Zede&fd       Zede&fd       Zede&fd       Zede&fd       Zede&fd       Zede&fd       Zede&fd       Zede&fd       Zede&fd       Zede&fd       Zede&fd       Zede&fd       Zede&fd       Zede&fd       Zede&fd       Zede&fd       ZǐdJdZdedefdZde&fdZede%fd       Zde&fdZde&fdZde&fdZde&fdZd Zde&fdZde&fdZҐdGde&fdZefdede%eg e%f   z  dee   ddfdńZede&fdƄ       Zde&fdǄZde&fdȄZde&fdɄZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZ dZdZdZdZdZdZdZdZdZ	 eg deeffdeveffdeWeffde}effdeeffde~effdeieffdeeffd ezeffdeeffdeeffdeeffdeneffdeeffdeheffdeeffdegeffd	eeffd
eeffdeeffdeeffdeeffdeeffdeeffdeeffdeeffdeeffdeeffde>effde_effdeeffdeeffdeeffdeZe ffdeeffdeeffdeueffdeeffdeXeffdeĐeffd ejeffd!ekeffd"eleffd#emeffd$eƐe	ff      Z
d% Z G d& d'eի      Zee%   Zeeee%ee%   f   f   Z G d( d)e      Z G d* d+e      ZdKd,e%defd-Z G d. d/e      Zede'e%e%e%f   fd0       Z G d1 d2      Zd3d4d5Zd6 d7d8 d9d: d;d< d=d> d;iZdee%   fd?Zed@        ZdA ZedGdBe%dCe%dz  defdD       ZdJdEZ y(L  zD
Import utilities: Utilities related to imports and our lazy inits.
    N)OrderedDict)Callable)Enum)	lru_cache)chain)
ModuleType)Any)version   )loggingpkg_namereturn_versionreturnc                    t         j                  j                  |       }|du}d}|rk|ri	 t        |    }| j	                  dd      }||v r|}n| |v r| }n|d   }t         j
                  j                  |      }t        j                  d|  d|        |r||fS |S # t         j
                  j                  t        f$ r% t        j                  |       }t        |dd      }Y jw xY w)	z@Check if `pkg_name` exist, and optionally try to get its versionNN/A_-r   __version__z	Detected z
 version: )	importlibutil	find_specPACKAGE_DISTRIBUTION_MAPPINGreplacemetadatar
   PackageNotFoundErrorKeyErrorimport_modulegetattrloggerdebug)	r   r   specpackage_existspackage_versiondistributionsnormalized_pkg_namedistribution_namepackages	            [/mnt/e/genesis-system/.venv/lib/python3.12/site-packages/transformers/utils/import_utils.py_is_package_availabler)   0   s   >>##H-D%NO.	E 9BM #+"2"23"<"m3$7!]*$,!$1!$4!'00889JKO 	y
*_4EFG.. ""77B 	E  --h7G%g}eDO		Es   AB AC#"C#env_variablec                 N    t        j                  | d      j                         dv S )zMDetect whether `env_variable` has been set to a true value in the environmentfalse)true1yyesonosgetenvlowerr*   s    r(   is_env_variable_truer7   P   s"    99\7+1137VVV    c                 N    t        j                  | d      j                         dv S )zNDetect whether `env_variable` has been set to a false value in the environmentr-   )r,   0nnooffr2   r6   s    r(   is_env_variable_falser>   U   s"    99\6*0026VVVr8   >   r.   ONYESTRUEAUTOUSE_TORCH_XLAr.   z1.1.0z0.46.1z1.2.6z1.12.0z0.10.02.2.0z0.2.1z0.0.4z0.4.0z0.5.0z1.0.0z0.10.2c                  V   	 t        dd      \  } }t        j                  |      }| r0|t        j                  d      k  rt        j	                  d|        | xr+ t        j                  |      t        j                  d      k\  S # t
        j                  j                  $ r Y yw xY w)NtorchTr   z2.4.0z?Disabling PyTorch because PyTorch >= 2.4 is required but found F)r)   r
   parser   warning_once	packagingInvalidVersion)is_availabletorch_versionparsed_versions      r(   is_torch_availablerO   n   s    &;GTX&Y#m }5NW]]7-CC"aboap qrVm <g@V VV++ s   BB B('B(c                  &    t        dd      \  } }|S )NrF   TrG   r)   )r   rM   s     r(   get_torch_versionrR   z   s    ,WTJA}r8   library_version
accept_devc                 "   t               sy|rPt        j                  t        j                  t                     j                        t        j                  |       k\  S t        j                  t                     t        j                  |       k\  S )
    Accepts a library version and returns True if the current version of the library is greater than or equal to the
    given version. If `accept_dev` is True, it will also accept development versions (e.g. 2.7.0.dev20250320 matches
    2.7.0).
    FrO   r
   rH   rR   base_versionrS   rT   s     r(   is_torch_greater_or_equalrZ      e     }}W]]+<+>?LLMQXQ^Q^_nQooo}}.01W]]?5SSSr8   c                 "   t               sy|rPt        j                  t        j                  t                     j                        t        j                  |       k  S t        j                  t                     t        j                  |       k  S )z
    Accepts a library version and returns True if the current version of the library is less than or equal to the
    given version. If `accept_dev` is True, it will also accept development versions (e.g. 2.7.0.dev20250320 matches
    2.7.0).
    FrW   rY   s     r(   is_torch_less_or_equalr]      r[   r8   c                  8    t               rdd l} t        | d      S y)Nr   acceleratorF)rO   rF   hasattrrF   s    r(   is_torch_accelerator_availablerb      s    um,,r8   c                  T    t               rdd l} | j                  j                         S yNr   F)rO   rF   cudarL   ra   s    r(   is_torch_cuda_availablerf      s!    zz&&((r8   c                  P    t               rdd l} | j                  j                  d uS yrd   )rO   rF   r
   re   ra   s    r(   is_cuda_platformrh      s#    }}!!--r8   c                  P    t               rdd l} | j                  j                  d uS yrd   )rO   rF   r
   hipra   s    r(   is_rocm_platformrk      s#    }}  ,,r8   c                  ~    t               sydd lmc mc m}  | j                         | j                  j                  k(  S )NFr   )is_torch_hpu_available*habana_frameworks.torch.utils.experimentalrF   utilsexperimental_get_device_typesynDeviceTypesynDeviceGaudi)htexps    r(   is_habana_gaudi1ru      s3    !#>> !!#u':':'I'IIIr8   min_versionc                 .   t               rdd l}|j                  j                  j	                         xr$ |j                  j                  j                         }| 9t        j                  t                     t        j                  |       k\  }|xr |}|S yrd   )	rO   rF   backendsmpsrL   is_builtr
   rH   rR   )rv   rF   backend_availableflags       r(   is_torch_mps_availabler}      sv    !NN..;;=_%..BTBTB]B]B_"==!2!45{9SSD 1 :d  r8   c                    t               rt        d      syddl}ddl}| r5	 |j                  j                         }|j                  j                         S t        |d      xr |j                  j                         S # t        $ r Y yw xY w)zQChecks if `torch_npu` is installed and potentially if a NPU is in the environment	torch_npuFr   Nnpu)	rO   r)   rF   r   r   device_countrL   RuntimeErrorr`   )check_devicerF   r   r   s       r(   is_torch_npu_availabler      s}     '<['I			&&(A99))++ 5% =UYY%;%;%==  		s   3A> >	B
	B
r   c                 t   t               syt        j                  t                     }|j                  dk(  r|j
                  dk  ryddl}| r5	 |j                  j                         }|j                  j                         S t        |d      xr |j                  j                         S # t        $ r Y yw xY w)z
    Checks if XPU acceleration is available via stock PyTorch (>=2.6) and
    potentially if a XPU is in the environment.
    F      r   Nxpu)rO   r
   rH   rR   majorminorrF   r   r   rL   r   r`   )r   rM   rF   r   s       r(   is_torch_xpu_availabler      s     MM"3"56MaM$7$7!$;			&&(A99))++ 5% =UYY%;%;%==  		s   3B+ +	B76B7c                     t               rt        d      syddl} ddl}t        j
                  j                  d      }	 t        d      t        j
                  d<   | j                  j                         }|r|t        j
                  d<   |S t        j
                  j                  dd       |S # |r|t        j
                  d<   w t        j
                  j                  dd       w xY w)z
    Checks if `mlu` is available via an `cndev-based` check which won't trigger the drivers and leave mlu
    uninitialized.
    	torch_mluFr   NPYTORCH_CNDEV_BASED_MLU_CHECKr   )rO   r)   rF   r   r3   environgetstrmlurL   pop)rF   r   ,pytorch_cndev_based_mlu_check_previous_value	availables       r(   is_torch_mlu_availabler   	  s     '<['I35::>>Ba3b0B69!f

23II**,	7:fBJJ67  JJNN:DA 8:fBJJ67JJNN:DAs   6B. .8C&c                    t               rt        d      syddl}ddl}d}t        dd      \  }}|r,t	        j
                  |      t	        j
                  |      k  ry| r5	 |j                  j                         }|j                  j                         S t        |d	      xr |j                  j                         S # t        $ r Y yw xY w)
zSChecks if `torch_musa` is installed and potentially if a MUSA is in the environment
torch_musaFr   Nz0.33.0
accelerateTrG   musa)rO   r)   rF   r   r
   rH   r   r   rL   r   r`   )r   rF   r   torch_musa_min_versionaccelerate_availableaccelerate_versionr   s          r(   is_torch_musa_availabler   "  s     '<\'J%/D\bf/g,,.@ AGMMRhDi i	

'')A::**,, 5&!?ejj&=&=&??  		s   "3B> >	C
	C
c                     | r	|rJ d       t         t        v xr t        d      }|syddl}|r|j                  j                         dv S | r|j                  j                         dk(  S y)	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.	torch_xlaFr   N)GPUCUDATPUT)rC   ENV_VARS_TRUE_VALUESr)   r   runtimedevice_type)check_is_tpucheck_is_gputorch_xla_availabler   s       r(   is_torch_xla_availabler   :  ss     h0hh.'+??fDYZeDf  ,,./AA	  ,,.%77r8   c            
        	
 t               rt        d      rt        d      syd} t        dd      \  }}|r,t        j                  |      t        j                  |       k  rydd	lt
        j                  j                  d
d      dk(  rdd	l}t        d      rj                  j                         syj                  dj                  dt        dj                  dj                  ffd}|_        |j                  _        j                   ddj                  dj                  dt        d	z  dj                  ffd}|_        j"                  j$                  		fd}|j"                  _        j&                  dj                  dt        dj                  dj                  dj                  f
fd}|_        |j                  _        j(                  

fd}|_        y)zQChecks if `torch.hpu` is available and potentially if a HPU is in the environmenthabana_frameworkszhabana_frameworks.torchFz1.5.0r   TrG   r   NPT_HPU_LAZY_MODEr.   hpuinputdimindexr   c                     | j                   j                  k(  rU| j                  j                  dk(  r< | j	                  j
                        ||      j	                  j                        S  | ||      S Nr   dtypeint64devicetypetoint32)r   r   r   original_gatherrF   s      r(   patched_gatherz.is_torch_hpu_available.<locals>.patched_gatherm  s^    ;;%++%%,,*;*;u*D"588EKK#8#uEHHUU"5#u55r8   indicesc                     | j                   j                  k(  rU| j                  j                  dk(  r< | j	                  j
                        ||      j	                  j                        S  | ||      S r   r   )r   r   r   original_take_along_dimrF   s      r(   patched_take_along_dimz6is_torch_hpu_available.<locals>.patched_take_along_dimx  sa    ;;%++%%,,*;*;u*D*588EKK+@'3ORRSXS^S^__*5'3??r8   c                      | g|i |}j                  |      j                         rKd}j                  | j                  d      | j                  | j
                        |z  } | |z   g|i |}|S )Ng&.>r   r   )isnananyeyesizer   r   )Aargskwargsoutputjitter_valuediag_jitteroriginal_choleskyrF   s         r(   safe_choleskyz-is_torch_hpu_available.<locals>.safe_cholesky  sx    "16t6v6;;v""$L))AFF2Jaggahh)OR^^K&q;HHHFr8   srcc                     | j                   j                  dk(  r!| |u r | |||j                         g|i |S  | |||g|i |S r   )r   r   clone)r   r   r   r   r   r   original_scatters         r(   patched_scatterz/is_torch_hpu_available.<locals>.patched_scatter  sY     <<%%3,#E3syy{TTTVTT#E3sLTLVLLr8   c                      |j                  d      dvr-t        j                  d|j                  d       d       d|d<    | i |S )Nbackend)hpu_backendeagerz#Calling torch.compile with backend=ze on a Gaudi device is not supported. We will override the backend with 'hpu_backend' to avoid errors.r   )r   r   warning)r   r   original_compiles     r(   hpu_backend_compilez3is_torch_hpu_available.<locals>.hpu_backend_compile  s[    ::i (@@NN5fjj6K5L MS S !.F9000r8   N)rO   r)   r
   rH   rF   r3   r   r   habana_frameworks.torchr`   r   rL   gatherTensorint
LongTensortake_along_dimlinalgcholeskyscattercompile) torch_hpu_min_accelerate_versionr   r   r   r   r   r   r   r   r   r   r   r   r   rF   s            @@@@@@r(   rm   rm   P  s     $%89$%>?'.$/D\bf/g,,.@ AGMMRrDs s	zz~~(#.#5&5% 		(>(>(@
 llO6ell 6 6U=M=M 6RWR^R^ 6 "EL(ELL#22@ell @U=M=M @TWZ^T^ @jojvjv @ 2E-- *ELL}}M||M"%M.3llMAFM	M $EM*ELL }}1 (EMr8   c                     t               sydd l} | j                  j                         r| j                  j	                         S t               r| j                  j	                         S t               ryt               r| j                  j	                         S t               r&| j                  j                  j                  dd      S t               r| j                  j	                         S y)NFr   T   )rO   rF   re   rL   is_bf16_supportedr   r   rm   r   r   r}   rx   ry   is_macos_or_newerr   r   ra   s    r(   is_torch_bf16_gpu_availabler     s    zz zz++--yy**,,yy**,,~~!!33B:: zz++--r8   r   c                 b   t               syt               rt               ryydd l}	 |j	                  dd|j
                  |       }||z  }d\  }}}|j                  ||||j
                  |       }|j                  j                  ||j
                  |       } ||      }y# t        $ r Y yw xY w)NFTr   r   r   )         )
rO   rm   ru   rF   zerosfloat16randnnn	LayerNorm	Exception)	r   rF   xr   batchsentence_lengthembedding_dim	embedding
layer_norms	            r(   !is_torch_fp16_available_on_devicer     s    KK1EMM&KAE 18-KKU]]ciKj	XX''U]]SY'Z
y! s   A:B" "	B.-B.c                     t               sydd l}| dk(  r
t               S | dk(  ry	 |j                  dd|j                  |       }||z  }y# t
        $ r Y yw xY w)NFr   re   r   Tr   r   )rO   rF   r   r   bfloat16r   )r   rF   r   r   s       r(   !is_torch_bf16_available_on_devicer     sf    *,,KK1ENN6KBE s   $A 	AAc                     t               sydd l} t               rR| j                  j	                  | j                  j                               }|j                   |j                   dk\  ryy| j                  j                         r| j                  j                  y| j                  j	                  | j                  j                               j                  dk  ryy)NFr   22T   )rO   rF   r   r   get_device_propertiescurrent_devicer   r   re   rL   r
   )rF   device_infos     r(   is_torch_tf32_availabler    s     jj66uzz7P7P7RS !2!2 34<::""$(:(:(Bzz''

(A(A(CDJJQNr8   enablec                 r   ddl }t        j                  t                     }|t        j                  d      k\  r| rdnd}||j                  _        yt               r| |j                  j                  _        y| |j                  j                  j                  _        | |j                  j                  _        y)z
    Set TF32 mode using the appropriate PyTorch API.
    For PyTorch 2.9+, uses the new fp32_precision API.
    For older versions, uses the legacy allow_tf32 flags.
    Args:
        enable: Whether to enable TF32 mode
    r   N2.9.0tf32ieee)rF   r
   rH   rR   rx   fp32_precisionr   mudnn
allow_tf32re   matmulcudnn)r  rF   pytorch_versionprecision_modes       r(   enable_tf32r  
  s     mm$5$78O'--00#)v(6%"$.4ENN  +4:ENN&&1.4ENN  +r8   c                      t               xr3 t        j                  t                     t        j                  d      k\  S )Nz2.5.0rO   r
   rH   rR    r8   r(   is_torch_flex_attn_availabler  !  ,    `GMM2C2E$F'--X_J`$``r8   c                      t               xr3 t        j                  t                     t        j                  d      k\  S )Nr
  r  r  r8   r(   is_grouped_mm_availabler  &  r  r8   c                      t        d      S )NkenlmrQ   r  r8   r(   is_kenlm_availabler  +       ))r8   MIN_VERSIONc                     t        dd      \  }}|xr+ t        j                  |      t        j                  |       k\  S )NkernelsTrG   r)   r
   rH   )r   rL   kernels_versions      r(   is_kernels_availabler%  0  6    $9)TX$Y!L/XGMM/:gmmK>XXXr8   c                      t        d      S )Ncv2rQ   r  r8   r(   is_cv2_availabler)  6       ''r8   c                      t        d      S )Nyt_dlprQ   r  r8   r(   is_yt_dlp_availabler-  ;       **r8   c                      t        d      S )NlibcstrQ   r  r8   r(   is_libcst_availabler1  @  r.  r8   c                     t        dd      \  }}|xr+ t        j                  |      t        j                  |       k\  S )Nr   TrG   r#  )rv   rL   r   s      r(   is_accelerate_availabler3  E  8    '<\Z^'_$L$[GMM*<={A[[[r8   c                     t        dd      \  }}|xr+ t        j                  |      t        j                  |       k\  S )NtritonTrG   r#  )rv   rL   triton_versions      r(   is_triton_availabler8  K  s6    #8RV#W L.WGMM.9W]];=WWWr8   c                      t        d      S )Nfast_hadamard_transformrQ   r  r8   r(   is_hadamard_availabler;  Q  s     !:;;r8   c                     t        dd      \  }}|xr+ t        j                  |      t        j                  |       k\  S )NhqqTrG   r#  )rv   rL   hqq_versions      r(   is_hqq_availabler?  V  s5     5eD QL+TGMM+6'--:TTTr8   c                      t        d      S )NpygmentsrQ   r  r8   r(   is_pygments_availablerB  \       ,,r8   c                      t        d      S )NtorchvisionrQ   r  r8   r(   is_torchvision_availablerF  a       //r8   c                      t               S r   )rF  r  r8   r(   is_torchvision_v2_availablerI  f  s    #%%r8   c                      t        d      S )Ngalore_torchrQ   r  r8   r(   is_galore_torch_availablerL  k       00r8   c                      t        d      S )Napollo_torchrQ   r  r8   r(   is_apollo_torch_availablerP  p  rM  r8   c                      t        d      S )NoptimirQ   r  r8   r(   is_torch_optimi_availablerS  u  r.  r8   c                      t        d      S )N
lomo_optimrQ   r  r8   r(   is_lomo_availablerV  z       ..r8   c                      t        d      S )N	grokadamwrQ   r  r8   r(   is_grokadamw_availablerZ         --r8   c                     t        dd      \  }}|xr+ t        j                  |      t        j                  |       k\  S )NschedulefreeTrG   r#  )rv   rL   schedulefree_versions      r(   is_schedulefree_availabler_    9    )>~^b)c&L&]GMM*>?7==Q\C]]]r8   c                      t        d      S )NpyctcdecoderQ   r  r8   r(   is_pyctcdecode_availablerc    rG  r8   c                      t        d      S )NlibrosarQ   r  r8   r(   is_librosa_availablerf         ++r8   c                      t        d      S )NessentiarQ   r  r8   r(   is_essentia_availablerj    rC  r8   c                      t        d      S )NpydanticrQ   r  r8   r(   is_pydantic_availablerm    rC  r8   c                      t        d      S )NfastapirQ   r  r8   r(   is_fastapi_availablerp    rg  r8   c                      t        d      S )NuvicornrQ   r  r8   r(   is_uvicorn_availablers    rg  r8   c                      t        d      S )NopenairQ   r  r8   r(   is_openai_availablerv    r.  r8   c                      t        d      S )Npretty_midirQ   r  r8   r(   is_pretty_midi_availablery    rG  r8   c                  0    t               xr t        d      S )N	mamba_ssmrf   r)   r  r8   r(   is_mamba_ssm_availabler}    s    "$K)>{)KKr8   c                      t        dd      \  } }t               xr/ | xr+ t        j                  |      t        j                  d      k\  S )Nr{  TrG   2.0.4r)   rf   r
   rH   )rL   mamba_ssm_versions     r(   is_mamba_2_ssm_availabler    sD    &;KX\&]#L#"$tt'--HY:Z^e^k^kls^t:ttr8   c                      t        dd      \  } }t               xr/ | xr+ t        j                  |      t        j                  d      k\  S )NflaTrG   z0.2.2r  )rL   fla_versions     r(   #is_flash_linear_attention_availabler    sA     5eD QL+"$nn'--:TX_XeXefmXn:nnr8   c                  0    t               xr t        d      S )Ncausal_conv1dr|  r  r8   r(   is_causal_conv1d_availabler    s    "$O)>)OOr8   c                  0    t               xr t        d      S )NxlstmrO   r)   r  r8   r(   is_xlstm_availabler    s    B$9'$BBr8   c                  0    t               xr t        d      S )Nmambapyr  r  r8   r(   is_mambapy_availabler    s    D$9)$DDr8   c                      t        d      S )NpeftrQ   r  r8   r(   is_peft_availabler         ((r8   c                      t        d      S )Nbs4rQ   r  r8   r(   is_bs4_availabler    r*  r8   c                      t        d      S )NcoloredlogsrQ   r  r8   r(   is_coloredlogs_availabler    rG  r8   c                      t        d      S )NonnxrQ   r  r8   r(   is_onnx_availabler    r  r8   c                      t        dd      \  } }| xr+ t        j                  |      t        j                  d      k\  S )NfluteTrG   z0.4.1r#  )rL   flute_versions     r(   is_flute_availabler    s6    "7PT"UL-RGMM-8GMM'<RRRr8   c                      t        d      S )Ng2p_enrQ   r  r8   r(   is_g2p_en_availabler    r.  r8   c                 0    t               xr t        d      S )Ntorch_neuronx)r   r)   )r   s    r(   is_torch_neuroncore_availabler    s    !#N(=o(NNr8   c                  2    t        d      xr t        d      S )Ntorch_tensorrtztorch_tensorrt.fxrQ   r  r8   r(   is_torch_tensorrt_fx_availabler    s     !12a7LM`7aar8   c                      t        d      S )NdatasetsrQ   r  r8   r(   is_datasets_availabler    rC  r8   c                  0    	 ddl m}  y# t        $ r Y yw xY w)Nr   META_ARCH_REGISTRYTF)detectron2.modelingr  r   r  s    r(   is_detectron2_availabler     s    
: s   	 	c                      t        d      S )NrjiebarQ   r  r8   r(   is_rjieba_availabler    r.  r8   c                      t        d      S )NpsutilrQ   r  r8   r(   is_psutil_availabler    r.  r8   c                      t        d      S )Npy3nvmlrQ   r  r8   r(   is_py3nvml_availabler    rg  r8   c                      t        d      S )N
sacremosesrQ   r  r8   r(   is_sacremoses_availabler    rW  r8   c                      t        d      S )NapexrQ   r  r8   r(   is_apex_availabler  !  r  r8   c                      t        d      S )NaqlmrQ   r  r8   r(   is_aqlm_availabler  &  r  r8   c                     t        dd      \  }}|xr+ t        j                  |      t        j                  |       k\  S )NvptqTrG   r#  )rv   rL   vptq_versions      r(   is_vptq_availabler  +  5    !6vd!SL,UGMM,77==;UUUr8   c                      t        d      S )NavrQ   r  r8   r(   is_av_availabler  1  s     &&r8   c                      t        d      S )NdecordrQ   r  r8   r(   is_decord_availabler  6  r.  r8   c                      t        d      S )N
torchcodecrQ   r  r8   r(   is_torchcodec_availabler  ;  rW  r8   c                  R    	 t        j                  ddg       y# t        $ r Y y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.
    ninjaz	--versionTF)
subprocesscheck_outputr   r  r8   r(   is_ninja_availabler  @  s3    + 67   s    	&&c                     t        dd      \  }}|xr+ t        j                  |      t        j                  |       k\  S )NbitsandbytesTrG   r#  )rv   rL   bitsandbytes_versions      r(   is_bitsandbytes_availabler  N  r`  r8   c                     t        dd      \  } }| rt               st               sydd l}	 |j                  j
                  r+t	        j                  |      t	        j                  d      k\  S |j                  j                  r+t	        j                  |      t	        j                  d      k\  S t               r+t	        j                  |      t	        j                  d      k\  S y# t        j                  j                  $ r Y yw xY w)	N
flash_attnTrG   Fr   2.1.0r  z2.3.3)
r)   rf   r   rF   r
   re   rH   rj   rJ   rK   )rL   flash_attn_versionrF   s      r(   is_flash_attn_2_availabler  T  s    '<\Z^'_$L$ 7 9=S=U====!34g8NNN]]==!34g8NNN#%==!34g8NNN++ s   A C% .A C% /4C% %DDc                  0    t               xr t        d      S )Nflash_attn_3r|  r  r8   r(   is_flash_attn_3_availabler  j  s    "$N)>~)NNr8   c                      t        dd      \  } }t               xr+ t        j                  |      t        j                  d      k\  S )Nr  TrG   r  )r)   r  r
   rH   )r   r  s     r(   #is_flash_attn_greater_or_equal_2_10r  o  s>    1,tTA$&f7==9K+LPWP]P]^ePf+ffr8   c                     t        dd      \  }}|sy	 t        j                  |      t        j                  |       k\  S # t        j                  j                  $ r Y yw xY w)Nr  TrG   F)r)   r
   rH   rJ   rK   )rS   rL   r  s      r(   is_flash_attn_greater_or_equalr  u  s\    '<\Z^'_$L$}}/0GMM/4RRR++ s   *A   A A c                    t        dd      \  }}|sy|rHt        j                  t        j                  |      j                        t        j                  |       k\  S t        j                  |      t        j                  |       k\  S )Nhuggingface_hubTrG   F)r)   r
   rH   rX   )rS   rT   rL   hub_versions       r(   #is_huggingface_hub_greater_or_equalr    sh     56GX\ ]L+}}W]];7DDEWfIggg}}[)W]]?-KKKr8   c                 "   t               syt        dd      \  }}|rHt        j                  t        j                  |      j                        t        j                  |       kD  S t        j                  |      t        j                  |       kD  S )rV   Foptimum.quantoTrG   )is_optimum_quanto_availabler)   r
   rH   rX   )rS   rT   r   quanto_versions       r(   is_quanto_greaterr    sl     '(-.>tTA~}}W]]>:GGH7==YhKiii}}^,w}}_/MMMr8   c                      t        d      S )N
torchdistxrQ   r  r8   r(   is_torchdistx_availabler    rW  r8   c                      t        d      S )NfaissrQ   r  r8   r(   is_faiss_availabler    r  r8   c                      t        d      S )NscipyrQ   r  r8   r(   is_scipy_availabler    r  r8   c                      t        d      S )NsklearnrQ   r  r8   r(   is_sklearn_availabler    rg  r8   c                      t        d      S )NsentencepiecerQ   r  r8   r(   is_sentencepiece_availabler    s     11r8   c                      t        d      S )NseqiorQ   r  r8   r(   is_seqio_availabler    r  r8   c                     t        dd      \  }}|xr+ t        j                  |      t        j                  |       k\  S )NggufTrG   r#  )rv   rL   gguf_versions      r(   is_gguf_availabler    r  r8   c                  2    t        d      xr t        d      S )Ngooglezgoogle.protobufrQ   r  r8   r(   is_protobuf_availabler	    s     *W/DEV/WWr8   c                     t               xr3 t        j                  t                     t        j                  |       k\  S r   r  )rv   s    r(   is_fsdp_availabler    s,    dGMM2C2E$F'--XcJd$ddr8   c                      t        d      S )NoptimumrQ   r  r8   r(   is_optimum_availabler    rg  r8   c                      t        d      S )NawqrQ   r  r8   r(   is_llm_awq_availabler    r*  r8   c                     t        dd      \  }}|xr+ t        j                  |      t        j                  |       k\  S )N
auto_roundTrG   r#  )rv   rL   auto_round_versions      r(   is_auto_round_availabler    r4  r8   c                  0    t               xr t        d      S )Nr  r  r)   r  r8   r(   r  r        !M&;<L&MMr8   c                      t        d      S )NquarkrQ   r  r8   r(   is_quark_availabler    r  r8   c                      t        dd      \  } }| xr+ t        j                  |      t        j                  d      k\  S )Nfp_quantTrG   z0.3.2r#  )rL   fp_quant_versions     r(   is_fp_quant_availabler    s8    %::VZ%["L"UGMM*:;w}}W?UUUr8   c                      t        dd      \  } }| xr+ t        j                  |      t        j                  d      k\  S )NqutlassTrG   z0.2.0r#  )rL   qutlass_versions     r(   is_qutlass_availabler#    s6    $9)TX$Y!L/TGMM/:gmmG>TTTr8   c                      t        d      S )Ncompressed_tensorsrQ   r  r8   r(   is_compressed_tensors_availabler&    s     !566r8   c                      t        d      S )NsinqrQ   r  r8   r(   is_sinq_availabler)    r  r8   c                      t        d      S )N	gptqmodelrQ   r  r8   r(   is_gptqmodel_availabler,    r[  r8   c                      t        d      S )N
fbgemm_gpurQ   r  r8   r(   is_fbgemm_gpu_availabler/     rW  r8   c                      t        d      S )NLevenshteinrQ   r  r8   r(   is_levenshtein_availabler2    rG  r8   c                  0    t               xr t        d      S )Nzoptimum.neuronr  r  r8   r(   is_optimum_neuron_availabler4  
  r  r8   c                      t        d      S )N
tokenizersrQ   r  r8   r(   is_tokenizers_availabler7    rW  r8   c                      t        d      S )NPILrQ   r  r8   r(   is_vision_availabler:    r*  r8   c                      t        d      S )NpytesseractrQ   r  r8   r(   is_pytesseract_availabler=    rG  r8   c                      t        d      S )NpytestrQ   r  r8   r(   is_pytest_availabler@    r.  r8   c                  0    t               xr t        d      S )Npytest_order)r@  r)   r  r8   r(   is_pytest_order_availablerC  #  s     J%:>%JJr8   c                      t        d      S )NspacyrQ   r  r8   r(   is_spacy_availablerF  (  r  r8   c                      t        d      S )Npytorch_quantizationrQ   r  r8   r(   !is_pytorch_quantization_availablerI  -  s     !788r8   c                      t        d      S )NpandasrQ   r  r8   r(   is_pandas_availablerL  2  r.  r8   c                      t        d      S )N	soundfilerQ   r  r8   r(   is_soundfile_availablerO  7  r[  r8   c                      t        d      S )NtimmrQ   r  r8   r(   is_timm_availablerR  <  r  r8   c                      t        d      S )NnattenrQ   r  r8   r(   is_natten_availablerU  A  r.  r8   c                      t        d      S )NnltkrQ   r  r8   r(   is_nltk_availablerX  F  r  r8   c                      t        d      } | syt        dd      \  }}| xs+ t        j                  |      t        j                  d      k  S )NnumbaFnumpyTrG   rD   r#  )rL   numpy_availablenumpy_versions      r(   is_numba_availabler^  K  sI    (1L%:7SW%X"O]W'--">wAW"WWr8   c                      t        d      S )N
torchaudiorQ   r  r8   r(   is_torchaudio_availablera  U  rW  r8   c                     t        dd      \  }}|xr+ t        j                  |      t        j                  |       k\  S )NtorchaoTrG   r#  )rv   rL   torchao_versions      r(   is_torchao_availablere  Z  r&  r8   c                      t               S r   )ra  r  r8   r(   is_speech_availablerg  `  s     #$$r8   c                      t        d      S )N
spqr_quantrQ   r  r8   r(   is_spqr_availablerj  f  rW  r8   c                      t        d      S )N
phonemizerrQ   r  r8   r(   is_phonemizer_availablerm  k  rW  r8   c                      t        d      S )NuromanrQ   r  r8   r(   is_uroman_availablerp  p  r.  r8   c                      t        d      S )N	sudachipyrQ   r  r8   r(   is_sudachi_availablers  u  r[  r8   c                      t        dd      \  } }| xr+ t        j                  |      t        j                  d      k\  S )Nrr  TrG   z0.6.8r#  )rL   sudachipy_versions     r(   is_sudachi_projection_availablerv  z  s8    &;KX\&]#L#VGMM*;<g@VVVr8   c                  J    t        d      xr t        j                  d      d uS )Nrhoknpjumanpp)r)   shutilwhichr  r8   r(   is_jumanpp_availabler|    s      *Rv||I/Fd/RRr8   c                      t        d      S )N	pyximportrQ   r  r8   r(   is_cython_availabler    r[  r8   c                      t        d      S )Njinja2rQ   r  r8   r(   is_jinja_availabler    r.  r8   c                      t        d      S )NjmespathrQ   r  r8   r(   is_jmespath_availabler    rC  r8   c                      t        d      S )NmlxrQ   r  r8   r(   is_mlx_availabler    r*  r8   c                      t        d      S )N	num2wordsrQ   r  r8   r(   is_num2words_availabler    r[  r8   c                  2    t        d      xr t        d      S )NtiktokenblobfilerQ   r  r8   r(   is_tiktoken_availabler    s     ,R1Fz1RRr8   c                      t        dd      \  } }| xr+ t        j                  |      t        j                  d      k\  S )Nliger_kernelTrG   z0.3.0r#  )rL   liger_kernel_versions     r(   is_liger_kernel_availabler    s9    )>~^b)c&L&YGMM*>?7==QXCYYYr8   c                      t        d      S )NrichrQ   r  r8   r(   is_rich_availabler    r  r8   c                      t        d      S )N
matplotlibrQ   r  r8   r(   is_matplotlib_availabler    rW  r8   c                      t        d      S )Nmistral_commonrQ   r  r8   r(   is_mistral_common_availabler    s     !122r8   c                      	 t        d      xrH t        j                  t        j                  j                  d            t        j                  d      k\  S # t
        $ r
} Y d } ~ yd } ~ ww xY w)Nopentelemetryzopentelemetry-apiz1.30.0F)r)   r
   rH   r   r   r   )r   s    r(   is_opentelemetry_availabler    s_    $_5 %'--&&':;;
]]8$;% 	%  s   AA 	A*%A*c                  0    t        d      st        d      y )Nz2.6aH  Due to a serious vulnerability issue in `torch.load`, even with `weights_only=True`, we now require users to upgrade torch to at least v2.6 in order to use the function. This version restriction does not apply when loading files with safetensors.
See the vulnerability report here https://nvd.nist.gov/vuln/detail/CVE-2025-32434)rZ   
ValueErrorr  r8   r(   check_torch_load_is_safer    s"    $U+b
 	
 ,r8   fnc                       fd}|S )Nc                  >    t               st        d       | i |S )Nz7You need to install pytorch to use this method or class)rO   ImportError)r   r   r  s     r(   wrapperz"torch_only_method.<locals>.wrapper  s%    !#WXXt&v&&r8   r  )r  r  s   ` r(   torch_only_methodr    s    ' Nr8   c                  J    t               rddl} | j                         dk(  ryyy)z
    Check whether pytorch uses deterministic algorithms by looking if torch.set_deterministic_debug_mode() is set to 1 or 2"
    r   NFT)rO   rF   get_deterministic_debug_modera   s    r(   is_torch_deterministicr    s'     --/14r8   c                      t               } | dk(  ryt        j                  |       }t        |j                        dz   t        |j
                        z   S )Nr   .)rR   r
   rH   r   r   r   )rM   rN   s     r(   !get_torch_major_and_minor_versionr    sI    %'M]]=1N~##$s*S1E1E-FFFr8   c                  ^    	 dd l } | j                  j                         S # t        $ r Y yw xY wrd   )rF   compileris_compilingr   ra   s    r(   is_torchdynamo_compilingr    s/    ~~**,,      	,,c                  ^    	 dd l } | j                  j                         S # t        $ r Y yw xY wrd   )rF   r  is_exportingr   ra   s    r(   is_torchdynamo_exportingr    s/    ~~**,, r  c                 j    	 dd l }t        | |j                  j                        S # t        $ r Y yw xY wrd   )torch.fx
isinstancefxProxyr   r   rF   s     r(   is_torch_fx_proxyr    s1    !UXX^^,,    #& 	22c                 j    	 dd l }t        | |j                  j                        S # t        $ r Y yw xY wrd   )rF   r  _subclasses
FakeTensorr   r  s     r(   is_fake_tensorr    s5    !U..99:: r  c                     t        | d      sy	 ddl}t        | j                         |j                  j                        S # t
        $ r Y yw xY w)a  returns True if we are inside of `jax.jit` context, False otherwise.

    When a torch model is being compiled with `jax.jit` using torchax,
    the tensor that goes through the model would be an instance of
    `torchax.tensor.Tensor`, which is a tensor subclass. This tensor has
    a `jax` method to return the inner Jax array
    (https://github.com/google/torchax/blob/13ce870a1d9adb2430333c27bb623469e3aea34e/torchax/tensor.py#L134).
    Here we use ducktyping to detect if the inner jax array is a jax Tracer
    then we are in tracing context. (See more at: https://github.com/jax-ml/jax/discussions/9241)

    Args:
      x: torch.Tensor

    Returns:
      bool: whether we are inside of jax jit tracing.
    jaxFr   N)r`   r  r  coreTracerr   )r   r  s     r(   is_jax_jittingr    sF    $ 1e!%%'388??33 s   1A 	AAc                  ^    	 dd l } | j                  j                         S # t        $ r Y yw xY wrd   )rF   jit
is_tracingr   ra   s    r(   is_jit_tracingr  0  s/    yy##%% r  c                  ^    	 dd l } | j                  j                         S # t        $ r Y yw xY wrd   )rF   re   is_current_stream_capturingr   ra   s    r(   is_cuda_stream_capturingr  9  s/    zz5577 r  c                     t               xs t               xs
 t               }| *|t        |       z  }|t	        |       z  }|t        |       z  }|S )zChecks whether we are tracing a graph with dynamo (compile or export), torch.jit, torch.fx, jax.jit (with torchax) or
    CUDA stream capturing or FakeTensor)r  r  r  r  r  r  )tensor_is_tracings     r(   r  r  B  sW     +,^0@^D\D^K(00~f--~f--r8   condmsg
error_typec                    t        j                  dd      dk(  ryddl}t              sfd}n}t        |       r |        } t	        | |j
                        r|j                  || |       y|j                  || |       y)a  
    Combines the functionalities of `torch._check`, `torch._check_with` and `torch._check_tensor_all_with` to provide a
    unified way to perform checks that are compatible with TorchDynamo (torch.compile & torch.export).

    The advantage of using `torch._check(cond, msg, error_type)` over `if cond: raise error_type(msg)` is that the former
    works as a truthfulness hint for TorchDynamo, instead of failing with a data-dependent control flow error during compilation.

    All checks using this method can be disabled in production environments by setting `TRANSFORMERS_DISABLE_TORCH_CHECK=1`.

    Args:
        cond (`bool`, `torch.Tensor` or `Callable[[], bool | torch.Tensor]`): The condition to check.
        msg (`str` or `Callable[[], str]`): The error message to display if the condition is not met.
        error_type (`type[Exception]`, *optional*, defaults to `ValueError`): The type of error to raise if the condition is not met.

    Raises:
        error_type: If the condition is not met.
     TRANSFORMERS_DISABLE_TORCH_CHECKr:   r.   Nr   c                       S r   r  )r  s   r(   msg_callablez,torch_compilable_check.<locals>.msg_callablej  s    Jr8   )r3   r4   rF   callabler  r   _check_tensor_all_with_check_with)r  r  r  rF   r  s    `   r(   torch_compilable_checkr  Q  sr    $ 
yy3S9S@C=	 ~v$%$$Z|D*dL9r8   c                  |   	 dt         j                  v ryt         j                  d   j                  } d |        j                  vrt	        d      dt
        j                  v r!t
        j                  d   dk  rt	        d      t        j                  j                  d      d uS # t        t        t        f$ r Y y	w xY w)
NmarimoTIPythonIPKernelAppconsoleDATABRICKS_RUNTIME_VERSIONz11.0
databricksF)sysmodulesget_ipythonconfigr  r3   r   r   r   r   AttributeErrorr   )r  s    r(   is_in_notebookr  x  s    s{{"kk),88 4 44i(('2::5"**Ea:bek:k l++~~''	2$>>K2 s   B$ BB$ $B;:B;c                      t        j                  dd      } 	 t        j                  |       } | j	                  dd      sy	 t        d      S # t        j
                  $ r Y yw xY w)NSM_FRAMEWORK_PARAMS{}*sagemaker_distributed_dataparallel_enabledFsmdistributed)r3   r4   jsonloadsr   JSONDecodeErrorr)   )sagemaker_paramss    r(   is_sagemaker_dp_enabledr    sk    yy!6=::&67##$PRWX Y
 !11  s   'A A"!A"c                  `   t        j                  dd      } 	 t        j                  |       } d| vry	 t        j                  dd      }	 t        j                  |      }|j                  dd      sy	 t        d      S # t        j                  $ r Y yw xY w# t        j                  $ r Y yw xY w)NSM_HP_MP_PARAMETERSr  
partitionsFr  sagemaker_mpi_enabledr  )r3   r4   r  r  r  r   r)   )smp_optionsmpi_optionss     r(   is_sagemaker_mp_enabledr    s    ))148Kjj-{* + ))148Kjj-6> ?
 !11    s#   A> 
'B >BBB-,B-c                  &    dt         j                  v S )NSAGEMAKER_JOB_NAME)r3   r   r  r8   r(   is_training_run_on_sagemakerr    s    2::--r8   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 YT-DLP library but it was not found in your environment. You can install it with:
```
pip install yt-dlp
```
Please note that you may need to restart your runtime after installation.
z
{0} requires the PyAv library but it was not found in your environment. You can install it with:
```
pip install decord
```
Please note that you may need to restart your runtime after installation.
z
{0} requires the TorchCodec (https://github.com/pytorch/torchcodec) library, but it was not found in your environment. You can install it with:
```
pip install torchcodec
```
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.
aC  
{0} requires the SentencePiece library but it was not found in your environment. Check out 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.
aU  
{0} requires the protobuf library but it was not found in your environment. Check out 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.
aG  
{0} requires the faiss library but it was not found in your environment. Check out 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. Check out 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. Check out 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.
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.
aE  
{0} requires the detectron2 library but it was not found in your environment. Check out 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.
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 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 pydantic library but it was not found in your environment. You can install it with pip:
`pip install pydantic`. Please note that you may need to restart your runtime after installation.
z
{0} requires the fastapi library but it was not found in your environment. You can install it with pip:
`pip install fastapi`. Please note that you may need to restart your runtime after installation.
z
{0} requires the uvicorn library but it was not found in your environment. You can install it with pip:
`pip install uvicorn`. Please note that you may need to restart your runtime after installation.
z
{0} requires the openai library but it was not found in your environment. You can install it with pip:
`pip install openai`. 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.
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 the 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 the 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 rjieba library but it was not found in your environment. You can install it with pip: `pip install
rjieba`. 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.
z
{0} requires the rich library but it was not found in your environment. You can install it with pip: `pip install
rich`. Please note that you may need to restart your runtime after installation.
z
{0} requires the mistral-common library but it was not found in your environment. You can install it with pip: `pip install mistral-common`. Please note that you may need to restart your runtime after installation.
r  r  r(  r  r  
detectron2ri  r  r  rK  rl  ro  rx  levenshteinre  protobufrb  r<  r  rH  r  r  speechrQ  r`  rT  rW  r6  rF   rE  r  visionr  r   cythonr  r  jinjar,  r  rl  ro  rr  ru  zmistral-commonc                    t        |t        t        f      s|g}t        | d      r| j                  n| j
                  j                  }g }|D ]_  }t        |t              r|j                  |j                  }}nt        |   \  }} |       r@|j                  |j                  |             a |rt        dj                  |            y)a  
    Method that automatically raises in case the specified backends are not available. It is often used during class
    initialization to ensure the required dependencies are installed:

    ```py
    requires_backends(self, ["torch"])
    ```

    The backends should be defined in the `BACKEND_MAPPING` defined in `transformers.utils.import_utils`.

    Args:
        obj: object to be checked
        backends: list or tuple of backends to check.
    __name__ N)r  listtupler`   r  	__class__Backendis_satisfiederror_messageBACKENDS_MAPPINGappendformatr  join)objrx   namefailedr   r   r  s          r(   requires_backendsr  7  s     hu.:"3
33<<9O9ODF ,gw'$1173H3HsI-g6NIs{MM#**T*+, "''&/** r8   c                   &     e Zd 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.
    Tc                     |j                  d      r|dk7  s|dk(  s
|dk(  s|dk(  rt        | 	  |      S t        | | j                         y )Nr   _from_configis_dummymrocall)
startswithsuper__getattribute__r  	_backends)clskeyr
  s     r(   r  zDummyObject.__getattribute__a  sM    NN3C>$9cZ>OSVZ_S_cfjpcp7+C00#s}}-r8   )r  
__module____qualname____doc__r  r  __classcell__r
  s   @r(   r  r  Y  s    
 H. .r8   r  c                        e Zd ZdZ	 	 	 ddedededej                  j                  dz  de	ee
f   dz  de	eee   f   dz  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_objectsexplicit_import_shortcutc                    t         |   |       i | _        |r|ni | _        t	        d |D              r8t               | _        i | _        g | _        i }|j                         D ]  \  }}	g }
t        t        t        |	j                               D cg c]@  }t        |j                  d      dz         D cg c]  }|j                  d|      d    c}B c}}       }|D ]j  t         v rt            \  }}n:t	        fddD              rt#              j$                  }nt'        d       	  |       s|
j)                         l | j                  j/                  |      | _        |	j                         D ]_  \  }}|
r|
| j                  |<   |D ]#  }|| j                  |<   |
s|
| j                  |<   % |j1                  |g       j3                  |       a | j                  j3                  |t        t        |	j5                                z          || _        || _        t:        j<                  j?                  |      g| _         |i n|| _!        || _"        || _#        y t        |j                               | _        i | _        |j                         D ]  \  }}|D ]  }|| j                  |<     t        |j                               t        t        |j5                                z   | _        || _        || _        t:        j<                  j?                  |      g| _         |i n|| _!        || _"        || _#        y c c}w c c}}w # t*        t,        f$ r |
j)                         Y w xY w)Nc              3   <   K   | ]  }t        |t                y wr   r  	frozenset).0r"  s     r(   	<genexpr>z'_LazyModule.__init__.<locals>.<genexpr>  s     Fcz#y)F   r  r   r   c              3   &   K   | ]  }|v  
 y wr   r  r3  r"  r   s     r(   r4  z'_LazyModule.__init__.<locals>.<genexpr>  s     I#sg~I   =<>FBackend should be defined in the BACKENDS_MAPPING. Offending backend: )$r  __init___object_missing_backend_explicit_import_shortcutr   set_modules_class_to_module__all__itemsr   r  keysrangecountrsplitr  r  r  r  r  ModuleNotFoundErrorr   union
setdefaultextendvalues__file____spec__r3   pathdirname__path___objects_name_import_structure)selfr  r*  r+  r,  r-  r.  rV  rx   modulemissing_backendskimodule_keysr  r   r"  rN  valuer   r
  s                      @r(   r>  z_LazyModule.__init__r  sV    	')$E])Ace&F5EFFEDM$&D!DL "$4$:$:$< 5P &#% " "\`agalalan\opWX%q@P:QRQQXXc1-a0Rpq  ( 9G"22&6w&?!III&-g&6G'.';';H","hiphq r# 9'z,33G<9$ !% 3 3K @#)<<> IKC'<L44S9!' S7:--e4+BRD88?S &00b9@@HI ##K#eV]]_6M2N$NOk5Pn (DM'DMWW__[9:DM"/"7B]DMDJ%6D"   0 5 5 78DM$&D!/557 7V# 7E36D))%077   0 5 5 784GWG^G^G`@a;bbDL'DM'DMWW__[9:DM"/"7B]DMDJ%5D"s Sp$ 0> 9(//89s*   $M9MM8MM M<;M<c                 r    t         |          }| j                  D ]  }||vs|j                  |        |S r   )r  __dir__rD  r  )rW  resultattrr
  s      r(   r_  z_LazyModule.__dir__  s?    " LL 	$D6!d#	$ r8   r   c           
      >   || j                   v r| j                   |   S || j                  v rl| j                  |    G fddt              }||_        || j                  vrd| }n%| j                  |   }|j                  d      sd| }||_        |}n|| j                  v r-	 | j                  | j                  |         }t        ||      }n]|| j2                  v r	 | j                  |      }n;|j                  d      rZ|d d }|| j                  v rG	 | j                  | j                  |         }t        ||      }t        | ||       t        | ||       |S d }|j                  d      s|j                  d      rS|j                  d      r|d d n|}
	 ddlm} |
|v r/||
   }|j                  j#                  d	d
      }| d}|g}|j%                         D ]&  \  }}||u s||
k7  s||vs|j'                  |       ( |D ]  }|| j                  v r[	 | j                  | j                  |         }t        ||      }|}t        | ||       |
|k7  rt        | |
|       t        | ||        n_	 t4        j6                  j9                  d      }|r;t;        ||      r/t        ||      }|}|
|k7  rt        | |
|       t        | ||        n |9| j>                  j%                         D ]  \  }}||v s| j                  |      } n |t        d| j                   d|       t        | ||       |S # t        t        t        f$ r}|j                  d      r|d d }	 || j                  v r+| j                  | j                  |         }t        ||      }	n*| j                  | j                  |         }t        ||      }	t        | ||	       |	}n!# t        $ r d }||j                  d      r|d d }
	 ddlm} |
|v r||
   }|j                  j#                  d	d
      }| d}|g}|j%                         D ]&  \  }}||u s||
k7  s||vs|j'                  |       ( dd l}|D ],  }d }|j                  d      re|d d j+                         }d| d| }	  |j,                  |      }t        ||      }n*# t        $ r t.        j1                  | d| d       Y nw xY w|f|| j                  v rX	 | j                  |   }| j                  |      }t        ||      }n*# t        $ r t.        j1                   d| d       Y nw xY w|t.        j1                  d|        |}t        | ||       |
|k7  rt        | |
|       t        | ||        n n.# t        $ r"}t.        j1                  d|        Y d }~nd }~ww xY w|t        d| d      Y nw xY wt        d| d      |Y d }~d }~ww xY w# t        t        f$ r}t        d| d      |d }~ww xY w# t        $ r&}t.        j1                  d| d|        Y d }~ d }~ww xY w# t        $ r Y gw xY w# t        $ r Y ww xY w# t<        t        f$ r Y w xY w)Nc                   $    e Zd ZW  Z fdZd Zy),_LazyModule.__getattr__.<locals>.Placeholderc                     t        |        y r   )r  )rW  r   r   rY  s      r(   r>  z5_LazyModule.__getattr__.<locals>.Placeholder.__init__  s    %d,<=r8   c                      y r   r  )rW  r   r   s      r(   r  z1_LazyModule.__getattr__.<locals>.Placeholder.call  s    r8   N)r  r#  r$  r   r>  r  )rY  s   r(   Placeholderrd    s    ,	>r8   rg  )	metaclasstransformers.TokenizerFastr   )SLOW_TO_FAST_CONVERTERS	Converterr  	Tokenizerr   iztransformers.models.z.tokenization_z does not have z	 defined.z definedzskipping candidate z"Could not create tokenizer alias: zCould not import module 'z4'. Are this object's requirements defined correctly?zCould not load fallback z: transformerszmodule z has no attribute ) rT  r?  r  r  rC  r  r#  _get_moduler   rJ  r   r  endswithsetattrr   convert_slow_tokenizerrl  r   rE  r  r   r5   r   r   r    rB  r  r  r   r`   r  r@  )rW  r  rg  module_namer]  rX  efallback_name	fb_modulefallback_valuelookup_namerl  converter_classconverter_base_namepreferred_tokenizer_namecandidate_namestokenizer_nametokenizer_converterr   candidate_namebase_tokenizer_class
model_namemodule_pathalias_module_namealias_moduletransformers_moduler"  rN  rY  s                               @r(   __getattr__z_LazyModule.__getattr__  s   4== ==&&4///#;;DA  $(K 4000 -dV4"33D9"--o>$1+"?K%0K"ET***[))$*?*?*EF-v T]]"((. }}_- $Sb	 D$9$99V$($4$4T5J5J=5Y$Z	 '	= AmU;dE2$
 E}}[)T]]?-K+/==+Id3Bit8P #&==*A+*N
 />.F.F.N.N{\^._+6I5J)3T0 ,D*DCZC`C`Cb K?N,?2oE.\gJg#1#H$3$:$:>$JK /> -N-1F1FF!-373C3CDDYDYZhDi3jL;B<Q_;`$8,@E %,D.BV$W'2n'D(/k5(I$+D$$>$)!-:=++//.:Y$7':wGZ\j?k?FGZ\j?k(<0D+6.+H,3D+u,M(/dE(B(-;-F }#'#A#A#G#G#I KCv~ $ 0 0 5
 }$wt}}o=OPTv%VWWdE"u (~F X ==1$("IMM%(D,A,AA(,(8(89N9N}9](^I-4Y-NN%)%5%5d6K6KD6Q%RF-4V]-KNm^D .$ D% !% =T]]?-K*.s)K8W \#.2I#I6Mk6ZO:I:R:R:Z:Z[fhj:k$7BUAVV_?`$<7O6POOfOlOlOn %W(K8K+>/+QVdhsVs/=_/T0?0F0F~0V%W %5:I %%.?C(< ,:+B+B;+O9G9M9S9S9UJ<PQ[P\\jkujv:wK-w9P9P9PQ\9]GNvWeGf0D3< -w06}O\j[kkt=u0v-w ,@+GN^b^s^sLs-2DHDYDYZhDi0A?C?O?OPa?bGN|]kGl0D3< -2067H6IYgXhhp4q12-2 ,@+G,2LL;N~N^9_,`,4 1E(/nFZ([+6.+H,3D+u,M(/dE(B(-K%%.L $- W &/QRSQT-U V VW !="5";D6Au v##$% )CD%L .3D69mnmXz (6 )/v5ij  % V'?bQRPS%TUUVZ (1 !-$,!-" (1 !-$,!-#^4 sd  (*M  #X AX7 AZ	 .Z	 4Z	 9&Z	  AY)8Z	 ;AY9Z	  XX-A2O!X!&W/AV,V,V,"AV,.SV,$S4	1V,3S4	4V,,T54V,5$U	V,U	AV,+W/,	W5WW/WW/,X.W//XXX4X//X47	Y& Y!!Y&)	Y62Z	 5Y66Z	 9	ZZ	 ZZ	 	ZZrt  c                 p    	 t        j                  d|z   | j                        S # t        $ r}|d }~ww xY wNr  )r   r   r  r   )rW  rt  ru  s      r(   rp  z_LazyModule._get_module  s8    	**3+<dmmLL 	G	s   "% 	505c                 `    | j                   | j                  | j                  | j                  ffS r   )r
  rU  rO  rV  rW  s    r(   
__reduce__z_LazyModule.__reduce__  s&    T]]D<R<R STTr8   )NNN)r  r#  r$  r%  r   IMPORT_STRUCTURE_Tr   	machinery
ModuleSpecdictobjectr  r>  r_  r	   r  rp  r  r&  r'  s   @r(   r)  r)  k  s     >B26@Da6a6 a6 -	a6
 ((33d:a6 CK(4/a6 #'sDI~"6"=a6HY Y Yvs Ur8   r)  c                       e Zd ZdZy)OptionalDependencyNotAvailablezPInternally used error class for signalling an optional dependency was not found.N)r  r#  r$  r%  r  r8   r(   r  r    s    Zr8   r  rQ  c                 *   d}t         j                  j                  | |      }t        j                  j                  ||| g      }t        j                  j                  |      }|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
    ro  )submodule_search_locations)r3   rQ  r  r   r   spec_from_file_locationmodule_from_specloaderexec_moduler  r  )rQ  filer  locationr!   rX  s         r(   direct_transformers_importr    su     Dww||D$'H>>11$^b]c1dD^^,,T2FKKF#[[FMr8   c                       e Zd Zej                  Zej                  Zej                  Z	ej                  Zej                  Zej                  Zededd fd       Zy)VersionComparisonversion_stringr   c                 p   t         j                  j                  t         j                  j                  t         j                  j                  t         j                  j                  t         j
                  j                  t         j                  j                  t         j                  j                  d}||    S )N)r:  z==z!=r<  r;  z>=z<=)r  EQUALr]  	NOT_EQUALGREATER_THAN	LESS_THANGREATER_THAN_OR_EQUALLESS_THAN_OR_EQUAL)r  string_to_operators     r(   from_stringzVersionComparison.from_string  s     #((..#))//#--33"//55",,22#99??#66<<
 ".11r8   N)r  r#  r$  operatoreqr  ner  gtr  ltr  ger  ler  staticmethodr   r  r  r8   r(   r  r    s[    KKEI;;LI$KK!2C 2,? 2 2r8   r  c                     d}t        j                  ||       }|r2|j                  d      |j                  d      |j                  d      fS t        d|        )Nz#([a-zA-Z0-9_-]+)([!<>=~]+)([0-9.]+)r   r   r   z Invalid package version string: )rematchgroupr  )package_version_strpatternr  s      r(   split_package_versionr    sU    4GHHW12EAAA??;<O;PQRRr8   c                   L    e Zd ZdefdZdefdZdefdZdefdZe	d        Z
y)	r  backend_requirementc                     t        |      \  | _        | _        | _        | j                  t        vrt        d| j                         y )NzGBackends should be defined in the BACKENDS_MAPPING. Offending backend: )r  package_nameversion_comparisonr
   r  r  )rW  r  s     r(   r>  zBackend.__init__  sO    CXYlCm@42DL$44YZ^ZkZkYlm  5r8   r   c                 p    t        | j                  d      \  }}|st        d| j                   d      |S )z5Return the currently installed version of the backendTrG   zBackend z is not available.)r)   r  r   )rW  rL   current_versions      r(   get_installed_versionzBackend.get_installed_version	  s?    (=d>O>O`d(e%o$*;*;)<<NOPPr8   c                     t        j                  | j                        t        j                  | j                               t        j                  | j                              S r   )r  r  r  r
   rH   r  r  s    r(   r  zBackend.is_satisfied	  sD     ,,T-D-DEMM$4467t||9T
 	
r8   c                 d    d| j                    dt        | j                      d| j                   dS )Nz	Backend("z", z, "z"))r  r  r  r
   r  s    r(   __repr__zBackend.__repr__	  s;    4,,-S1B4CZCZ1[0\\_`d`l`l_mmoppr8   c                 T    d| j                    d| j                   | j                   dS )Nz{0} requires the z library version zC. That library was not found with this version in your environment.)r  r  r
   r  s    r(   r  zBackend.error_message	  s>     "$"3"3!44EdF]F]E^_c_k_k^l mL M	
r8   N)r  r#  r$  r   r>  r  boolr  r  propertyr  r  r8   r(   r  r    sH    C s 
d 

q# q 
 
r8   r  r  )rx   c                    t        | t              st        d      g | D ]X  t        v rj	                         t        fddD              rj	                  t                     Lt        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 '@requires' string is used to dynamically import objects
    zBackends should be a tuple.c              3   &   K   | ]  }|v  
 y wr   r  r7  s     r(   r4  zrequires.<locals>.<genexpr>,	  s     =c3'>=r8  r9  r=  c                     | _         | S r   )
__backends)funapplied_backendss    r(   inner_fnzrequires.<locals>.inner_fn1	  s    )
r8   )r  r	  	TypeErrorr  r  r   r  r  )rx   r  r  r   s     @@r(   requiresr  	  s     h&566 u&&##G,=_== ''(89 #ijqir!sttu Or8   c                 
    d| v S )N	modeling_r  ru  s    r(   <lambda>r  9	  s    kQ r8   ra   c                 J    | j                  d      xr | j                  d      S )Ntokenization__fastr  rq  r  s    r(   r  r  :	  s    all?+C

70C r8   )r6  c                 J    | j                  d      xr | j                  d      S )Nimage_processing_r  r  r  s    r(   r  r  ;	  s    all./GAJJw4G r8   )r  rF   rE  c                 $    | j                  d      S )Nr  r  r  s    r(   r  r  <	      all./ r8   )r  c                 $    | j                  d      S )Nvideo_processing_r  r  s    r(   r  r  =	  r  r8   c                 \   d| vrg S d}| j                         }t        |      D ]  \  }}|j                  d      s|} |g S ||d }|d   j                  d      st        d      |d   j	                  d      rR|d   j                  d      d   j                  d      j                  d	      D cg c]  }|j                  d
       c}S g }t        dt        |            D ]?  }||   j                         dk(  r|c S |j                  ||   j                  d             A |S c c}w )z
    Returns the content of the __all__ variable in the file content.
    Returns None if not defined, otherwise returns a list of strings.
    rD  Nr   z`fetch__all__ accepts a list of lines, with the first line being the __all__ variable declaration]r:  r   z [],z"' z"', )

splitlines	enumerater  r  rq  splitstriprG  lenr  )file_contentstart_indexlinesr   liner  _all__all__line_indexs           r(   fetch__all__r  A	  sI    $	K##%E '  t??9%K 
 	+,E8y)n
 	

 Qx-21X^^C-@-C-I-I%-P-V-VWZ-[\c		&!\\ !&q#e*!5 	E&'--/36E"34::7CD		E  ]s   3D)c                 ^	   i }t         j                  j                  |       rt         j                  j                  |       } | }g }t        j                  |       D ]  }|dk7  rjt         j                  j                  t         j                  j                  | |            r-t        t         j                  j                  | |            ||<   rt         j                  j                  t         j                  j                  ||            r|j                  |        d|v r|j                  d       d } |d|      r |d|      r|D cg c]	  }d|vs| }}i }|D ]-  }|j                  d      st        t         j                  j                  ||      d      5 }|j                         }	d	d	d	       |d	d
 }d}
d}d}t        j                         D ]  \  }} ||      s|} n t               }d	v r5|	j!                  d      }t#        |      D ]  \  }}|j%                  d      r|j%                  d      s*d}d|
v rd}d|
v r||
j!                  d      d   j!                  d      d   j!                  d      d   }t'        t)        |j!                  d      D cg c]  }|s|j+                  d       c}            }nd||dz      v rg }||| D ]  }d|v r|j!                  d      d   }d|v sd|v rLd|v r(|j-                  d |j!                  d      D               n |j                  |j+                  d             |j+                         dk(  s n t'        |      }nd}t/        ||z         }||vri ||<   |||   vrt               ||   |<   |j%                  d      s|j%                  d      sd }nc|j%                  d      rd!nd"}||d	 j!                  d      d   j+                  d#      }||   |   j1                  |       |j1                  |       |r|}
|} d$|	v st3        |	      D ]I  }||vst/        |      }||vri ||<   |||   vrt               ||   |<   ||   |   j1                  |       K 0 i ||}|S c c}w # 1 sw Y   xY wc c}w )%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 `@require` 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 `@require`, if they are exported with that decorator. This `@require` 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 `tokenization_*_fast.py`, it will have a `tokenizers` backend
       - If a file is named like `image_processing*_fast.py`, it will have a `torchvision` + `torch` 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'}
            },
            frozenset({'tokenizers'}): {
                'tokenization_albert_fast': {'AlbertTokenizer'}
            },
        },
        'align': {
            frozenset(): {
                'configuration_align': {'AlignConfig', 'AlignTextConfig', 'AlignVisionConfig'},
                'processing_align': {'AlignProcessor'}
            },
        },
        'altclip': {
            frozenset(): {
                'configuration_altclip': {'AltCLIPConfig', 'AltCLIPTextConfig', 'AltCLIPVisionConfig'},
                'processing_altclip': {'AltCLIPProcessor'},
            }
        }
    }
    __pycache____init__.pyc                 ,     t         fd|D              S )Nc              3   &   K   | ]  }|v  
 y wr   r  )r3  r   	substrings     r(   r4  zLcreate_import_structure_from_path.<locals>.find_substring.<locals>.<genexpr>	  s     1a9>1r8  )r   )r  list_s   ` r(   find_substringz9create_import_structure_from_path.<locals>.find_substring	  s    15111r8   modular_r  z.pyzutf-8)encodingNr  r   r  z	@requires
) 	@)Frx   z	backends=r   (r  z, z'",r:  "'c              3   >   K   | ]  }|j                  d         yw)()"', N)r  )r3  r   s     r(   r4  z4create_import_structure_from_path.<locals>.<genexpr>
  s     3uQXGMM)4L3us   r  classdefTr   r   :rD  )r3   rQ  isfilerR  listdirisdirr  !create_import_structure_from_pathr  removerq  openreadBASE_FILE_REQUIREMENTSrE  rA  r  r  r  r	  sortedr  rM  r2  addr  )r  r+  	directoryadjacent_modulesfr  rX  module_requirementsrt  r  previous_lineprevious_indexbase_requirementsstring_checkrequirementsexported_objectsr  r   r  	skip_linebackends_stringbrx   backend_liner  object_name_all_objects                              r(   r  r  k	  s   j 	ww~~k"ggook2IZZ$ '"''--[!0L"M"CBGGLLQ\^_D`"aQrww||Iq9:##A&' ((.2 j"23{Td8e1A^vZW]E]F^^' oP##E*"'',,y+6I 	$Q668L	$ "#2&
 *@*F*F*H 	&L,K($0!	 5,& &&t,E(/ F+t ??#89$//R]B^
 "	-/ %I "]2*7*=*=k*J1*M*S*STW*XYZ*[*a*abe*fgh*i#(/J_J_`dJe0kQij0k)l#m" $u^a-?'@@#%,1.,G &L)\9/;/A/A#/Fq/I"l2c\6I#'<#7$,OO3u\h\n\nos\t3u$u$,OOL4F4Fy4Q$R  ,113s: %& $)? $&(4E)EFH'::8:+H5"*=h*GGEHU+H5kB??73DOOE<R$(	+/??7+Ca&*;<&8&>&>s&CA&F&L&LS&Q+H5kBFF{S(,,[9 $(M%*NMF+T $+L9 P&66():;H'::8:+H5"*=h*GGEHU+H5kB'1+>BB;OPOoPb C-B1ABk _	$ 	$P 1ls$   	RR R#R*+R*R'	c                     fddfd	| }t        d      D ]
  } |      } i }|j                         j                         D ]$  \  }}t        |t              r||=  |      ||<   & |S )ae  
    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'}
            },
            frozenset({'tokenizers'}): {
                'tokenization_albert_fast': {'AlbertTokenizer'}
            },
        },
        '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': {'AlbertTokenizer'}
        },
        frozenset(): {
            'albert.configuration_albert': {'AlbertConfig'},
            'align.processing_align': {'AlignProcessor'},
            'align.configuration_align': {'AlignConfig', 'AlignTextConfig', 'AlignVisionConfig'},
            'altclip.configuration_altclip': {'AltCLIPConfig', 'AltCLIPTextConfig', 'AltCLIPVisionConfig'},
            'altclip.processing_altclip': {'AltCLIPProcessor'}
        }
    }

    c                 |   i }| j                         D ]$  \  }}t        |t              s|||<   t        d |D              r|j                         D ]  \  }}t        |t              r0||vri ||<   |||   vri ||   |<   ||   |   j                  |       F 	||i      }|j                         D ]t  \  }}t        |t              r0||vri ||<   |||   vri ||   |<   ||   |   j                  |       F||vri ||<   |||   vri ||   |<   ||   |   j                  |       v   	|      ||<   ' |S )Nc              3   <   K   | ]  }t        |t                y wr   r1  )r3  vs     r(   r4  zGspread_import_structure.<locals>.propagate_frozenset.<locals>.<genexpr>h
  s     >!Z9->r5  )rE  r  r  r   r2  update)
unordered_import_structure frozenset_first_import_structure_key_valuerZ  r"  propagated_frozensetr_kr_vpropagate_frozensets
            r(   r+  z4spread_import_structure.<locals>.propagate_frozenseta
  s   +-(6<<> +	ULD&fd+9?06>v>>"LLN "XDAq!!Y/$DDBD<Q?'G'JJHJ<Q?E8;DAHHK 0CAq6/J,(<(B(B(D XHC)$	:#&.N#NLN$DS$I#'/OPS/T#TRT$DS$I$$O !A Ed K R RSV W#'/O#OMO$DT$J#&.Nt.T#TRT$DT$J3$O !A Fs K R RSV W!X%"XJ :MV9T06W+	UZ 0/r8   c                     g }| j                         D ]Z  \  }}|| d| n|}t        |t              r'|j                   ||      j                                H|j	                  ||f       \ t        |      S r  )rE  r  r  rM  r  )_dictprevious_keyrE  r&  r'  flatten_dicts        r(   r/  z-spread_import_structure.<locals>.flatten_dict
  sz    !KKM 	-LD&/;/Gl^1TF+TD&$'\&$7==?@dF^,	- E{r8   r   r   )rG  copyrE  r  r   )nested_import_structureordered_import_structurer[  flattened_import_structurer"  r]  r/  r+  s         @@r(   spread_import_structurer4  2
  s    ^/0b  7 1X Q#67O#P Q "$.335;;= B
Uc3(-.:5.A&s+	B &%r8   r  prefixc                     t        |       }t        |      }||S |j                         D ci c]/  \  }}||j                         D ci c]  \  }}| d| | c}}1 }}}}}|S c c}}w c c}}}}w )a  
    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': {'AlbertTokenizer'}
        },
        frozenset(): {
            'albert.configuration_albert': {'AlbertConfig'},
            '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.

    If `prefix` is not None, it will add that prefix to all keys in the returned dict.
    r  )r  r4  rE  )r  r5  r+  spread_dictrZ  r"  kkvvs           r(   define_import_structurer:  
  s    0 9E)*:;K~U`UfUfUhiiTQPQqaggiHFBfXQrd+R/HHii Iis   A1
A+A1
+A1
c                     t         j                  D  cg c]  } | j                  d      s|  }} |D ]=  } t         j                  |    }t        |t              ri |_        t         j                  | = ? dt         j                  v r@t         j                  d   }t        |t              ri |_        t        j                  |       yyc c} w )z
    Clear cached Transformers modules to allow reloading modified code.

    This is useful when actively developing/modifying Transformers code.
    ri  ro  N)r  r  r  r  r)  rT  r   reload)mod_nametransformers_modulesrX  main_modules       r(   clear_import_cacher@  
  s     69[[iHDWDWXgDhHii ) "X&fk* FOKK!" $kk.1k;/#%K %	 % js
   CC)Fr   )FF)T)r   N)r  (!  r%  importlib.machineryr   importlib.metadataimportlib.utilr  r  r3   r  rz  r  r  collectionsr   collections.abcr   enumr   	functoolsr   	itertoolsr   typesr   typingr	   packaging.versionrJ   r
   r  r   
get_loggerr  r   r   packages_distributionsr   r   r  r	  r)   r7   r>   r   rK  ENV_VARS_TRUE_AND_AUTO_VALUESr   r   upperrC   ACCELERATE_MIN_VERSIONBITSANDBYTES_MIN_VERSIONSCHEDULEFREE_MIN_VERSIONFSDP_MIN_VERSIONGGUF_MIN_VERSIONXLA_FSDPV2_MIN_VERSIONHQQ_MIN_VERSIONVPTQ_MIN_VERSIONTORCHAO_MIN_VERSIONAUTOROUND_MIN_VERSIONTRITON_MIN_VERSIONKERNELS_MIN_VERSIONrO   rR   rZ   r]   rb   rf   rh   rk   ru   r}   r   r   r   r   r   rm   r   r   r   r  r  r  r  r  r%  r)  r-  r1  r3  r8  r;  r?  rB  rF  rI  rL  rP  rS  rV  rZ  r_  rc  rf  rj  rm  rp  rs  rv  ry  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  r  r#  r&  r)  r,  r/  r2  r4  r7  r:  r=  r@  rC  rF  rI  rL  rO  rR  rU  rX  r^  ra  re  rg  rj  rm  rp  rs  rv  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  AV_IMPORT_ERRORYT_DLP_IMPORT_ERRORDECORD_IMPORT_ERRORTORCHCODEC_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_ERRORBS4_IMPORT_ERRORSKLEARN_IMPORT_ERRORDETECTRON2_IMPORT_ERRORLEVENSHTEIN_IMPORT_ERRORG2P_EN_IMPORT_ERROR!PYTORCH_QUANTIZATION_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PYDANTIC_IMPORT_ERRORFASTAPI_IMPORT_ERRORUVICORN_IMPORT_ERROROPENAI_IMPORT_ERRORPYTESSERACT_IMPORT_ERRORPYCTCDECODE_IMPORT_ERRORACCELERATE_IMPORT_ERRORESSENTIA_IMPORT_ERRORLIBROSA_IMPORT_ERRORPRETTY_MIDI_IMPORT_ERRORCYTHON_IMPORT_ERRORRJIEBA_IMPORT_ERRORPEFT_IMPORT_ERRORJINJA_IMPORT_ERRORRICH_IMPORT_ERRORMISTRAL_COMMON_IMPORT_ERRORr  r  r  r2  
BACKENDS_Tr  rA  r  r)  BaseExceptionr  r  r  r  r  r  r  r  r  r  r4  r:  r@  r  r8   r(   <module>r     s        	 	   
 # $         
		H	%  )11HHJ C  %PTVYPYJZ]aJa @Ws Wt W
W W W
 2  4 : :F8 D  

4::<  # "           D   3  
 Ts T TQU T T TC TT Td T T       $   $   J$ J J 	d
 	d 	 	 >$ > >$ > >$ > >0   0 @4 @ @. d  * \ \ \~ T  , c d  4 c d  (   $ 5 5 5 5, ad a a a a a *D * * ,? Yc YD Y Y
 ($ ( ( +T + + +T + + /E \ \$ \ \
 += XS X$ X X
 <t < < (7 U# UD U U
 -t - - 0$ 0 0 &T & & 14 1 1 14 1 1 +4 + + /4 / / . . . 1I ^3 ^d ^ ^
 0$ 0 0 ,d , , -t - - -t - - ,d , , ,d , , +T + + 0$ 0 0 L L L u$ u u
 o o
 PD P P CD C C Ed E E )4 ) ) ($ ( ( 0$ 0 0 )4 ) ) SD S S
 +T + + O O O b b b -t - - 	 	 	 +T + + +T + + ,d , , / / / )4 ) ) )4 ) ) )9 V3 Vd V V
 ' ' ' +T + + / / / 
D 
 
 1I ^3 ^d ^ ^
 4  * O4 O O gT g g
 C D   L L$ L[_ L L Ns N N N N  / / *D * * *D * * ,d , , 2D 2 2 *D * * )9 V3 Vd V V
 Xt X X )9 e3 ed e e ,d , , (d ( ( /D \ \ \ \
 N N *D * * V V
 U U
 7 7 7 )4 ) ) . . . / / / 0$ 0 0 NT N N / / / (T ( ( 0$ 0 0 +T + + K4 K K *D * * 94 9 9 +T + + . . . )4 ) ) +T + + )4 ) ) XD X X / / / ,? Yc YD Y Y
 %T % %
 /4 / / / / / +T + + .d . . W W W
 Sd S S .T . . +D + + -t - - ($ ( ( . . . St S S Z4 Z Z
 )4 ) ) / / / 3T 3 3 D  
( x   G3 G G$ $ D  8 $ t  cm $: $:3"c'1B+B $:PTU^P_ $:qu $:N   (2 22 20.d .
     $
       
    % !   
                    
 
 
 
 
 
 .	12.	!#345. 
!#345. 
+-BCD	.
 
')<=>. 
/1HIJ. 
+-BCD. 
%'9:;. 
')<=>. 
')<=>. 
/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 
#%6781.2 
/1HIJ3.4 
')<=>5.6 
#%6787.8 
/1HIJ9.: 
%';<=;.< 
13KLM=.> 
/1HIJ?.@ 
')<=>A.B 
%'9:;C.D 
/1HIJE.F 
')<=>G.H 
')<=>I.J 
#%678K.L 
%'9:;M.N 
')<=>O.P 
#%678Q.R 
+-BCDS.T 
)+?@AU.V 
)+?@AW.X 
')<=>Y.Z 
79TUV[.0 f+D.$ . s^
*d3C=&99: VU* VUr
[] [S  &2 2. S%S#2F S S
 
@  : 
C_GIk//1S '$s) 'T C CL{&|  cDj L^  B&r8   