
    Ph                     2   d dl mZ d dlmZ d dlmZ d dlZd dlmZ d dl	m
Z
 d dlmZ d dlmZ d d	lmZ  ed
ddg      Z edg d      Zej(                  j*                  Zej(                  j.                  Zej(                  j2                  Z G d de      Zy)    )
namedtuple)deepcopy)combinationsN)normalize_function)clone_inputs)_pytree)TorchDispatchMode)tree_mapMutationop_namearg_nameAliasing)r   r   output_numberc                   &    e Zd Zd Zd Zd ZddZy)SchemaCheckModec                 .    g | _         g | _        g | _        y N)opsmutatedaliasingselfs    nC:\Users\daisl\Desktop\realtime-object-detection\venv\Lib\site-packages\torch/_subclasses/schema_check_mode.py__init__zSchemaCheckMode.__init__   s         c                     | j                   j                          | j                  j                          | j                  j                          y r   )r   clearr   r   r   s    r   reset_cachezSchemaCheckMode.reset_cache%   s0    r   c                 .    t        | j                  ddi y )Nsep,)printr   r   s    r   display_opszSchemaCheckMode.display_ops*   s    txx!S!r   Nc                 F
   d fdd }d }d }d }| j                   j                  |j                  j                         t	        |||d      j
                  }	t        t        |	j                         t        |	j                                           }
|
D ci c]  }|t        ||
j                  |              }}|	D ci c];  }|t        j                  |	j                  |            D cg c]
  } ||       c}= }}} ||i |}|	D ci c]  }|t        ||	j                  |              }}t        |t               r|n|f}t        ||      }t#        |j                        }|j%                  |	       t'        t)        |j                  j*                              D ]  }|j                  j*                  |   } ||j                        }|j                  |      A|j                  |      }|j                  |      }|j                  |      }t'        t)        |            D ]}  }d	} |||   |      r|j                  j                  |vr|j-                  t/        t0        j2                  |      t/        t0        j4                  |            st7        d
| d      | j8                  j                  t;        |j                  j                  |d|              |||   u st        |t<        j>                        s|jA                  t/        t0        j4                  |            r|t<        j                   jB                  jD                  jF                  t<        j                   jB                  jH                  jF                  fvsft7        dtK        |       d|        tM        fdt        t        j                  |      t        j                  |      |      D              sP|jA                  t/        t0        j4                  |            st7        d
| d      | jN                  j                  tQ        |j                  j                  |              tS        t'        t)        |j                  jT                              d      D ]i  \  }} |||   ||         s|j-                  t/        t0        j2                  |      t/        t0        j2                  |            rYt7        d| d| d       |S c c}w c c}w c c}}w c c}w )Nc                 v    | j                   rt        j                  | |      S t        j                  | |d      S )NT)	equal_nan)is_quantizedtorchequalallclose)lhsrhss     r   bitwise_equalz9SchemaCheckMode.__torch_dispatch__.<locals>.bitwise_equal.   s1     {{3,,~~c3$??r   c                    t        |       t        j                  k(  xr t        |      t        j                  k(  }|r| j                  t        j                  k7  r|j                  t        j                  k7  rg| j                         |j                         k(  xrC  | |      xr8 |d   |j                         k(  xr  |d   |j                         j                  k(   S y)Nr      F)	typer(   Tensorlayout
sparse_csrsizestride_typed_storage_cdata)beforeaftermdare_tensorsr-   s       r   has_mutatedz7SchemaCheckMode.__torch_dispatch__.<locals>.has_mutated6   s    v,%,,6V4;%,,;VKMMU%5%55LLE$4$44 KKMUZZ\1 ?%fe4?1/? 1!5!5!7!>!>>	  r   c                     	 t         j                  j                  | |      S # t        $ r&}t	        |      j                  d      rY d }~y|d }~ww xY w)NzCannot inspect value of type F)r(   _C	_overlaps	Exceptionstr
startswith)r+   r,   	exceptions      r   has_aliasedz7SchemaCheckMode.__torch_dispatch__.<locals>.has_aliasedE   sI    $xx))#s33 $y>,,-LM #O	$s   " 	AA
AAc                     | dk7  r| S dS )Nr   input )names    r   standardize_namez<SchemaCheckMode.__torch_dispatch__.<locals>.standardize_nameN   s    6>46w6r   c                     t        | t        j                        r)t        |       t        j                  k(  s	 | j                  S | S # t
        $ r}| cY d }~S d }~ww xY wr   )
