Ë
    [^(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mZ d dl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 d dlmZ d dlZd„ Z ed	„ d
D «       «      Z	 	 dd„Z G d„ de	«      Zy)é    N)Úfloating_and_complex_types_and)ÚTestCaseÚfreeze_rng_stateÚTemporaryFileNameÚ)enable_profiling_mode_for_profiling_testsÚis_iterable_of_tensors)Úenable_profiling_mode)Úchain)ÚUnion)Ú
TensorTypec                 ó  — t        |dd «      }|j                  «       D �cg c]  }|j                  «       ‘Œ }}| j                  t	        |«      dk(  «       |d   }t
        j                  j                  ||«       y c c}w )NÚ
last_graphé   r   )ÚgetattrÚoutputsÚtypeÚ
assertTrueÚlenÚtorchÚ_CÚ_jit_assert_is_instance)	ÚselfÚfuncÚref_outputsÚargsÚkwargsÚgraphÚoÚtypesÚts	            ú`/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/torch/testing/_internal/common_jit.pyÚcheck_output_typesr"      se   € Ü�D˜,¨Ó-€EØ$Ÿ}™}›Ö/˜!ˆQ�V‰V�XÐ/€EÐ/Ø‡O�O”C˜“J !‘OÔ$Øˆa‰€AÜ	‡H�H×$Ñ$ [°!Õ4ùò 0s    A<c              #   ó&   K  — | ]	  }d |z   –— Œ y­w)Útest_nn_N© )Ú.0Únames     r!   ú	<genexpr>r(       s   è ø€ ò 	&¸D j°4Õ&7ñ 	&ùs   ‚)ÚpdistÚmultilabel_margin_lossÚmax_unpool3dÚmulti_margin_lossÚbinary_cross_entropyÚ!binary_cross_entropy_size_averageÚctc_lossÚgrid_samplec
                 óž  ‡‡— |r|ni }d„ }
d„ Šdt         fˆˆfd„}d„ } |d¬«      }| j                  |||«      }t        «       5  | j                  |||«      }ddd«       | j                  |«       |rt	        | ||||«       |ryt        «       5   |d	¬«      } ||«      } || j                  |||«      «      }t
        j                  j                   |
|«      ||¬
«      } || j                  |||«      «      }t
        j                  j                   |
|«      ||¬
«      }| j                  ||«       | j                  ||«       | j                  t        v s|	r
	 ddd«       y || j                  |||«      «      } |
|«      }t
        j                  j                  ||d	|¬«      } |
|«      |z  }t
        j                  j                  |||¬
«      } |d	¬«      } ||«      } || j                  |||«      «      } |
|«      }t
        j                  j                  ||d	|¬«      } |
|«      |z  }t
        j                  j                  |||¬
«      }| j                  ||«       | j                  ||«       t        ||«      D ]  \  }}|€|€Œ| j                  ||dd¬«       Œ! 	 ddd«       y# 1 sw Y   �Œ_xY w# 1 sw Y   yxY w)zèVerifies a function performs identically to some reference implementation.

    Commonly, this is used to verify that a JIT implementation
    (output_func) matches the behavior of the eager implementation
    (reference_func).
    c                 ór   — t        | t        j                  «      r| f} t        d„ t	        | «      D «       «      S )Nc              3   ó.  K  — | ]�  \  }}|�†|j                   t        t        j                  t        j                  «      v rR|j                   j
                  r$|dz   |j                  «       j                  «       z  n|dz   |j                  «       z  –— Œ� y ­w)Nr   )Údtyper   r   ÚhalfÚbfloat16Ú
is_complexÚsumÚabs)r&   ÚiÚvs      r!   r(   z:check_against_reference.<locals>.allSum.<locals>.<genexpr>8   s}   è ø€ ò oÙ�q˜!Ø�m¨¯©Ô3QÔRW×R\ÑR\Ô^c×^lÑ^lÓ3mÑ(mð /0¯g©g×.@Ò.@�A˜‘E˜QŸU™U›WŸ[™[›]Ò*ÀqÈ1ÁuÐPQ×PUÑPUÓPWÑFWÓWñ oùs   ‚BB)Ú
isinstancer   ÚTensorr8   Ú	enumerate)Úvss    r!   ÚallSumz'check_against_reference.<locals>.allSum5   s9   € Ü�bœ%Ÿ,™,Ô'Ø�ˆBÜñ oÜ(¨›}ôoó oð 	oó    c                 ó|   — |xr | j                   }| j                  «       j                  «       j                  |«      S ©N)Úrequires_gradÚdetachÚcloneÚrequires_grad_)r    Úpreserve_requires_gradÚrequire_grads      r!   Úclone_tensorz-check_against_reference.<locals>.clone_tensor<   s0   € Ø-ÒA°!·/±/ˆØ�x‰x‹z×ÑÓ!×0Ñ0°Ó>Ð>rA   rH   c           
      ó  •— g }‰D ]x  }t        |t        j                  «      r|j                   ‰|| «      «       Œ6t	        |«      r'|j                  |D �cg c]  } ‰|| «      ‘Œ c}«       Œh|j                  |«       Œz |S c c}w rC   )r<   r   r=   Úappendr   )rH   ÚinputsÚargr    r   rJ   s       €€r!   Úclone_inputsz-check_against_reference.<locals>.clone_inputs@   sz   ø€ Ø@Bˆàò 	#ˆCÜ˜#œuŸ|™|Ô,Ø—‘™l¨3Ð0FÓGÕHÜ'¨Ô,Ø—‘ÐPSÖTÈ1™|¨AÐ/EÕFÒTÕUà—‘˜cÕ"ð	#ð ˆùò	 Us   ÁB
c                 óØ   — g }| D ]b  }t        |t        j                  «      r|j                  r|j	                  |«       Œ;t        |«      sŒG|j                  t        d„ |«      «       Œd |S )Nc                 ó   — | j                   S rC   )rD   )r    s    r!   ú<lambda>zHcheck_against_reference.<locals>.get_recording_tensors.<locals>.<lambda>U   s
   € ¸!¿/¹/€ rA   )r<   r   r=   rD   rL   r   ÚextendÚfilter)r   Úrecording_tensorsrN   s      r!   Úget_recording_tensorsz6check_against_reference.<locals>.get_recording_tensorsN   sc   € Ø02Ðàò 	QˆCÜ˜#œuŸ|™|Ô,°×1BÒ1BØ!×(Ñ(¨Õ-Ü'¨Õ,Ø!×(Ñ(¬Ñ0IÈ3Ó)OÕPð		Qð !Ð rA   F)rH   NT)Úallow_unused)Úcreate_graphrW   gü©ñÒMb@?g-Cëâ6?)ÚatolÚrtol)ÚboolÚrunAndSaveRNGr   ÚassertEqualr"   r   ÚautogradÚgradÚ_testMethodNameÚnn_functional_single_gradÚzip)r   r   Úreference_funcÚoutput_funcr   r   rW   Úcheck_typesÚno_gradÚno_gradgradr@   rO   rV   Únograd_inputsr   Úoutputs_testÚrecording_inputsrU   ÚgradsÚ
grads_testÚl1Úl2Úgrads2Úl1_testÚl2_testÚgrads2_testÚg2Úg2_testrJ   s       `                       @r!   Úcheck_against_referenceru   +   s  ù€ ñ ‰V 2€Fòoò?ð¬Tö ò	!ñ !¸Ô>€MØ× Ñ  °ÀÓG€GÜ	2Ó	4ñ GØ×)Ñ)¨$°¸vÓFˆ÷Gà×Ñ�W˜lÔ+áÜ˜4  |°]ÀFÔKáàä	2Ó	4ñ &@á'¸tÔDÐÙ1Ð2BÓCÐÙ˜d×0Ñ0°ÐAQÐSYÓZÓ[ˆÜ—‘×#Ñ#¡F¨7£OÐ5FØ1=ð $ó ?ˆá" 4×#5Ñ#5°dÐ<LÈfÓ#UÓVˆÜ—^‘^×(Ñ(©°Ó)=Ð?PØ6Bð )ó Dˆ
à×Ñ˜ ,Ô/Ø×Ñ˜ 
Ô+à×ÑÔ#<Ñ<ÁØ÷&@ð &@ñ  ˜d×0Ñ0°ÐAQÐSYÓZÓ[ˆÙ�G‹_ˆÜ—‘×#Ñ# BÐ(9ÈØ1=ð $ó ?ˆñ �U‹m˜bÑ ˆÜ—‘×$Ñ$ RÐ):ÈÐ$ÓVˆÙ'¸tÔDÐÙ1Ð2BÓCÐÙ" 4×#5Ñ#5°dÐ<LÈfÓ#UÓVˆÙ˜Ó&ˆÜ—^‘^×(Ñ(ØÐ&°TÈð )ó Vˆ
ñ ˜*Ó%¨Ñ/ˆÜ—n‘n×)Ñ)¨'Ð3DÐS_Ð)Ó`ˆà×Ñ˜ ,Ô/Ø×Ñ˜ 
Ô+Ü˜v {Ó3ò 	@‰KˆB�Øˆz˜g˜oØØ×Ñ˜R ¨t¸$ÐÕ?ñ	@÷G&@ð &@÷Gñ Gú÷&@ð &@ús    ÁJ6ÂCKÅ'EKÊ6K ËKc                   óf   — e Zd Zd„ Zd„ Zd„ Zdd„Zdd„Zd„ Zd„ Z		 dd	e
ee   eee      f   fd
„Zy)ÚJitCommonTestCasec                 ó®   — t        |t        j                  j                  «      r|n|j	                  «       }t        j                  j                  d|«      S )NÚforward)r<   r   r   ÚGraphr   Ú_create_function_from_graph)r   Útracer   s      r!   ÚcreateFunctionFromGraphz)JitCommonTestCase.createFunctionFromGraph�   s7   € Ü# E¬5¯8©8¯>©>Ô:‘ÀÇÁÃˆÜ�x‰x×3Ñ3°I¸uÓEÐErA   c                 óJ   — | j                  |«      }| j                  ||«       y rC   )r}   ÚassertExportImportModule)r   r|   rM   Úms       r!   ÚassertExportImportz$JitCommonTestCase.assertExportImport”   s"   € Ø×(Ñ(¨Ó/ˆØ×%Ñ% a¨Õ0rA   c                 ó”   — | j                  |«      }| j                  ||«      }| j                  ||«      }| j                  ||d«       y )NzIResults of original model and exported/imported version of model differed)ÚgetExportImportCopyr\   r]   )r   r€   rM   Úm_importÚaÚbs         r!   r   z*JitCommonTestCase.assertExportImportModule˜   sO   € Ø×+Ñ+¨AÓ.ˆØ×Ñ˜q &Ó)ˆØ×Ñ˜x¨Ó0ˆØ×Ñ˜˜Að  Mõ 	NrA   Nc                 ób   — |r|ni }t        «       5   ||i |¤Ž}d d d «       |S # 1 sw Y   S xY wrC   )r   )r   r   rM   r   Úresultss        r!   r\   zJitCommonTestCase.runAndSaveRNGŸ   s:   € Ù!‘ rˆÜÓñ 	.Ù˜FÐ- fÑ-ˆG÷	.àˆ÷	.àˆús   ‘	$¤.c                 ó˜  — t        j                  «       }t        j                  j	                  ||«       |j                  d«       t        j                  j                  ||¬«      }|s|S t        «       5 }t        j                  j	                  ||«       t        j                  j                  ||¬«      cd d d «       S # 1 sw Y   y xY w)Nr   )Úmap_location)ÚioÚBytesIOr   ÚjitÚsaveÚseekÚloadr   )r   r€   Úalso_test_filerŠ   ÚbufferÚimportedÚfnames          r!   rƒ   z%JitCommonTestCase.getExportImportCopy¥   s�   € Ü—‘“ˆÜ�	‰	�‰�q˜&Ô!Ø�‰�AŒÜ—9‘9—>‘> &°|�>ÓDˆáØˆOäÓ ð 	D EÜ�I‰I�N‰N˜8 UÔ+Ü—9‘9—>‘> %°l�>ÓC÷	D÷ 	Dò 	Dús   Á5AC Ã C	c                 ó  — d}|rÇ|dz  }g }g }	g }
g }|D ])  }||v r|	j                  |«       Œ|j                  |«       Œ+ |D ])  }||v r|j                  |«       Œ|
j                  |«       Œ+ t        |«      dkD  r	|d|› d�z  }t        |	«      dkD  r	|d|	› d�z  }t        |
«      dkD  r	|d|
› d�z  }t        |«      dkD  r	|d|› d�z  }|S |d	z  }t        |«      dkD  r	|d|› d
�z  }t        |«      dkD  r	|d|› d�z  }|S )Nz0
Failure in testing nodes' autodifferentiation. z�One or more nodes were expected to be autodiffed, but were not found in specified fusible/nonfusible DifferentiableGraph groups. 
Specifically:r   z
  z³ were not in one of the DifferentiableGraphs when they were expected to be. Did you intend for these nodes to be autodiffed? If not, remove them from the list of nonfusible nodes.a#   were found in one of the FusionGroups when they were expected to be just in a DifferentiableGraph. If it was intended for these nodes to be in FusionGroups, reclassify these nodes as fusible nodes. If these nodes were not intended to be fused, your autodifferentiation logic might be wrong.aP   were not in one of the FusionGroups of the DifferentiableGraphs when they were expected to be. They were also not found in an outer DifferentiableGraph. Did you intend for these nodes to be autodifferentiated? If not, you should remove these nodes from the test's fusible nodes. Otherwise your autodifferentiation logic might be wrong.aH   were not in one of the FusionGroups of the DifferentiableGraphs when they were expected to be, instead they were found just in an outer DifferentiableGraph. Did you intend for these nodes to be fused? If not, you should move these nodes into the test's nonfusible nodes. Otherwise your autodifferentiation logic might be wrong.a  One or more nodes were not expected to be autodiffed but were found in a DifferentiableGraph or in a FusionGroup of a DifferentiableGraph. Did you intend for these nodes to be autodiffed? If so, change this test to expect autodifferentiation. 
