U
    9%e                  *   @   s  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
mZ ddlmZ ddlmZ ddlmZ ddlmZmZmZ ddlmZ d	d
lmZ eeZdWeeeeeef ef dddZddddhZ e !dhZ"ej#$dd% Z&ej#$dd% Z'ej#$dd% Z(ej#$dd% Z)e*dZ+eddd\Z,Z-edZ.edZ/edZ0ej12ddk	Z3ed Z4ej12d!dk	Z5ed"Z6ej12d#dk	Z7ed$Z8ej12d%dk	Z9z ej:d%Z;e<d&e;  W nZ ej:j=k
r4   z ej:d'Z;e<d&e;  W n ej:j=k
r.   dZ9Y nX Y nX ed(Z>ed)dd\Z?Z@ed*ZAed+ZBed,ZCed-ZDed.ZEed/ZFed0ZGed1ZHed2ZIed3ZJed4ZKed5ZLed6ZMed7ZNed8ZOed9ZPed:ZQed;ZRed<ZSed=ZTed>ZUed?ZVed@ZWedAZXedBZYedCZZedDZ[ej12dEdk	Z\e\rlzej:dF W n ej:j=k
rj   dZ\Y nX ej12dGdk	Z]edHZ^edIZ_edJZ`edKZaedLZbedMZcedNZdedOZeedPZfedQZgedRZhdSZidZje'e"kre&e kredTdd\ZjZinekdU dZjdSZldZme)e kr(dZmne&e"kre'e krej12dVdk	ZmemrdWZndZlenD ]:Zozej:eoZlW  qW n ej:j=k
r   Y nX q^eldk	Zmemre*ele*dXk rekdYel dZ dZmn
ekd[ ej12d\dk	Zpz ej:d\Zqe<d]eq  W n ej:j=k
r.   dZqY nX ej12d^dk	Zrz ej:d^Zse<d_es  W n ej:j=k
r~   dZrY nX dSZtej12d`dk	pej12dadk	Zuz ej:dbZte<dcet  W n ej:j=k
r   dZuY nX dZve(e"krJedddd\ZvZwevrJededd\ZxZyexr:ekdfey dgew dh nd ZvZxdS ZyZwdZzejrve*eiZ{e{j|e{j}fe+j|e+j}fkZzdidj Z~dkdl Zdmdn Zdodp Zdqdr Zdsdt Zdudv Zdwdx Zdydz Zd{d| Zd}d~ Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Ze dXddZe dYddZe dZddZdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zed[ddZdd Zdd Zdd ZddĄ ZddƄ ZddȄ Zddʄ Zdd̄ Zdd΄ Zd\edϜddфZd]edϜddԄZddք Zdd؄ Zddڄ Zdd܄ Zddބ Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  ZȐdd Zɐdd Zʐdd Zːdd Z̐d	d
 Z͐dd Zΐdd Zϐdd ZАdd Zѐdd ZҐdd ZӐdd ZԐdZՐdZ֐dZאdZؐdZِdZڐdZېd Zܐd!Zݐd"Zސd#Zߐd$Zd%Zd&Zd'Zd(Zd)Zd*Zd+Zd,Zd-Zd.Zd/Zd0Zd1Zd2Zd3Zd4Zd5Zd6Zd7Zd8Zd9Zd:Zd;Zd<Zd=Zd>Zd?Zd@ZdAZedeeffd!eeffd"eeffd$eeffd\eeffd%eeffddeeffd(eeffd6eeffd8eeffd^eeffdBeeffd/eeffdCeeffd;eeffd<eeffd@eeffd>eeffdCeeffdEeeffdDeeffdKeeffdEeeffdLeeffdNeeffd0eeffd1eeffdOeeffdTeeffdReeffdFeeffdBeeffdeeffdbeeffd#eeffdGeeffd*eeffd7eeffdHeeffg'ZdIdJ ZG dKdL dLe ZdMdN ZG dOdP dPeZG dQdR dReZd^eedTdUdVZdS (_  zD
Import utilities: Utilities related to imports and our lazy inits.
    N)OrderedDict)	lru_cache)chain)
