
    ;iS	                     R    S SK Jr  S SKJr  SrS rS	S jrS r\S:X  a  \" 5         gg)
    )CustomArgumentParser)merge_fsdp_weightsa!  Utility to merge the weights from multiple FSDP checkpoints into a single combined checkpoint. Should be used if
`SHARDED_STATE_DICT` was used for the model. Weights will be saved to `{output_path}`.

This is a CPU-bound process and requires enough RAM to load the entire model state dict.c                 z    [        U R                  U R                  U R                  (       + U R                  5        g N)r   checkpoint_directoryoutput_pathunsafe_serializationremove_checkpoint_dir)argss    i/home/dmtnaga/Documents/work/airagagent/rag_env/lib/python3.13/site-packages/accelerate/commands/merge.pymerge_commandr      s/    !!4#3#39R9R5RTXTnTn    Nc                    U b  U R                  S[        S9nO[        [        S9nUR                  S[        SS9  UR                  S[        SS9  UR                  SS	S
SS9  UR                  SS	SS
S9  U b  UR                  [        S9  U$ )Nzmerge-weights)descriptionr   z5A directory containing sharded weights saved by FSDP.)typehelpr   zHThe path to save the merged weights. Defaults to the current directory. z--unsafe_serialization
store_trueFzZWhether to save the merged weights as `.bin` rather than `.safetensors` (not recommended).)actiondefaultr   z--remove_checkpoint_dirz9Whether to remove the checkpoint directory after merging.)r   r   r   )func)
add_parserr   r   add_argumentstrset_defaultsr   )
subparsersparsers     r   merge_command_parserr       s    &&K&P%+>
.S?vw
W  
  i	   !H	   /Mr   c                  N    [        5       n U R                  5       n[        U5        g r   )r   
parse_argsr   )r   r   s     r   mainr    >   s     !#FD$r   __main__r   )	accelerate.commands.utilsr   accelerate.utilsr   r   r   r   r    __name__ r   r   <module>r&      s8     ; /\< zF r   