o
    h
                     @   s   d dl Z d dlmZ d dlmZ dgZdddZedd	Zed
dZeddZ	eddZ
dd Zdee dee dee fddZdeeef deddfddZdS )    N)repeat)Any'consume_prefix_in_state_dict_if_presentparsec                    s    fdd}||_ |S )Nc                    s$   t | tjjrt| S tt|  S N)
isinstancecollectionsabcIterabletupler   )xn j/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/torch/nn/modules/utils.pyr      s   z_ntuple.<locals>.parse)__name__)r   namer   r   r   r   _ntuple
   s   r      _single   _pair   _triple   
_quadruplec                    s   t  fddt| D S )zReverse the order of `t` and repeat each element for `n` times.

    This can be used to translate padding arg used by Conv and Pooling modules
    to the ones used by `F.pad`.
    c                 3   s"    | ]}t  D ]}|V  qqd S r   )range).0r   _r   r   r   	<genexpr>    s     z(_reverse_repeat_tuple.<locals>.<genexpr>)r   reversed)tr   r   r   r   _reverse_repeat_tuple   s   r"   out_sizedefaultsreturnc                 C   sd   dd l }t| t|jfr| S t|t| kr!tdt| d  dd t| |t|  d  D S )Nr   z#Input dimension should be at least r   c                 S   s    g | ]\}}|d ur|n|qS r   r   )r   vdr   r   r   
<listcomp>*   s    z&_list_with_default.<locals>.<listcomp>)torchr   intSymIntlen
ValueErrorzip)r#   r$   r)   r   r   r   _list_with_default#   s   r/   
state_dictprefixc                 C   s   t |  }|D ]}||r|t|d }| || |< qt| drUt | j }|D ])}t|dkr6q-||ddksC||rT|t|d }| j|| j|< q-dS dS )a  Strip the prefix in state_dict in place, if any.

    .. note::
        Given a `state_dict` from a DP/DDP model, a local model can load it by applying
        `consume_prefix_in_state_dict_if_present(state_dict, "module.")` before calling
        :meth:`torch.nn.Module.load_state_dict`.

    Args:
        state_dict (OrderedDict): a state-dict to be loaded to the model.
        prefix (str): prefix.
    N	_metadatar   . )listkeys
startswithr,   pophasattrr2   replace)r0   r1   r6   keynewkeyr   r   r   r   /   s"   

)r   )r   	itertoolsr   typingr   __all__r   r   r   r   r   r"   r5   r*   r/   dictstrr   r   r   r   r   <module>   s$   





"	