ModuleType)AnyTupleUnion)version   )loggingF)pkg_namereturn_versionreturnc                 C   st   t j| d k	}d}|r`zt j| }d}W n t jjk
rH   d}Y nX td|  d|  |rl||fS |S d S )NN/ATFz	Detected z	 version 	importlibutil	find_specmetadatar	   PackageNotFoundErrorloggerdebug)r   r   Zpackage_existspackage_version r   ^/var/www/html/Darija-Ai-API/env/lib/python3.8/site-packages/transformers/utils/import_utils.py_is_package_available)   s    
r   1ONZYESTRUEZAUTOUSE_TF	USE_TORCHZUSE_FLAXFORCE_TF_AVAILABLEz1.10Z
accelerateT)r   ZapexZbitsandbytesZ
flash_attnZbs4ZcoloredlogsZcv2ZdatasetsZdecordZ
detectron2Zfaissz$Successfully imported faiss version z	faiss-cpuZftfyintel_extension_for_pytorchZjiebaZjinja2ZkenlmZ	keras_nlpZLevenshteinZlibrosaZnattenZnltkZonnxZopenaiZoptimumZ	auto_gptqZpandasZpeftZ
phonemizerZpsutilZpy3nvmlZpyctcdecodeZpytesseractZpytestZpytorch_quantizationZrjiebaZ
sacremosesZsafetensorsZscipyZsentencepieceZseqioZsklearnzscikit-learnZsmdistributedZ	soundfileZspacyZ	sudachipyZtensorflow_probabilityZtensorflow_textZtf2onnxZtimmZ
tokenizersZ
torchaudioZ
torchdistxZtorchvisionr   torchz'Disabling PyTorch because USE_TF is set
tensorflow)r$   ztensorflow-cpuztensorflow-gpuz
tf-nightlyztf-nightly-cpuztf-nightly-gpuzintel-tensorflowzintel-tensorflow-avx512ztensorflow-rocmztensorflow-macosztensorflow-aarch642z"TensorFlow found but with version z*. Transformers requires version 2 minimum.z-Disabling Tensorflow because USE_TORCH is setZessentiaz'Successfully imported essentia version Zpretty_midiz*Successfully imported pretty_midi version Z	torch_cclZoneccl_bindings_for_pytorchZoneccl_bind_ptz Detected oneccl_bind_pt version ZflaxZjaxzJAX version z, Flax version z available.c                   C   s   t S N)_kenlm_availabler   r   r   r   is_kenlm_available   s    r(   c                   C   s   t S r&   )_cv2_availabler   r   r   r   is_cv2_available   s    r*   c                   C   s   t S r&   )_torch_availabler   r   r   r   is_torch_available   s    r,   c                   C   s   t S r&   )_torch_versionr   r   r   r   get_torch_version   s    r.   c                   C   s   t S r&   )_torchvision_availabler   r   r   r   is_torchvision_available  s    r0   c                   C   s   t S r&   )_pyctcdecode_availabler   r   r   r   is_pyctcdecode_available  s    r2   c                   C   s   t S r&   )_librosa_availabler   r   r   r   is_librosa_available  s    r4   c                   C   s   t S r&   )_essentia_availabler   r   r   r   is_essentia_available  s    r6   c                   C   s   t S r&   )_pretty_midi_availabler   r   r   r   is_pretty_midi_available  s    r8   c                  C   s    t  rdd l} | j S dS d S Nr   F)r,   r#   cudais_availabler#   r   r   r   is_torch_cuda_available  s    
r=   c                  C   s*   t  r&dd l} t| jdr&| jj S dS )Nr   mpsF)r,   r#   hasattrbackendsr>   r;   r<   r   r   r   is_torch_mps_available   s
    rA   c                  C   s~   t  s
dS dd l} | j rv| jjd k	rv| j| j jdk rDdS t| jj	dd dk rbdS t
| jjdszdS ndS dS )NFr      .   autocastT)r,   r#   r:   r;   r	   get_device_propertiescurrent_devicemajorintsplitr?   ampr<   r   r   r   is_torch_bf16_gpu_available)  s    rL   c                  C   s<   t  s
dS dd l} z| jjj}W n tk
r6   Y dS X dS NFr   T)r,   r#   cpurK   rE   AttributeError)r#   _r   r   r   is_torch_bf16_cpu_availableE  s    rQ   c                   C   s   t dt t S )NzThe util is_torch_bf16_available is deprecated, please use is_torch_bf16_gpu_available or is_torch_bf16_cpu_available instead according to whether it's used with cpu or gpu)warningswarnFutureWarningrL   r   r   r   r   is_torch_bf16_availableT  s
    rU   c                  C   s   t  s
dS dd l} | j r(| jjd kr,dS | j| j jdk rHdS t| jj	dd dk rfdS t
t
| jjt
dk rdS dS )NFr   rB   rC   rD   z1.7T)r,   r#   r:   r;   r	   rF   rG   rH   rI   rJ   parse__version__base_versionr<   r   r   r   is_torch_tf32_available_  s    rY   c                   C   s   t S r&   )_torch_fx_availabler   r   r   r   is_torch_fx_availableq  s    r[   c                   C   s   t S r&   )_peft_availabler   r   r   r   is_peft_availableu  s    r]   c                   C   s   t S r&   )_bs4_availabler   r   r   r   is_bs4_availabley  s    r_   c                   C   s   t S r&   )_tf_availabler   r   r   r   is_tf_available}  s    ra   c                   C   s   t S r&   )_coloredlogs_availabler   r   r   r   is_coloredlogs_available  s    rc   c                   C   s   t S r&   )_tf2onnx_availabler   r   r   r   is_tf2onnx_available  s    re   c                   C   s   t S r&   )_onnx_availabler   r   r   r   is_onnx_available  s    rg   c                   C   s   t S r&   )_openai_availabler   r   r   r   is_openai_available  s    ri   c                   C   s   t S r&   )_flax_availabler   r   r   r   is_flax_available  s    rk   c                   C   s   t S r&   )_ftfy_availabler   r   r   r   is_ftfy_available  s    rm   c                 C   s\   t sdS tjddk	rX| rTz ddlm  m} | }W dS  tk
rR   Y dS X dS dS )zQChecks if `torch_xla` is installed and potentially if a TPU is in the environmentFZ	torch_xlaNr   T)	r+   r   r   r   Ztorch_xla.core.xla_modelcoreZ	xla_modelZ
xla_deviceRuntimeError)check_deviceZxmrP   r   r   r   is_torch_tpu_available  s    rq   c                 C   s   t jdd k	rt| S dS )NZtorch_neuronxF)r   r   r   rq   )rp   r   r   r   is_torch_neuroncore_available  s    rr   c                 C   sn   t rtjddkrdS ddl}ddl}| rZz|j }|j W S  t	k
rX   Y dS X t
|dol|j S )zQChecks if `torch_npu` is installed and potentially if a NPU is in the environment	torch_npuNFr   npu)r+   r   r   r   r#   rs   rt   device_countr;   ro   r?   )rp   r#   rs   rP   r   r   r   is_torch_npu_available  s    
rv   c                  C   s8   t  s
dS zdd lm}  W dS  tk
r2   Y dS X d S rM   )r,   torch._dynamo_dynamo	ExceptionZdynamor   r   r   is_torchdynamo_available  s    r{   c                  C   s   t  s
dS dd l} t| dS )NFr   compile)r,   r#   r?   r<   r   r   r   is_torch_compile_available  s    r}   c                  C   s<   t  s
dS zdd lm}  |  W S  tk
r6   Y dS X d S NFr   )r,   rw   rx   Zis_compilingry   rz   r   r   r   is_torchdynamo_compiling  s    
r   c                   C   s$   t jdd krdS t jdd k	S )NZtorch_tensorrtFztorch_tensorrt.fxr   r   r   r   r   r   r   is_torch_tensorrt_fx_available  s    r   c                   C   s   t S r&   )_datasets_availabler   r   r   r   is_datasets_available  s    r   c                   C   s   t S r&   )_detectron2_availabler   r   r   r   is_detectron2_available  s    r   c                   C   s   t S r&   )_rjieba_availabler   r   r   r   is_rjieba_available  s    r   c                   C   s   t S r&   )_psutil_availabler   r   r   r   is_psutil_available  s    r   c                   C   s   t S r&   )_py3nvml_availabler   r   r   r   is_py3nvml_available  s    r   c                   C   s   t S r&   )_sacremoses_availabler   r   r   r   is_sacremoses_available  s    r   c                   C   s   t S r&   )_apex_availabler   r   r   r   is_apex_available  s    r   c                   C   s2   zt d  W n tk
r(   Y dS X dS dS )z
    Code comes from *torch.utils.cpp_extension.is_ninja_available()*. Returns `True` if the
    [ninja](https://ninja-build.org/) build system is available on the system, `False` otherwise.
    zninja --versionFTN)
subprocesscheck_outputrJ   ry   r   r   r   r   is_ninja_available	  s
    r   c               	   C   sT   dd } t  rtsdS | t}| t}||krPtd| d| dt d dS dS )	Nc                 S   s$   t t| jd t t| j S )NrC   )strr	   rV   rH   minor)Zfull_versionr   r   r    get_major_and_minor_from_version  s    z;is_ipex_available.<locals>.get_major_and_minor_from_versionFzIntel Extension for PyTorch z needs to work with PyTorch z.*, but PyTorch z? is found. Please switch to the matching version and run again.T)r,   _ipex_availabler-   _ipex_versionr   warning)r   Ztorch_major_and_minorZipex_major_and_minorr   r   r   is_ipex_available  s    
r   c                 C   s`   t  s
dS ddl}ddl}| rLz|j }|j W S  tk
rJ   Y dS X t|do^|j S )zcChecks if `intel_extension_for_pytorch` is installed and potentially if a XPU is in the environmentFr   Nxpu)r   r"   r#   r   ru   r;   ro   r?   )rp   r"   r#   rP   r   r   r   is_torch_xpu_available(  s    
r   c                  C   s    t  s
dS dd l} to| j S r~   )r,   r#   _bitsandbytes_availabler:   r;   r<   r   r   r   is_bitsandbytes_available;  s    r   c                  C   s    t  s
dS dd l} to| j S r~   )r,   r#   _flash_attn_availabler:   r;   r<   r   r   r   is_flash_attn_availableF  s    r   c                   C   s   t S r&   )_torchdistx_availabler   r   r   r   is_torchdistx_availableP  s    r   c                   C   s   t S r&   )_faiss_availabler   r   r   r   is_faiss_availableT  s    r   c                   C   s   t S r&   )_scipy_availabler   r   r   r   is_scipy_availableX  s    r   c                   C   s   t S r&   )_sklearn_availabler   r   r   r   is_sklearn_available\  s    r   c                   C   s   t S r&   )_sentencepiece_availabler   r   r   r   is_sentencepiece_available`  s    r   c                   C   s   t S r&   )_is_seqio_availabler   r   r   r   is_seqio_availabled  s    r   c                   C   s$   t jdd krdS t jdd k	S )NZgoogleFzgoogle.protobufr   r   r   r   r   is_protobuf_availableh  s    r   min_versionc                 C   s$   | d k	r t ottt| kS t S r&   )_accelerate_availabler	   rV   _accelerate_versionr   r   r   r   is_accelerate_availablen  s    r   1.12.0c                 C   s   t  ottt| kS r&   )r,   r	   rV   r-   r   r   r   r   is_fsdp_availablet  s    r   c                   C   s   t S r&   )_optimum_availabler   r   r   r   is_optimum_availablex  s    r   c                   C   s   t S r&   )_auto_gptq_availabler   r   r   r   is_auto_gptq_available|  s    r   c                   C   s   t S r&   )_levenshtein_availabler   r   r   r   is_levenshtein_available  s    r   c                   C   s   t o
tdS )Nzoptimum.neuron)r   r   r   r   r   r   is_optimum_neuron_available  s    r   c                   C   s   t S r&   )_safetensors_availabler   r   r   r   is_safetensors_available  s    r   c                   C   s   t S r&   )_tokenizers_availabler   r   r   r   is_tokenizers_available  s    r   c                  C   s   t jdd k	} | r|zt jd}W nF t jjk
rj   zt jd}W n t jjk
rd   Y Y dS X Y nX td|  | S )NZPILZPillowzPillow-SIMDFzDetected PIL version r   )Z_pil_availabler   r   r   r   is_vision_available  s    r   c                   C   s   t S r&   )_pytesseract_availabler   r   r   r   is_pytesseract_available  s    r   c                   C   s   t S r&   )_pytest_availabler   r   r   r   is_pytest_available  s    r   c                   C   s   t S r&   )_spacy_availabler   r   r   r   is_spacy_available  s    r   c                   C   s
   t  otS r&   )ra   _tensorflow_text_availabler   r   r   r   is_tensorflow_text_available  s    r   c                   C   s
   t  otS r&   )r   _keras_nlp_availabler   r   r   r   is_keras_nlp_available  s    r   c               
   C   s   zdt jd j} d|  jkr"tddtjkr4tddtjkrTtjd dk rTtdtj	dd k	W S  t
