Ë
    S^(h‡« ã                   óŒ  — 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
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mZ d dlmZmZmZmZ d dlmZmZ d dlmZmZ d dl m!Z! d dl"m#Z# d dl$m%Z%m&Z&m'Z'm(Z( d d	lm)Z) d d
l*m+Z+ d dl,Z-d dl.Z.d dl/Z/d dl-m0Z0 d dl1m2Z2 d dl3m4Z4 d dl3mZ5 ddl6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z= ddl>m?Z? ddl@mAZAmBZBmCZCmDZDmEZEmFZFmGZGmHZHmIZImJZJmKZKmLZLmMZMmNZNmOZOmPZPmQZQmRZRmSZSmTZTmUZUmVZVmWZWmXZXmYZYmZZZm[Z[m\Z\m]Z]m^Z^m_Z_m`Z`maZambZbmcZcmdZdmeZemfZfmgZgmhZhmiZimjZjmkZkmlZlmmZmmnZnmoZompZpmqZqmrZrmsZsmtZtmuZumvZvmwZwmxZxmyZymzZzm{Z{m|Z|m}Z}m~Z~mZm€Z€m�Z�m‚Z‚mƒZƒm„Z„m…Z…m†Z†m‡Z‡mˆZˆm‰Z‰mŠZŠm‹Z‹mŒZŒm�Z�mŽZŽm�Z�m�Z�m‘Z‘m’Z’m“Z“m”Z”m•Z•m–Z–m—Z—m˜Z˜m™Z™mšZšm›Z›mœZœm�Z�mžZžmŸZŸm Z m¡Z¡  eC«       rd dl¢m£Z£m¤Z¤ d dl¥m¦Z¦  eu«       r%d dl§m¨Z¨m©Z©mªZªm«Z«m¬Z¬m­Z­m®Z® d dl¯m°Z° d dl±m²Z² d dl³m´Z´ neµZ¨eµZ´dZ¶dZ·dZ¸dZ¹dZºdZ» e‹«       r7d dl¼Z¼e¼jd                  �jz                  duZ¾e¼jd                  �j~                  duZÀndZ¾dZÀ e5�j‚                  eÂ«      ZÃ�dd „ZÄ�dd!„ZÅ eÄd"d¬#«      ZÆ eÄd$d¬#«      ZÇ eÄd%d¬#«      ZÈ eÄd&d'¬#«      ZÉ eÄd(d¬#«      ZÊ eÄd)d¬#«      ZËd*„ ZÌd+„ ZÍd,„ ZÎd-„ ZÏd.„ ZÐd/„ ZÑd0„ ZÒd1„ ZÓd2„ ZÔd3„ ZÕd4„ ZÖd5„ Z×d6„ ZØd7„ ZÙd8„ ZÚd9„ ZÛd:„ ZÜeAfd;eÝfd<„ZÞeBfd;eÝfd=„Zß�dd;eÝfd>„Zàd?„ Zád@„ ZâdA„ ZãdB„ ZädC„ ZådD„ ZædE„ ZçdF„ ZèdG„ ZédH„ ZêdIeÝfdJ„ZëdK„ ZìdL„ ZídM„ ZîdN„ ZïdO„ ZðdP„ ZñdQ„ ZòdR„ ZódS„ ZôdT„ ZõdU„ ZödV„ Z÷dW„ ZødX„ ZùdY„ ZúdZ„ Zûd[„ Züd\„ Zýd]„ Zþd^„ Zÿd_„ �Z d`„ �Zda„ �Zdb„ �Zdc„ �Zdd„ �Zde„ �Zdf„ �Zdg„ �Zdh„ �Z	di„ �Z
dj„ �Zdk„ �Zdl„ �Zdm„ �Zdn„ �Zdo„ �Zdp„ �Zdq„ �Z e‹«       �red dl¼Z¼dre
�j&                  v r'e
�j&                  dr   �Z	  e�j*                  �e«      �Zdue
�j&                  v rÄe
�j&                  du   �Z�edvk(  r*e¼�j~                  �j5                  «       s �edw�e› dx�«      ‚�edyk(  r eš«       s �edw�e› dz�«      ‚�ed{k(  r e•«       s �edw�e› d|�«      ‚�ed}k(  r e“«       s �edw�e› d~�«      ‚�edk(  r e’«       s �edw�e› d€�«      ‚	  e¼�j8                  �e«      �Zn[e¼�j~                  �j5                  «       rdv�Zn;eËr e•«       rd{�Zn.eËr e“«       rd}�Zn!eËr e’«       rd�ZneËr eš«       rdy�Znd‚�Znd�Z e‡«       rd d�l�Z eV«       rd d�l �Z  �e �jB                  «       �Z"nd�Z"dƒ„ �Z#d„„ �Z$d…„ �Z%d†„ �Z&d‡„ �Z'�ddˆ�e(fd‰„�Z)dŠ„ �Z*d‹„ �Z+dŒ„ �Z,d�„ �Z-dŽ„ �Z.d�„ �Z/d�„ �Z0d‘„ �Z1d’„ �Z2d“„ �Z3d”„ �Z4d•„ �Z5d–„ �Z6d—„ �Z7d˜„ �Z8d™„ �Z9dš„ �Z:d›„ �Z;dœ„ �Z<d�„ �Z=dž„ �Z>dŸ„ �Z?d „ �Z@d¡„ �ZAd¢„ �ZBd£„ �ZCd¤„ �ZDd¥„ �ZEd¦„ �ZFd§„ �ZGd¨„ �ZHd©„ �ZIdª„ �ZJd«„ �ZKd¬„ �ZLd­„ �ZMd®„ �ZNd¯„ �ZOd°„ �ZPd±„ �ZQd²„ �ZRd³„ �ZSd´„ �ZTdµ„ �ZUd¶„ �ZVd·„ �ZWd¸„ �ZXd¹„ �ZYdº„ �ZZd»„ �Z[�dd¼„�Z\d½e4d¾�e]fd¿„�Z^dÀ�e_�e`eÝ�e(f      d¾e�e`eÝ�e(f   ddf   fdÁ„�ZadÂ„ �ZbdÃ„ �ZcdÄ„ �ZddÅ„ �ZedÆ„ �Zf G dÇ„ dÈ«      �Zg G dÉ„ dÊ�eg«      �Zh G dË„ dÌ�eg«      �Zi G dÍ„ dÎ«      �Zje�jÖ                  dÏ„ «       �Zl G dÐ„ dÑ«      �Zme�jÖ                  dÒe(eÝe
�jÜ                  f   d¾ed   fdÓ„«       �Zo G dÔ„ dÕe�jà                  «      �ZqdÖ„ �Zre�jÖ                  d×„ «       �Zsi �ZtdØ„ �ZudÙ„ �Zvd d�lw�Zw G dÚ„ dÛ«      �ZxdÜ„ �Zy�dd¾�exfdÝ„�Zz�dd¾�exfdÞ„�Z{dß„ �Z|dà„ �Z}�ddá„�Z~dâ„ �Zdã„ �Z€ G dä„ då�e�«      �Z‚�ddæ�e_eÝ   fdç„�Zƒ G dè„ dé«      �Z„�ddê�e]dëe'�e(   dìe'eÝ   fdí„�Z…�d dê�e]dëe'�e(   fdî„�Z†dï„ �Z‡�d!dð„�Zˆdñ„ �Z‰	 dò„ �ZŠ G dó„ dôe�j                  «      �ZŒ G dõ„ döe¨«      �Z�d÷eÝdø�e`eÝe&f   fdù„�ZŽ e‹«       rpe¼�j~                  �j                  e¼�j                  e¼�j                  dúœ�Z�e¼�j~                  �j"                  dddúœ�Z’e¼�j~                  �j&                  dû„ dü„ dúœ�Z”ndýdi�Z�dýdi�Z’dýdþ„ i�Z” e’«       r8e¼�j*                  �j                  �e�d<   e¼�j*                  �j&                  �e”d<    e“«       rTe¼�j,                  �j"                  �e’d}<   e¼�j,                  �j                  �e�d}<   e¼�j,                  �j&                  �e”d}<    e•«       rTe¼�j.                  �j"                  �e’d{<   e¼�j.                  �j                  �e�d{<   e¼�j.                  �j&                  �e”d{<    eš«       rTe¼�j0                  �j"                  �e’dy<   e¼�j0                  �j                  �e�dy<   e¼�j0                  �j&                  �e”dy<    e™«       rTe¼�j~                  �j"                  �e’dÿ<   e¼�j~                  �j                  �e�dÿ<   e¼�j~                  �j&                  �e”dÿ<   d÷eÝ�d �e]f�d„�Z™d÷eÝf�d„�Zšd÷eÝf�d„�Z› e‹«       �rU�de
�j&                  v �rDe
�j&                  �d   �Zœ e#�eœ«      �j;                  «       s �e�d�eœ› �«      ‚e
�j<                  �j?                  e
�j<                  �jA                  �eœ«      «      \  �Z¡�Ze�j<                  �jE                  �e¡«       	 �eœd�eœ�jG                  �d«       �Z¤ e�j*                  �e¤«      �Z¥	 �e¥�jL                  �Z§due
�j&                  v r(�e�e§k7  r!�d	�e› �d
�e§› �d��Z©�e©�dz  �Z© �e�e©«      ‚�e§�Z�d�e`eÝe&f   �deÝf�d„�Zª �eª�e��d«        �eª�e’�d«        �eª�e”�d«       �d„ �Z«eê�dd÷eÝf�d„«       �Z¬�e­e(eÝdf   e(�e]df   f   �Z®ed¾�e®f�d„«       �Z¯ G �d„ �de�e®e%f   «      �Z°y# �e$ r�Z �eds�e› dt�e› �«      �e‚d�Z�[ww xY w# �e$ r�Z �ed��e› �«      �e‚d�Z�[ww xY w# �e$ r�Z �e�d�eœ› �«      �e‚d�Z�[ww xY w# �e¨$ r�Z �e¨�d«      �e‚d�Z�[ww xY w("  é    N)ÚUserDictÚdefaultdict)Ú	GeneratorÚIterableÚIteratorÚMapping)ÚMISSINGÚfields)ÚcacheÚwraps)ÚStringIO)ÚPath)ÚAnyÚCallableÚOptionalÚUnion)Úmock©Úpatch)Údelete_repo)Úversion)ÚTrainer)Úloggingé   )Úis_clearml_availableÚis_optuna_availableÚis_ray_availableÚis_sigopt_availableÚis_swanlab_availableÚis_tensorboard_availableÚis_wandb_available)Úis_deepspeed_available)aÚACCELERATE_MIN_VERSIONÚGGUF_MIN_VERSIONÚis_accelerate_availableÚis_apex_availableÚis_apollo_torch_availableÚis_aqlm_availableÚis_auto_awq_availableÚis_auto_gptq_availableÚis_av_availableÚis_bitsandbytes_availableÚ'is_bitsandbytes_multi_backend_availableÚis_bs4_availableÚis_compressed_tensors_availableÚis_cv2_availableÚis_cython_availableÚis_detectron2_availableÚis_eetq_availableÚis_essentia_availableÚis_faiss_availableÚis_fbgemm_gpu_availableÚis_flash_attn_2_availableÚis_flax_availableÚis_flute_availableÚis_fsdp_availableÚis_ftfy_availableÚis_g2p_en_availableÚis_galore_torch_availableÚis_gguf_availableÚis_gptqmodel_availableÚis_grokadamw_availableÚis_hadamard_availableÚis_hqq_availableÚis_ipex_availableÚis_jieba_availableÚis_jinja_availableÚis_jumanpp_availableÚis_keras_nlp_availableÚis_levenshtein_availableÚis_librosa_availableÚis_liger_kernel_availableÚis_lomo_availableÚis_natten_availableÚis_nltk_availableÚis_onnx_availableÚis_optimum_availableÚis_optimum_quanto_availableÚis_pandas_availableÚis_peft_availableÚis_phonemizer_availableÚis_pretty_midi_availableÚis_pyctcdecode_availableÚis_pytesseract_availableÚis_pytest_availableÚ!is_pytorch_quantization_availableÚis_quark_availableÚis_rjieba_availableÚis_sacremoses_availableÚis_safetensors_availableÚis_schedulefree_availableÚis_scipy_availableÚis_sentencepiece_availableÚis_seqio_availableÚis_soundfile_availableÚis_spacy_availableÚis_spqr_availableÚis_sudachi_availableÚis_sudachi_projection_availableÚ#is_tensorflow_probability_availableÚis_tensorflow_text_availableÚis_tf2onnx_availableÚis_tf_availableÚis_tiktoken_availableÚis_timm_availableÚis_tokenizers_availableÚis_torch_availableÚ!is_torch_bf16_available_on_deviceÚis_torch_bf16_cpu_availableÚis_torch_bf16_gpu_availableÚis_torch_deterministicÚ!is_torch_fp16_available_on_deviceÚis_torch_greater_or_equalÚis_torch_hpu_availableÚis_torch_mlu_availableÚis_torch_neuroncore_availableÚis_torch_npu_availableÚis_torch_sdpa_availableÚis_torch_tensorrt_fx_availableÚis_torch_tf32_availableÚis_torch_xla_availableÚis_torch_xpu_availableÚis_torchao_availableÚis_torchaudio_availableÚis_torchdynamo_availableÚis_torchvision_availableÚis_vision_availableÚis_vptq_availableÚ	strtobool)ÚAcceleratorStateÚPartialState)Úis_fp8_available)ÚModuleÚ_get_checkerÚ_get_continue_on_failureÚ_get_runnerÚ
_is_mockedÚ_patch_unwrap_mock_awareÚget_optionflags)Úskip)Úimport_path)ÚDoctestItemzjulien-c/bert-xsmall-dummyzjulien-c/dummy-unknownzjulien-c/dummy-diff-tokenizerÚ__DUMMY_TRANSFORMERS_USER__zhttps://hub-ci.huggingface.coÚ%hf_94wBhPGp6KrrTH3KDchhKpRxZwd6dmHWLLFc                 ó¢   — 	 t         j                  |    }	 t        |«      }|S # t        $ r t        d| › d�«      ‚w xY w# t        $ r |}Y |S w xY w)NúIf set, z must be yes or no.)ÚosÚenvironrƒ   Ú
ValueErrorÚKeyError©ÚkeyÚdefaultÚvalueÚ_values       úX/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/testing_utils.pyÚparse_flag_from_envrŸ   Ô   sp   € ðBÜ—
‘
˜3‘ˆð	BÜ˜uÓ%ˆFð €Møô ò 	Bä˜x¨ uÐ,?Ð@ÓAÐAð	Bûô ò à‰ð €Mðúó   ‚? –# £<¿AÁAc                 ó¢   — 	 t         j                  |    }	 t        |«      }|S # t        $ r t        d| › d�«      ‚w xY w# t        $ r |}Y |S w xY w)Nr”   z must be a int.)r•   r–   Úintr—   r˜   r™   s       rž   Úparse_int_from_envr£   ä   sj   € ð>Ü—
‘
˜3‘ˆð	>Ü˜“ZˆFð €Møô ò 	>Ü˜x¨ u¨OÐ<Ó=Ð=ð	>ûô ò Ø‰ð €Mðúr    ÚRUN_SLOW)r›   ÚRUN_CUSTOM_TOKENIZERSÚHUGGINGFACE_CO_STAGINGÚRUN_PIPELINE_TESTSTÚRUN_AGENT_TESTSÚRUN_THIRD_PARTY_DEVICE_TESTSc                 ó²   — t         s t        j                  d¬«      | «      S 	 ddl} |j                  j                  «       | «      S # t        $ r | cY S w xY w)zž
    Decorator marking a test as a staging test.

    Those tests will run using the staging environment of huggingface.co instead of the real model hub.
    ztest is staging test©Úreasonr   N)Ú_run_stagingÚunittestrŽ   ÚpytestÚmarkÚis_staging_testÚImportError©Ú	test_caser¯   s     rž   r±   r±   ù   sY   € õ Ø;Œx�}‰}Ð$:Ô;¸IÓFÐFð	<Ûð 1�6—;‘;×.Ñ.Ó0°Ó;Ð;øô ò 	ØÒð	úó   ¤A ÁAÁAc                 ó²   — t         s t        j                  d¬«      | «      S 	 ddl} |j                  j                  «       | «      S # t        $ r | cY S w xY w)z†
    Decorator marking a test as a pipeline test. If RUN_PIPELINE_TESTS is set to a falsy value, those tests will be
    skipped.
    ztest is pipeline testr«   r   N)Ú_run_pipeline_testsr®   rŽ   r¯   r°   Úis_pipeline_testr²   r³   s     rž   r¸   r¸   
  sY   € õ
 Ø<Œx�}‰}Ð$;Ô<¸YÓGÐGð	=Ûð 2�6—;‘;×/Ñ/Ó1°)Ó<Ð<øô ò 	ØÒð	úrµ   c                 ó²   — t         s t        j                  d¬«      | «      S 	 ddl} |j                  j                  «       | «      S # t        $ r | cY S w xY w)z|
    Decorator marking a test as an agent test. If RUN_TOOL_TESTS is set to a falsy value, those tests will be skipped.
    ztest is an agent testr«   r   N)Ú_run_agent_testsr®   rŽ   r¯   r°   Úis_agent_testr²   r³   s     rž   r»   r»     sY   € õ Ø<Œx�}‰}Ð$;Ô<¸YÓGÐGð	:Ûð /�6—;‘;×,Ñ,Ó.¨yÓ9Ð9øô ò 	ØÒð	úrµ   c                 óB   —  t        j                  t        d«      | «      S )z™
    Decorator marking a test as slow.

    Slow tests are skipped by default. Set the RUN_SLOW environment variable to a truthy value to run them.

    ztest is slow)r®   Ú
skipUnlessÚ_run_slow_tests©r´   s    rž   ÚslowrÀ   )  s   € ð @Œ8×Ñœ°Ó?À	ÓJÐJó    c                 ó:   —  t        j                  d¬«      | «      S )zÌ
    Decorator marking a test as too slow.

    Slow tests are skipped while they're in the process of being fixed. No test should stay tagged as "tooslow" as
    these will not be tested by the CI.

    ztest is too slowr«   )r®   rŽ   r¿   s    rž   ÚtooslowrÃ   3  s   € ð 4Œ8�=‰=Ð 2Ô3°IÓ>Ð>rÁ   c                 óB   ‡ — t        j                  ‰ «      ˆ fd„«       }|S )Nc                  óh   •— 	  ‰| i |¤ŽS # t         $ r}t        j                  d|› �«      ‚d }~ww xY w)Nz)Test skipped due to NotImplementedError: )ÚNotImplementedErrorr®   ÚSkipTest)ÚargsÚkwargsÚeÚ	test_funcs      €rž   Úwrapperz(skip_if_not_implemented.<locals>.wrapper?  sE   ø€ ð	UÙ˜dÐ- fÑ-Ð-øÜ"ò 	UÜ×#Ñ#Ð&OÐPQÈsÐ$SÓTÐTûð	Uús   ƒ ‹	1”,¬1©Ú	functoolsr   )rË   rÌ   s   ` rž   Úskip_if_not_implementedrÏ   >  s'   ø€ Ü‡_�_�YÓóUó  ðUð €NrÁ   c                 ó¦   — t        | «      D ]B  }|j                  d«      sŒt        | |«      }t        |«      sŒ-t	        | |t        |«      «       ŒD | S )zP
    Class decorator to apply @skip_if_not_implemented to all test methods.
    Útest_)ÚdirÚ
startswithÚgetattrÚcallableÚsetattrrÏ   )ÚclsÚ	attr_nameÚattrs      rž   Úapply_skip_if_not_implementedrÚ   I  sS   € ô ˜“Xò Gˆ	Ø×Ñ Õ(Ü˜3 	Ó*ˆDÜ˜�~Ü˜˜YÔ(?ÀÓ(EÕFð	Gð
 €JrÁ   c                 óB   —  t        j                  t        d«      | «      S )zä
    Decorator marking a test for a custom tokenizer.

    Custom tokenizers require additional dependencies, and are skipped by default. Set the RUN_CUSTOM_TOKENIZERS
    environment variable to a truthy value to run them.
    ztest of custom tokenizers)r®   r½   Ú_run_custom_tokenizersr¿   s    rž   Úcustom_tokenizersrÝ   U  s"   € ð TŒ8×ÑÔ5Ð7RÓSÐT]Ó^Ð^rÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )z}
    Decorator marking a test that requires BeautifulSoup4. These tests are skipped when BeautifulSoup4 isn't installed.
    ztest requires BeautifulSoup4)r®   r½   r.   r¿   s    rž   Úrequire_bs4rß   _  s%   € ð SŒ8×ÑÔ/Ó1Ð3QÓRÐS\Ó]Ð]rÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )z—
    Decorator marking a test that requires GaLore. These tests are skipped when GaLore isn't installed.
    https://github.com/jiaweizzhao/GaLore
    ztest requires GaLore)r®   r½   r=   r¿   s    rž   Úrequire_galore_torchrá   f  ó%   € ð
 TŒ8×ÑÔ8Ó:Ð<RÓSÐT]Ó^Ð^rÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )z–
    Decorator marking a test that requires GaLore. These tests are skipped when APOLLO isn't installed.
    https://github.com/zhuhanqing/APOLLO
    ztest requires APOLLO)r®   r½   r'   r¿   s    rž   Úrequire_apollo_torchrä   n  râ   rÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )z•
    Decorator marking a test that requires LOMO. These tests are skipped when LOMO-optim isn't installed.
    https://github.com/OpenLMLab/LOMO
    ztest requires LOMO)r®   r½   rK   r¿   s    rž   Úrequire_lomoræ   v  s$   € ð
 JŒ8×ÑÔ0Ó2Ð4HÓIÈ)ÓTÐTrÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )zs
    Decorator marking a test that requires GrokAdamW. These tests are skipped when GrokAdamW isn't installed.
    ztest requires GrokAdamW)r®   r½   r@   r¿   s    rž   Úrequire_grokadamwrè   ~  ó%   € ð TŒ8×ÑÔ5Ó7Ð9RÓSÐT]Ó^Ð^rÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )z¯
    Decorator marking a test that requires schedulefree. These tests are skipped when schedulefree isn't installed.
    https://github.com/facebookresearch/schedule_free
    ztest requires schedulefree)r®   r½   r]   r¿   s    rž   Úrequire_schedulefreerë   …  s%   € ð
 ZŒ8×ÑÔ8Ó:Ð<XÓYÐZcÓdÐdrÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )zs
    Decorator marking a test that requires OpenCV.

    These tests are skipped when OpenCV isn't installed.

    ztest requires OpenCV)r®   r½   r0   r¿   s    rž   Úrequire_cv2rí   �  s$   € ð KŒ8×ÑÔ/Ó1Ð3IÓJÈ9ÓUÐUrÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )z}
    Decorator marking a test that requires Levenshtein.

    These tests are skipped when Levenshtein isn't installed.

    ztest requires Levenshtein)r®   r½   rH   r¿   s    rž   Úrequire_levenshteinrï   —  ó%   € ð XŒ8×ÑÔ7Ó9Ð;VÓWÐXaÓbÐbrÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )zo
    Decorator marking a test that requires NLTK.

    These tests are skipped when NLTK isn't installed.

    ztest requires NLTK)r®   r½   rM   r¿   s    rž   Úrequire_nltkrò   ¡  ó$   € ð JŒ8×ÑÔ0Ó2Ð4HÓIÈ)ÓTÐTrÁ   Úmin_versionc                 óR   —  t        j                  t        |«      d|› �«      | «      S )zu
    Decorator marking a test that requires accelerate. These tests are skipped when accelerate isn't installed.
    z$test requires accelerate version >= )r®   r½   r%   ©r´   rô   s     rž   Úrequire_accelerater÷   «  s5   € ðŒ8×ÑÜ Ó,Ð0TÐU`ÐTaÐ.bóàóð rÁ   c                 óR   —  t        j                  t        |«      d|› �«      | «      S )zj
    Decorator marking a test that requires ggguf. These tests are skipped when gguf isn't installed.
    ztest requires gguf version >= )r®   r½   r>   rö   s     rž   Úrequire_ggufrù   ´  s4   € ð oŒ8×ÑÔ0°Ó=ÐA_Ð`kÐ_lÐ?mÓnØóð rÁ   c                 óR   —  t        j                  t        |«      d|› �«      | «      S )zi
    Decorator marking a test that requires fsdp. These tests are skipped when fsdp isn't installed.
    ztest requires torch version >= )r®   r½   r:   rö   s     rž   Úrequire_fsdprû   ½  s4   € ð pŒ8×ÑÔ0°Ó=ÐA`ÐalÐ`mÐ?nÓoØóð rÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )zt
    Decorator marking a test that requires g2p_en. These tests are skipped when SentencePiece isn't installed.
    ztest requires g2p_en)r®   r½   r<   r¿   s    rž   Úrequire_g2p_enrý   Æ  ó$   € ð NŒ8×ÑÔ2Ó4Ð6LÓMÈiÓXÐXrÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )zw
    Decorator marking a test that requires safetensors. These tests are skipped when safetensors isn't installed.
    ztest requires safetensors)r®   r½   r\   r¿   s    rž   Úrequire_safetensorsr   Í  ó%   € ð XŒ8×ÑÔ7Ó9Ð;VÓWÐXaÓbÐbrÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )zm
    Decorator marking a test that requires rjieba. These tests are skipped when rjieba isn't installed.
    ztest requires rjieba)r®   r½   rZ   r¿   s    rž   Úrequire_rjiebar  Ô  rþ   rÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )zk
    Decorator marking a test that requires jieba. These tests are skipped when jieba isn't installed.
    ztest requires jieba)r®   r½   rD   r¿   s    rž   Úrequire_jiebar  Û  ó$   € ð LŒ8×ÑÔ1Ó3Ð5JÓKÈIÓVÐVrÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )zk
    Decorator marking a test that requires jinja. These tests are skipped when jinja isn't installed.
    ztest requires jinja)r®   r½   rE   r¿   s    rž   Úrequire_jinjar  â  r  rÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )Nztest requires tf2onnx)r®   r½   rh   r¿   s    rž   Úrequire_tf2onnxr
  é  s"   € ØOŒ8×ÑÔ3Ó5Ð7NÓOÐPYÓZÐZrÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )Nztest requires ONNX)r®   r½   rN   r¿   s    rž   Úrequire_onnxr  í  s!   € ØIŒ8×ÑÔ0Ó2Ð4HÓIÈ)ÓTÐTrÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )zo
    Decorator marking a test that requires Timm.

    These tests are skipped when Timm isn't installed.

    ztest requires Timm)r®   r½   rk   r¿   s    rž   Úrequire_timmr  ñ  ró   rÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )zs
    Decorator marking a test that requires NATTEN.

    These tests are skipped when NATTEN isn't installed.

    ztest requires natten)r®   r½   rL   r¿   s    rž   Úrequire_nattenr  û  ó$   € ð NŒ8×ÑÔ2Ó4Ð6LÓMÈiÓXÐXrÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )zu
    Decorator marking a test that requires PyTorch.

    These tests are skipped when PyTorch isn't installed.

    útest requires PyTorch)r®   r½   rm   r¿   s    rž   Úrequire_torchr    s$   € ð NŒ8×ÑÔ1Ó3Ð5LÓMÈiÓXÐXrÁ   r   c                 ó   ‡ — ˆ fd„}|S )z˜
    Decorator marking a test that requires PyTorch version >= `version`.

    These tests are skipped when PyTorch version is less than `version`.
    c                 óT   •—  t        j                  t        ‰«      d‰› �«      | «      S )Nz!test requires PyTorch version >= )r®   r½   rs   )r´   r   s    €rž   Ú	decoratorz1require_torch_greater_or_equal.<locals>.decorator  s2   ø€ ØuŒx×"Ñ"Ô#<¸WÓ#EÐIjÐkrÐjsÐGtÓuØó
