
    iz                        d Z ddlZddlZddlmZmZmZmZmZ ddl	m
Z
 ddlmZmZ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 ddlmZmZ ddlmZmZ ddlmZm Z  ddl!m"Z"m#Z# erddl$m%Z% ddl&m'Z' ddl(m)Z) ddl*m+Z+  ejX                  e-      Z. G d de
      Z/ G d d      Z0 G d de0      Z1 G d de0      Z2 G d de0      Z3 G d de3      Z4 G d  d!e3      Z5d"e6d#e7fd$Z8d%e0d#e7fd&Z9 G d' d(e:      Z; G d) d*e<      Z= G d+ d,e=      Z> G d- d.e=/      Z?d0ed1e@d#efd2ZAd3eBd#e@fd4ZCe<j                  ZEdd5lmFZF dd6lGmHZH y)7a  
Core variable tracking functionality for Dynamo. This module defines the fundamental
classes and systems used to track and manage variables during Dynamo's operation.

The module provides:
1. VariableTracker - The base class for tracking variables during compilation
2. MutationType system - Classes for tracking and managing mutations to variables
3. Source type management - Utilities for tracking variable origins and scope
4. Variable state management - Tools for managing variable state and transformations

These components form the foundation of Dynamo's variable handling system,
enabling accurate tracking and transformation of Python code into optimized
computations.
    N)Callable	ItemsViewKeysViewSequence
ValuesView)Enum)AnyNoReturnOptionalTYPE_CHECKING)Guard)Node   )graph_break_hints	variables)current_scope_id)raise_observed_exceptionunimplemented)GuardBuilderinstall_guard)
AttrSourceSource)cmp_name_to_op_mappingistype)	PyCodegen)InstructionTranslator   )ConstantVariable)UserFunctionVariablec                       e Zd ZdZdZdZy)
SourceTypea  
    This Enum divides VariableTracker into 2 cases, depending on the variable
    it represents:
    - already existed that Dynamo began tracking while introspection (Existing)
    - is a new variable that is created during Dynamo introspection (New)

    In general, we have these invariants:
    1. for `VariableTracker` associated with `Existing`, its `source` field must not be None.
    2. for `VariableTracker` associated with `New`, most of the time its
       `source` field is None, except for cases like side effect codegen for
       `AttributeMutationNew`, during which we generate a
       `LocalSource('tmp...')` for such variable, to facilitate codegen.
    r   r   N)__name__
__module____qualname____doc__ExistingNew     V/var/www/html/engine/venv/lib/python3.12/site-packages/torch/_dynamo/variables/base.pyr!   r!   +   s     H
Cr)   r!   c                        e Zd ZdZdeddfdZy)MutationTypez
    Base class for Variable.mutation_type. It encodes information about
    1. The type of mutation Dynamo allows on the variable.
    2. Whether the value represented by this variable already existed before
    Dynamo tracing.
    typreturnNc                     |t         j                  u rd| _        y |t         j                  u rt	               | _        y t        dd|  d| d| ddgt        j                         y )	Nr   zUnsupported SourceTypezMutationType.__init__  z"Dynamo does not support the type ``z,This branch is not supposed to be reachable.gb_typecontextexplanationhints)r!   r&   scoper'   r   r   r   
