
    Vh                     v    d dl Z d dlmZ d dlmZ d dlmc mZ e j                  j                  dfdZd Zd Zy)    N)make_fxwrapper_set_seedFc                     t        | ||      ^}}d } t        ||      | }	d}
|rt        |      }	  ||g| } ||	g| } ||||
       y # t        $ r |rY y  w xY w)Nc                      t        | g|i |S Nr   )fargskwargss      W/home/dcms/DCMS/lib/python3.12/site-packages/torch/testing/_internal/optests/make_fx.pyrunzmake_fx_check.<locals>.run   s    3D3F33    )tracing_modea   op(*args, **kwargs) and make_fx(op)(*args, **kwargs) produced different values. This could mean that your abstract impls (meta/FakeTensor impls) are incorrect, that your operator is not completely traceable (e.g., it relies on some global state), or that there is a bug in make_fx. Note that if you passed a python function (and not an operator) to make_fx_check, it is still possible that the python function will still work with torch.compile because it handles capturing pieces of your python code to compile.)msg)handle_sizes_for_dynamic_shapesr   	randomize	Exception)funcr
   r   r   assert_closerandomize_datar	   new_argsr   traced_fr   expectedresults                r   make_fx_checkr   	   s     34vFLA4 5wq|4h?H	'   X&q$8$
 %H%Fs+  s   	A A A c                 j     fd}g }i }t        |      D ]H  \  }}t        |t        j                        s!|j	                  |t        j
                  |d      f       J |j                         D ]:  \  }}	t        |	t        j                        s!t        j
                  |	d      ||<   < |||||fS )Nc                     |r|D ]  \  }}|j                         | |<    |r+|j                         D ]  \  }}|j                         ||<     | i |S r   )sizeitems)r
   r   
extra_argsextra_kwargsitkr   s          r   r	   z*handle_sizes_for_dynamic_shapes.<locals>.f>   sh    " #1&&(Q#$**, %1FFHq	% T$V$$r   cpu)device)	enumerate
isinstancetorchSizeappendemptyr   )
r   r
   r   r	   r    r!   r"   argkeyvalues
   `         r   r   r   =   s    % JLD/ C3c5::&q%++c%"@ABC lln A
UeUZZ( %E% @LA dFJ44r   c                 R    d }t        j                  t        j                  ||       S )Nc                     | j                   j                  s| S | j                         j                         j	                  dd      j                  | j                        S )Nr      )dtypeis_floating_pointdetachcloneuniform_requires_grad_requires_grad)xs    r   	transformzrandomize.<locals>.transformU   sE    ww((Hxxz!**1a0??PPr   )pytreetree_map_onlyr)   Tensor)r
   r;   s     r   r   r   T   s#    Q i>>r   )r)   "torch.fx.experimental.proxy_tensorr   torch.testing._utilsr   torch.utils._pytreeutils_pytreer<   testingr   r   r   r    r   r   <module>rF      s8     6 1 $ $ ++(,h5.?r   