ð 	
rÁ   © )r   r  s   ` rž   Úrequire_torch_greater_or_equalr    s   ø€ ô
ð
 ÐrÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )z…
    Decorator marking a test that requires Flash Attention.

    These tests are skipped when Flash Attention isn't installed.

    ztest requires Flash Attention)r®   r½   r7   r¿   s    rž   Úrequire_flash_attnr    s%   € ð ]Œ8×ÑÔ8Ó:Ð<[Ó\Ð]fÓgÐgrÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )zŒ
    Decorator marking a test that requires PyTorch's SDPA.

    These tests are skipped when requirements are not met (torch version).
    ztest requires PyTorch SDPA)r®   r½   rx   r¿   s    rž   Úrequire_torch_sdpar  (  s%   € ð XŒ8×ÑÔ6Ó8Ð:VÓWÐXaÓbÐbrÁ   c                 ó\   ‡ ‡— t        j                  d«      Št        ‰ «      ˆ ˆfd„«       }|S )zZ
    A decorator that loads the HF token for tests that require to load gated models.
    ÚHF_HUB_READ_TOKENc                  ón   •— ‰�t        d‰¬«      5   ‰| i |¤Žcd d d «       S  ‰| i |¤ŽS # 1 sw Y   y xY w)Nz(huggingface_hub.utils._headers.get_token)Úreturn_valuer   )rÈ   rÉ   ÚfnÚtokens     €€rž   Ú_innerz"require_read_token.<locals>._inner7  sN   ø€ àÐÜÐAÐPUÔVñ +Ù˜4Ð* 6Ñ*÷+ñ +ñ �tÐ&˜vÑ&Ð&÷+ð +ús   ‘+«4)r•   Úgetenvr   )r"  r$  r#  s   ` @rž   Úrequire_read_tokenr&  1  s1   ù€ ô �I‰IÐ)Ó*€Eä
ˆ2ƒYô'ó ð'ð €MrÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )zo
    Decorator marking a test that requires PEFT.

    These tests are skipped when PEFT isn't installed.

    ztest requires PEFT)r®   r½   rR   r¿   s    rž   Úrequire_peftr(  B  ró   rÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )z}
    Decorator marking a test that requires Torchvision.

    These tests are skipped when Torchvision isn't installed.

    ztest requires Torchvision)r®   r½   r€   r¿   s    rž   Úrequire_torchvisionr*  L  rð   rÁ   c                 ób   —  t        j                  t        «       xs
 t        «       d«      | «      S )z—
    Decorator marking a test that requires PyTorch or TensorFlow.

    These tests are skipped when neither PyTorch not TensorFlow is installed.

    z#test requires PyTorch or TensorFlow)r®   r½   rm   ri   r¿   s    rž   Úrequire_torch_or_tfr,  V  s1   € ð qŒ8×ÑÔ1Ó3ÒH´Ó7HÐJoÓpØóð rÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )zÎ
    Decorator marking a test that requires Intel Extension for PyTorch.

    These tests are skipped when Intel Extension for PyTorch isn't installed or it does not match current PyTorch
    version.

    z•test requires Intel Extension for PyTorch to be installed and match current PyTorch version, see https://github.com/intel/intel-extension-for-pytorch)r®   r½   rC   r¿   s    rž   Ú#require_intel_extension_for_pytorchr.  b  s/   € ðŒ8×ÑÜÓð	@óð ó	ð rÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )z“
    Decorator marking a test that requires TensorFlow probability.

    These tests are skipped when TensorFlow probability isn't installed.

    z$test requires TensorFlow probability)r®   r½   rf   r¿   s    rž   Úrequire_tensorflow_probabilityr0  q  s)   € ð nŒ8×ÑÔBÓDÐFlÓmØóð rÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )zu
    Decorator marking a test that requires torchaudio. These tests are skipped when torchaudio isn't installed.
    ztest requires torchaudio)r®   r½   r~   r¿   s    rž   Úrequire_torchaudior2  }  ó%   € ð VŒ8×ÑÔ6Ó8Ð:TÓUÐV_Ó`Ð`rÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )zu
    Decorator marking a test that requires TensorFlow. These tests are skipped when TensorFlow isn't installed.
    ztest requires TensorFlow)r®   r½   ri   r¿   s    rž   Ú