ttfk
r   Y d	S X d S )
NZIPythonZIPKernelAppconsoleZ
VSCODE_PIDZvscodeDATABRICKS_RUNTIME_VERSIONz11.0Z
databricksF)sysmodulesget_ipythonconfigImportErrorosenvironr   r   r   rO   KeyError)r   r   r   r   is_in_notebook  s    
r   c                   C   s   t S r&   )_pytorch_quantization_availabler   r   r   r   !is_pytorch_quantization_available  s    r   c                   C   s   t S r&   )!_tensorflow_probability_availabler   r   r   r   #is_tensorflow_probability_available  s    r   c                   C   s   t S r&   )_pandas_availabler   r   r   r   is_pandas_available  s    r   c                  C   sJ   t dd} z t| } | dds*W dS W n tjk
rD   Y dS X tS )NSM_FRAMEWORK_PARAMS{}Z*sagemaker_distributed_dataparallel_enabledF)r   getenvjsonloadsgetJSONDecodeError_smdistributed_available)Zsagemaker_paramsr   r   r   is_sagemaker_dp_enabled  s    

r   c                  C   s   t dd} zt| } d| kr&W dS W n tjk
r@   Y dS X t dd}z t|}|ddslW dS W n tjk
r   Y dS X tS )NZSM_HP_MP_PARAMETERSr   Z
partitionsFr   Zsagemaker_mpi_enabled)r   r   r   r   r   r   r   )Zsmp_optionsZmpi_optionsr   r   r   is_sagemaker_mp_enabled  s    



