
    Ph!                     h    d dl Z d dlmZ ddlmZ  G d d      Z G d de      Zd	 Zd
 Z e        y)    N)Optional   )VariableTrackerc                       e Zd ZdZd Zd Zy)	LazyCachez+Container to cache the real VariableTrackerc                 6    |sJ || _         || _        d | _        y N)valuesourcevt)selfr
   r   s      gC:\Users\daisl\Desktop\realtime-object-detection\venv\Lib\site-packages\torch/_dynamo/variables/lazy.py__init__zLazyCache.__init__
   s    v
-1    c                     | j                   J ddlm} ddlm} |j                         }  ||| j                        | j                        | _         | j                   j                  j                  |       | `| `y )N   )InstructionTranslatorr   )VariableBuilder)
r   symbolic_convertr   builderr   
current_txr   r
   parents_trackeradd)r   r   r   r   txs        r   realizezLazyCache.realize   sc    ww<,"--/2/"dkk24::>##O4JKr   N)__name__
__module____qualname____doc__r   r    r   r   r   r      s    52	r   r   c                        e Zd ZdZdhej
                  Zed        Z fdZdefdZ	d Z
d Zd	 Zd
 Zd Zej                  Zej                   Zej"                  Zej$                  Z xZS )LazyVariableTrackera  
    A structure that defers the creation of the actual VariableTracker
    for a given underlying value until it is accessed.

    The `realize` function invokes VariableBuilder to produce the real object.
    Once a LazyVariableTracker has been realized, internal bookkeeping will
    prevent double realization.

    This object should be utilized for processing containers, or objects that
    reference other objects where we may not want to take on creating all the
    VariableTrackers right away.
    _cachec                 2    t        t        | |      fd|i|S )Nr   )r"   r   )r
   r   optionss      r   createzLazyVariableTracker.create,   s    "9UF#;VFVgVVr   c                 V    t        |t              sJ t        |   di | || _        y )Nr    )
isinstancer   superr   r#   )r   r#   kwargs	__class__s      r   r   zLazyVariableTracker.__init__0   s*    &),,,"6"r   returnc                     | j                   j                  %| j                   j                  | j                         | j                   j                  S )z.Force construction of the real VariableTracker)r#   r   r   r   r   s    r   r   zLazyVariableTracker.realize5   s6    ;;>>!KK 4 45{{~~r   c                 R    | j                         r| j                  j                  S | S )z4Return the real VariableTracker if it already exists)is_realizedr#   r   r.   s    r   unwrapzLazyVariableTracker.unwrap;   s!    ;;>>!r   c                 2    | j                   j                  d uS r	   )r#   r   r.   s    r   r0   zLazyVariableTracker.is_realizedA   s    {{~~T))r   c                    |j                  d| j                        | j                  u sJ |j                  d| j                        | j                  ur| j                          t	        j
                  | j                         fi |S )Nr#   r   )getr#   r   r   r   cloner1   )r   r*   s     r   r5   zLazyVariableTracker.cloneD   sc    zz(DKK0DKK???::h,DKK?LLN$$T[[]=f==r   c                 H    t        j                  | j                               S r	   )r   __str__r1   r.   s    r   r7   zLazyVariableTracker.__str__J   s    &&t{{}55r   c                 6    t        | j                         |      S r	   getattrr   )r   items     r   __getattr__zLazyVariableTracker.__getattr__M   s    t||~t,,r   )r   r   r   r   r   _nonvar_fieldsstaticmethodr&   r   r   r1   r0   r5   r7   r<   applycopy__post_init____repr____classcell__)r+   s   @r   r"   r"      s     @!?!?@NW W
 *>6- !!ED#11M''Hr   r"   c                 ^     t        j                  t        t                      fd       }|S )Nc                 D     t        | j                               |i |S r	   r9   )r   argsr*   names      r   realize_and_forwardz8_create_realize_and_forward.<locals>.realize_and_forwardX   s"    ,wt||~t,d=f==r   )	functoolswrapsr:   r   )rG   rH   s   ` r   _create_realize_and_forwardrK   W   s-    __W_d34> 5> r   c                      t         j                  j                         D ]>  \  } }| t        j                  vst	        |      s%t        t        | t        |              @ y r	   )r   __dict__itemsr"   callablesetattrrK   )rG   r
   s     r   	_populaterQ   _   sH    &//557e*333+T3Nt3TU 8r   )	rI   typingr   baser   r   r"   rK   rQ   r    r   r   <module>rT      s7      ! *8(/ 8(vV 
r   