o
    
shV                     @   sJ   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 dZdS )    N)	dataclass)AnyUnionc                   @   sx   e Zd ZU dZdZeed< edd Zde	e
ejf fddZd	ee
ef fd
dZdd Zdd Zdd Zdd ZdS )DistributedConfigz,
    Base class for distributed configs
    Fenable_expert_parallelc                 K   s^   | di |}g }|  D ]\}}t||r!t||| || q|D ]}||d q$|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valuer   r   j/var/www/html/alpaca_bot/venv/lib/python3.10/site-packages/transformers/distributed/configuration_utils.py	from_dict   s   


zDistributedConfig.from_dictjson_file_pathc                 C   sZ   t |ddd}|  }tj|dddd }|| W d   dS 1 s&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_stringr   r   r   to_json_file4   s
   
"zDistributedConfig.to_json_filereturnc                 C   s   t | 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"   r   r   r   r   D   s   zDistributedConfig.to_dictc                 c   s*    t | j D ]	\}}||fV  q	dS )zTallows `dict(obj)` for situations where obj may be a dict or QuantizationConfigMixinN)r'   r(   r)   r   )r"   attrr   r   r   r   __iter__L   s   zDistributedConfig.__iter__c                 C   s   | j j d|   S )N )	__class____name__to_json_stringr*   r   r   r   __repr__R   s   zDistributedConfig.__repr__c                 C   s   t j| jddd 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*   r   r   r   r0   U   s   z DistributedConfig.to_json_stringc                    sP   g  |  D ]\}}t| |rt| ||  | q fd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                    s   i | ]\}}| vr||qS r   r   ).0r   r   r   r   r   
<dictcomp>n   s    z,DistributedConfig.update.<locals>.<dictcomp>)r   r	   r
   r   )r"   r   r   r   unused_kwargsr   r3   r   update]   s   


zDistributedConfig.updateN)r/   
__module____qualname____doc__r   bool__annotations__classmethodr   r   strosPathLiker%   dictr   r   r,   r1   r0   r6   r   r   r   r   r      s   
 
r   )	r'   r   r>   dataclassesr   typingr   r   r   r   r   r   r   <module>   s   