r   c                   C   s
   dt jkS )NZSAGEMAKER_JOB_NAME)r   r   r   r   r   r   is_training_run_on_sagemaker  s    r   c                   C   s   t S r&   )_soundfile_availabler   r   r   r   is_soundfile_availble  s    r   c                   C   s   t S r&   )_timm_availabler   r   r   r   is_timm_available  s    r   c                   C   s   t S r&   )_natten_availabler   r   r   r   is_natten_available  s    r   c                   C   s   t S r&   )_nltk_availabler   r   r   r   is_nltk_available  s    r   c                   C   s   t S r&   _torchaudio_availabler   r   r   r   is_torchaudio_available
  s    r   c                   C   s   t S r&   r   r   r   r   r   is_speech_available  s    r   c                   C   s   t S r&   )_phonemizer_availabler   r   r   r   is_phonemizer_available  s    r   c                    s    fdd}|S )Nc                     s   t stdn
 | |S d S )Nz|You need to install pytorch to use this method or class, or activate it with environment variables USE_TORCH=1 and USE_TF=0.)r+   r   )argskwargsfnr   r   wrapper  s
    z"torch_only_method.<locals>.wrapperr   )r   r   r   r   r   torch_only_method  s    	r   c                   C   s   t S r&   )_is_ccl_availabler   r   r   r   is_ccl_available$  s    r   c                   C   s   t S r&   )_decord_availabler   r   r   r   is_decord_available(  s    r   c                   C   s   t S r&   )_sudachipy_availabler   r   r   r   is_sudachi_available,  s    r   c                   C   s   t jdd k	otdd k	S )NZrhoknpZjumanpp)r   r   r   shutilwhichr   r   r   r   is_jumanpp_available0  s    r  c                   C   s   t jdd k	S )NZ	pyximportr   r   r   r   r   is_cython_available4  s    r  c                   C   s   t S r&   )_jieba_availabler   r   r   r   is_jieba_available8  s    r  c                   C   s   t S r&   )_jinja_availabler   r   r   r   is_jinja_available<  s    r  z
{0} requires the OpenCV library but it was not found in your environment. You can install it with:
```
pip install opencv-python
```
Please note that you may need to restart your runtime after installation.
ub  
{0} requires the 🤗 Datasets library but it was not found in your environment. You can install it with:
```
pip install datasets
```
In a notebook or a colab, you can install it by executing a cell with
```
!pip install datasets
```
then restarting your kernel.

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

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