require_tfr5  „  s#   € ð NŒ8×ÑœÓ0Ð2LÓMÈiÓXÐXrÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )zv
    Decorator marking a test that requires JAX & Flax. These tests are skipped when one / both are not installed
    ztest requires JAX & Flax)r®   r½   r8   r¿   s    rž   Úrequire_flaxr7  ‹  s%   € ð PŒ8×ÑÔ0Ó2Ð4NÓOÐPYÓZÐZrÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )ú{
    Decorator marking a test that requires SentencePiece. These tests are skipped when SentencePiece isn't installed.
    ztest requires SentencePiece)r®   r½   r_   r¿   s    rž   Úrequire_sentencepiecer:  ’  s%   € ð \Œ8×ÑÔ9Ó;Ð=ZÓ[Ð\eÓfÐfrÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )zu
    Decorator marking a test that requires Sacremoses. These tests are skipped when Sacremoses isn't installed.
    ztest requires Sacremoses)r®   r½   r[   r¿   s    rž   Úrequire_sacremosesr<  ™  r3  rÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )r9  ztest requires Seqio)r®   r½   r`   r¿   s    rž   Úrequire_seqior>     r  rÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )zs
    Decorator marking a test that requires Scipy. These tests are skipped when SentencePiece isn't installed.
    ztest requires Scipy)r®   r½   r^   r¿   s    rž   Úrequire_scipyr@  §  r  rÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )u   
    Decorator marking a test that requires ðŸ¤— Tokenizers. These tests are skipped when ðŸ¤— Tokenizers isn't installed.
    ztest requires tokenizers)r®   r½   rl   r¿   s    rž   Úrequire_tokenizersrB  ®  r3  rÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )zƒ
    Decorator marking a test that requires tensorflow_text. These tests are skipped when tensroflow_text isn't
    installed.
    ztest requires tensorflow_text)r®   r½   rg   r¿   s    rž   Úrequire_tensorflow_textrD  µ  s%   € ð
 `Œ8×ÑÔ;Ó=Ð?^Ó_Ð`iÓjÐjrÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )zs
    Decorator marking a test that requires keras_nlp. These tests are skipped when keras_nlp isn't installed.
    ztest requires keras_nlp)r®   r½   rG   r¿   s    rž   Úrequire_keras_nlprF  ½  ré   rÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )zm
    Decorator marking a test that requires pandas. These tests are skipped when pandas isn't installed.
    ztest requires pandas)r®   r½   rQ   r¿   s    rž   Úrequire_pandasrH  Ä  rþ   rÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )zw
    Decorator marking a test that requires PyTesseract. These tests are skipped when PyTesseract isn't installed.
    ztest requires PyTesseract)r®   r½   rV   r¿   s    rž   Úrequire_pytesseractrJ  Ë  r  rÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )z�
    Decorator marking a test that requires PyTorch Quantization Toolkit. These tests are skipped when PyTorch
    Quantization Toolkit isn't installed.
    z*test requires PyTorch Quantization Toolkit)r®   r½   rX   r¿   s    rž   Úrequire_pytorch_quantizationrL  Ò  s)   € ð
 rŒ8×ÑÔ@ÓBÐDpÓqØóð rÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )z†
    Decorator marking a test that requires the vision dependencies. These tests are skipped when torchaudio isn't
    installed.
    ztest requires vision)r®   r½   r�   r¿   s    rž   Úrequire_visionrN  Ü  s$   € ð
 NŒ8×ÑÔ2Ó4Ð6LÓMÈiÓXÐXrÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )zi
    Decorator marking a test that requires ftfy. These tests are skipped when ftfy isn't installed.
    ztest requires ftfy)r®   r½   r;   r¿   s    rž   Úrequire_ftfyrP  ä  ó$   € ð JŒ8×ÑÔ0Ó2Ð4HÓIÈ)ÓTÐTrÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )zk
    Decorator marking a test that requires SpaCy. These tests are skipped when SpaCy isn't installed.
    ztest requires spacy)r®   r½   rb   r¿   s    rž   Úrequire_spacyrS  ë  r  rÁ   c                 óÄ   — t        «       s t        j                  d¬«      | «      S ddl} t        j                  |j
                  j                  «       dkD  d«      | «      S )a  
    Decorator marking a test that requires a multi-GPU CUDA setup (in PyTorch). These tests are skipped on a machine without
    multiple CUDA GPUs.

    To run *only* the multi_gpu tests, assuming all test names contain multi_gpu: $ pytest -sv ./tests -k "multi_gpu"
    r  r«   r   Nr   z test requires multiple CUDA GPUs©rm   r®   rŽ   Útorchr½   ÚcudaÚdevice_count©r´   rV  s     rž   Úrequire_torch_multi_gpurZ  ò  sR   € ô ÔØ<Œx�}‰}Ð$;Ô<¸YÓGÐGãàaŒ8×Ñ˜uŸz™z×6Ñ6Ó8¸1Ñ<Ð>`ÓaÐbkÓlÐlrÁ   c                 ó¦   — t        «       s t        j                  d¬«      | «      S  t        j                  t	        t
        «      dkD  d«      | «      S )a(  
    Decorator marking a test that requires a multi-accelerator (in PyTorch). These tests are skipped on a machine
    without multiple accelerators. To run *only* the multi_accelerator tests, assuming all test names contain
    multi_accelerator: $ pytest -sv ./tests -k "multi_accelerator"
    r  r«   r   z#test requires multiple accelerators©rm   r®   rŽ   r½   Úbackend_device_countÚtorch_devicer¿   s    rž   Úrequire_torch_multi_acceleratorr_    sL   € ô ÔØ<Œx�}‰}Ð$;Ô<¸YÓGÐGàmŒ8×ÑÔ3´LÓAÀAÑEÐGlÓmØóð rÁ   c                 óÄ   — t        «       s t        j                  d¬«      | «      S ddl} t        j                  |j
                  j                  «       dk  d«      | «      S )zO
    Decorator marking a test that requires 0 or 1 GPU setup (in PyTorch).
    r  r«   r   Né   ztest requires 0 or 1 GPUrU  rY  s     rž   Úrequire_torch_non_multi_gpurb    sR   € ô ÔØ<Œx�}‰}Ð$;Ô<¸YÓGÐGãàYŒ8×Ñ˜uŸz™z×6Ñ6Ó8¸1Ñ<Ð>XÓYÐZcÓdÐdrÁ   c                 ó¦   — t        «       s t        j                  d¬«      | «      S  t        j                  t	        t
        «      dk  d«      | «      S )zW
    Decorator marking a test that requires 0 or 1 accelerator setup (in PyTorch).
    r  r«   ra  z test requires 0 or 1 acceleratorr\  r¿   s    rž   Ú#require_torch_non_multi_acceleratorrd    sH   € ô ÔØ<Œx�}‰}Ð$;Ô<¸YÓGÐGàjŒ8×ÑÔ3´LÓAÀAÑEÐGiÓjÐktÓuÐurÁ   c                 óÄ   — t        «       s t        j                  d¬«      | «      S ddl} t        j                  |j
                  j                  «       dk  d«      | «      S )zT
    Decorator marking a test that requires 0 or 1 or 2 GPU setup (in PyTorch).
    r  r«   r   Né   ztest requires 0 or 1 or 2 GPUsrU  rY  s     rž   Úrequire_torch_up_to_2_gpusrg  %  sR   € ô ÔØ<Œx�}‰}Ð$;Ô<¸YÓGÐGãà_Œ8×Ñ˜uŸz™z×6Ñ6Ó8¸1Ñ<Ð>^Ó_Ð`iÓjÐjrÁ   c                 ó¦   — t        «       s t        j                  d¬«      | «      S  t        j                  t	        t
        «      dk  d«      | «      S )z\
    Decorator marking a test that requires 0 or 1 or 2 accelerator setup (in PyTorch).
    r  r«   rf  z&test requires 0 or 1 or 2 acceleratorsr\  r¿   s    rž   Ú"require_torch_up_to_2_acceleratorsri  1  sL   € ô ÔØ<Œx�}‰}Ð$;Ô<¸YÓGÐGàpŒ8×ÑÔ3´LÓAÀAÑEÐGoÓpØóð rÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )zG
    Decorator marking a test that requires TorchXLA (in PyTorch).
    ztest requires TorchXLA)r®   r½   r{   r¿   s    rž   Úrequire_torch_xlark  =  s%   € ð SŒ8×ÑÔ5Ó7Ð9QÓRÐS\Ó]Ð]rÁ   c                 óN   —  t        j                  t        d¬«      d«      | «      S )zI
    Decorator marking a test that requires NeuronCore (in PyTorch).
    F)Úcheck_devicez test requires PyTorch NeuronCore)r®   r½   rv   r¿   s    rž   Úrequire_torch_neuroncorern  D  s+   € ð vŒ8×ÑÔ<È%ÔPÐRtÓuØóð rÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )zB
    Decorator marking a test that requires NPU (in PyTorch).
    útest requires PyTorch NPU)r®   r½   rw   r¿   s    rž   Úrequire_torch_npurq  M  s%   € ð VŒ8×ÑÔ5Ó7Ð9TÓUÐV_Ó`Ð`rÁ   c                 óÄ   — t        «       s t        j                  d¬«      | «      S  t        j                  t        j
                  j                  «       dkD  d«      | «      S )a  
    Decorator marking a test that requires a multi-NPU setup (in PyTorch). These tests are skipped on a machine without
    multiple NPUs.

    To run *only* the multi_npu tests, assuming all test names contain multi_npu: $ pytest -sv ./tests -k "multi_npu"
    rp  r«   r   ztest requires multiple NPUs)rw   r®   rŽ   r½   rV  ÚnpurX  r¿   s    rž   Úrequire_torch_multi_npurt  T  óO   € ô "Ô#Ø@Œx�}‰}Ð$?Ô@ÀÓKÐKà[Œ8×ÑœuŸy™y×5Ñ5Ó7¸!Ñ;Ð=ZÓ[Ð\eÓfÐfrÁ   c                 óH   —  t        j                  t        dk7  d«      | «      S )zB
    Decorator marking a test that should be skipped for HPU.
    Úhpuztest requires a non-HPU©r®   r½   r^  r¿   s    rž   Úrequire_non_hpury  a  ó&   € ð QŒ8×Ñœ|¨uÑ4Ð6OÓPÐQZÓ[Ð[rÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )aN  
    Decorator marking a test that requires XPU (in PyTorch).

    These tests are skipped when XPU backend is not available. XPU backend might be available either via stock
    PyTorch (>=2.4) or via Intel Extension for PyTorch. In the latter case, if IPEX is installed, its version
    must match match current PyTorch version.
    ztest requires XPU device)r®   r½   r|   r¿   s    rž   Úrequire_torch_xpur|  h  s%   € ð UŒ8×ÑÔ5Ó7Ð9SÓTÐU^Ó_Ð_rÁ   c                 óH   —  t        j                  t        dk7  d«      | «      S )zB
    Decorator marking a test that should be skipped for XPU.
    Úxpuztest requires a non-XPUrx  r¿   s    rž   Úrequire_non_xpur  s  rz  rÁ   c                 óÄ   — t        «       s t        j                  d¬«      | «      S  t        j                  t        j
                  j                  «       dkD  d«      | «      S )a  
    Decorator marking a test that requires a multi-XPU setup (in PyTorch). These tests are skipped on a machine without
    multiple XPUs.

    To run *only* the multi_xpu tests, assuming all test names contain multi_xpu: $ pytest -sv ./tests -k "multi_xpu"
    ztest requires PyTorch XPUr«   r   ztest requires multiple XPUs)r|   r®   rŽ   r½   rV  r~  rX  r¿   s    rž   Úrequire_torch_multi_xpur�  z  ru  rÁ   c                 óÄ   — t        «       s t        j                  d¬«      | «      S  t        j                  t        j
                  j                  «       dkD  d«      | «      S )a  
    Decorator marking a test that requires a multi-HPU setup (in PyTorch). These tests are skipped on a machine without
    multiple HPUs.

    To run *only* the multi_hpu tests, assuming all test names contain multi_hpu: $ pytest -sv ./tests -k "multi_hpu"
    ztest requires PyTorch HPUr«   r   ztest requires multiple HPUs)rt   r®   rŽ   r½   rV  rw  rX  r¿   s    rž   Úrequire_torch_multi_hpurƒ  ‡  ru  rÁ   ÚTRANSFORMERS_TEST_BACKENDz.Failed to import `TRANSFORMERS_TEST_BACKEND` 'zf'! This should be the name of an installed module. The original error (look up to see its traceback):
ÚTRANSFORMERS_TEST_DEVICErW  zTRANSFORMERS_TEST_DEVICE=zH, but CUDA is unavailable. Please double-check your testing environment.r~  zG, but XPU is unavailable. Please double-check your testing environment.rs  zG, but NPU is unavailable. Please double-check your testing environment.ÚmluzG, but MLU is unavailable. Please double-check your testing environment.rw  zG, but HPU is unavailable. Please double-check your testing environment.zUUnknown testing device specified by environment variable `TRANSFORMERS_TEST_DEVICE`: Úcpuc                 óJ   —  t        j                  t        «       d«      | «      S )z2Decorator marking a test that requires TorchDynamoztest requires TorchDynamo)r®   r½   r   r¿   s    rž   Úrequire_torchdynamor‰  Ú  s"   € àWŒ8×ÑÔ7Ó9Ð;VÓWÐXaÓbÐbrÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )z.Decorator marking a test that requires torchaoztest requires torchao)r®   r½   r}   r¿   s    rž   Úrequire_torchaor‹  ß  s"   € àOŒ8×ÑÔ3Ó5Ð7NÓOÐPYÓZÐZrÁ   c                 ó   ‡ — ˆ fd„}|S )Nc                 ó&  •— t        «       xre t        j                  t        j                  t        j                  j                  d«      «      j
                  «      t        j                  ‰«      k\  } t        j                  |d‰› d�«      | «      S )NÚtorchaoz4Test requires torchao with the version greater than ú.)r}   r   ÚparseÚ	importlibÚmetadataÚbase_versionr®   r½   )r´   Úcorrect_torchao_versionÚtorchao_versions     €rž   r  z;require_torchao_version_greater_or_equal.<locals>.decoratorå  s�   ø€ Ü"6Ó"8ò #,¼W¿]¹]Ü�M‰Mœ)×,Ñ,×4Ñ4°YÓ?Ó@×MÑMó>
ä�]‰]˜?Ó+ñ>,Ðð
Œx×"Ñ"Ø#Ð'[Ð\kÐ[lÐlmÐ%nó
à
óð 	rÁ   r  )r•  r  s   ` rž   Ú(require_torchao_version_greater_or_equalr–  ä  s   ø€ ôð ÐrÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )z8Decorator marking a test that requires Torch-TensorRT FXztest requires Torch-TensorRT FX)r®   r½   ry   r¿   s    rž   Úrequire_torch_tensorrt_fxr˜  ð  s"   € àcŒ8×ÑÔ=Ó?ÐAbÓcÐdmÓnÐnrÁ   c                 óH   —  t        j                  t        dk(  d«      | «      S )z8Decorator marking a test that requires CUDA and PyTorch.rW  ztest requires CUDArx  r¿   s    rž   Úrequire_torch_gpurš  õ  s"   € àLŒ8×Ñœ|¨vÑ5Ð7KÓLÈYÓWÐWrÁ   Úmemoryc                 óî   — t         dk7  r  t        j                  d|› d�¬«      | «      S  t        j                  t        j
                  j                  d«      j                  dz  |kD  d|› d�«      | «      S )zXDecorator marking a test that requires a CUDA GPU with more than `memory` GiB of memory.rW  z(test requires a CUDA GPU with more than z GiB of memoryr«   r   i   @z#test requires a GPU with more than )r^  r®   rŽ   r½   rV  rW  Úget_device_propertiesÚtotal_memory)r´   r›  s     rž   Úrequire_torch_large_gpurŸ  ú  s{   € ä�vÒØfŒx�}‰}Ð&NÈvÈhÐVdÐ$eÔfÐgpÓqÐqðŒ8×ÑÜ�
‰
×(Ñ(¨Ó+×8Ñ8¸7ÑBÀVÑKØ
-¨f¨X°^ÐDóð óð rÁ   c                 óD   — t        «       rt        «       r| S t        | «      S )zl
    Decorator marking a test that requires a GPU if bitsandbytes multi-backend feature is not enabled.
    )r,   r-   rš  r¿   s    rž   Ú2require_torch_gpu_if_bnb_not_multi_backend_enabledr¡    s!   € ô !Ô"Ô'NÔ'PØÐÜ˜YÓ'Ð'rÁ   c                 ó\   —  t        j                  t        duxr	 t        dk7  d«      | «      S )zMDecorator marking a test that requires an accessible accelerator and PyTorch.Nr‡  ztest requires acceleratorrx  r¿   s    rž   Úrequire_torch_acceleratorr£    s1   € àoŒ8×Ñœ|°4Ð7ÒQ¼LÈEÑ<QÐSnÓoØóð rÁ   c                 óT   —  t        j                  t        t        «      d«      | «      S )zBDecorator marking a test that requires a device that supports fp16z&test requires device with fp16 support)r®   r½   rr   r^  r¿   s    rž   Úrequire_torch_fp16r¥    ó,   € ðŒ8×ÑÜ)¬,Ó7Ð9aóàóð rÁ   c                 ób   —  t        j                  t        «       xr
 t        «       d«      | «      S )z7Decorator marking a test that requires supports for fp8ztest requires fp8 support)r®   r½   r%   r†   r¿   s    rž   Úrequire_fp8r¨    s/   € àmŒ8×ÑÔ6Ó8ÒOÔ=MÓ=OÐQlÓmØóð rÁ   c                 óT   —  t        j                  t        t        «      d«      | «      S )zBDecorator marking a test that requires a device that supports bf16z&test requires device with bf16 support)r®   r½   rn   r^  r¿   s    rž   Úrequire_torch_bf16rª  #  r¦  rÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )zbDecorator marking a test that requires torch>=1.10, using Ampere GPU or newer arch with cuda>=11.0zItest requires torch>=1.10, using Ampere GPU or newer arch with cuda>=11.0)r®   r½   rp   r¿   s    rž   Úrequire_torch_bf16_gpur¬  *  s,   € ðŒ8×ÑÜ#Ó%ØSóð óð rÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )z>Decorator marking a test that requires torch>=1.10, using CPU.z$test requires torch>=1.10, using CPU)r®   r½   ro   r¿   s    rž   Úrequire_torch_bf16_cpur®  2  s,   € ðŒ8×ÑÜ#Ó%Ø.óð óð rÁ   c                 ób   — t        «       r$ t        j                  t        «       d«      | «      S | S )Nz3test requires torch to use deterministic algorithms)r|   r®   r½   rq   r¿   s    rž   Úrequire_deterministic_for_xpur°  :  s4   € ÜÔØsŒx×"Ñ"Ô#9Ó#;Ð=rÓsØó
ð 	
ð ÐrÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )z[Decorator marking a test that requires Ampere or a newer GPU arch, cuda>=11 and torch>=1.7.zAtest requires Ampere or a newer GPU arch, cuda>=11 and torch>=1.7)r®   r½   rz   r¿   s    rž   Úrequire_torch_tf32r²  C  s*   € ðŒ8×ÑÜÓ!Ð#fóàóð rÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )z2Decorator marking a test that requires detectron2.ztest requires `detectron2`)r®   r½   r2   r¿   s    rž   Úrequire_detectron2r´  J  s"   € àWŒ8×ÑÔ6Ó8Ð:VÓWÐXaÓbÐbrÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )z-Decorator marking a test that requires faiss.ztest requires `faiss`)r®   r½   r5   r¿   s    rž   Úrequire_faissr¶  O  s!   € àMŒ8×ÑÔ1Ó3Ð5LÓMÈiÓXÐXrÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )zs
    Decorator marking a test that requires optuna.

    These tests are skipped when optuna isn't installed.

    ztest requires optuna)r®   r½   r   r¿   s    rž   Úrequire_optunar¸  T  r  rÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )zw
    Decorator marking a test that requires Ray/tune.

    These tests are skipped when Ray/tune isn't installed.

    ztest requires Ray/tune)r®   r½   r   r¿   s    rž   Úrequire_rayrº  ^  s$   € ð MŒ8×ÑÔ/Ó1Ð3KÓLÈYÓWÐWrÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )zs
    Decorator marking a test that requires SigOpt.

    These tests are skipped when SigOpt isn't installed.

    ztest requires SigOpt)r®   r½   r   r¿   s    rž   Úrequire_sigoptr¼  h  r  rÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )zu
    Decorator marking a test that requires swanlab.

    These tests are skipped when swanlab isn't installed.

    ztest requires swanlab)r®   r½   r   r¿   s    rž   Úrequire_swanlabr¾  r  ó%   € ð PŒ8×ÑÔ3Ó5Ð7NÓOÐPYÓZÐZrÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )zq
    Decorator marking a test that requires wandb.

    These tests are skipped when wandb isn't installed.

    ztest requires wandb)r®   r½   r!   r¿   s    rž   Úrequire_wandbrÁ  |  s$   € ð LŒ8×ÑÔ1Ó3Ð5JÓKÈIÓVÐVrÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )zp
    Decorator marking a test requires clearml.

    These tests are skipped when clearml isn't installed.

    ztest requires clearml)r®   r½   r   r¿   s    rž   Úrequire_clearmlrÃ  †  r¿  rÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )zx
    Decorator marking a test that requires soundfile

    These tests are skipped when soundfile isn't installed.

    ztest requires soundfile)r®   r½   ra   r¿   s    rž   Úrequire_soundfilerÅ  �  s%   € ð TŒ8×ÑÔ5Ó7Ð9RÓSÐT]Ó^Ð^rÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )z:
    Decorator marking a test that requires deepspeed
    ztest requires deepspeed)r®   r½   r"   r¿   s    rž   Úrequire_deepspeedrÇ  š  ré   rÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )z5
    Decorator marking a test that requires apex
    ztest requires apex)r®   r½   r&   r¿   s    rž   Úrequire_apexrÉ  ¡  rQ  rÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )z5
    Decorator marking a test that requires aqlm
    ztest requires aqlm)r®   r½   r(   r¿   s    rž   Úrequire_aqlmrË  ¨  rQ  rÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )z5
    Decorator marking a test that requires vptq
    ztest requires vptq)r®   r½   r‚   r¿   s    rž   Úrequire_vptqrÍ  ¯  rQ  rÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )z5
    Decorator marking a test that requires spqr
    ztest requires spqr)r®   r½   rc   r¿   s    rž   Úrequire_spqrrÏ  ¶  rQ  rÁ   c                 ó¦   — t        «       }|r	 ddl} t	        j
                  |d«      | «      S # t        $ r}dt        |«      v rd}Y d}~Œ9d}~ww xY w)z5
    Decorator marking a test that requires eetq
    r   NÚshard_checkpointFztest requires eetq)r3   Úeetqr²   Ústrr®   r½   )r´   Úeetq_availablerÒ  Úexcs       rž   Úrequire_eetqrÖ  ½  s[   € ô 'Ó(€NÙð	'Ûð EŒ8×Ñ˜~Ð/CÓDÀYÓOÐOøô ò 	'Ø!¤S¨£XÑ-ð "'�ÿøð	'ús   Ž. ®	A·AÁAc                 óJ   —  t        j                  t        «       d«      | «      S )z3
    Decorator marking a test that requires av
    ztest requires av)r®   r½   r+   r¿   s    rž   Ú
require_avrØ  Î  s#   € ð FŒ8×ÑœÓ0Ð2DÓEÀiÓPÐPrÁ   c                 óÄ   — t        «       r*t        «       r 	 ddl}|j                  j	                  | «      S  t        j                  d¬«      | «      S # t
        $ r | cY S w xY w)zš
    Decorator marking a test that requires the bitsandbytes library. Will be skipped when the library or its hard dependency torch is not installed.
    r   Nz$test requires bitsandbytes and torchr«   )r,   rm   r¯   r°   Úbitsandbytesr²   r®   rŽ   r³   s     rž   Úrequire_bitsandbytesrÛ  Õ  s^   € ô !Ô"Ô'9Ô';ð	Ûà—;‘;×+Ñ+¨IÓ6Ð6ð LŒx�}‰}Ð$JÔKÈIÓVÐVøô ò 	ØÒð	ús   –A ÁAÁAc                 óJ   —  t        j                  t        «       d«      | «      S )z*
    Decorator for optimum dependency
    ztest requires optimum)r®   r½   rO   r¿   s    rž   Úrequire_optimumrÝ  ä  ó%   € ð PŒ8×ÑÔ3Ó5Ð7NÓOÐPYÓZÐZrÁ   c                 ó>   — t        j                  t        «       d«      S )z0
    Decorator for `tensorboard` dependency
    ztest requires tensorboard)r®   r½   r    r¿   s    rž   Úrequire_tensorboardrà  ë  s   € ô ×ÑÔ7Ó9Ð;VÓWÐWrÁ   c                 ób   —  t        j                  t        «       xs
 t        «       d«      | «      S )z,
    Decorator for auto_gptq dependency
    z$test requires gptqmodel or auto-gptq)r®   r½   r?   r*   r¿   s    rž   Úrequire_gptqrâ  ò  s3   € ðŒ8×ÑÜÓ Ò<Ô$:Ó$<Ð>dóàóð rÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )z&
    Decorator for hqq dependency
    ztest requires hqq)r®   r½   rB   r¿   s    rž   Úrequire_hqqrä  û  s$   € ð HŒ8×ÑÔ/Ó1Ð3FÓGÈ	ÓRÐRrÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )z+
    Decorator for auto_awq dependency
    ztest requires autoawq)r®   r½   r)   r¿   s    rž   Úrequire_auto_awqræ    s%   € ð QŒ8×ÑÔ4Ó6Ð8OÓPÐQZÓ[Ð[rÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )z)
    Decorator for quanto dependency
    ztest requires optimum-quanto)r®   r½   rP   r¿   s    rž   Úrequire_optimum_quantorè  	  s%   € ð ^Œ8×ÑÔ:Ó<Ð>\Ó]Ð^gÓhÐhrÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )z5
    Decorator for compressed_tensors dependency
    z test requires compressed_tensors)r®   r½   r/   r¿   s    rž   Úrequire_compressed_tensorsrê    s%   € ð fŒ8×ÑÔ>Ó@ÐBdÓeÐfoÓpÐprÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )z-
    Decorator for fbgemm_gpu dependency
    ztest requires fbgemm-gpu)r®   r½   r6   r¿   s    rž   Úrequire_fbgemm_gpurì    r3  rÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )z(
    Decorator for quark dependency
    ztest requires quark)r®   r½   rY   r¿   s    rž   Úrequire_quarkrî    r  rÁ   c                 ób   —  t        j                  t        «       xr
 t        «       d«      | «      S )zC
    Decorator marking a test that requires higgs and hadamard
    z/test requires flute and fast_hadamard_transform)r®   r½   r9   rA   r¿   s    rž   Úrequire_flute_hadamardrð  %  s3   € ðŒ8×ÑÜÓÒ8Ô!6Ó!8Ð:kóàóð rÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )z;
    Decorator marking a test that requires phonemizer
    ztest requires phonemizer)r®   r½   rS   r¿   s    rž   Úrequire_phonemizerrò  .  r3  rÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )z<
    Decorator marking a test that requires pyctcdecode
    ztest requires pyctcdecode)r®   r½   rU   r¿   s    rž   Úrequire_pyctcdecoderô  5  r  rÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )z8
    Decorator marking a test that requires librosa
    ztest requires librosa)r®   r½   rI   r¿   s    rž   Úrequire_librosarö  <  rÞ  rÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )z=
    Decorator marking a test that requires liger_kernel
    ztest requires liger_kernel)r®   r½   rJ   r¿   s    rž   Úrequire_liger_kernelrø  C  s%   € ð ZŒ8×ÑÔ8Ó:Ð<XÓYÐZcÓdÐdrÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )z9
    Decorator marking a test that requires essentia
    ztest requires essentia)r®   r½   r4   r¿   s    rž   Úrequire_essentiarú  J  ó%   € ð RŒ8×ÑÔ4Ó6Ð8PÓQÐR[Ó\Ð\rÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )z<
    Decorator marking a test that requires pretty_midi
    ztest requires pretty_midi)r®   r½   rT   r¿   s    rž   Úrequire_pretty_midirý  Q  r  rÁ   c                 ó0   — t        j                  | «      d uS ©N)ÚshutilÚwhich)Úcmds    rž   Ú
