a
    hV                     @   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e	e
ejf dddZee
ef d	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^   | f i |}g }|  D ](\}}t||rt||| || q|D ]}||d qH|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value r   h/var/www/html/assistant/venv/lib/python3.9/site-packages/transformers/distributed/configuration_utils.py	from_dict   s    

zDistributedConfig.from_dict)json_file_pathc                 C   sX   t |ddd6}|  }tj|dddd }|| W d   n1 sJ0    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   Z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   r/   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       z,DistributedConfig.update.<locals>.<dictcomp>)r   r   r	   r
   )r"   r   r   r   Zunused_kwargsr   r2   r   update]   s    

zDistributedConfig.updateN)r.   
__module____qualname____doc__r   bool__annotations__classmethodr   r   strosPathLiker$   dictr   r   r+   r0   r/   r5   r   r   r   r   r      s   

r   )	r&   r   r=   dataclassesr   typingr   r   r   r   r   r   r   <module>   s   