Ë
    ÛÓ^j£  ã                   ód   — d dl Z d dlZd dlmZmZ ddlmZ  e«       rd dlZe G d„ d«      «       Zy)é    N)ÚasdictÚ	dataclassé   )Úis_torch_availablec                   óô   — e Zd ZU dZdZedz  ed<   dZee	e	f   dz  ed<   dZ
eed<   dZeed<   dZedz  ed<   dZeed	<   dZeed
<   d„ Zededd fd„«       Zdefd„Zde	fd„Zde	ej,                  z  fd„Zd„ Zy)ÚDistributedConfigaK  
    Configuration for native distributed training (FSDP2 + TP).

    Args:
        tp_size (`int`, *optional*):
            Number of devices for tensor parallelism. If `None` and `fsdp_size` is set, defaults to 1.
        tp_plan (`dict`, *optional*):
            Tensor parallel sharding plan. Leave as `None` to use the model's `base_model_tp_plan`.
            Set explicitly to override.
        enable_sequence_parallel (`bool`, *optional*, defaults to `False`):
            Reserved for sequence parallelism. Not wired up yet.
        enable_expert_parallel (`bool`, *optional*, defaults to `False`):
            Route MoE models through the expert-parallel path (``base_model_ep_plan``).
        fsdp_size (`int`, *optional*):
            Number of devices for FSDP (data parallelism). If `None` and `tp_size` is set, defaults to 1.
        fsdp_cpu_offload (`bool`, *optional*, defaults to `False`):
            Whether to enable CPU offloading for FSDP2.
        fsdp_mixed_precision (`bool`, *optional*, defaults to `False`):
            Whether to enable mixed precision for FSDP2.
    NÚtp_sizeÚtp_planFÚenable_sequence_parallelÚenable_expert_parallelÚ	fsdp_sizeÚfsdp_cpu_offloadÚfsdp_mixed_precisionc           	      óÄ  — | j                   €| j                  €y | j                   €d| _         | j                  €d| _        t        j                  j	                  «       rƒt        j                  j                  «       rdt        j                  j                  «       }| j                   | j                  z  |k7  r)t        d| j                   › d| j                  › d|› d�«      ‚y y y )Né   z	tp_size (z) * fsdp_size (z) is not equal to world_size (ú))r	   r   ÚtorchÚdistributedÚis_availableÚis_initializedÚget_world_sizeÚRuntimeError)ÚselfÚ
world_sizes     úw/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/transformers/distributed/configuration_utils.pyÚ__post_init__zDistributedConfig.__post_init__9   sÆ   € Ø�<‰<Ð D§N¡NÐ$:Øà�<‰<ÐØˆDŒLØ�>‰>Ð!ØˆDŒNä×Ñ×)Ñ)Ô+´×0AÑ0A×0PÑ0PÔ0RÜ×*Ñ*×9Ñ9Ó;ˆJØ�|‰|˜dŸn™nÑ,°
Ò:Ü"Ø §¡˜~¨_¸T¿^¹^Ð<LÐLjÐkuÐjvÐvwÐxóð ð ;ð 1SÐ+ó    Úconfig_dictÚreturnc           
      óä   — i |¥|¥}| j                   j                  «       D �ch c]  }|j                  ’Œ }} | di |j                  «       D ��ci c]  \  }}||v sŒ||“Œ c}}¤ŽS c c}w c c}}w )N© )Ú__dataclass_fields__ÚvaluesÚnameÚitems)Úclsr   ÚkwargsÚmergedÚfÚ
valid_keysÚkÚvs           r   Ú	from_dictzDistributedConfig.from_dictI   sm   € à*�KÐ* 6Ð*ˆØ&)×&>Ñ&>×&EÑ&EÓ&GÖH �a—f“fÐHˆ
ÐHÙÑJ v§|¡|£~×I™t˜q !¸¸jº�a˜‘dÓIÑJÐJùò IùÛIs   £A'ÁA,ÁA,c                 ó   — t        | «      S )N)r   ©r   s    r   Úto_dictzDistributedConfig.to_dictO   s   € Ü�d‹|Ðr   c                 óR   — t        j                  | j                  «       d¬«      dz   S )Nr   )Úindentú
)ÚjsonÚdumpsr0   r/   s    r   Úto_json_stringz DistributedConfig.to_json_stringR   s   € Ü�z‰z˜$Ÿ,™,›.°Ô3°dÑ:Ð:r   Újson_file_pathc                 óˆ   — t        |dd¬«      5 }|j                  | j                  «       «       d d d «       y # 1 sw Y   y xY w)NÚwzutf-8)Úencoding)ÚopenÚwriter6   )r   r7   r)   s      r   Úto_json_filezDistributedConfig.to_json_fileU   s:   € Ü�. #°Ô8ð 	+¸AØ�G‰G�D×'Ñ'Ó)Ô*÷	+÷ 	+ñ 	+ús	   � 8¸Ac                 óT   — | j                   j                  › d| j                  «       › �S )Nú )Ú	__class__Ú__name__r6   r/   s    r   Ú__repr__zDistributedConfig.__repr__Y   s(   € Ø—.‘.×)Ñ)Ð*¨!¨D×,?Ñ,?Ó,AÐ+BÐCÐCr   )rA   Ú
__module__Ú__qualname__Ú__doc__r	   ÚintÚ__annotations__r
   ÚdictÚstrr   Úboolr   r   r   r   r   Úclassmethodr-   r0   r6   ÚosÚPathLiker=   rB   r!   r   r   r   r      sÇ   … ñð* €GˆS�4‰ZÓØ%)€GˆT�#�s�(‰^˜dÑ"Ó)Ø%*Ð˜dÓ*Ø#(Ð˜DÓ(Ø €Iˆs�T‰zÓ Ø"Ð�dÓ"Ø!&Ð˜$Ó&òð  ðK Dð KÐ7Jò Kó ðKð
˜ó ð; ó ;ð+¨3°·±Ñ+<ó +óDr   r   )	r4   rL   Údataclassesr   r   Úutilsr   r   r   r!   r   r   ú<module>rP      s:   ðó Û 	ß )å &ñ ÔÛð ÷?Dð ?Dó ñ?Dr   