+
     °³j…  ã                   óF   € R t ^ RIt^ RIHt R R ltR R ltR	R R lltR# )
aV  
A collection of utilities for comparing `examples/complete_*_example.py` scripts with the capabilities inside of each
`examples/by_feature` example. `compare_against_test` is the main function that should be used when testing, while the
others are used to either get the code that matters, or to preprocess them (such as stripping comments)
N)ÚOptionalc                óF   € V ^8„  d   QhR\         \        ,          R\        /# )é   ÚlinesÚname©ÚlistÚstr)Úformats   "Ú_/home/luca/screen-checking/.venv/lib/python3.14/site-packages/accelerate/test_utils/examples.pyÚ__annotate__r      s   € ÷ $ñ $¬¬c­ð $¼#ñ $ó    c                ó$  € VR8w  d   VR8w  d   \        RV R24      h. Rr2V  Fi  pV'       g    RV 2V9   d   RpVP                  V4       K*  V'       g   K4  VR8X  d   RV9   d   Vu # VR8X  d   R	V9   d   Vu # VP                  V4       Kk  	  R
# )a  
Extracts a function from `lines` of segmented source code with the name `name`.

Args:
    lines (`List[str]`):
        Source code of a script separated by line.
    name (`str`):
        The name of the function to extract. Should be either `training_function` or `main`
Útraining_functionÚmainz Incorrect function name passed: z-, choose either 'main' or 'training_function'Fzdef Tzdef mainzif __name__N)Ú
ValueErrorÚappend)r   r   Ú
good_linesÚfound_startÚlines   &&   r   Úget_function_contents_by_namer      s�   € ð Ð"Ô" t¨v¤~ÜÐ;¸D¸6ÐAnÐoÓpÐpØ  %�Ûˆß  d V˜}°Ô4ØˆKØ×Ñ˜dÔ#Ùß‰;ØÐ*Ô*¨z¸TÔ/AØ!Ò!Ø�vŒ~ -°4Ô"7Ø!Ò!Ø×Ñ˜dÖ#ó r   c                ó:   € V ^8„  d   QhR\         \        ,          /# )r   r   r   )r
   s   "r   r   r   4   s   € ÷ Zñ Z”tœC•yñ Zr   c                óŽ   € V  Uu. uF4  qP                  4       P                  R4      '       d   K)  VR8w  g   K2  VNK6  	  up# u upi )zË
    Filters `lines` and removes any entries that start with a comment ('#') or is just a newline ('
')

    Args:
        lines (`List[str]`):
            Source code of a script separated by line.
    Ú#Ú
)ÚlstripÚ
startswith)r   r   s   & r   Úclean_linesr   4   s8   € ñ #ÓY™U�T¯+©+«-×*BÑ*BÀ3×*GŒDÈDÐTXÉL�DˆD™UÑYÐYùÒYs   …&A°A¹Ac          	      ó^   € V ^8„  d   QhR\         R\         R\        R\        \         ,          /# )r   Úbase_filenameÚfeature_filenameÚparser_onlyÚsecondary_filename)r	   Úboolr   )r
   s   "r   r   r   ?   s8   € ÷ Uñ UÜðUÜ*-ðUÜ<@ðUÜV^Ô_bÕVcñUr   c                óÌ  € \        V 4      ;_uu_ 4       pVP                  4       pRRR4       \        \        P                  P	                  \        P                  P                  RR4      4      4      ;_uu_ 4       pVP                  4       pRRR4       \        V4      ;_uu_ 4       pVP                  4       pRRR4       Ve-   \        V4      ;_uu_ 4       pVP                  4       pRRR4       V'       dZ   \        \        XR4      4      p	\        \        XR4      4      p
\        \        XR4      4      pVe   \        \        XR4      4      pMX\        \        XR4      4      p	\        \        XR4      4      p
\        \        XR4      4      pVe   \        \        XR4      4      pRp. p. p\        V4      p\        \        V4      ^,
          4       Fm  pVV9  g   K  \        V4      pVV
9  g   K   VP                  4       V8w  g   K7  RV9  d%   VP                  V4       VP                  V4       Kb  \        V4      pKo  	  . p. p\        V	4       FZ  w  ppVV9  g   K  VV
9  g   K  VP                  4       V8w  g   K/  RV9  g   K8  VP                  V4       VP                  V4       K\  	  V Uu. uF  pVV9  g   K  VNK  	  ppVe5   V Uu. uF  pVX9  g   K  VNK  	  ppV Uu. uF  pVV9  g   K  VNK  	  ppV#   + '       g   i     ELë; i  + '       g   i     EL˜; i  + '       g   i     EL€; i  + '       g   i     ELd; iu upi u upi u upi )a­  
Tests whether the additional code inside of `feature_filename` was implemented in `base_filename`. This should be
used when testing to see if `complete_*_.py` examples have all of the implementations from each of the
`examples/by_feature/*` scripts.