If you really do want to use TensorFlow, please follow the instructions on the
installation page https://www.tensorflow.org/install that match your environment.
z
{0} requires the Beautiful Soup library but it was not found in your environment. You can install it with pip:
`pip install beautifulsoup4`. Please note that you may need to restart your runtime after installation.
aC  
{0} requires the scikit-learn library but it was not found in your environment. You can install it with:
```
pip install -U scikit-learn
```
In a notebook or a colab, you can install it by executing a cell with
```
!pip install -U scikit-learn
```
Please note that you may need to restart your runtime after installation.
a!  
{0} requires the TensorFlow library but it was not found in your environment. Checkout the instructions on the
installation page: https://www.tensorflow.org/install and follow the ones that match your environment.
Please note that you may need to restart your runtime after installation.
aD  
{0} requires the detectron2 library but it was not found in your environment. Checkout the instructions on the
installation page: https://github.com/facebookresearch/detectron2/blob/master/INSTALL.md and follow the ones
that match your environment. Please note that you may need to restart your runtime after installation.
a  
{0} requires the FLAX library but it was not found in your environment. Checkout the instructions on the
installation page: https://github.com/google/flax and follow the ones that match your environment.
Please note that you may need to restart your runtime after installation.
a8  
{0} requires the ftfy library but it was not found in your environment. Checkout the instructions on the
installation section: https://github.com/rspeer/python-ftfy/tree/master#installing and follow the ones
that match your environment. Please note that you may need to restart your runtime after installation.
z
{0} requires the python-Levenshtein library but it was not found in your environment. You can install it with pip: `pip
install python-Levenshtein`. Please note that you may need to restart your runtime after installation.
a  
{0} requires the pytorch-quantization library but it was not found in your environment. You can install it with pip:
`pip install pytorch-quantization --extra-index-url https://pypi.ngc.nvidia.com`
Please note that you may need to restart your runtime after installation.
z
{0} requires the tensorflow_probability library but it was not found in your environment. You can install it with pip as
explained here: https://github.com/tensorflow/probability. Please note that you may need to restart your runtime after installation.
a  
{0} requires the tensorflow_text library but it was not found in your environment. You can install it with pip as
explained here: https://www.tensorflow.org/text/guide/tf_text_intro.
Please note that you may need to restart your runtime after installation.
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 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 NLTK library but it was not found in your environment. You can install it by referring to:
https://www.nltk.org/install.html. Please note that you may need to restart your runtime after installation.
z
{0} requires the PIL library but it was not found in your environment. You can install it with pip:
`pip install pillow`. Please note that you may need to restart your runtime after installation.
z
{0} requires the PyTesseract library but it was not found in your environment. You can install it with pip:
`pip install pytesseract`. Please note that you may need to restart your runtime after installation.
z
{0} requires the pyctcdecode library but it was not found in your environment. You can install it with pip:
`pip install pyctcdecode`. Please note that you may need to restart your runtime after installation.
z
{0} requires the accelerate library but it was not found in your environment. You can install it with pip:
`pip install accelerate`. Please note that you may need to restart your runtime after installation.
a  
{0} requires the torch ccl library but it was not found in your environment. You can install it with pip:
`pip install oneccl_bind_pt -f https://developer.intel.com/ipex-whl-stable`
Please note that you may need to restart your runtime after installation.
z
{0} requires essentia library. But that was not found in your environment. You can install them with pip:
`pip install essentia==2.1b6.dev1034`
Please note that you may need to restart your runtime after installation.
z
{0} requires thes librosa library. But that was not found in your environment. You can install them with pip:
`pip install librosa`
Please note that you may need to restart your runtime after installation.
z
{0} requires thes pretty_midi library. But that was not found in your environment. You can install them with pip:
`pip install pretty_midi`
Please note that you may need to restart your runtime after installation.
z
{0} requires the decord library but it was not found in your environment. You can install it with pip: `pip install
decord`. Please note that you may need to restart your runtime after installation.
z
{0} requires the Cython library but it was not found in your environment. You can install it with pip: `pip install
Cython`. Please note that you may need to restart your runtime after installation.
z
{0} requires the jieba library but it was not found in your environment. You can install it with pip: `pip install
jieba`. Please note that you may need to restart your runtime after installation.
z
{0} requires the peft library but it was not found in your environment. You can install it with pip: `pip install
peft`. Please note that you may need to restart your runtime after installation.
z
{0} requires the jinja library but it was not found in your environment. You can install it with pip: `pip install
jinja2`. Please note that you may need to restart your runtime after installation.
ZlevenshteinprotobufZspeechtfZvisioncythonjinjac                    s   t |ttfs|g}t| dr$| jn| jj d|krVd|krVt sVt rVtt	
 d|krd|krt rt stt
 dd |D } fdd|D }|rtd|d S )	N__name__r#   r	  c                 s   s   | ]}t | V  qd S r&   )BACKENDS_MAPPING).0backendr   r   r   	<genexpr>  s     z$requires_backends.<locals>.<genexpr>c                    s    g | ]\}}| s|  qS r   )format)r  	availablemsgnamer   r   
