o
    h                     @   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	< d
ejdedef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   sp   | |f}zt | }W |S  ty7   tt|  tjd| |d}W d   n1 s+w   Y  |t |< Y |S w )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   N)r   KeyErrorr   r   torchempty)r   r   keyphony r   [/var/www/html/ai/venv/lib/python3.10/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   