U
    yh                     @   sp   d dl Z d dlZd dlmZmZ ddlmZmZ de	ddd	Z
dd
dZdd Zdd ZdddZdd ZdS )    N)tree_flattentree_unflatten   )add_step_closurerun_step_closures F)devicec                 C   s   t jjj| g |d t  dS )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_lazyZ
_mark_stepr   )r   r	    r   F/var/www/html/venv/lib/python3.8/site-packages/torch/_lazy/__init__.py	mark_step
   s    r   c                 C   s    | dkrg } t jjj| d dS )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   Z_wait_device_opsr   r   r   r   wait_device_ops   s    r   c                 C   s   t jj| | dS )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   Z_sync_multi)tensorsr   r   r   r   
sync_multi"   s    r   c                 C   s   t jj| S )z7Return a unique id of the lazy tensor maintained by LTC)r
   r   r   Z_get_tensor_id)Ztensorr   r   r   get_tensor_id*   s    r   c                 C   s4   |pdg}t | \}}t|| tdd |D |S )NZlazyc                 S   s   g | ]}| d qS )cpu)to).0tr   r   r   
<listcomp>4   s     zto_cpu.<locals>.<listcomp>)r   r   r   )r   r   Z	flattenedspecr   r   r   to_cpu/   s    

r   c                 O   s   t jt| f|| d S )N)r
   saver   )r   argskwargsr   r   r   r   7   s    r   )r   F)N)N)	threadingZtorch._C._lazyr
   Ztorch.utils._pytreer   r   closurer   r   strr   r   r   r   r   r   r   r   r   r   <module>   s   