DYNAMO_BUG)selfr-   s     r*   __init__zMutationType.__init__F   sl    0 *%%%DJJNN")+DJ00au=@QGB&11	r)   )r"   r#   r$   r%   r!   r:   r(   r)   r*   r,   r,   >   s    %J %4 %r)   r,   c                   @     e Zd ZdZd fdZdefdZdedefdZ	 xZ
S )ValueMutationNewa  
    This case of VariableTracker.mutation_type marker indicates
    1. Dynamo allows mutation on the value itself (rather than its attributes).
    2. The value is created by the bytecode Dynamo is tracing through.

    For instance, Dynamo could model a newly created list with this marker,
    indicating that while we need to model mutations to this list, we don't have
    to emit bytecode for these mutations if the list doesn't escape into the
    Python world.
    r.   c                 @    t         |   t        j                         y N)superr:   r!   r'   r9   	__class__s    r*   r:   zValueMutationNew.__init__z   s    (r)   c                     t        |       S r>   )idr9   s    r*   __hash__zValueMutationNew.__hash__}   s    $xr)   otherc                 
    | |u S r>   r(   r9   rF   s     r*   __eq__zValueMutationNew.__eq__   s    u}r)   r.   N)r"   r#   r$   r%   r:   intrE   objectboolrI   __classcell__rA   s   @r*   r<   r<   n   s,    	)# F t r)   r<   c                   :     e Zd ZU dZeed<   ddeddf fdZ xZS )ValueMutationExistinga  
    This case of VariableTracker.mutation_type marker indicates
    1. Dynamo allows mutation on the value itself (rather than its attributes).
    2. The value exists before Dynamo tracing started.

    For instance, Dynamo could model a pre-existing list with this marker,
    indicating that if we encounter mutations to this list, we need to buffer
    and re-apply those mutations after the graph runs, since the list might be
    used afterwards in Python.
    is_modifiedr.   Nc                 N    t         |   t        j                         || _        y r>   )r?   r:   r!   r&   rR   )r9   rR   rA   s     r*   r:   zValueMutationExisting.__init__   s    ,,-&r)   )F)r"   r#   r$   r%   rM   __annotations__r:   rN   rO   s   @r*   rQ   rQ      s(    	 'D 'T ' 'r)   rQ   c                       e Zd ZdZy)AttributeMutationz
    This case of VariableTracker.mutation_type marker indicates that Dynamo
    allows mutation on the value's attributes.
    N)r"   r#   r$   r%   r(   r)   r*   rV   rV      s    r)   rV   c                   $     e Zd ZdZd fdZ xZS )AttributeMutationExistinga  
    This case of VariableTracker.mutation_type marker indicates
    1. Dynamo allows mutation on the value's attributes.
    2. The value exists before Dynamo tracing started.

    For instance, Dynamo could model a pre-existing object with this marker,
    indicating that if we encounter mutations to this object, we need to buffer
    then re-apply those mutations after the graph runs, since the object might
    be used afterwards in Python.
    c                 @    t         |   t        j                         y r>   )r?   r:   r!   r&   r@   s    r*   r:   z"AttributeMutationExisting.__init__   s    ,,-r)   rJ   )r"   r#   r$   r%   r:   rN   rO   s   @r*   rX   rX      s    	. .r)   rX   c                   4     e Zd ZdZddee   ddf fdZ xZS )AttributeMutationNewa  
    This case of VariableTracker.mutation_type marker indicates
    1. Dynamo allows mutation on the value's attributes.
    2. The value is created by the bytecode Dynamo is tracing through.

    For instance, Dynamo could model a newly created object with this marker,
    indicating that while we need to model mutations to this object, we don't
    have to emit bytecode for these mutations if the object doesn't escape into
    the Python world.
    N
cls_sourcer.   c                 N    t         |   t        j                         || _        y r>   )r?   r:   r!   r'   r\   )r9   r\   rA   s     r*   r:   zAttributeMutationNew.__init__   s    ($r)   r>   )r"   r#   r$   r%   r   r   r:   rN   rO   s   @r*   r[   r[      s%    	%8F#3 %t % %r)   r[   scope_idr.   c                     | dk(  S )Nr   r(   )r^   s    r*   _is_top_level_scoper`      s    q=r)   mc                 L    t               }t        |      ry| j                  |k(  S )NT)r   r`   r7   )ra   r^   s     r*   is_side_effect_saferc      s&    !H
 8$77hr)   c                   ,     e Zd ZU ded<   d fdZ xZS )#AsPythonConstantNotImplementedErrorVariableTrackervtc                 8    t         |   | d       || _        y )Nz is not a constant)r?   r:   rg   )r9   rg   rA   s     r*   r:   z,AsPythonConstantNotImplementedError.__init__   s    B4123r)   )rg   rf   r.   N)r"   r#   r$   rT   r:   rN   rO   s   @r*   re   re      s     r)   re   c            
            e Zd ZU g Zee   ed<   dededeedf   de	ee
f   def
 fdZd	ededeedf   de	ee
f   dd
f
 fdZ xZS )VariableTrackerMetaall_subclassesmcsnamebases.attrsr.   c                     |j                  dd      xs t        d |D              }|s|dk(  rt        |   t        |||      S t        |   t
        |||      S )N_no_implicit_realizeFc              3   6   K   | ]  }t        |d d        yw)rq   FN)getattr).0bases     r*   	<genexpr>z.VariableTrackerMeta.__new__.<locals>.<genexpr>   s!      N
