o
    IÆ&i!  ã                   @   sX   d dl Z d dlmZ ddlmZ G dd„ dƒZG dd„ deƒZd	d
„ Zdd„ Zeƒ  dS )é    N)ÚOptionalé   )ÚVariableTrackerc                   @   s    e Zd ZdZdd„ Zdd„ ZdS )Ú	LazyCachez+Container to cache the real VariableTrackerc                 C   s   |sJ ‚|| _ || _d | _d S ©N)ÚvalueÚsourceÚvt)Úselfr   r   © r   úGC:\wamp64\www\opt\env\Lib\site-packages\torch/_dynamo/variables/lazy.pyÚ__init__
   s   
zLazyCache.__init__c                 C   s\   | j d u sJ ‚ddlm} ddlm} | ¡ }||| jƒ| jƒ| _ | j j 	|¡ | `| `d S )Né   )ÚInstructionTranslatorr   )ÚVariableBuilder)
r	   Zsymbolic_convertr   Zbuilderr   Z
current_txr   r   Úparents_trackerÚadd)r
   r   r   r   Ztxr   r   r   Úrealize   s   zLazyCache.realizeN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r      s    r   c                       s†   e Zd ZdZdhej£Zedd„ ƒZ‡ fdd„Zdefdd	„Z	d
d„ Z
dd„ Zdd„ Zdd„ Zdd„ ZejZejZejZejZ‡  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                 K   s   t t| |ƒfd|i|¤ŽS )Nr   )r   r   )r   r   Úoptionsr   r   r   Úcreate,   s   zLazyVariableTracker.createc                    s*   t |tƒsJ ‚tƒ jdi |¤Ž || _d S )Nr   )Ú
isinstancer   Úsuperr   r   )r
   r   Úkwargs©Ú	__class__r   r   r   0   s   
zLazyVariableTracker.__init__Úreturnc                 C   s"   | j jdu r| j  | j¡ | j jS )z.Force construction of the real VariableTrackerN)r   r	   r   r   ©r
   r   r   r   r   5   s   zLazyVariableTracker.realizec                 C   s   |   ¡ r| jjS | S )z4Return the real VariableTracker if it already exists)Úis_realizedr   r	   r"   r   r   r   Úunwrap;   s   zLazyVariableTracker.unwrapc                 C   s   | j jd uS r   )r   r	   r"   r   r   r   r#   A   s   zLazyVariableTracker.is_realizedc                 K   sJ   |  d| j¡| ju sJ ‚|  d| j¡| jur|  ¡  tj|  ¡ fi |¤ŽS )Nr   r   )Úgetr   r   r   r   Úcloner$   )r
   r   r   r   r   r&   D   s   zLazyVariableTracker.clonec                 C   s   t  |  ¡ ¡S r   )r   Ú__str__r$   r"   r   r   r   r'   J   ó   zLazyVariableTracker.__str__c                 C   s   t |  ¡ |ƒS r   ©Úgetattrr   )r
   Úitemr   r   r   Ú__getattr__M   r(   zLazyVariableTracker.__getattr__)r   r   r   r   r   Z_nonvar_fieldsÚstaticmethodr   r   r   r$   r#   r&   r'   r,   ÚapplyÚcopyÚ__post_init__Ú__repr__Ú__classcell__r   r   r   r   r      s     
r   c                    s    t  ttˆ ƒ¡‡ fdd„ƒ}|S )Nc                    s   t |  ¡ ˆ ƒ|i |¤ŽS r   r)   )r
   Úargsr   ©Únamer   r   Úrealize_and_forwardX   s   z8_create_realize_and_forward.<locals>.realize_and_forward)Ú	functoolsÚwrapsr*   r   )r5   r6   r   r4   r   Ú_create_realize_and_forwardW   s   r9   c                  C   s:   t j ¡ D ]\} }| tjvrt|ƒrtt| t| ƒƒ qd S r   )r   Ú__dict__Úitemsr   ÚcallableÚsetattrr9   )r5   r   r   r   r   Ú	_populate_   s   
€ýr>   )	r7   Útypingr   Úbaser   r   r   r9   r>   r   r   r   r   Ú<module>   s    ;