Specifically:zu were not expected to be in one of the DifferentiableGraphs, but appeared in a FusionGroup of a DifferentiableGraph. zE were not expected to be in one of the DifferentiableGraphs but were.)rL   r   )r   Úshould_autodiff_nodeÚnodes_not_in_diff_graphÚfusion_nodes_not_foundÚnon_fusible_nodes_being_fusedÚfusion_nodes_foundÚnodes_in_diff_graphÚerr_msgÚdiff_nodes_missingÚdiff_nodes_in_fusionÚfusion_nodes_missingÚfusion_nodes_in_diffÚnodes                r!   ÚautoDiffErrorMessagez&JitCommonTestCase.autoDiffErrorMessage²   sØ  € ð FˆÙØð >ñ >ˆGð "$Ðð $&Ð à#%Ð ð $&Ð Ø/ò 4�ØÐ8Ñ8Ø(×/Ñ/°Õ5à&×-Ñ-¨dÕ3ð	4ð
 /ò 6�ØÐ.Ñ.Ø(×/Ñ/°Õ5à(×/Ñ/°Õ5ð	6ô
 Ð%Ó&¨Ò*Ø˜TÐ"4Ð!5ð 6Mð Mñ M�ô Ð'Ó(¨1Ò,Ø˜TÐ"6Ð!7ð 8@ð @ñ @�ô
 Ð'Ó(¨1Ò,Ø˜TÐ"6Ð!7ð 8@ð @ñ @�ô Ð'Ó(¨1Ò,Ø˜TÐ"6Ð!7ð 8@ð @ñ @�ð& ˆð ð "ñ "ˆGô
 Ð%Ó&¨Ò*Ø˜TÐ"4Ð!5ð 61ð 1ñ 1�ô Ð&Ó'¨!Ò+Ø˜TÐ"5Ð!6ð 7Fð Fñ F�àˆrA   c           
      óH  ‡— |j                  d«      }|D �cg c]  }|j                  d«      ‘Œ }}t        t        j                  |D �cg c]  }|j                  d«      ‘Œ c}«      «      }	|	D �cg c]  }|j                  d«      ‘Œ }
}g }g }g }|D ]_  Št        ˆfd„|D «       «      r|j                  ‰«       n|j                  ‰«       t        ˆfd„|
D «       «      sŒO|j                  ‰«       Œa t        |«      t        |«      k(  }g }g }|D ]9  Št        ˆfd„|
D «       «      r|j                  ‰«       Œ)|j                  ‰«       Œ; t        |«      t        |«      k(  }|�.| j                  ||||||«      }| j                  ||xr ||«       y y c c}w c c}w c c}w )Nzprim::DifferentiableGraphÚSubgraphzprim::FusionGroupc              3   óD   •K  — | ]  }|j                  ‰«      d u–— Œ y ­wrC   ©ÚfindNode©r&   Úgr¡   s     €r!   r(   z7JitCommonTestCase.assertAutodiffNode.<locals>.<genexpr>  s   øè ø€ ÒH°A�1—:‘:˜dÓ#¨4Ô/ÑHùó   ƒ c              3   óD   •K  — | ]  }|j                  ‰«      d u–— Œ y ­wrC   r¦   r¨   s     €r!   r(   z7JitCommonTestCase.assertAutodiffNode.<locals>.<genexpr>  ó   øè ø€ ÒJ°A�1—:‘:˜dÓ#¨4Ô/ÑJùrª   c              3   óD   •K  — | ]  }|j                  ‰«      d u–— Œ y ­wrC   r¦   r¨   s     €r!   r(   z7JitCommonTestCase.assertAutodiffNode.<locals>.<genexpr>  r¬   rª   )
ÚfindAllNodesr©   Úlistr
   Úfrom_iterableÚanyrL   r   r¢   r]   )r   r   r–   Únonfusible_nodesÚfusible_nodesÚ