isinstancer(   r1   r0   elemAttributeError)ets     r   unwrapz2SchemaCheckMode.__torch_dispatch__.<locals>.unwrapQ   sK    !U\\*47ell3J66M H & Hs   A 	AAAAc                    t        | t        j                        rt        |       t        j                  k(  s@	 | j                  }t        |j                               |j                         j                  fS | j                  t        j                  k7  r3t        | j                               | j                         j                  fS y # t        $ r
}Y d }~y d }~ww xY wr   )rK   r(   r1   r0   rL   r   r5   r6   r7   rM   r2   r3   )rN   currentrO   s      r   parse_metadataz:SchemaCheckMode.__torch_dispatch__.<locals>.parse_metadataY   s    !U\\*Aw%,,.$"#&&$W^^%56#224;;   XX!1!11$QXXZ0!2B2B2D2K2KLL * $#$s   >C 	CCT)normalize_to_only_use_kwargs)zaten::_unsafe_viewzaten::unsafe_splitz	Argument z0 is not defined to alias output but was aliasingoutput_zoDispatcher operators below autograd are not allowed to directly return inputs.
However, we found that `outputs[z] is c              3   :   K   | ]  \  }}} |||        y wr   rG   ).0abcr<   s       r   	<genexpr>z5SchemaCheckMode.__torch_dispatch__.<locals>.<genexpr>   s,      $1a  1a($s   z* is not defined as mutable but was mutated   zOutputs z and z alias unexpectedly)+r   append_schemarH   r   kwargsdictzipkeysr   valuesr
   getpytreetree_leavesrK   tuple
SchemaInfoadd_argument_valuesrangelen	argumentsmay_contain_aliasSchemaArgumentSchemaArgTypeoutputrF   RuntimeErrorr   r   r(   r1   
is_mutableatenliftdefault
lift_freshrA   anyr   r   r   returns)r   functypesargsr_   rD   rI   rP   rS   pre_argumentsc_p_argsrH   cloned_argumentsrX   cloned_metadataoutrl   	tuple_outschema_infoiargr8   r:   r9   j
unsafe_opsr-   r<   s                             @@r   __torch_dispatch__z"SchemaCheckMode.__torch_dispatch__-   s   	@		$	7		  	))* +$T

& 	 M..0,}?S?S?U2VWXCK
CK4D(68<<#5668 	 
 &	
 & +1+=+=m>O>OPT>U+V+Vaq!+V  &	 	 
 D#F#HU
HUD(6=#4#4T#:;; 	 
 &c51Cv	VY/	 .''6 s4<<1123A,,((+C#CHH-D}}T".)--d3$((.!d+s9~.A!MJ#IaL%8 LL--Z?*<<*=+?+?C*=+>+>B  #/"+D61a b#  !MM00 ():):DGA3- P 	!,E5<<1P*55*=+>+>B "!IINN//77!IINN55==+  #/%!!$QdV!7# 5 />  #&**62F4F4Fu4Mr$  '11&}':':A> +'v-WX  ++HT\\5F5F,MNg 4l !s4<<+?+?'@!A1EDAq9Q<16"44"=#7#7;"=#7#7; '!E!<O'PQQ F 
g


s$   #T,T3TT#TT)rG   N)__name__
__module____qualname__r   r   r#   r   rG   r   r   r   r      s    
"Wr   r   )collectionsr   copyr   	itertoolsr   r(   torch.fx.operator_schemasr   !torch.testing._internal.jit_utilsr   torch.utilsr   re   torch.utils._python_dispatchr	   torch.utils._pytreer
   r   r   r>   _SchemaArgumentrn   _SchemaArgTypero   _SchemaInforh   r   rG   r   r   <module>r      s~    "  "  8 : ) : ( j9j"9:j"JK ))''XX!!
h' hr   