=AGD0%8N
s   rf   )getanyr?   __new__rj   $ImplicitRealizingVariableTrackerMeta)rl   rm   rn   ro   no_implicit_realizerA   s        r*   ry   zVariableTrackerMeta.__new__   sr     $ii(>F 
# N
EJN
 K
 $*;";7?#6eUKK 7?4dE5 r)   clsNc                 f    t         |   |||       t        j                  j	                  |        y r>   )r?   r:   rj   rk   append)r|   rm   rn   ro   rA   s       r*   r:   zVariableTrackerMeta.__init__   s*     	ue,**11#6r)   )r"   r#   r$   rk   listtyperT   strtupledictr	   ry   r:   rN   rO   s   @r*   rj   rj      s    !#NDJ#%*49%5>B38n	&777%*49%57>B38n7	7 7r)   rj   c                       e Zd ZdedefdZy)rz   instancer.   c                 \    t        t        |      r|j                  |       S t        | |      S )z-Make isinstance work with LazyVariableTracker)instancecheckLazyVariableTrackerlazy_isinstance)r9   r   s     r*   __instancecheck__z6ImplicitRealizingVariableTrackerMeta.__instancecheck__   s+    ,h7++D11T8,,r)   N)r"   r#   r$   rL   rM   r   r(   r)   r*   rz   rz      s    -& -T -r)   rz   c                       e Zd ZdZh dZdedd fdZe	 dDded gdf   ded	e	e
eef      ddfd
       ZdefdZdefdZdefdZdefdZdefdZdefdZdefdZdedefdZdefdZdedef   defdZdddedefdZdefdZdefdZdddedd fdZdefdZdefdZ de	e!   fd Z"dEd!Z#dede$d    fd"Z%dede$d    fd#Z&dedefd$Z'dedefd%Z(deded gef   ddfd&Z)dededd'fd(Z*ded)e+d    de
ed f   dd fd*Z,deded)e$d    de
ed f   dd f
d+Z-ded,d-d.d d/e+d    d0e
ed f   dd fd1Z.ded,d-d.d d/e+d    d0e
ed f   dd fd2Z/ded,d-d.d d/e+d    d0e
ed f   dd fd3Z0deddfd4Z1dFd5Z2dFd6Z3defd7Z4dedd fd8Z5dedefd9Z6defd:Z7defd;Z8e9	 dDdeded<e	e:   defd=       Z;d> Z<d? Z=d@ Z>dddAd<e	e:   dBe	e?   ddf fdCZ@ xZAS )Grf   z
    Base class for tracked locals and stack values

    VariableTracker instances are immutable and should be copied in
    order to change them.

    Prefer the factory function VariableTracker.build() over VariableTracker.__init__().
    >   valueguardssourcemutation_typeparents_trackeruser_code_variable_namekwargsr.   c                 r    t        | j                        }|j                  |        | j                  di |S )z)Shallow copy with some (optional) changesr(   )r   __dict__updaterA   )r9   r   argss      r*   clonezVariableTracker.clone  s0    DMM"Ft~~%%%r)   Nfnr   cachec                 (   |i }t        |      }||v ry|||<   t        |t              ro|j                         } ||       |j                         }|j                  }|j
                  j                         D ]  \  }}||vs| j                  |||        yt        |t        t        f      r|D ]  }| j                  |||        yt        |t        t        j                  f      r)|j                         D ]  }| j                  |||        yy)zM
        Walk value and call fn on all the VariableTracker instances
        N)rC   