diff_nodesr¡   Údiff_subgraphsr©   Úfusion_nodesÚfusion_subgraphsr›   r—   r™   Úfound_all_nonfusible_nodesrš   r˜   Úfound_all_fusible_nodesrœ   s         `            r!   ÚassertAutodiffNodez$JitCommonTestCase.assertAutodiffNodeö   s»  ø€ Ø×'Ñ'Ð(CÓDˆ
Ø9CÖD°˜$Ÿ&™& Õ,ÐDˆÐDô œE×/Ñ/Ð^lÖ0mÐYZ°·±Ð@SÕ1TÒ0mÓnÓoˆØ;GÖH°4˜DŸF™F :Õ.ÐHÐÐHð !ÐØ"$ÐØ(*Ð%Ø$ò 	;ˆDÜÓH¸ÔHÔHØ#×*Ñ*¨4Õ0à'×.Ñ.¨tÔ4ÜÓJÐ9IÔJÕJØ-×4Ñ4°TÕ:ð	;ô &)Ð)<Ó%=ÄÐEUÓAVÑ%VÐ"ð  ÐØ!#ÐØ!ò 	4ˆDÜÓJÐ9IÔJÔJØ"×)Ñ)¨$Õ/à&×-Ñ-¨dÕ3ð		4ô
 #&Ð&8Ó"9¼SÀÓ=OÑ"OÐàÐ+Ø×/Ñ/Ð0DØ0GØ0FØ0MØ0BØ0CóEˆGð ×ÑÐ1Ø7ÒSÐ<SÐU\õ^ð ,ùò; Eùò 1nùÚHs   —FÁ	FÁ0FÚ	out_sizesc                 óÜ  ‡ ‡— t         j                  j                  «       }dD �]'  }t         j                  j                  |«       t         j                  j	                  |«       |rt         j                  j                  |«       t         j                  j                  |«       t        |j                  «       «      j                  «       }ˆˆ fd„}|j                  t         j                  j                  j                  «       «      r
 |||«       Œð|j                  «       }	t        t        |	«      «      D ]  }
 ||	|
   ||
   «       Œ �Œ* t         j                  j                  |«       y )N)TFc                 ó8  •— | j                  «       }t        j                  «       j                  |«      }t        j                  «       j                  |«      }‰j	                  |j                  |«      «       ‰r!‰j                  |j                  «       |«       y y rC   )Úsymbolic_sizesr   ÚgetÚ
with_sizesr   ÚisSubtypeOfr]   Úsizes)r   Úactual_sizerÂ   Úout_typeÚactual_typeÚassert_propagationr   s        €€r!   Ú	test_typez7JitCommonTestCase.checkShapeAnalysis.<locals>.test_type/  sy   ø€ Ø×+Ñ+Ó-�Ü%Ÿ>™>Ó+×6Ñ6°uÓ=�Ü(Ÿn™nÓ.×9Ñ9¸+ÓF�ð —‘ × 7Ñ 7¸Ó AÔBñ &Ø×$Ñ$ X§^¡^Ó%5°{ÕCð &rA   )r   r   Ú&_jit_symbolic_shapes_test_mode_enabledÚ"_jit_set_symbolic_shapes_test_modeÚ&_jit_erase_non_input_shape_informationÚ_jit_pass_constant_propagationÚ#_jit_pass_propagate_shapes_on_graphÚnextr   r   rÁ   r   r¿   ÚelementsÚranger   )r   r»   Útraced_graphrÆ   Úconstant_propÚ!prev_symbolic_shapes_test_enabledÚenable_test_modeÚoutputrÇ   Útuple_elementsr:   s   `  `       r!   ÚcheckShapeAnalysisz$JitCommonTestCase.checkShapeAnalysis  s  ù€ ô -2¯H©H×,[Ñ,[Ó,]Ð)Ø -ó 	?Ðô �H‰H×7Ñ7Ð8HÔIÜ�H‰H×;Ñ;¸LÔIÙÜ—‘×7Ñ7¸ÔEÜ�H‰H×8Ñ8¸ÔFô ˜,×.Ñ.Ó0Ó1×6Ñ6Ó8ˆFõDð ×!Ñ!¤%§(¡(×"5Ñ"5×"9Ñ"9Ó";Ô<Ù˜& )Õ,à!'§¡Ó!2�Üœs >Ó2Ó3ò ?�AÙ˜n¨QÑ/°¸1±Õ>ò?ð;	?ô@ 	�‰×3Ñ3Ð4UÕVrA   rC   )TN)T)Ú__name__Ú
__module__Ú__qualname__r}   r�   r   r\   rƒ   r¢   rº   r   r¯   ÚintrÖ   r%   rA   r!   rw   rw   �   sW   „ òFò1òNóóDòBòH'^ðT LPñ$W¨E°$°s±)¸TÀ$ÀsÁ)¹_Ð2LÑ,Mô $WrA   rw   )NTTFF)r   Ú
torch.cudaÚ	torch.jitÚtorch.jit._loggingÚtorch.jit.frontendÚtorch.jit.quantizedÚ$torch.testing._internal.common_dtyper   Ú$torch.testing._internal.common_utilsr   r   r   r   r   r	   Ú	itertoolsr
   Útypingr   Útorch._Cr   r‹   r"   Ú	frozensetra   ru   rw   r%   rA   r!   ú<module>ræ      s€   ðó Û Û Û Û Û õ P÷kõ kå Fõ Ý Ý ã 	ò5ñ &ñ 	&ð 	Eô 	&ó 	Ð ð SWØ\aób@ôHtW˜õ tWrA   