
    3jd                         S r SSKJr  SSKrSSKJr  SSKJr  SSKJ	r	  SS	K
Jr  \(       a  SS
KJr   SS\SSSS4S jjrS\S\4S jr " S S5      rg)a)  
Hashability utilities for PyTorch Dynamo variable tracking.

This module provides the HashableTracker wrapper class and associated utilities
for making VariableTracker instances usable as dictionary keys and set elements
during symbolic execution. Used by both ConstDictVariable and SetVariable.
    )TYPE_CHECKINGN   )	variables)raise_observed_exception)specialize_symnode   )VariableTrackerInstructionTranslatorargtxzInstructionTranslator | Nonereturnc                     Uc  SSK Jn  UR                  " 5       n U R                  5       n[        [        USU< S[        U R                  5       5       3/S9  g ! [         a    [        U 5      n NFf = f)Nr   r
   zunhashable type: z and variable tracker = )args)	torch._dynamo.symbolic_convertr   
current_txpython_type	Exceptiontyper   	TypeErrorrealize)r   r   r   arg_types       Z/home/wildlama/miniconda3/lib/python3.13/site-packages/torch/_dynamo/variables/hashable.pyraise_unhashabler      sw     
zH"--/??$ 
|+CDDWCXY
  9s   A A32A3xc                     [        U [        R                  5      (       a+  U R                  5       (       d  U R	                  5       (       a  gU R                  5       $ )NT)
isinstancer   LazyVariableTrackeris_realizedis_hashableis_python_hashable)r   s    r   r    r    ,   s?     	1i3344MMOO!!    c                   t    \ rS rSrSr\" 5       rS\SS4S jr\	S\S\4S j5       r
S\4S jrS	\S\4S
 jrSrg)HashableTracker:   z
Class that wraps a VariableTracker and makes it hashable.
Note that it's fine to put VTs into dictionaries and sets, but doing so
does not take into account aliasing.
vtr   Nc                 \    [        U5      n[        U5      (       d  [        U5        Xl        g N)r   r    r   r&   )selfr&   s     r   __init__HashableTracker.__init__C   s$    #
 2R r"   c                    SSK Jn  SSKJn  [	        U[
        R                  5      (       aR  UR                  5       (       d=  [	        UR                  5       [        R                  5      (       a  UR                  5       $ [	        X5      (       d  U R                  $ / nUR                   GH
  nUR                  5       (       a!  UR                  UR                  5       5        M:  [	        XS5      (       a  [!        USS 5      n[!        USS 5      nUb  [!        USS 5      OS n[	        U["        5      (       a  UR%                  S5      OS n	[!        U	SS 5      n
[	        U
[        R&                  5      (       a5  U
R)                  5       S:X  a!  UR                  U
R+                  5       5        M  U R                  s  $    [        R                  " U5      $ )	Nr   )SizeVariable)TensorVariableproxynodemetaexample_valueconstant)listsr-   tensorr.   r   r   r   r   original_valuetorchSize_MISSINGitemsis_python_constantappendas_python_constantgetattrdictgetTensornumelitem)clsr&   r-   r.   r:   rC   r/   r0   r1   r2   r3   s              r   _maybe_constant_torch_size*HashableTracker._maybe_constant_torch_sizeN   s\   '* r98899NN$$2,,.

;;$$&&"++<<HHD&&((T4467$//gt4ufd36:6FwtVT2D1;D$1G1GDHH_-T  #=*dCh55(..:Ja:OLL1<<% ( zz%  r"   c                    [        U R                  [        R                  5      (       aa  U R                  R	                  5       (       dB  U R                  R                  5       (       a#  [        U R                  R                  5       5      $ U R                  U R                  5      nXR                  La  [        U5      $ U R                  R                  5       $ )aU  
Computes the hash value for the wrapped VariableTracker.

For unrealized LazyVariableTrackers, uses the hash of the original value
to avoid realizing the tracker and inserting unnecessary guards.
For all other cases, delegates to the VariableTracker's get_python_hash method.

Returns:
    The hash value of the underlying variable tracker
)r   r&   r   r   r   r    hashr6   rE   r9   get_python_hash)r)   maybe_constants     r   __hash__HashableTracker.__hash__t   s     tww	 = =>>GG''))##%%..01188A.''ww&&((r"   otherc                 X   [        U[        5      (       d  gU R                  UR                  L a  gU R                  U R                  5      nU R                  UR                  5      nX R                  La  X0R                  La  X#:H  $ U R                  R                  UR                  5      $ )aV  
Checks equality between two HashableTracker instances.

Delegates to the VariableTracker's is_python_equal method to compare
the underlying variable trackers for Python-level equality.

Args:
    other: Another HashableTracker instance to compare with

Returns:
    True if the underlying variable trackers are Python-equal, False otherwise
FT)r   r$   r&   rE   r9   is_python_equal)r)   rM   self_constantother_constants       r   __eq__HashableTracker.__eq__   s     %1177ehh77@88B-.2U 22ww&&uxx00r"   )r&   )__name__
__module____qualname____firstlineno____doc__objectr9   r	   r*   classmethodrE   intrK   boolrR   __static_attributes__ r"   r   r$   r$   :   se     xH	? 	t 	 #!O #! #! #!J)# )01F 1t 1r"   r$   r(   )rX   typingr   r7    r   excr   utilsr   baser	   r   r   r   r\   r    r$   r^   r"   r   <module>rd      si    !   * & ! D @D	<	*"? "t "i1 i1r"   