cmd_existsr  X  s   € Ü�<‰<˜Ó DÐ(Ð(rÁ   c                 óL   —  t        j                  t        d«      d«      | «      S )z@
    Decorator marking a test that requires `/usr/bin/time`
    ú/usr/bin/timeztest requires /usr/bin/time)r®   r½   r  r¿   s    rž   Úrequire_usr_bin_timer  \  s&   € ð [Œ8×Ñœz¨/Ó:Ð<YÓZÐ[dÓeÐerÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )z8
    Decorator marking a test that requires sudachi
    ztest requires sudachi)r®   r½   rd   r¿   s    rž   Úrequire_sudachir  c  rÞ  rÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )zC
    Decorator marking a test that requires sudachi_projection
    z/test requires sudachi which supports projection)r®   r½   re   r¿   s    rž   Úrequire_sudachi_projectionr
  j  s)   € ð uŒ8×ÑÔ>Ó@ÐBsÓtØóð rÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )ú8
    Decorator marking a test that requires jumanpp
    ztest requires jumanpp)r®   r½   rF   r¿   s    rž   Úrequire_jumanppr  s  rÞ  rÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )r  ztest requires cython)r®   r½   r1   r¿   s    rž   Úrequire_cythonr  z  rþ   rÁ   c                 óJ   —  t        j                  t        «       d«      | «      S )zq
    Decorator marking a test that requires TikToken. These tests are skipped when TikToken isn't installed.
    ztest requires TikToken)r®   r½   rj   r¿   s    rž   Úrequire_tiktokenr  �  rû  rÁ   c                  óö   — t        «       rddl} | j                  j                  «       S t	        «       r(ddl}t        |j                  j                  d«      «      S t        «       rddl
} |j                  «       S y)z^
    Return the number of available gpus (regardless of whether torch, tf or jax is used)
    r   NÚGPU)rm   rV  rW  rX  ri   Ú
tensorflowÚlenÚconfigÚlist_physical_devicesr8   Újax)rV  Útfr  s      rž   Úget_gpu_countr  ˆ  s`   € ô ÔÛà�z‰z×&Ñ&Ó(Ð(Ü	Ô	Ûä�2—9‘9×2Ñ2°5Ó9Ó:Ð:Ü	Ô	Ûàˆs×ÑÓ!Ð!àrÁ   c                 óz  — t        j                  «       d   d   }t        j                  j	                  t        j                  j                  |«      «      }|j                  d«      s1t        j                  j                  |«      }|j                  d«      sŒ1| r t        j                  j                  || «      S |S )a  
    Args:
        append_path: optional path to append to the tests dir path

    Return:
        The full path to the `tests` dir, so that the tests can be invoked from anywhere. Optionally `append_path` is
        joined after the `tests` dir the former is provided.

    r   Útests)ÚinspectÚstackr•   ÚpathÚabspathÚdirnameÚendswithÚjoin)Úappend_pathÚcaller__file__Ú	tests_dirs      rž   Úget_tests_dirr'  œ  sˆ   € ô —]‘]“_ QÑ'¨Ñ*€NÜ—‘—‘¤§¡§¡°Ó ?Ó@€Ià× Ñ  Ô)Ü—G‘G—O‘O IÓ.ˆ	ð × Ñ  Õ)ñ Ü�w‰w�|‰|˜I {Ó3Ð3àÐrÁ   ÚtrainerÚreturnc                 ó„   — | j                   }| j                  «       }| j                  |||j                  ¬«      }|d   }|S )N)rÈ   Ú
dataloaderÚtotal_train_batch_sizer   )rÈ   Úget_train_dataloaderÚset_initial_training_valuesÚper_device_train_batch_size)r(  Útraining_argsÚtrain_dataloaderÚinitial_training_valuesÚsteps_per_epochs        rž   Úget_steps_per_epochr4  ³  sR   € Ø—L‘L€MØ×3Ñ3Ó5Ðà%×AÑAØØ#Ø,×HÑHð Bó Ðð
 .¨aÑ0€OàÐrÁ   Úside_effect_valuesc              #   ó4   K  — | E d{  –—†  	 | d   –— Œ7 Œ­w)z•
    Function that returns side effects for the _evaluate method.
    Used when we're unsure of exactly how many times _evaluate will be called.
    Néÿÿÿÿr  )r5  s    rž   Úevaluate_side_effect_factoryr8  Á  s)   è ø€ ð "×!Ð!à
Ø  Ñ$Ò$ð ð "ús   ‚ˆ‰c                 óP   — t        j                  dd| dt         j                  «      S )Nz^.*\rÚ r   )ÚreÚsubÚM)Úbufs    rž   Úapply_print_resetsr?  Ý  s   € Ü�6‰6�(˜B  Q¬¯©Ó-Ð-rÁ   c                 ó˜   — t        | «      j                  «       }|j                  |j                  «       «      }|dk7  sJ d|› d|› �«       ‚y )Nr7  zexpecting to find z in output: f)r?  ÚlowerÚfind)ÚoutÚwhatÚout_prÚ	match_strs       rž   Úassert_screenoutrG  á  sH   € Ü Ó$×*Ñ*Ó,€FØ—‘˜DŸJ™J›LÓ)€IØ˜Š?ÐLÐ0°°°mÀFÀ8ÐLÓL‰?rÁ   c                 ó‚  — d}g d¢}| j                   j                  j                  |v rd }t        | j                   d«      st        | j                   d«      rd }t        | j                   d«      r|�|| j                   _        t        | j                   d«      r«d| j                   j
                  v r“|�‘t        j                  | j                   j
                  «      | j                   _        t        | j                   j
                  t        «      rd| j                   j
                  d<   nd| j                   j
                  _        t        | j                   d«      r«d| j                   j                  v r“|�‘t        j                  | j                   j                  «      | j                   _
        t        | j                   j                  t        «      rd| j                   j                  d<   nd| j                   j                  _        t        | j                   d«      r&| j                   j                  | j                   _        y y )	Nr   )ÚZambaModelTesterÚZamba2ModelTesterÚRwkvModelTesterÚAriaVisionText2TextModelTesterÚGPTNeoModelTesterÚDPTModelTesterÚout_featuresÚout_indicesÚnum_hidden_layersÚvision_configÚtext_configÚnum_hidden_groups)Úmodel_testerÚ	__class__Ú__name__ÚhasattrrQ  rR  ÚcopyÚdeepcopyÚ
isinstanceÚdictrS  rT  )r´   Útarget_num_hidden_layersÚexceptional_classess      rž   Ú$set_model_tester_for_less_flaky_testr_  ç  sÌ  € Ø ÐòÐð ×Ñ×'Ñ'×0Ñ0Ð4GÑGØ#'Ð Üˆy×%Ñ% ~Ô6¼'À)×BXÑBXÐZgÔ:hØ#'Ð äˆy×%Ñ%Ð':Ô;Ð@XÐ@dØ3Kˆ	×ÑÔ0ä�	×&Ñ&¨Ô8Ø 9×#9Ñ#9×#GÑ#GÑGØ$Ð0ä/3¯}©}¸Y×=SÑ=S×=aÑ=aÓ/bˆ	×ÑÔ,Ü�i×,Ñ,×:Ñ:¼DÔAØHIˆI×"Ñ"×0Ñ0Ð1DÒEàEFˆI×"Ñ"×0Ñ0ÔBä�	×&Ñ&¨Ô6Ø 9×#9Ñ#9×#EÑ#EÑEØ$Ð0ä-1¯]©]¸9×;QÑ;Q×;]Ñ;]Ó-^ˆ	×ÑÔ*Ü�i×,Ñ,×8Ñ8¼$Ô?ØFGˆI×"Ñ"×.Ñ.Ð/BÒCàCDˆI×"Ñ"×.Ñ.Ô@ô
 ˆy×%Ñ%Ð':Ô;Ø3<×3IÑ3I×3[Ñ3[ˆ	×ÑÕ0ð <rÁ   c                 ó    — g d¢}|D ]  }t        | |d«       Œ g d¢}|D ]-  }t        | |«      sŒ|D ]  }t        t        | |«      |d«       Œ Œ/ y )N)Úrms_norm_epsÚlayer_norm_epsÚnorm_epsÚnorm_epsilonÚlayer_norm_epsilonÚbatch_norm_epsç      ð?)rS  rR  Útext_encoderÚaudio_encoderÚdecoder)rÖ   rX  rÔ   )r  Útarget_attrsÚtarget_attrÚattrsrÙ   s        rž   Úset_config_for_less_flaky_testrn    sm   € ò€Lð $ò *ˆÜ�˜ SÕ)ð*ò
 Y€EØò AˆÜ�6˜4Õ Ø+ò A�Üœ ¨Ó-¨{¸CÕ@ñAñArÁ   c                 ó&  — d}g d¢}t        «       r�t        | t        j                  j                  «      r\| j                  «       D ]H  }t        |«      j                  j                  |«      sŒ(|D ]  }t        ||«      sŒt        ||d«       Œ ŒJ y y y )N)Ú	LayerNormÚ	GroupNormÚ	BatchNormÚRMSNormÚBatchNorm2dÚBatchNorm1dÚBitGroupNormActivationÚWeightStandardizedConv2d)ÚepsÚepsilonÚvariance_epsilonrg  )rm   r[  rV  Únnr‡   ÚmodulesÚtyperW  r"  rX  rÖ   )ÚmodelÚtarget_namesrk  ÚmodulerÙ   s        rž   Úset_model_for_less_flaky_testr�  *  s‚   € ð	€Lò :€LÜÔ¤
¨5´%·(±(·/±/Ô BØ—m‘m“oò 	3ˆFÜ�F‹|×$Ñ$×-Ñ-¨lÕ;Ø(ò 3�DÜ˜v tÕ,Ü ¨¨cÕ2ñ3ñ	3ð !CÐrÁ   c                   ó*   — e Zd ZdZdd„Zd„ Zd„ Zd„ Zy)Ú
CaptureStdav  
    Context manager to capture:

        - stdout: replay it, clean it up and make it available via `obj.out`
        - stderr: replay it and make it available via `obj.err`

    Args:
        out (`bool`, *optional*, defaults to `True`): Whether to capture stdout or not.
        err (`bool`, *optional*, defaults to `True`): Whether to capture stderr or not.
        replay (`bool`, *optional*, defaults to `True`): Whether to replay or not.
            By default each captured stream gets replayed back on context's exit, so that one can see what the test was
            doing. If this is a not wanted behavior and the captured data shouldn't be replayed, pass `replay=False` to
            disable this feature.

    Examples:

    ```python
    # to capture stdout only with auto-replay
    with CaptureStdout() as cs:
        print("Secret message")
    assert "message" in cs.out

    # to capture stderr only with auto-replay
    import sys

    with CaptureStderr() as cs:
        print("Warning: ", file=sys.stderr)
    assert "Warning" in cs.err

    # to capture both streams with auto-replay
    with CaptureStd() as cs:
        print("Secret message")
        print("Warning: ", file=sys.stderr)
    assert "message" in cs.out
    assert "Warning" in cs.err

    # to capture just one of the streams, and not the other, with auto-replay
    with CaptureStd(err=False) as cs:
        print("Secret message")
    assert "message" in cs.out
    # but best use the stream-specific subclasses

    # to capture without auto-replay
    with CaptureStd(replay=False) as cs:
        print("Secret message")
    assert "message" in cs.out
    ```c                 ó®   — || _         |rt        «       | _        d| _        nd | _        d| _        |rt        «       | _        d| _        y d | _        d| _        y )Nz=error: CaptureStd context is unfinished yet, called too earlyznot capturing stdoutznot capturing stderr)Úreplayr   Úout_bufrC  Úerr_bufÚerr)ÚselfrC  rˆ  r…  s       rž   Ú__init__zCaptureStd.__init__p  sK   € ØˆŒáÜ#›:ˆDŒLØVˆD�HàˆDŒLØ-ˆDŒHáÜ#›:ˆDŒLØVˆD�HàˆDŒLØ-ˆD�HrÁ   c                 óÞ   — | j                   r*t        j                  | _        | j                   t        _        | j                  r*t        j
                  | _        | j                  t        _        | S rÿ  )r†  ÚsysÚstdoutÚout_oldr‡  ÚstderrÚerr_old©r‰  s    rž   Ú	__enter__zCaptureStd.__enter__�  sA   € Ø�<Š<ÜŸ:™:ˆDŒLØŸ™ŒCŒJà�<Š<ÜŸ:™:ˆDŒLØŸ™ŒCŒJàˆrÁ   c                 óÌ  — | j                   rj| j                  t        _        | j                   j	                  «       }| j
                  rt        j                  j                  |«       t        |«      | _        | j                  rb| j                  t        _        | j                  j	                  «       }| j
                  rt        j                  j                  |«       || _        y y rÿ  )r†  rŽ  rŒ  r�  Úgetvaluer…  Úwriter?  rC  r‡  r�  r�  rˆ  )r‰  rÕ  Úcaptureds      rž   Ú__exit__zCaptureStd.__exit__Œ  s”   € Ø�<Š<ØŸ™ŒCŒJØ—|‘|×,Ñ,Ó.ˆHØ�{Š{Ü—
‘
× Ñ  Ô*Ü)¨(Ó3ˆDŒHà�<Š<ØŸ™ŒCŒJØ—|‘|×,Ñ,Ó.ˆHØ�{Š{Ü—
‘
× Ñ  Ô*ØˆD�Hð rÁ   c                 ó†   — d}| j                   r|d| j                  › d�z  }| j                  r|d| j                  › d�z  }|S )Nr:  zstdout: ú
ústderr: )r†  rC  r‡  rˆ  )r‰  Úmsgs     rž   Ú__repr__zCaptureStd.__repr__›  sH   € ØˆØ�<Š<Ø�X˜dŸh™h˜Z rÐ*Ñ*ˆCØ�<Š<Ø�X˜dŸh™h˜Z rÐ*Ñ*ˆCØˆ
rÁ   N)TTT©rW  Ú
__module__Ú__qualname__Ú__doc__rŠ  r’  r—  rœ  r  rÁ   rž   rƒ  rƒ  ?  s   „ ñ.ó`.ò"	ò órÁ   rƒ  c                   ó$   ‡ — e Zd ZdZdˆ fd„	Zˆ xZS )ÚCaptureStdoutz+Same as CaptureStd but captures only stdoutc                 ó(   •— t         ‰| �  d|¬«       y )NF)rˆ  r…  ©ÚsuperrŠ  ©r‰  r…  rV  s     €rž   rŠ  zCaptureStdout.__init__­  ó   ø€ Ü‰Ñ˜U¨6ÐÕ2rÁ   ©T©rW  rž  rŸ  r   rŠ  Ú__classcell__©rV  s   @rž   r¢  r¢  ª  ó   ø„ Ù5÷3ñ 3rÁ   r¢  c                   ó$   ‡ — e Zd ZdZdˆ fd„	Zˆ xZS )ÚCaptureStderrz+Same as CaptureStd but captures only stderrc                 ó(   •— t         ‰| �  d|¬«       y )NF)rC  r…  r¤  r¦  s     €rž   rŠ  zCaptureStderr.__init__´  r§  rÁ   r¨  r©  r«  s   @rž   r®  r®  ±  r¬  rÁ   r®  c                   ó(   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zy)ÚCaptureLoggera:  
    Context manager to capture `logging` streams

    Args:
        logger: 'logging` logger object

    Returns:
        The captured output is available via `self.out`

    Example:

    ```python
    >>> from transformers import logging
    >>> from transformers.testing_utils import CaptureLogger

    >>> msg = "Testing 1, 2, 3"
    >>> logging.set_verbosity_info()
    >>> logger = logging.get_logger("transformers.models.bart.tokenization_bart")
    >>> with CaptureLogger(logger) as cl:
    ...     logger.info(msg)
    >>> assert cl.out, msg + "
"
    ```
    c                 ó†   — || _         t        «       | _        t        j                  | j                  «      | _        d| _        y )Nr:  )Úloggerr   Úior   ÚStreamHandlerÚshrC  )r‰  r³  s     rž   rŠ  zCaptureLogger.__init__Ñ  s/   € ØˆŒÜ“*ˆŒÜ×'Ñ'¨¯©Ó0ˆŒØˆ�rÁ   c                 óP   — | j                   j                  | j                  «       | S rÿ  )r³  Ú
addHandlerr¶  r‘  s    rž   r’  zCaptureLogger.__enter__×  s   € Ø�‰×Ñ˜tŸw™wÔ'ØˆrÁ   c                 óŒ   — | j                   j                  | j                  «       | j                  j	                  «       | _        y rÿ  )r³  ÚremoveHandlerr¶  r´  r”  rC  )r‰  rÕ  s     rž   r—  zCaptureLogger.__exit__Û  s,   € Ø�‰×!Ñ! $§'¡'Ô*Ø—7‘7×#Ñ#Ó%ˆ�rÁ   c                 ó"   — d| j                   › d�S )Nz
captured: r™  )rC  r‘  s    rž   rœ  zCaptureLogger.__repr__ß  s   € Ø˜DŸH™H˜: RÐ(Ð(rÁ   Nr�  r  rÁ   rž   r±  r±  ¸  s   „ ñò0òò&ó)rÁ   r±  c              #   óÆ   K  — t        j                  «       }	 t        j                  | «       d–— t        j                  |«       y# t        j                  |«       w xY w­w)ae  
    This is a context manager to temporarily change transformers modules logging level to the desired value and have it
    restored to the original setting at the end of the scope.

    Example:

    ```python
    with LoggingLevel(logging.INFO):
        AutoModel.from_pretrained("openai-community/gpt2")  # calls logger.info() several times
    ```
    N)Útransformers_loggingÚget_verbosityÚset_verbosity)ÚlevelÚ
orig_levels     rž   ÚLoggingLevelrÂ  ã  sI   è ø€ ô &×3Ñ3Ó5€Jð7Ü×*Ñ*¨5Ô1Ûä×*Ñ*¨:Õ6øÔ×*Ñ*¨:Õ6üs   ‚A!˜A ±A!ÁAÁA!c                   ó>   — e Zd ZdZd	dee   dee   ddfd„Zd„ Zd„ Zy)
ÚTemporaryHubRepoaø  Create a temporary Hub repository and return its `RepoUrl` object. This is similar to
    `tempfile.TemporaryDirectory` and can be used as a context manager. For example:

        with TemporaryHubRepo(token=self._token) as temp_repo:
            ...

    Upon exiting the context, the repository and everything contained in it are removed.

    Example:

    ```python
    with TemporaryHubRepo(token=self._token) as temp_repo:
        model.push_to_hub(tmp_repo.repo_id, token=self._token)
    ```
    NÚ	namespacer#  r)  c                 óì   — || _         t        j                  «       5 }t        |«      j                  }|�|› d|› �}t        j                  || j                   ¬«      | _        d d d «       y # 1 sw Y   y xY w)Nú/)r#  )r#  ÚtempfileÚTemporaryDirectoryr   ÚnameÚhuggingface_hubÚcreate_repoÚrepo_url)r‰  rÅ  r#  Útmp_dirÚrepo_ids        rž   rŠ  zTemporaryHubRepo.__init__	  sm   € ØˆŒ
