
    bi"                     `    d dl Z d dlZd dlZd dlmZ d dlmZ e G d d                      ZdS )    N)	dataclass)Anyc                       e Zd ZU dZdZeed<   ed             Zde	e
j        z  fdZdee	ef         fdZd	 Zd
 Zd Zd ZdS )DistributedConfigz,
    Base class for distributed configs
    Fenable_expert_parallelc                      | di |}g }|                                 D ];\  }}t          ||          r&t          |||           |                    |           <|D ]}|                    |d           |S )a  
        Constructs a DistributedConfig instance from a dictionary of parameters.
        Args:
            config_dict (Dict[str, Any]): Dictionary containing configuration parameters.
            **kwargs: Additional keyword arguments to override dictionary values.
        Returns:
            DistributedConfig: Instance of DistributedConfig constructed from the dictionary.
        N )itemshasattrsetattrappendpop)clsconfig_dictkwargsconfig	to_removekeyvalues          g/root/projects/butler/venv/lib/python3.11/site-packages/transformers/distributed/configuration_utils.py	from_dictzDistributedConfig.from_dict   s     ##{##	 ,,.. 	& 	&JCvs## &U+++  %%% 	" 	"CJJsD!!!!    json_file_pathc                     t          |dd          5 }|                                 }t          j        |dd          dz   }|                    |           ddd           dS # 1 swxY w Y   dS )	a  
        Save this instance to a JSON file.
        Args:
            json_file_path (`str` or `os.PathLike`):
                Path to the JSON file in which this configuration instance's parameters will be saved.
            use_diff (`bool`, *optional*, defaults to `True`):
                If set to `True`, only the difference between the config instance and the default
                `QuantizationConfig()` is serialized to JSON file.
        wzutf-8)encoding   T)indent	sort_keys
N)opento_dictjsondumpswrite)selfr   writerr   json_strings        r   to_json_filezDistributedConfig.to_json_file4   s     .#888 	&F,,..K*[dKKKdRKLL%%%		& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	&s   AA$$A(+A(returnc                 4    t          j        | j                  S )z
        Serializes this instance to a Python dictionary. Returns:
            `Dict[str, Any]`: Dictionary of all the attributes that make up this configuration instance.
        )copydeepcopy__dict__r&   s    r   r"   zDistributedConfig.to_dictD   s    
 }T]+++r   c              #   l   K   t          j        | j                                                  E d{V  dS )zTallows `dict(obj)` for situations where obj may be a dict or QuantizationConfigMixinN)r,   r-   r.   r
   r/   s    r   __iter__zDistributedConfig.__iter__L   s<      =//5577777777777r   c                 H    | j         j         d|                                  S )N )	__class____name__to_json_stringr/   s    r   __repr__zDistributedConfig.__repr__Q   s'    .)CCD,?,?,A,ACCCr   c                 >    t          j        | j        d          dz   S )z
        Serializes this instance to a JSON formatted string.
        Returns:
            str: JSON formatted string representing the configuration instance.
        r   )r   r    )r#   r$   r.   r/   s    r   r6   z DistributedConfig.to_json_stringT   s      z$-222T99r   c                     g |                                 D ];\  }}t          | |          r&t          | ||                               |           <fd|                                 D             }|S )a  
        Updates attributes of this class instance with attributes from `kwargs` if they match existing attributes,
        returning all the unused kwargs.
        Args:
            kwargs (`Dict[str, Any]`):
                Dictionary of attributes to tentatively update this class.
        Returns:
            `Dict[str, Any]`: Dictionary containing all the key-value pairs that were not used to update the instance.
        c                 $    i | ]\  }}|v	||S r	   r	   ).0r   r   r   s      r   
<dictcomp>z,DistributedConfig.update.<locals>.<dictcomp>m   s*    ]]]
US\H\H\eH\H\H\r   )r
   r   r   r   )r&   r   r   r   unused_kwargsr   s        @r   updatezDistributedConfig.update\   s     	 ,,.. 	& 	&JCtS!! &c5)))  %%% ^]]]fllnn]]]r   N)r5   
__module____qualname____doc__r   bool__annotations__classmethodr   strosPathLiker)   dictr   r"   r1   r7   r6   r>   r	   r   r   r   r      s           $)D(((   [(&3+< & & & & ,c3h , , , ,8 8 8
D D D: : :    r   r   )r,   r#   rF   dataclassesr   typingr   r   r	   r   r   <module>rK      s      				 ! ! ! ! ! !       W W W W W W W W W Wr   