§
    9²¸j  ã                   ó\   — d dl Z d dlZd dlmZmZ d dlmZ e G d„ d¦  «        ¦   «         ZdS )é    N)ÚasdictÚ	dataclass)ÚLiteralc                   ó  — e Zd ZU dZdZedz  ed<   dZee	e	f         e
d         z  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z  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dS )ÚDistributedConfigaÑ  
    Configuration for native distributed inference and training with tensor, pipeline, or FSDP2 parallelism.

    Args:
        tp_size (`int`, *optional*):
            Number of devices for tensor parallelism. If `None` and `tp_plan` is set, defaults to
            `WORLD_SIZE // (other_parallel_size)`. If `None` and no `tp_plan` is set, defaults to 1.
        tp_plan (`dict[str, str]` or `"auto"`, *optional*):
            Tensor parallel sharding plan. Pass `"auto"`, or leave as `None` when `tp_size` is set, to use the
            model's predefined `base_model_tp_plan`. Pass a dictionary to override the predefined plan.
        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.
        pp_size (`int`, *optional*):
            Number of devices for pipeline parallelism. If `None` and another parallel mode is set, defaults to 1.
    NÚtp_sizeÚautoÚtp_planFÚenable_sequence_parallelÚenable_expert_parallelÚ	fsdp_sizeÚfsdp_cpu_offloadÚfsdp_mixed_precisionÚpp_sizec                 óæ  — | j         €| j        €| j        €	| j        €d S | j        €d| _        | j        €d| _        | j        €m| j         �ft	          t
          j                             dd¦  «        ¦  «        }| j        | j        z  }||z  dk    rt          d|› d|› d�¦  «        ‚||z  | _        n| j        €d| _        | j        dk    r%| j        dk    r| j        dk    rt          d¦  «        ‚d S d S d S )Né   Ú
WORLD_SIZEr   zWORLD_SIZE (z,) must be divisible by fsdp_size * pp_size (z) to derive tp_size.z¹FSDP+TP+PP is not supported yet. Use DistributedConfig(fsdp_size=N) or DistributedConfig(tp_size=N) or DistributedConfig(pp_size=N), not all three. Only 1D support is available for now.)	r
   r   r   r   ÚintÚosÚenvironÚgetÚ