It utilizes `nlp_example.py` to extract out all of the repeated training code, so that only the new additional code
is examined and checked. If something *other* than `nlp_example.py` should be used, such as `cv_example.py` for the
`complete_cv_example.py` script, it should be passed in for the `secondary_filename` parameter.

Args:
    base_filename (`str` or `os.PathLike`):
        The filepath of a single "complete" example script to test, such as `examples/complete_cv_example.py`
    feature_filename (`str` or `os.PathLike`):
        The filepath of a single feature example script. The contents of this script are checked to see if they
        exist in `base_filename`
    parser_only (`bool`):
        Whether to compare only the `main()` sections in both files, or to compare the contents of
        `training_loop()`
    secondary_filename (`str`, *optional*):
        A potential secondary filepath that should be included in the check. This function extracts the base
        functionalities off of "examples/nlp_example.py", so if `base_filename` is a script other than
        `complete_nlp_example.py`, the template script should be included here. Such as `examples/cv_example.py`
NÚexamplesznlp_example.pyr   r   zMtrain_dataloader, eval_dataloader = get_dataloaders(accelerator, batch_size)
ÚTESTING_MOCKED_DATALOADERS)ÚopenÚ	readlinesÚosÚpathÚabspathÚjoinr   r   ÚiterÚrangeÚlenÚnextr   r   Ú	enumerate)r   r    r!   r"   ÚfÚbase_file_contentsÚfull_file_contentsÚfeature_file_contentsÚsecondary_file_contentsÚbase_file_funcÚfull_file_funcÚfeature_file_funcÚsecondary_file_funcÚ_dl_lineÚnew_feature_codeÚpassed_idxsÚitÚir   Ú_Únew_full_example_partsÚdiff_from_exampleÚdiff_from_twos   &&&&                   r   Úcompare_against_testrD   ?   sò  € ô4 
ˆm×	Ô	 ØŸ[™[›]Ð÷ 
ä	Œb�g‰g�o‰oœbŸg™gŸl™l¨:Ð7GÓHÓI×	JÔ	JÈaØŸ[™[›]Ð÷ 
Kä	Ð×	Ô	 1Ø !§¡£Ð÷ 
 àÒ%ÜÐ$×%Ô%¨Ø&'§k¡k£mÐ#÷ &÷ Ü$Ô%BÐCUÐW]Ó%^Ó_ˆÜ$Ô%BÐCUÐW]Ó%^Ó_ˆÜ'Ô(EÐF[Ð]cÓ(dÓeÐØÒ)Ü"-Ô.KÐLcÐekÓ.lÓ"mÐøä$Ô%BÐCUÐWjÓ%kÓlˆÜ$Ô%BÐCUÐWjÓ%kÓlˆÜ'Ô(EÐF[Ð]pÓ(qÓrÐØÒ)Ü"-Ü-Ð.EÐGZÓ[ó#Ðð `€Hð ÐØ€KÜ	ÐÓ	 €BÜ”3Ð(Ó)¨AÕ-Ö.ˆØ�KÖÜ˜“8ˆDØ˜NÖ*°·±³À(Ö1JØ/°tÔ;Ø$×+Ñ+¨DÔ1Ø×&Ñ& qÖ)ô ˜R›’Añ /ð  ÐØ€KÜ˜^Ö,‰ˆˆ4Ø�KÖØ˜NÖ*°·±³À(Ö1JØ/°tÖ;Ø*×1Ñ1°$Ô7Ø×&Ñ& qÖ)ñ -ñ +;ÓaÑ*: $¸dÐJ`Ñ>`Ÿ˜Ñ*:ÐÐaØÒ%Ù*<Ó`Ñ*< $ÀÐL_Ñ@_Ÿ˜Ñ*<ˆÐ`Ù.?Ó]Ñ.? dÀ4È}ÑC\ŸT˜TÑ.?ÐÐ]àÐ÷w 
×	Ð	úç	J×	JÐ	Júç	×	Ð	ú÷ &×%Ð%üò^ bùâ`ùÚ]sS   ”LÁ;LÂ'L/ÃMÊ7	MËMË	MË#MË/	M!Ë=M!ÌL	ÌL,	Ì/M 	ÍM	)N)Ú__doc__r)   Útypingr   r   r   rD   © r   r   Ú<module>rH      s)   ðñ ó 
Ý õ$õ4Z÷Uñ Ur   