o
    Ti_                     @   sR   d dl Z ddlT G dd deZG dd deZG dd	 d	eZG d
d dZdS )    N   )*c                   @      e Zd ZdZdS )ElasticityErrorz:
    Base exception for all elasticity related errors
    N__name__
__module____qualname____doc__ r   r   O/home/ubuntu/.local/lib/python3.10/site-packages/deepspeed/elasticity/config.pyr   
       r   c                   @   r   )ElasticityConfigErrorz(
    Elasticity configuration error
    Nr   r   r   r   r   r      r   r   c                   @   r   )ElasticityIncompatibleWorldSizezY
    Attempting to run a world size that is incompatible with a given elastic config
    Nr   r   r   r   r   r      r   r   c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	ElasticityConfiga  
    Elastic config object, constructed from a param dictionary that only contains elastic
    config parameters, example below:

    If elasticity is enabled, user must specify (at least) max_train_batch_size
    and micro_batch_sizes.

    {
        "enabled": true,
        "max_train_batch_size": 2000,
        "micro_batch_sizes": [2,4,6],
        "min_gpus": 1,
        "max_gpus" : 10000
        "min_time": 20
        "ignore_non_elastic_batch_info": false
        "version": 0.1
    }
    c                 C   s  | tt| _| jr,t|v r|t | _ntdt t|v r%|t | _ntdt | tt	| _| tt
| _t| jtsQtdt dt| j d| j ttdd | jsftdt d| j ttd	d | js{tdt d
| j | tt| _| tt| _| jdk s| jdk rtd| j d| j | j| jk rtd| j d| j | tt| _| jdk rtd| j | tt| _| jdk rtd| j | tt| _| jdk rtd| j | tt | _!| t"t#| _$| t%t&| _'d S )NzElasticity config missing zElasticity expected value of z, to be a list of micro batches, instead is: z, containing: c                 S   s
   t | tS N)
isinstanceintmr   r   r   <lambda>E   s   
 z+ElasticityConfig.__init__.<locals>.<lambda>zElasticity expected z8 to only contain a list of integers, instead contains: fc                 S   s   | dkS )Nr   r   r   r   r   r   r   I   s    z7 to only contain positive integers, instead contains: fr   z5Elasticity min/max gpus must be > 0, given min_gpus: z, max_gpus: zEElasticity min_gpus cannot be greater than max_gpus, given min_gpus: zFModel-Parallel size cannot be less than 1, given model-parallel size: zNNumber of GPUs per node cannot be less than 1, given number of GPUs per node: r   z,Elasticity min time needs to be >= 0: given )(getENABLEDENABLED_DEFAULTenabledMAX_ACCEPTABLE_BATCH_SIZEmax_acceptable_batch_sizer   MICRO_BATCHESmicro_batches!MAX_ACCEPTABLE_BATCH_SIZE_DEFAULTMICRO_BATCHES_DEFAULTr   listtypeallmapMIN_GPUSMIN_GPUS_DEFAULTmin_gpusMAX_GPUSMAX_GPUS_DEFAULTmax_gpusMODEL_PARALLEL_SIZEMODEL_PARALLEL_SIZE_DEFAULTmodel_parallel_sizeNUM_GPUS_PER_NODENUM_GPUS_PER_NODE_DEFAULTnum_gpus_per_nodeMIN_TIMEMIN_TIME_DEFAULTmin_timeVERSIONVERSION_DEFAULTversionPREFER_LARGER_BATCHPREFER_LARGER_BATCH_DEFAULTprefer_larger_batch_sizeIGNORE_NON_ELASTIC_BATCH_INFO%IGNORE_NON_ELASTIC_BATCH_INFO_DEFAULTignore_non_elastic_batch_info)self
param_dictr   r   r   __init__0   sx   





zElasticityConfig.__init__c                 C   s   | j S r   )__dict__r=   r   r   r   reprj   s   zElasticityConfig.reprc                 C   s   t j| jdddS )NT   )	sort_keysindent)jsondumpsr@   rA   r   r   r   __repr__m   s   zElasticityConfig.__repr__N)r   r   r	   r
   r?   rB   rH   r   r   r   r   r      s
    :r   )rF   	constants	Exceptionr   r   r   r   r   r   r   r   <module>   s   