isinstancerf   unwrap_nonvar_fieldsr   itemsvisitr   r   r   r   collectionsOrderedDictvalues)r|   r   r   r   idxnonvarskeysubvalues           r*   r   zVariableTracker.visit  s    =Ei%<c
e_-LLNEuILLNE**G!&!5!5!7 3Xg%IIb(E23 ED%=)! /		"h./ED+"9"9:;!LLN /		"h./ <r)   c                 4    | j                   j                   dS )Nz())rA   r"   rD   s    r*   __repr__zVariableTracker.__repr__>  s    ..))*"--r)   c                 j    	 t        | j                               S # t        $ r t        |       cY S w xY wr>   )repras_python_constantNotImplementedErrorrD   s    r*   
debug_reprzVariableTracker.debug_reprA  s4    	//122" 	:	s    22c                 n    	 t        | j                               S # t        $ r t        |  d      dw xY w)a  
        Abstract method to be implemented by subclasses of VariableTracker.

        This method should return the type represented by the instance of the subclass.
        The purpose is to provide a standardized way to retrieve the Python type information
        of the variable being tracked.

        Returns:
            type: The Python type (such as int, str, list, etc.) of the variable tracked by
                the subclass. If the type cannot be determined or is not relevant,
                leaving it undefined or invoking super() is always sound.

        Note:
            This is an abstract method and may be overridden in subclasses.

        Example:
            class SetVariable(VariableTracker):
                def python_type(self):
                    return set

        Raises:
            NotImplementedError: If the method is not implemented in a subclass.
        z has no typeN)r   r   r   rD   s    r*   python_typezVariableTracker.python_typeH  sA    0	G//122" 	G%l&;<$F	Gs    4c                 V    	 | j                         j                  S # t        $ r Y yw xY w)Nz<unknown type>)r   r"   r   rD   s    r*   python_type_namez VariableTracker.python_type_namee  s.    	$##%..." 	$#	$s    	((c                     t        |       )zFor constants)re   rD   s    r*   r   z"VariableTracker.as_python_constantk  s    1$77r)   c                 n    	 | j                         S # t        $ r t        dd|  d|  dg        Y yw xY w)zcSimilar to as_python_constant(), but add ID_MATCH guards to try to force things to become constantszNot a Python constantzguard_as_python_constant zFailed to convert z into a Python constant.r2   N)r   r   r   rD   s    r*   guard_as_python_constantz(VariableTracker.guard_as_python_constanto  sJ    	**,," 	/3D6:06NO		s    44c                 D    	 | j                          y# t        $ r Y yw xY wNTF)r   r   rD   s    r*   is_python_constantz"VariableTracker.is_python_constant{  s(    	##%" 		    	r   c                      y)an  
        Check if this variable is a python constant matching one of the given values.

        Examples:
            var.is_constant_match(None)  # True if var is constant None
            var.is_constant_match(True, False)  # True if var is constant True or False
            var.is_constant_match(NotImplemented)  # True if var is constant NotImplemented
        Fr(   )r9   r   s     r*   is_constant_matchz!VariableTracker.is_constant_match  s     r)   c                      y)z0Check if this variable is a constant None value.Fr(   rD   s    r*   is_constant_nonez VariableTracker.is_constant_none      r)   .c                 \    | j                   r| j                   j                  |      S t        r>   )r   
make_guardr   )r9   r   s     r*   r   zVariableTracker.make_guard  s$    ;;;;))"--!!r)   txr   rm   c                     t         )z/getattr(self, name) returning a python constantr   r9   r   rm   s      r*   const_getattrzVariableTracker.const_getattr  s    !!r)   c                      y)zAReturn True for values that can participate in SymNode operationsFr(   rD   s    r*   is_symnode_likezVariableTracker.is_symnode_like  r   r)   c                      y)z(Return True for TensorVariable instancesFr(   rD   s    r*   	is_tensorzVariableTracker.is_tensor  r   r)   c                 n   | j                  ||      }t        j                  j                  |      st        | j
                  xr t        | j
                  |      }|r8| j                         s(t        |j                  t        j                               t        j                  j                  ||      S )z,getattr(self, name) returning a new variable)r   )r   r   r   
