
    Vh06                     b   d dl Z d dlZd dlZd dlmZ d dlmZmZ d dlm	Z	 d dl
mZ d dlmZmZ d dlmZmZmZ d dlmZ d d	lmZmZ d
 Zd Zd Zd Zd Zg dZej<                  j?                  ddej@                  jB                         ej<                  jE                  dd      d        Z#ej<                  jE                  dd      d        Z$ej<                  jK                  d      d        Z&d Z'd Z(d Z)ed        Z*d Z+d Z,d Z-d Z.d  Z/d! Z0d" Z1d# Z2 e       Z3d$ Z4d% Z5 ed&d'e2e1 eejl                  ejn                        d(d(d(d(d(d(d()       ed*d'e+e) eejl                  ejn                        d(d(d(d(d(d+d()       ed,d'ee eejl                  ejn                        d(d(d(d(d(-
       ed,d.ee eejl                  ejn                        d(d(d(d(d(-
       ed,d/ee eejl                  ejn                        d(d(d(d(d(-
       ed0d'e(e' eejl                  ejn                        d(d(d(d(d(d+d()       ed1d'e4e) eejl                  ejn                        d(d(d(d(d(d+ eejp                  d2d3       eejp                  d2d4       eejp                  d2d5       eejp                  d2d6      fd(7       ed8d'e5e) eejl                  ejn                        d(d(d(d(d(d+d()       ed9d'e0e/ eejl                  ejn                        d(d(d(d(d(d(:       ed;d'e-e, eejl                  ejn                        d(d(d(d(d(d(:       ed<d'ee. eejr                  ejt                        d(d(d(d(d( eejp                  d2d3       eejp                  d2d4       eejp                  d2d5       eejp                  d2d6      feg=       ed>d'ee. eejr                  ejt                        d(d(d(d(d( eejp                  d2d3       eejp                  d2d4       eejp                  d2d5       eejp                  d2d6      feg=      gZ;y)?    Nmap)_create_empty_block_maskflex_attention)make_tensor)onlyCUDA)all_types_andcustom_types)DecorateInfoOpInfoSampleInput)mark_compile_region)InvokeQuantinvoke_quant_packedc           
   +      K   t        j                  t        |||      }t         |ddddd       |ddddd      g |ddd       |ddd      f       y w)Ndevicedtyperequires_grad   皙?lowhigh   )args	functoolspartialr   r   opinfor   r   r   kwargsmake_args         N/home/dcms/DCMS/lib/python3.12/site-packages/torch/testing/_internal/hop_db.pysample_inputs_mapr%      sj       F%}H 	!Qs	+XaA3Q-OPqc*HQCa,HI s   AAc                     | d   j                         j                  d      |z  | d   |j                         z   j                         j	                  | d   j                               gS )Nr   g      ?r   )cosadd_sincos_viewsizexy0y1s      r$   inner_fr1      sQ    aDHHJOOC 2%!rvvx'='='?'D'DQqTYY['QRR    c                 $    d }t        || ||      S )Nc                     t        | ||      S Nr1   r-   s      r$   fzsimple_map.<locals>.f    s    q"b!!r2   r   )xsr/   r0   r7   s       r$   
simple_mapr9      s    " q"b"r2   c                 $    d }t        || ||      S )Nc                 $    d }t        || ||      S )Nc                     t        | ||      S r5   r6   r-   s      r$   f2z"nested_map.<locals>.f1.<locals>.f2(   s    1b"%%r2   r   xxr/   r0   r=   s       r$   f1znested_map.<locals>.f1'   s    	& 2r2r""r2   r   r8   r/   r0   r@   s       r$   
nested_maprB   &   s    # r2r2r2   c                 $    d }t        || ||      S )Nc                 $    d }t        || ||      S )Nc                 $    d }t        || ||      S )Nc                     t        | ||      S r5   r6   r-   s      r$   r=   z5triple_nested_map.<locals>.f0.<locals>.f1.<locals>.f23   s    q"b))r2   r   r>   s       r$   r@   z)triple_nested_map.<locals>.f0.<locals>.f12   s    * r2r2&&r2   r   rA   s       r$   f0ztriple_nested_map.<locals>.f01   s    	' 2r2r""r2   r   )r8   r/   r0   rG   s       r$   triple_nested_maprH   0   s    # r2r2r2   )custom_function_callautograd_function_applyrun_and_save_rng_staterun_with_rng_stategraphsafe_run_with_rng_state	out_dtypetrace_wrappedtag_activation_checkpointexecutorch_call_delegatewrapwrap_with_set_grad_enabledauto_functionalized_v2associative_scan
flat_applywrap_with_autocastwrap_activation_checkpointrun_const_graphauto_functionalizedr   map_implwith_effectsstrict_mode_export_tracepointcall_torchbindtriton_kernel_wrapper_mutation triton_kernel_wrapper_functionalhints_wrapperforeach_mapaoti_call_delegateztestlib::mutating_custom_opz8(Tensor(a!) x, Tensor(b!) z) -> (Tensor, Tensor, Tensor))tagscpuc                 V    | j                  d       |j                  d       | || |z   fS N   r(   r.   zs     r$   foo_impl_cpurm   r   (    FF1IFF1IaQ;r2   cudac                 V    | j                  d       |j                  d       | || |z   fS rh   rj   rk   s     r$   foo_impl_cudarq   y   rn   r2   c                     | || |z   fS r5    rk   s     r$   foo_impl_abstractrt      s    aQ;r2   c           	   +   v   K   t        j                  t        |||      }t         |ddddd             y wNr   r   r   r   r   r    s         r$   sample_inputs_condrw      9       F%}H hq!QCa8
99   79c                 Z    t        j                  | j                         dkD  d d | g      S )Nr   c                 $    | j                         fS r5   r'   r.   s    r$   <lambda>zsimple_cond.<locals>.<lambda>   s    aeegZ r2   c                 $    | j                         fS r5   )r)   r}   s    r$   r~   zsimple_cond.<locals>.<lambda>   s    AEEG: r2   )torchcondsumr}   s    r$   simple_condr      s&    ::aeegk#79MPQsSSr2   c           	   +   v   K   t        j                  t        |||      }t         |ddddd             y wrv   r   r    s         r$   sample_inputs_invoke_subgraphr      rx   ry   c                 ,    t        j                  |       S r5   r   r)   r}   s    r$   fn_for_invoke_subgraphr      s    99Q<r2   c                     t        |       S r5   )r   r}   s    r$   simple_invoke_subgraphr      s    !!$$r2   c           
   +      K   t        j                  t        ||d      }t         |ddddd       |ddddd             y w)NFr   r   r   r   r   r    s         r$    sample_inputs_auto_functionalizer      sM       F%uH Aqc*HQ1#A,N s   AAc                 V    t         j                  j                  j                  | |      S r5   )r   opstestlibmutating_custom_oprk   s     r$   simple_auto_functionalizer      s    99//155r2   c              +      
K   t        j                  t        |||      
d }
fdt        d      D        \  }}}t	        ||      }	t        |||||	       y w)Nr   c                     | |z   S r5   rs   )scorebhmns        r$   	score_modz/sample_inputs_flex_attention.<locals>.score_mod   s    qyr2   c           	   3   :   K   | ]  } d d dddd         yw)r         r   r   Nrs   ).0_r#   s     r$   	<genexpr>z/sample_inputs_flex_attention.<locals>.<genexpr>   s#     I1x1c1#A66Is      )r   r   r   ranger   r   )r!   r   r   r   r"   r   qkv
block_maskr#   s             @r$   sample_inputs_flex_attentionr      s[       F%}H JaIGAq!)!Q/J
aAy*
55s   AAc           
   +      K   t        j                  t        ||d      }t        t	        j
                  d       |ddddd             y w)NFr   r   r      r   r   )r   r   r   r   r   tensorr    s         r$   sample_inputs_while_loopr      sI       F%uH QAqc* s   AAc                 T    d }d }t         j                  j                  ||| |f      S )Nc                     | dkD  S )Nr   rs   iter_tr.   s     r$   cond_fnz"simple_while_loop.<locals>.cond_fn   s    zr2   c                 ,    | dz
  |j                         fS )Nr   r|   r   s     r$   body_fnz"simple_while_loop.<locals>.body_fn   s    z1557""r2   )r   _higher_order_ops
