U
    Mh[                      @   s  d dl Z d dlZd dlmZ d dlZd dlmZ d dlmZm	Z	 d dl
mZmZ d dlmZ d dlmZ dd	 Zd
d Zdd Zdd Zdd Zddddddddddddg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!d/d0 Z"d1d2 Z#d3d4 Z$d5d6 Z%edd7eeee j&e j'd8d8d8d8d8d9
edd:eeee j&e j'd8d8d8d8d8d9
edd;eeee j&e j'd8d8d8d8d8d9
ed<d7e eee j&e j'd8d8d8d8d8d8d=ed>d7e%e$ee j&e j'd8d8d8d8d8d8d=ed?d7e"e!ee j&e j'd8d8d8d8d8d8d=ed@d7ee#ee j(e j)d8d8d8d8d8eej*dAdBeej*dAdCeej*dAdDeej*dAdEfdFedGd7ee#ee j(e j)d8d8d8d8d8eej*dAdBeej*dAdCeej*dAdDeej*dAdEfdFgZ+dS )H    N)make_tensormap)OpInfoSampleInput)all_types_andcustom_types)DecorateInfo)_flex_attentionc              	   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   P/var/www/html/venv/lib/python3.8/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    r)   c                 C   s   dd }t || ||S )Nc                 S   s   t | ||S Nr)   r%   r   r   r   f   s    zsimple_map.<locals>.fr   )xsr'   r(   r,   r   r   r   
simple_map   s    r.   c                 C   s   dd }t || ||S )Nc                 S   s   dd }t || ||S )Nc                 S   s   t | ||S r*   r+   r%   r   r   r   f2    s    z"nested_map.<locals>.f1.<locals>.f2r   Zxxr'   r(   r/   r   r   r   f1   s    znested_map.<locals>.f1r   r-   r'   r(   r1   r   r   r   
nested_map   s    r3   c                 C   s   dd }t || ||S )Nc                 S   s   dd }t || ||S )Nc                 S   s   dd }t || ||S )Nc                 S   s   t | ||S r*   r+   r%   r   r   r   r/   (   s    z5triple_nested_map.<locals>.f0.<locals>.f1.<locals>.f2r   r0   r   r   r   r1   '   s    z)triple_nested_map.<locals>.f0.<locals>.f1r   r2   r   r   r   f0&   s    ztriple_nested_map.<locals>.f0r   )r-   r'   r(   r4   r   r   r   triple_nested_map%   s    r5   Zcustom_function_callZautograd_function_applyZrun_and_save_rng_stateZrun_with_rng_stateZ	out_dtypeZtrace_wrappedr   Zmap_implZwith_effectsZstrict_modeZ_export_tracepointZcall_torchbindztestlib::mutating_custom_opz8(Tensor(a!) x, Tensor(b!) z) -> (Tensor, Tensor, Tensor))tagscpuc                 C   s"   |  d | d | || | fS N   r!   r&   zr   r   r   foo_impl_cpuG   s    

r=   cudac                 C   s"   |  d | d | || | fS r8   r:   r;   r   r   r   foo_impl_cudaN   s    

r?   c                 C   s   | || | fS r*   r   r;   r   r   r   foo_impl_abstractU   s    r@   c                 k   s.   t jt||dd}t|ddddddV  d S NFr   r   r   r   r   r   r   r   r   sample_inputs_condZ   s       rB   c                 C   s$   t | jd dkdd dd | gS )Nr   r   c                 S   s   |   S r*   r    r&   r   r   r   <lambda>b       zsimple_cond.<locals>.<lambda>c                 S   s   |   S r*   )r"   rD   r   r   r   rE   b   rF   )torchcondshaperD   r   r   r   simple_conda   s    rJ   c              	   k   s>   t jt||dd}t|dddddd|ddddddV  d S rA   r   r   r   r   r    sample_inputs_auto_functionalizee   s       rK   c                 C   s   t jj| |S r*   )rG   ZopsZtestlibZmutating_custom_opr;   r   r   r   simple_auto_functionalizel   s    rL   c                 k   s^   t jt|||d}dd }t|ddddddd|ddddddd|ddddddd|V  d S )	Nr   c                 S   s   | | S r*   r   )Zscorebhmnr   r   r   	score_modu   s    z/sample_inputs_flex_attention.<locals>.score_modr         r   r   r   )r   r   r   r   r   r   rQ   r   r   r   sample_inputs_flex_attentionp   s       rT   c              	   k   s6   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   rG   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   s    z"simple_while_loop.<locals>.cond_fnc                 S   s   | d |  fS )Nr   rC   rX   r   r   r   body_fn   s    z"simple_while_loop.<locals>.body_fn)rG   Z_higher_order_ops
while_loop)rY   r&   rZ   r[   r   r   r   simple_while_loop   s    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nestedZtriple_nestedrH   )r_   r`   ra   rb   rc   rd   re   rf   rg   rh   Zsupports_autogradr\   Zauto_functionalizeZflex_attentionZTestHOPZtest_aot_exportZtest_pre_dispatch_exportZtest_serialize_exportZtest_retrace_export)r_   r`   ra   rb   rc   rd   re   rf   rg   rh   skipsZflex_attention_backward),rG   r   Ztorch.testingr   ZunittestZ#functorch.experimental.control_flowr   Z#torch.testing._internal.opinfo.corer   r   Z$torch.testing._internal.common_dtyper   r   r	   Z"torch.nn.attention._flex_attentionr
   r   r)   r.   r3   r5   Z*hop_that_doesnt_have_opinfo_test_allowlistlibrarydefineTagZpt2_compliant_tagimplr=   r?   Zregister_faker@   rB   rJ   rK   rL   rT   rW   r]   boolZhalfZfloat16Zfloat32ZexpectedFailureZhop_dbr   r   r   r   <module>   s4  



	