
     `iV                     d    d dl Z d dlZd dlZd dlmZ d dlmZmZ e G d d                      ZdS )    N)	dataclass)AnyUnionc                       e Zd ZU dZdZeed<   ed             Zde	e
ej        f         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          /home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/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              #   x   K   t          j        | j                                                  D ]\  }}||fV  dS )zTallows `dict(obj)` for situations where obj may be a dict or QuantizationConfigMixinN)r-   r.   r/   r   )r'   attrr   s      r   __iter__zDistributedConfig.__iter__L   sN      =77==?? 	 	KD%+	 	r   c                 H    | j         j         d|                                  S )N )	__class____name__to_json_stringr0   s    r   __repr__zDistributedConfig.__repr__R   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/   r0   s    r   r8   z DistributedConfig.to_json_stringU   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>n   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)r7   
__module____qualname____doc__r   bool__annotations__classmethodr   r   strosPathLiker*   dictr   r#   r3   r9   r8   r@   r
   r   r   r   r      s           $)D(((   [(&5bk1A+B & & & & ,c3h , , , ,  D D D: : :    r   r   )	r-   r$   rH   dataclassesr   typingr   r   r   r
   r   r   <module>rM      s      				 ! ! ! ! ! !         X X X X X X X X X Xr   