<listcomp>  s      z%requires_backends.<locals>.<listcomp> )
isinstancelisttupler?   r  	__class__r,   ra   r   PYTORCH_IMPORT_ERROR_WITH_TFr  TF_IMPORT_ERROR_WITH_PYTORCHjoin)objr@   Zchecksfailedr   r  r   requires_backends  s    r!  c                       s    e Zd ZdZ fddZ  ZS )DummyObjectz
    Metaclass for the dummy objects. Any class inheriting from it will return the ImportError generated by
    `requires_backend` each time a user tries to access any method of that class.
    c                    s.   | dr|dkrt |S t| | j d S )NrP   Z_from_config)
startswithsuper__getattribute__r!  Z	_backends)clskeyr  r   r   r%    s    zDummyObject.__getattribute__)r  
__module____qualname____doc__r%  __classcell__r   r   r(  r   r"    s   r"  c                 C   s    t  rdd l}t| |jjS dS r9   )r[   Ztorch.fxr  ZfxZProxy)xr#   r   r   r   is_torch_fx_proxy  s    r.  c                       sT   e Zd ZdZd fdd	Z fddZeeddd	Zed
ddZ	dd Z
  ZS )_LazyModulezu
    Module class that surfaces all objects but only performs associated imports when the objects are requested.
    Nc           	         s   t  | t| | _i | _| D ]\}}|D ]}|| j|< q4q(t| tt|	   | _
|| _|| _tj|g| _|d kri n|| _|| _|| _d S r&   )r$  __init__setkeys_modules_class_to_moduleitemsr  r   values__all____file____spec__r   pathdirname__path___objects_name_import_structure)	selfr  Zmodule_fileZimport_structureZmodule_specextra_objectsr'  r6  valuer(  r   r   r0    s    z_LazyModule.__init__c                    s,   t   }| jD ]}||kr|| q|S r&   )r$  __dir__r7  append)r@  resultattrr(  r   r   rC    s
    

