o
    wZh06                     @   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"   M/var/www/auris/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_sinZ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-   r3   r"   r"   r#   
simple_map      r6   c                 C   r/   )Nc                 S   r/   )Nc                 S   r0   r1   r2   r*   r"   r"   r#   f2(   r4   z"nested_map.<locals>.f1.<locals>.f2r   xxr,   r-   r8   r"   r"   r#   f1'   r7   znested_map.<locals>.f1r   r5   r,   r-   r;   r"   r"   r#   
nested_map&      r=   c                 C   r/   )Nc                 S   r/   )Nc                 S   r/   )Nc                 S   r0   r1   r2   r*   r"   r"   r#   r8   3   r4   z5triple_nested_map.<locals>.f0.<locals>.f1.<locals>.f2r   r9   r"   r"   r#   r;   2   r7   z)triple_nested_map.<locals>.f0.<locals>.f1r   r<   r"   r"   r#   f01   r>   ztriple_nested_map.<locals>.f0r   )r5   r,   r-   r?   r"   r"   r#   triple_nested_map0   s   	r@   )Zcustom_function_callZautograd_function_applyZrun_and_save_rng_stateZrun_with_rng_stateZgraphsafe_run_with_rng_stateZ	out_dtypeZtrace_wrappedZtag_activation_checkpointZexecutorch_call_delegatewrapZwrap_with_set_grad_enabledZauto_functionalized_v2Zassociative_scanZ
flat_applyZwrap_with_autocastZwrap_activation_checkpointZrun_const_graphZauto_functionalizedr   Zmap_implZwith_effectsZstrict_modeZ_export_tracepointZcall_torchbindZtriton_kernel_wrapper_mutationZ triton_kernel_wrapper_functionalZhints_wrapperZforeach_mapZ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      

rJ   cudac                 C   rD   rE   rG   rH   r"   r"   r#   foo_impl_cuday   rK   rM   c                 C   s   | || | fS r1   r"   rH   r"   r"   r#   foo_impl_abstract   s   rN   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   
   rQ   c                 C   s"   t |  dkdd dd | gS )Nr   c                 S   
   |   fS r1   r%   r+   r"   r"   r#   <lambda>      
 zsimple_cond.<locals>.<lambda>c                 S   rS   r1   )r'   rU   r"   r"   r#   rV      rW   )torchcondsumrU   r"   r"   r#   simple_cond   s   "r[   c                 k   rO   rP   r   r   r"   r"   r#   sample_inputs_invoke_subgraph   rR   r\   c                 C   s
   t | S r1   rX   r'   rU   r"   r"   r#   fn_for_invoke_subgraph   s   
r^   c                 C   s   t | S r1   )r^   rU   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    
ra   c                 C   s   t jj| |S r1   )rX   opsZtestlibZmutating_custom_oprH   r"   r"   r#   simple_auto_functionalize      rc   c           
      +   sX    t jt|||d dd } fddtdD \}}}t||}	t|||||	V  d S )Nr   c                 S   s   | | S r1   r"   )Z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    ri   qkvZ
block_maskr"   rn   r#   sample_inputs_flex_attention   s   
ru   c              	   k   s8    t jt||dd}ttd|ddddddV  d S )NFr   rp   r      r   r   )r   r   r   r   rX   Ztensorr   r"   r"   r#   sample_inputs_while_loop   s   
rw   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   rT   rx   r"   r"   r#   body_fn   rd   z"simple_while_loop.<locals>.body_fn)rX   _higher_order_ops
while_loop)ry   r+   rz   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 rP   r   r   r"   r"   r#   sample_inputs_scan   s   
r   c                 C   s   dd }t j|| |S )Nc                 S   s   | | | }||   fS r1   )clone)Zcarryr+   resultr"   r"   r#   
combine_fn   s   zsimple_scan.<locals>.combine_fn)rX   r|   scan)initr5   r   r"   r"   r#   simple_scan   s   r   c                 C   s   dd }t || | d d S )Nc                 S   s   t | | fS r1   r]   )r+   yr"   r"   r#   fn   rd   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 r1   r]   rU   r"   r"   r#   r      r4   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_gradgradZinvoke_subgraphTr   )
r   r   r   r   r   r   r   r   r   r   nestedZtriple_nestedrY   Zinvoke_quantZTestHOPZtest_aot_exportZtest_pre_dispatch_exportZtest_serialize_exportZ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   Zauto_functionalizer   )r   r   r   r   r   r   r   r   r   r   r   Z
decoratorsZflex_attention_backward)<r   ZunittestrX   Z#functorch.experimental.control_flowr   Z!torch.nn.attention.flex_attentionr   r   Ztorch.testingr   Z*torch.testing._internal.common_device_typer   Z$torch.testing._internal.common_dtyper   r	   Z#torch.testing._internal.opinfo.corer
   r   r   Z'torch._higher_order_ops.invoke_subgraphr   Ztorch._higher_order_opsr   r   r$   r.   r6   r=   r@   Z0FIXME_hop_that_doesnt_have_opinfo_test_allowlistZlibraryZdefineTagZpt2_compliant_tagimplrJ   rM   Zregister_fakerN   rQ   r[   r\   r^   r_   ra   rc   ru   rw   r~   r   r   r   r   r   boolZhalfZexpectedFailureZfloat16Zfloat32Zhop_dbr"   r"   r"   r#   <module>   s  

 




	


			 