o
    0h06                     @   s  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
d Zdd Zdd Zdd Zdd Zg dZejjddej j!d ej"dddd Z#ej"dddd Z$ej%ddd Z&d d! Z'd"d# Z(d$d% Z)ed&d' Z*d(d) Z+d*d+ Z,d,d- Z-d.d/ Z.d0d1 Z/d2d3 Z0d4d5 Z1d6d7 Z2e Z3d8d9 Z4d:d; Z5ed<d=e2e1eej6ej7d>d>d>d>d>d>d>d?ed@d=e+e)eej6ej7d>d>d>d>d>dAd>d?edBd=eeeej6ej7d>d>d>d>d>dC
edBdDeeeej6ej7d>d>d>d>d>dC
edBdEeeeej6ej7d>d>d>d>d>dC
edFd=e(e'eej6ej7d>d>d>d>d>dAd>d?edGd=e4e)eej6ej7d>d>d>d>d>dAeej8dHdIeej8dHdJeej8dHdKeej8dHdLfd>dMedNd=e5e)eej6ej7d>d>d>d>d>dAd>d?edOd=e0e/eej6ej7d>d>d>d>d>d>dPedQd=e-e,eej6ej7d>d>d>d>d>d>dPedRd=ee.eej9ej:d>d>d>d>d>eej8dHdIeej8dHdJeej8dHdKeej8dHdLfegdSedTd=ee.eej9ej:d>d>d>d>d>eej8dHdIeej8dHdJeej8dHdKeej8dHdLfegdSgZ;dS )U    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   s^    t jt|||d}t|dddddd|ddddddg|dddd|ddddfdV  d S )Ndevicedtyperequires_grad   皙?lowhigh   )args	functoolspartialr   r   opinfor   r   r   kwargsmake_arg r"   R/var/www/vscode/kcb/lib/python3.10/site-packages/torch/testing/_internal/hop_db.pysample_inputs_map   s   "r$   c                 C   s8   | d   d| | d |   | d  gS )Nr   g      ?r   )cosadd_sincos_viewsizexy0y1r"   r"   r#   inner_f   s   8r/   c                 C      dd }t || ||S )Nc                 S      t | ||S Nr/   r+   r"   r"   r#   f       zsimple_map.<locals>.fr   )xsr-   r.   r4   r"   r"   r#   
simple_map      r7   c                 C   r0   )Nc                 S   r0   )Nc                 S   r1   r2   r3   r+   r"   r"   r#   f2(   r5   z"nested_map.<locals>.f1.<locals>.f2r   xxr-   r.   r9   r"   r"   r#   f1'   r8   znested_map.<locals>.f1r   r6   r-   r.   r<   r"   r"   r#   
nested_map&      r>   c                 C   r0   )Nc                 S   r0   )Nc                 S   r0   )Nc                 S   r1   r2   r3   r+   r"   r"   r#   r9   3   r5   z5triple_nested_map.<locals>.f0.<locals>.f1.<locals>.f2r   r:   r"   r"   r#   r<   2   r8   z)triple_nested_map.<locals>.f0.<locals>.f1r   r=   r"   r"   r#   f01   r?   ztriple_nested_map.<locals>.f0r   )r6   r-   r.   r@   r"   r"   r#   triple_nested_map0   s   	rA   )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                 C   "   |  d | d | || | fS N   r&   r,   zr"   r"   r#   foo_impl_cpur      

rf   cudac                 C   r`   ra   rc   rd   r"   r"   r#   foo_impl_cuday   rg   ri   c                 C   s   | || | fS r2   r"   rd   r"   r"   r#   foo_impl_abstract   s   rj   c                 k   0    t jt|||d}t|ddddddV  d S Nr   r   r   r   r   r   r"   r"   r#   sample_inputs_cond   
   rm   c                 C   s"   t |  dkdd dd | gS )Nr   c                 S   
   |   fS r2   r%   r,   r"   r"   r#   <lambda>      
 zsimple_cond.<locals>.<lambda>c                 S   ro   r2   )r'   rq   r"   r"   r#   rr      rs   )torchcondsumrq   r"   r"   r#   simple_cond   s   "rw   c                 k   rk   rl   r   r   r"   r"   r#   sample_inputs_invoke_subgraph   rn   rx   c                 C   s
   t | S r2   rt   r'   rq   r"   r"   r#   fn_for_invoke_subgraph   s   
rz   c                 C   s   t | S r2   )rz   rq   r"   r"   r#   simple_invoke_subgraph      r{   c              	   k   s@    t jt||dd}t|dddddd|ddddddV  d S )NFr   r   r   r   r   r   r"   r"   r#    sample_inputs_auto_functionalize   s    
r}   c                 C   s   t jj| |S r2   )rt   opstestlibmutating_custom_oprd   r"   r"   r#   simple_auto_functionalize      r   c           
      +   sX    t jt|||d dd } fddtdD \}}}t||}	t|||||	V  d S )Nr   c                 S   s   | | S r2   r"   )scorebhmnr"   r"   r#   	score_mod   r|   z/sample_inputs_flex_attention.<locals>.score_modc              	   3   s$    | ]} d d dddd dV  qdS )r         r   r   Nr"   ).0_r!   r"   r#   	<genexpr>   s   " z/sample_inputs_flex_attention.<locals>.<genexpr>   )r   r   r   ranger   r   )
r   r   r   r   r    r   qkv
block_maskr"   r   r#   sample_inputs_flex_attention   s   
r   c              	   k   s8    t jt||dd}ttd|ddddddV  d S )NFr   r   r      r   r   )r   r   r   r   rt   tensorr   r"   r"   r#   sample_inputs_while_loop   s   
r   c                 C   s$   dd }dd }t j||| |fS )Nc                 S   s   | dkS )Nr   r"   iter_tr,   r"   r"   r#   cond_fn   r|   z"simple_while_loop.<locals>.cond_fnc                 S   s   | d |  fS )Nr   rp   r   r"   r"   r#   body_fn   r   z"simple_while_loop.<locals>.body_fn)rt   _higher_order_ops
while_loop)r   r,   r   r   r"   r"   r#   simple_while_loop   s   r   c              	   k   s>    t jt|||d}t|ddddd|ddddddV  d S rl   r   r   r"   r"   r#   sample_inputs_scan   s   
r   c                 C   s   dd }t j|| |S )Nc                 S   s   | | | }||   fS r2   )clone)carryr,   resultr"   r"   r#   
combine_fn   s   zsimple_scan.<locals>.combine_fn)rt   r   scan)initr6   r   r"   r"   r#   simple_scan   s   r   c                 C   s   dd }t || | d d S )Nc                 S   s   t | | fS r2   ry   )r,   yr"   r"   r#   fn   r   zsimple_invoke_quant.<locals>.fnr          @)quant_tracerr,   r   r"   r"   r#   simple_invoke_quant   s   r   c                 C   s   dd }t || d d S )Nc                 S   s   t | fS r2   ry   rq   r"   r"   r#   r      r5   z&simple_invoke_quant_packed.<locals>.fnr   r   )r   r   r"   r"   r#   simple_invoke_quant_packed   s   r   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_nestedru   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   unittestrt   #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$   r/   r7   r>   rA   0FIXME_hop_that_doesnt_have_opinfo_test_allowlistlibrarydefineTagpt2_compliant_tagimplrf   ri   register_fakerj   rm   rw   rx   rz   r{   r}   r   r   r   r   r   r   r   r   r   boolhalfexpectedFailurefloat16float32hop_dbr"   r"   r"   r#   <module>   s  

 




	


			 