is_literalr   r   r   r   r   r   r   CONSTANT_MATCHcreate)r9   r   rm   r   r   s        r*   var_getattrzVariableTracker.var_getattr  s    ""2t,))44U;%%>DKK!>$113 &++L,G,GHI))00v0FFr)   c                 D    	 | j                          y# t        $ r Y yw xY wr   )as_proxyr   rD   s    r*   is_proxyzVariableTracker.is_proxy  s%    	MMO" 		r   c                 *    t        t        |             r>   )r   r   rD   s    r*   r   zVariableTracker.as_proxy  s    !#d),,r)   c                     	 | j                         }dd l}t        ||j                  j                        r|j
                  S y # t        $ r Y y w xY w)Nr   )r   torch.fxr   fxProxynoder   )r9   proxytorchs      r*   maybe_fx_nodezVariableTracker.maybe_fx_node  sF    	MMOE%0zz!" 		s   ?A 	AAc                     t         r>   r   )r9   codegens     r*   reconstructzVariableTracker.reconstruct      !!r)   c                     t         r>   r   r9   r   s     r*   unpack_var_sequencez#VariableTracker.unpack_var_sequence  r   r)   c                 $    | j                  |      S r>   )r   r   s     r*   force_unpack_var_sequencez)VariableTracker.force_unpack_var_sequence  s     ''++r)   c                 F    	 | j                  |       y# t        $ r Y yw xY wr   )r   r   r   s     r*   has_unpack_var_sequencez'VariableTracker.has_unpack_var_sequence  s*    	$$R(" 		s    	  c                 $    | j                  |      S r>   )r   r   s     r*   has_force_unpack_var_sequencez-VariableTracker.has_force_unpack_var_sequence  s    ++B//r)   c                 f    | j                  |      sJ | j                  |      D ]
  } ||        y r>   )r   r   )r9   r   r   vs       r*   force_apply_to_var_sequencez+VariableTracker.force_apply_to_var_sequence  s9     11"555))"- 	AqE	r)   r   c           
          t        dd|  d| d| j                          dd| j                  j                   d| dgt        j
                  	       y )
NzUnsupported hasattr callzcall_obj_hasattr r0   0Dynamo does not know how to trace the function `r1   zAvoid calling `hasattr(, z)` in your code.r2   )r   r   rA   r"   r   SUPPORTABLEr   s      r*   call_obj_hasattrz VariableTracker.call_obj_hasattr  sc    .'vQtf5J4??K\J]]^_)$..*A*A)B"TFJZ["..		
r)   r   c           	          t        dd|  d| d| d| j                          dd| j                          ddg	       y )
NzUnsupported function callzcall_function r0   r   r1   Avoid calling `` in your code."Please report an issue to PyTorch.r2   )r   r   )r9   r   r   r   s       r*   call_functionzVariableTracker.call_function  sV     	/$TF!D66(;J4??K\J]]^_!$//"3!4OD4		
r)   c                 V   |dk(  rN| j                  |      r=|s|rJ t        j                  j                  t	        | j                  |                  S |dk(  rFt	        |      dk(  r8|d   j                         r%|s#| j                  ||d   j                               S |t        v r_t	        |      dk(  rP|sM|d   }t        | t        |            sWt        | t        j                        s=t        |t        j                        s#t        j                  j                  t              S | j                         rZ|j                         rJ|j                  j                  j!                  |       s%|j                  j                  j!                  |      r)t#        dd|  d| d| d| d|  d	| d
d| dz   g        	 t        j                  j                  t        |   | j                         |j                                     S d| j/                          d| ddg}t        | t        j0                        r\|dv rXt        | j2                  t4        t6        t8        f      r|j;                  d       |j;                  d       |j;                  d       t#        dd|  d| d| d| d| d| j/                          d|       y # t$        $ rX}t'        t        |      |t)        t+        t        j                  j                  |j,                              g       Y d }~d }~ww xY w)N__len____getattr__r   r   z;Builtin `operator.*` comparison with constant `self` failedzcall_method r0   zFailed to compare z with r   zbecause z6 is not a Python constant or its mutation check fails.r2   r   r   .r   r   )__iter____next__zConsider moving the creation of dict view object (e.g. `dict.keys()`, `dict.items()`,) to the compiled region, instead of passing it as an input to the compiled region.a   Dynamo does not fully support tracing builtin iterators (e.g. `map`, `zip`, `enumerate`) passed in from uncompiled to compiled regions (e.g. `torch.compile(fn)(enumerate(...))`). This can happen unintentionally if a previous graph break happens with a builtin iterator in the local scope.aF  List/dict comprehensions in Python <= 3.11 result in implicit function calls, which Dynamo cannot trace as a top level frame. Possible workarounds are (1) use a loop instead of a comprehension, (2) fix any graph breaks in the function above the comprehension, (3) wrap the comprehension in a function, or (4) use Python 3.12+.zUnsupported method callz*Dynamo does not know how to trace method `z` of class `r1   )r   r   r   r   lenr   r   r   r   r   r   r   GetAttrVariableNotImplementedoutputside_effectshas_pending_mutationr   	Exceptionr   r   mapr   r   UserDefinedObjectVariabler   r   r   r   r~   )r9   r   rm   r   r   rF   er6   s           r*   call_methodzVariableTracker.call_method  s    9!=!=b!A''--44S9Q9QRT9U5VWWM!D	QQ**,##BQ(B(B(DEE++D	QvGEdDK04!:!:;eY%>%>? !1188HH ++-//199))>>tD99))>>uEY*4&$qaxH"4TF&r J ']^!_ 1188*40//153K3K3M  d3356av_M0

 dI??@T N
 F
 $**xJ&GHh LL& LL5 	-"4&$qax@DTF,W[WlWlWnVoopq		
