o
    0iS	                     @   sL   d dl mZ d dlmZ dZdd ZdddZd	d
 Zedkr$e  dS dS )    )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                 C   s   t | j| j| j | j d S N)r   checkpoint_directoryoutput_pathunsafe_serializationremove_checkpoint_dir)args r
   [/sda-disk/www/egybert/egybert_env/lib/python3.10/site-packages/accelerate/commands/merge.pymerge_command   s   r   Nc                 C   s~   | d ur| j dtd}nttd}|jdtdd |jdtdd |jdd	d
dd |jdd	dd
d | d ur=|jtd |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parserr
   r
   r   merge_command_parser    s0   
r   c                  C   s   t  } |  }t| d S r   )r   
parse_argsr   )r   r	   r
   r
   r   main>   s   r   __main__r   )	accelerate.commands.utilsr   accelerate.utilsr   r   r   r   r   __name__r
   r
   r
   r   <module>   s   