Ü×(Ñ(Ó*ð 	S¨gÜ˜7“m×(Ñ(ˆGØÐ$Ø&˜K q¨¨	Ð2�Ü+×7Ñ7¸ÀtÇzÁzÔRˆDŒM÷		S÷ 	Sñ 	Sús   œAA*Á*A3c                 ó   — | j                   S rÿ  )rÍ  r‘  s    rž   r’  zTemporaryHubRepo.__enter__  s   € Ø�}‰}ÐrÁ   c                 ó\   — t        | j                  j                  | j                  d¬«       y )NT)rÏ  r#  Ú
missing_ok)r   rÍ  rÏ  r#  )r‰  rÕ  rœ   Útbs       rž   r—  zTemporaryHubRepo.__exit__  s   € Ü˜DŸM™M×1Ñ1¸¿¹ÐPTÖUrÁ   ©NN)	rW  rž  rŸ  r   r   rÓ  rŠ  r’  r—  r  rÁ   rž   rÄ  rÄ  ø  s9   „ ññ S (¨3¡-ð S¸xÈ¹}ð SÐX\ó SòóVrÁ   rÄ  r  c              #   ó  K  — t        j                  | «      } 	 t        j                  j	                  d| «       d–— t        j                  j                  | «       y# t        j                  j                  | «       w xY w­w)z´
    Temporary add given path to `sys.path`.

    Usage :

    ```python
    with ExtendSysPath("/path/to/dir"):
        mymodule = importlib.import_module("mymodule")
    ```
    r   N)r•   ÚfspathrŒ  r  ÚinsertÚremove)r  s    rž   ÚExtendSysPathrÙ    sO   è ø€ ô �9‰9�T‹?€DðÜ�‰�‰˜˜4Ô Ûä�‰�‰˜ÕøŒ�‰�‰˜Õüs   ‚B™$A ½ BÁ!A>Á>Bc                   óð   — e Zd ZdZd„ Zed„ «       Zed„ «       Zed„ «       Zed„ «       Z	ed„ «       Z
ed„ «       Zed	„ «       Zed
„ «       Zed„ «       Zed„ «       Zed„ «       Zed„ «       Zd„ Zdd„Zd„ Zd„ Zy)ÚTestCasePlusa¢  
    This class extends *unittest.TestCase* with additional features.

    Feature 1: A set of fully resolved important file and dir path accessors.

    In tests often we need to know where things are relative to the current test file, and it's not trivial since the
    test could be invoked from more than one directory or could reside in sub-directories with different depths. This
    class solves this problem by sorting out all the basic paths and provides easy accessors to them:

    - `pathlib` objects (all fully resolved):

       - `test_file_path` - the current test file path (=`__file__`)
       - `test_file_dir` - the directory containing the current test file
       - `tests_dir` - the directory of the `tests` test suite
       - `examples_dir` - the directory of the `examples` test suite
       - `repo_root_dir` - the directory of the repository
       - `src_dir` - the directory of `src` (i.e. where the `transformers` sub-dir resides)

    - stringified paths---same as above but these return paths as strings, rather than `pathlib` objects:

       - `test_file_path_str`
       - `test_file_dir_str`
       - `tests_dir_str`
       - `examples_dir_str`
       - `repo_root_dir_str`
       - `src_dir_str`

    Feature 2: Flexible auto-removable temporary dirs which are guaranteed to get removed at the end of test.

    1. Create a unique temporary dir:

    ```python
    def test_whatever(self):
        tmp_dir = self.get_auto_remove_tmp_dir()
    ```

    `tmp_dir` will contain the path to the created temporary dir. It will be automatically removed at the end of the
    test.


    2. Create a temporary dir of my choice, ensure it's empty before the test starts and don't
    empty it after the test.

    ```python
    def test_whatever(self):
        tmp_dir = self.get_auto_remove_tmp_dir("./xxx")
    ```

    This is useful for debug when you want to monitor a specific directory and want to make sure the previous tests
    didn't leave any data in there.

    3. You can override the first two options by directly overriding the `before` and `after` args, leading to the
        following behavior:

    `before=True`: the temporary dir will always be cleared at the beginning of the test.

    `before=False`: if the temporary dir already existed, any existing files will remain there.

    `after=True`: the temporary dir will always be deleted at the end of the test.

    `after=False`: the temporary dir will always be left intact at the end of the test.

    Note 1: In order to run the equivalent of `rm -r` safely, only subdirs of the project repository checkout are
    allowed if an explicit `tmp_dir` is used, so that by mistake no `/tmp` or similar important part of the filesystem
    will get nuked. i.e. please always pass paths that start with `./`

    Note 2: Each test can register multiple temporary dirs and they all will get auto-removed, unless requested
    otherwise.

    Feature 3: Get a copy of the `os.environ` object that sets up `PYTHONPATH` specific to the current test suite. This
    is useful for invoking external programs from the test suite - e.g. distributed training.


    ```python
    def test_whatever(self):
        env = self.get_env()
    ```c                 ó  — g | _         t        j                  | j                  «      | _        t        | j                  «      j                  «       }|j                  d   | _        dD ]:  }|j                  |   }|dz  j                  «       sŒ&|dz  j                  «       sŒ: n r|| _
        nt        d| j                  › �«      ‚| j                  dz  | _        | j                  dz  | _        | j                  dz  | _        y )Nr   )r   ra  rf  Úsrcr  z+can't figure out the root of the repo from Úexamples)Úteardown_tmp_dirsr  ÚgetfilerV  Ú_test_file_pathr   ÚresolveÚparentsÚ_test_file_dirÚis_dirÚ_repo_root_dirr—   Ú
_tests_dirÚ_examples_dirÚ_src_dir)r‰  r  ÚuprÎ  s       rž   ÚsetUpzTestCasePlus.setUp}  sè   € à!#ˆÔô  'Ÿ™¨t¯~©~Ó>ˆÔÜ�D×(Ñ(Ó)×1Ñ1Ó3ˆØ"Ÿl™l¨1™oˆÔØò 	ˆBØ—l‘l 2Ñ&ˆGØ˜%‘×'Ñ'Õ)¨w¸Ñ/@×.HÑ.HÕ.JÙð	ñ Ø")ˆDÕäÐJÈ4×K_ÑK_ÐJ`ÐaÓbÐbØ×-Ñ-°Ñ7ˆŒØ!×0Ñ0°:Ñ=ˆÔØ×+Ñ+¨eÑ3ˆ�rÁ   c                 ó   — | j                   S rÿ  )rá  r‘  s    rž   Útest_file_pathzTestCasePlus.test_file_path‘  s   € à×#Ñ#Ð#rÁ   c                 ó,   — t        | j                  «      S rÿ  )rÓ  rá  r‘  s    rž   Útest_file_path_strzTestCasePlus.test_file_path_str•  s   € ä�4×'Ñ'Ó(Ð(rÁ   c                 ó   — | j                   S rÿ  )rä  r‘  s    rž   Útest_file_dirzTestCasePlus.test_file_dir™  ó   € à×"Ñ"Ð"rÁ   c                 ó,   — t        | j                  «      S rÿ  )rÓ  rä  r‘  s    rž   Útest_file_dir_strzTestCasePlus.test_file_dir_str�  ó   € ä�4×&Ñ&Ó'Ð'rÁ   c                 ó   — | j                   S rÿ  )rç  r‘  s    rž   r&  zTestCasePlus.tests_dir¡  s   € à�‰ÐrÁ   c                 ó,   — t        | j                  «      S rÿ  )rÓ  rç  r‘  s    rž   Útests_dir_strzTestCasePlus.tests_dir_str¥  s   € ä�4—?‘?Ó#Ð#rÁ   c                 ó   — | j                   S rÿ  )rè  r‘  s    rž   Úexamples_dirzTestCasePlus.examples_dir©  s   € à×!Ñ!Ð!rÁ   c                 ó,   — t        | j                  «      S rÿ  )rÓ  rè  r‘  s    rž   Úexamples_dir_strzTestCasePlus.examples_dir_str­  s   € ä�4×%Ñ%Ó&Ð&rÁ   c                 ó   — | j                   S rÿ  )ræ  r‘  s    rž   Úrepo_root_dirzTestCasePlus.repo_root_dir±  rò  rÁ   c                 ó,   — t        | j                  «      S rÿ  )rÓ  ræ  r‘  s    rž   Úrepo_root_dir_strzTestCasePlus.repo_root_dir_strµ  rõ  rÁ   c                 ó   — | j                   S rÿ  )ré  r‘  s    rž   Úsrc_dirzTestCasePlus.src_dir¹  s   € à�}‰}ÐrÁ   c                 ó,   — t        | j                  «      S rÿ  )rÓ  ré  r‘  s    rž   Úsrc_dir_strzTestCasePlus.src_dir_str½  s   € ä�4—=‘=Ó!Ð!rÁ   c                 óP  — t         j                  j                  «       }| j                  g}d| j                  v r|j                  | j                  «       n|j                  | j                  «       |j                  |j                  dd«      «       dj                  |«      |d<   |S )a®  
        Return a copy of the `os.environ` object that sets up `PYTHONPATH` correctly, depending on the test suite it's
        invoked from. This is useful for invoking external programs from the test suite - e.g. distributed training.

        It always inserts `./src` first, then `./tests` or `./examples` depending on the test suite type and finally
        the preset `PYTHONPATH` if any (all full resolved paths).

        z	/examplesÚ
PYTHONPATHr:  ú:)
r•   r–   rY  r  rô  Úappendrü  rø  Úgetr#  )r‰  ÚenvÚpathss      rž   Úget_envzTestCasePlus.get_envÁ  s‚   € ô �j‰j�o‰oÓˆØ×!Ñ!Ð"ˆØ˜$×0Ñ0Ñ0Ø�L‰L˜×.Ñ.Õ/à�L‰L˜×+Ñ+Ô,Ø�‰�S—W‘W˜\¨2Ó.Ô/àŸH™H U›OˆˆLÑØˆ
rÁ   Nc                 ó€  — |�€|€d}|€d}t        |«      j                  «       }|j                  d«      st        d|› d�«      ‚|du r'|j	                  «       rt        j                  |d¬«       |j                  dd¬«       n|€d}|€d}t        j                  «       }|du r| j                  j                  |«       |S )a  
        Args:
            tmp_dir (`string`, *optional*):
                if `None`:

                   - a unique temporary path will be created
                   - sets `before=True` if `before` is `None`
                   - sets `after=True` if `after` is `None`
                else:

                   - `tmp_dir` will be created
                   - sets `before=True` if `before` is `None`
                   - sets `after=False` if `after` is `None`
            before (`bool`, *optional*):
                If `True` and the `tmp_dir` already exists, make sure to empty it right away if `False` and the
                `tmp_dir` already exists, any existing files will remain there.
            after (`bool`, *optional*):
                If `True`, delete the `tmp_dir` at the end of the test if `False`, leave the `tmp_dir` and its contents
                intact at the end of the test.

        Returns:
            tmp_dir(`string`): either the same value as passed via *tmp_dir* or the path to the auto-selected tmp dir
        TFz./zI`tmp_dir` can only be a relative path, i.e. `./some/path`, but received `ú`©Úignore_errors©rã  Úexist_ok)r   râ  rÓ   r—   Úexistsr   ÚrmtreeÚmkdirrÈ  Úmkdtemprß  r  )r‰  rÎ  ÚbeforeÚafterr  s        rž   Úget_auto_remove_tmp_dirz$TestCasePlus.get_auto_remove_tmp_dirÕ  sÕ   € ð0 Ðð
 ˆ~Ø�Øˆ}Ø�ô ˜“=×(Ñ(Ó*ˆDð ×%Ñ% dÔ+Ü Ø_Ð`gÐ_hÐhiÐjóð ð
 ˜‰~ $§+¡+¤-Ü—‘˜g°TÕ:à�J‰J˜t¨dˆJÕ3ð ˆ~Ø�Øˆ}Ø�ô ×&Ñ&Ó(ˆGà�D‰=à×"Ñ"×)Ñ)¨'Ô2àˆrÁ   c                 óL  — t        d«      st        d«      ‚t        j                  d|› d�«      }t	        «       5 }t        || j                  «       ¬«       ddd«       t        j                  j                  d«      d   j                  d	d
«      «      dz  }|S # 1 sw Y   ŒExY w)aÍ  
        Runs the passed python one liner (just the code) and returns how much max cpu memory was used to run the
        program.

        Args:
            one_liner_str (`string`):
                a python one liner code that gets passed to `python -c`

        Returns:
            max cpu memory bytes used to run the program. This value is likely to vary slightly from run to run.

        Requirements:
            this helper needs `/usr/bin/time` to be installed (`apt install time`)

        Example:

        ```
        one_liner_str = 'from transformers import AutoModel; AutoModel.from_pretrained("google-t5/t5-large")'
        max_rss = self.python_one_liner_max_rss(one_liner_str)
        ```
        r  z:/usr/bin/time is required, install with `apt install time`z/usr/bin/time -f %M python -c 'ú')r
  Nr™  éþÿÿÿrš  r:  i   )
r  r—   ÚshlexÚsplitrƒ  Úexecute_subprocess_asyncr  r¢   rˆ  Úreplace)r‰  Úone_liner_strr  ÚcsÚmax_rsss        rž   Úpython_one_liner_max_rssz%TestCasePlus.python_one_liner_max_rss  s‘   € ô. ˜/Ô*ÜÐYÓZÐZä�k‰kÐ;¸M¸?È!ÐLÓMˆÜ‹\ð 	>˜RÜ$ S¨d¯l©l«nÕ=÷	>ô �b—f‘f—l‘l 4Ó(¨Ñ,×4Ñ4°ZÀÓDÓEÈÑLˆØˆ÷		>ð 	>ús   ºBÂB#c                 óL  — | j                   D ]  }t        j                  |d¬«       Œ g | _         t        «       rkt	        j
                  «        t        j
                  «        t        t        j                  j                  «       «      D ]  }d|v sŒt        j                  |= Œ y y )NTr  Ú
ACCELERATE)rß  r   r  r%   r„   Ú_reset_stater…   Úlistr•   r–   Úkeys)r‰  r  Úks      rž   ÚtearDownzTestCasePlus.tearDown:  s„   € à×*Ñ*ò 	4ˆDÜ�M‰M˜$¨dÖ3ð	4à!#ˆÔÜ"Ô$Ü×)Ñ)Ô+Ü×%Ñ%Ô'ô œ"Ÿ*™*Ÿ/™/Ó+Ó,ò &�Ø 1Ò$ÜŸ
™
 1™ñ&ð %rÁ   )NNN)rW  rž  rŸ  r   rë  Úpropertyrí  rï  rñ  rô  r&  rø  rú  rü  rþ  r   r  r  r  r  r$  r+  r  rÁ   rž   rÛ  rÛ  .  s  „ ñLò\4ð( ñ$ó ð$ð ñ)ó ð)ð ñ#ó ð#ð ñ(ó ð(ð ñó ðð ñ$ó ð$ð ñ"ó ð"ð ñ'ó ð'ð ñ#ó ð#ð ñ(ó ð(ð ñó ðð ñ"ó ð"òó(BòHóB&rÁ   rÛ  c                  ó^   — t         j                  j                  t        j                  | «      S )zÒ
    this is a convenience wrapper, that allows this ::

    @mockenv(RUN_SLOW=True, USE_TF=False) def test_something():
        run_slow = os.getenv("RUN_SLOW", False) use_tf = os.getenv("USE_TF", False)

    )r   r   r\  r•   r–   )rÉ   s    rž   Úmockenvr.  I  s   € ô �:‰:�?‰?œ2Ÿ:™: vÓ.Ð.rÁ   c               /   óp  ‡K  — t         j                  Š|xs i }| xs g } t        |j                  «       «      t        | «      z  t        ‰j                  «       «      z  }|D �ci c]  }|‰|   “Œ
 }}t	        ˆfd„|D «       «      }	 ‰j                  |«       | D �cg c]  }‰j                  |d«      ‘Œ c} d–— ‰j                  |«       |D �cg c]  }‰j                  |«      ‘Œ c} yc c}w c c}w c c}w # ‰j                  |«       |D �cg c]  }‰j                  |«      ‘Œ c} w c c}w xY w­w)aM  
    Temporarily updates the `os.environ` dictionary in-place. Similar to mockenv

    The `os.environ` dictionary is updated in-place so that the modification is sure to work in all situations.

    Args:
      remove: Environment variables to remove.
      update: Dictionary of environment variables and values to add/update.
    c              3   ó,   •K  — | ]  }|‰vsŒ|–— Œ y ­wrÿ  r  )Ú.0r*  r
  s     €rž   ú	<genexpr>z"mockenv_context.<locals>.<genexpr>i  s   øè ø€ Ò? 1°!¸3²,œQÑ?ùs   ƒ	�N)r•   r–   Úsetr)  Ú	frozensetÚupdateÚpop)rØ  r5  Ústompedr*  Úupdate_afterÚremove_afterr
  s         @rž   Úmockenv_contextr:  U  sÿ   øè ø€ ô �*‰*€CØŠ\�r€FØŠ\�r€Fô �6—;‘;“=Ó!¤C¨£KÑ/´3°s·x±x³z³?ÑB€Gà'.Ö/ !�A�s˜1‘v‘IÐ/€LÐ/äÓ?¨Ô?Ó?€Lð+Ø�
‰
�6ÔØ#)Ö*˜aˆ�‰��DÕ	Ó*Ûà�
‰
�<Ô Ø)Ö*˜ˆ�‰��Ô*ùò 0ùò 	+ùò 	+øð 	�
‰
�<Ô Ø)Ö*˜ˆ�‰��Ô*ùÒ*üsZ   ƒA D6Á#C-Á0D6ÂC< ÂC2Â5C< Â<D6ÃC7Ã)	D6Ã2C< Ã7D6Ã<D3ÄD.Ä*	D3Ä3D6c                 óV   — d}|t         vr| j                  |ddd¬«       dt         |<   yy)zö
    This function is to be called from `conftest.py` via `pytest_addoption` wrapper that has to be defined there.

    It allows loading both `conftest.py` files at once without causing a failure due to adding the same `pytest`
    option.

    z--make-reportsÚstoreFzSgenerate report files. The value of this option is used as a prefix to report names)Úactionr›   Úhelpr   N)Úpytest_opt_registeredÚ	addoption)ÚparserÚoptions     rž   Úpytest_addoption_sharedrC  z  sC   € ð €FØÔ*Ñ*Ø×ÑØØØØfð	 	ô 	
ð )*Ô˜fÒ%ð +rÁ   c           
      ó’  — ddl m} t        |«      sd}| j                  }|j	                  «       }|j
                  j                  }| j                  }d|› �}t        |«      j                  dd¬«       dD �ci c]  }||› d|› d	�“Œ }	}g }
| j                  j                  «       D ]'  }|D ]   }t        |d
«      sŒ|
j                  |«       Œ" Œ) |
rÀ|
j                  d„ d¬«       t        |	d   d«      5 }d}|j!                  d«       t#        |
«      D ]s  \  }}|j$                  |k  r%|j!                  t        |
«      |z
  › d|› d�«        n<|j!                  |j$                  d›d|j&                  d›d|j(                  › d�«       Œu ddd«       d„ }d|j
                  _        t        |	d   d«      5 } |||«      | _        | j-                  «        ddd«       t        |	d   d«      5 } |||«      | _         || «       ddd«       d|j
                  _        t        |	d   d«      5 } |||«      | _        | j-                  «        ddd«       t        |	d   d«      5 } |||«      | _        | j/                  «        ddd«       t        |	d    d«      5 } |||«      | _        | j1                  «        | j1                  «        ddd«       d!| _        t        |	d"   d«      5 } |||«      | _        | j3                  «        ddd«       t        |	d#   d«      5 } |||«      | _        | j5                  «        ddd«       || _        || _        ||j
                  _        yc c}w # 1 sw Y   �ŒÝxY w# 1 sw Y   �Œ xY w# 1 sw Y   �ŒxY w# 1 sw Y   �ŒExY w# 1 sw Y   �ŒxY w# 1 sw Y   ŒâxY w# 1 sw Y   Œ±xY w# 1 sw Y   Œ‡xY w)$a�  
    Generate multiple reports at the end of test suite run - each report goes into a dedicated file in the current
    directory. The report files are prefixed with the test suite name.

    This function emulates --duration and -rA pytest arguments.

    This function is to be called from `conftest.py` via `pytest_terminal_summary` wrapper that has to be defined
    there.

    Args:
    - tr: `terminalreporter` passed from `conftest.py`
    - id: unique id like `tests` or `examples` that will be incorporated into the final reports filenames - this is
      needed as some jobs have multiple runs of pytest, so we can't have them overwrite each other.

    NB: this functions taps into a private _pytest API and while unlikely, it could break should pytest do internal
    changes - also it calls default internal methods of terminalreporter which can be hijacked by various `pytest-`
    plugins and interfere.

    r   )Úcreate_terminal_writerr  zreports/Tr  )	Ú	durationsÚerrorsÚfailures_longÚfailures_shortÚfailures_lineÚpassesÚstatsÚsummary_shortÚwarningsrÇ  z.txtÚdurationc                 ó   — | j                   S rÿ  )rO  ©Úxs    rž   ú<lambda>z.pytest_terminal_summary_main.<locals>.<lambda>Å  s
   €  §¡€ rÁ   )rš   ÚreverserF  Úwgš™™™™™©?zslowest durations
z durations < z secs were omittedz02.2fzs z<8ú r™  Nc           	      ód  — | j                  d«      }|sy | j                  dd«       |D ]…  }| j                  |«      }| j                  d|dd¬«       t        j                  dd|j
                  d	t        j                  t        j                  z  «      }| j                  j                  |«       Œ‡ y )
NÚfailedú=zFAILURES SHORT STACKÚ_T)ÚredÚboldz.*_ _ _ (_ ){10,}_ _ r:  r   )
Ú
getreportsÚ	write_sepÚ_getfailureheadliner;  r<  Úlongreprtextr=  ÚSÚ_twÚline)ÚtrÚreportsÚrepr›  Úlongreprs        rž   Úsummary_failures_shortz<pytest_terminal_summary_main.<locals>.summary_failures_shortÏ  s˜   € à—-‘- Ó)ˆÙØØ
�‰�SÐ0Ô1Øò 	"ˆCØ×(Ñ(¨Ó-ˆCØ�L‰L˜˜c t°$ˆLÔ7ä—v‘vÐ6¸¸C×<LÑ<LÈaÔQS×QUÑQUÔXZ×X\ÑX\ÑQ\Ó]ˆHØ�F‰F�K‰K˜Õ!ñ	"rÁ   ÚautorH  rI  rc  rJ  rG  rN  ÚwPpsxXEfrM  rL  )Ú_pytest.configrE  r  r  Úget_terminal_writerrB  ÚtbstyleÚreportcharsr   r  rL  ÚvaluesrX  r  ÚsortÚopenr•  Ú	enumeraterO  ÚwhenÚnodeidrb  Úsummary_failuresÚsummary_errorsÚsummary_warningsÚshort_test_summaryÚsummary_stats)rd  ÚidrE  r  Úorig_writerÚorig_tbstyleÚorig_reportcharsrÒ   r*  Úreport_filesÚdlistÚreplistrf  ÚfÚdurations_minÚirh  s                    rž   Úpytest_terminal_summary_mainr„  �  sÆ  € õ( 6äˆrŒ7Øˆà�Y‰Y€FØ×,Ñ,Ó.€KØ—=‘=×(Ñ(€LØ—~‘~Ðà�R�Dˆ/€CÜˆƒI‡O�O˜D¨4€OÔ0ð

öàð 	
ˆcˆU�!�A�3�dÐÑð€Lð ð$ €EØ—8‘8—?‘?Ó$ò "ˆØò 	"ˆCÜ�s˜JÕ'Ø—‘˜SÕ!ñ	"ð"ñ Ø�
‰
Ñ+°Tˆ
Ô:Ü�,˜{Ñ+¨SÓ1ð 	O°QØ ˆMØ�G‰GÐ)Ô*Ü# EÓ*ò O‘��3Ø—<‘< -Ò/Ø—G‘Gœs 5›z¨A™~Ð.¨m¸M¸?ÐJ\Ð]Ô^ÙØ—‘˜3Ÿ<™<¨Ð.¨b°·±¸"°¸Q¸s¿z¹z¸lÈ"ÐMÕNð	O÷	Oò"ð( #€F‡M�MÔÜ	ˆl˜?Ñ+¨SÓ	1ð °QÙ'¨°Ó2ˆŒØ
×ÑÔ÷ô
 
ˆlÐ+Ñ,¨cÓ	2ð #°aÙ'¨°Ó2ˆŒÙ˜rÔ"÷#ð #€F‡M�MÔÜ	ˆl˜?Ñ+¨SÓ	1ð °QÙ'¨°Ó2ˆŒØ
×ÑÔ÷ô 
ˆl˜8Ñ$ cÓ	*ð ¨aÙ'¨°Ó2ˆŒØ
×ÑÔ÷ô 
ˆl˜:Ñ&¨Ó	,ð °Ù'¨°Ó2ˆŒØ
×ÑÔØ
×ÑÔ÷ð
  €B„Nô 
ˆl˜?Ñ+¨SÓ	1ð  °QÙ'¨°Ó2ˆŒØ
×ÑÔ÷ ô 
ˆl˜7Ñ# SÓ	)ð ¨QÙ'¨°Ó2ˆŒØ
×ÑÔ÷ð
 €B„FØ%€B„NØ(€F‡M�MÕùòE÷2	Oñ 	Oú÷<ñ ú÷
#ñ #ú÷
ñ ú÷ñ ú÷ð ú÷ ð  ú÷ð úsg   Á7MÃ4BM$Æ4M1Ç*M>È)NÉNÊ/N%Ë"N1ÌN=Í$M.Í1M;Í>NÎNÎN"Î%N.Î1N:Î=Oc                   ó   — e Zd Zd„ Zy)Ú
_RunOutputc                 ó.   — || _         || _        || _        y rÿ  )Ú
returncoder�  r�  )r‰  rˆ  r�  r�  s       rž   rŠ  z_RunOutput.__init__	  s   € Ø$ˆŒØˆŒØˆ�rÁ   N)rW  rž  rŸ  rŠ  r  rÁ   rž   r†  r†  	  s   „ órÁ   r†  c              ƒ   óZ   K  — 	 | j                  «       ƒ d {  –—† }|r	 ||«       ny Œ%7 Œ­wrÿ  )Úreadline)ÚstreamÚcallbackrc  s      rž   Ú_read_streamr�  	  s-   è ø€ Ø
Ø—_‘_Ó&×&ˆÙÙ�T�Nàð Ø&ús   ‚+—)˜+c           
   ƒ   óT  ‡‡‡‡	K  — |rt        ddj                  | «      «       t        j                  | d   g| dd  ¢­|t        j                  j
                  t        j                  j
                  |dœŽƒ d {  –—† }g Šg Šd
ˆfd„	Š	t        j                  t        j                  t        |j                  ˆˆ	fd„«      «      t        j                  t        |j                  ˆˆ	fd„«      «      g|¬	«      ƒ d {  –—†  t        |j                  «       ƒ d {  –—† ‰‰«      S 7 Œ¨7 Œ)7 Œ­w)Nz

Running: rV  r   r   )Ústdinr�  r�  r
  c                 óˆ   •— | j                  d«      j                  «       } |j                  | «       ‰st        || |¬«       y y )Núutf-8)Úfile)ÚdecodeÚrstripr  Úprint)rc  ÚsinkÚpipeÚlabelÚquiets       €rž   Úteez_stream_subprocess.<locals>.tee@	  s:   ø€ Ø�{‰{˜7Ó#×*Ñ*Ó,ˆØ�‰�DÔÙÜ�%˜ DÖ)ð rÁ   c                 ó8   •—  ‰| ‰t         j                  d¬«      S )Nzstdout:©r˜  )rŒ  r�  )ÚlrC  rš  s    €€rž   rS  z$_stream_subprocess.<locals>.<lambda>I	  ó   ø€ ÁÀQÈÌSÏZÉZÐ_hÔAi€ rÁ   c                 ó8   •—  ‰| ‰t         j                  d¬«      S )Nzstderr:rœ  )rŒ  r�  )r�  rˆ  rš  s    €€rž   rS  z$_stream_subprocess.<locals>.<lambda>J	  rž  rÁ   ©Útimeout)r:  )r•  r#  ÚasyncioÚcreate_subprocess_execÚ
subprocessÚPIPEÚwaitÚcreate_taskr�  r�  r�  r†  )
r  r
  r�  r¡  r™  ÚechoÚprˆ  rC  rš  s
       `  @@@rž   Ú_stream_subprocessrª  (	  s  ûè ø€ ÙÜˆm˜SŸX™X c›]Ô+ä×,Ñ,ØˆA‰ðà	ˆQˆRˆñð Ü×!Ñ!×&Ñ&Ü×!Ñ!×&Ñ&Øò÷ 	€Að" €CØ
€Cõ*ô �,‰,ä×Ñ¤¨Q¯X©XÔ7iÓ jÓkÜ×Ñ¤¨Q¯X©XÔ7iÓ jÓkð	
ð ô÷ ð ô ˜AŸF™F›H—n c¨3Ó/Ð/ðE	øð6øð %ús7   †A3D(Á9D"Á:B D(Ã:D$Ã;D(ÄD&ÄD(Ä$D(Ä&D(c           
      ón  — t        j                  «       }|j                  t        | |||||¬«      «      }dj	                  | «      }|j
                  dkD  r9dj	                  |j                  «      }	t        d|› d|j
                  › d|	› �«      ‚|j                  s|j                  st        d|› d�«      ‚|S )	N)r
  r�  r¡  r™  r¨  rV  r   r™  r  z' failed with returncode z,