A  (Gs9#=#=#D#DaffMNO s   ?AK 	L(AL##L(tree_map_fnr   map_fnresttree_map_kwargsc                 4   |j                  d      }|M|j                         s=|j                  || gi       }	 |j                         }|r|j                  || g|i       S | j                  |||||      S # t        $ r | j                  |||||      cY S w xY w)zLPerformance optimization to implement optree.tree_map faster than tracing itis_leaf)rw   r   r   r   r   _tree_map_fallbackcall_tree_map_branch)	r9   r   r  r  r  r	  is_leaf_varpred_resultleaf_decisions	            r*   call_tree_mapzVariableTracker.call_tree_map]  s     &)))4";+G+G+I%33BCK	 + > > @ ++BrBB((
 	
 ' ..# s   A6 6BBc                 ,    | j                  |||||      S )zKEmulate optree.tree_map without is_leaf/none_is_leaf checks (handled above))r  )r9   r   r  r  r  r	  s         r*   r  z$VariableTracker.call_tree_map_branch~  s&     &&
 	
r)   c                     |j                         }d |_        t        j                  d| ||       |j	                  ||| g||      S )Nc                       y r>   r(   )r   r   s     r*   <lambda>z4VariableTracker._tree_map_fallback.<locals>.<lambda>  s    r)   z@tree_map fastpath fallback triggered for %s (rest=%s, kwargs=%s))r   _maybe_call_tree_map_fastpathlogdebugr   )r9   r   r  r  r  r	  tree_map_fn_copys          r*   r  z"VariableTracker._tree_map_fallback  s\     ',,.9U6		N		
  --T!D!
 	
r)   c                      y r>   r(   )r9   rm   s     r*   set_name_hintzVariableTracker.set_name_hint  s    r)   c                     | S )z=Used by LazyVariableTracker to build the real VariableTrackerr(   rD   s    r*   realizezVariableTracker.realize      r)   c                     | S )zSUsed by LazyVariableTracker to return the real VariableTracker if it already existsr(   rD   s    r*   r   zVariableTracker.unwrap  r  r)   c                      y)z:Used by LazyVariableTracker to indicate an unrealized nodeTr(   rD   s    r*   is_realizedzVariableTracker.is_realized  s    r)   c                 R    t        dd|  dd|  dg t        j                         y )NzUnsupported next() callznext()z@Dynamo does not know how to trace calling `next()` on variable `z`.r2   )r   r   
USER_ERRORr   s     r*   next_variablezVariableTracker.next_variable  s6    -D6OZ[_Z``bc1%001		
r)   c                 R    t        |j                  xr |j                  |             S r>   )rM   strict_checks_fnr   s     r*   is_strict_modezVariableTracker.is_strict_mode  s#    B''EB,?,?,EFFr)   c                 $    | j                          S )z0Whether Dynamo allows mutation on this variable.)is_immutablerD   s    r*   
is_mutablezVariableTracker.is_mutable  s    $$&&&r)   c                     | j                   du S )z.Whether Dynamo bans mutation on this variable.N)r   rD   s    r*   r*  zVariableTracker.is_immutable  s    !!T))r)   r   c                     | t         j                  j                  | |      S t        j                  j                  ||      S )z=Create a new VariableTracker from a value and optional Source)builderSourcelessBuilderr   r   r   )r   r   r   s      r*   buildzVariableTracker.build  s;     >,,33B>>0077vFFr)   c                     	 | j                         }t        dd|  d|  dd| dgt        j
                         y# t        $ r t        |       }Y Bw xY w)	z
        Unlike the variable tracker's own __hash__, this method checks whether
        the underlying Python object referenced by this variable tracker is hashable.
        zADynamo cannot determine whether the underlying object is hashablezis_python_hashable z>Dynamo does not know whether the underlying python object for z is hashableKConsider using a different type of object as the dictionary key instead of r   r2   N)r   r   r   r   r   r   )r9   	type_selfs     r*   is_python_hashablez"VariableTracker.is_python_hashable  s|    
	#((*I 	W)$0XY]X^^jk bbkallmn #..		
	
 # 	#T
