a
    ßñh©  ã                   @   sL   d dl mZ d dlZd dlZd dlmZ G dd„ deƒZdd„ Zdd	„ Z	dS )
é    )ÚOrderedDictN)ÚAnyc                   @   s|   e Zd ZU dZeed< dZeed< eddœdd„Zdd	œd
d„Z	dd„ Z
dd	œdd„Zd d	œdd„Zeeeddœdd„ZdS )ÚRemovableHandlez8A handle which provides the capability to remove a hook.Úidr   Únext_idN)Ú
hooks_dictÚreturnc                 C   s&   t  |¡| _tj| _t jd7  _d S )Né   )ÚweakrefÚrefÚhooks_dict_refr   r   r   ©Úselfr   © r   úQ/home/yuhw/wc/uboone-dl-vtx/venv/lib/python3.9/site-packages/torch/utils/hooks.pyÚ__init__   s    zRemovableHandle.__init__)r   c                 C   s&   |   ¡ }|d ur"| j|v r"|| j= d S ©N©r   r   r   r   r   r   Úremove   s    zRemovableHandle.removec                 C   s   |   ¡ | jfS r   r   ©r   r   r   r   Ú__getstate__   s    zRemovableHandle.__getstate__c                 C   sN   |d d u rt  tƒ ¡| _nt  |d ¡| _|d | _ttj| jd ƒt_d S )Nr   r	   )r
   r   r   r   r   Úmaxr   r   )r   Ústater   r   r   Ú__setstate__   s
    
zRemovableHandle.__setstate__c                 C   s   | S r   r   r   r   r   r   Ú	__enter__#   s    zRemovableHandle.__enter__)ÚtypeÚvalueÚtbr   c                 C   s   |   ¡  d S r   )r   )r   r   r   r   r   r   r   Ú__exit__&   s    zRemovableHandle.__exit__)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚintÚ__annotations__r   r   r   r   r   r   r   r   r   r   r   r   r      s   
	r   c                 C   s
   d| _ | S )z·
    Decorator which marks a function as an unserializable hook.
    This suppresses warnings that would otherwise arise if you attempt
    to serialize a tensor that has a hook.
    T)Ú__torch_unserializable__)Úfr   r   r   Úunserializable_hook*   s    r'   c                 C   s>   | j r:| j D ],}| j | }t|dƒst d t|ƒ¡¡ qd S )Nr%   z«backward hook {} on tensor will not be serialized.  If this is expected, you can decorate the function with @torch.utils.hooks.unserializable_hook to suppress this warning)Z_backward_hooksÚhasattrÚwarningsÚwarnÚformatÚrepr)ZtensorÚkÚhookr   r   r   Úwarn_if_has_hooks4   s    


ýr/   )
Úcollectionsr   r
   r)   Útypingr   Úobjectr   r'   r/   r   r   r   r   Ú<module>   s   #
