L iN NddlZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZddlZddlZddlZddlZddlZddlZddlZddlZddlmZmZddlmZmZmZmZddlmZm Z ddlm!Z!m"Z"ddl#m$Z$ddl%m&Z&ddl'm(Z(m)Z)m*Z*m+Z+dd lm,Z,dd l-m.Z.ddl/Z0ddl1Z1ddl2Z2dd l0m3Z3dd l4m5Z5dd l6m7Z7ddl6m Z8ddl9m:Z:m;Z;mZ>m?Z?m@Z@mAZAddlBmCZCddlDmEZEmFZFmGZGmHZHmIZImJZJmKZKmLZLmMZMmNZNmOZOmPZPmQZQmRZRmSZSmTZTmUZUmVZVmWZWmXZXmYZYmZZZm[Z[m\Z\m]Z]m^Z^m_Z_m`Z`maZambZbmcZcmdZdmeZemfZfmgZgmhZhmiZimjZjmkZkmlZlmmZmmnZnmoZompZpmqZqmrZrmsZsmtZtmuZumvZvmwZwmxZxmyZymzZzm{Z{m|Z|m}Z}m~Z~mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZeHrddlmZmZddlmZer%ddlmZmZmZmZmZmZmZddlmZddlmZddlmZneZeZdZdZdZdZdZdZdd d!d"d#d$ZerMddlZejjjduZejjjduZeejjd%dduZnd&Zd&Zd&Ze8jeЫZѐd=d'ZҐd>d(Zed)d&*Zed+d,*Zed-d&*Zed.d&*Zed/d,*Zed0d&*Zd1Zd2Zd3Zd4Zd5Zd6Zd7Zd8Zd9Zd:Zd;Zd<Zd=Zd>Zd?Zd@ZdAZdBZeEfdCefdDZeGfdCefdEZeFfdCefdFZd?dCefdGZdHZdIZdJZdKZdLZdMZdNZdOZdPefdQZdPefdRZdSZdTZdUZdVZdWZdXZdYZdZZd[Zd\Zd]Zd^Zd_Zd`ZdaZ dbZ dcZ ddZ deZ dfZdgZdhZdiZdjZdkZdlZdmZdnZdoZdpZdqZdrZdsZdtZduZdvZdwZer]ddlZdxe j@vr'e j@dxZ! ejDe!Z#d{e j@vre j@d{Z&e&d|k(r*eȐjjOse(d}e&d~e&d%k(rese(d}e&de&dk(rese(d}e&de&dk(rese(d}e&de&dk(rese(d}e&d eȐjRe&Z#nSeȐjjOrd|Z&n3erdZ&n(erdZ&nerdZ&nerd%Z&ndZ&ndZ&erddl+Z,e^rddl-Z-e-j\Z/ndZ/dZ0dZ1dZ2dZ3dZ4dZ5d@de6fdZ7dAde6fdZ8dAde6fdZ9dZ:dZ;dZdZ?dZ@dZAdZBdZCdZDdZEdZFdZGdZHdZIdZJdZKdZLdZMdZNdZOdZPdZQdZRdZSdZTdZUdZVdZWdZXdZYdZZdZ[dZ\dZ]dZ^dZ_dZ`dZadZbdZcdZddZedZfdZgdZhdZid„ZjdÄZkdĄZldńZmdƄZndDŽZodȄZpdɄZqd>dʄZrde7d̐esfd̈́Ztdΐeuevee6fdeevee6fddffdτZwdЄZxdфZyd҄ZzdӄZ{GdԄdիZ|Gdքdאe|Z}Gd؄dِe|Z~Gdڄd۫Zejd܄ZGd݄dޫZejde+ee jfdedfdZGddej ZdZejdZiZdZdZddlZGddZdZdBd̐efdZdCd̐efdZdZdZdDdZdZdZGddeZd=deuefdZGddZdEdesde*e6de*efdZdFdesde*e6fdZdZdGdZdZ dZGddej@ZGddeZdedevee)ffdZereȐjjHeȐjHeȐjHdZeȐjjLdddZeȐjjPdd dZeȐjjTdddZeȐjjXdddZeȐjj\dddZeȐjj`dddZeȐjjddddZeȐjdddZn8d diZd diZd d iZd diZd diZd diZd diZd diZd diZerIeȐjjjHed<eȐjjjPed<eȐjjed<ereeȐjljLed<eȐjljHed<eȐjljPed<eȐjled<ereeȐjnjLed<eȐjnjHed<eȐjnjPed<eȐjned<ereȐjpjLed%<eȐjpjHed%<eȐjpjPed%<eȐjpj\ed%<eȐjpj\ed%<eȐjpjXed%<eȐjpj`ed%<eȐjpjded%<eȐjped%<erWeȐjjLed <eȐjjHed <eȐjjPed <ded esfdZdefdZdefdZdefdZdefdZdefdZdefdZdefdZdefdZerUde j@vrDe j@dZe&e«jse(de›e jje jje«\ZǐZ#ejjeǫ edejdZejDeʫZ eːjZd{e j@vr(e&ek7r!de&de͛dZϐeϐdz Ze(eϫe͐Z&d evee)fd!efd"ZeАed#eАed$eАed%d&Zed=defd'ZҐee*ee*ese*esfZԐee*ee+deseӐesesfffZe!d̐efd(Z d>d)e*ed̐efd*ZGd+d,eee(fZؐd-Zِd.Zڐd/Zېd0Zܐd1Zݐd2Zސd3Zߐd4ZdHd5ed6esd7ed8e*evfd9ZdId:Zd;ZdJd<Zy#e$$rZ%e$dye!dze%e%dZ%[%wwxYw#e*$rZ%e*de&e%dZ%[%wwxYw#e($rZ%e(de›e%dZ%[%wwxYw#e$rZ%eΐde%dZ%[%wwxYw(KN)UserDict defaultdict) GeneratorIterableIteratorMapping)MISSINGfields)cachewraps)StringIO)Path)AnyCallableOptionalUnion)mock)patch) delete_repo)version)Trainer)logging)is_clearml_availableis_optuna_availableis_ray_availableis_sigopt_availableis_swanlab_availableis_tensorboard_availableis_trackio_availableis_wandb_available)is_deepspeed_available)hACCELERATE_MIN_VERSIONGGUF_MIN_VERSIONTRITON_MIN_VERSIONis_accelerate_availableis_apex_availableis_apollo_torch_availableis_aqlm_availableis_auto_awq_availableis_auto_gptq_availableis_auto_round_availableis_av_availableis_bitsandbytes_available'is_bitsandbytes_multi_backend_availableis_bs4_availableis_compressed_tensors_availableis_cv2_availableis_cython_availableis_decord_availableis_detectron2_availableis_eetq_availableis_essentia_availableis_faiss_availableis_fbgemm_gpu_availableis_flash_attn_2_availableis_flash_attn_3_availableis_flax_availableis_flute_availableis_fp_quant_availableis_fsdp_availableis_ftfy_availableis_g2p_en_availableis_galore_torch_availableis_gguf_availableis_gptqmodel_availableis_grokadamw_availableis_hadamard_availableis_hqq_available#is_huggingface_hub_greater_or_equalis_ipex_availableis_jinja_availableis_jumanpp_availableis_keras_nlp_availableis_kernels_availableis_levenshtein_availableis_librosa_availableis_liger_kernel_availableis_lomo_availableis_mistral_common_availableis_natten_availableis_nltk_availableis_onnx_availableis_openai_availableis_optimum_availableis_optimum_quanto_availableis_pandas_availableis_peft_availableis_phonemizer_availableis_pretty_midi_availableis_psutil_availableis_pyctcdecode_availableis_pytesseract_availableis_pytest_available!is_pytorch_quantization_availableis_quark_availableis_qutlass_availableis_rjieba_availableis_sacremoses_availableis_safetensors_availableis_schedulefree_availableis_scipy_availableis_sentencepiece_availableis_seqio_availableis_spacy_availableis_speech_availableis_spqr_availableis_sudachi_availableis_sudachi_projection_availableis_tf_availableis_tiktoken_availableis_timm_availableis_tokenizers_availableis_torch_available!is_torch_bf16_available_on_deviceis_torch_bf16_gpu_available!is_torch_fp16_available_on_deviceis_torch_greater_or_equalis_torch_hpu_availableis_torch_mlu_availableis_torch_neuroncore_availableis_torch_npu_availableis_torch_optimi_availableis_torch_tensorrt_fx_availableis_torch_tf32_availableis_torch_xla_availableis_torch_xpu_availableis_torchao_availableis_torchaudio_availableis_torchcodec_availableis_torchdynamo_availableis_torchvision_availableis_triton_availableis_vision_availableis_vptq_available strtobool)AcceleratorState PartialState)is_fp8_available)Module _get_checker_get_continue_on_failure _get_runner _is_mocked_patch_unwrap_mock_awareget_optionflags)skip) import_path) DoctestItemzjulien-c/bert-xsmall-dummyzjulien-c/dummy-unknownzjulien-c/dummy-diff-tokenizer__DUMMY_TRANSFORMERS_USER__zhttps://hub-ci.huggingface.co%hf_94wBhPGp6KrrTH3KDchhKpRxZwd6dmHWLLConfig ForCausalLMForQuestionAnsweringForSequenceClassificationForTokenClassification) config_classcausal_lm_classquestion_answering_classsequence_classification_classtoken_classification_classxpuFc tj|} t|}|S#t$rtd|dwxYw#t$r|}Y|SwxYw)NIf set, z must be yes or no.)osenvironr ValueErrorKeyErrorkeydefaultvalue_values `/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/transformers/testing_utils.pyparse_flag_from_envrsp B 3  Bu%F M Bxu,?@A A B  M? #< A Ac tj|} t|}|S#t$rtd|dwxYw#t$r|}Y|SwxYw)Nrz must be a int.)rrintrrrs rparse_int_from_envrsj> 3 >ZF M >xuO<= = >  MrRUN_SLOW)r RUN_FLAKYTRUN_CUSTOM_TOKENIZERSHUGGINGFACE_CO_STAGINGRUN_PIPELINE_TESTSRUN_AGENT_TESTSctstjd|S ddl}|jj |S#t $r|cYSwxYw)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. ztest is staging testreasonrN) _run_stagingunittestrpytestmarkis_staging_test ImportError test_casers rrrsY ;x}}$:;IFF < 16;;..0; ;   A AActstjd|S ddl}|jj |S#t $r|cYSwxYw)z Decorator marking a test as a pipeline test. If RUN_PIPELINE_TESTS is set to a falsy value, those tests will be skipped. ztest is pipeline testrrN)_run_pipeline_testsrrrris_pipeline_testrrs rrr"sY >rcBtjfd}|S)Nch |i|S#t$r}tjd|d}~wwxYw)Nz)Test skipped due to NotImplementedError: )NotImplementedErrorrSkipTest)argskwargse test_funcs rwrapperz(skip_if_not_implemented..wrapperWsE Ud-f- -" U##&OPQs$ST T Us 1,1 functoolsr )rrs` rskip_if_not_implementedrVs'__YU U Nrct|D]B}|jdst||}t|s-t ||t |D|S)zP Class decorator to apply @skip_if_not_implemented to all test methods. test_)dir startswithgetattrcallablesetattrr)cls attr_nameattrs rapply_skip_if_not_implementedrasSXG    (3 *D~Y(?(EF G JrcBtjtd|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. ztest of custom tokenizers)rr_run_custom_tokenizersrs rcustom_tokenizersrms" T8  57R ST] ^^rcJtjtd|S)z} Decorator marking a test that requires BeautifulSoup4. These tests are skipped when BeautifulSoup4 isn't installed. ztest requires BeautifulSoup4)rrr0rs r require_bs4rws% S8  /13Q RS\ ]]rcJtjtd|S)z Decorator marking a test that requires GaLore. These tests are skipped when GaLore isn't installed. https://github.com/jiaweizzhao/GaLore ztest requires GaLore)rrrBrs rrequire_galore_torchr~% T8  8:= )rrr&rr s rrequire_accelerater s5 8   ,0TU`Ta.b  rcfd}|S)zm Decorator marking a test that requires triton. These tests are skipped when triton isn't installed. cTtjtd|S)Nz test requires triton version >= )rrrr s r decoratorz!require_triton..decorators2vx""#6{#CGghsgtEuv   r)r rs` rrequire_tritonrs  rcRtjt|d||S)zj Decorator marking a test that requires ggguf. These tests are skipped when gguf isn't installed. ztest requires gguf version >= )rrrCr s r require_ggufrs4 o8  0=A_`k_l?m n rcRtjt|d||S)zi Decorator marking a test that requires fsdp. These tests are skipped when fsdp isn't installed. ztest requires torch version >= )rrr?r s r require_fsdprs4 p8  0=A`al`m?n o rcJtjtd|S)zt Decorator marking a test that requires g2p_en. These tests are skipped when SentencePiece isn't installed. ztest requires g2p_en)rrrArs rrequire_g2p_enr$ N8  246L Mi XXrcJtjtd|S)zw Decorator marking a test that requires safetensors. These tests are skipped when safetensors isn't installed. ztest requires safetensors)rrrfrs rrequire_safetensorsr% X8  79;V WXa bbrcJtjtd|S)zm Decorator marking a test that requires rjieba. These tests are skipped when rjieba isn't installed. ztest requires rjieba)rrrdrs rrequire_rjiebarrrcJtjtd|S)zk Decorator marking a test that requires jinja. These tests are skipped when jinja isn't installed. ztest requires jinja)rrrJrs r require_jinjar$ L8  135J KI VVrcJtjtd|S)Nztest requires ONNX)rrrUrs r require_onnxr"s! I8  024H I) TTrcJtjtd|S)zo Decorator marking a test that requires Timm. These tests are skipped when Timm isn't installed. ztest requires Timm)rrrrrs r require_timmr$rrcJtjtd|S)zs Decorator marking a test that requires NATTEN. These tests are skipped when NATTEN isn't installed. ztest requires natten)rrrSrs rrequire_nattenr&$ N8  246L Mi XXrcJtjtd|S)zu Decorator marking a test that requires PyTorch. These tests are skipped when PyTorch isn't installed. test requires PyTorch)rrrtrs r require_torchr*'s$ N8  135L Mi XXrrcfd}|S)z Decorator marking a test that requires PyTorch version >= `version`. These tests are skipped when PyTorch version is less than `version`. cTtjtd|S)Nz!test requires PyTorch version >= )rrrxrrs rrz1require_torch_greater_or_equal..decorator8s2ux""#= `version`. These tests are skipped when huggingface_hub version is less than `version`. cTtjtd|S)Nz)test requires huggingface_hub version >= )rrrHr-s rrz;require_huggingface_hub_greater_or_equal..decoratorGs6 x"" / 8ls% _8  8:<] ^_h iircztjdttr_t D]O}t |}t|t js*t |ddr8t|}t||QSt ddrStjfd}d|_ |S)zZ A decorator that loads the HF token for tests that require to load gated models. HF_HUB_READ_TOKEN__require_read_token__Fc$td5|i|cdddSdtjjvr6t |dkDr(t |dt jr |ddi|S|i|S#1swYyxYw)Nz(huggingface_hub.utils._headers.get_token) return_value staticmethodrr)rinspect getsourcestriplen isinstancerTestCase)rrrtokens rrz#require_read_token..wrappers ETYZ6$d5f566"W%6%6y%A%G%G%II4y1}DGX=N=N)O($qr(=f== $1&1166s BBT) rgetenvrItyperrtypes FunctionTyperequire_read_tokenrrr rA)rrrwrappedrrKs` @rrPrPus II) *E)T"Y 7I9i0D$ 2 234!95A,T2 9g6  7 96 >   # 2 $ 2*.&rcJtjtd|S)zo Decorator marking a test that requires PEFT. These tests are skipped when PEFT isn't installed. ztest requires PEFT)rrrZrs r require_peftrSrrcJtjtd|S)z} Decorator marking a test that requires Torchvision. These tests are skipped when Torchvision isn't installed. ztest requires Torchvision)rrrrs rrequire_torchvisionrUrrcJtjtd|S)z{ Decorator marking a test that requires Torchcodec. These tests are skipped when Torchcodec isn't installed. ztest requires Torchcodec)rrrrs rrequire_torchcodecrWs% V8  68:T UV_ ``rcbtjtxs td|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)rrrtrprs rrequire_torch_or_tfrYs1 q8  13H7HJo p rcJtjtd|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. ztest requires Intel Extension for PyTorch to be installed and match current PyTorch version, see https://github.com/intel/intel-extension-for-pytorch)rrrIrs r#require_intel_extension_for_pytorchr[s/ 8   @   rcJtjtd|S)zu Decorator marking a test that requires torchaudio. These tests are skipped when torchaudio isn't installed. test requires torchaudio)rrrrs rrequire_torchaudior^% V8  68:T UV_ ``rcJtjtd|S){ Decorator marking a test that requires SentencePiece. These tests are skipped when SentencePiece isn't installed. ztest requires SentencePiece)rrrirs rrequire_sentencepiecerbs% \8  9;=Z [\e ffrcJtjtd|S)zu Decorator marking a test that requires Sacremoses. These tests are skipped when Sacremoses isn't installed. ztest requires Sacremoses)rrrers rrequire_sacremosesrdr_rcJtjtd|S)raztest requires Seqio)rrrjrs r require_seqiorfr rcJtjtd|S)zs Decorator marking a test that requires Scipy. These tests are skipped when SentencePiece isn't installed. ztest requires Scipy)rrrhrs r require_scipyrhr rcJtjtd|S)u Decorator marking a test that requires 🤗 Tokenizers. These tests are skipped when 🤗 Tokenizers isn't installed. ztest requires tokenizers)rrrsrs rrequire_tokenizersrjr_rcJtjtd|S)zs Decorator marking a test that requires keras_nlp. These tests are skipped when keras_nlp isn't installed. ztest requires keras_nlp)rrrLrs rrequire_keras_nlprlrrcJtjtd|S)zm Decorator marking a test that requires pandas. These tests are skipped when pandas isn't installed. ztest requires pandas)rrrYrs rrequire_pandasrnrrcJtjtd|S)zw Decorator marking a test that requires PyTesseract. These tests are skipped when PyTesseract isn't installed. ztest requires PyTesseract)rrr_rs rrequire_pytesseractrp rrcJtjtd|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)rrrars rrequire_pytorch_quantizationrrs) r8  @BDp q rcJtjtd|S)z Decorator marking a test that requires the vision dependencies. These tests are skipped when torchaudio isn't installed. ztest requires vision)rrrrs rrequire_visionrts$ N8  246L Mi XXrcJtjtd|S)zi Decorator marking a test that requires ftfy. These tests are skipped when ftfy isn't installed. ztest requires ftfy)rrr@rs r require_ftfyrv"$ J8  024H I) TTrcJtjtd|S)zk Decorator marking a test that requires SpaCy. These tests are skipped when SpaCy isn't installed. ztest requires spacy)rrrkrs r require_spacyry)r rctstjd|Sddl}tj|j j dkDd|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)rrNrz test requires multiple CUDA GPUsrtrrtorchrcuda device_countrr|s rrequire_torch_multi_gpur0sR  ` abk llrctstjd|Stjt t dkDd|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)rrz#test requires multiple acceleratorsrtrrrbackend_device_count torch_devicers rrequire_torch_multi_acceleratorr?sL  X YZc ddrctstjd|Stjt t dkd|S)zW Decorator marking a test that requires 0 or 1 accelerator setup (in PyTorch). r)rrz test requires 0 or 1 acceleratorrrs r#require_torch_non_multi_acceleratorrYsH  ^ _`i jjrctstjd|Stjt t dkd|S)z\ Decorator marking a test that requires 0 or 1 or 2 accelerator setup (in PyTorch). r)rrz&test requires 0 or 1 or 2 acceleratorsrrs r"require_torch_up_to_2_acceleratorsrosL  =2.4) or via Intel Extension for PyTorch. In the latter case, if IPEX is installed, its version must match match current PyTorch version. ztest requires XPU device)rrrrs rrequire_torch_xpurs% U8  579S TU^ __rcHtjtdk7d|S)zB Decorator marking a test that should be skipped for XPU. rztest requires a non-XPUrrs rrequire_non_xpurrrctstjd|Stjtj j dkDd|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" ztest requires PyTorch XPUrrztest requires multiple XPUs)rrrrr|rr~rs rrequire_torch_multi_xpurrrctstjd|Stjtj j dkDd|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" ztest requires PyTorch HPUrrztest requires multiple HPUs)ryrrrr|rr~rs rrequire_torch_multi_hpurrrTRANSFORMERS_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_DEVICEr}zTRANSFORMERS_TEST_DEVICE=zH, but CUDA is unavailable. Please double-check your testing environment.zG, but XPU is unavailable. Please double-check your testing environment.rzG, but NPU is unavailable. Please double-check your testing environment.mluzG, but MLU is unavailable. Please double-check your testing environment.rzG, but HPU is unavailable. Please double-check your testing environment.zUUnknown testing device specified by environment variable `TRANSFORMERS_TEST_DEVICE`: cpucJtjtd|S)z2Decorator marking a test that requires TorchDynamoztest requires TorchDynamo)rrrrs rrequire_torchdynamors" W8  79;V WXa bbrcJtjtd|S)z.Decorator marking a test that requires torchaoztest requires torchao)rrrrs rrequire_torchaors" O8  357N OPY ZZrcfd}|S)Nc&txretjtjtjjdj tjk\}t j|dd|S)Ntorchaoz4Test requires torchao with the version greater than .)rrparse importlibmetadata base_versionrr)rcorrect_torchao_versiontorchao_versions rrz;require_torchao_version_greater_or_equal..decorator#s"6"8#,W]] MM),,44Y? @ M M> ]]? +>, x"" #'[\k[llm%n  rr)rrs` r(require_torchao_version_greater_or_equalr"s rcJtjtd|S)z8Decorator marking a test that requires Torch-TensorRT FXztest requires Torch-TensorRT FX)rrr~rs rrequire_torch_tensorrt_fxr.s" c8  =?Ab cdm nnrcHtjtdk(d|S)8Decorator marking a test that requires CUDA and PyTorch.r}ztest requires CUDArrs rrequire_torch_gpur3s" L8  |v57K LY WWrcHtjtdk(d|S)rmpsztest requires MPSrrs rrequire_torch_mpsr8s" J8  |u46I J9 UUrmemorycts|Sddl}tj|j j dz |kDd|d|S)zWDecorator marking a test that requires a CPU RAM with more than `memory` GiB of memory.rN@z'test requires a machine with more than z GiB of CPU RAM memory)r]psutilrrvirtual_memorytotal)rrrs rrequire_large_cpu_ramr=s[   8  %%/&8 1&9OP  rctdk7r tjd|d|Stjtj j djdz |kDd|d|S)zXDecorator marking a test that requires a CUDA GPU with more than `memory` GiB of memory.r}z(test requires a CUDA GPU with more than  GiB of memoryrrrz#test requires a GPU with more than )rrrrr|r}get_device_properties total_memory)rrs rrequire_torch_large_gpurJs{vfx}}&NvhVd$efgpqq 8   ((+887BVK -fX^D  rc tdk7r)tdk7r tjd|d|Sttt}tj |j djdz |kDd|d|S)z\Decorator marking a test that requires an accelerator with more than `memory` GiB of memory.r}rz*test requires a GPU or XPU with more than rrrr)rrrrr|rrr)rrtorch_accelerator_modules rrequire_torch_large_acceleratorrUsv,%"7hx}}&PQWPXXf$ghirss&ul; 8   66q9FFPSYY 4VHNK  rcDtr tr|St|S)zl Decorator marking a test that requires a GPU if bitsandbytes multi-backend feature is not enabled. )r.r/rrs r2require_torch_gpu_if_bnb_not_multi_backend_enabledrbs!!"'N'P Y ''rc\tjtduxr tdk7d|S)zMDecorator marking a test that requires an accessible accelerator and PyTorch.Nrztest requires acceleratorrrs rrequire_torch_acceleratorrks1 o8  |47QLE=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)rrrvrs rrequire_torch_bf16_gpurs, 8  #%S  rc.tfd}|S)NctrGtj} tjd|i|tj|S|i|S#tj|wxYw)NT)rr|$are_deterministic_algorithms_enableduse_deterministic_algorithms)rroriginal_staters rrz.require_deterministic_for_xpu..wrappersh ! #"GGIN C2248 $1&122>Bd-f- -22>Bs AA2)r )rrs` rrequire_deterministic_for_xpurs! 9 . . NrcJtjtd|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)rrrrs rrequire_torch_tf32rs* 8  !#f  rcJtjtd|S)z2Decorator marking a test that requires detectron2.ztest requires `detectron2`)rrr5rs rrequire_detectron2rs" W8  68:V WXa bbrcJtjtd|S)z-Decorator marking a test that requires faiss.ztest requires `faiss`)rrr8rs r require_faissrs! M8  135L Mi XXrcJtjtd|S)zs Decorator marking a test that requires optuna. These tests are skipped when optuna isn't installed. ztest requires optuna)rrrrs rrequire_optunarr'rcJtjtd|S)zw Decorator marking a test that requires Ray/tune. These tests are skipped when Ray/tune isn't installed. ztest requires Ray/tune)rrrrs r require_rayrs$ M8  /13K LY WWrcJtjtd|S)zs Decorator marking a test that requires SigOpt. These tests are skipped when SigOpt isn't installed. ztest requires SigOpt)rrrrs rrequire_sigoptrr'rcJtjtd|S)zu Decorator marking a test that requires swanlab. These tests are skipped when swanlab isn't installed. ztest requires swanlab)rrrrs rrequire_swanlabr% P8  357N OPY ZZrcJtjtd|S)zu Decorator marking a test that requires trackio. These tests are skipped when trackio isn't installed. ztest requires trackio)rrr rs rrequire_trackiorrrcJtjtd|S)zq Decorator marking a test that requires wandb. These tests are skipped when wandb isn't installed. ztest requires wandb)rrr!rs r require_wandbrs$ L8  135J KI VVrcJtjtd|S)zp Decorator marking a test requires clearml. These tests are skipped when clearml isn't installed. ztest requires clearml)rrrrs rrequire_clearmlrrrcJtjtd|S)z: Decorator marking a test that requires deepspeed ztest requires deepspeed)rrr"rs rrequire_deepspeedrrrcJtjtd|S)z5 Decorator marking a test that requires apex ztest requires apex)rrr'rs r require_apexrrwrcJtjtd|S)z5 Decorator marking a test that requires aqlm ztest requires aqlm)rrr)rs r require_aqlmrrwrcJtjtd|S)z5 Decorator marking a test that requires vptq ztest requires vptq)rrrrs r require_vptqr rwrcJtjtd|S)z5 Decorator marking a test that requires spqr ztest requires spqr)rrrmrs r require_spqrrrwrct}|r ddl}t j |d|S#t$r}dt|vrd}Yd}~9d}~wwxYw)z5 Decorator marking a test that requires eetq rNshard_checkpointFztest requires eetq)r6eetqrstrrr)reetq_availablerexcs r require_eetqr s['(N '  E8  ~/C DY OO  '!SX-"'  's. AA  AcJtjtd|S)z3 Decorator marking a test that requires av ztest requires av)rrr-rs r require_avr *s# F8  02D Ei PPrcJtjtd|S)z7 Decorator marking a test that requires decord ztest requires decord)rrr4rs rrequire_decordr1rrctr*tr ddl}|jj |St jd|S#t $r|cYSwxYw)z Decorator marking a test that requires the bitsandbytes library. Will be skipped when the library or its hard dependency torch is not installed. rNz$test requires bitsandbytes and torchr)r.rtrr bitsandbytesrrrrs rrequire_bitsandbytesr8s^!"'9';  ;;++I6 6Lx}}$JKIVV   sA AAcJtjtd|S)z* Decorator for optimum dependency ztest requires optimum)rrrWrs rrequire_optimumrG% P8  357N OPY ZZrc>tjtdS)z0 Decorator for `tensorboard` dependency ztest requires tensorboard)rrrrs rrequire_tensorboardrNs   79;V WWrcbtjtxs td|S)z, Decorator for auto_gptq dependency z$test requires gptqmodel or auto-gptq)rrrDr+rs r require_gptqrUs3 8   <$:$<>d  rcJtjtd|S)z& Decorator for hqq dependency ztest requires hqq)rrrGrs r require_hqqr^s$ H8  /13F G RRrcJtjtd|S)z+ Decorator for auto_awq dependency ztest requires autoawq)rrr*rs rrequire_auto_awqres% Q8  468O PQZ [[rcJtjtd|S)z- Decorator for auto_round dependency ztest requires autoround)rrr,rs rrequire_auto_roundrls% U8  68:S TU^ __rcJtjtd|S)z) Decorator for quanto dependency ztest requires optimum-quanto)rrrXrs rrequire_optimum_quantor!s% ^8  :<>\ ]^g hhrcJtjtd|S)z5 Decorator for compressed_tensors dependency z test requires compressed_tensors)rrr1rs rrequire_compressed_tensorsr$zs% f8  >@Bd efo pprcJtjtd|S)z- Decorator for fbgemm_gpu dependency ztest requires fbgemm-gpu)rrr9rs rrequire_fbgemm_gpur&r_rcJtjtd|S)z( Decorator for quark dependency ztest requires quark)rrrbrs r require_quarkr(r rcbtjtxr td|S)zC Decorator marking a test that requires higgs and hadamard z/test requires flute and fast_hadamard_transform)rrr=rFrs rrequire_flute_hadamardr*s3 8  8!6!8:k  rcJtjtd|S)zE Decorator marking a test that requires fp_quant and qutlass ztest requires fp_quant)rrr>rs rrequire_fp_quantr,% R8  468P QR[ \\rcJtjtd|S)z8 Decorator marking a test that requires qutlass ztest requires qutlass)rrrcrs rrequire_qutlassr/rrcJtjtd|S)z; Decorator marking a test that requires phonemizer ztest requires phonemizer)rrr[rs rrequire_phonemizerr1r_rcJtjtd|S)z< Decorator marking a test that requires pyctcdecode ztest requires pyctcdecode)rrr^rs rrequire_pyctcdecoder3rrcJtjtd|S)z8 Decorator marking a test that requires librosa ztest requires librosa)rrrOrs rrequire_librosar5rrcJtjtd|S)z= Decorator marking a test that requires liger_kernel ztest requires liger_kernel)rrrPrs rrequire_liger_kernelr7s% Z8  8:@Bs t rcJtjtd|S)8 Decorator marking a test that requires jumanpp ztest requires jumanpp)rrrKrs rrequire_jumanpprKrrcJtjtd|S)rJztest requires cython)rrr3rs rrequire_cythonrMrrcJtjtd|S)zq Decorator marking a test that requires TikToken. These tests are skipped when TikToken isn't installed. ztest requires TikToken)rrrqrs rrequire_tiktokenrOr-rcJtjtd|S)zm Decorator marking a test that requires speech. These tests are skipped when speech isn't available. r])rrrlrs rrequire_speechrQs% R8  246P QR[ \\rcJtjtd|S)z7 Decorator marking a test that requires openai ztest requires openai)rrrVrs rrequire_openairSrrcJtjtd|S)z} Decorator marking a test that requires mistral-common. These tests are skipped when mistral-common isn't available. ztest requires mistral-common)rrrRrs rrequire_mistral_commonrUr"rctrddl}|jjSt r(ddl}t |jjdStrddl }|jSy)z^ Return the number of available gpus (regardless of whether torch, tf or jax is used) rNGPU) rtr|r}r~rp tensorflowrHconfiglist_physical_devicesr<jax)r|tfr[s r get_gpu_countr]s`zz&&((  2992259::  s!!rcztjdd}tjj tjj |}|j ds1tjj |}|j ds1|r tjj||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. rtests)rEstackrpathabspathdirnameendswithjoin) append_pathcaller__file__ tests_dirs r get_tests_dirri)s]]_Q'*N ?@I  )GGOOI.   )ww||I{33rtrainerreturnc|j}|j}|j|||j}|d}|S)N)r dataloadertotal_train_batch_sizer)rget_train_dataloaderset_initial_training_valuesper_device_train_batch_size)rj training_argstrain_dataloaderinitial_training_valuessteps_per_epochs rget_steps_per_epochrv@sRLLM335%AA #,HHB .a0O rside_effect_valuesc#4K|Ed{ |d7 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. Nr)rws revaluate_side_effect_factoryrzNs)"!!  $$ "s cPtjdd|dtjS)Nz^.*\rr)resub MULTILINE)bufs rapply_print_resetsrjs 66(BQ 55rct|j}|j|j}|dk7s Jd|d|y)Nryzexpecting to find z in output: f)rlowerfind)outwhatout_pr match_strs rassert_screenoutrnsH  $ * * ,F DJJL)I ?L0mF8LL?rcgd}|D]}t||dgd}|D]-}t||s|D]}tt|||d/y)N) rms_norm_epslayer_norm_epsnorm_eps norm_epsilonlayer_norm_epsilonbatch_norm_eps?) text_config vision_config text_encoder audio_encoderdecoder)rhasattrr)rY target_attrs target_attrattrsrs rset_config_for_less_flaky_testrtsmL$*  S)* YEA 64 + A -{C@ AArc&d}gd}trt|tjjr\|j D]H}t |jj|s(|D]}t||st||dJyyy)N) LayerNorm GroupNorm BatchNormRMSNorm BatchNorm2d BatchNorm1dBitGroupNormActivationWeightStandardizedConv2d)epsepsilonvariance_epsilonr) rtrIr|nnrmodulesrM__name__rdrr)model target_namesrmodulers rset_model_for_less_flaky_testrs L:L 5%((// Bmmo 3FF|$$--l;(3Dvt,c23 3!Crc*eZdZdZddZdZdZdZy) 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||_|rt|_d|_nd|_d|_|rt|_d|_yd|_d|_y)Nz=error: CaptureStd context is unfinished yet, called too earlyznot capturing stdoutznot capturing stderr)replayr out_bufrerr_buferr)selfrrrs r__init__zCaptureStd.__init__sK #:DLVDHDL-DH #:DLVDHDL-DHrc|jr*tj|_|jt_|jr*tj |_|jt_|Sr=)rsysstdoutout_oldrstderrerr_oldrs r __enter__zCaptureStd.__enter__sA <<::DLCJ <<::DLCJ rc|jrj|jt_|jj }|j rtjj |t||_|jrb|jt_ |jj }|j rtjj |||_ yyr=) rrrrgetvaluerwriterrrrrr)rr captureds r__exit__zCaptureStd.__exit__s <<CJ||,,.H{{   *)(3DH <<CJ||,,.H{{   *DH rcd}|jr|d|jdz }|jr|d|jdz }|S)Nr|zstdout:  stderr: )rrrr)rmsgs r__repr__zCaptureStd.__repr__sH << XdhhZr* *C << XdhhZr* *C rN)TTTr __module__ __qualname____doc__rrrrrrrrrs. `."   rrc$eZdZdZdfd ZxZS) CaptureStdoutz+Same as CaptureStd but captures only stdoutc(t|d|y)NF)rrsuperrrr __class__s rrzCaptureStdout.__init__  U62rTrrrrr __classcell__rs@rrr 533rrc$eZdZdZdfd ZxZS) CaptureStderrz+Same as CaptureStd but captures only stderrc(t|d|y)NF)rrrrs rrzCaptureStderr.__init__rrrrrs@rrrrrrc(eZdZdZdZdZdZdZy) 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|_tj|j|_d|_y)Nr|)loggerr ior StreamHandlershr)rrs rrzCaptureLogger.__init__0s/ *''0rcP|jj|j|Sr=)r addHandlerrrs rrzCaptureLogger.__enter__6s tww' rc|jj|j|jj |_yr=)r removeHandlerrrrr)rr s rrzCaptureLogger.__exit__:s, !!$''*77##%rc"d|jdS)Nz captured: r)rrs rrzCaptureLogger.__repr__>sDHH:R((rNrrrrrrs0 &)rrc#Ktj} tj|dtj|y#tj|wxYww)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 LoggingLevelrBsI&335J7**51 **:6**:6sA!AA!AA!c>eZdZdZd deedeeddfdZdZdZy) TemporaryHubRepoaCreate 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 namespacerKrkc||_tj5}t|j}||d|}t j ||j|_dddy#1swYyxYw)N/)rK)rKtempfileTemporaryDirectoryrnamehuggingface_hub create_reporepo_url)rrrKtmp_dirrepo_ids rrzTemporaryHubRepo.__init__hsm  ( ( * Sg7m((G$&Kq 2+77tzzRDM  S S Ss AA**A3c|jSr=)rrs rrzTemporaryHubRepo.__enter__ps }}rc\t|jj|jdy)NT)rrK missing_ok)rrrrK)rr rtbs rrzTemporaryHubRepo.__exit__ssDMM11PTUrNN) rrrrrrrrrrrrrrWs9 S(3-Sx}SX\SVrrrac#Ktj|} tjj d|dtjj |y#tjj |wxYww)z Temporary add given path to `sys.path`. Usage : ```python with ExtendSysPath("/path/to/dir"): mymodule = importlib.import_module("mymodule") ``` rN)rfspathrrainsertremove)ras r ExtendSysPathrwsO 99T?D 4   sB$A B!A>>BceZdZdZdZedZedZedZedZ edZ edZ ed Z ed Z ed Zed Zed ZedZdZddZdZdZy) 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() ```cg|_tj|j|_t |jj }|jd|_dD]:}|j|}|dz js&|dz js:nr||_ ntd|j|jdz |_ |jdz |_ |jdz |_y)Nr)rrrsrcr_z+can't figure out the root of the repo from examples)teardown_tmp_dirsrEgetfiler_test_file_pathrresolveparents_test_file_diris_dir_repo_root_dirr _tests_dir _examples_dir_src_dir)rrauprs rsetUpzTestCasePlus.setUps!# 't~~>D(()113"ll1o Bll2&G%'')w/@.H.H.J  ")D J4K_K_J`ab b--7!00:=++e3 rc|jSr=)rrs rtest_file_pathzTestCasePlus.test_file_paths###rc,t|jSr=)rrrs rtest_file_path_strzTestCasePlus.test_file_path_strs4''((rc|jSr=)rrs r test_file_dirzTestCasePlus.test_file_dir"""rc,t|jSr=)rrrs rtest_file_dir_strzTestCasePlus.test_file_dir_str4&&''rc|jSr=)rrs rrhzTestCasePlus.tests_dirs rc,t|jSr=)rrrs r tests_dir_strzTestCasePlus.tests_dir_strs4??##rc|jSr=)rrs r examples_dirzTestCasePlus.examples_dirs!!!rc,t|jSr=)rrrs rexamples_dir_strzTestCasePlus.examples_dir_str s4%%&&rc|jSr=)rrs r repo_root_dirzTestCasePlus.repo_root_dirr rc,t|jSr=)rrrs rrepo_root_dir_strzTestCasePlus.repo_root_dir_strr#rc|jSr=)rrs rsrc_dirzTestCasePlus.src_dirs }}rc,t|jSr=)rrrs r src_dir_strzTestCasePlus.src_dir_strs4==!!rcftjj}|j|jg}d|j vr|j |jn|j |j|j |jdddj||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|:) rrcopyr.r2r"appendr*r&getre)renvpathss rget_envzTestCasePlus.get_env sjjoo'')9)9: $00 0 LL.. / LL++ , SWW\2./HHUOL rNc||d}|d}t|j}|jdstd|d|dur'|j rt j |d|jddn|d}|d}tj}|dur|jj||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_errorsrexist_ok) rrrrexistsr>rmtreemkdirrmkdtempr r7)rrbeforeafterras rget_auto_remove_tmp_dirz$TestCasePlus.get_auto_remove_tmp_dir4s0   ~}=((*D%%d+ _`g_hhij ~$++- gT: JJtdJ 3~}&&(G D=  " " ) )' 2rcLtds tdtjd|d}t 5}t ||j dddtjjddjd d d z}|S#1swYExYw) 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) ``` rCz:/usr/bin/time is required, install with `apt install time`z/usr/bin/time -f %M python -c '')r9Nrrr|i) rArshlexsplitrexecute_subprocess_asyncr;rrreplace)r one_liner_strr@csmax_rsss rpython_one_liner_max_rssz%TestCasePlus.python_one_liner_max_rssxs./*YZ Zkk;M?!LM \ >R $Sdlln = >bffll4(,44ZDEL  > >s BB#cL|jD]}tj|dg|_trkt j t j ttjjD]}d|vstj|=yy)NTr> ACCELERATE) r r>rCr&r _reset_staterlistrrkeys)rraks rtearDownzTestCasePlus.tearDowns** 4D MM$d 3 4!# " $  ) ) +  % % '"**//+, &1$ 1  & %rNNN)rrrrrpropertyrrrr"rhr&r(r*r,r.r0r2r;rHrSrZrrrr r sL \4($$))##(($$""''##((""(BHB &rr c ^tjjtj|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) )rrdictrr)rs rmockenvr_s ::??2::v ..rc/pKtj|xsi}|xsg}t|jt|ztjz}|Dcic]}|| }}t fd|D} j ||Dcgc]}j |dc}dj ||Dcgc]}j |c}ycc}wcc}wcc}w#j ||Dcgc]}j |c}wcc}wxYww)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. c3,K|] }|vs| ywr=r).0rYr9s r z"mockenv_context..s?1!3,Q?s N)rrsetrX frozensetupdatepop)rrfstompedrY update_after remove_afterr9s @rmockenv_contextrks **C \rF \rF6;;=!CK/3sxxz?BG'./!As1vI/L/???L+ 6#)*aD *  < )**0 + + < )***sZA D6# C-0D6C<C25C<<D6C7) D62C<7D6<D3D.* D33D6cVd}|tvr|j|ddddt|<yy)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-reportsstoreFzSgenerate report files. The value of this option is used as a prefix to report names)actionrhelprN)pytest_opt_registered addoption)parseroptions rpytest_addoption_sharedrtsCF ** f  )*f%+rc ddlm}t|sd}|j}|j }|j j }|j}d|}t|jdddDcic] }||d|d  } }g} |jjD]'} | D] } t| d s| j| ")| r| jd d t| d d5} d}| j!dt#| D]s\}} | j$|kr%| j!t| |z d|dn<| j!| j$dd| j&dd| j(dudddd}d|j _t| dd5} ||| |_|j-dddt| dd5} ||| |_||dddd|j _t| dd5} ||| |_|j-dddt| dd5} ||| |_|j/dddt| d d5} ||| |_|j1|j1dddd!|_t| d"d5} ||| |_|j3dddt| d#d5} ||| |_|j5ddd||_||_||j _ycc}w#1swYxYw#1swYxYw#1swYxYw#1swYExYw#1swYxYw#1swYxYw#1swYxYw#1swYxYw)$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_zreports/Tr@) durationserrors failures_longfailures_short failures_linepassesstats summary_shortwarningsrz.txtdurationc|jSr=)rxs rz.pytest_terminal_summary_main..$ s r)rreverserwwg?zslowest durations z durations < z secs were omittedz02.2fzs z<8 rNc d|jd}|sy|jdd|D]}|j|}|jd|ddtjdd|j d tj tjz}|jj|y) Nfailed=zFAILURES SHORT STACKr9T)redboldz.*_ _ _ (_ ){10,}_ _ r|r) getreports write_sep_getfailureheadliner}r~ longreprtextrDOTALL_twline)trreportsreprlongreprs rsummary_failures_shortz.summary_failures_short. s--)  S01 "C((-C LLct$L 7vv6C)N N/N%"N1N=$M.1M;>N NN"%N.1N:=OceZdZdZy) _RunOutputc.||_||_||_yr=) returncoderr)rrrrs rrz_RunOutput.__init__x s$  rN)rrrrrrrrrw srrcZK |jd{}|r ||ny%7wr=)readline)streamcallbackrs r _read_streamr~ s- __&&  TN  &s +)+c T K|rtddj|tj|dg|dd|tjj tjj |dd{}ggd fd tj tjt|j fdtjt|j fdg| d{t|j d{S77)7w) Nz Running: rrr)stdinrrr9c|jdj}|j|st|||yy)Nutf-8)file)decoderstripr7print)rsinkpipelabelquiets rteez_stream_subprocess..tee s:{{7#**, D %D )rc8|tjdS)Nzstdout:r)rr)lrrs rrz$_stream_subprocess.. QSZZ_hAirc8|tjdS)Nzstderr:r)rr)rrrs rrz$_stream_subprocess.. rrtimeout)r|) rreasynciocreate_subprocess_exec subprocessPIPEwait create_taskrrrr) r@r9rrrechoprrrs ` @@@r_stream_subprocessr s  mSXXc]+,, A QR!!&&!!&&   A" C C* ,,    QXX7i j k    QXX7i j k    AFFHnc3 //E 6%s7A3D(9D":BD(:D$;D(D& D($D(&D(c ntj}|jt||||||}dj |}|j dkDr9dj |j } td|d|j d| |js|j std|d|S) N)r9rrrrrrrrJz' failed with returncode z, The combined stderr from workers follows: z' produced no output.) rget_event_looprun_until_completerrerr RuntimeErrorr) r@r9rrrrloopresultcmd_strrs rrNrN s  ! ! #D  $ $3CugUY]^FhhsmG 16==)y1&2C2C1DE::@ C   ==Qwi'<=>> Mrctjjdd}tjdd|dtj }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_WORKERgw0z^gwr|r)rrr8r}r~rr)workers rpytest_xdist_worker_idr s= ZZ^^15 9F VVFB2<< 8F v;rc$d}t}||zS)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. sE_T84EszNot supported: )numpyrIrWrtuplendarraytolistritemsrrint64rtr|Tensorrpr\ is_tensorfloatroundint32float32float16rr6rM)objrnprrYvs ` rrr sx #t>#s* **a  (!%(mc%(//2C.DD "a''' (9??$+ ++ , , ,sB B:B::CcVt|tjjr|S||fSr=)rI collectionsabcrrs r to_2tupler  s$![__--. q6Mrc eZdZy)SubprocessCallExceptionN)rrrrrrrr srrcommandc: tj|tj}|rt|dr|j d}|Sy#tj $r>}t ddj|d|jj |d}~wwxYw)z Runs `command` with `subprocess.check_output` and will potentially return the `stdout`. Will also properly capture if an error occurred while running `command` )rrrz Command `rz$` failed with the following error: N) r check_outputSTDOUTrrCalledProcessErrorrreoutput)r return_stdoutrrs r run_commandr s ((9J9JK vx(w/M   ( (%)**PQRQYQYQ`Q`QbPc d  sAA B9BBcDeZdZdZdZd dZdedefdZe defdZ 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 ``` crtt_tj_g_fd}tjtjjd|tjjj_ jj_S)Ncfd}|S)Ncnjjtj|i|Sr=) _extra_infor7 threading get_ident)rrfuncrs rwrapzHRequestCounter.__enter__..patched_with_thread_info..wrap< s0  '' (;(;(=>T,V,,rr)r r!rs` rpatched_with_thread_infoz:RequestCounter.__enter__..patched_with_thread_info; s -Krdebug) side_effect)rr_counterrr _thread_idrrobjecturllib3connectionpoollogr#patcherstartr)rr"s` rrzRequestCounter.__enter__6 s#C( #--/ ||  " " & &=UV]VlVlVpVpVvVv=w  LL&&(  rrkNct|jjt|jk(sJt |j|jjD]k\}}||j k7r|j ddk(r)|j d|j ddz}dD]}||vs|j|xxdz cc<km|jjy)NrKi3rr) HEADGETPOSTPUTDELETECONNECTOPTIONSTRACEPATCH) rHrcall_args_listrzipr&rr%r+stop)rrr thread_idcallr*methods rrzRequestCounter.__exit__H s499++,D4D4D0EEEE"4#3#3TYY5M5MN OItDOO+yy}#))A,12.Cj S=MM&)Q.)   rrc |j|Sr=)r%)rrs r __getitem__zRequestCounter.__getitem__W s}}S!!rcHt|jjSr=)sumr%rrs r total_callszRequestCounter.total_callsZ s4=='')**rrkN) rrrrrrrrr>r\rArrrrr& s? $ "s"s"+S++rr max_attemptswait_before_retry descriptioncfd}|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.) ctjfd}tjtd|S)Nc d}|kr |i|S|i|S#t$rE}tjd|d|ddtj|dz }Yd}~nd}~wwxYw|krh`)NrTest failed with  at try rr)r6rerrortimesleeprr retry_countrrC test_func_refrDs rrz,is_flaky..decorator..wrappers sK ,%($9&99!$1&1 1 !%LL#4SE+aP\~]^!_`(4 #451$K %  ,s A(;A##A(z test is flaky)rr rr_run_flaky_testsrPrrCrDs` rrzis_flaky..decoratorr s<  ' 2 ( 2Fx""#3_EgNNrr)rCrDrErs`` ris_flakyrS_ s&O& rcfd}|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. cHtjfd}|S)Nc d}|kr |i|S|i|S#tjjtjjtjjtjj tjj f$rE}tjd|d|ddtj|dz }Yd}~nd}~wwxYw|kr)NrrIrJrz8 as it couldn't connect to the specified Hub repository.) requests exceptionsConnectionErrorTimeout ReadTimeout HTTPErrorRequestExceptionrrKrLrMrNs rrz-hub_retry..decorator..wrapper sK ,%($9&99 !$1&1 1''77''//''33''11''88  %LL+C5 Q|nUMN)4 #451$K %  ,sBC!;CC!rrRs` rrzhub_retry..decorator s%  ' 2 ( 2.rr)rCrDrs`` r hub_retryr^ s6 rcLddl}|jjd|S)a Decorator marking a test with order(1). When pytest-order plugin is installed, tests marked with this decorator are guaranteed 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. rNr)rrorderrs r run_firstra s# 6;;  Q  **rcL|)ttjjdd}d}t j |}|j d}|jd}|j|||j||||f}|j |j|} |j|j| d|j| dyy#t$r+} |j|j| Yd} ~ ]d} ~ wwxYw) 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`. NPYTEST_TIMEOUT600spawnrr)targetrrK)rrrr8multiprocessing get_contextQueue JoinableQueueputProcessr, task_doner6 terminatefailre) r target_funcinputsr start_methohdctx input_queue output_queueprocessresultsrs rrun_test_in_subprocessrx sbjjnn%5u=>M  % %m 4C))A,K$$Q'LOOFGO,kkKw3WkXG MMO""7"3  LLL!w#''*+-$ qs"C// D#8!DD#cNddltjfd}|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`). rNctjdddk(r  |i|ydjtjj dj ddd} t jtj}d|d<d|d<d|vrt|djj}t|D]Q\}}||djvs|j d d d}d j jd g|z||<Stjd d g|z}|Dcgc] }|dk7s | }}ntjd d |g}tj ||ddycc}w#tj"$r}|j$j'}|j d} d| dvrd} | d dD]} | j)dr2| t+dd} dj| j dd d} F| j)dr| j-drd| vrnt+| dkDs}| d| z } d| z} | g| z} dj| } j/|dd}~wwxYw)N_INSIDE_SUB_PROCESS1rPYTEST_CURRENT_TESTrytrueCI pytestconfig::r__file__z-mrz --no-summaryT)r9checkcapture_outputrz= test session starts =rr|zFAILED z - rz failed in z (subprocess) F)pytrace)rrLrerr8rMr6deepcopyrWinvocation_paramsrr __globals__r executablerrunrrrrrHrdro)rrtestr9ridxrrexception_messagertextrr rs rrz*run_test_using_subprocess..wrapper s 99*D 1S 8 $ !& !88BJJNN+@AGGLSbQRD( DmmBJJ/-0)*#D "V+"6.#9#K#K#P#PQG"+G"4aQ~ 6 ; ;;#'::d#3AB#7D+/999I9I*9U8V5X[_5_+`GCLa#&..!1D(CgMG*1IQQ.5HqIGI#&..!1D(tfNGwCtDQ J 00 D$%HHOO$5!)//5-a8D %ab 0??95#'I(8#9D#%774::e+>> )(.*?```))flagsFz load_dataset(z# doctest: +IGNORE_RESULTz(>>> .*load_dataset\(.*)z\1 # doctest: +IGNORE_RESULTz>>>z...zcuda|to\(0\)|device=0Tr|)r}rMrrr~searchre)stringskip_cuda_testscodeblock_pattern codeblocks is_cuda_foundr codeblockmodified_strings rpreprocess_stringr/ sB+V299EJM!*-  9 i ',Gy,XFF#>@_ajkJqM i 5I#5 2I> M  O ''*- rceZdZUdZej dej ejzZe e jjddZ e ed<dfd ZxZS)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 (?:^(?P [ ]*) >>> .*) # PS1 line (?:\n [ ]* \.\.\. .*)*) # PS2 lines \n? # Want consists of any non-blank lines that do not start with PS1. (?P (?:(?![ ]*$) # 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_DOCTEST0rcPt||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` )rrrr)rrrrs rrzHfDocTestParser.parseq s( #64+?+?@w}VT**r)z)rrrrr}compilerVERBOSE _EXAMPLE_REboolrrr8r__annotations__rrrs@rrrL s\"** \\BJJ &K&!0CS!IJOTJ++rrc"eZdZdZdeefdZy)HfDoctestModulez Overwrites the `DoctestModule` of the pytest package to make sure the HFDocTestParser is used when discovering tests. rkc#vKGddtj}|jjdk(r`|jj j |j|jjd|jj}nF t|j|jj|jjd}|t }t|}td |t!t#|j }|j%|j&D]4}|j(st+j,||j|| 6y#t$r8|jjdrtd|jznYwxYww) Nc.eZdZdZfdZdfd ZxZS)7HfDoctestModule.collect..MockAwareDocTestFinderzA 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 ct|tr t|d|}t|drt j |}t |||S)a3Doctest 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__)rIr\rrrEunwrapr _find_lineno)rr source_linesrs rrzDHfDoctestModule.collect..MockAwareDocTestFinder._find_lineno sOc8,!#vs3C3 .!..-Cw+ rc t|ryt5t| |||||||dddy#1swYyxYwr=)rrr_find) rr_rrrrglobsseenrs rrz=HfDoctestModule.collect..MockAwareDocTestFinder._find sCc?-/GMsD&,ts 7ArB)rrrrrrrrs@rMockAwareDocTestFinderr s   (  rrz conftest.py importmode)rootpath)rootmodedoctest_ignore_import_errorszunable to import module %r)rrF)verbose optionflagscheckercontinue_on_failure)rrunnerdtest)doctest DocTestFinderrarrY pluginmanager_importconftest getoptionrrrrrrrrrrrrr r from_parent)rrrfinderrrrs rcollectzHfDoctestModule.collect sb! W%:%:! F 99>>] *[[..>>  %%l3--?F $II--..|<(/@A%d+ # N 8 E   KK8 _D}}!--d6Y]^^ _! ;;''(FG5 ABC s2BF9AE5A1F9 (F95>F63F95F66F9N)rrrrrrrrrrrrz s C_+.C_rrdevicedispatch_tablecz||vrt|ds|dS|d|i|S||}t|s|S||i|S)Nr)r)rrrrfns r_device_agnostic_dispatchr sa ^#y12!), ,(~i($9&99  B B< t v r)r}rrcyNrrrrrrr rcy)Nrrrrrrr rrrcyrrrrrrr rrxlaseedc$t|t|Sr=)rBACKEND_MANUAL_SEED)rrs rbackend_manual_seedr5 s $V-@$ GGrc"t|tSr=)rBACKEND_EMPTY_CACHErs rbackend_empty_cacher9  $V-@ AArc"t|tSr=)rBACKEND_DEVICE_COUNTrs rrr= s $V-A BBrc"t|tSr=)r"BACKEND_RESET_MAX_MEMORY_ALLOCATEDrs r"backend_reset_max_memory_allocatedrA s $V-O PPrc"t|tSr=)rBACKEND_RESET_PEAK_MEMORY_STATSrs rbackend_reset_peak_memory_statsrE s $V-L MMrc"t|tSr=)rBACKEND_MAX_MEMORY_ALLOCATEDrs rbackend_max_memory_allocatedrI s $V-I JJrc"t|tSr=)rBACKEND_MEMORY_ALLOCATEDrs rbackend_memory_allocatedrM s $V-E FFrc"t|tSr=)rBACKEND_SYNCHRONIZErs rbackend_synchronizerQ rrc"t|tSr=)r BACKEND_TORCH_ACCELERATOR_MODULErs r backend_torch_accelerator_modulerU s $V-M NNrTRANSFORMERS_TEST_DEVICE_SPECzISpecified path to device spec file is not a file or not found. Received '.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_dictattribute_namec tt|}||t<y#t$r%}d|vrtd|dtd|Yd}~yd}~wwxYw)Nrr=z` not found in 'z)' and no default fallback function found.)rdevice_spec_modulerAttributeErrordevice_spec_path)rrspec_fnrs rupdate_mapping_from_specr{ sb !"4nE/6|,! N2(N++;. s6196)all)r's r is_defaultzExpectations.is_default s6o666rrotherc|\}}}|\}}}d}|#||k(r|dz }|!||k(r|dz }|||k(r|dz }n |dvr|dvrd}tj|rd}|S)a Returns score indicating how similar two instances of the `Properties` tuple are. Rules are as follows: * Matching `type` adds one point, semi-matching `type` adds 0.1 point (e.g. cuda and rocm). * If types match, matching `major` adds another point, and then matching `minor` adds another. * The Default expectation (None, None) is worth 0.5 point, which is better than semi-matching. More on this in the `is_default` function. rr)r}rg?g?)r r,) rr-rrrother_device_type other_major other_minorscores rr2zExpectations.score s%/! UE6;3;   "{6G'G QJE Uk%9 $+)=QJE , ,1BFV1VE  " "5 )E rct|jfd\}}tj|dk(rt d|S)a  Find best matching expectation based on provided device properties. We score each expectation, and to distinguish between expectations with the same score, we use the major and minor version numbers, prioritizing most recent versions. c~tj|d|dd|ddnd|dd |ddfSdfS)Nrrryr)r r2)rrs rrz/Expectations.find_expectation.. s\"":qt4Q47.!QBQ47.!Q57r)rrz"No matching expectation found for )maxr&r r2r)rr result_keyrs ` rr"zExpectations.find_expectation sQ # MMO V   j* 5 :A*NO O rc|jSr=)r%rs rrzExpectations.__repr__+ s))rN)r[)rrrrr#rWrDevicePropertiesr&rDPackedDevicePropertiesrr,rr2r"rrrrr r  s>>P$u%5s%:;<P7$:7t77*3C<+;UX(rr ctjjdd}|jdv}|rddl}|j fd}||_yy)a Patch `torch.compile` to always use `fullgraph=True`. This is useful when some `torch.compile` tests are running with `fullgraph=False` and we want to be able to run them with `fullgraph=True` in some occasion (without introducing new tests) to make sure there is no graph break. After PR #40137, `CompileConfig.fullgraph` is `False` by default, this patch is necessary. TORCH_COMPILE_FORCE_FULLGRAPHr|)yesr~ontyr|rNcd|d<|i|S)NT fullgraphr)rr orig_methods rpatchedz0patch_torch_compile_force_graph..patchedA s"&F; // /r)rrr8rr|r)force_fullgraphr|rCrBs @rpatch_torch_compile_force_graphrE/ sPjjnn%DbIO%++-1UUOmm  0   rc *tjjddjdd}|jd\}}}t j }||}}d\}}} t |D]} | j|k(sd| jjvs,t| jjd|sP| }| jjd}| j}t||} n| |j} d} g} d }t |D]} | j|k(r>d| jjvr&t| jjd|rd }n)d | jjjk(r| } d }n|s|| j!| d}t | D]N}t#j$||j|jj&|jj(}|}P}| jjd }t+j,}d}t |D]} |j.| j0vs| }tj2j5|j}|j} }dd lm}t;|5}|j=}||}dj?|jA|dz jB}dddt;|5}|j=}||}dj?|jA|dz jB}dddd|ddd|d|d }|ddd|d|d }||||| |||||||f S#1swYxYw#1swYDxYw)z Collect some information about the current test. For example, test full name, line number, stack, traceback, etc. r}r|rrrr[rNFTrCrB)Sourcerrztest:  P--------------------------------------------------------------------------------z test context: r5z caller context: )"rrr8rMrEr`reversedfunctionframef_localsrfilenamerlinenof_codeco_namer7rN TracebackTypef_lastif_lineno traceback extract_stackrrrarelpath_pytest._code.sourcerGrreadre getstatementr) full_test_name test_file test_class test_namestack_from_inspectactual_test_file_actual_test_class test_frametest_obj test_methodrL line_numberframe_of_patched_objcaptured_frames to_capturetb_next frame_infortest_tracebackorigin_method_being_patchedr` caller_frame caller_path caller_lineno test_linenorGfpssourcetest_code_contextcaller_code_context test_infos r_get_test_inforwI sZZ^^$92>DDSI!LN'5';';D'A$Iz9!,5j((8%J+,- NNi '%++... ,,V4i@J{{++F3H %~~ !(I6K %( ''  OJ,- * NNi '%++... ,,V4i@J %++,,44 4#( J    " "5 ) *G/  **:*:J.get_argument_name sb dCHH %77N cmm ,;;t$ $ cll + # #;;t$ $rrr|eval)rN)positional_args keyword_argsstarargsrrrrzError parsing: )rHrrOrzrrIbodyCallrr7keywordsargr SyntaxErrorrr) code_contextrindenttree call_noderrarg_namekeywordrs r_get_call_argumentsr sQ % \%8%8%:!; ;F''f b9L!%yyF3$))SXX...II #% "  F!~~ ;,S1()00: ; %-- C;;&'8'GF8$ 1?H:BF>*7;;7 CM/ 8   (% s#$$ %sCDE(D;;Ec|d|}tjjtjj ddd}t |d5}|j |dddddd|S#1swY|SxYw)zgCombine the information about the test and the call information to a patched function/method within it.rH#_PATCHED_TESTING_METHODS_OUTPUT_DIRr|captured_info.txtazx========================================================================================================================N)rrarerr8rr)rvinforrqs r_prepare_debugging_infor s{[TF #D  RZZ^^$I2NPcdA a/ D6i[-./ K/ Ks A44A>cg}t|dr|jjrt|jjD]7}|\}\}}}|jt |d|j ddd9|jjj tj} | t|_ | |g|i|t||j} | jjt| } | dd} | dd} | Dcgc]}|d  }}dd dj!|}|rt | dd d t#|d d d|dd dt#|dd ddj!d|Ddd dd }t| |}| j$|_| j&|_|} | j`| j)| cc}w)a%Used to report a test that has failures captured and handled by patched functions/methods (without re-raise). The patched functions/methods refer to the `patched` defined in `_patch_with_call_info`, which is applied to `torch.testing.assert_close` and `unittest.case.TestCase.assertEqual`. The objective is to avoid a failure being silence after being processed. If there is any failure that is not handled by the patched functions/methods, we add custom error message for them along with the usual pytest failure report. _outcomerHztest_modeling_vit.py)messagerMrrr exceptionrUrzP================================================================================z Handled Failures: (z handled): rIz Unhandled Failures: (z unhandled): , c3LK|]}|dd|d|dd|dyw)rM: rrr5rNr)rbrs rrcz$_patched_tearDown..Is7 oQUd6l^2d9o.tF|nAd6l^ L os"$z Note: This failure occurred after other failures analyzed by the patched assertion methods. To see the full details, temporarily disable assertion patching. )rrrxr7rrclear_patched_tearDown orig_tearDownrMrZr_testMethodName__func__captured_failuresrrerH __cause__ __context__with_traceback)rrrregular_failures_info error_entry test_instanceexc_typeexc_objexc_tbrrdrcaptured_exceptionscaptured_tracebackrcapturued_infocapturued_info_strenhanced_messageenhanced_exceptions rrrsB&tZ T]]%9%9==// K9D 6M6Hgv ! ( ("%g,t4$--2    ""$&33M'DJ$((($ 4 45K#,,>>r+O,A.{;*1-k:):;Aai;N;z.33NC #$7 89:  '()    /012   oYn oopq   $7T"567GH':'D'D$)<)H)H&1 .  , ,-? @@C.patchediszz~~3R8// /; <  ( (9 22OD $X 7 7 2?!/*;X''Em9 N\st(--00-AQ_vw(--00,@P^hi(--002CEUcmn(--00/CSakl(--002FHXfpqrscriptnproc_per_node is_torchrunr9ctjdd5}|j||j|j d|r,d|dt d|j j}nd|j g} tj|d |d d } d d d y #tj$r}td |jd }~wwxYw#1swYy xYw) zmRun the `script` using `torchrun` command for multi-processing in a subprocess. Captures errors as necessary.zw+r)rsuffixrztorchrun --nproc_per_node z --master_port rpython3T)rr9rrz"The following error was captured: N) rNamedTemporaryFilerflushseekrrrMrrrr6r)rrrr9tmpr@r9rs rtorchrunrs  $ $$u =M &   ,^,.Es$kdeN1rr is_scalart_strs `` rrrs a & LLOIvv{ LL!   vv{c!''!B-(QC/ HHJMM% A i,44S"= emMM$,Eem dC(emMM$,Eem !BKE,&. A  u}5 H 1,&. kijkkk <//#55 - Lrcvd|v}d|v}|r|r|jdd}d|dS|rd|dS|rd|dSd|dS)a$Given a string `s`, return a python literal expression that give `s` when it is used in a python source code. For example, if `s` is the string `abc`, the return value is `"abc"`. We choice double quotes over single quote despite `str(s)` would give `'abc'` instead of `"abc"`. rJ"z\")rO)rrhas_single_quotehas_double_quotes r _quote_stringr Mshaxax, IIc5 !1#Qx 1#Qx 1#Qx1#Qxrc $ "#|i}n#t||||f|vr|t||||fSt|jdk(r t|S|jjdk(r!t |}|j dd}|}nl|jjdvr t|}nG|jjdvr.dd d d}||jj\}} g} t|trt|jD]\} \} } | t|d z k(}t| |d zd | }t| |d z|||s|jdzdznd}| j|jd|jnZt|D]L\} }| t|d z k(}t||d z|||sdnd}| j|jNg}g}t| D]\} }|j|d|dv}| t| d z k7}|xsBtdd|d zzztdj|ddzdt!|z kD}|}|sAtdd|d zzztdj|zdt!|z kD}|}t#|turt#|| n$t#t%|j'| t$t(tfvrd}d}d}t#|turt#|| n$t#t%|j'| }t|d kDrSt#|turt#|| d z n't#t%|j'| d z }||k7}|rd}||tur |turd}|turd}|dtfvrd}|st|}|d kDrxd}|tur6tdd|d zzztdj|ddzdkD}|r|ddD]}|j|gn|j|dd|dd}|su|j|g}t|dkDrjd}tur3tdd|d zzztdj|zdkD}|r|D]}|j|gn|j|d|z|d}|Dcgc] }dd|d zzzdj|z"}}|dj|z }|dd|z| z }t+d|D##""r}dj|Dcgc]}|jc}} || | } |d k(r|Std|zt|zt| zdk""#fd}!|!|r d|z| }|t||||f<|Scc}wcc}w)zFormat python objects of basic built-in type in a pretty way so we could copy-past them to code editor easily. Currently, this support int, float, str, list, tuple, and dict. It also works with `torch.Tensor` via calling `format_tesnor`. Nzrrz\n)rrrWrr^z[]z()rrzone-line)rrr r,r|)rrr prefixryrrxTFwrrrc3$K|]}d|v yw)rNrrbrs rrcz!_format_py_obj..s%Md!m%Mr*ct|tttfvrg}t|tur'|j d|j Dn/t|ttfvr|j d|Dt d|Dr+t|dkDryt|t|duryStt|dkDry|dttfvrS|dturt|dk(rSSy)Nc32K|]}t|ywr=rMrs rrcz<_format_py_obj..use_one_line_repr..s,KT!W,Kc32K|]}t|ywr=rrs rrcz<_format_py_obj..use_one_line_repr..s,BT!W,Brc3BK|]}|tttfvywr=rrs rrcz<_format_py_obj..use_one_line_repr..sK1ud 33KsrFrT) rMrWrr^extendranyrHrdrrr)r element_typescould_use_one_lineno_new_line_in_elementss ruse_one_line_reprz)_format_py_obj..use_one_line_repr s9ud 33$&MCyD(%,,,Kcjjl,KKctUm3%,,,Bc,BBK]KKs8a<#( 9DQL8#( 763}-.2$%Q'C<766&q)S0s8q=#::$65r)rrrrrr rOrIr^rrrHrrr7rerrMrWrrr+)$rrrr r quoted_stringr parenthesisp1p2elements_without_indentrrYr last_elementokovrogroupsr x_expandednot_last_elementshould_finalize_xshould_finalize_bufbuf_not_fit_into_one_line prev_type current_type type_changed orig_buf_lennot_fit_into_one_lineelement_strings one_line_formr"r r!s$ @@rrrcs } sGVT6 *e 3"S'6489 9 3==55c""   5 (%c* %--dE:    #3 3S   #< < S]]334B"$ c4 (5 P Va"c#hl2 #AfqjzQVW#!A:;G299;-3R (.."))+b /NO P$C. ;Q"c#hl2 "fqjt5T`fh(..qxxz:  ; 78C FC JJqMRJ"c*A&BQ&FF  *!,cSA!TRUR\R\R^M_`cMdHeL3x!|26s)42GDS1W.TRVWZWaWaWcRdehklelRmMn +y8 *.' Y#%5,#:M&+#s"$)!s +*/'""3x !#,0)!C'03sa6A:>N7O6P0RUXY]YbYbcfgjhjckYlUm0mpw0w-,!$Sb/A"MM1#./ c#2h/bc(C$MM#&CGC L s8a<$( !s"(+sa6A:6F/G.H(JSQUQZQZ[^Q_M`(`cf(f%$'AMM1#&' c"f$%bT,U[\ccQ&1*%567499S>I\\%**_--Bw'(--#&%M_%M"M4  II?&Kaqxxz&KLM!d=/"6Mz! "%&(8'9!;c&k!ICP]L^!^be!e ( V!%#f,-m_=-3E2c7FD& )* MM]'Ls %XX )Fr=)z1.12.0)P))NNNFF)NNFT)r)NN)r<rr)TN)rN)rr|Nr|(rzr  contextlibr6rrrrrErrgrr}rLr>rrrrrLrUrNrrrcollections.abcrrrr dataclassesr r r r rr pathlibrtypingrrrrr unittest.mockrhuggingface_hub.utilsrrWr(r packagingr transformersrr integrationsrrrrrrr r!integrations.deepspeedr"utilsr#r$r%r&r'r(r)r*r+r,r-r.r/r0r1r2r3r4r5r6r7r8r9r:r;r<r=r>r?r@rArBrCrDrErFrGrHrIrJrKrLrMrNrOrPrQrRrSrTrUrVrWrXrYrZr[r\r]r^r_r`rarbrcrdrerfrgrhrirjrkrlrmrnrorprqrrrsrtrurvrwrxryrzr{r|r}r~rrrrrrrrrrrraccelerate.staterraccelerate.utils.importsr_pytest.doctestrrrrrrr_pytest.outcomesr_pytest.pathlibrrrr'SMALL_MODEL_IDENTIFIERDUMMY_UNKNOWN_IDENTIFIERDUMMY_DIFF_TOKENIZER_IDENTIFIERUSERENDPOINT_STAGINGTOKEN_COMMON_MODEL_NAMES_MAPr|hiprr}rrr get_loggerrrrrrrQrrrrrrrrrrrrrrrrrrrrrrrr rrrrrrrr"r$r&r*r/r2r:r<r>rPrSrUrWrYr[r^rbrdrfrhrjrlrnrprrrtrvryrrrrrrrrrrrrrrrrbackend import_moduler9ModuleNotFoundErrorrr is_availablerrrrXr\r[default_backend jax_devicerrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr r rrrrrrrrr!r$r&r(r*r,r/r1r3r5r7r9r;rArDrFrHrKrMrOrQrSrUr]rirrvrWr^rzrrrrrrrrcontextmanagerrrPathLikerrJr r_rkrprtrrrrrrNrrrr r r6rrrrSr^rarxrr DocTestParserrrr manual_seedr empty_cacherr~rreset_max_memory_allocatedrmax_memory_allocatedrreset_peak_memory_statsrmemory_allocatedr synchronizerrrrrrrrrrrrrrrris_filerarMrealpathdevice_spec_dirr7index import_namer DEVICE_NAME device_namerrrrr rr8r9rrr rErwrrrrrrrrrr rrrrrns-       -BB'"11' 8   ;iiiiiiiiiiiiiiiiiiiiiiiiiiiX?9&+" FK63"A%2 0 $ 6%@": ]]&&d2N]]''t3NEMM5$7tCMNNM (  ( ( 2  &j%@&{DA,-DeT"#;UK )*>M&'8%H<" = :K? _^__eU_eVcU6Ls'9  0@YcYWUUYY C  c u&gj FUca  agaWWa_YcYUW m  ev k ^a g\`\ g g"bjj0**89 ' ''0A"RZZ/zz"<= 6 !%***A*A*C+L>:BC  5 )?)A+L>:AB  5 )?)A+L>:AB  5 )?)A+L>:AB  5 )?)A+L>:AB   \*A  "  !  !  !  !  L$$$&JJc [ o X V U u u (  c Y YXY[[W[_UUUUP"QY W[XS\`iqaW][ac[e]c)f[[Y]]Yi(.  S  %T#u*-. %tCJt+, %86M A*3*bbV3J33J3()()V 77(VV@ c2;;./HTN(X&8$$X&v/ ++B*&B)P&0bl&0R`j, 7:," i c"6+6+r&3&x&\deh\i&R'C''T +(.V7t:++g++++\I_fI_X c 4X ;N   &&  $$  &&  ''  55*&  //$  22'#  ++   &&  ($ %d+$d+%y1*3T):&'0$&7#$-q> )1~$d+(14'8$!&!6!6"'))"8"8.3ii$U+!&!6!6!&!6!6"'))"8"8.3ii$U+!&!6!6!&!6!6"'))"8"8.3ii$U+!&!6!6!&!6!6"'))"8"805 0Q0Q&u--2YY-N-N#E**/))*H*H '&+ii&@&@U#!&!6!6.3ii$U+!&!7!7!&!7!7"'**"9"9HH3HBBCCQsQNCNKKGSGBBOSO'"**4::&EF$%--/[\l[mn   WW]]277+;+;