The combined stderr from workers follows:
z' produced no output.)	r¢  Úget_event_loopÚrun_until_completerª  r#  rˆ  r�  ÚRuntimeErrorr�  )
r  r
  r�  r¡  r™  r¨  ÚloopÚresultÚcmd_strr�  s
             rž   r  r  Q	  s¾   € Ü×!Ñ!Ó#€DØ×$Ñ$Ü˜3 C¨u¸gÈUÐY]Ô^ó€Fð �h‰h�s‹m€GØ×Ñ˜1ÒØ—‘˜6Ÿ=™=Ó)ˆÜØ�ˆyÐ1°&×2CÑ2CÐ1Dð E:Ø:@¸ðCó
ð 	
ð �=Š= §¢Ü˜Q˜w˜iÐ'<Ð=Ó>Ð>à€MrÁ   c                  ó¦   — t         j                  j                  dd«      } t        j                  dd| dt        j
                  «      } t        | «      S )z®
    Returns an int value of worker's numerical id under `pytest-xdist`'s concurrent workers `pytest -n N` regime, or 0
    if `-n 1` or `pytest-xdist` isn't being used.
    ÚPYTEST_XDIST_WORKERÚgw0z^gwr:  r   )r•   r–   r	  r;  r<  r=  r¢   )Úworkers    rž   Úpytest_xdist_worker_idr¶  g	  s=   € ô
 �Z‰Z�^‰^Ð1°5Ó9€FÜ�V‰V�F˜B ¨¬2¯4©4Ó0€FÜˆv‹;ÐrÁ   c                  ó$   — d} t        «       }| |z   S )zô
    Returns a port number that can be fed to `torch.distributed.launch`'s `--master_port` argument.

    Under `pytest-xdist` it adds a delta number based on a worker id so that concurrent tests don't try to use the same
    port at once.
    i<s  )r¶  )ÚportÚ
uniq_deltas     rž   Úget_torch_dist_unique_portrº  q	  s   € ð €DÜ'Ó)€JØ�*ÑÐrÁ   c           	      ó  — ddl }t        | t        «      r| D �cg c]  }t        ||«      ‘Œ c}S t        | t        «      r#t	        | D �cg c]  }t        ||«      ‘Œ c}«      S t        | |j
                  «      rt        | j                  «       «      S t        | t        «      r8| j                  «       D ��ci c]  \  }}t        ||«      t        ||«      “Œ c}}S t        | t        t        |j                  f«      r| S | €| S t        «       r4t        | t        j                  «      rt        | j                  «       |«      S t        «       r<t!        j"                  | «      r't        | j                  «       j                  «       «      S t        | t$        «      rt'        | |«      S t        | |j(                  |j*                  |j,                  f«      rt        | j/                  «       |«      S t1        dt3        | «      › �«      ‚c c}w c c}w c c}}w )zŒ
    Simplifies an object by rounding float numbers, and downcasting tensors/numpy arrays to get simple equality test
    within tests.
    r   NzNot supported: )Únumpyr[  r(  Únested_simplifyÚtupleÚndarrayÚtolistr   ÚitemsrÓ  r¢   Úint64rm   rV  ÚTensorri   r  Ú	is_tensorÚfloatÚroundÚint32Úfloat32Úfloat16ÚitemÚ	Exceptionr}  )ÚobjÚdecimalsÚnprÊ  r*  Úvs         rž   r½  r½  }	  sŒ  € ó
 ä�#”tÔØ<?Ö@°D”  hÕ/Ò@Ð@Ü�#”uÔÜÀ#ÖF¸$”o d¨HÕ5ÒFÓGÐGÜ	�C˜Ÿ™Ô	$Ü˜sŸz™z›|Ó,Ð,Ü	�CœÔ	!ØWZ×W`ÑW`ÓWb×cÉtÈqÐRS”  8Ó,¬o¸aÀÓ.JÑJÓcÐcÜ	�Cœ#œs B§H¡HÐ-Ô	.Øˆ
Ø	ˆØˆ
Ü	Ô	¤*¨S´%·,±,Ô"?Ü˜sŸz™z›|¨XÓ6Ð6Ü	Ô	œrŸ|™|¨CÔ0Ü˜sŸy™y›{×1Ñ1Ó3Ó4Ð4Ü	�CœÔ	Ü�S˜(Ó#Ð#Ü	�C˜"Ÿ(™( B§J¡J°·
±
Ð;Ô	<Ü˜sŸx™x›z¨8Ó4Ð4ä˜/¬$¨s«)¨Ð5Ó6Ð6ùò) AùâFùó ds   ™G>ÁHÂ4!Hc                 óŒ  — t        | «      5 }|j                  «       }t        |«      dk(  r
|d   dk(  s~J ‚t        |«      dk\  sJ ‚|d   j                  «       dk(  sJ ‚|dd D ]4  }t        |d   «      t        |d   j	                  «       «      z
  }|dk(  rŒ4J ‚ |d   j                  «       dk(  sJ ‚d d d «       y # 1 sw Y   y xY w)	Nr   r   z{}rf  ú{r7  ra  ú})rq  Ú	readlinesr  ÚstripÚlstrip)Ú	file_pathr�  Úlinesrc  Úleft_indents        rž   Ú"check_json_file_has_correct_formatrÙ  œ	  sÓ   € Ü	ˆi‹ð ,˜AØ—‘“ˆÜˆu‹:˜Š?à˜‘8˜tÒ#Ð#Ð#ô �u“: ’?Ð"�?à˜‘8—>‘>Ó# sÒ*Ð*Ð*Ø˜a ˜ò (�Ü! %¨¡(›m¬c°%¸±(·/±/Ó2CÓ.DÑD�Ø" aÓ'Ð'Ð'ð(ð ˜‘9—?‘?Ó$¨Ò+Ð+Ð+÷,÷ ,ñ ,ús   ŒB	B:ÂB:Â:Cc                 óV   — t        | t        j                  j                  «      r| S | | fS rÿ  )r[  ÚcollectionsÚabcr   rQ  s    rž   Ú	to_2tuplerÝ  ­	  s$   € Ü�!”[—_‘_×-Ñ-Ô.ØˆØˆqˆ6€MrÁ   c                   ó   — e Zd Zy)ÚSubprocessCallExceptionN)rW  rž  rŸ  r  rÁ   rž   rß  rß  ´	  s   „ ØrÁ   rß  Úcommandc                 ó:  — 	 t        j                  | t         j                  ¬«      }|rt        |d«      r|j	                  d«      }|S y# t         j
                  $ r>}t        ddj                  | «      › d|j                  j	                  «       › �«      |‚d}~ww xY w)z­
    Runs `command` with `subprocess.check_output` and will potentially return the `stdout`. Will also properly capture
    if an error occurred while running `command`
    )r�  r“  r‘  z	Command `rV  z$` failed with the following error:

N)	r¤  Úcheck_outputÚSTDOUTrX  r“  ÚCalledProcessErrorrß  r#  Úoutput)rà  Úreturn_stdoutrå  rÊ   s       rž   Úrun_commandrç  ¸	  s˜   € ð
	Ü×(Ñ(¨¼×9JÑ9JÔKˆÙÜ�v˜xÔ(ØŸ™ wÓ/�ØˆMð øô ×(Ñ(ò Ü%Ø˜Ÿ™ Ó)Ð*Ð*PÐQR×QYÑQY×Q`ÑQ`ÓQbÐPcÐdó
àð	ûðús   ‚AA	 Á	BÁ9BÂBc                   óD   — e Zd ZdZd„ Zd	d„Zdedefd„Ze	defd„«       Z
y)
ÚRequestCounteraš  
    Helper class that will count all requests made online.

    Might not be robust if urllib3 changes its logging format but should be good enough for us.

    Usage:
    ```py
    with RequestCounter() as counter:
        _ = AutoTokenizer.from_pretrained("hf-internal-testing/tiny-random-bert")
    assert counter["GET"] == 0
    assert counter["HEAD"] == 1
    assert counter.total_calls == 1
    ```
    c                 ór  ‡ — t        t        «      ‰ _        t        j                  «       ‰ _        g ‰ _        ˆ fd„}t        j                  t        j                  j                  d |t        j                  j                  j                  «      ¬«      ‰ _        ‰ j                  j                  «       ‰ _        ‰ S )Nc                 ó   •‡ — ˆ ˆfd„}|S )Nc                  ón   •— ‰j                   j                  t        j                  «       «        ‰| i |¤ŽS rÿ  )Ú_extra_infor  Ú	threadingÚ	get_ident)rÈ   rÉ   Úfuncr‰  s     €€rž   ÚwrapzHRequestCounter.__enter__.<locals>.patched_with_thread_info.<locals>.wrapß	  s0   ø€ Ø× Ñ ×'Ñ'¬	×(;Ñ(;Ó(=Ô>Ù˜TÐ, VÑ,Ð,rÁ   r  )rð  rñ  r‰  s   ` €rž   Úpatched_with_thread_infoz:RequestCounter.__enter__.<locals>.patched_with_thread_infoÞ	  s   ù€ õ-ð ˆKrÁ   Údebug)Úside_effect)r   r¢   Ú_counterrî  rï  Ú
_thread_idrí  r   ÚobjectÚurllib3ÚconnectionpoolÚlogró  ÚpatcherÚstartr   )r‰  rò  s   ` rž   r’  zRequestCounter.__enter__Ù	  s…   ø€ Ü#¤CÓ(ˆŒÜ#×-Ñ-Ó/ˆŒØˆÔô	ô —|‘|Ü×"Ñ"×&Ñ&¨Ñ=UÔV]×VlÑVl×VpÑVp×VvÑVvÓ=wô
ˆŒð —L‘L×&Ñ&Ó(ˆŒ	ØˆrÁ   r)  Nc                 óÖ  — t        | j                  j                  «      t        | j                  «      k(  sJ ‚t	        | j                  | j                  j                  «      D ]k  \  }}|| j
                  k7  rŒ|j                  d   dk(  rŒ)|j                  d   |j                  dd  z  }dD ]  }||v sŒ| j                  |xx   dz  cc<    Œk Œm | j                  j                  «        y )Nr  i3  r   r   )	ÚHEADÚGETÚPOSTÚPUTÚDELETEÚCONNECTÚOPTIONSÚTRACEÚPATCH)