while_loop)r   r.   r   r   s       r$   simple_while_loopr      s-    # ""--gwLLr2   c           
   +      K   t        j                  t        |||      }t         |dddd       |ddddd             y wrv   r   r    s         r$   sample_inputs_scanr      sL       F%}H A3Q'Aqc* s   AAc                 J    d }t         j                  j                  || |      S )Nc                 6    | |z  |z   }|| j                         fS r5   )clone)carryr.   results      r$   
combine_fnzsimple_scan.<locals>.combine_fn   s     Qu{{}$$r2   )r   r   scan)initr8   r   s      r$   simple_scanr      s$    % ""''
D"==r2   c                 .    d }t        || |       d   dz  S )Nc                 4    t        j                  |       |z  fS r5   r   )r.   ys     r$   fnzsimple_invoke_quant.<locals>.fn   s    		!q ""r2   r          @)quant_tracerr.   r   s     r$   simple_invoke_quantr      s"    # Aq!!$r))r2   c                 ,    d }t        ||       d   dz  S )Nc                 .    t        j                  |       fS r5   r   r}   s    r$   r   z&simple_invoke_quant_packed.<locals>.fn   s    		!r2   r   r   )r   r   s     r$   simple_invoke_quant_packedr      s      r1%a(2--r2   r   simpleF)namevariant_test_nameopsample_inputs_funcdtypessupports_outcheck_batched_gradcheck_batched_gradgradcheck_batched_forward_grad"check_inplace_batched_forward_gradsupports_autogradsupports_gradgradinvoke_subgraphTr   )
r   r   r   r   r   r   r   r   r   r   nestedtriple_nestedr   invoke_quantTestHOPtest_aot_exporttest_pre_dispatch_exporttest_serialize_exporttest_retrace_export)r   r   r   r   r   r   r   r   r   r   r   skipsr   r   r   )r   r   r   r   r   r   r   r   r   r   r   auto_functionalizer   )r   r   r   r   r   r   r   r   r   r   r   
decoratorsflex_attention_backward)<r   unittestr   #functorch.experimental.control_flowr   !torch.nn.attention.flex_attentionr   r   torch.testingr   *torch.testing._internal.common_device_typer   $torch.testing._internal.common_dtyper	   r
   #torch.testing._internal.opinfo.corer   r   r   'torch._higher_order_ops.invoke_subgraphr   torch._higher_order_opsr   r   r%   r1   r9   rB   rH   0FIXME_hop_that_doesnt_have_opinfo_test_allowlistlibrarydefineTagpt2_compliant_tagimplrm   rq   register_fakert   rw   r   r   r   r   r   r   r   r   r   r   r   r   r   r   boolhalfexpectedFailurefloat16float32hop_dbrs   r2   r$   <module>r      s      3 V % ? L Q Q G DS
64 0@   !>		$	$   159 : 16: ; :; <:T:  %6
6M> }*. "-UZZ4 $#(+0 "!8UZZ4 $#(+0 ",UZZ4 $#(+0 ",UZZ4 $#(+0 ),UZZ4 $#(+0 "-UZZ4 $#(+0 "8UZZ4 $#(+0 119>OP(()5O 119>UV119>ST
  -0 ""%8UZZ4 $#(+0 "3UZZ4 $#(+0 !"$;UZZ4 $#(+0 "7EMM5==9 $#(+0119>OP(()5O 119>UV119>ST
 :'* &"7EMM5==9 $#(+0119>OP(()5O 119>UV119>ST
 :'Q}
r2   