z_LazyModule.__dir__)r  r   c                 C   sz   || j kr| j | S || jkr*| |}n@|| j krT| | j| }t||}ntd| j d| t| || |S )Nzmodule z has no attribute )	r=  r3  _get_moduler4  r2  getattrrO   r  setattr)r@  r  rB  moduler   r   r   __getattr__  s    


z_LazyModule.__getattr__)module_namec              
   C   sZ   zt d| | jW S  tk
rT } z"td| j d| d| |W 5 d }~X Y nX d S )NrC   zFailed to import z@ because of the following error (look up to see its traceback):
)r   import_moduler  ry   ro   )r@  rL  er   r   r   rG     s    z_LazyModule._get_modulec                 C   s   | j | j| j| jffS r&   )r  r>  r8  r?  )r@  r   r   r   
__reduce__	  s    z_LazyModule.__reduce__)NN)r  r)  r*  r+  r0  rC  r   r   rK  rG  rO  r,  r   r   r(  r   r/    s   		r/  c                   @   s   e Zd ZdZdS )OptionalDependencyNotAvailablezPInternally used error class for signalling an optional dependency was not found.N)r  r)  r*  r+  r   r   r   r   rP    s   rP  __init__.py)r:  r   c                 C   sL   d}t j| |}tjj||| gd}tj|}|j| t	j
| }|S )zImports transformers directly

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

    Returns:
        `ModuleType`: The resulting imported module
    Ztransformers)submodule_search_locations)r   r:  r  r   r   spec_from_file_locationmodule_from_specloaderexec_moduler   r   )r:  filer  locationspecrJ  r   r   r   direct_transformers_import  s    

