o
    ‡ZŽho  ã                   @   st   d dl Z dd„ Zeƒ re j ¡ sedƒ‚eƒ r1d dlmZmZmZm	Z	m
Z
mZmZmZmZmZmZ G dd„ dƒZdS )é    Nc                   C   s   t tjdƒS )NÚ_dist_autograd_init)ÚhasattrÚtorchÚ_C© r   r   úR/var/www/auris/lib/python3.10/site-packages/torch/distributed/autograd/__init__.pyÚis_available   s   r   z/Failed to initialize torch.distributed.autograd)Ú_current_contextÚ_get_debug_infoÚ_get_max_idÚ_initÚ_is_valid_contextÚ_new_contextÚ_release_contextÚ_retrieve_contextÚbackwardÚDistAutogradContextÚget_gradientsc                   @   s    e Zd ZdZdd„ Zdd„ ZdS )Úcontexta!  
    Context object to wrap forward and backward passes when using
    distributed autograd. The ``context_id`` generated in the ``with``
    statement  is required to uniquely identify a distributed backward pass
    on all workers. Each worker stores metadata associated with this
    ``context_id``, which is required to correctly execute a distributed
    autograd pass.

    Example::
        >>> # xdoctest: +SKIP
        >>> import torch.distributed.autograd as dist_autograd
        >>> with dist_autograd.context() as context_id:
        >>>     t1 = torch.rand((3, 3), requires_grad=True)
        >>>     t2 = torch.rand((3, 3), requires_grad=True)
        >>>     loss = rpc.rpc_sync("worker1", torch.add, args=(t1, t2)).sum()
        >>>     dist_autograd.backward(context_id, [loss])
    c                 C   s   t ƒ | _| j ¡ S ©N)r   Úautograd_contextÚ_context_id)Úselfr   r   r   Ú	__enter__0   s   
zcontext.__enter__c                 C   s   t | j ¡ ƒ d S r   )r   r   r   )r   ÚtypeÚvalueÚ	tracebackr   r   r   Ú__exit__4   s   zcontext.__exit__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r      s    r   )r   r   r   r   ÚRuntimeErrorZtorch._C._distributed_autogradr	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   Ú<module>   s   4