I	#s   > AAc                 t    t        dd|  d|  d| j                          dgt        j                         y)u   
        Unlike the variable tracker’s own __hash__, this method is used by
        ConstDictVariableTracker to compute the hash of the underlying key object.
        z-Dynamo cannot determine the hash of an objectzget_python_hash zBDynamo does not know the hash of the underlying python object for r2  r   r2   Nr   r   r   r   rD   s    r*   get_python_hashzVariableTracker.get_python_hash  sU    
 	C&tf-\]a\bc bbfbrbrbtauuvw #..		
	
r)   c                 t    t        dd|  d|  d| j                          dgt        j                         y)z
        NB - Deliberately not overriding the __eq__ method because that can
        disable the __hash__ for the vt itself.
        z<Dynamo cannot determine the equality comparison of an objectzis_python_equal zQDynamo does not know the equality comparison of the underlying python object for r2  r   r2   Nr6  rH   s     r*   is_python_equalzVariableTracker.is_python_equal  sU    
 	R&tf-klpkqr bbfbrbrbtauuvw #..		
	
r)   )r   r   r   c                    t         |           || _        || _        |8t	        |t
        t        f      r|J y t	        |t        t        f      sJ |J y y r>   )	r?   r:   r   r   r   r<   r[   rQ   rX   )r9   r   r   rA   s      r*   r:   zVariableTracker.__init__  su     	* $-*:<P)QR ~%~!!$9;T#U   ))) %r)   r>   )r   r   r.   N)r.   rf   )Br"   r#   r$   r%   r   r	   r   classmethodr   r   r   rK   r   r   r   r   r   r   r   r   r   rM   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r  r   r!  r%  r(  r+  r*  staticmethodr   r0  r4  r7  r9  r,   r:   rN   rO   s   @r*   rf   rf     s   N&c &&7 & 
 +/	/'($.// / S#X'	/
 
/ /B.# .C GT G:$# $8C 8
# 
D 	 	 	$ "Xc3h/ "E "" 7 "s "s " 4 
G5 
GS 
GEV 
G$ -# -	x~ 	""c "d3D.E ",C ,D9J4K ,# $ 0 0 0#%6$7$<=		
3 	
c 	
6H 	


 ()
 S++,	

 

 W
W
 W
 $%	W

 S++,W
 
W
r

 ,
 "	

 ()
 c#445
 

B

 ,
 "	

 ()
 c#445
 

"

 ,
 "	

 ()
 c#445
 

,# $ T 
 
(9 
G G G'D '*d *  $(	G	G	G  	G 
		G 	G
,
"
( $(04	*  *  -	*
 
* *r)   rf   )	metaclassr   msg_strc                 h    t         j                  j                  |      }t        t        | |g       y )Nr   )r   r   r   r   	TypeError)r   r>  msgs      r*   raise_type_error_excrB  '  s&    

$
$
+
+G
4CY#7r)   objsc                      t        |       dk(  r4| \  }t        |t              rt        |      S t	        |      j
                  S dj                  t        t        |             S )Nr   r0   )	r   r   rf   r   r   r"   joinr  typestr)rC  objs     r*   rF  rF  ,  sM    
4yA~c?+s8O9%%%xxGT*++r)   )r.  )r   )Ir%   r   loggingcollections.abcr   r   r   r   r   enumr   typingr	   r
   r   r   torch._guardsr   torch.fx.proxyr    r   r   r   excr   r   r   r   r   r   r   r   utilsr   r   r   r   symbolic_convertr   constantr   	functionsr   	getLoggerr"   r  r!   r,   r<   rQ   rV   rX   r[   rK   rM   r`   rc   r   re   r   rj   rz   rf   r   rB  rL   rF  r   r   r.  lazyr   r(   r)   r*   <module>rV     sO     O O  9 9   + / 9 0 ' 2 #8*/ g! &- -`| ,'L ', . 1 . %, %"# $ 	< 	D 	*= 7$ 7:-+> -b* 3 b*J8S 83 88 8
,6 ,c , &&  %r)   