
    iPA                         S SK r S SKrS SKJrJrJr  S SKJr  S SKJs  J	s  J
r
  S SKrS SKJr  S SKJr  S SKJr  S SKJrJrJr  S SKJrJr  S SKJr  S S	KJr  S S
KJr  S SKJr   " S S\R@                  5      r!g)    N)DictListTuple)CaptureConfig)ops!register_additional_test_aten_ops)dynamo_traceExirDynamoConfigusing_dynamo)condmap)parameterized)SpecViolationError)is_concrete_int)	FileCheckc                   8   \ rS rSr\SS j5       rSS jrSS jrSS jrSS jr	SS	 jr
SS
 jrSS jrSS jrSS jrSS jr\R"                  " S/5      S\SS4S j5       rSS jrSS jrSS jrSS jrSS jrSS jrSS jrSS jrSS jrSS jrSS jrSrg)TestTorchDispatchFXTracer   returnNc                     [        5         g Nr   )clss    `/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/executorch/exir/tests/test_tracer.py
setUpClass$TestTorchDispatchFXTracer.setUpClass   s    )+    c                 F   [         R                  " 5       n[        R                  " XR	                  5       [        R
                  " 5       5      R                  5       R                  R                  n[        5       R                  S5      R                  UR                  5        g )N+executorch_exir_dialects_edge__ops_aten_sin)modelsBasicSinMaxexircaptureget_random_inputsr   to_edgeexported_programgraph_moduler   checkruncodeselffs     r   test_simple%TestTorchDispatchFXTracer.test_simple#   sh     LL//143E3E3GHWYll 	
 	GHLLQVVTr   c                    S[         S[        R                  S[        R                  4S jnSn[        R                  " S5      n[        R
                  " XU4[        R                  " 5       5      R                  5       R                  R                  n[        5       R                  S5      R                  S5      R                  UR                  5        S	n[        R
                  " XU4[        R                  " 5       5      R                  5       R                  R                  n[        5       R                  S5      R                  S5      R                  UR                  5        g )
Npredxr   c                     U (       a$  [         R                  " U5      R                  5       $ [         R                  " U5      $ r   )torchsinmax)r1   r2   s     r   r-   =TestTorchDispatchFXTracer.test_static_control_flow.<locals>.f.   s*    yy|''))yy|#r   Td   r   +executorch_exir_dialects_edge__ops_aten_maxF)boolr4   Tensorrandnr"   r#   r   r%   r&   r'   r   r(   r)   r*   	check_not)r,   r-   r1   r2   f_truef_falses         r   test_static_control_flow2TestTorchDispatchFXTracer.test_static_control_flow-   s    	$D 	$U\\ 	$ell 	$ KKLL1It'9'9';<WYll 	 	GHNN9	

#fkk
LL1It'9'9';<WYll 	
 	GHRR9	

#gll
r   c                    [         R                  " 5       n[        R                  " XR	                  5       [        R
                  " 5       5      R                  5       R                  R                  nU R                  [        U[        R                  R                  5      5        [        R                  " U5      nU R                  [        U[        R                  R                  5      5        g r   )r    r!   r"   r#   r$   r   r%   r&   r'   
assertTrue
isinstancer4   fxGraphModulecopydeepcopy)r,   r-   gs      r   	test_copy#TestTorchDispatchFXTracer.test_copyJ   s     LL//143E3E3GHWYll 	
 	
1ehh&:&:;<MM!
1ehh&:&:;<r   c                    S[         R                  S[         R                  4S jn[        R                  " U[         R                  " SS5      4[        R
                  " 5       5      R                  5       R                  R                  nU R                  [        S UR                  R                   5       5      5        U R                  [        S UR                  R                   5       5      5        g )Nr2   r   c                 
    X -   $ r    r2   s    r   r-   4TestTorchDispatchFXTracer.test_stacktrace.<locals>.fW   s	    5Lr      c              3   X   #    U  H   oR                   R                  S S5      v   M"     g7fstack_traceNmetaget.0nodes     r   	<genexpr><TestTorchDispatchFXTracer.test_stacktrace.<locals>.<genexpr>a   "     T?St		mT22?S   (*c              3   X   #    U  H   oR                   R                  S S5      v   M"     g7frS   rU   rX   s     r   r[   r\   d   r]   r^   )r4   r;   r"   r#   randr   r%   r&   r'   rC   anygraphnodes)r,   r-   traced_fs      r   test_stacktrace)TestTorchDispatchFXTracer.test_stacktraceV   s    	 	%,, 	 LLUZZ1-/1C1C1EFWYll 	 	Tx~~?S?STT	
 	Tx~~?S?STT	
r   c           	      ,    " S S[         R                  R                  5      n[         R                  R                  U" 5       [         R                  " S5      4SS[         R                  R                  S5      00SS9n[        R                  " U5        g )Nc                       \ rS rSrS rSrg).TestTorchDispatchFXTracer.test_ones.<locals>.Mh   c                 P    [         R                  " UR                  S   5      nX-   $ Nr   )r4   onesshaper,   r2   ys      r   forward6TestTorchDispatchFXTracer.test_ones.<locals>.M.forwardi   s    JJqwwqz*ur   rN   N)__name__
__module____qualname____firstlineno__rq   __static_attributes__rN   r   r   Mri   h   s    r   rx      r2   r   T)dynamic_shapesstrict)r4   nnModuleexportrm   Dimr"   r%   )r,   rx   eps      r   	test_ones#TestTorchDispatchFXTracer.test_onesg   sq    	 	
 \\  CZZ]!U\\%5%5c%:!;<	 ! 
 	Rr   c                 J   S[         R                  S[         R                  4S jnU R                  [        S5         [        R
                  " U[         R                  " S5      4[        R                  " 5       5      R                  5         S S S 5        g ! , (       d  f       g = f)Nr2   r   c                 ~    [         R                  " [         R                  " S5      [         R                  " S5      U S9$ )N   )out)r4   addrm   rO   s    r   r-   ATestTorchDispatchFXTracer.test_possible_input_mutation.<locals>.fv   s%    99UZZ]EJJqMqAAr   zoperator .* is not functionalr   )	r4   r;   assertRaisesRegexr   r"   r#   zerosr   r%   r+   s     r   test_possible_input_mutation6TestTorchDispatchFXTracer.test_possible_input_mutationu   su    	B 	B%,, 	B ##,
 LLU[[^-t/A/A/CDLLN	
 
 
s   AB
B"c                 8  ^  " U4S jS[         R                  R                  5      mT" 5       n[        R                  " XR                  5       [        R                  " 5       5      R                  [        R                  " SS95      R                  R                  nSnSnUR                  R                   H=  nUR                  S:X  d  M  US-  nUR                  R                  S5      c  M8  US-  nM?     U R!                  S	U5        U R!                  S	U5        g )
Nc                      >^  \ rS rSrS	UU 4S jjrS\R                  S\R                  4S jrS\\R                  S4   4S jr	Sr
U =r$ )
LTestTorchDispatchFXTracer.test_tensor_spec_for_const_tensors.<locals>.Module   r   c                 l   > [         TU ]  5         [        R                  R	                  SS5      U l        g )NrQ   ry   )super__init__r4   r|   Linearlinearr,   r}   	__class__s    r   r   UTestTorchDispatchFXTracer.test_tensor_spec_for_const_tensors.<locals>.Module.__init__   s&    fd,.#hhooa3r   r2   c                 $    U R                  U5      $ r   r   r,   r2   s     r   rq   TTestTorchDispatchFXTracer.test_tensor_spec_for_const_tensors.<locals>.Module.forward   s    {{1~%r   .c                 0    [         R                  " S5      4$ )NrQ   )r4   r<   r,   s    r   r$   ^TestTorchDispatchFXTracer.test_tensor_spec_for_const_tensors.<locals>.Module.get_random_inputs   s    A((r   r   r   N)rs   rt   ru   rv   r   r4   r;   rq   r   r$   rw   __classcell__r   r}   s   @r   r}   r      sG    4 4& &%,, &)5s1B+C ) )r   r}   F_check_ir_validityr   get_attr   valrQ   )r4   r|   r}   r"   r#   r$   r   r%   EdgeCompileConfigr&   r'   rb   rc   oprV   rW   assertEqual)r,   modelr'   num_get_attr_node!num_get_attr_node_with_tensorspecndr}   s         @r   "test_tensor_spec_for_const_tensors<TestTorchDispatchFXTracer.test_tensor_spec_for_const_tensors   s    		)UXX__ 		) LL 7 7 94;M;M;OPW&&%@|| 	 ,-)$$**Buu
"!Q&!77;;u%15:5	 + 	-.=>r   c                 r   S[         R                  S[        [         R                  [         R                  4   4S jnSn[        R                  " U[         R
                  " SSS5      4[        R                  " 5       5      R                  5       R                  R                  nUR                  R                   Hi  nUR                  [        R                  R                  R                   R"                  :X  d  MA  US-  nU R%                  UR&                  S   [(        5        Mk     U R+                  US5        g )	Nr2   r   c                 l    [         R                  R                  R                  R	                  U SS5      $ )Nr   F)r4   r   atenr6   dimrO   s    r   r-   ?TestTorchDispatchFXTracer.test_multiple_returns_spec.<locals>.f   s%    99>>%%))!Q66r   r   r   rQ   ry   r   )r4   r;   r   r"   r#   r   r   r%   r&   r'   rb   rc   targetexir_opsedger   r6   r   assertIsInstancerV   tupler   )r,   r-   cntmodulerZ   s        r   test_multiple_returns_spec4TestTorchDispatchFXTracer.test_multiple_returns_spec   s    	7 	7%ell(B"C 	7 LLU[[Aq13T5G5G5IJWYll 	
 LL&&D{{hmm0044888q%%dii&6> ' 	a r   c                     S[         R                  S[        [         R                  [         R                  4   4S jn[         R                  " SSS5      4nU" U6 n[        R
                  " UU[        R                  " 5       5      R                  5       R                  R                  nU" U6 nUR                  R                   H`  nUR                  S:X  d  M  U R                  UR                  S   [        5        U R!                  [#        UR                  S   5      S5        Mb     U R%                  [         R&                  " US	   US	   5      5        U R%                  [         R&                  " US   US   5      5        g )
Nr2   r   c                     X -  nX-   nX4$ r   rN   )r2   abs      r   r-   CTestTorchDispatchFXTracer.test_multiple_returns_pt2_mode.<locals>.f   s    AA4Kr   r   rQ   ry   outputr   r   )r4   r;   r   rm   r"   r#   r   r%   r&   r'   rb   rc   r   r   rV   listr   lenrC   allclose)r,   r-   inputsorig_resr   new_resrZ   s          r   test_multiple_returns_pt2_mode8TestTorchDispatchFXTracer.test_multiple_returns_pt2_mode   s#   	 	%ell(B"C 	
 **Q1%'f:LL""$
 WYll 	 &/LL&&Dww("%%dii&6=  TYYu%5!6: '
 	x{GAJ?@x{GAJ?@r   c                     S[         R                  S[        4S jn[        U[         R                  " S5      4SS[        5       5      u  p#g )Nr2   r   c                 "    U R                  5       $ r   )itemrO   s    r   r-   GTestTorchDispatchFXTracer.test_dynamo_capture_scalar_outputs.<locals>.f   s    668Or   r   Freal)r4   r;   floatr
   rm   r   )r,   r-   gmguardss       r   "test_dynamo_capture_scalar_outputs<TestTorchDispatchFXTracer.test_dynamo_capture_scalar_outputs   sF    	 	% 	 "ZZ]

Fr   )stock_tensor
input_typec           	      d    " S S[         R                  R                  5      n[         R                  " S[         R                  S9nU" 5       n[
        R                  " UU4[
        R                  " SSS95      R                  5       R                  R                  n[        UR                  5        g )Nc                   2   ^  \ rS rSrSU 4S jjrS rSrU =r$ )FTestTorchDispatchFXTracer.test_embedding_dynamic_shape.<locals>.Module   c                 "   > [         TU ]  5         g r   r   r   r,   r   s    r   r   OTestTorchDispatchFXTracer.test_embedding_dynamic_shape.<locals>.Module.__init__   s     "r   c                 
    X-   $ r   rN   r   s     r   rq   NTestTorchDispatchFXTracer.test_embedding_dynamic_shape.<locals>.Module.forward   s	    ur   rN   r   rs   rt   ru   rv   r   rq   rw   r   r   s   @r   r}   r      s    # r   r}   
   dtypeFT)enable_functionalizationenable_dynamic_shape)r4   r|   r}   rm   int64r"   r#   r   r%   r&   r'   printrb   )r,   r   r}   example_inputmr   s         r   test_embedding_dynamic_shape6TestTorchDispatchFXTracer.test_embedding_dynamic_shape   s    	UXX__ 	 