r  r   Úcall_args_listrí  Úziprö  rÈ   rõ  rû  Ústop)r‰  rÈ   rÉ   Ú	thread_idÚcallrú  Úmethods          rž   r—  zRequestCounter.__exit__ë	  sÑ   € Ü�4—9‘9×+Ñ+Ó,´°D×4DÑ4DÓ0EÒEÐEÐEÜ" 4×#3Ñ#3°T·Y±Y×5MÑ5MÓNò 
	‰OˆI�tØ˜DŸO™OÒ+Øà�y‰y˜‰} Ò#ØØ—)‘)˜A‘, §¡¨1¨2 Ñ.ˆCØjò �Ø˜S’=Ø—M‘M &Ó)¨QÑ.Ó)Ùñð
	ð 	�‰×ÑÕrÁ   rš   c                 ó    — | j                   |   S rÿ  )rõ  )r‰  rš   s     rž   Ú__getitem__zRequestCounter.__getitem__ú	  s   € Ø�}‰}˜SÑ!Ð!rÁ   c                 óH   — t        | j                  j                  «       «      S rÿ  )Úsumrõ  ro  r‘  s    rž   Útotal_callszRequestCounter.total_callsý	  s   € ä�4—=‘=×'Ñ'Ó)Ó*Ð*rÁ   ©r)  N)rW  rž  rŸ  r   r’  r—  rÓ  r¢   r  r,  r  r  rÁ   rž   ré  ré  É	  s?   „ ñòó$ð"˜sð " só "ð ð+˜Sò +ó ñ+rÁ   ré  Úmax_attemptsÚwait_before_retryÚdescriptionc                 ó   ‡ ‡— ˆ ˆfd„}|S )a¯  
    To decorate flaky tests. They will be retried on failures.

    Please note that our push tests use `pytest-rerunfailures`, which prompts the CI to rerun certain types of
    failed tests. More specifically, if the test exception contains any substring in `FLAKY_TEST_FAILURE_PATTERNS`
    (in `.circleci/create_circleci_config.py`), it will be rerun. If you find a recurrent pattern of failures,
    expand `FLAKY_TEST_FAILURE_PATTERNS` in our CI configuration instead of using `is_flaky`.

    Args:
        max_attempts (`int`, *optional*, defaults to 5):
            The maximum number of attempts to retry the flaky test.
        wait_before_retry (`float`, *optional*):
            If provided, will wait that number of seconds before retrying the test.
        description (`str`, *optional*):
            A string to describe the situation (what / where / why is flaky, link to GH issue/PR comments, errors,
            etc.)
    c                 óH   •‡ — t        j                  ‰ «      ˆˆ ˆfd„«       }|S )Nc            
      óä   •— d}|‰k  r		  ‰| i |¤ŽS  ‰| i |¤ŽS # t         $ rE}t        j                  d|› d|› d‰› d�«       ‰�t        j                  ‰«       |dz  }Y d }~nd }~ww xY w|‰k  rŒhŒ`)Nr   úTest failed with ú at try rÇ  r�  )rË  r³  ÚerrorÚtimeÚsleep©rÈ   rÉ   Úretry_countrˆ  r  Útest_func_refr  s       €€€rž   rÌ   z,is_flaky.<locals>.decorator.<locals>.wrapper
  s•   ø€ àˆKà Ò,ð%Ù(¨$Ð9°&Ñ9Ð9ñ ! $Ð1¨&Ñ1Ð1øô !ò %Ü—L‘LÐ#4°S°E¸À+ÀÈaÐP\È~Ð]^Ð!_Ô`Ø(Ð4ÜŸ
™
Ð#4Ô5Ø 1Ñ$•Kûð	%úð	  Ó,øs   Š š	A(£;A#Á#A(rÍ   ©r   rÌ   r  r  s   ` €€rž   r  zis_flaky.<locals>.decorator
  s%   ù€ Ü	�‰˜Ó	'õ	2ó 
(ð	2ð ˆrÁ   r  )r  r  r  r  s   ``  rž   Úis_flakyr"  
  s   ù€ õ&ð& ÐrÁ   c                 ó   ‡ ‡— ˆ ˆfd„}|S )a²  
    To decorate tests that download from the Hub. They can fail due to a
    variety of network issues such as timeouts, connection resets, etc.

    Args:
        max_attempts (`int`, *optional*, defaults to 5):
            The maximum number of attempts to retry the flaky test.
        wait_before_retry (`float`, *optional*, defaults to 2):
            If provided, will wait that number of seconds before retrying the test.
    c                 óH   •‡ — t        j                  ‰ «      ˆˆ ˆfd„«       }|S )Nc            
      óÖ  •— d}|‰k  r		  ‰| i |¤ŽS  ‰| i |¤ŽS # t         j                  j                  t         j                  j                  t         j                  j                  t         j                  j
                  t         j                  j                  f$ rE}t        j                  d|› d|› d‰› d�«       ‰�t        j                  ‰«       |dz  }Y d }~nd }~ww xY w|‰k  rŒáŒÙ)Nr   r  r  rÇ  z8 as it couldn't connect to the specified Hub repository.)ÚrequestsÚ
exceptionsÚConnectionErrorÚTimeoutÚReadTimeoutÚ	HTTPErrorÚRequestExceptionr³  r  r  r  r  s       €€€rž   rÌ   z-hub_retry.<locals>.decorator.<locals>.wrapper8
  sî   ø€ àˆKà Ò,ð%Ù(¨$Ð9°&Ñ9Ð9ñ  ! $Ð1¨&Ñ1Ð1øô ×'Ñ'×7Ñ7Ü×'Ñ'×/Ñ/Ü×'Ñ'×3Ñ3Ü×'Ñ'×1Ñ1Ü×'Ñ'×8Ñ8ðò %ô —L‘LØ+¨C¨5°¸¸ÀQÀ|Ànð  UMð  Nôð )Ð4ÜŸ
™
Ð#4Ô5Ø 1Ñ$•Kûð%úð	  Ó,øs   Š šBC!Â;CÃC!rÍ   r!  s   ` €€rž   r  zhub_retry.<locals>.decorator7
  s%   ù€ Ü	�‰˜Ó	'õ	2ó 
(ð	2ð. ˆrÁ   r  )r  r  r  s   `` rž   Ú	hub_retryr-  +
  s   ù€ õð6 ÐrÁ   c                 óL   — ddl } |j                  j                  d«      | «      S )a¡  
    Decorator marking a test with order(1). When pytest-order plugin is installed, tests marked with this decorator
    are garanteed to run first.

    This is especially useful in some test settings like on a Gaudi instance where a Gaudi device can only be used by a
    single process at a time. So we make sure all tests that run in a subprocess are launched first, to avoid device
    allocation conflicts.
    r   Nr   )r¯   r°   Úorderr³   s     rž   Ú	run_firstr0  U
  s#   € ó àˆ6�;‰;×Ñ˜QÓ 	Ó*Ð*rÁ   c                 óL  — |€)t        t        j                  j                  dd«      «      }d}t	        j
                  |«      }|j                  d«      }|j                  d«      }|j                  ||¬«       |j                  ||||f¬«      }|j                  «        	 |j                  |¬«      }	|j                  «        |j                  |¬«       	d   �| j                  |	d   › «       yy# t        $ r+}
|j                  «        | j                  |
«       Y d}
~
Œ]d}
~
ww xY w)	aÆ  
    To run a test in a subprocess. In particular, this can avoid (GPU) memory issue.

    Args:
        test_case (`unittest.TestCase`):
            The test that will run `target_func`.
        target_func (`Callable`):
            The function implementing the actual testing logic.
        inputs (`dict`, *optional*, defaults to `None`):
            The inputs that will be passed to `target_func` through an (input) queue.
        timeout (`int`, *optional*, defaults to `None`):
            The timeout (in seconds) that will be passed to the input and output queues. If not specified, the env.
            variable `PYTEST_TIMEOUT` will be checked. If still `None`, its value will be set to `600`.
    NÚPYTEST_TIMEOUTiX  Úspawnr   r   )ÚtargetrÈ   r  )r¢   r•   r–   r	  ÚmultiprocessingÚget_contextÚQueueÚJoinableQueueÚputÚProcessrü  Ú	task_donerË  Ú	terminateÚfailr#  )r´   Útarget_funcÚinputsr¡  Ústart_methohdÚctxÚinput_queueÚoutput_queueÚprocessÚresultsrÊ   s              rž   Úrun_test_in_subprocessrF  c
  s  € ð €Ü”b—j‘j—n‘nÐ%5°sÓ;Ó<ˆà€MÜ
×
%Ñ
% mÓ
4€Cà—)‘)˜A“,€KØ×$Ñ$ QÓ'€Lð ‡O�O�F G€OÔ,à�k‰k °KÀÈwÐ3WˆkÓX€GØ‡M�M„OðØ×"Ñ"¨7Ð"Ó3ˆØ×ÑÔ ð ‡L�L˜€LÔ!àˆwÑÐ#Ø�‰˜' 'Ñ*Ð+Õ-ð $øô ò Ø×ÑÔØ�‰�q×Ñûðús   Â"C/ Ã/	D#Ã8!DÄD#c                 óN   ‡ ‡— ddl Št        j                  ‰ «      ˆ ˆfd„«       }|S )zï
    To decorate a test to run in a subprocess using the `subprocess` module. This could avoid potential GPU memory
    issues (GPU OOM or a test that causes many subsequential failing with `CUDA error: device-side assert triggered`).
    r   Nc                  ó  •— t        j                  dd «      dk(  r	 ‰| i |¤Ž y dj                  t         j                  j	                  d«      j                  d«      d d «      }	 dd l} |j                  t         j                  «      }d|d<   d|d<   d	|v r­t        |d	   j                  j                  «      }t        |«      D ]Q  \  }}||d	   j                  v sŒ|j                  d
«      dd  }d
j                  ‰j                  d   › g|z   «      ||<   ŒS t        j                  › ddg|z   }|D �cg c]	  }|dvsŒ|‘Œ }}nt        j                  › dd|› g}t        j                   ||dd¬«       y c c}w # t        j"                  $ rô}|j$                  j'                  «       }	|	j                  d«      }
d|
d   v r™d}|
dd  D ]„  }|j)                  d«      r2|t+        d«      d  }dj                  |j                  d«      dd  «      }ŒF|j)                  d«      r|j-                  d«      rd|v r nt+        |«      dkD  sŒ}|d|› �z  }Œ† d|z   }|g|
z   }
dj                  |
«      }	‰j/                  |	d¬«      ‚d }~ww xY w)NÚ_INSIDE_SUB_PROCESSÚ1rV  ÚPYTEST_CURRENT_TESTr7  r   ÚtrueÚCIÚpytestconfigz::r   Ú__file__z-mr¯   )z--no-summaryT)r
  ÚcheckÚcapture_outputr™  z= test session starts =r:  zFAILED z - rY  z failed in z(subprocess) F)Úpytrace)r•   r%  r#  r–   r	  r  rY  rZ  r(  Úinvocation_paramsrÈ   rr  Ú__globals__rŒ  Ú
executabler¤  Úrunrä  r�  r“  rÓ   r  r"  r=  )rÈ   rÉ   ÚtestrY  r
  rà  ÚidxrR  rÊ   Úexception_messager×  Útextrc  rð  r¯   s                €€rž   rÌ   z*run_test_using_subprocess.<locals>.wrapper•
  s�  ø€ ä�9‰9Ð*¨DÓ1°SÒ8Ù�$Ð!˜&Ó!à—8‘8œBŸJ™JŸN™NÐ+@ÓA×GÑGÈÓLÈSÈbÐQÓRˆDð*DÛà#�d—m‘m¤B§J¡JÓ/�Ø-0�Ð)Ñ*ð #��D‘	ð " VÑ+Ü" 6¨.Ñ#9×#KÑ#K×#PÑ#PÓQ�GÜ"+¨GÓ"4ò a™˜˜QØ  ~Ñ 6× ;Ñ ;Ò;Ø#'§:¡:¨dÓ#3°A°BÐ#7˜DØ+/¯9©9¸×9IÑ9IÈ*Ñ9UÐ8VÐ5XÐ[_Ñ5_Ó+`˜G CšLðaô #&§.¡.Ð!1°D¸(ÐCÀgÑM�GØ*1ÖO Q°QÐ>NÒ5NšqÐO�GÑOô #&§.¡.Ð!1°D¸(ÀtÀfÐN�Gä—‘˜w¨C°tÈDÖQùò Pøô ×0Ñ0ò DØ$%§H¡H§O¡OÓ$5Ð!Ø)×/Ñ/°Ó5�ð -°°a±Ñ8Ø�DØ % a b 	ò 0˜ØŸ?™?¨9Ô5Ø#'¬¨I«Ð(8Ð#9˜DØ#%§7¡7¨4¯:©:°eÓ+<¸Q¸RÐ+@Ó#A™DØ!Ÿ_™_¨SÔ1°d·m±mÀCÔ6HÈ]Ð^bÑMbÙ!Ü  ›Y¨›]Ø  b¨¨ KÑ/™Dð0ð +¨TÑ1�DØ!˜F U™N�EØ$(§I¡I¨eÓ$4Ð!Ø—k‘kÐ"3¸U�kÓCÐCûð%Dús?   Á%A6E9 ÃAE9 Ä3	E4Ä=E4Å2E9 Å4E9 Å9J ÆB5I;É9I;É;J )r¯   rÎ   r   )rð  rÌ   r¯   s   ` @rž   Úrun_test_using_subprocessr[  Ž
  s-   ù€ ó
 ä‡_�_�TÓô/Dó ð/Dðb €NrÁ   c                 ó:  — d}t        j                  || t         j                  ¬«      }d}t        |«      D ]M  \  }}d|v rd|vrt        j                  dd|«      ||<   d|v sd	|v sŒ1t        j
                  d
|«      sŒH|sŒKd} n d}|sdj                  |«      }|S )a®  Prepare a docstring or a `.md` file to be run by doctest.

    The argument `string` would be the whole file content if it is a `.md` file. For a python file, it would be one of
    its docstring. In each case, it may contain multiple python code examples. If `skip_cuda_tests` is `True` and a
    cuda stuff is detective (with a heuristic), this method will return an empty string so no doctest will be run for
    `string`.
    z&(```(?:python|py)\s*\n\s*>>> )(.*?```))ÚflagsFzload_dataset(z# doctest: +IGNORE_RESULTz(>>> .*load_dataset\(.*)z\1 # doctest: +IGNORE_RESULTz>>>z...zcuda|to\(0\)|device=0Tr:  )r;  r  ÚDOTALLrr  r<  Úsearchr#  )ÚstringÚskip_cuda_testsÚcodeblock_patternÚ
codeblocksÚis_cuda_foundrƒ  Ú	codeblockÚmodified_strings           rž   Úpreprocess_stringrg  Ô
  s¯   € ð BÐÜ—‘Ð+¨V¼2¿9¹9ÔE€JØ€MÜ! *Ó-ò 	‰ˆˆ9Ø˜iÑ'Ð,GÈyÑ,XÜŸF™FÐ#>Ð@_ÐajÓkˆJ�q‰Mà�iÑ 5¨IÒ#5Ü—	‘	Ð2°IÕ>Úà ˆMÙð	ð €OÙØŸ'™' *Ó-ˆàÐrÁ   c                   óÈ   ‡ — e Zd ZU dZ ej
                  dej                  ej                  z  «      Z e	e
j                  j                  dd«      «      Ze	ed<   dˆ fd„	Zˆ xZS )ÚHfDocTestParsera¾  
    Overwrites the DocTestParser from doctest to properly parse the codeblocks that are formatted with black. This
    means that there are no extra lines at the end of our snippets. The `# doctest: +IGNORE_RESULT` marker is also
    added anywhere a `load_dataset` call is made as a print would otherwise fail the corresponding line.

    Tests involving cuda are skipped base on a naive pattern that should be updated if it is not enough.
    aó  
        # Source consists of a PS1 line followed by zero or more PS2 lines.
        (?P<source>
            (?:^(?P<indent> [ ]*) >>>    .*)    # PS1 line
            (?:\n           [ ]*  \.\.\. .*)*)  # PS2 lines
        \n?
        # Want consists of any non-blank lines that do not start with PS1.
        (?P<want> (?:(?![ ]*$)    # Not a blank line
             (?![ ]*>>>)          # Not a line starting with PS1
             # !!!!!!!!!!! HF Specific !!!!!!!!!!!
             (?:(?!```).)*        # Match any character except '`' until a '```' is found (this is specific to HF because black removes the last line)
             # !!!!!!!!!!! HF Specific !!!!!!!!!!!
             (?:\n|$)  # Match a new line or end of string
          )*)
        ÚSKIP_CUDA_DOCTESTFra  c                 óP   •— t        || j                  «      }t        ‰| �  ||«      S )zŸ
        Overwrites the `parse` method to incorporate a skip for CUDA tests, and remove logs and dataset prints before
        calling `super().parse`
        )rg  ra  r¥  r�  )r‰  r`  rÊ  rV  s      €rž   r�  zHfDocTestParser.parse  s(   ø€ ô
 # 6¨4×+?Ñ+?Ó@ˆÜ‰w‰}˜V TÓ*Ð*rÁ   )z<string>)rW  rž  rŸ  r   r;  ÚcompileÚ	MULTILINEÚVERBOSEÚ_EXAMPLE_REÚboolr•   r–   r	  ra  Ú__annotations__r�  rª  r«  s   @rž   ri  ri  ñ
  s\   ø… ñð �"—*‘*ð ð �\‰\˜BŸJ™JÑ&ó€Kñ& ! §¡§¡Ð0CÀUÓ!KÓL€O�TÓL÷+ñ +rÁ   ri  c                   ó"   — e Zd ZdZdee   fd„Zy)ÚHfDoctestModulezƒ
    Overwrites the `DoctestModule` of the pytest package to make sure the HFDocTestParser is used when discovering
    tests.
    r)  c              #   óv  K  —  G d„ dt         j                  «      }| j                  j                  dk(  r`| j                  j
                  j                  | j                  | j                  j                  d«      | j                  j                  ¬«      }nF	 t        | j                  | j                  j                  | j                  j                  d«      ¬«      } |t        «       ¬	«      }t        | «      }t        d
