o
    TÃi  ã                   @   sD   d dl mZ ddlmZ ddlmZmZ dd„ Zdd„ Zd	d
„ Z	dS )é   )ÚRandomLayerTokenDropé    )ÚOrderedDict)Úrecursive_getattrÚrecursive_setattrc                 C   s\   t | dƒr	| j}n| }| ¡ D ]\}}t||ƒr't||ƒ}t|ƒ}t|||ƒ q|  ¡  | S ©NÚmodule)Úhasattrr   Únamed_modulesÚ
isinstancer   r   r   Úrandom_ltd_initialize)ÚmodelÚconvert_typeÚc_modelÚnamer   Ú
old_moduleÚ
new_module© r   úg/home/ubuntu/.local/lib/python3.10/site-packages/deepspeed/runtime/data_pipeline/data_routing/helper.pyÚconvert_to_random_ltd   s   


€r   c                 C   s&   t | dƒr	| j}n| }| ¡ }t|ƒS r   )r	   r   Ú
state_dictÚremove_random_ltd_state_dict)r   r   Ú	model_dicr   r   r   Úsave_without_random_ltd   s
   
r   c                 C   sB   t ƒ }|  ¡ D ]\}}d|v rd | d¡¡}n|}|||< q|S )Nz.random_ltd_layerÚ )r   ÚitemsÚjoinÚsplit)r   Únew_state_dictÚkeyÚvalueÚnew_keyr   r   r   r   &   s   
r   N)
Úbasic_layerr   Úcollectionsr   Údeepspeed.compression.helperr   r   r   r   r   r   r   r   r   Ú<module>   s   
