
    biS	                     N    d dl mZ d dlmZ dZd Zd	dZd Zedk(  r e        yy)
    )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                 r    t        | j                  | j                  | j                   | j                         y N)r   checkpoint_directoryoutput_pathunsafe_serializationremove_checkpoint_dir)argss    T/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/accelerate/commands/merge.pymerge_commandr      s/    !!4#3#39R9R5RTXTnTn    Nc                 >   | | j                  dt              }nt        t              }|j                  dt        d       |j                  dt        d       |j                  dd	d
d       |j                  dd	dd
       | |j                  t               |S )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    t               } | j                         }t        |       y 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   