rZ  )F)T)T)F)F)N)r   )rQ  (  r+  importlib.metadatar   importlib.utilr   r   r   r   r   rR   collectionsr   	functoolsr   	itertoolsr   typesr   typingr   r   r   	packagingr	   r  r   Z
get_loggerr  r   r   boolr   ZENV_VARS_TRUE_VALUESunionZENV_VARS_TRUE_AND_AUTO_VALUESr   r   upperr   r    ZUSE_JAXr!   rV   ZTORCH_FX_REQUIRED_VERSIONr   r   r   r   r   r   r   r^   rb   r)   r   r   r   r   r   Z_faiss_versionr   r   rl   r   r   r  r  r'   r   r   r3   r   r   rf   rh   r   r   r   r\   r   r   r   r1   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rd   r   r   r   r   r/   r-   r+   infoZ_tf_versionr`   
candidatespkgr5   Z_essentia_versionr7   Z_pretty_midi_versionZccl_versionr   rj   Z_flax_versionZ_jax_availableZ_jax_versionrZ   Ztorch_versionrH   r   r(   r*   r,   r.   r0   r2   r4   r6   r8   r=   rA   rL   rQ   rU   rY   r[   r]   r_   ra   rc   re   rg   ri   rk   rm   rq   rr   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   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  ZCV2_IMPORT_ERRORZDATASETS_IMPORT_ERRORZTOKENIZERS_IMPORT_ERRORZSENTENCEPIECE_IMPORT_ERRORZPROTOBUF_IMPORT_ERRORZFAISS_IMPORT_ERRORZPYTORCH_IMPORT_ERRORZTORCHVISION_IMPORT_ERRORr  r  ZBS4_IMPORT_ERRORZSKLEARN_IMPORT_ERRORZTENSORFLOW_IMPORT_ERRORZDETECTRON2_IMPORT_ERRORZFLAX_IMPORT_ERRORZFTFY_IMPORT_ERRORZLEVENSHTEIN_IMPORT_ERRORZ!PYTORCH_QUANTIZATION_IMPORT_ERRORZ#TENSORFLOW_PROBABILITY_IMPORT_ERRORZTENSORFLOW_TEXT_IMPORT_ERRORZPANDAS_IMPORT_ERRORZPHONEMIZER_IMPORT_ERRORZSACREMOSES_IMPORT_ERRORZSCIPY_IMPORT_ERRORZSPEECH_IMPORT_ERRORZTIMM_IMPORT_ERRORZNATTEN_IMPORT_ERRORZNLTK_IMPORT_ERRORZVISION_IMPORT_ERRORZPYTESSERACT_IMPORT_ERRORZPYCTCDECODE_IMPORT_ERRORZACCELERATE_IMPORT_ERRORZCCL_IMPORT_ERRORZESSENTIA_IMPORT_ERRORZLIBROSA_IMPORT_ERRORZPRETTY_MIDI_IMPORT_ERRORZDECORD_IMPORT_ERRORZCYTHON_IMPORT_ERRORZJIEBA_IMPORT_ERRORZPEFT_IMPORT_ERRORZJINJA_IMPORT_ERRORr  r!  typer"  r.  r/  BaseExceptionrP  rZ  r   r   r   r   <module>   s  
&












		


































-<