2U[[9HLL ""-2)- WYll 	 	bhhr   c                    S[         R                  S[         R                  4S jn[        R                  " U[         R                  " SS[         R
                  S94[        R                  " SS[        SS	9S
95      R                  [        R                  " SS95      R                  R                  nUR                  R                   H1  nUR                  S;   d  M  U R                  SUR                   5        M3     g )Nr2   r   c                 t    U R                  U R                  S   S-
  S5      n [        R                  " X /5      $ )Nr   r   )viewrn   r4   catrO   s    r   rq   =TestTorchDispatchFXTracer.test_dynamic_shape.<locals>.forward   s/    qwwqzA~r*A99aV$$r   ry   rQ   r   FTassume_static_by_default)r   r   _dynamo_configr   )placeholdercall_functionr   )r4   r;   r"   r#   rm   r   r   r   r%   r   r&   r'   rb   rc   r   assertInrV   )r,   rq   r   rZ   s       r   test_dynamic_shape,TestTorchDispatchFXTracer.test_dynamic_shape   s    	%u|| 	% 	%
 LLAq46""-2)-#3T#R	 WT++uEFll 	 HHNNDww::eTYY/ #r   c           	        ^  " U4S jS[         R                  R                  5      m[        S5         [         R                  " S5      [         R                  " S5      [         R                  " S5      444n[
        R                  " T" 5       U[
        R                  " 5       5      nU R                  [         R                  " T" 5       " U6 U" U6 5      5        S S S 5        g ! , (       d  f       g = f)Nc                      >^  \ rS rSrSUU 4S jjrS\\R                  \\R                  \R                  4   4   S\R                  4S jrSr	U =r
$ )NTestTorchDispatchFXTracer.test_dynamo_frontend_container_input.<locals>.Modulei  r   c                 "   > [         TU ]  5         g r   r   r   s    r   r   WTestTorchDispatchFXTracer.test_dynamo_frontend_container_input.<locals>.Module.__init__	  s    fd,.r   r2   c                     US   nUS   nSnU H  nXER                  5       -  nM     UR                  5       UR                  5       -   $ Nr   r   )sumcosr5   )r,   r2   r   r   cumis         r   rq   VTestTorchDispatchFXTracer.test_dynamo_frontend_container_input.<locals>.Module.forward  sI     aDaDA557NC uuw**r   rN   r   )rs   rt   ru   rv   r   r   r4   r;   rq   rw   r   r   s   @r   r}   r     sK    / /+u||U5<<3M-NNO++ +r   r}   T   )
r4   r|   r}   r   rm   r"   r#   r   rC   r   )r,   inpr   r}   s      @r   $test_dynamo_frontend_container_input>TestTorchDispatchFXTracer.test_dynamo_frontend_container_input  s    	+UXX__ 	+ $JJqMEJJqM5::a=#ABDCfhT-?-?-ABBOOENN68S>2s8DE  s   B%C!!
C/c                 <   S[         R                  S[         R                  4S jn[         R                  " SS5      4n[        R                  " UU5      R                  5       nU R                  U" [         R                  " SS5      5      R                  S   S5        g )Nr2   r   c                 ,    U S U R                   S   S-
   $ r  )rn   rO   s    r   r-   ETestTorchDispatchFXTracer.test_pt2_mode_with_dynamo_config.<locals>.f  s    %qwwqzA~&&r      r   r   ry   )r4   r;   r<   r"   r#   r%   rC   rn   )r,   r-   r  progs       r    test_pt2_mode_with_dynamo_config:TestTorchDispatchFXTracer.test_pt2_mode_with_dynamo_config  s}    	' 	'%,, 	' {{1a "||
 ')	 	
 	U[[A./55a8!<r   c                 
   S[         R                  S[        [         R                     S[        [        [         R                  4   4S jn[         R
                  " SS5      [         R
                  " SS5      [         R
                  " SS5      /4n[         R                  R                  " U/UQ7SSS	.6u  p4[        R                  " X[        R                  " 5       S
9R                  5       nU R                  U" U6 U" U6 5        g )Nr2   rp   r   c                 Z    SU R                  5       [        U5      R                  5       -   0$ )Nr   )r  r2   rp   s     r   r-   >TestTorchDispatchFXTracer.test_input_container_type.<locals>.f)  s"    3q6::</00r   r
  r   Tsymbolic)
aten_graphtracing_mode)config)r4   r;   r   r   strr<   _dynamor~   r"   r#   r   r%   r   )r,   r-   r  r   _r  s         r   test_input_container_type3TestTorchDispatchFXTracer.test_input_container_type(  s    	1 	1$u||"4 	1c5<<>O9P 	1 {{1a 5;;q!#4ekk!Q6G"HI $$QWWJW||A4+=+=+?@HHJsQW-r   c                 J   S[         R                  S[         R                  S[         R                  4S jn[        SS9n[        R                  " SUS9n[        R
                  " U[         R                  " SS	5      [         R                  " SS
5      4U5      R                  R                  nSnUR                  R                   HK  nSUR                  ;   d  M  UR                  S   nUR                   H  n[        U5      (       d  M  SnM     MM     U R                  U5        g )Nr2   rp   r   c                 h    U R                   S   S:  a  U R                  5       $ U R                  5       $ )Nr   ry   )rn   r  r5   r  s     r   fooKTestTorchDispatchFXTracer.test_assume_constant_by_default_prop.<locals>.foo7  s'    wwqzA~uuw557Nr   Tr   )r   r   r
  rQ   ry   Fr   )r4   r;   r   r"   r   r#   rm   r&   r'   rb   rc   rV   rn   r   rC   )	r,   r$  dynamo_configcapture_configcapturedfoundrZ   fake_valr   s	            r   $test_assume_constant_by_default_prop>TestTorchDispatchFXTracer.test_assume_constant_by_default_prop6  s    	5<< 	ELL 	U\\ 	
 )$G++!%m
 <<%**Q"EJJq!$45~


<< 	 NN((D		!99U+#>>C&s++ $ *	 ) 	r   c           	          " S S[         R                  R                  5      n[        R                  " SS9n[        R
                  " U" 5       [         R                  " SS5      4U5      nUR                  R                  n[        5       n[        UR                  5        UR                  R                   H  nU R                  UR                  S:H  5        UR                  S:X  a  UR                  U5        UR                  S	:X  d  MT  UR                   [         R"                  R$                  R                  R&                  :X  d  M  UR(                  u  pxU R+                  U[-        UR.                  R1                  5       5      S
   [-        UR.                  R1                  5       5      S
   15        M     U R+                  [3        U5      S5        UR5                  5         g )Nc                   .   ^  \ rS rSrU 4S jrS rSrU =r$ )@TestTorchDispatchFXTracer.test_aot_config.<locals>.FooWithBufferiO  c                 n   > [         TU ]  5         U R                  S[        R                  " S5      5        g )Nbuffer*   )r   r   register_bufferr4   r   r   s    r   r   ITestTorchDispatchFXTracer.test_aot_config.<locals>.FooWithBuffer.__init__P  s&     "$$Xu{{2?r   c                 X    UR                  5       U R                  R                  5       -   $ r   )r  r1  r  r   s     r   rq   HTestTorchDispatchFXTracer.test_aot_config.<locals>.FooWithBuffer.forwardT      uuw!222r   rN   r   r   s   @r   FooWithBufferr/  O  s    @3 3r   r8  T)
enable_aotr
  rQ   r   r   r   r   )r4   r|   r}   r"   r   r#   rm   r&   r'   setr   rb   rc   assertFalser   r   r   r   r   r;   argsr   r   _input_nodeskeysr   r%   )	r,   r8  r'  captured_epcaptured_gmplaceholder_nodesrZ   arg_0arg_1s	            r   test_aot_config)TestTorchDispatchFXTracer.test_aot_configN  s`   	3EHHOO 	3 ++t<ll=?UZZ15E4GX!22??Ek %%++DTWW
23ww-'!%%d+ww/)dkkUYY^^=O=O=V=V.V#yy  %U//4467:U//4467: , 	./3r   c                     " S S[         R                  R                  5      n[        R                  " U" 5       [         R
                  " SS5      4[        R                  " SSS95      nU R                  [         R                  " U" [         R
                  " SS5      5      U" 5       " [         R
                  " SS5      5      5      5        g )Nc                   .   ^  \ rS rSrU 4S jrS rSrU =r$ )9TestTorchDispatchFXTracer.test_export_unlift.<locals>.Fooip  c                 p   > [         TU ]  5         U R                  S[        R                  " SS5      5        g Nr1  r
  r  r   r   r3  r4   rm   r   s    r   r   BTestTorchDispatchFXTracer.test_export_unlift.<locals>.Foo.__init__q  )     "$$Xuzz!Q/?@r   c                 X    UR                  5       U R                  R                  5       -   $ r   )r  r1  r5   r   s     r   rq   ATestTorchDispatchFXTracer.test_export_unlift.<locals>.Foo.forwardu  r7  r   rN   r   r   s   @r   FoorH  p  s    A3 3r   rP  r
  r  Tr9  _unlift)	r4   r|   r}   r"   r#   rm   r   rC   r   )r,   rP  r   s      r   test_export_unlift,TestTorchDispatchFXTracer.test_export_unlifto  s    	3%((// 	3 \\EZZ1$=
 	r%**Q*:';SU5::aQRCS=TUVr   c           	      b    " S S[         R                  R                  5      n[         R                  " SS5      [         R                  " SS5      44n[        R
                  " U" 5       U4[        SSS95      nU R                  [         R                  " U" U5      U" 5       " U5      5      5        g )Nc                   .   ^  \ rS rSrU 4S jrS rSrU =r$ )WTestTorchDispatchFXTracer.test_export_container_unlift.<locals>.FooContainerInputOutputi  c                 p   > [         TU ]  5         U R                  S[        R                  " SS5      5        g rJ  rK  r   s    r   r   `TestTorchDispatchFXTracer.test_export_container_unlift.<locals>.FooContainerInputOutput.__init__  rM  r   c                     US   S   R                  5       US   S   R                  5       -   U R                  R                  5       -   $ r  r  r5   r1  r   s     r   rq   _TestTorchDispatchFXTracer.test_export_container_unlift.<locals>.FooContainerInputOutput.forward  s9    tAw{{}qtAw{{}4t{{7HHHr   rN   r   r   s   @r   FooContainerInputOutputrW    s    AI Ir   r]  r
  r  TrQ  	r4   r|   r}   rm   r"   r#   r   rC   r   )r,   r]  r  r   s       r   test_export_container_unlift6TestTorchDispatchFXTracer.test_export_container_unlift  s    	Iehhoo 	I 

1a %**Q"235\\#%FT48

 	r#w0G0I#0NOPr   c           	      V    " S S[         R                  R                  5      n[         R                  " SS5      4[         R                  " SS5      44n[        R
                  " U" 5       U[        SSS95      nU R                  [         R                  " U" U6 U" 5       " U6 5      5        g )Nc                   .   ^  \ rS rSrU 4S jrS rSrU =r$ )_TestTorchDispatchFXTracer.test_export_container_input_unlift.<locals>.FooContainerInputOutputV2i  c                 p   > [         TU ]  5         U R                  S[        R                  " SS5      5        g rJ  rK  r   s    r   r   hTestTorchDispatchFXTracer.test_export_container_input_unlift.<locals>.FooContainerInputOutputV2.__init__  rM  r   c                     US   R                  5       US   R                  5       -   U R                  R                  5       -   $ rl   r[  ro   s      r   rq   gTestTorchDispatchFXTracer.test_export_container_input_unlift.<locals>.FooContainerInputOutputV2.forward  s1    txxzAaDHHJ.1BBBr   rN   r   r   s   @r   FooContainerInputOutputV2rc    s    AC Cr   rh  r
  r  TrQ  r^  )r,   rh  r  r   s       r   "test_export_container_input_unlift<TestTorchDispatchFXTracer.test_export_container_input_unlift  s    	C 	C 

1a "UZZ1%5$78\\%'T48

 	r3x1J1Lc1RSTr   c                   ^  " S S[         R                  R                  5      m " U4S jS[         R                  R                  5      n[         R                  " SS5      n[        R
                  " U" 5       U4[        SSS95      nU R                  [         R                  " U" [         R                  " SS5      5      U" 5       " [         R                  " SS5      5      5      5        g )	Nc                   .   ^  \ rS rSrU 4S jrS rSrU =r$ )5TestTorchDispatchFXTracer.test_export_cond.<locals>.Ai  c                 p   > [         TU ]  5         U R                  S[        R                  " SS5      5        g rJ  rK  r   s    r   r   >TestTorchDispatchFXTracer.test_export_cond.<locals>.A.__init__  rM  r   c                 6    U R                   R                  5       $ r   )r1  r  r   s    r   rq   =TestTorchDispatchFXTracer.test_export_cond.<locals>.A.forward      {{((r   rN   r   r   s   @r   Arm        A) )r   rs  c                   2   >^  \ rS rSrUU 4S jrS rSrU =r$ )7TestTorchDispatchFXTracer.test_export_cond.<locals>.Fooi  c                 :   > [         TU ]  5         T" 5       U l        g r   r   r   r   r,   rs  r   s    r   r   @TestTorchDispatchFXTracer.test_export_cond.<locals>.Foo.__init__       "r   c                 R   ^  U 4S jnS n[        UR                  S   S:  X#U/5      $ )Nc                 b   > U R                  5       TR                  5       R                  5       -   $ r   )r  r   r  r2   r,   s    r   true_fnPTestTorchDispatchFXTracer.test_export_cond.<locals>.Foo.forward.<locals>.true_fn  s     557TVVX\\^33r   c                 "    U R                  5       $ r   )r5   rO   s    r   false_fnQTestTorchDispatchFXTracer.test_export_cond.<locals>.Foo.forward.<locals>.false_fn  s    557Nr   r   r  )r   rn   )r,   r2   r  r  s   `   r   rq   ?TestTorchDispatchFXTracer.test_export_cond.<locals>.Foo.forward  s,    4# AGGAJNGsCCr   r   r   r   rs  s   @r   rP  rv    s    D Dr   rP  r
  r  TrQ  r^  )r,   rP  r  r   rs  s       @r   test_export_cond*TestTorchDispatchFXTracer.test_export_cond  s    	) 	)	D%((// 	D jjA\\EFT48

 	r%**Q*:';SU5::aQRCS=TUVr   c           
        ^  " S S[         R                  R                  5      m " U4S jS[         R                  R                  5      n[         R                  " SSS5      n[        R
                  " U" 5       [         R                  " S5      U4[        SSS	95      n[         R                  " SSS5      nU R                  [         R                  " U" [         R                  " S5      U5      U" 5       " [         R                  " S5      U5      5      5        U R                  [         R                  " U" [         R                  " S
5      U5      U" 5       " [         R                  " S
5      U5      5      5        g )Nc                   .   ^  \ rS rSrU 4S jrS rSrU =r$ )9TestTorchDispatchFXTracer.test_export_cond_map.<locals>.Ai  c                 p   > [         TU ]  5         U R                  S[        R                  " SS5      5        g rJ  rK  r   s    r   r   BTestTorchDispatchFXTracer.test_export_cond_map.<locals>.A.__init__  rM  r   c                 6    U R                   R                  5       $ r   )r1  r  r   s    r   rq   ATestTorchDispatchFXTracer.test_export_cond_map.<locals>.A.forward  rr  r   rN   r   r   s   @r   rs  r    rt  r   rs  c                   8   >^  \ rS rSrUU 4S jrS rS rSrU =r$ )>TestTorchDispatchFXTracer.test_export_cond_map.<locals>.Modulei  c                 :   > [         TU ]  5         T" 5       U l        g r   rx  ry  s    r   r   GTestTorchDispatchFXTracer.test_export_cond_map.<locals>.Module.__init__  r{  r   c                 6   ^  U 4S jnU 4S jn[        X#XA/5      $ )Nc                 .   > X -   TR                  5       -   $ r   r  r~  s    r   r  UTestTorchDispatchFXTracer.test_export_cond_map.<locals>.Module.inner.<locals>.true_fn      54668++r   c                 .   > X -  TR                  5       -
  $ r   r  r~  s    r   r  VTestTorchDispatchFXTracer.test_export_cond_map.<locals>.Module.inner.<locals>.false_fn  r  r   )r   )r,   r2   r1   r  r  s   `    r   innerDTestTorchDispatchFXTracer.test_export_cond_map.<locals>.Module.inner  s    ,, D8S99r   c                 (   ^  U 4S jn[        X2U5      $ )Nc                 H   > TR                  X5      TR                  5       -   $ r   )r  r   )r2   r1   r,   s     r   bodyTTestTorchDispatchFXTracer.test_export_cond_map.<locals>.Module.forward.<locals>.body  s    ::a.99r   )r   )r,   r1   xsr  s   `   r   rq   FTestTorchDispatchFXTracer.test_export_cond_map.<locals>.Module.forward  s    : 4T**r   r  )	rs   rt   ru   rv   r   r  rq   rw   r   r  s   @r   r}   r    s    :+ +r   r}   ry   rQ   r   TrQ  F)
r4   r|   r}   r<   r"   r#   tensorr   rC   r   )r,   r}   r  r   inp_testrs  s        @r   test_export_cond_map.TestTorchDispatchFXTracer.test_export_cond_map  s   	) 	)	+UXX__ 	+( kk!Q"\\H\\$%T48
 ;;q!Q'NN5<<%x0d+X6	
 	NN5<<&1e,h7	
r   rN   r   ) rs   rt   ru   rv   classmethodr   r.   r@   rJ   re   r   r   r   r   r   r   r   expandr  r   r   r  r  r   r+  rD  rS  r_  ri  r  r  rw   rN   r   r   r   r      s    , ,U:
=
"O?>! A4

 ,-.s t  /200F*
=.0BW"Q"U"W>0
r   r   )"rG   unittesttypingr   r   r   executorch.exirr"   executorch.exir.tests.modelstestsr    r4   r   executorch.exir.dialects._opsr   r   executorch.exir.tests.commonr	   executorch.exir.tracerr
   r   r   #functorch.experimental.control_flowr   r   r   torch._export.verifierr   %torch.fx.experimental.symbolic_shapesr   torch.testingr   TestCaser   rN   r   r   <module>r     sQ      $ $  - -  ) 9 J O O 9 ' 5 A #S
 1 1 S
r   