o
    "j!                     @   s  d dl Z ddlmZ G dd dZG dd deZG dd	 d	eZG d
d deZG dd deZG dd deZG dd deZ	G dd deZ
G dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG d d! d!eZdS )"    N   )	constantsc                   @   s@   e Zd ZdddZdd Zdd Zdd	 Zd
d ZdddZdS )
BaseConfigNc                 C   sx   || _ d | _|d urt|tr|| _ntd| t| j }| D ]
\}}t| || q$| jr:| 	| j d S d S Nz%Expected a dictionary. But received: )
	_category_config_dict
isinstancedict
ValueErrorr   get_category_default_configitemssetattr	from_dict)selfcategoryconfig_dictconfigfielddefault_value r   j/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/paddle/distributed/auto_parallel/strategy.py__init__   s   
zBaseConfig.__init__c                 C   sB   t | j}| D ]}||t j}|t jkrt| || q
d S N)r   r   r   keysget	NOT_FOUNDr   )r   r   r   r   valuer   r   r   r   (   s   
zBaseConfig.from_dictc                 C   s^   i }t | j}| D ]}t| |}|||< q| j D ]\}}t|tr,|	 ||< q|S r   )
r   r   r   r   getattr__dict__r   r   r   to_dict)r   result_dictr   r   r   r   r   r   r   0   s   


zBaseConfig.to_dictc                 C   s<   |   }d}| D ]\}}|d| d| d7 }q
|d S )N{"z":"z",})r   r   )r   r    stringkvr   r   r   __repr__;   s
   zBaseConfig.__repr__c                 C   sH   | j }||}||t| < | j D ]\}}t||t|| q|S r   )	__class____new__idr   r   r   copydeepcopy)r   memoclsresultr%   r&   r   r   r   __deepcopy__B   s   
zBaseConfig.__deepcopy__c                 C   s   |   }|||S r   )r   r   )r   r%   dr    r   r   r   r   J   s   zBaseConfig.getr   )	__name__
__module____qualname__r   r   r   r'   r0   r   r   r   r   r   r      s    
r   c                          e Zd Zd fdd	Z  ZS )RecomputeConfigNc                       t j}t || d S r   )r   	RECOMPUTEsuperr   r   r   r   r(   r   r   r   P      zRecomputeConfig.__init__r   r2   r3   r4   r   __classcell__r   r   r;   r   r6   O       r6   c                       r5   )FusedLinearPromotionConfigNc                    r7   r   )r   FUSEDLINEARPROMOTIONr9   r   r:   r;   r   r   r   V   r<   z#FusedLinearPromotionConfig.__init__r   r=   r   r   r;   r   r@   U   r?   r@   c                       r5   )	AMPConfigNc                    r7   r   )r   AMPr9   r   r:   r;   r   r   r   \   r<   zAMPConfig.__init__r   r=   r   r   r;   r   rB   [   r?   rB   c                       r5   )ShardingConfigNc                    r7   r   )r   SHARDINGr9   r   r:   r;   r   r   r   b   r<   zShardingConfig.__init__r   r=   r   r   r;   r   rD   a   r?   rD   c                       r5   )GradientMergeConfigNc                    r7   r   )r   GRADIENT_MERGEr9   r   r:   r;   r   r   r   h   r<   zGradientMergeConfig.__init__r   r=   r   r   r;   r   rF   g   r?   rF   c                       r5   )PipelineConfigNc                    r7   r   )r   PIPELINEr9   r   r:   r;   r   r   r   n   r<   zPipelineConfig.__init__r   r=   r   r   r;   r   rH   m   r?   rH   c                       r5   )	QATConfigNc                    r7   r   )r   QATr9   r   r:   r;   r   r   r   t   r<   zQATConfig.__init__r   r=   r   r   r;   r   rJ   s   r?   rJ   c                       r5   )TuningConfigNc                    r7   r   )r   TUNINGr9   r   r:   r;   r   r   r   z   r<   zTuningConfig.__init__r   r=   r   r   r;   r   rL   y   r?   rL   c                       r5   )DatasetConfigNc                    r7   r   )r   DATASETr9   r   r:   r;   r   r   r      r<   zDatasetConfig.__init__r   r=   r   r   r;   r   rN      r?   rN   c                       r5   )FusedPassesConfigNc                    r7   r   )r   FUSED_PASSESr9   r   r:   r;   r   r   r      r<   zFusedPassesConfig.__init__r   r=   r   r   r;   r   rP      r?   rP   c                       r5   )DPOptimizationConfigNc                    r7   r   )r   DP_OPTIMIZATIONr9   r   r:   r;   r   r   r      r<   zDPOptimizationConfig.__init__r   r=   r   r   r;   r   rR      r?   rR   c                       r5   )MPOptimizationConfigNc                    r7   r   )r   MP_OPTIMIZATIONr9   r   r:   r;   r   r   r      r<   zMPOptimizationConfig.__init__r   r=   r   r   r;   r   rT      r?   rT   c                       r5   )SPOptimizationConfigNc                    r7   r   )r   SP_OPTIMIZATIONr9   r   r:   r;   r   r   r      r<   zSPOptimizationConfig.__init__r   r=   r   r   r;   r   rV      r?   rV   c                       s"   e Zd ZdZd fdd	Z  ZS )Strategya  
    The `Strategy` object is used to configure the parallelization and optimization for static graph.

    Args:
        config (dict|string, optional): If this is None, the default configurations will used.
        If this is a dictionary, the recognized key-value of it will be used to override the default
        configurations while other default configurations are left unchanged. If this is a string,
        it is interpreted as the path to a YAML configuration and will be loaded to override the
        corresponding default configurations.

    Examples:
        .. code-block:: python

            >>> import paddle
            >>> from paddle.distributed.fleet import auto

            >>> strategy = auto.Strategy()
            >>> sharding = strategy.sharding
            >>> assert sharding.enable == False
            >>> assert sharding.stage == 1
            >>> assert sharding.degree == 8

            >>> sharding.enable = True
            >>> sharding.stage = 2
            >>> sharding.degree = 2
            >>> assert sharding.enable == True
            >>> assert sharding.stage == 2
            >>> assert sharding.degree == 2

    Nc                    s  |d urt |trt|| _n
td| i | _tj}t 	|| j | j
tjd }t|| _| j
tjd }t|| _| j
tjd }t|| _| j
tjd }t|| _| j
tjd }t|| _| j
tjd }t|| _| j
tjd }t|| _| j
tj d }t!|| _"| j
tj#d }t$|| _%| j
tj&d }t'|| _(| j
tj)d }t*|| _+| j
tj,d }t-|| _.| j
tj/d }t0|| _1d S r   )2r   r	   r+   r,   r   r
   r   ZBASEr9   r   r   r8   r6   Z	recomputerC   rB   amprE   rD   ZshardingrG   rF   Zgradient_mergerI   rH   ZpipelinerK   rJ   ZqatrM   rL   ZtuningrO   rN   ZdatasetrQ   rP   Zfused_passesrA   r@   Zfused_linear_promotionrS   rR   Zdp_optimizationrU   rT   Zmp_optimizationrW   rV   Zsp_optimization)r   r   r   r   r;   r   r   r      sJ   












zStrategy.__init__r   )r2   r3   r4   __doc__r   r>   r   r   r;   r   rX      s    rX   )r+    r   r   r6   r@   rB   rD   rF   rH   rJ   rL   rN   rP   rR   rT   rV   rX   r   r   r   r   <module>   s"   ;