o
    iO	                     @   s   d dl Z d dlmZ d dlmZmZ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)ListDict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 e/var/www/html/eduruby.in/lip-sync/lip-sync-env/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   sV   t | tr| S t|t| krtdt| d  dd t| |t|  d  D S )Nz#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>)r	   intlen
ValueErrorzip)r%   r&   r   r   r   _list_with_default!   s   
r/   
state_dictprefixc                 C   s   t |  }|D ]}||r|t|d }| || |< qd| v rF| d }t| D ]}t|dkr6q-|t|d }||||< 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   )sortedkeys
startswithr,   poplist)r0   r1   r4   keyZnewkeymetadatar   r   r   r   -   s   
)r   )r
   	itertoolsr   typingr   r   r   __all__r   r   r   r   r   r$   r+   r/   strr   r   r   r   r   <module>   s$    



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