U
    ©Ê¹j  ã                   @   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   úd/var/www/html/bwave/python/venv/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   