Ë
    ÿÍ:jU  ã                   ó  — d dl Z d dlZd dlmZmZ d dlmZ d dlZd dlm	Z	 d dl
mZmZ  e j                  e«      Zdefd„Zdedefd	„Zed
k(  r? e«       Z ee«      Z eej(                  «      Z ej,                  eej.                  «       yy)é    N)ÚArgumentParserÚ	Namespace)ÚPath)Ú_TORCH_GREATER_EQUAL_2_3)Ú_METADATA_FILENAMEÚ_load_distributed_checkpointÚreturnc                  óš   — t        d¬«      } | j                  dt        d¬«       | j                  dt        d¬«       | j                  «       S )NzšConverts a distributed/sharded checkpoint into a single file that can be loaded with `torch.load()`. Only supports FSDP sharded checkpoints at the moment.)ÚdescriptionÚcheckpoint_folderzxPath to a checkpoint folder, containing the sharded checkpoint files saved using the `torch.distributed.checkpoint` API.)ÚtypeÚhelpz--output_filezçPath to the file where the converted checkpoint should be saved. The file should not already exist. If no path is provided, the file will be saved next to the input checkpoint folder with the same name and a '.consolidated' suffix.)r   Úadd_argumentÚstrÚ
parse_args)Úparsers    ú†/home/mcse/projects/srt_converter/srt-converter-venv/lib/python3.12/site-packages/lightning_fabric/utilities/consolidate_checkpoint.pyÚ_parse_cli_argsr      sc   € ÜðEô€Fð ×ÑØÜð3ð	 ô ð ×ÑØÜð-ð	 ô ð ×ÑÓÐó    Úargsc                 ó  — t         s*t        j                  d«       t        j                  d«       t        | j                  «      }|j                  «       s-t        j                  d|› �«       t        j                  d«       |j                  «       s-t        j                  d|› �«       t        j                  d«       |t        z  j                  «       s-t        j                  d|› �«       t        j                  d«       | j                  €|j                  |j                  dz   «      }nt        | j                  «      }|j                  «       r-t        j                  d|› �«       t        j                  d«       t        ||¬«      S )	Nz;Processing distributed checkpoints requires PyTorch >= 2.3.é   z/The provided checkpoint folder does not exist: zQThe provided checkpoint path must be a folder, containing the checkpoint shards: zOnly FSDP-sharded checkpoints saved with Lightning are supported for consolidation. The provided folder is not in that format: z.consolidatedzŠThe path for the converted checkpoint already exists. Choose a different path by providing `--output_file` or move/delete the file first: )r   Úoutput_file)r   Ú_logÚerrorÚsysÚexitr   r   ÚexistsÚis_dirr   Úis_filer   Úwith_suffixÚsuffixr   )r   r   r   s      r   Ú_process_cli_argsr#   )   sB  € Ý#Ü�
‰
ÐPÔQÜ�‰�Œä˜T×3Ñ3Ó4ÐØ×#Ñ#Ô%Ü�
‰
ÐDÐEVÐDWÐXÔYÜ�‰�ŒØ×#Ñ#Ô%Ü�
‰
Ø_Ð`qÐ_rÐsô	
ô 	�‰�ŒØÔ 2Ñ2×;Ñ;Ô=Ü�
‰
ð'Ø'8Ð&9ð;ô	
ô 	�‰�Œà×ÑÐØ'×3Ñ3Ð4E×4LÑ4LÈÑ4^Ó_‰ä˜4×+Ñ+Ó,ˆØ×ÑÔÜ�
‰
ð?Ø?J¸mðMô	
ô 	�‰�ŒäÐ'8ÀkÔRÐRr   Ú__main__)Úloggingr   Úargparser   r   Úpathlibr   ÚtorchÚ"lightning_fabric.utilities.importsr   Úlightning_fabric.utilities.loadr   r   Ú	getLoggerÚ__name__r   r   r#   r   Úconfigr   Ú
checkpointÚsaver   © r   r   ú<module>r1      s–   ðÛ Û 
ß .Ý ã å Gß \à€w×Ñ˜Ó"€ð˜ó ð6 S˜Ið  S¨)ó  SðF ˆzÒÙÓ€DÙ˜tÓ$€FÙ-¨f×.FÑ.FÓG€JØ€E‡J�Jˆz˜6×-Ñ-Õ.ð	 r   