
    ɯwg                     \    d dl Zd dlmZmZ ddlmZmZ ddefdZ	ddZ
d Zd	 Zdd
Zd Zy)    N)tree_flattentree_unflatten   )add_step_closurerun_step_closuresdevicec                 p    t         j                  j                  j                  | g |       t	                y)aV  Triggers a mark step, which amounts to
    - collecting a group of 'live' lazy tensors to index into the compilation cache
      (lowering/compiling their IR graphs if not cached)
    - kicking off execution of the compiled function
    - (optionally, wait=True) waiting for cpu-side execution to complete (does not sync the accelerator)
    )waitN)torch_C_lazy
_mark_stepr   )r   r
   s     Y/home/mcse/projects/flask/flask-venv/lib/python3.12/site-packages/torch/_lazy/__init__.py	mark_stepr   	   s'     
HHNNfbt4    c                 `    | g } t         j                  j                  j                  |        y)zWaits for all the async operations on the given devices to complete.
    Args:
      devices (string..., optional): The devices whose async ops need to be waited
        for. If empty, all the local devices will be waited for.
    Ndevices)r   r   r   _wait_device_opsr   s    r   wait_device_opsr      s'     	HHNN##G#4r   c                 X    t         j                  j                  j                  | |       y)z
    Sync the list of lazy tensors so there IR get lowered for the activate backend
    and the compiled computation graph get cached.
    N)r   r   r   _sync_multi)tensorsr   s     r   
sync_multir   !   s    
 
HHNNw0r   c                 T    t         j                  j                  j                  |       S )z7Return a unique id of the lazy tensor maintained by LTC)r   r   r   _get_tensor_id)tensors    r   get_tensor_idr   )   s    88>>((00r   c                     |xs dg}t        |       \  }}t        ||       t        |D cg c]  }|j                  d       c}|      S c c}w )Nlazycpu)r   r   r   to)r   r   	flattenedspects        r   to_cpur&   .   sI    !&G"7+OIty'"	:1144;:DAA:s   Ac                 H    t        j                  t        |       g|i | y N)r   saver&   )r   argskwargss      r   r)   r)   6   s    	JJvg000r   ) Fr(   )torch._C._lazyr   torch.utils._pytreer   r   closurer   r   strr   r   r   r   r&   r)    r   r   <module>r2      s6     < 8
c 
511
B1r   