U
    *-e                     @   s   U d Z ddlmZmZmZ ddlZddlmZ ddlmZm	Z	 dgZ
ee ed< i Zeeejef ef ed	< ejeed
ddZdS )z<Provides phony for arbitrary dependency in a autograd graph.    )DictListTupleN)Tensor   )default_stream
use_stream	get_phony__all___phonies)devicerequires_gradreturnc                C   s^   | |f}zt | }W nD tk
rX   tt|  tjd| |d}W 5 Q R X |t |< Y nX |S )a  Gets a phony. Phony is tensor without space. It is useful to make
    arbitrary dependency in a autograd graph because it doesn't require any
    gradient accumulation.

    .. note::

        Phonies for each device are cached. If an autograd function gets a phony
        internally, the phony must be detached to be returned. Otherwise, the
        autograd engine will mutate the cached phony in-place::

            class Phonify(torch.autograd.Function):
                @staticmethod
                def forward(ctx, input):
                    phony = get_phony(input.device, requires_grad=False)
                    return phony.detach()  # detach() is necessary.

    r   )r   r   )r   KeyErrorr   r   torchempty)r   r   keyZphony r   f/var/www/html/Darija-Ai-Train/env/lib/python3.8/site-packages/torch/distributed/pipeline/sync/phony.pyr	      s    )__doc__typingr   r   r   r   r   streamr   r   r
   str__annotations__r   r   boolr	   r   r   r   r   <module>   s   