ValueError)ÚselfÚ
world_sizeÚother_parallel_sizes      ú|/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/transformers/distributed/configuration_utils.pyÚ__post_init__zDistributedConfig.__post_init__8   s;  € ØŒ<Ð D¤LÐ$8¸T¼^Ð=SÐX\ÔXdÐXlØˆFàŒ>Ð!ØˆDŒNØŒ<ÐØˆDŒLØŒ<Ð D¤LÐ$<Ý�RœZŸ^š^¨L¸!Ñ<Ô<Ñ=Ô=ˆJØ"&¤.°4´<Ñ"?ÐØÐ/Ñ/°1Ò4Ð4Ý ðB :ð Bð BØ+ðBð Bð Bñô ð ð &Ð)<Ñ<ˆDŒLˆLØŒ\Ð!ØˆDŒLàŒ<˜!ÒÐ ¤°Ò 2Ð 2°t´|ÀaÒ7GÐ7GÝð8ñô ð ð ÐÐ 2Ð 2Ð7GÐ7Gó    Úconfig_dictÚreturnc                 ó¢   ‡— i |¥|¥}d„ | j                              ¦   «         D ¦   «         Š | di ˆfd„|                     ¦   «         D ¦   «         ¤ŽS )Nc                 ó   — h | ]	}|j         ’Œ
S © )Úname)Ú.0Úfs     r   ú	<setcomp>z.DistributedConfig.from_dict.<locals>.<setcomp>V   s   € ÐHÐHÐH �a”fÐHÐHÐHr   c                 ó$   •— i | ]\  }}|‰v ¯	||“ŒS r#   r#   )r%   ÚkÚvÚ
valid_keyss      €r   ú
<dictcomp>z/DistributedConfig.from_dict.<locals>.<dictcomp>W   s$   ø€ ÐIÐIÐI™t˜q !¸¸j¸¸�a˜¸¸¸r   r#   )Ú__dataclass_fields__ÚvaluesÚitems)Úclsr   ÚkwargsÚmergedr+   s       @r   Ú	from_dictzDistributedConfig.from_dictS   sg   ø€ à*�KÐ* 6Ð*ˆØHÐH cÔ&>×&EÒ&EÑ&GÔ&GÐHÑHÔHˆ
ØˆsÐJÐJÐIÐIÐIÐI v§|¢|¡~¤~ÐIÑIÔIÐJÐJÐJr   c                 ó    — t          | ¦  «        S )N)r   ©r   s    r   Úto_dictzDistributedConfig.to_dictY   s   € Ý�d‰|Œ|Ðr   c                 óX   — t          j        |                      ¦   «         d¬¦  «        dz   S )Né   )Úindentú
)ÚjsonÚdumpsr6   r5   s    r   Úto_json_stringz DistributedConfig.to_json_string\   s$   € ÝŒz˜$Ÿ,š,™.œ.°Ð3Ñ3Ô3°dÑ:Ð:r   Újson_file_pathc                 óª   — t          |dd¬¦  «        5 }|                     |                      ¦   «         ¦  «         d d d ¦  «         d S # 1 swxY w Y   d S )NÚwzutf-8)Úencoding)ÚopenÚwriter=   )r   r>   r&   s      r   Úto_json_filezDistributedConfig.to_json_file_   s–   € Ý�. #°Ð8Ñ8Ô8ð 	+¸AØ�GŠG�D×'Ò'Ñ)Ô)Ñ*Ô*Ð*ð	+ð 	+ð 	+ñ 	+ô 	+ð 	+ð 	+ð 	+ð 	+ð 	+ð 	+ð 	+øøøð 	+ð 	+ð 	+ð 	+ð 	+ð 	+s   “(AÁAÁAc                 óH   — | j         j        › d|                      ¦   «         › �S )Nú )Ú	__class__Ú__name__r=   r5   s    r   Ú__repr__zDistributedConfig.__repr__c   s'   € Ø”.Ô)ÐCÐC¨D×,?Ò,?Ñ,AÔ,AÐCÐCÐCr   )rH   Ú
__module__Ú__qualname__Ú__doc__r   r   Ú__annotations__r
   ÚdictÚstrr   r   Úboolr   r   r   r   r   r   Úclassmethodr3   r6   r=   r   ÚPathLikerD   rI   r#   r   r   r   r      sx  € € € € € € ðð ð0 €GˆS�4‰ZÐÐÑØ7;€GˆT�#�s�(Œ^˜g fœoÑ-°Ñ4Ð;Ð;Ñ;Ø%*Ð˜dÐ*Ð*Ñ*Ø#(Ð˜DÐ(Ð(Ñ(Ø €Iˆs�T‰zÐ Ð Ñ Ø"Ð�dÐ"Ð"Ñ"Ø!&Ð˜$Ð&Ð&Ñ&Ø€GˆS�4‰ZÐÐÑðð ð ð6 ðK Dð KÐ7Jð Kð Kð Kñ „[ðKð
˜ð ð ð ð ð; ð ;ð ;ð ;ð ;ð+¨3°´Ñ+<ð +ð +ð +ð +ðDð Dð Dð Dð Dr   r   )r;   r   Údataclassesr   r   Útypingr   r   r#   r   r   ú<module>rU      s•   ðð €€€Ø 	€	€	€	Ø )Ð )Ð )Ð )Ð )Ð )Ð )Ð )Ø Ð Ð Ð Ð Ð ð ðNDð NDð NDð NDð NDñ NDô NDñ „ðNDð NDð NDr   