|t!        «       t#        | j                  «      ¬«      }|j%                  |j&                  «      D ]4  }|j(                  sŒt+        j,                  | |j                  ||¬«      –— Œ6 y # t        $ r8 | j                  j                  d«      rt        d| j                  z  «       n‚ Y ŒÚw xY w­w)Nc                   ó.   ‡ — e Zd ZdZˆ fd„Zdˆ fd„Zˆ xZS )ú7HfDoctestModule.collect.<locals>.MockAwareDocTestFinderz»A hackish doctest finder that overrides stdlib internals to fix a stdlib bug.

            https://github.com/pytest-dev/pytest/issues/3456 https://bugs.python.org/issue25532
            c                 ó    •— t        |t        «      rt        |d|«      }t        |d«      rt	        j
                  |«      }t        ‰| �  ||«      S )a3  Doctest code does not take into account `@property`, this
                is a hackish way to fix it. https://bugs.python.org/issue17446

                Wrapped Doctests will need to be unwrapped so the correct line number is returned. This will be
                reported upstream. #8796
                ÚfgetÚ__wrapped__)r[  r,  rÔ   rX  r  Úunwrapr¥  Ú_find_lineno)r‰  rÌ  Úsource_linesrV  s      €rž   r{  zDHfDoctestModule.collect.<locals>.MockAwareDocTestFinder._find_lineno,  sO   ø€ ô ˜c¤8Ô,Ü! # v¨sÓ3�Cä˜3 Ô.ä!Ÿ.™.¨Ó-�Cô ‘wÑ+ØØ óð rÁ   c           
      ó†   •— t        |«      ry t        «       5  t        ‰| �  |||||||«       d d d «       y # 1 sw Y   y xY wrÿ  )r‹   rŒ   r¥  Ú_find)	r‰  r  rÌ  rÊ  r€  r|  ÚglobsÚseenrV  s	           €rž   r~  z=HfDoctestModule.collect.<locals>.MockAwareDocTestFinder._find@  sC   ø€ Ü˜c”?ØÜ-Ó/ñ ä‘G‘MØ˜s D¨&°,ÀÀtô÷÷ ñ ús	   ˜7·A r  )rW  rž  rŸ  r   r{  r~  rª  r«  s   @rž   ÚMockAwareDocTestFinderrv  &  s   ø„ ñô
÷(ñ rÁ   r�  zconftest.pyÚ
importmode)Úrootpath)ÚrootÚmodeÚdoctest_ignore_import_errorszunable to import module %r)rA  F)ÚverboseÚoptionflagsÚcheckerÚcontinue_on_failure)rÊ  ÚrunnerÚdtest)ÚdoctestÚDocTestFinderr  rÊ  r  ÚpluginmanagerÚ_importconftestÚ	getoptionrƒ  r�   r²   r”  rŽ   ri  r�   rŠ   rˆ   r‰   rB  rW  rÞ  r�   Úfrom_parent)r‰  r�  r€  Úfinderrˆ  r‹  rW  s          rž   ÚcollectzHfDoctestModule.collect%  sb  è ø€ ô!	¤W×%:Ñ%:ô !	ðF �9‰9�>‰>˜]Ò*Ø—[‘[×.Ñ.×>Ñ>Ø—	‘	Ø—‘×%Ñ% lÓ3ØŸ™×-Ñ-ð ?ó ‰Fð
Ü$Ø—I‘IØŸ™×-Ñ-ØŸ™×.Ñ.¨|Ó<ô�ñ (¬Ó/@ÔAˆä% dÓ+ˆÜØØ#Ü “NÜ 8¸¿¹Ó Eô	
ˆð —K‘K ¨¯©Ó8ò 	_ˆDØ�}‹}Ü!×-Ñ-¨d¸¿¹È6ÐY]Ô^Ó^ñ	_øô! ò Ø—;‘;×'Ñ'Ð(FÔGÜÐ5¸¿	¹	ÑAÕBàñ Cðüs2   ‚BF9ÂAE5 ÃA1F9Å(F9Å5>F6Æ3F9Æ5F6Æ6F9N)rW  rž  rŸ  r   r   r�   r”  r  rÁ   rž   rs  rs    s   „ ñð
C_˜ +Ñ.ô C_rÁ   rs  ÚdeviceÚdispatch_tablec                 ó@   — | |vr |d   |i |¤ŽS ||    }|€y  ||i |¤ŽS )Nr›   r  )r•  r–  rÈ   rÉ   r"  s        rž   Ú_device_agnostic_dispatchr˜  k  sE   € Ø�^Ñ#Ø(ˆ~˜iÑ(¨$Ð9°&Ñ9Ð9à	˜Ñ	€Bð 
€zØÙˆtÐ�vÑÐrÁ   )rW  r‡  r›   c                   ó   — y©Nr   r  r  rÁ   rž   rS  rS  ‡  ó   � rÁ   c                   ó   — y)Nr   r  r  rÁ   rž   rS  rS  ˆ  r›  rÁ   r›   c                   ó   — yrš  r  r  rÁ   rž   rS  rS  �  r›  rÁ   ÚxlaÚseedc                 ó$   — t        | t        |«      S rÿ  )r˜  ÚBACKEND_MANUAL_SEED)r•  rŸ  s     rž   Úbackend_manual_seedr¢  ¨  s   € Ü$ VÔ-@À$ÓGÐGrÁ   c                 ó"   — t        | t        «      S rÿ  )r˜  ÚBACKEND_EMPTY_CACHE©r•  s    rž   Úbackend_empty_cacher¦  ¬  s   € Ü$ VÔ-@ÓAÐArÁ   c                 ó"   — t        | t        «      S rÿ  )r˜  ÚBACKEND_DEVICE_COUNTr¥  s    rž   r]  r]  °  s   € Ü$ VÔ-AÓBÐBrÁ   ÚTRANSFORMERS_TEST_DEVICE_SPECzISpecified path to device spec file is not a file or not found. Received 'z.pyz;Provided device spec file was not a Python file! Received 'z.Device spec file did not contain `DEVICE_NAME`zBMismatch between environment variable `TRANSFORMERS_TEST_DEVICE` 'z' and device found in spec 'z'
zNEither unset `TRANSFORMERS_TEST_DEVICE` or ensure it matches device spec name.Údevice_fn_dictÚattribute_namec                 óš   — 	 t        t        |«      }|| t        <   y # t        $ r%}d| vrt        d|› dt        › d�«      |‚Y d }~y d }~ww xY w)Nr›   r  z` not found in 'z)' and no default fallback function found.)rÔ   Údevice_spec_moduler^  ÚAttributeErrorÚdevice_spec_path)rª  r«  Úspec_fnrÊ   s       rž   Úupdate_mapping_from_specr±  Ö  sb   € ð	ä!Ô"4°nÓE�Ø/6�œ|Ò,øÜ!ò à NÑ2Ü(Ø˜NÐ+Ð+;Ô<LÐ;MÐMvÐwóàðô 3ûðús   ‚ œ	A
¥AÁA
ÚMANUAL_SEED_FNÚEMPTY_CACHE_FNÚDEVICE_COUNT_FNc                 óV  — g }g }t        |«      D �ch c]  }|j                  ’Œ }}t        | j                  «       D �cg c]	  }||v sŒ|‘Œ c}«      }t        |«      D ]?  }|j                  t
        u sŒ|j                  | vsŒ%|j                  |j                  «       ŒA | D ]  }||vsŒ|j                  |«       Œ |s|r_dg}	|r|	j                  d|› �«       |r|	j                  d|› �«       |r|	j                  d|› �«       t        dj                  |	«      «      ‚y c c}w c c}w )Nz(Pipeline output does not match Hub spec!zMatching keys: z*Missing required keys in pipeline output: z2Keys in pipeline output that are not in Hub spec: r™  )	r
   rÊ  Úsortedr)  r›   r	   r  r˜   r#  )
rå  Úhub_specÚmissing_keysÚunexpected_keysÚfieldÚall_field_namesrš   Úmatching_keysÚ
output_keyr  s
             rž   Ú#compare_pipeline_output_to_hub_specr¾  è  s&  € Ø€LØ€OÜ/5°hÓ/?Ö@ e�u—z“zÐ@€OÐ@Ü¨6¯;©;«=ÖS C¸CÀ?Ò<RšCÒSÓT€Mô ˜Ó!ò ,ˆØ�=‰=œGÒ#¨¯
©
¸&Ò(@Ø×Ñ §
¡
Õ+ð,ð
 ò /ˆ
Ø˜_Ò,Ø×"Ñ" :Õ.ð/ñ ‘Ø;Ð<ˆÙØ�L‰L˜?¨=¨/Ð:Ô;ÙØ�L‰LÐEÀlÀ^ÐTÔUÙØ�L‰LÐMÈoÐM^Ð_Ô`Ü�t—y‘y Ó'Ó(Ð(ð 'ùò AùÚSs   ’D!¾	D&ÁD&c                 ó‚   — |rt        j                  «        t        | «       t        j                  j                  «        y rÿ  )Úgcr”  r¦  rV  Ú_dynamoÚreset)r•  Ú
gc_collects     rž   ÚcleanuprÄ    s&   € áÜ
�
‰
ŒÜ˜ÔÜ	‡M�M×ÑÕrÁ   c                  óˆ   — t         st        r/ddl} | j                  j	                  «       \  }}t        rd|fS d|fS t
        dfS )z,
    Get environment device properties.
    r   NÚrocmrW  )ÚIS_CUDA_SYSTEMÚIS_ROCM_SYSTEMrV  rW  Úget_device_capabilityr^  )rV  ÚmajorrZ  s      rž   r�  r�    sD   € õ
 �Ûà—:‘:×3Ñ3Ó5‰ˆˆqÝØ˜E�?Ð"à˜E�?Ð"ä˜dÐ#Ð#rÁ   c                   óh   — e Zd Zdefd„Zededefd„«       Zededede	fd„«       Z
d
dedefd„Zd„ Zy	)ÚExpectationsr)  c                 ó4   — | j                  t        «       «      S )zX
        Find best matching expectation based on environment device properties.
        )Úfind_expectationr�  r‘  s    rž   Úget_expectationzExpectations.get_expectation!  s   € ð ×$Ñ$Ô%:Ó%<Ó=Ð=rÁ   rš   c                 ó&   — t        d„ | D «       «      S )Nc              3   ó$   K  — | ]  }|d u –— Œ
 y ­wrÿ  r  )r1  r©  s     rž   r2  z*Expectations.is_default.<locals>.<genexpr>)  s   è ø€ Ò* �1˜”9Ñ*ùs   ‚)Úall©rš   s    rž   Ú
is_defaultzExpectations.is_default'  s   € äÑ* cÔ*Ó*Ð*rÁ   Úotherc                 ó¬   — | \  }}|\  }}d}||k(  r|dz  }n|dv r	|dv r|dz  }||k(  r|�|dz  }t         j                  |«      r|dz  }t        |«      S )aÐ  
        Returns score indicating how similar two instances of the `Properties` tuple are.
        Points are calculated using bits, but documented as int.
        Rules are as follows:
            * Matching `type` gives 8 points.
            * Semi-matching `type`, for example cuda and rocm, gives 4 points.
            * Matching `major` (compute capability major version) gives 2 points.
            * Default expectation (if present) gives 1 points.
        r   é   )rW  rÆ  é   ra  r   )rÌ  rÔ  r¢   )rš   rÕ  Údevice_typerÊ  Úother_device_typeÚother_majorÚscores          rž   rÜ  zExpectations.score+  s‚   € ð  #Ñˆ�eØ+0Ñ(Ð	˜KàˆØÐ+Ò+Ø�V‰O‰EØÐ,Ñ,Ð1BÐFVÑ1VØ�U‰NˆEà�KÒ KÐ$;Ø�T‰MˆEä×"Ñ" 5Ô)Ø�S‰LˆEä�5‹zÐrÁ   c                 ó¬   ‡— t        | j                  j                  «       ˆfd„¬«      \  }}t        j	                  ‰|«      dk(  rt        d‰› �«      ‚|S )zU
        Find best matching expectation based on provided device properties.
        c                 ó6   •— t         j                  ‰| d   «      S rš  )rÌ  rÜ  )rR  rš   s    €rž   rS  z/Expectations.find_expectation.<locals>.<lambda>K  s   ø€ ÄL×DVÑDVÐWZÐ\]Ð^_Ñ\`ÓDa€ rÁ   rÓ  r   z"No matching expectation found for )ÚmaxÚdatarÁ  rÌ  rÜ  r—   )r‰  rš   Ú
result_keyr°  s    `  rž   rÎ  zExpectations.find_expectationG  sO   ø€ ô  # 4§9¡9§?¡?Ó#4Ó:aÔbÑˆ�Vä×Ñ˜c :Ó.°!Ò3ÜÐAÀ#ÀÐGÓHÐHàˆrÁ   c                 ó   — | j                   › S rÿ  )rà  r‘  s    rž   rœ  zExpectations.__repr__R  s   € Ø—)‘)�ÐrÁ   N)rÔ  )rW  rž  rŸ  r   rÏ  ÚstaticmethodÚDevicePropertiesrp  rÔ  r¢   rÜ  rÎ  rœ  r  rÁ   rž   rÌ  rÌ     su   „ ð> ó >ð ð+Ð(ð +¨Tò +ó ð+ð ðÐ#ð Ð,<ð Àò ó ðñ6	Ð$4ð 	Èó 	órÁ   rÌ  )Frÿ  )z1.12.0)é   )NNNFF)NNé´   FT)rf  )é   NN)rç  ra  rÔ  (±  rÛ  Ú
contextlibrY  r�  rÎ   rÀ  r‘  r  r   r5  r•   r;  r  r   r¤  rŒ  rÈ  rî  r  r®   r   r   Úcollections.abcr   r   r   r   Údataclassesr	   r
   r   r   r´  r   Úpathlibr   Útypingr   r   r   r   r   Úunittest.mockr   Úhuggingface_hub.utilsrË  r&  rø  r   Ú	packagingr   Útransformersr   r½  Úintegrationsr   r   r   r   r   r    r!   Úintegrations.deepspeedr"   Úutilsr#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   rS   rT   rU   rV   rW   rX   rY   rZ   r[   r\   r]   r^   r_   r`   ra   rb   rc   rd   re   rf   rg   rh   ri   rj   rk   rl   rm   rn   ro   rp   rq   rr   rs   rt   ru   rv   rw   rx   ry   rz   r{   r|   r}   r~   r   r€   r�   r‚   rƒ   Úaccelerate.stater„   r…   Úaccelerate.utils.importsr†   Ú_pytest.doctestr‡   rˆ   r‰   rŠ   r‹   rŒ   r�   Ú_pytest.outcomesrŽ   Ú_pytest.pathlibr�   r¯   r�   r÷  ÚSMALL_MODEL_IDENTIFIERÚDUMMY_UNKNOWN_IDENTIFIERÚDUMMY_DIFF_TOKENIZER_IDENTIFIERÚUSERÚENDPOINT_STAGINGÚTOKENrV  ÚhiprÈ  rW  rÇ  Ú
get_loggerrW  r³  rŸ   r£   r¾   rÜ   r­   r·   rº   Ú_run_third_party_device_testsr±   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.  r0  r2  r5  r7  r:  r<  r>  r@  rB  rD  rF  rH  rJ  rL  rN  rP  rS  rZ  r_  rb  rd  rg  ri  rk  rn  rq  rt  ry  r|  r  r�  rƒ  r–   ÚbackendÚimport_modulerZ  ÚModuleNotFoundErrorrÊ   r^  Úis_availabler—   r•  r®  r  r  r  Údefault_backendÚ
jax_devicer‰  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¢   r4  r(  r\  r8  r?  rG  r_  rn  r�  rƒ  r¢  r®  r±  ÚcontextmanagerrÂ  rÄ  ÚPathLikerÙ  ÚTestCaserÛ  r.  r:  r?  rC  r„  r¢  r†  r�  rª  r  r¶  rº  r½  rÙ  rÝ  rË  rß  rç  ré  r"  r-  r0  rF  r[  rg  ÚDocTestParserri  rs  r˜  Úmanual_seedr¡  Úempty_cacher¤  rX  r¨  rw  r†  rs  r~  r¢  r¦  r]  r¯  Úis_filer  r  ÚrealpathÚdevice_spec_dirr  ÚindexÚimport_namer­  ÚDEVICE_NAMEÚdevice_namer®  r›  r±  r¾  rÄ  r¾  rä  r�  rÌ  r  rÁ   rž   ú<module>r     s  ðó Û Û Û Û Û 	Û Û Û Û Û 	Û 	Û Û Û Û 
Û Û Û Û ß -ß BÓ Bß 'ß "Ý Ý ß 1Ó 1Ý Ý ã Û Û Ý 'Ý å  Ý 8÷÷ ñ õ ;÷b÷ b÷ b÷ b÷ b÷ b÷ b÷ b÷ b÷ b÷ b÷ b÷ b÷ b÷ b÷ b÷ b÷ b÷ b÷ b÷ b÷ b÷ b÷ bõ bñJ Ôß?Ý9ñ Ô÷÷ ñ õ &Ý+Þ"à€FØ€Kð 6Ð Ø3Ð Ø"AÐ ð %€Ø2Ð ð 	0€áÔÛà—]‘]×&Ò&¨dÐ2€NØ—]‘]×'Ò'¨tÐ3�Nà€NØ€Nà	(Ð	×	(Ò	(¨Ó	2€ôô 
ñ & j¸%Ô@€Ù,Ð-DÈeÔTÐ Ù"Ð#;ÀUÔK€Ù)Ð*>ÈÔMÐ Ù&Ð'8À%ÔHÐ Ù 3Ð4RÐ\aÔ bÐ ò<ò"=ò :òKò?òò	ò_ò^ò_ò_òUò_òeòVòcòUð 6Lñ ¨só ð 0@ñ ¨ó ò¨ó òYòcòYòWòWò[òUòUòYòYð¨Có òhòcòò"Uòcò	òò	òaòYò[ògòaòWòWòaòkò_òYòcóóYóUóWómóó	eóvó	kó	ó^óóaó
gó\ó`ó\ó
gó
gñ Õãà" b§j¢jÑ0Ø—*’*Ð8Ñ9‰ð	Ø'�	×'Ò'©Ó0‰Að " R§Z¢ZÑ/Ø—z’zÐ"<Ñ=‰Ù˜6Ò!¨%¯*ª*×*AÒ*AÔ*CÚØ+©L¨>ð  :Bð  Cóð ñ ˜5Ò Ñ)?Ô)AÚØ+©L¨>ð  :Að  Bóð ñ ˜5Ò Ñ)?Ô)AÚØ+©L¨>ð  :Að  Bóð ñ ˜5Ò Ñ)?Ô)AÚØ+©L¨>ð  :Að  Bóð ñ ˜5Ò Ñ)?Ô)AÚØ+©L¨>ð  :Að  Bóð ð	à�—’™\Ó*ŠAð
 
�Š×	 Ò	 Ô	"ØŠÙ	&Ñ+AÔ+CØŠÙ	&Ñ+AÔ+CØŠÙ	&Ñ+AÔ+CØŠÙ	&Ñ+AÔ+CØŠàŠà�LáÔÝáÔÝà$‘×$Ò$Ó&‚Jà�Jócó
[ó
	óoó
Xò
©uô ó(óóóóóóóóócó
Yó
YóXóYó[óWó[ó_ó_óUóUóUóUóPó"QóWó[óXóóSó\óióqóaóWóóaócó[óeó]ócó)ófó[óó[óYó]óõ(ð. ð ©Sô ð
%Ù™T #¡u *Ñ-Ñ.ð
%à‰t�C™�JÑ  tÐ+Ñ,ô
%ó8.óMó+\ó\Aó*3÷*bò bôV3‘Jõ 3ô3‘Jõ 3÷()ò ()ðV ×Òñ7ó ñ7÷(Vò Vð@ ×Òð˜˜c 2§;¢;Ð.Ñ/ð °H¸T±Nò ó ñô(X&�8×$Ò$õ X&óv/ð ×Òñ+ó ñ+ðB Ñ ó*ó&B)õP ÷ò óò&0Ñblô &0òRÑ`jô ó,ó	õ7ó>,ó"ô	™iõ 	ò™˜c™ô ÷"6+ò 6+òr&™3ð &°xÁ±ð &Ð\dÐehÑ\iô &òR'™Cð '¸Á¹ô 'óT+õ(.óV9ðxóô:++�g×+Ò+õ ++ô\I_�fõ I_ðX
 cð 
¹4ÀÀXÀÑ;Nô 
ñ Ôð —
’
×&Ò&Ø× Ò Ø×$Ò$ñÑð —
’
×&Ò&ØØñÑð —
’
×'Ò'ÙÙñÒð % dÐ+ÑØ$ dÐ+ÑØ%¡yÐ1ÑáÔØ!&§¢×!6Ò!6Ñ˜ÑØ"'§)¢)×"8Ò"8Ñ˜ÑáÔØ!&§¢×!6Ò!6Ñ˜ÑØ!&§¢×!6Ò!6Ñ˜ÑØ"'§)¢)×"8Ò"8Ñ˜ÑáÔØ!&§¢×!6Ò!6Ñ˜ÑØ!&§¢×!6Ò!6Ñ˜ÑØ"'§)¢)×"8Ò"8Ñ˜ÑáÔØ!&§¢×!6Ò!6Ñ˜ÑØ!&§¢×!6Ò!6Ñ˜ÑØ"'§)¢)×"8Ò"8Ñ˜ÑáÔØ!&§¢×!7Ò!7Ñ˜ÑØ!&§¢×!7Ò!7Ñ˜ÑØ"'§*¢*×"9Ò"9Ñ˜ÑðH ñ H©3õ HðB õ BðC õ Cñ Õñ '¨"¯*ª*Ò4ØŸ:š:Ñ&EÑFÑÙÑ$Ó%×-Ò-Ô/ÚÙ[Ñ\lÐ[mÐnóð ð  ŸWšWŸ]š]¨2¯7ª7×+;Ò+;Ñ<LÓ+MÓNÑ‰™Ø�Š�Š™Ô(ð	vÙ*Ð+JÑ-=×-CÒ-CÁEÓ-JÐK‰Kð 5˜Y×4Ò4±[ÓAÑð	ZÙ,×8Ò8‰Kð &¨¯ªÑ3¹ÉÒ8SÙVÑWcÐVdñ  eAñ  BMð  ANñ  NQð  R‰CÙÑcÑc‰CÚ™S“/Ð!á"‰ñ
	±T¸#¸x¸-Ñ5Hñ 
	ÐZ]õ 
	ò 	!Ñ!4Ñ6FÔGÚ Ñ!4Ñ6FÔGÚ Ñ!5Ñ7HÔIô)ð6 ò�Có ó ññ ˜˜s D˜yÑ)¨5±°d°Ñ+;Ð;Ñ<Ñ ð ð$Ñ/ó $ó ñ$ö 3�8Ñ,¨cÐ1Ñ2ö 3øñID #ó 	Ú%Ø@ÁÀ	ð J!Ù!" ð%óñ ðýð	ûñ@ ó 	ÚØgÑhtÐguÐvóáðýð	ûñP@ ó 	vÚÑZÑ[kÐZlÐmÓnÑtuÐuýð	vûñ ó 	ZÚ Ñ!QÓRÑXYÐYýð	Zús`   Î+o Ñ=o( ë
p ë9p) ïo%ïoïo%ï(pï/o>ï>pðp&ðpðp&ð)qð0p<ð<q