
    wiw	                     J    d dl mZ d dlZ G d dej        j                  ZdS )    )DictNc                   >     e Zd Zdeeej        f         f fdZ xZS )AttnProcsLayers
state_dictc                     t                                                       t          j                            |                                           _        t          t          |	                                                     _
        d t          |	                                          D              _        ddg _        d } fdfd}                     |                                |d           d S )	Nc                     i | ]\  }}||	S  r	   ).0kvs      g/root/.openclaw/workspace/chatterbox_venv_py311/lib/python3.11/site-packages/diffusers/loaders/utils.py
<dictcomp>z,AttnProcsLayers.__init__.<locals>.<dictcomp>   s    JJJTQAqJJJ    z
.processorz
.self_attnc                     i }|                                 D ]V\  }}t          |                    d          d                   }|                    d| | j        |                   }|||<   W|S )N.   layers.)itemsintsplitreplacemapping)	moduler   argskwargsnew_state_dictkeyvaluenumnew_keys	            r   map_toz(AttnProcsLayers.__init__.<locals>.map_to    su    N(..00 0 0
U#))C..+,,++ooov~c7JKK*/w''!!r   c           	          j         D ]&}|| v r |                     |          d         |z   c S 't          dt          |                                           d|  dj          d          )Nr   z1There seems to be a problem with the state_dict: z. z has to have one of r   )
split_keysr   
ValueErrorsetkeys)r   r   r   selfs      r   	remap_keyz+AttnProcsLayers.__init__.<locals>.remap_key)   s    _ / /8899Q<<?Q....   JC
HYHYDZDZ  J  J^a  J  Jw{  xG  J  J  J  r   c                     t          |                                          }|D ]@} ||          }|                    |d| j        |                    }||         ||<   ||= Ad S )Nr   )listr&   r   rev_mapping)	r   r   r   r   all_keysr   replace_keyr    r(   s	           r   map_fromz*AttnProcsLayers.__init__.<locals>.map_from2   s    JOO--..H $ $'iZ88++k3^V=OP[=\3^3^__&0o
7#sOO	$ $r   T)with_module)super__init__torchnn
ModuleListvalueslayersdict	enumerater&   r   r+   r#   _register_state_dict_hook"_register_load_state_dict_pre_hook)r'   r   r!   r.   r(   	__class__s   `   @r   r1   zAttnProcsLayers.__init__   s   h))**;*;*=*=>>Ijoo&7&78899JJYz7H7H-I-IJJJ (6	" 	" 	"	 	 	 	 		$ 	$ 	$ 	$ 	$ 	&&v...//d/KKKKKr   )	__name__
__module____qualname__r   strr2   Tensorr1   __classcell__)r;   s   @r   r   r      s[        &L4U\(9#: &L &L &L &L &L &L &L &L &L &Lr   r   )typingr   r2   r3   Moduler   r	   r   r   <module>rD      sd          'L 'L 'L 'L 'Leho 'L 'L 'L 'L 'Lr   