Ë
    �\;j2í ã                   óP  — d dl Z d dlZd dlZd dlZd dlZd dlmZ d dlZd dl	m
Z
 ddl
mZmZmZmZ ddlmZmZmZmZ ddlmZ dd	lmZmZmZmZmZmZmZmZmZmZ dd
l m!Z" ddl#m$Z$m%Z% ddl&m'Z' g Z( ejR                  «       a*ejV                  Z,ejZ                  Z.d„ Z/d„ Z0e'd„ «       Z1d.d„Z2d„ Z3d„ Z4d/d„Z5d/d„Z6d„ Z7	 d0d„Z8	 d1d„Z9	 d.d„Z:d„ Z;d„ Z<d„ Z=d2d„Z>d„ Z?d„ Z@d„ ZAd „ ZBd!„ ZCd"„ ZDd3d#„ZEd$„ ZF e«       d%„ «       ZG G d&„ d'«      ZH G d(„ d)«      ZI G d*„ d+«      ZJ G d,„ d-«      ZKy)4é    N)Ú	lru_cache)Úpiré   )ÚOpResultÚProgramÚValueÚtranslate_to_piré   )ÚcompilerÚcoreÚ	frameworkÚunique_name)Úconvert_dtype)
ÚOperatorr   ÚVariableÚ_apply_passÚconvert_np_dtype_to_dtype_Údefault_main_programÚ	get_flagsÚin_pir_modeÚpaddle_type_to_proto_typeÚ	set_flags)Úauto_checkpoint)ÚFetchHandlerMonitorÚTrainerFactory)Úsignature_safe_contextmanagerc                  ó   — t         S )a'  
    :api_attr: Static Graph

    Get the global/default scope instance. There are a lot of APIs use
    :code:`global_scope` as its default value, e.g., :code:`Executor.run`

    Returns:
        Scope: The global/default scope instance.

    Examples:
        .. code-block:: python

            >>> import paddle
            >>> import numpy

            >>> paddle.static.global_scope().var("data").get_tensor().set(numpy.ones((2, 2)), paddle.CPUPlace())
            >>> numpy.array(paddle.static.global_scope().find_var("data").get_tensor())
    ©Úg_scope© ó    ú]G:\00. PROJECTS\API\Inventory\templateJSON\kerjaOCR\Lib\site-packages\paddle/base/executor.pyÚglobal_scoper#   9   s	   € ô& €Nr!   c                 ó   — t         }| a |S ©Nr   ©ÚscopeÚexs     r"   Ú_switch_scoper)   O   s   € ä	€BØ€GØ€Ir!   c              #   ób   K  — t        | «      }	 d–— t        |«       y# t        |«       w xY w­w)aØ  

    This function switches scope through python `with` statement.
    Scope records the mapping between variable names and variables ( :ref:`api_guide_Variable` ),
    similar to brackets in programming languages.
    If this function is not invoked, all variables and variable names are recorded in the default global scope.
    When users need to create variables with the same name,
    they need to switch scopes through this function
    if they do not want the mapping of variables with the same name to be overwritten.
    After switching through the `with` statement,
    all variables created in the `with` block will be assigned to a new scope.

    Parameters:
        scope: The new scope.

    Returns:
        None

    Examples:

        .. code-block:: python

            >>> import paddle
            >>> import numpy
            >>> paddle.enable_static()

            >>> new_scope = paddle.static.Scope()
            >>> with paddle.static.scope_guard(new_scope):
            ...         paddle.static.global_scope().var("data").get_tensor().set(numpy.ones((2, 2)), paddle.CPUPlace())
            >>> numpy.array(new_scope.find_var("data").get_tensor())
            array([[1., 1.],
                   [1., 1.]])
    N)r)   r&   s     r"   Úscope_guardr+   V   s+   è ø€ ôH 
�uÓ	€BðÛä�bÕøŒ�bÕüs   ‚/� “/Ÿ,¬/c                 óÖ  — t        | t        j                  «      r| D �cg c]  }t        ||«      ‘Œ c}S t        | t        «      r| D �cg c]  }t        ||«      ‘Œ c}S t        | t        j
                  «      sJ ‚| j                  «       }t        |«      dkD  rt        d«      ‚| j                  «       r,|rt        j                  | «      S t        j                  | «      S yc c}w c c}w )a#  
    Convert a Tensor to a numpy.ndarray, its only support Tensor without LoD information.
    For higher dimensional sequence data, please use LoDTensor directly.

    Examples:
        .. code-block:: python

            >>> import paddle.base as base
            >>> import numpy

            >>> new_scope = base.Scope()
            >>> with base.scope_guard(new_scope):
            ...     base.global_scope().var("data").get_tensor().set(numpy.ones((2, 2)), base.CPUPlace())
            >>> tensor = new_scope.find_var("data").get_tensor()
            >>> base.executor.as_numpy(tensor) # or numpy.array(new_scope.find_var("data").get_tensor())

    Args:
       tensor(Variable): a instance of Tensor
       copy(bool, optional): Whether to use deep copy.

    Returns:
        numpy.ndarray
    r   záSome of your fetched tensors hold LoD information.             They can not be completely cast to Python ndarray.             Please set the parameter 'return_numpy' as 'False' to             return LoDTensor itself directly.N)Ú
isinstancer   ÚLoDTensorArrayÚas_numpyÚlistÚ	LoDTensorÚlodÚlenÚRuntimeErrorÚ_is_initializedÚnpÚarrayÚasarray)ÚtensorÚcopyÚtr2   s       r"   r/   r/   �   sÌ   € ô0 �&œ$×-Ñ-Ô.Ù+1Ó2©6 a”˜˜DÕ!¨6Ñ2Ð2Ü�&œ$ÔÙ+1Ó2©6 a”˜˜DÕ!¨6Ñ2Ð2Ü�fœdŸn™nÔ-Ð-Ð-Ø
�*‰*‹,€CÜ
ˆ3ƒx�!‚|Üð/ó
ð 	
ð ×ÑÔÙÜ—8‘8˜FÓ#Ð#ä—:‘:˜fÓ%Ð%àùò% 3ùâ2s   ŸC!Á	C&c                 óÈ   — t        | t        j                  j                  «      st	        | «      } t        |t        j                  j                  «      st	        |«      }| |k(  S )a  
    Returns True if the first dtype can be compatible the second one.
    Currently, we require the two dtype's have to be same.

    Args:
        dtype (np.dtype|VarType|str): The type of data: float32, int64, etc.

    Returns:
        True if the two types are same.
    )r-   r   ÚVarDescÚVarTyper   )ÚfirstÚseconds     r"   Údtype_is_compatible_withrA   ¯   sJ   € ô �eœTŸ\™\×1Ñ1Ô2Ü*¨5Ó1ˆÜ�fœdŸl™l×2Ñ2Ô3Ü+¨FÓ3ˆØ�F‰?Ðr!   c                 óª   — t        | «      }|t        |«      k7  ryt        |«      D ]+  }| |   �| |   dk  rŒ||   �||   dk  rŒ| |   ||   k7  sŒ+ y y)aw  
    Returns True if the two dimensions are compatible.

    A dimension is compatible with the other if:
    1. The length of the dimensions are same.
    2. Each non-negative number of the two dimensions are same.
    3. For negative number or 'None' in a dimension, it means unknown so it
       is compatible with any number.

    Args:
        first (list/tuple): integers representing shape. "None" or negative
            number means unknown.
        second (list/tuple): integers representing shape. "None" or negative
            number means unknown.

    Returns:
        True if the two dimensions are compatible.
    Fr   T)r3   Úrange)r?   r@   Údim_lenÚis       r"   Údimension_is_compatible_withrF   Á   sp   € ô( �%‹j€GØ”#�f“+ÒØä�7Ž^ˆØ�‰8Ð˜u Q™x¨!š|ØØ�!‰9Ð  q¡	¨A¢ØØ�‰8�v˜a‘yÓ Ùð ð r!   c                 óÚ  — | j                   j                  «       �rPt        j                  || j                   |«      }|�9t	        d| j
                  t        | j                  «      | j                  |fz  «      ‚t        |j                  «       | j                  «      sÐt        | j                  t        j                  j                  «      rt        | j                  «      n| j                  }t        |j                  «       t        j                  j                  «      rt        |j                  «       «      n|j                  «       }t	        dj                  | j
                  ||«      «      ‚y)a„  
    Returns True if the variable doesn't require feed check or it is compatible
    with the shape and have same dtype as the fed value.

    A dimension is compatible with the other if:
    1. The length of the dimensions are same.
    2. Each non-negative number of the two dimensions are same.
    3. For negative number or 'None' in a dimension, it means unknown so it
       is compatible with any number.

    Args:
        var (Variable): the Variable object
        feed (LoDTensor): the fed value, which must be a LoDTensor
        num_places: an integer value indicating the number of places.
            ParallelExecutor will divide data into devices (CPU/GPU) evenly.
    Returns:
        True if the shape and dtype of variable is compatible with the feed value
    Raises:
        ValueError: if the shape or dtype of the variable is not compatible with
            the feed value
    úeThe fed Variable %r should have dimensions = %d, shape = %r, but received fed shape %r on each deviceúBThe data type of fed Variable {!r} must be {!r}, but received {!r}T)ÚdescÚneed_check_feedr   Údiff_tensor_shapeÚ
ValueErrorÚnamer3   ÚshaperA   Ú_dtypeÚdtyper-   r=   r>   r   Úformat)ÚvarÚfeedÚ
num_placesÚ
diff_shapeÚvar_dtype_formatÚfeed_dtype_formats         r"   Úcheck_feed_shape_typerY   ä   s  € ð, ‡x�x×ÑÕ!Ü×+Ñ+¨D°#·(±(¸JÓGˆ
ØÐ!Üð?à—8‘8œS §¡›^¨S¯Y©Y¸
ÐCñDóð ô
 (¨¯©«°s·y±yÔAô ˜cŸi™i¬¯©×)=Ñ)=Ô>ô ˜cŸi™iÔ(à—Y‘Yð ô ˜dŸk™k›m¬T¯\©\×-AÑ-AÔBô ˜dŸk™k›mÔ,à—[‘[“]ð ô
 ØT×[Ñ[Ø—H‘HÐ.Ð0Aóóð ð
 r!   c                 óð  — t        j                  | ||«      }|�t        d|t        |«      ||fz  «      ‚t	        | j                  «       |«      s¨t        |t         j                  j                  «      rt        |«      n|}t        | j                  «       t         j                  j                  «      rt        | j                  «       «      n| j                  «       }t        dj                  |||«      «      ‚y)a  
    Returns True if the variable doesn't require feed check or it is compatible
    with the shape and have same dtype as the fed value.

    A dimension is compatible with the other if:
    1. The length of the dimensions are same.
    2. Each non-negative number of the two dimensions are same.
    3. For negative number or 'None' in a dimension, it means unknown so it
       is compatible with any number.

    Args:
        feed (LoDTensor): the fed value, which must be a LoDTensor
        name (str): name of the variable
        target_shape (list): the shape that will be compared with feed
        dtype (core.VarDesc.VarType): the dtype that will be compared with feed
        num_places: an integer value indicating the number of places.
            ParallelExecutor will divide data into devices (CPU/GPU) evenly.
    Returns:
        True if the shape and dtype of variable is compatible with the feed value
    Raises:
        ValueError: if the shape or dtype of the variable is not compatible with
            the feed value
    rH   rI   T)r   rL   rM   r3   rA   rP   r-   r=   r>   r   rR   )rT   rN   Útarget_shaperQ   rU   rV   rW   rX   s           r"   Úpir_check_feed_shape_typer\     sæ   € ô0 ×'Ñ'¨¨l¸JÓG€JØÐÜð;à”S˜Ó&¨°jÐAñBó
ð 	
ô
 $ D§K¡K£M°5Ô9ô ˜%¤§¡×!5Ñ!5Ô6ô ˜%Ô àð 	ô ˜$Ÿ+™+›-¬¯©×)=Ñ)=Ô>ô ˜$Ÿ+™+›-Ô(à—‘“ð 	ô
 ØP×WÑWØÐ&Ð(9óó
ð 	
ð
 r!   c                 ó^  — d}| j                   D ]z  }|j                  j                  «       dk(  rZ|dz  }|j                  j                  d«      d   |k(  sJ ‚|j                  j	                  d«      d   }||vsŒkt        d|› d�«      ‚ n |dkD  r|t        |«      k7  rt        d«      ‚|dkD  S )	aª  Check whether the block already has feed operators.

    Return false if the block does not have any feed operators.
    If some feed operators have been prepended to the block, check that
    the info contained in these feed operators matches the feed_targets
    and feed_holder_name. Raise exception when any mismatch is found.
    Return true when the block has feed operators with matching info.

    Args:
        block: a block instance (typically global block of a program)
        feed_targets: a dictionary of {feed_target_name: feed_target_data}
        feed_holder_name: the name of the variable that holds the data of
            all feed targets. The type of this feed_holder variable is
            FEED_MINIBATCH, which is essentially vector<LoDTensor>.

    Returns:
        A boolean value that indicates whether a block has feed operators
        that match the info contained in feed_targets and feed_holder_name.
    r   rT   r
   ÚXÚOutz'feed_targets' does not have ú	 variablez:Feed operators in program desc do not match 'feed_targets')ÚopsrJ   ÚtypeÚinputÚoutputÚ	Exceptionr3   )ÚblockÚfeed_targetsÚfeed_holder_nameÚ
feed_countÚopÚfeed_target_names         r"   Úhas_feed_operatorsrl   G  sÄ   € ð* €JØ�iŒiˆØ�7‰7�<‰<‹>˜VÒ#Ø˜!‰OˆJØ—7‘7—=‘= Ó% aÑ(Ð,<Ò<Ð<Ð<Ø!Ÿw™wŸ~™~¨eÓ4°QÑ7ÐØ |Ò3ÜØ3Ð4DÐ3EÀYÐOóð ñ ð ð �A‚~˜*¬¨LÓ(9Ò9ÜØHó
ð 	
ð ˜‰>Ðr!   c                 ó,  — d}| j                   D ]Ü  }|j                  j                  «       |k(  sŒ!|dz  }|j                  j                  d«      d   |k(  sJ ‚|j                  j	                  d«      d   }||D �cg c]  }|j                  j                  «       ‘Œ c}vrt        d|› d�«      ‚|j                  j                  d«      }|||   j                  j                  «       k(  rŒÜJ ‚ |dkD  r|t        |«      k7  rt        d«      ‚|dkD  S c c}w )	aá  Check whether the block already has fetch operators.

    Return false if the block does not have any fetch operators.
    If some fetch operators have been appended to the block, check that
    the info contained in these fetch operators matches the fetch_targets
    and fetch_holder_name. Raise exception when any mismatch is found.
    Return true when the block has fetch operators with matching info.

    Args:
        block: a block instance (typically global block of a program)
        fetch_targets: a dictionary of {fetch_target_name: fetch_target_data}
        fetch_holder_name: the name of the variable that holds the data of
            all fetch targets. The type of this fetch_holder variable is
            FETCH_LIST, which is essentially vector<LoDTensor>.
        fetch_op: the operator name of fetch

    Return:
        A boolean value that indicates whether a block has fetch operators
        that match the info contained in fetch_targets and fetch_holder_name.
    r   r
   r_   r^   z'fetch_targets' does not have r`   Úcolz<Fetch operators in program desc do not match 'fetch_targets')	ra   rJ   rb   rd   rc   rN   re   Úattrr3   )	rf   Úfetch_targetsÚfetch_holder_nameÚfetch_opÚfetch_countrj   Úfetch_target_namerS   Úidxs	            r"   Úhas_fetch_operatorsrv   o  s  € ð0 €KØ�iŒiˆØ�7‰7�<‰<‹>˜XÓ%Ø˜1ÑˆKØ—7‘7—>‘> %Ó(¨Ñ+Ð/@Ò@Ð@Ð@Ø "§¡§¡¨cÓ 2°1Ñ 5ÐØ Ù+8ó)Ù+8 C�—‘—‘•¨=ñ)ñ ô  Ø4Ð5FÐ4GÀyÐQóð ð —'‘'—,‘,˜uÓ%ˆCØ$¨°cÑ(:×(?Ñ(?×(DÑ(DÓ(FÓFÐFÐFð ð �Q‚˜;¬#¨mÓ*<Ò<ÜØJó
ð 	
ð ˜‰?Ðùò)s   Á;!Dc                 ó’  — g g g}| j                   D ]^  }|j                  «       |k(  sŒ|d   j                  |j                  d«      «       |d   j                  |j	                  «       d   «       Œ` g }t        |«      D ]E  \  }}t        |t        «      r||d   vsŒt        d|› d�«      ‚||d   vsŒ5|j                  |«       ŒG |S )aÆ  Check whether the block already has fetch operation.

    Return false if the block does not have any fetch operation.
    If some fetch operation have been appended to the block, check that
    the info contained in these fetch operation matches the fetch_targets.
    Raise exception when any mismatch is found.
    Return true when the block has fetch operation with matching info.

    Args:
        block: a block instance (typically global block of a program)
        fetch_targets: a list of fetch_target_data
        fetch_op: the operator name of fetch

    Return:
        A boolean value that indicates whether a block has fetch operators
        that match the info contained in fetch_targets.
    r   r
   rN   zFound fetch_target[z)] is type(str) and doesn't have fetch op.)	ra   rN   ÚappendÚoperand_sourceÚattrsÚ	enumerater-   Ústrre   )	rf   rp   rq   rr   Ú
fetch_inforj   Úneed_fetch_inforE   Ú	fetch_vars	            r"   Úhas_fetch_operationsr€   œ  sÑ   € ð* �b�€JØ�iŒiˆØ�7‰7‹9˜Ó Ø�q‰M× Ñ  ×!2Ñ!2°1Ó!5Ô6Ø�q‰M× Ñ  §¡£¨FÑ!3Õ4ð ð
 €OÜ! -Ö0‰ˆˆ9Ü�i¤Ô%Ø 
¨1¡Ò-ÜØ)¨!¨Ð,UÐVóð ð ˜j¨™mÒ+Ø×"Ñ" 9Õ-ð 1ð Ðr!   c                 óp  — | j                  «       }|j                  «       }||j                  v r|j                  |«      }n6|j	                  |t
        j                  j                  j                  d¬«      }||j                  v r|j                  |«      }	n6|j	                  |t
        j                  j                  j                  d¬«      }	t        |||«      skt        |«      D ]]  \  }
}|j                  |«      r/|j                  |«      }|j                  dd|gid|gid|
i¬«       ŒFt        j                  d|z  «       Œ_ |rd	}nd
}t!        ||||«      s\t        |«      D ]N  \  }
}t#        |t$        t&        f«      sJ d|
› dt)        |«      › �«       ‚|j+                  |d|gid|	gid|
i¬«       ŒP |S )NT©rN   rb   ÚpersistablerT   r^   r_   rn   ©rb   ÚinputsÚoutputsrz   úIThe variable %s is not found in program. It is not declared or is pruned.Úfetch_v2ÚfetchúWrong type for fetch_list[ú]: )ÚcloneÚglobal_blockÚvarsrS   Ú
create_varr   r=   r>   ÚFEED_MINIBATCHÚ
FETCH_LISTrl   r{   Úhas_varÚ_prepend_opÚwarningsÚwarnrv   r-   r   r|   rb   Ú	append_op)ÚprogramrT   Ú
fetch_listÚfeed_var_nameÚfetch_var_nameÚuse_fetch_v2Útmp_programr�   Úfeed_varr   rE   rN   Úoutrr   rS   s                  r"   Ú_add_feed_fetch_opsrŸ   Ä  sã  € ð —-‘-“/€Kà×+Ñ+Ó-€Là˜×)Ñ)Ñ)Ø×#Ñ# MÓ2‰à×*Ñ*ØÜ—‘×%Ñ%×4Ñ4Øð +ó 
ˆð ˜×*Ñ*Ñ*Ø ×$Ñ$ ^Ó4‰	à ×+Ñ+ØÜ—‘×%Ñ%×0Ñ0Øð ,ó 
ˆ	ô ˜l¨D°-Ô@Ü  –‰GˆAˆtØ×#Ñ# DÔ)Ø"×&Ñ& tÓ,�Ø×(Ñ(ØØ ( Ð,Ø" S E˜NØ  !˜*ð	 )õ ô —‘Ø_Øñõð 'ñ Ø‰àˆô Ø�j .°(ôô   
Ö+‰FˆAˆsÜØ”h¤�_ôð >à+¨A¨3¨c´$°s³)°Ð=ó>ð ð ×"Ñ"ØØ˜c˜U�|Ø  Ð,Ø˜a�jð	 #õ ð	 ,ð Ðr!   c           	      ó’  — dd l }| j                  «       }d}t        ||||«      }|r•|j                  j	                  | «      5  t        |«      D ]a  \  }}t        |t        t        f«      sJ d|› dt        |«      › �«       ‚|j                  j                  ||t        |«      z   |«      }	d|	_        Œc 	 d d d «       y y # 1 sw Y   y xY w)Nr   úpd_op.fetchrŠ   r‹   T)Úpaddler�   r€   ÚstaticÚprogram_guardr{   r-   r   r   rb   Ú_pir_opsr‰   r|   rƒ   )
r—   r˜   rš   r¢   r�   rr   r~   rE   Úfetch_inputrž   s
             r"   Ú_add_pir_fetch_opsr§     sÑ   € Ûà×'Ñ'Ó)€LØ€HÜ*Ø�j .°(ó€Oñ Ø�]‰]×(Ñ(¨Õ1Ü"+¨OÖ"<‘��;Ü!Ø¤(¬EÐ!2ôð Jà/°¨s°#´d¸;Ó6GÐ5HÐIóJð ð —o‘o×+Ñ+Ø ´#°a³&Ñ!8¸!ó�ð #'�•ñ #=÷ 2Ð1ð ß1Ð1ús   ÁA0B=Â=Cc                 óâ   — |dk  r| S t        | «      |z  dk(  sJ ‚t        dt        | «      |«      D �cg c]
  }| |||z    ‘Œ }}|D �cg c]  }t        j                  |«      ‘Œ c}S c c}w c c}w )Nr
   r   )r3   rC   r6   r7   )r9   Úmicro_batch_numrE   Úchunk_tensorÚchunks        r"   Ú_merge_tensorsr¬     sŠ   € Ø˜!ÒØˆÜˆv‹;˜Ñ(¨AÒ-Ð-Ð-ô �qœ#˜f›+ Ô7óá7ˆAð 	ˆq�1�Ñ&Ò'Ø7ð ð ñ *6Ó6© ŒB�H‰H�U�O¨Ñ6Ð6ùò	ùò 7s   ³A'ÁA,c                 ó°   — t        j                  «       rdnd}||dœ}dddœ}t        «       }|rd}t        | ||||«       |r|rd}t        | ||||«       y y y )NTF)Úuse_cudaÚmem_opt_skip_varsÚboolz	list[str]Úbuffer_shared_inplace_passÚinplace_addto_op_pass)r   Úis_compiled_with_cudar   r   )	r—   Úenable_inplaceÚenable_addtoÚskip_var_namesr®   rz   Ú
attr_typesÚempty_startup_programÚ	pass_names	            r"   Ú_apply_inplace_addto_passrº   $  su   € ô ×1Ñ1Ô3‰t¸€Hà!¸ÑG€EØ$¸;ÑG€Jä#›IÐÙØ0ˆ	ÜØÐ*¨I°u¸jô	
ñ ™Ø+ˆ	ÜØÐ*¨I°u¸jõ	
ð !€|r!   c                 ó
  — t        | t        «      sJ ‚|€
t        «       }t        |t        j                  «      sJ ‚|j                  t        | «      «      }|€J d| z   dz   «       ‚|j                  «       }|rt        |d¬«      }|S )aR  
    Fetch the value of the variable with the given name from the
    given scope.

    Args:
        name(str): name of the variable. Typically, only persistable variables
            can be found in the scope used for running the program.
        scope(core.Scope|None): scope object. It should be the scope where
            you pass to Executor.run() when running your program.
            If None, global_scope() will be used. Default None.
        return_numpy(bool): whether convert the tensor to numpy.ndarray.
            Default True.

    Returns:
       LodTensor|numpy.ndarray
    zCannot find zm in scope. Perhaps you need to make the variable persistable by using var.persistable = True in your program.T©r:   )	r-   r|   r#   r   Ú_ScopeÚfind_varÚ_to_name_strÚ
get_tensorr/   )rN   r'   Úreturn_numpyrS   r9   s        r"   Ú
_fetch_varrÂ   9  sŒ   € ô" �dœCÔ Ð Ð Ø€}Ü“ˆÜ�eœTŸ[™[Ô)Ð)Ð)à
�.‰.œ dÓ+Ó
,€CØˆ?ð Ø˜Ñð !ñ 	óˆ?ð
 �^‰^Ó€FÙÜ˜& tÔ,ˆØ€Mr!   c                 ó¸   — d„ }t        | t        «      r| d   } t        | t        «      r&| D �cg c]
  } ||«      ‘Œ }}dj                  |«      S  || «      S c c}w )Nc                 ó’  — t        | t        «      r| j                  j                  «       S t        | t        «      r| S t        | t        «      rt	        | «      S t        | t
        «      rt	        t        | «      «      S t        | t        «      rt	        | «      S t        | t        «      rt	        | «      S t        t	        | «      dz   «      ‚)Nz$ should be Variable, Operator or str)
r-   r   rJ   rN   r|   r   Úidr   r   Ú	TypeError©rS   s    r"   Ú_to_strz_to_name_str.<locals>._to_str\  s‘   € Ü�cœ8Ô$Ø—8‘8—=‘=“?Ð"Ü˜œSÔ!ØˆJÜ˜œSÔ!Ü�s“8ˆOÜ˜œXÔ&Ü”r˜#“w“<ÐÜ˜œXÔ&Ü�s“8ˆOÜ˜œUÔ#Ü�s“8ˆOäœC ›HÐ'MÑMÓNÐNr!   r   Ú,)r-   Útupler0   Újoin)rS   rÈ   ÚitemÚss       r"   r¿   r¿   [  s\   € òOô$ �#”uÔØ�!‰fˆÜ�#”tÔÙ'*Ó+¡s˜t‰W�T�] sˆÐ+Ø�x‰x˜‹{Ðá�s‹|Ðùò ,s   ­Ac                  ó²  — ddl m}  ddlm}  | dd«      }|j	                  d«      }|j                  «       }t        t        j                  dd«      «      }||_	        t        |«      }t        |«      D ]>  \  }}|j                  «       }	||	_        ||	_        |j                  j!                  |	«       Œ@ t#        j$                  |j'                  «       «      }
|
S )	Nr   )Úgetenv_or_backup)Úfleet_executor_desc_pb2ÚPADDLE_TRAINER_ENDPOINTSÚ rÉ   ÚPADDLE_TRAINER_IDr   )Údistributed.backup_envrÏ   Údistributed.fleet.protorÐ   ÚsplitÚFleetExecutorDescÚintÚosÚgetenvÚcur_rankr3   r{   ÚRankInfoÚrankÚip_portÚcluster_inforx   r   ÚFleetExecutorÚSerializeToString)rÏ   rÐ   Útrainer_endpoints_strÚtrainer_endpointsÚfleet_exe_descrÛ   ÚnrankrÝ   ÚendpointÚ	rank_infoÚ	fleet_exes              r"   Ú_prepare_fleet_executorré   w  sÄ   € Ý9ÝAá,Ð-GÈÓLÐØ-×3Ñ3°CÓ8ÐØ,×>Ñ>Ó@€NÜ”2—9‘9Ð0°!Ó4Ó5€HØ&€NÔÜÐ!Ó"€EÜ#Ð$5Ö6‰ˆˆhØ+×4Ñ4Ó6ˆ	Øˆ	ŒØ$ˆ	ÔØ×#Ñ#×*Ñ*¨9Õ5ð	 7ô
 ×"Ñ" >×#CÑ#CÓ#EÓF€IØÐr!   c                 ó  — t        | t        «      r2t        | «      t        |j                  «       «      z   t	        ||«      z   S | j
                  j                  «       t        |j                  «       «      z   t	        ||«      z   S r%   )r-   Ú
PirProgramr|   Úraw_addressÚ_get_program_cache_keyrJ   Úcached_hash_str)r—   r'   rT   r˜   s       r"   Ú)_get_strong_program_cache_key_for_new_exerï   Š  sy   € Ü�'œ:Ô&ä�‹LÜ�%×#Ñ#Ó%Ó&ñ'ä$ T¨:Ó6ñ7ð	
ð �L‰L×(Ñ(Ó*Ü�%×#Ñ#Ó%Ó&ñ'ä$ T¨:Ó6ñ7ð	
r!   c                 óÆ   — d„ }t        | t        j                  «      r| j                  n| } ||j                  d   «      t        t        | «      «      z   t        ||«      z   S )Nc                 óš   — g }t        | j                  j                  «       «      D ]  }|j                  |«       Œ dj	                  |«      S )NÚ
)r0   rŽ   Úkeysrx   rË   )rf   Ú	block_strÚvar_names      r"   Ú_get_varname_from_blockz>_get_strong_program_cache_key.<locals>._get_varname_from_block›  s>   € Øˆ	Ü˜UŸZ™ZŸ_™_Ó.Ö/ˆHØ×Ñ˜XÕ&ð 0à�y‰y˜Ó#Ð#r!   r   )r-   r   ÚCompiledProgramÚ_programÚblocksr|   rÅ   rí   )r—   rT   r˜   rö   Úinner_programs        r"   Ú_get_strong_program_cache_keyrû   ™  sf   € ò$ô �gœx×7Ñ7Ô8ð 	×Òàð ñ 	  × 4Ñ 4°QÑ 7Ó8Ü
Œb�‹kÓ
ñ	ä
   zÓ
2ñ	3ðr!   c                 ó   — g }t        | t        «      rt        | j                  «       «      }nEt        | t        t        f«      r/t        | «      D ]!  \  }}|t        |j                  «       «      z  }Œ# t        t        t        |«      «      }||z   S r%   )r-   Údictr0   ró   rÊ   r{   Úmapr¿   )rT   r˜   Úfeed_var_namesrE   ÚeachÚfetch_var_namess         r"   Ú_get_feed_fetch_var_namesr  ­  sr   € Ø€NÜ�$œÔÜ˜dŸi™i›kÓ*‰Ü	�Dœ4¤˜-Ô	(Ü  –‰GˆAˆtØœd 4§9¡9£;Ó/Ñ/‰Nð 'äœ3œ|¨ZÓ8Ó9€OØ˜OÑ+Ð+r!   c                 ó,   — t        t        | |«      «      S r%   )r|   r  )rT   r˜   s     r"   rí   rí   ¸  s   € ÜÔ(¨¨zÓ:Ó;Ð;r!   c                 óh  — t        | t        j                  «      sñ|€J d«       ‚t        |t        j                  j
                  «      rt        |«      n|}t        j                  | «      r%t        j                  | «      j                  |«      } n}t        | t        t        f«      rOt        j                  | «      } | j                  t        j                  k(  rt        d«      ‚| j                  |«      } nt        dt        | «      › d�«      ‚t        j                   «       }|j#                  | |«       |S )a  
    Convert numpy.ndarray to Tensor, its only support Tensor without LoD information.
    For higher dimensional sequence data, please use LoDTensor directly.

    Examples:

        .. code-block:: python

            >>> import numpy as np
            >>> import paddle.base as base
            >>> place = base.CPUPlace()
            >>> exe = base.Executor(place)
            >>> data = np.array((100, 200, 300))
            >>> np_outs = map(lambda x: base.executor._as_lodtensor(x, place), data)

    Args:
        data(numpy.ndarray|list|tuple|scalar): a instance of array, scalar, list or tuple
        data(core.Place): the place of created tensor
        dtype(core.VarDesc.VarType|str): the expected data type of created tensor

    Returns:
        LoDTensor
    z:The dtype should be given when feed data is not np.ndarrayzÕ
	Faild to convert input data to a regular ndarray :
	* Usually this means the input data contains nested lists with different lengths. Please consider using 'base.create_lod_tensor' to convert it to a LoD-Tensor.zConvert data of type z to Tensor is not supported)r-   r6   Úndarrayr   r=   r>   r   Úisscalarr7   Úastyper0   rÊ   rQ   Úobject_rÆ   rb   r1   Úset)ÚdataÚplacerQ   r9   s       r"   Ú_as_lodtensorr  ¼  s  € ô2 �dœBŸJ™JÔ'àÐð	HàGó	HØô ˜%¤§¡×!5Ñ!5Ô6ô ˜%Ô àð 	ô
 �;‰;�tÔÜ—8‘8˜D“>×(Ñ(¨Ó/‰DÜ˜œt¤U˜mÔ,Ü—8‘8˜D“>ˆDØ�z‰zœRŸZ™ZÒ'Üðdóð ð
 —;‘;˜uÓ%‰DäØ'¬¨T«
 |Ð3NÐOóð ô
 �^‰^Ó€FØ
‡J�Jˆt�UÔØ€Mr!   c                 ó&  — t        | t        j                  «      xs$ t        | j                  t        j                  «      }|rOt        | t        j                  «      r| n| j                  }|j                  rt        j                  dt        «       yy)Nz-Standalone executor is not used for inferenceFT)r-   r   r÷   Ú_graphÚ_is_inferencer”   r•   ÚUserWarning)r—   r  ÚcompiledÚcompiled_programs       r"   Ú_can_use_interpreter_corer  ô  s}   € Ü˜'¤8×#;Ñ#;Ó<ò Ä
Ø�‰œ×0Ñ0óA€Hñ ô ˜'¤8×#;Ñ#;Ô<ñ à—‘ð 	ð ×)Ò)Ü�M‰MØ?Üôð àr!   c                 ó.   — t        j                  | «       y r%   )ÚloggingÚwarning)Úmsgs    r"   Ú_warning_oncer  
  s   € ä‡O�O�CÕr!   c                   ó*   — e Zd Zdd„Zd„ Zed„ «       Zy)ÚFetchHandlerNc                 ó(   — |€J ‚|| _         || _        y r%   )Úvar_dictÚperiod_secs)Úselfr  r  s      r"   Ú__init__zFetchHandler.__init__  s   € ØÐ#Ð#Ð#Ø ˆŒØ&ˆÕr!   c                 óä   — |D ]L  }t        ||   «      t        j                  u sŒ"t        j                  j                  |› d||   d   › d�«       ŒN t        j                  j                  d«       y )Nz[0]: r   Ú rò   )rb   r6   r  ÚsysÚstdoutÚwrite)r  Úres_dictÚkeys      r"   ÚhandlerzFetchHandler.handler  s^   € ÛˆCÜ�H˜S‘MÓ"¤b§j¡jÒ0Ü—
‘
× Ñ  C 5¨¨h°s©m¸AÑ.>Ð-?¸qÐ!AÕBð ô 	�
‰
×Ñ˜Õr!   c                  ó   — t        d«       y )Na  
class FetchHandlerExample(FetchHandler):
    def handler(self, res_dict):
        print(res_dict["auc"])
        print("auc: {}, {}".format(res_dict["auc"], time.ctime()))

auc = Variable()
var_dict = {"auc": auc}
handler = FetchHandlerExample(var_dict=var_dict)
)Úprintr    r!   r"   ÚhelpzFetchHandler.help  s   € äð	õ	
r!   )Né<   )Ú__name__Ú
__module__Ú__qualname__r  r'  Ústaticmethodr*  r    r!   r"   r  r    s    „ ó'ò
ð ñ
ó ñ
r!   r  c                   óB   — e Zd Zd„ Z	 dd„Zdej                  fd„Zd„ Zy)Ú_StandaloneExecutorc                 ó²   — t        j                  «       | _        | j                  j                  |«       || _        || _        | j                  «       | _        y r%   )r   ÚPlaceÚ_placeÚ	set_placeÚ_planÚ_scopeÚ_create_new_executorÚ_new_exe)r  r  Úplanr'   s       r"   r  z_StandaloneExecutor.__init__,  s?   € Ü—j‘j“lˆŒØ�‰×Ñ˜eÔ$ØˆŒ
ØˆŒØ×1Ñ1Ó3ˆ�r!   c                 ó0  — | j                   j                  ||«      j                  «       }|rAt        |d¬«      }t	        d«      d   s$t        || j                  j                  «       «      S |S | j                  j                  «       dkD  rt        d«      ‚|S )a  
        Args:
            feed_names(list): This parameter represents the input names of the model.
            fetch_list(list): This parameter represents the Tensors that need to be returned
                after the model runs. The default is None.
            return_numpy(bool): This parameter indicates whether convert the fetched Tensors
                (the Tensor specified in the fetch list) to numpy.ndarray. if it is False,
                the type of the return value is a list of :code:`LoDTensor`. The default is True.
        Tr¼   ÚFLAGS_enable_pir_in_executorr
   z;`merge_tensor` does not support when return_numpy is False.)	r9  ÚrunÚ_move_to_listr/   r   r¬   r6  r©   r4   )r  Ú
feed_namesrÁ   Úenable_job_schedule_profilerÚtensorss        r"   r=  z_StandaloneExecutor.run3  s—   € ð —-‘-×#Ñ#ØÐ4ó
ç
‰-‹/ð 	ñ Ü˜w¨TÔ2ˆGÜÐ;Ó<Ø.òô & g¨t¯z©z×/IÑ/IÓ/KÓLÐLØˆNà�z‰z×)Ñ)Ó+¨aÒ/Ü"ØQóð ð ˆNr!   Úreturnc                 ó<   — | j                   j                  |«      }|S r%   )r9  Úrun_profile)r  r?  Úprogram_descs      r"   rD  z_StandaloneExecutor.run_profileP  s   € Ø—}‘}×0Ñ0°Ó<ˆØÐr!   c                 óp   — t        j                  | j                  | j                  | j                  «      }|S r%   )r   ÚStandaloneExecutorr4  r6  r7  )r  Únew_exes     r"   r8  z(_StandaloneExecutor._create_new_executorT  s'   € Ü×)Ñ)¨$¯+©+°t·z±zÀ4Ç;Á;ÓOˆØˆr!   N)TF)	r,  r-  r.  r  r=  r   ÚProgramDescrD  r8  r    r!   r"   r1  r1  +  s*   „ ò4ð KPóð:¨×)9Ñ)9ó ór!   r1  c                   óD   — e Zd Z G d„ d«      Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	y	)
Ú_ExecutorCachec                   ó   — e Zd Zd„ Zd„ Zd„ Zy)ú_ExecutorCache._CachedDatac                 óŒ  — || _         || _        || _        || _        || _        || _        || _        t        | j                   t        j                  «      r«| j                   j                  sFt        j                  | j                   j                  «      j                  «       | j                   _
        t        t!        | j                   j                  | j                  | j                  | j                  «      «      | _        y t        t!        | j                   | j                  | j                  | j                  «      «      | _        y r%   )r—   rT   r˜   r™   rš   r  r'   r-   r   r÷   rø   r   ÚIrGraphr  Ú
to_programÚhashrï   r&  ©r  r—   rT   r˜   r™   rš   r  r'   s           r"   r  z#_ExecutorCache._CachedData.__init__[  sñ   € ð #ˆDŒLØˆDŒIØ(ˆDŒOØ!.ˆDÔØ"0ˆDÔØˆDŒJØˆDŒJô ˜$Ÿ,™,¬×(@Ñ(@ÔAØ—|‘|×,Ò,ô -6×,=Ñ,=ØŸ™×+Ñ+ó-ç ‘j“lð —L‘LÔ)ô  Ü=ØŸ™×-Ñ-ØŸ
™
ØŸ	™	ØŸ™ó	ó�•ô  Ü=ØŸ™ d§j¡j°$·)±)¸T¿_¹_óó�•r!   c                 ól   — t        |t        j                  «      xr | j                  |j                  k(  S r%   )r-   rK  Ú_CachedDatar&  )r  Úothers     r"   Ú__eq__z!_ExecutorCache._CachedData.__eq__…  s,   € ä˜5¤.×"<Ñ"<Ó=ò *Ø—H‘H §	¡	Ñ)ðr!   c                 ó   — | j                   S r%   )r&  ©r  s    r"   Ú__hash__z#_ExecutorCache._CachedData.__hash__‹  s   € Ø—8‘8ˆOr!   N)r,  r-  r.  r  rV  rY  r    r!   r"   rT  rM  Z  s   „ ò(	òT	ó	r!   rT  c                 óˆ   —  t        d¬«      | j                  «      | _         t        d¬«      | j                  «      | _        y )Né   )Úmaxsize)r   Ú_get_program_and_executorÚ _get_cached_program_and_executorÚ_get_pir_program_and_executorÚ)_get_cached_program_and_executor_pir_moderX  s    r"   r  z_ExecutorCache.__init__Ž  sB   € ð 1E´	À!Ô0DØ×*Ñ*ó1
ˆÔ-ð :N¼È1Ô9MØ×.Ñ.ó:
ˆÕ6r!   c                 ó8   — | j                   j                  «        y r%   )r^  Úcache_clearrX  s    r"   Úclearz_ExecutorCache.clear™  s   € Ø×-Ñ-×9Ñ9Õ;r!   c                 óN   — | j                  | j                  |||||||«      «      S r%   )r^  rT  rR  s           r"   Úget_program_and_executorz'_ExecutorCache.get_program_and_executorœ  s:   € ð ×4Ñ4Ø×ÑØØØØØØØóó

ð 
	
r!   c                 óâ  — |j                   }t        |t        j                  «      r|j                  n|}|j
                  }|j                  }|j                  }|j                  }|j                  }|j                  }	t        |t        j                  «      s$t        |j                  t        j                  «      rÄt        |t        j                  «      r|n|j                  }
|
j                  }d}|�"|j                  rd}d|_        t        ddi«       |
j                  |	|«       |rd|_        t!        j"                  |
j                  «      }|j%                  «       }t'        |d«      r|j(                  |_        |}n'd }ddlm}m}  |«       r|t1        «       k(  r |«        |}t3        |||||d¬«      }|�|j4                  rdnd}|�|j6                  rdnd}t9        d«      d   rd}d}|s|rt;        ||«      }t=        ||||«       |j?                  «       }|j@                  r4d	|j@                  v r&dd
l!m"} |j@                  d	   }|d   } |||||«      }n`tG        jH                  d«      }t9        d«      d   rdtK        |jL                  «      i}nd|jL                  i}tG        jN                  |g|«      }|jP                  r™d|jP                  v r‹tS        |jP                  d   «      dkD  rptU        jV                  «       }|jP                  d   D ]  }|jY                  |«       Œ |j[                  «       D ]$  }|j]                  |«      }|j_                  |«       Œ& ta        |||	«      }||fS )NFTÚ!FLAGS_new_executor_use_cuda_graphÚlr_schedulerr   )Ú	prim2origÚprim_enabled)r—   rT   r˜   r™   rš   r›   r<  Ústandalone_opt)Ú
apply_passÚschedule_modeÚdefaultÚ	pass_list)1r—   r-   r   r÷   rø   rT   r˜   r™   rš   r  r'   r  Ú_build_strategyÚallow_cuda_graph_capturer   Ú_compiler   rO  rP  Úhasattrrh  Úpaddle.incubate.autogradri  rj  r   rŸ   r´   rµ   r   r  rº   rŒ   Ú_pipeline_optÚ1paddle.distributed.passes.pipeline_scheduler_passrl  r   ÚJobr	   rJ   ÚPlanÚ	_pass_optr3   r   ÚPassManagerÚadd_passÚ	job_typesÚ
ir_programr=  r1  ) r  Úcached_datar—   rú   rT   r˜   r™   rš   r  r'   r  Úbuild_strategyÚuse_cuda_graphÚir_graphÚconverted_programri  rj  r´   rµ   r¶   Únew_programrl  rk  r¹   r:  Údefault_jobÚtype_to_programÚpmÚpÚjob_typer}  rH  s                                    r"   r]  z(_ExecutorCache._get_program_and_executor²  st  € Ø×%Ñ%ˆô ˜'¤8×#;Ñ#;Ô<ð ×Òàð 	ð
 ×ÑˆØ ×+Ñ+ˆ
Ø#×1Ñ1ˆØ$×3Ñ3ˆØ×!Ñ!ˆØ×!Ñ!ˆô �gœx×7Ñ7Ô8¼JØ�N‰NœH×4Ñ4ô=
ô
 ˜g¤x×'?Ñ'?Ô@ñ à—^‘^ð ð
 .×=Ñ=ˆNà"ˆNð Ð*Ø"×;Ò;à!%�Ø:?�Ô7ÜÐ>ÀÐEÔFØ×%Ñ% e¨UÔ3ÙØ:>�Ô7Ü ×(Ñ(Ð)9×)@Ñ)@ÓAˆHØ (× 3Ñ 3Ó 5Ðä�} nÔ5Ø1>×1KÑ1KÐ!Ô.à-‰Mð "ˆNßHáŒ~ 'Ô-AÓ-CÒ"CÙ”à#ˆMä%Ø!ØØ!Ø'Ø)Øô
ˆð Ð%¨×)FÒ)Fñ àð 	ð Ð)¨n×.IÒ.Iñ àð 	ô Ð3Ó4Ø*ò
ð #ˆNØ ˆLá™\ä6°t¸ZÓHˆNÜ%Ø˜¨°~ôð —m‘m“oˆà×%Ò%Ø  K×$=Ñ$=Ñ=õð )×6Ñ6Ð7GÑHˆNØ& Ñ7ˆIÙØ˜[¨)°^ó‰Dô Ÿ(™( 9Ó-ˆKÜÐ7Ó8Ø.òð Ô/°×0@Ñ0@ÓAð#‘ð $-¨k×.>Ñ.>Ð"?�Ü—9‘9˜k˜]¨OÓ<ˆDð ×!Ò!Ø˜{×4Ñ4Ñ4Ü�K×)Ñ)¨+Ñ6Ó7¸!Ò;ä—‘Ó"ˆBØ ×*Ñ*¨;Ô7�Ø—‘˜A•ð 8à ŸN™NÖ,�Ø!Ÿ_™_¨XÓ6�
Ø—‘�zÕ"ð -ô & e¨T°5Ó9ˆØ˜GÐ#Ð#r!   c                 óN   — | j                  | j                  |||||||«      «      S r%   )r`  rT  rR  s           r"   Úget_pir_program_and_executorz+_ExecutorCache.get_pir_program_and_executor7  s:   € ð ×=Ñ=Ø×ÑØØØØØØØóó

ð 
	
r!   c                 óH  — |j                   }|j                  }|j                  }|j                  }|j                  }|j
                  }|j                  }t        |||¬«       t        j                  d«      }	d|i}
t        j                  |	g|
«      }t        |||«      }||fS )N)r˜   rš   rn  )r—   rT   r˜   r™   rš   r  r'   r§   r   rw  rx  r1  )r  r~  r—   rT   r˜   r™   rš   r  r'   r„  r…  r:  rH  s                r"   r_  z,_ExecutorCache._get_pir_program_and_executorM  s£   € Ø×%Ñ%ˆØ×ÑˆØ ×+Ñ+ˆ
Ø#×1Ñ1ˆØ$×3Ñ3ˆØ×!Ñ!ˆØ×!Ñ!ˆäØ 
¸>õ	
ô —h‘h˜yÓ)ˆØ$ gÐ.ˆÜ�y‰y˜+˜¨Ó8ˆä% e¨T°5Ó9ˆØ˜ÐÐr!   N)
r,  r-  r.  rT  r  rc  re  r]  rŠ  r_  r    r!   r"   rK  rK  Y  s-   „ ÷2ñ 2òh	
ò<ò
ò,C$òJ
ó, r!   rK  c                   ó.  — e Zd ZdZd4d„Zd„ Zd„ Zd„ Zd„ Zd„ Z	d	„ Z
d
„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zdefd„Zd„ Zd„ Zd„ Zd„ Zd„ Zed„ «       Ze	 d5d„«       Zed„ «       Z	 d„ Zd„ Z	 	 	 	 	 	 	 	 	 d6d„Z d „ Z!d!„ Z"d"„ Z#d#„ Z$d7d$„Z%d%„ Z&d&„ Z'	 	 	 	 	 	 	 	 d8d'„Z(	 	 	 	 	 	 	 	 	 	 d9d(„Z)	 	 	 	 	 	 	 	 	 	 	 d:d)„Z*d*dddg dfd+„Z+	 	 	 	 	 	 	 d;d,„Z,d-„ Z-e	 d<d.„«       Z.ed=d/„«       Z/	 	 	 	 	 	 	 	 	 	 	 d:d0„Z0	 	 	 	 	 	 	 	 	 d>d1„Z1	 	 	 	 	 	 	 d?d2„Z2	 	 	 	 	 	 	 	 	 d>d3„Z3y)@ÚExecutora  
    :api_attr: Static Graph

    An Executor in Python, supports single/multiple-GPU running,
    and single/multiple-CPU running.

    Args:
        place(paddle.CPUPlace()|paddle.CUDAPlace(n)|str|None): This parameter represents
            which device the executor runs on. When this parameter is None, PaddlePaddle
            will set the default device according to its installation version. If Paddle
            is CPU version, the default device would be set to `CPUPlace()` . If Paddle is
            GPU version, the default device would be set to `CUDAPlace(0)` . Default is None.
            If ``place`` is string, it can be ``cpu``, and ``gpu:x``, where ``x``
            is the index of the GPUs. Note: users only pass one Place or None to initialize
            Executor when using multiple-cards. Other APIs will override the cards. See
            `document for multiple-cards <https://www.paddlepaddle.org.cn/documentation/docs/en/develop/guides/01_paddle2.0_introduction/update_en.html#stand-alone-multi-card-launch>`_

    Returns:
        Executor

    Examples:

        .. code-block:: python

            >>> import paddle
            >>> import numpy
            >>> import os

            >>> # Executor is only used in static graph mode
            >>> paddle.enable_static()

            >>> # Set place explicitly.
            >>> # use_cuda = True
            >>> # place = paddle.CUDAPlace(0) if use_cuda else paddle.CPUPlace()
            >>> # exe = paddle.static.Executor(place)

            >>> # If you don't set place, PaddlePaddle sets the default device.
            >>> exe = paddle.static.Executor()

            >>> train_program = paddle.static.Program()
            >>> startup_program = paddle.static.Program()
            >>> with paddle.static.program_guard(train_program, startup_program):
            ...     data = paddle.static.data(name='X', shape=[None, 1], dtype='float32')
            ...     hidden = paddle.static.nn.fc(data, 10)
            ...     loss = paddle.mean(hidden)
            ...     paddle.optimizer.SGD(learning_rate=0.01).minimize(loss)
            ...
            >>> # Run the startup program once and only once.
            >>> # Not need to optimize/compile the startup program.
            >>> exe.run(startup_program)

            >>> # Run the main program directly without compile.
            >>> x = numpy.random.random(size=(10, 1)).astype('float32')
            >>> loss_data, = exe.run(train_program, feed={"X": x}, fetch_list=[loss.name])

            >>> # Or, compiled the program and run. See `CompiledProgram`
            >>> # for more details.
            >>> compiled_prog = paddle.static.CompiledProgram(
            ...     train_program)
            >>> loss_data, = exe.run(compiled_prog, feed={"X": x}, fetch_list=[loss.name])

    Nc                 óT  — |€t        j                  «       }|| _        nt        j                  |«      | _        i | _        i | _        i | _        i | _        i | _        i | _	        i | _
        t        j                  «       }|j                  | j                  «       t        j                  |«      | _        d| _        i | _        d| _        t'        j(                  d«      | _        t-        «       | _        d | _        d| _        t        j4                  j7                  «       | _        d| _        y )NFÚ__auto_checkpoint_executor__)r   Ú_current_expected_place_r  Ú_get_paddle_placeÚprogram_cachesÚ
ctx_cachesÚtrainer_cachesÚscope_cachesÚmicro_scope_cacheÚ
var_cachesÚpruned_program_cachesr   r3  r5  r�  Ú_default_executorÚ_closedÚpruned_program_scope_cachesÚ_prepare_to_run_calledr   ÚgenerateÚ_auto_checkpoint_namerK  Ú_executor_cacheÚ_fleet_executorÚ_fleet_executor_with_standaloneÚop_proto_and_checker_makerÚkOpRoleAttrNameÚop_role_keyr@  )r  r  Úexpected_placer‡  s       r"   r  zExecutor.__init__¢  sû   € Øˆ=Ü&×?Ñ?ÓAˆNØ'ˆD�Jä"×4Ñ4°UÓ;ˆDŒJØ ˆÔØˆŒØ ˆÔØˆÔØ!#ˆÔØˆŒØ%'ˆÔ"Ü�J‰J‹LˆØ	�‰�D—J‘JÔÜ!%§¡¨qÓ!1ˆÔØˆŒØ+-ˆÔ(Ø&+ˆÔ#ä%0×%9Ñ%9Ø*ó&
ˆÔ"ô  .Ó/ˆÔà#ˆÔð 05ˆÔ,ä×:Ñ:×JÑJÓLˆÔà,1ˆÕ)r!   c                 óÞ   — | j                   |j                  v xrT t        |j                  «       | j                      «      t        t        j
                  j                  j                  «      z  S r%   )r¤  Ú
attr_namesrØ   Ú	all_attrsr   r¢  ÚOpRoleÚOptimize)r  rj   s     r"   Ú_is_optimizer_opzExecutor._is_optimizer_opÅ  s[   € Ø×Ñ 2§=¡=Ð0ò A´SØ�L‰L‹N˜4×+Ñ+Ñ,ó6
ä”×/Ñ/×6Ñ6×?Ñ?Ó@ñ6Að 	Ar!   c                 óX   — | j                  «        | j                  j                  «        y r%   )ÚcloserŸ  rc  rX  s    r"   Ú__del__zExecutor.__del__Ê  s   € ð 	�
‰
ŒØ×Ñ×"Ñ"Õ$r!   c                 ó:   — | j                   j                  |d «      S r%   )r•  Úget©r  Úprogram_cache_keys     r"   Ú_get_scope_cachezExecutor._get_scope_cacheÑ  s   € Ø× Ñ ×$Ñ$Ð%6¸Ó=Ð=r!   c                 ó:   — | j                   j                  |d «      S r%   )r“  r°  r±  s     r"   Ú_get_ctx_cachezExecutor._get_ctx_cacheÔ  s   € Ø�‰×"Ñ"Ð#4°dÓ;Ð;r!   c                 ó:   — | j                   j                  |d «      S r%   )r”  r°  r±  s     r"   Ú_get_trainer_cachezExecutor._get_trainer_cache×  ó   € Ø×"Ñ"×&Ñ&Ð'8¸$Ó?Ð?r!   c                 ó:   — | j                   j                  |d «      S r%   )r’  r°  r±  s     r"   Ú_get_program_cachezExecutor._get_program_cacheÚ  r¸  r!   c                 ó"   — || j                   |<   y r%   )r’  ©r  r²  r—   s      r"   Ú_add_program_cachezExecutor._add_program_cacheÝ  s   € Ø18ˆ×ÑÐ-Ò.r!   c                 ó:   — | j                   j                  |d «      S r%   )r˜  r°  r±  s     r"   Ú_get_pruned_program_cachez"Executor._get_pruned_program_cacheà  s   € Ø×)Ñ)×-Ñ-Ð.?ÀÓFÐFr!   c                 ó"   — || j                   |<   y r%   )r˜  r¼  s      r"   Ú_add_pruned_program_cachez"Executor._add_pruned_program_cacheã  s   € Ø8?ˆ×"Ñ"Ð#4Ò5r!   c                 ó:   — | j                   j                  |d «      S r%   )r›  r°  r±  s     r"   Ú_get_pruned_program_scope_cachez(Executor._get_pruned_program_scope_cacheæ  s   € Ø×/Ñ/×3Ñ3Ð4EÀtÓLÐLr!   c                 ó"   — || j                   |<   y r%   )r›  r¼  s      r"   Ú_add_pruned_program_scope_cachez(Executor._add_pruned_program_scope_cacheé  s   € Ø>Eˆ×(Ñ(Ð):Ò;r!   c                 ó"   — || j                   |<   y r%   )r“  )r  Úctx_cache_keyÚctxs      r"   Ú_add_ctx_cachezExecutor._add_ctx_cacheì  s   € Ø),ˆ�‰˜Ò&r!   c                 ó"   — || j                   |<   y r%   )r”  )r  Útrainer_cache_keyrÈ  s      r"   Ú_add_trainer_cachezExecutor._add_trainer_cacheï  s   € Ø14ˆ×ÑÐ-Ò.r!   c                 ó"   — || j                   |<   y r%   )r•  )r  Úscope_cache_keyr'   s      r"   Ú_add_scope_cachezExecutor._add_scope_cacheò  s   € Ø-2ˆ×Ñ˜/Ò*r!   Úmicro_scopesc                 ó"   — || j                   |<   y r%   )r–  )r  r²  rÐ  s      r"   Ú_add_micro_scopes_cachez Executor._add_micro_scopes_cacheõ  s   € Ø4@ˆ×ÑÐ0Ò1r!   c                 ó:   — | j                   j                  |d «      S r%   )r–  r°  r±  s     r"   Ú_get_micro_scopes_cachez Executor._get_micro_scopes_cacheø  s   € Ø×%Ñ%×)Ñ)Ð*;¸TÓBÐBr!   c                 ó"   — t        d|› d�«       y )Nz"use_program_cache is force set to z! by FLAGS_FORCE_USE_PROGRAM_CACHE)r  )r  Úuse_program_caches     r"   Ú_log_force_set_program_cachez%Executor._log_force_set_program_cacheû  s   € ÜØ0Ð1BÐ0CÐCdÐeõ	
r!   c           	      ó\  — |j                  «       }|j                  D �]  }|j                  j                  «       dk(  �rë|j                  j	                  d«      d   }||   }|j                  |«      }	|	j                  t        j                  j                  j                  k7  rGt        |t        j                  «      s!t        || j                  |	j                  «      }t        |	|«       |j                  j!                  d«      }
d}t#        |«      |   rt        j$                  ||||
«       �Œ|g}d}|j&                  r‹d|j&                  v r}|j&                  d   d   }t)        |j*                  «      r|j+                  «       d   n|j*                  d   }||z  dk(  sJ ‚t-        j.                  t-        j0                  |«      |d«      }t3        |«      D ]N  }|dkD  r$t        ||   | j                  |	j                  «      n||   }t        j$                  ||||
|z  |z   «       ŒP �Œ y  y )	NrT   r_   r   rn   r<  r
   rk  Únum_micro_batches)r�   ra   rJ   rb   rd   rS   rQ   r   r=   r>   ÚSTRINGSr-   r1   r  r  rY   ro   r   Úset_feed_variableru  ÚcallablerO   r6   rÖ   r7   rC   )r  r—   rT   r™   r'   r�   rj   rk   Úcur_feedrS   ru   Úpir_flag_nameÚmicro_cur_feedÚnum_micro_batchÚ
batch_sizerE   Ú
micro_feeds                    r"   Ú
_feed_datazExecutor._feed_data   s  € à×+Ñ+Ó-ˆØ×"Õ"ˆBØ�w‰w�|‰|‹~ Ó'Ø#%§7¡7§>¡>°%Ó#8¸Ñ#;Ð ØÐ 0Ñ1�Ø"×&Ñ&Ð'7Ó8�Ø—9‘9¤§¡× 4Ñ 4× <Ñ <Ò<Ü% h´·±Ô?Ü#0Ø$ d§j¡j°#·)±)ó$˜ô *¨#¨xÔ8Ø—g‘g—l‘l 5Ó)�Ø >�Ü˜]Ó+¨MÒ:Ü×*Ñ*Ø˜xÐ)9¸3öð '/ Z�NØ&'�Oà×-Ò-Ø,°×0EÑ0EÑEà*1×*?Ñ*?Ø,ñ+à-ñ+/˜ô
  (¨¯©Ô7ð %ŸN™NÓ,¨QÒ/à!)§¡°Ñ!2ð #ð
  *¨OÑ;¸qÒ@Ð@Ð@Ü)+¯©ÜŸH™H XÓ.°Àó*˜ô # ?Ö3˜ð
  /°Ò2ô *Ø .¨qÑ 1°4·:±:¸s¿y¹yôð "0°Ñ!2ð #ô ×.Ñ.Ø!Ø&Ø)Ø /Ñ1°AÑ5õ	ò 4ñ ñg #r!   c                 óv  — t        «       }|j                  «       }|j                  D ]Ä  }|j                  «       dk(  r®|j	                  «       d   }|j                  |«       t        |j	                  «       d      }|j	                  «       d   }	||   }
t        |
t        j                  «      st        |
| j                  |«      }
t        |
||	|«       t        j                  ||
|d«       ŒÄ n t        |j                  «       «      D ]0  }||vsŒ|j!                  |«       t#        j$                  d|z  «       Œ2 y )Nz
pd_op.datarN   rQ   rO   r   zFThe value %s is not found in program. It is not declared or is pruned.)r	  r�   ra   rN   rz   Úaddr   r-   r   r1   r  r  r\   rÛ  r0   ró   Úpopr”   r•   )r  r—   rT   r'   Úfeed_target_namesr�   rj   rk   Úvar_typeÚ	var_shaperÝ  Ú	feed_names               r"   Ú_pir_feed_datazExecutor._pir_feed_data8  s  € ä›EÐØ×+Ñ+Ó-ˆØ×"Ô"ˆBØ�w‰w‹y˜LÒ(Ø#%§8¡8£:¨fÑ#5Ð Ø!×%Ñ%Ð&6Ô7Ü4°R·X±X³ZÀÑ5HÑI�ØŸH™H›J wÑ/�	ØÐ 0Ñ1�Ü! (¬D¯N©NÔ;Ü,¨X°t·z±zÀ8ÓL�HÜ)ØÐ.°	¸8ôô ×&Ñ& u¨hÐ8HÈ!ÕLáð #ô$ ˜dŸi™i›kÖ*ˆIØÐ 1Ò1Ø—‘˜Ô#Ü—‘Ø\Øñ õñ +r!   c                 ó|   — t        t        |«      «      D �cg c]  }t        j                  |||«      ‘Œ }}|S c c}w r%   )rC   r3   r   Úget_fetch_variable)r  r˜   rš   r'   rE   Úoutss         r"   Ú_fetch_datazExecutor._fetch_dataV  sH   € ô œ3˜z›?Ô+ó
á+�ô ×#Ñ# E¨>¸1Õ=Ø+ð 	ð 
ð ˆùò	
s   —9c                 óx  — g }g }d„ }t        |«      D ]¢  \  }}t        |t        «      r|D ]  } ||||«       Œ Œ(t        |t        «      rat        |d   t        t        f«      s3t	        dj                  |||t        |d   «      j                  «      «      ‚|d   D ]  } ||||«       Œ Œ™ ||||«       Œ¤ ||fS )a4  
        Split optimize_ops from fetch_list, which provided to specify program prunning.
        Args:
            fetch_list(list): The original fetch_list.
            Possible types of fetch_list are:
                fetch_list = ['loss']
                fetch_list = [[sgd, sgd], 'loss']
                fetch_list = [([sgd, sgd], [(param, grad)]), 'loss']

        Returns:
            optimize_ops(list): The optimize operators splited from fetch_list.
            fetch_list(list):  The updated fetch_list which does not contain optimize operators.
        c                 óö   — t        |t        «      r-|j                  «       r| j                  |«       y t	        d«      ‚t        |t
        t        f«      r|j                  |«       y t	        dt        |«      «      ‚)Nz0The operator in fetch_list is not an optimize_opzOThe item in fetch_list should be str, variable or optimize_op, but received %s.)r-   r   Ú_is_optimize_oprx   rÆ   r   r|   rb   )Ú_optimize_opsÚ_fetch_listrÌ   s      r"   Ú_get_targetsz@Executor._split_optimize_ops_in_fetch_list.<locals>._get_targetso  sk   € Ü˜$¤Ô)Ø×'Ñ'Ô)Ø!×(Ñ(¨Õ.ä#ØJóð ô ˜D¤8¬S /Ô2Ø×"Ñ" 4Õ(äØeÜ˜“Jóð r!   r   z�Requires fetch_list[{}][0] shall be one of (list, tuple) when type(fetch_list[{}]) is `tuple`, but received fetch_list[{}][0]'s type is `{}`.)r{   r-   r0   rÊ   rÆ   rR   rb   r,  )Úclsr˜   ró  rô  rõ  ÚindexrÌ   rE   s           r"   Ú!_split_optimize_ops_in_fetch_listz*Executor._split_optimize_ops_in_fetch_list]  sØ   € ð ˆØˆò	ô  % ZÖ0‰KˆE�4ô ˜$¤Ô%Û�AÙ  °¸QÕ?ñ ä˜D¤%Ô(Ü! $ q¡'¬D´%¨=Ô9Ü#ð h÷  oñ  oØ! 5¨%´°d¸1±g³×1GÑ1Góóð ð
 ˜aœ�AÙ  °¸QÕ?ñ !ñ ˜]¨K¸Õ>ð# 1ð& ˜MÐ)Ð)r!   c                 ó¬  — t        |t        j                  «      }|r/|j                  r|j                  }nt	        j
                  d«       y|}g }t        |t        «      rt        |j                  «       «      }nEt        |t        t        f«      r/t        |«      D ]!  \  }}	|t        |	j                  «       «      z  }Œ# |sD|j                  D ]5  }
|
j                  D ]$  }|j                  «       sŒ|j                  |«       Œ& Œ7 ||z   }|j                  ||«      }|r4||_        t!        j"                  |j$                  «      |_        d|_        |S |}|S )a‰  
        Prune operators and variables which are not needed to generate
        :code:`fetch_list` and optimize operators.
        Prune operators and variables which are needed
        to generate variables to be feeded.

        Notes: This is a very low level API. Users should not use this API
        directly.

        Args:
            program(Program): the origin program
            feed(list|dict): feed dict or list.
            fetch_list(list|Variable): A list of variables need to be fetched
            optimize_ops(list[Operator]): A list of optimizer operators

        Returns:
            Program:  A new, pruned program.
        z[The program holds no _program, maybe it is constructed by graph, which can't be pruned yet.NF)r-   r   r÷   rø   r”   r•   rý   r0   ró   rÊ   r{   rù   ra   rò  rx   Ú_prune_with_inputr   ÚGraphrJ   r  Ú	_compiled)rö  r—   rT   r˜   Úoptimize_opsr  Úorigin_programr?  rE   r   rf   rj   ÚtargetsÚpruned_programs                 r"   Ú_prune_programzExecutor._prune_program”  s3  € ô, ˜g¤x×'?Ñ'?Ó@ˆÙØ×ÒØ!(×!1Ñ!1‘ä—‘Øqôð à$ˆNàˆ
Ü�dœDÔ!Ü˜dŸi™i›kÓ*‰JÜ˜œt¤U˜mÔ,Ü$ Tž?‘��4Øœd 4§9¡9£;Ó/Ñ/‘
ð +ñ Ø'×.Ô.�ØŸ)œ)�BØ×)Ñ)Õ+Ø$×+Ñ+¨BÕ/ñ $ð /ð
 ˜|Ñ+ˆØ'×9Ñ9¸*ÀgÓNˆáð  .ˆGÔÜ!ŸZ™Z¨×(;Ñ(;Ó<ˆGŒNØ %ˆGÔð ˆð %ˆGàˆr!   c                 ó´  — t        |t        j                  «      }|r>|j                  r|j                  j	                  «       }n't        j                  d«       |S |j	                  «       }t        |t        «      r[t        |j                  «       «      D ]=  }|j                  |«      rŒ|j                  |«       t        j                  d|z  «       Œ? |S t        |t        t        f«      rlt        |«      D ]^  \  }}t        |j                  «       «      D ]=  }|j                  |«      rŒ|j                  |«       t        j                  d|z  «       Œ? Œ` |S )ae  
        Update the feed dict, remove the feed item which is pruned in program.

        Notes: This is a very low level API. Users should not use this API
        directly.

        Args:
            program(Program): the pruned program.
            feed(list|dict): feed dict or list.

        Returns:
            feed:(list|dict)  updated feed.
        z@The program holds no _program, maybe it is constructed by graph.r‡   )r-   r   r÷   rø   r�   r”   r•   rý   r0   ró   r’   ræ  rÊ   r{   )rö  r—   rT   r  r�   rê  rE   r   s           r"   Ú_update_feedzExecutor._update_feedÒ  s   € ô ˜g¤x×'?Ñ'?Ó@ˆÙØ×ÒØ&×/Ñ/×<Ñ<Ó>‘ä—‘ØVôð �à"×/Ñ/Ó1ˆLä�dœDÔ!Ü! $§)¡)£+Ö.�	Ø#×+Ñ+¨IÕ6Ø—H‘H˜YÔ'Ü—M‘MØcØ#ñ$õð /ð" ˆô ˜œt¤U˜mÔ,Ü$ Tž?‘��4Ü!% d§i¡i£kÖ!2�IØ'×/Ñ/°	Õ:ØŸ™ Ô+Ü Ÿ™ØgØ'ñ(õñ "3ð +ð ˆr!   c                 óÜ   — | j                   s`d| _         | j                  j                  «       D ]!  \  }}| j                  j	                  |«       ~Œ# | j                  j                  «        yy)a2  
        Close the executor. This interface is used for distributed training (PServers mode).
        This executor can not be used after calling the interface, because
        this interface releases resources associated with the current Trainer.

        Returns:
            None

        Examples:

            .. code-block:: python

                >>> import paddle

                >>> cpu = paddle.CPUPlace()
                >>> exe = paddle.static.Executor(cpu)
                >>> # execute training or testing
                >>> exe.close()
        TN)rš  r”  Úitemsr™  Úrelease_trainerr­  )r  ÚkÚtrainer_instances      r"   r­  zExecutor.close  sc   € ð( �|Š|ØˆDŒLØ'+×':Ñ':×'@Ñ'@Ö'BÑ#�Ð#Ø×&Ñ&×6Ñ6Ð7GÔHÙ$ð (Cð ×"Ñ"×(Ñ(Õ*ð r!   c                 óÎ   — | j                   ry| j                  j                  «       D ]!  \  }}| j                  j	                  |«       ~Œ# | j                  j                  «        y)z7
        flush all trainer param to root_scope
        N)rš  r”  r  r™  r  rc  )r  Ú_r  s      r"   ÚflushzExecutor.flush"  sY   € ð �<Š<ØØ#'×#6Ñ#6×#<Ñ#<Ö#>ÑˆAÐØ×"Ñ"×2Ñ2Ð3CÔDÙ ð $?ð 	×Ñ×!Ñ!Õ#r!   Fc
                 ó  — t         j                  j                  dd«      }
|
�|
dv }| j                  |«       t	        «       r| j                  |||||||¬«      }|S | j                  |||||||||	¬«	      }t        j                  «        |S )a®  
        Run the specified :code:`Program` or :code:`CompiledProgram`. It should be noted that the executor
        will execute all the operators in :code:`Program` or :code:`CompiledProgram` without pruning some
        operators of the :code:`Program` or :code:`CompiledProgram` according to fetch_list. And you could
        specify the scope to store the :code:`Tensor` during the executor running if the scope
        is not set, the executor will use the global scope, i.e. :code:`paddle.static.global_scope()`.

        Args:
            program(Program|CompiledProgram): This parameter represents the :code:`Program` or
                :code:`CompiledProgram` to be executed. If this parameter is not provided, that
                parameter is None, the program will be set to :code:`paddle.static.default_main_program()`.
                The default is None.
            feed(list|dict): This parameter represents the input Tensors of the model.
                If it is single card training, the feed is dict type, and if it is multi-card
                training, the parameter feed can be dict or list of Tensors. If the
                parameter type is dict, the data in the feed will be split and sent to
                multiple devices (CPU/GPU), that is to say, the input data will be evenly
                sent to different devices, so you should make sure the number of samples of
                the current mini-batch must be greater than the number of places;
                if the parameter type is list, those data are copied directly to each device,
                so the length of this list should be equal to the number of places.
                The default is None.
            fetch_list(list): This parameter represents the Tensors that need to be returned
                after the model runs. The default is None.
            feed_var_name(str): This parameter represents the name of the input Tensor of
                the feed operator. The default is "feed".
            fetch_var_name(str): This parameter represents the name of the output Tensor of
                the fetch operator. The default is "fetch".
            scope(Scope): the scope used to run this program, you can switch
                it to different scope. default is :code:`paddle.static.global_scope()`
            return_numpy(bool): This parameter indicates whether convert the fetched Tensors
                (the Tensor specified in the fetch list) to numpy.ndarray. if it is False,
                the type of the return value is a list of :code:`LoDTensor`. The default is True.
            use_program_cache(bool): This parameter indicates whether the input :code:`Program` is cached.
                If the parameter is True, the model may run faster in the following cases:
                the input program is :code:`paddle.static.Program`, and the parameters(program, feed Tensor name
                and fetch_list Tensor) of this interface remains unchanged during running.
                The default is False.
            use_prune(bool): This parameter indicates whether the input :code:`Program` will be pruned.
                If the parameter is True, the program will be pruned accroding to the given feed and fetch_list,
                which means the operators and variables in program that generate :code:`feed` and are not
                needed to generate :code:`fetch_list` will be pruned. The default is False, which means the
                program will not pruned and all the operators and variables will be executed during running.
                Note that if the tuple returned from :code:`Optimizer.minimize()` is passed to :code:`fetch_list`,
                :code:`use_prune` will be overrided to True, and the program will be pruned.

        Returns:

            List: The fetched result list.

        Examples:

            .. code-block:: python
                :name: code-example-1

                >>> import paddle
                >>> import numpy

                >>> # First create the Executor.
                >>> paddle.enable_static()
                >>> place = paddle.CPUPlace()  # paddle.CUDAPlace(0)
                >>> exe = paddle.static.Executor(place)

                >>> data = paddle.static.data(name='X', shape=[None, 1], dtype='float32')
                >>> hidden = paddle.static.nn.fc(data, 10)
                >>> loss = paddle.mean(hidden)
                >>> adam = paddle.optimizer.Adam()
                >>> adam.minimize(loss)
                >>> i = paddle.zeros(shape=[1], dtype='int64')
                >>> array = paddle.tensor.array_write(x=loss, i=i)

                >>> # Run the startup program once and only once.
                >>> exe.run(paddle.static.default_startup_program())

                >>> x = numpy.random.random(size=(10, 1)).astype('float32')
                >>> loss_val, array_val = exe.run(feed={'X': x},
                ...                                 fetch_list=[loss.name, array.name])
                >>> print(array_val)
                >>> # doctest: +SKIP("Random output")
                [array(0.16870381, dtype=float32)]
                >>> # doctest: -SKIP

            .. code-block:: python
                :name: code-example-2

                >>> # doctest: +REQUIRES(env:GPU)
                >>> import paddle
                >>> import numpy as np

                >>> # First create the Executor.
                >>> paddle.enable_static()
                >>> place = paddle.CUDAPlace(0)
                >>> exe = paddle.static.Executor(place)

                >>> data = paddle.static.data(name='X', shape=[None, 1], dtype='float32')
                >>> class_dim = 2
                >>> prediction = paddle.static.nn.fc(data, class_dim)
                >>> loss = paddle.mean(prediction)
                >>> adam = paddle.optimizer.Adam()
                >>> adam.minimize(loss)

                >>> # Run the startup program once and only once.
                >>> exe.run(paddle.static.default_startup_program())
                >>> build_strategy = paddle.static.BuildStrategy()
                >>> binary = paddle.static.CompiledProgram(
                ...     paddle.static.default_main_program(), build_strategy=build_strategy)
                >>> batch_size = 6
                >>> x = np.random.random(size=(batch_size, 1)).astype('float32')

                >>> prediction, = exe.run(binary,
                ...                         feed={'X': x},
                ...                     fetch_list=[prediction.name])
                >>> # If the user uses two GPU cards to run this python code, the printed result will be
                >>> # (6, class_dim). The first dimension value of the printed result is the batch_size.
                >>> print("The prediction shape: {}".format(
                ...     np.array(prediction).shape))
                The prediction shape: (6, 2)

                >>> print(prediction)
                >>> # doctest: +SKIP("Random output")
                [[-0.37789783 -0.19921964]
                 [-0.3577645  -0.18863106]
                 [-0.24274671 -0.12814042]
                 [-0.24635398 -0.13003758]
                 [-0.49232286 -0.25939852]
                 [-0.44514108 -0.2345845 ]]
                >>> # doctest: -SKIP

        ÚFLAGS_FORCE_USE_PROGRAM_CACHEN)r
   Ú1TÚTrueÚtrue)r—   rT   r˜   r™   rš   r'   rÁ   )	r—   rT   r˜   r™   rš   r'   rÁ   rÖ  Ú	use_prune)	rÙ   Úenvironr°  r×  r   Ú_run_pir_implÚ	_run_implr   Úupdate_autotune_status)r  r—   rT   r˜   r™   rš   r'   rÁ   rÖ  r  Úforce_use_program_cacheÚress               r"   r=  zExecutor.run-  s¿   € ô\ #%§*¡*§.¡.Ø+¨Tó#
Ðð #Ð.Ø 7ð <ð !Ðð ×-Ñ-Ð.?Ô@ÜŒ=Ø×$Ñ$ØØØ%Ø+Ø-ØØ)ð %ó ˆCð, ˆ
ð —.‘.ØØØ%Ø+Ø-ØØ)Ø"3Ø#ð !ó 
ˆCô ×'Ñ'Ô)Øˆ
r!   c
           	      óÐ  — | j                   rt        d«      ‚|d u }
|€
t        «       }| j                  |«      }ddlm} t        |t        «      rŽ|j                  r‚ |«       s{d|j                  v r;| j                  €t        «       | _	        | j                  |||| j                  |¬«      S d|j                  v r|j                  d   }n| j                  |||¬«      S t        |t        «      rŒ|j                  r€|j                  d   }t        j                   |«      }t#        j$                  «       }|j'                  |«       t#        j(                  |«      | _        d|j                  v r|j                  d   }t        |t        «      r?t-        |j/                  «       j0                  «      dk(  r|
rd	}t3        j4                  |«       |€
t7        «       }|}|}| j9                  |«      \  }}|rd
}	|	rþt;        |||«      }| j=                  |«      }|€Èt        |t>        j@                  «      r‡| jC                  tE        tG        |«      «      «      }tI        jH                  |«      }||_%        | jC                  tE        tG        |«      «      «      	 €$| jM                  tE        tG        |«      «      |«       | jO                  ||||«      }| jQ                  ||«       n|}| jS                  ||«      }|}tU        || jV                  «      �r@|€i }n0t        |tX        tZ        f«      rt-        |«      dk(  sJ d«       ‚|d   }t        |t\        «      st_        dta        |«      z  «      ‚| jS                  ||«      }i }t        |t>        j@                  «      s$t        |jb                  t>        j@                  «      r´t        |t>        j@                  «      r|n|jb                  }|jd                  }|�~|jf                  rrddg}|D ]O  }ti        jj                  |d«      }t        |tD        «      r|jm                  «       }|dk(  rd
nd}to        |«      ||<   ŒQ tq        |D �ci c]  }|d
“Œ c}«       | jr                  ju                  |||||| jV                  |«      \  }}| jw                  ||||«       ty        |d«      �rNddl=m>} t        |j~                  |«      sJ d«       ‚|j~                  } |«       } |j/                  «       j€                  |j‚                     }!t…        j†                  | g«      j‰                  t‹        |!jŒ                  «      «      }"t#        jŽ                  ||j‚                  «      }#t‘        |"t#        j’                  «       «      }$t#        j”                  «       rt3        j4                  d«       nQt#        j–                  «       r!|#j™                  |$|#j›                  «       «       n|#j™                  |$| jV                  «       |j�                  tY        |jŸ                  «       «      || j                   «      }%tq        |«       |%S t        |t>        j@                  «      }&|	�r|&r|j¢                  j/                  «       }'n|j/                  «       }'|'j€                  D ]Õ  }(|'j¤                  j§                  |(j©                  «       «      })|'j€                  |(   }*|)j«                  «       du sŒN|)ja                  «       t"        j¬                  j®                  j°                  k(  sŒ„|)j³                  «       d
u sŒ—|*j´                  d
u sŒ¦|*j¶                  d
u sŒµ|*j¸                  du sŒÄ|(|vsŒÉt»        d|(z  «      ‚ t½        j¾                  | |«       |jÁ                  || jV                  «       |jÂ                  sJ d|jÂ                  › �«       ‚| jÅ                  |jÆ                  |«      S c c}w )Nú"Attempted to use a closed Executorr   )Úuse_new_executorÚ	fleet_opt)r—   rT   r˜   Úwith_standalone_executorrÁ   Ústartup_program)r˜   rÖ  Úheter_placeúÇNow you are using default_main_program, but there are no operators in the program to be executed. Please ensure you create model correctly or you can pass the Program or the CompiledProgram manually.Tr
   úNot compiled with data parallelú9feed requires dict as its Parameter. But you passed in %sÚFLAGS_new_executor_serial_runÚ!FLAGS_new_executor_sequential_runFr  rh  ©ÚLRSchedulerúmust be LRSchedulerú•Caution!!! When capturing CUDA Graph, the learning rate scheduler would not take any effect! Please set the learning rate manually before each batch!zNeed feed data for variable %sz0Program must have _is_inference = True, but get )drš  r4   r   Ú_check_fetch_listÚ-paddle.distributed.auto_parallel.static.utilsr  r-   r   ru  r   ré   Ú_run_using_fleet_executorr¡  Ú_run_pipelineÚ_heter_pipeline_optr   r‘  r   r3  r5  r�  r™  r3   r�   ra   r”   r•   r#   rø  rû   r¿  r   r÷   rÃ  r|   rÅ   r:   Ú_share_vars_fromrÅ  r  rÁ  r  r  r  r0   rÊ   rý   rÆ   rb   r  rp  Úsequential_runrÙ   rÚ   Úlowerr°   r   rŸ  re  rã  rs  Úpaddle.optimizer.lrr%  rh  rŽ   Ú	_var_namer6   r7   r  r   rQ   Úget_variable_tensorr  ÚCPUPlaceÚis_cuda_graph_capturingÚis_compiled_with_ipuÚ
_copy_fromr4  r=  ró   r@  rø   rJ   r¾   Úencoderƒ   r=   r>   Ú
LOD_TENSORrK   Ústop_gradientÚis_dataÚbelong_to_optimizerrM   ÚacpÚ_auto_checkpointrr  r  Ú_run_inferenceÚ	_executor)+r  r—   rT   r˜   r™   rš   r'   rÁ   rÖ  r  Úuse_default_main_programr  r  r‡  Ú
error_infoÚ_origin_fetch_listÚ_origin_programrý  Ú	cache_keyÚcached_pruned_programÚprogram_scope_cacher   Ústored_flagr  r  Úschedule_flagÚflagÚvalueÚfrH  r%  rh  Úlr_valueÚlr_varr
  r9   Ú
cpu_tensorÚretr  r�   ÚvarnameÚvardescÚvarobjs+                                              r"   r  zExecutor._run_implà  s@  € ð �<Š<ÜÐCÓDÐDà#*¨d ?Ð Øˆ?Ü*Ó,ˆGà×+Ñ+¨JÓ7ˆ
õ	
ô
 �w¤Ô(Ø×%Ò%Ù$Ô&à˜g×3Ñ3Ñ3à×'Ñ'Ð/Ü+BÓ+D�DÔ(Ø×5Ñ5Ø#ØØ)Ø-1×-QÑ-QØ!-ð 6ó ð ð ! G×$9Ñ$9Ñ9Ø!×/Ñ/Ð0AÑB‘à×)Ñ)ØØ)Ø&7ð *ó ð ô �gœwÔ'¨G×,GÒ,Gð "×5Ñ5°mÑDˆKÜ#×5Ñ5°kÓBˆKÜ—
‘
“ˆAØ�K‰K˜Ô$Ü%)§]¡]°1Ó%5ˆDÔ"à  G×$?Ñ$?Ñ?à!×5Ñ5Ð6GÑH�ô �w¤Ô(Ü�G×(Ñ(Ó*×.Ñ.Ó/°1Ò4á'ðCð ô —‘˜jÔ)àˆ=Ü “NˆEð (ÐØ!ˆØ#'×#IÑ#IØó$
Ñ ˆ
�Lñ ØˆIÙÜ5Ø˜Ð1óˆIð %)×$BÑ$BÀ9Ó$MÐ!Ø$Ð,Ü˜g¤x×'?Ñ'?Ô@Ø*.×*NÑ*NÜœB˜Ó/Ó0ó+Ð'ô #Ÿi™i¨Ó0�Gà/B�GÔ,à×<Ñ<Ü¤ ?Ó 3Ó4óð  ð ð
 ×<Ñ<Ü¤ ?Ó 3Ó4°gôð "&×!4Ñ!4Ø˜T :¨|ó"�ð ×.Ñ.¨y¸.ÕIà!6�à×$Ñ$ ^°TÓ:ˆDØ$ˆGä$ W¨d¯j©jÕ9Øˆ|Ø‘Ü˜D¤4¬ -Ô0Ü˜4“y A’~ÐHÐ'HÓH�~Ø˜A‘w�Ü˜d¤DÔ)ÜØOÜ˜D“zñ#óð ð ×$Ñ$ W¨dÓ3ˆDàˆKÜ˜'¤8×#;Ñ#;Ô<Ä
Ø—‘¤× 8Ñ 8ôAô
 " '¬8×+CÑ+CÔDñ à Ÿ™ð !ð
 "2×!AÑ!A�Ø!Ð-°.×2OÒ2Oà7Ø;ð%�Mó !.˜Ü "§	¡	¨$°Ó 6˜Ü% e¬SÔ1Ø$)§K¡K£M˜EØ,1°VªO¡DÀ˜EÜ,0°«K˜ DÒ)ð !.ô ±Ó>±¨1˜q $™w°Ñ>Ô?à#×3Ñ3×LÑLØØØØØØ—
‘
Øó ÑˆG�Wð �O‰O˜G T¨=¸%Ô@Ü�w Õ/Ý;ä!Ø×(Ñ(¨+ôð )à(ó)ð ð  '×3Ñ3�Ù'›>�Ø ×-Ñ-Ó/×4Ñ4°\×5KÑ5KÑL�Ü—x‘x  
Ó+×2Ñ2´=ÀÇÁÓ3NÓO�Ü×1Ñ1°%¸×9OÑ9OÓP�ä*¨4´·±³ÓA�
Ü×/Ñ/Ô1Ü—M‘Mðdõô ×.Ñ.Ô0à×%Ñ% j°&·-±-³/ÕBà×%Ñ% j°$·*±*Ô=à—+‘+Ü�T—Y‘Y“[Ó!ØØ×1Ñ1óˆCô
 �kÔ"ØˆJä˜g¤x×'?Ñ'?Ó@ˆò ÙØ&×/Ñ/×<Ñ<Ó>‘à&×3Ñ3Ó5�Ø'×,Ô,�Ø&×+Ñ+×4Ñ4°W·^±^Ó5EÓF�Ø%×*Ñ*¨7Ñ3�ð ×'Ñ'Ó)¨UÒ2ØŸ™›¬$¯,©,×*>Ñ*>×*IÑ*IÓIØ×/Ñ/Ó1°TÒ9Ø×,Ñ,°Ò4ØŸ™¨$Ò.Ø×2Ñ2°eÒ;Ø tÒ+ä$Ð%EÈÑ%OÓPÐPð -ô 	×Ñ˜T 7Ô+à×Ñ˜ §
¡
Ô+à×!Ò!ð	Và=¸g×>SÑ>SÐ=TÐUó	VØ!à×"Ñ" 7×#4Ñ#4°dÓ;Ð;ùòU ?s   Ñ
_#c           	      ó®  — dd l }|j                  j                  }	|j                  j                  j                  }
| j
                  rt        d«      ‚|d u }|r |
«       }| j                  |«      }t        ||	«      r?t        |j                  «       j                  «      dk(  r|rd}t        j                  |«       |€
t        «       }|€i }n0t        |t        t         f«      rt        |«      dk(  sJ d«       ‚|d   }t        |t"        «      st%        dt'        |«      z  «      ‚| j(                  j+                  |||||| j,                  |«      \  }}| j/                  |||«       t1        |d«      �r;ddlm} t        |j6                  |«      sJ d	«       ‚|j6                  } |«       }|j8                  }t;        j<                  |g«      j?                  tA        |jB                  «      «      }t        jD                  t        «       |jF                  «      }tI        |t        jJ                  «       «      }t        jL                  «       rt        j                  d
«       nQt        jN                  «       r!|jQ                  ||jS                  «       «       n|jQ                  || j,                  «       |jU                  t        |jW                  «       «      |«      }|S )Nr   r  r  r
   r   r!  rh  r$  r&  r'  ),r¢   r   r   r   r   rš  r4   r(  r-   r3   r�   ra   r”   r•   r#   r0   rÊ   rý   rÆ   rb   rŸ  rŠ  r  rë  rs  r0  r%  rh  rM  r6   r7   r  r   rQ   r2  r1  r  r3  r4  r5  r6  r4  r=  ró   )r  r—   rT   r˜   r™   rš   r'   rÁ   r¢   r   r   r@  rA  rH  r%  rh  rL  rM  r
  r9   rN  rO  s                         r"   r  zExecutor._run_pir_implÇ  ss  € ó 	à—*‘*×$Ñ$ˆØ%Ÿz™zŸ™×CÑCÐà�<Š<ÜÐCÓDÐDà#*¨d ?Ð Ù#Ù*Ó,ˆGà×+Ñ+¨JÓ7ˆ
ô �w Ô(Ü�G×(Ñ(Ó*×.Ñ.Ó/°1Ò4á'ðCð ô —‘˜jÔ)àˆ=Ü “NˆEàˆ<Ø‰DÜ˜œt¤U˜mÔ,Ü�t“9 ’>ÐDÐ#DÓD�>Ø˜‘7ˆDÜ˜$¤Ô%ÜØKÜ˜“:ñóð ð
  ×/Ñ/×LÑLØØØØØØ�J‰JØó
Ñˆ�ð 	×Ñ˜G T¨5Ô1ä�7˜NÕ+Ý7äØ×$Ñ$ kôð %à$ó%ð ð #×/Ñ/ˆLÙ#“~ˆHØ—^‘^ˆFä—8‘8˜X˜JÓ'×.Ñ.¬}¸V¿\¹\Ó/JÓKˆDÜ×-Ñ-Ü“ × 6Ñ 6óˆFô ' t¬T¯]©]«_Ó=ˆJÜ×+Ñ+Ô-Ü—‘ð`õô ×*Ñ*Ô,à×!Ñ! *¨f¯m©m«oÕ>à×!Ñ! *¨d¯j©jÔ9à�k‰kœ$˜tŸy™y›{Ó+¨\Ó:ˆØˆ
r!   c                 ó$   — |j                  |«      S r%   )r=  )r  ÚexerT   s      r"   r>  zExecutor._run_inference%  s   € Ø�w‰w�t‹}Ðr!   c           	      óÊ  ‡— d„ Šd„ }|€g S  ‰|«      r|gS  ||«      sJ dj                  t        |«      «      «       ‚g }t        |«      D ]•  \  }} ‰|«      r|j                  |«       Œ  ||«      rAt	        ˆfd„|D «       «      r|j                  t        |«      «       ŒW|j                  |«       Œit        dj                  |t        |«      j                  «      «      ‚ |S )Nc                 óB   — t        | t        t        t        t        f«      S r%   )r-   r   r|   r   r   rÇ   s    r"   Ú<lambda>z,Executor._check_fetch_list.<locals>.<lambda>)  s   € ¤:Ø”(œC¤¬5Ð1ô$
r!   c                 ó.   — t        | t        t        f«      S r%   )r-   rÊ   r0   rÇ   s    r"   rX  z,Executor._check_fetch_list.<locals>.<lambda>,  s   € ¤J¨s´U¼D°MÔ$Br!   z•Currently , The fetch_list type only should be list or tuple, 
but the input type is {}. For more information please refer to 
the executor.run(...).c              3   ó.   •K  — | ]  } ‰|«      –— Œ y ­wr%   r    )Ú.0ÚvÚis_fetch_vars     €r"   Ú	<genexpr>z-Executor._check_fetch_list.<locals>.<genexpr>?  s   øè ø€ Ð4±¨1‘| A—±ùs   ƒzPRequire fetch_list[{}] 's type shall be one of (OpResult, str), but received {}.)	rR   rb   r{   rx   ÚallÚextendr0   rÆ   r,  )r  r˜   Úis_tuple_listr  rE   rS   r]  s         @r"   r(  zExecutor._check_fetch_list(  så   ø€ ñ
ˆñ CˆàÐØˆIÙ˜
Ô#Ø�<Ðá˜ZÔ(ð 	
ð%ç%+¡V¬D°Ó,<Ó%=ó	
Ð(ð ˆÜ 
Ö+‰FˆAˆsÙ˜CÔ Ø—
‘
˜3•á˜sÔ#ÜÓ4±Ó4Ô4Ø—J‘Jœt C›yÕ)à—J‘J˜s•OäØf×mÑmØœ4 ›9×-Ñ-óóð ð ,ð  ˆ
r!   c                 ól  — t        t        t        |«      «      dz   d«      5 }|j                  t        |«      «       d d d «       |j                  rLd|j                  v r=t        dd«      5 }|j                  t        |j                  d   «      «       d d d «       y y y # 1 sw Y   ŒbxY w# 1 sw Y   y xY w)Nz_train_desc.prototxtÚwÚ
fleet_desczfleet_desc.prototxt)Úopenr|   rÅ   r$  Ú
_fleet_opt)r  r—   ÚtrainerÚfouts       r"   Ú_dump_debug_infozExecutor._dump_debug_infoL  s–   € Ü”#”b˜“kÓ"Ð%;Ñ;¸SÔAÀTØ�J‰J”s˜7“|Ô$÷ Bà×Ò ,°'×2DÑ2DÑ"DÜÐ+¨SÔ1°TØ—
‘
œ3˜w×1Ñ1°,Ñ?Ó@ÔA÷ 2Ð1ð #EÐ÷ BÐAú÷ 2Ð1ús   ¢BÁ+(B*ÂB'Â*B3c                 ó  — t        |j                  j                  «       «      }||k  r|}t        d||fz  «       |||d   d   z  k  rt        d||z  |fz  «       ||z  |d   d<   |j	                  |d   d   |z  «       |S )Nz[Pipeline training: setting the pipeline num to %d is enough because there are only %d filesÚconcurrency_listr   znPipeline training: setting the 1st element in concurrency_list to %d is enough because there are only %d files)r3   ÚdatasetÚget_filelistr)  Ú
set_thread)r  Úpipeline_optrl  Úpipeline_numÚfilelist_lengths        r"   Ú_adjust_pipeline_resourcez"Executor._adjust_pipeline_resourceS  s¹   € Ü˜gŸo™o×:Ñ:Ó<Ó=ˆØ˜\Ò)Ø*ˆLÜØmØ" OÐ4ñ5ôð ˜\¨LÐ9KÑ,LÈQÑ,OÑOÒOÜð AØ" lÑ2°OÐDñEôð
   <Ñ/ð Ð+Ñ,¨QÑ/ð 	×Ñ˜<Ð(:Ñ;¸AÑ>ÀÑMÔNØÐr!   c                 óò	  — g }g }d }d}|j                  «       j                  D ]�  }| j                  |«      r nz|j                  d«      sŒ(|j	                  d«      dk7  r|j	                  d«      n|}|�||k7  r"|j                  g «       |j                  |«       |d   j                  |«       |}Œ� t        |«      }d}	d }
|	|k  r¥|	|k  r||	   |k(  r|	dz  }	|	|k  r	||	   |k(  rŒ|	|k(  rn||	   }
|	dz  }	|	}d}|	|k  r&||	   |
k7  r||	   |k7  rd}n|	dz  }	|	|k  r	||	   |
k7  rŒ|	|k(  rn@|sŒmt        ||	«      D ](  }||   D ]  }|j                  d|
«       Œ |
||<   |dz  }Œ* |	|k  rŒ¥d }g }g }t        |«      D ]M  }	|�|||	   k7  r%|j                  g «       |j                  ||	   «       |d   j                  ||	   «       ||	   }ŒO t        «       }|j                  «       j                  D ]I  }|j                  «       j                  |«      }|j                  rŒ/|j                  |j                  «       ŒK t        |«      }t        «       }t        «       }t        |«      D �	cg c]  }	g ‘Œ }}	t        |«      D ]ã  }	t        «       }t        «       }||	   D ]w  }|j                   D ].  }|j#                  |«      D ]  }||vsŒ|j                  |«       Œ Œ0 |j$                  D ])  }|j'                  |«      D ]  }|j                  |«       Œ Œ+ Œy |	dk(  rg ||	<   n|	dk(  r||z  |z  ||	<   n||z  ||	<   t)        j*                  |«      }t)        j*                  |«      }Œå t        |«      }g }g }t        |«      D �	cg c]  }	g ‘Œ }}	d}g }t        |«      D ]×  }	|j                  |«       |j                  |t        ||	   «      z   dz
  «       |t        ||	   «      z  }|	|dz
  k  r#||	   j                  t-        ||	dz      «      «       |j/                  «       } ||	   |k7  r<| j1                  t-        ||	   «      t-        ||	   «      «      } |j                  | «       ŒÇ|j                  | «       ŒÙ |D �	cg c]  }	t-        |	«      ‘Œ }!}	d}"d }#t        t        |«      «      D ]  }	||	   }$|$|k7  sŒ|"rt3        d	«       d}"|	}#Œ  |#€t3        d
«       y ||#   ||#   ||#   |!|#   ||#   gS c c}	w c c}	w c c}	w )NÚcpuÚ	op_devicerÒ   éÿÿÿÿr   r
   TFz'only one region of program can be heterzwarning: non heter program)r�   ra   r«  Úhas_attrro   rx   r3   rC   Ú	_set_attrr`  r	  rŽ   rS   rƒ   rå  rN   Úinput_namesrc   Úoutput_namesrd   r:   Údeepcopyr0   rŒ   rú  r)  )%r  r—   Úops_listÚ	type_listÚpreÚtype_cpurj   Úcur_attrÚlrE   Ú
type_heterÚstartÚvalidÚjÚmerged_ops_listÚmerged_type_listÚ	data_varsr  rS   Ú
inputs_preÚoutputs_preÚin_from_prer…   r†   rc   Útmprd   Ú
start_listÚend_listÚ	send_listÚsumÚprogram_listÚprogÚ	recv_listÚfoundÚheter_indexr;   s%                                        r"   Úsplit_program_by_devicez Executor.split_program_by_devicef  s_  € ØˆØˆ	ØˆØˆØ×&Ñ&Ó(×,Ô,ˆBØ×$Ñ$ RÔ(ÙØ�{‰{˜;Õ'ð —w‘w˜{Ó+¨rÒ1ð —G‘G˜KÔ(à!ð ð
 �; #¨¢/Ø—O‘O BÔ'Ø×$Ñ$ XÔ.Ø˜‘×#Ñ# BÔ'Ø‘ð -ô �	‹NˆØˆØˆ
Ø�!ŠeØ�a’%˜I a™L¨HÒ4Ø�Q‘�ð �a’%˜I a™L¨HÓ4à�AŠvØà" 1™ˆJØ�‰FˆAØˆEØˆEØ�a’%˜I a™L¨JÒ6Ø˜Q‘< 8Ò+Ø!�EØØ�Q‘�ð	 �a’%˜I a™L¨JÓ6ð �AŠvØÙØä˜5 !–_�Ø" 1œ+�BØ—L‘L ¨jÕ9ð &à)�	˜!‘Ø�Q‘‘ð	 %ð+ �!‹eð6 ˆØˆØÐÜ�q–ˆAØˆ{˜c Y¨q¡\Ò1Ø×&Ñ& rÔ*Ø ×'Ñ'¨	°!©Ô5Ø˜BÑ×&Ñ& x°¡{Ô3Ø˜A‘,‰Cð ô “Eˆ	Ø×%Ñ%Ó'×,Ô,ˆAØ×&Ñ&Ó(×,Ñ,¨QÓ/ˆCØ—?“?Ø—‘˜cŸh™hÕ'ð -ô
 �Ó ˆÜ“Uˆ
Ü“eˆÜ#(¨¤8Ó,¡8˜a’r 8ˆÐ,Ü�q–ˆAÜ“UˆFÜ“eˆGØ% aÔ(�ØŸ^œ^�EØ!Ÿx™x¨ž˜Ø gÒ-Ø"ŸJ™J s�Oñ  /ð ,ð !Ÿoœo�FØ!Ÿy™y¨Ö0˜ØŸ™ CÕ(ñ  1ñ .ð )ð �AŠvØ!#�˜A’Ø�a’Ø"-°	Ñ"9¸VÑ!C�˜A’à!,¨vÑ!5�˜A‘ÜŸ™ vÓ.ˆJÜŸ-™-¨Ó0‰Kð% ô( �ÓˆØˆ
ØˆÜ!& q¤Ó*¡˜A’R ˆ	Ð*ØˆØˆÜ�q–ˆAØ×Ñ˜cÔ"Ø�O‰O˜C¤# o°aÑ&8Ó"9Ñ9¸AÑ=Ô>Ø”3� qÑ)Ó*Ñ*ˆCØ�1�q‘5ŠyØ˜!‘×#Ñ#¤D¨°Q¸±UÑ);Ó$<Ô=Ø—=‘=“?ˆDØ Ñ" hÒ.Ø×-Ñ-Ü˜ Q™Ó(¬$¨y¸©|Ó*<ó�ð ×#Ñ# DÕ)à×#Ñ# DÕ)ð ñ '2Ó2¡k ”T˜!•W kˆ	Ð2ØˆØˆÜ”sÐ+Ó,Ö-ˆAØ  Ñ#ˆAØ�H‹}ÙÜÐCÔDØ�Ø‘ð .ð ÐÜÐ.Ô/Øð ˜;Ñ'Ø˜Ñ%Ø˜+Ñ&Ø˜+Ñ&Ø˜[Ñ)ðð ùòo -ùò0 +ùò" 3s   É)	S*Î	S/Ñ9S4c	                 óÔ  — d}	d}
|j                   �`|j                   j                  dd«      dk(  rd}	|j                   j                  dd«      dk(  rd}	|j                   j                  dd	«      rd
}
|€
t        «       }|€g }|€g }t        |«      t        |«      k(  sJ ‚t	        |t
        j                  «      }|	r| j                  |«      }|sÃ|j                  r$t        «       j                  |j                  «      }nn|j                  r$t        «       j                  |j                  «      }n>t        «       j                  |j                   «      }|j                  |j                  «       |j                  |«       |	rÎ|j                  «       n¼|j                  r.t        «       j                  |j                   j                  «      }ng|j                  r.t        «       j                  |j                   j                  «      }n-t        «       j                  |j                   j                   «      }|j                  |j                   «       |dk  r`|
r(|j#                  t        |j                   d   «      «       nG|j$                  dk  rt'        d«      ‚|j#                  |j$                  «       n|j#                  |«       |j)                  |«       |j+                  |||«       ||fS )Nr   Úworker_classrÒ   ÚHeterCpuWorkerr
   rg  ÚHeterXpuTrainerÚ
use_ps_gpuFTÚworker_placeszSYou should set thread num first, either in Datasetor in Executor.train_from_dataset)rf  r°  r#   r3   r-   r   r÷   r–  ru  r   Ú_create_trainerr,  Ú_set_thread_barrierÚ_is_distributedÚ_set_programÚ_set_heter_infor—   Ú_set_threadÚ
thread_numr4   Ú
_set_debugÚ_set_fetch_var_and_info)r  r—   rl  r'   ÚthreadÚdebugr˜   r}   Úprint_periodÚis_heterr›  r  rO  rg  s                 r"   Ú_prepare_trainerzExecutor._prepare_traineré  s‘  € ð ˆØˆ
Ø×ÑÐ)Ø×!Ñ!×%Ñ% n°bÓ9Ð=MÒMØ�Ø×!Ñ!×%Ñ% i°Ó4Ð8IÒIØ�Ø×!Ñ!×%Ñ% l°EÔ:Ø!�
Øˆ=Ü “NˆEØÐØˆJØÐØˆJÜ�:‹¤# j£/Ò1Ð1Ð1Ü˜g¤x×'?Ñ'?Ó@ˆÙØ×.Ñ.¨wÓ7ˆCÙà×$Ò$Ü(Ó*×:Ñ:Ø×)Ñ)ó‘ð ×,Ò,Ü(Ó*×:Ñ:Ø×/Ñ/ó‘ô )Ó*×:Ñ:¸7×;MÑ;MÓN�Ø×+Ñ+¨G×,CÑ,CÔDØ× Ñ  Ô)ÙØ×'Ñ'¨Õ,à×$Ò$Ü(Ó*×:Ñ:Ø—O‘O×1Ñ1ó‘ð ×,Ò,Ü(Ó*×:Ñ:Ø—O‘O×7Ñ7ó‘ô )Ó*×:Ñ:Ø—O‘O×.Ñ.ó�ð × Ñ  §¡Ô1à�QŠ;ÙØ×#Ñ#¤C¨×(:Ñ(:¸?Ñ(KÓ$LÕMØ×#Ñ# qÒ(Ü"ð8óð ð
 ×#Ñ# G×$6Ñ$6Õ7à×Ñ Ô'à×Ñ˜5Ô!Ø×'Ñ'¨
°JÀÔMØ�gˆ~Ðr!   c           
      óÀ  — |j                   �Îdd l}|�t        d«      ‚g }|j                  «       j                  j                  «       D ]   }|j                  sŒ|j                  |«       Œ" |j                  j                  «       j                  d«      }|j                  d«       |j                  d«       |j                  dg«       |j                  |«       �nz|j                  ��`|j                  d   }|j                  d   }|dk7  rÛd|j                  vrÚdd l}|�t        d	«      ‚g }|j                  «       j                  j                  «       D ]   }|j                  sŒ|j                  |«       Œ" |j                  j                  «       j                  d
«      }|j                  d«       |j                  d«       |j                  dg«       |j                  |«       n|€t        d«      ‚t!        j"                  |«      }t%        j&                  «       }|j)                  |«       t%        j*                  |«      | _        n|€t        d«      ‚|j/                  «        g }|j                   �r|j                   d   }|D ]O  }t1        |t2        «      r|j4                  }n|}||j                  «       j                  v sŒ?|j                  |«       ŒQ t7        |j                   d   g |dd¬«      |j                   d<   |j                   d   j9                  d«      }|j:                  D ]F  }|j<                  dk(  sŒ|j?                  dt$        j@                  jB                  jD                  «       ŒH d }| jG                  ||||||||	¬«      \  }}|jI                  |«       |jK                  «        |j                   €|j                  €| jM                  ||¬«       |jN                  du r+|jP                  jN                  rtS        jT                  d«       |jW                  |jP                  jX                  «       |j                  d uxs, |jZ                  d uxr |jZ                  j]                  dd«      }|du rA| j,                  j_                  |j`                  |jc                  «       ||jd                  «      }n’|€g }tg        |d |«      }| ji                  |«      }|€S| j,                  j_                  |j`                  |jc                  «       ||jd                  «      }| jk                  ||«       n|jm                  |jd                  «       |
�x|jo                  d«      }tq        ||
«      }|js                  «        | j,                  ju                  |«       |jw                  «        |du rV| j,                  jy                  |«       n:| j,                  ju                  |«       |du r| j,                  jy                  |«       |j{                  «        |j}                  «        |r:|j                  d«      j�                  «       }|jƒ                  «       }t…        |«      S y )Nr   ú(dataset should be None for pipeline modeÚFileInstantDatasetr
   ÚNoneÚpipeline_stager  Ú
is_fl_modez.dataset should be None for heter pipeline modeÚInMemoryDatasetz)dataset is need and should be initializedÚsection_programrT   r‰   ©r—   rT   r˜   r™   rš   Úop_role©r—   rl  r'   r¦  r§  r˜   r}   r¨  ©r—   rg  Fú0dataset should call set_use_ps_gpu in PsGpu moder›  )Cru  r¢   r4   r�   rŽ   Úvaluesr:  rx   ÚbaseÚDatasetFactoryÚcreate_datasetÚset_batch_sizern  Úset_filelistÚset_use_varr,  r   r‘  r   r3  r5  r�  r™  Ú_prepare_to_runr-   r   rN   rŸ   rf   ra   rb   rx  r¢  r©  rª  rª  Ú
_set_inferÚ_gen_trainer_descri  r›  Ú
proto_descr  r  Ú_dynamic_adjust_before_trainr£  rf  r°  Úinit_for_datasetrJ   Ú_descrl  rû   r·  rÌ  ÚResetDatasetÚget_worker_scoper   rƒ  Úrun_from_datasetÚstopr  Ú_dynamic_adjust_after_trainÚ_finish_to_runr¾   Úget_fetch_listr>  r/   )r  r—   rl  r'   r¦  Úis_inferr§  r˜   r}   r¨  Úfetch_handlerr¢   rˆ  rS   Ústage_idr  r‡  Úreal_fetch_listÚreal_programr   rš   Ú
main_blockrj   rg  Úreused_trainerr  rD  Úscope0Úfetch_monitorÚarrrA  s                                  r"   Ú_run_from_datasetzExecutor._run_from_dataset7	  sË  € ð × Ñ Ð,ÛàÐ"Ü"Ð#MÓNÐNð ˆIØ×+Ñ+Ó-×2Ñ2×9Ñ9Ö;�Ø—;“;Ø×$Ñ$ SÕ)ð <ð —k‘k×0Ñ0Ó2×AÑAØ$óˆGð ×"Ñ" 1Ô%Ø×Ñ˜qÔ!Ø× Ñ  & Ô*Ø×Ñ 	Ö*Ø×(Ñ(Ñ4Ø×2Ñ2Ð3CÑDˆHà!×5Ñ5°mÑDˆKØ˜1Š}Ø w×'BÑ'BÑBÛ!àÐ*Ü*ØLóð ð
 !#�IØ&×3Ñ3Ó5×:Ñ:×AÑAÖC˜ØŸ;›;Ø%×,Ñ,¨SÕ1ð  Dð %Ÿk™k×8Ñ8Ó:×IÑIØ)ó�Gð ×*Ñ*¨1Ô-Ø×&Ñ& qÔ)Ø×(Ñ(¨&¨Ô2Ø×'Ñ'¨	Õ2à�?Ü&ØCóð ô $×5Ñ5°kÓBˆKÜ—
‘
“ˆAØ�K‰K˜Ô$Ü%)§]¡]°1Ó%5ˆDÕ"àˆÜ"Ð#NÓOÐOà×ÑÔ!ØˆØ× Ó Ø"×0Ñ0Ð1BÑCˆLÛ'�	Ü˜i¬Ô2Ø%.§^¡^‘Nà%.�NØ! \×%>Ñ%>Ó%@×%EÑ%EÒEØ#×*Ñ*¨9Õ5ð (ô 8KØ×-Ñ-Ð.?Ñ@ØØ*Ø$Ø&ô8ˆG×!Ñ!Ð"3Ñ4ð !×.Ñ.Ð/@ÑA×GÑGÈÓJˆJØ —n”n�ð —7‘7˜gÓ%Ø—L‘LØ!Ü×7Ñ7×>Ñ>×GÑGõð	 %ð ˆJØ×.Ñ.ØØØØØØ!Ø!Ø%ð /ó 	
‰ˆˆwð 	×Ñ˜8Ô$Ø×!Ñ!Ô#à× Ñ Ð(Ø×*Ñ*Ð2Ø×%Ñ%¨g¸wÐ%ÔGà×Ñ Ñ&¨7×+=Ñ+=×+HÒ+HÜ�O‰OÐNÔOà×,Ñ,¨W×-?Ñ-?×-JÑ-JÔKà ×4Ñ4¸DÐ@ò 
Ø×Ñ dÐ*ò <Ø×"Ñ"×&Ñ& |°UÓ;ð 	ð
 ˜UÑ"à×&Ñ&×7Ñ7Ø—L‘L '§-¡-£/°5¸'¿/¹/óñ ð Ð!Ø�
Ü5°g¸tÀZÓPˆIØ#×6Ñ6°yÓAÐØÐ'Ø#'×#9Ñ#9×#JÑ#JØ—L‘L '§-¡-£/°5¸'¿/¹/ó$Ð ð ×'Ñ'¨	Ð3CÕDà ×-Ñ-¨g¯o©oÔ>àÐ$Ø%×6Ñ6°qÓ9ˆFÜ/°¸ÓFˆMØ×ÑÔ!Ø×"Ñ"×3Ñ3Ð4DÔEØ×ÑÔ Ø Ñ&Ø×&Ñ&×6Ñ6Ð7GÕHà×"Ñ"×3Ñ3Ð4DÔEØ Ñ&Ø×&Ñ&×6Ñ6Ð7GÔHà×+Ñ+Ô-Ø×ÑÔ ÙØ—.‘. Ó)×8Ñ8Ó:ˆCØ×'Ñ'Ó)ˆGÜ˜GÓ$Ð$àr!   c           
      óÒ  ‡‡‡— ‰j                   €J ‚|�J d«       ‚t        ‰d ‰«      }| j                  |«      }|r|�|S dd lŠˆˆfd„} |«       }ˆˆfd„} |«       \  }}|‰j                   d<   d Š| j	                  ‰||||‰||	¬«      \  }}|j                  |«       |j                  «        |j                  du r+|j                  j                  rt        j                  d«       |j                  |j                  j                  «       |j                  «       }| j                  j                  ‰j                   |||j"                  «      }|||g}|r| j%                  ||«       |S )	Nr¬  r   c                  óž  •— g } ‰j                  «       j                  j                  «       D ]   }|j                  sŒ| j	                  |«       Œ" ‰j
                  j                  «       j                  d«      }|j                  d«       |j                  d«       |j                  dg«       |j                  | «       |j                  «        |S )Nr­  r
   r®  )r�   rŽ   r¸  r:  rx   r¹  rº  r»  r¼  rn  r½  r¾  r¿  )rˆ  rS   rl  r¢   r—   s      €€r"   Ú_get_datasetz4Executor._prepare_pipeline_ctx.<locals>._get_datasetû	  s®   ø€ ØˆIØ×+Ñ+Ó-×2Ñ2×9Ñ9Ö;�Ø—;“;Ø×$Ñ$ SÕ)ð <ð —k‘k×0Ñ0Ó2×AÑAØ$óˆGð ×"Ñ" 1Ô%Ø×Ñ˜qÔ!Ø× Ñ  & Ô*Ø×Ñ 	Ô*Ø×#Ñ#Ô%ØˆNr!   c                  óÂ  •— ‰j                   d   } g }‰D ]O  }t        |t        «      r|j                  }n|}|| j	                  «       j
                  v sŒ?|j                  |«       ŒQ t        | g |dd¬«      } | j                  d«      }|j                  D ]F  }|j                  dk(  sŒ|j                  dt        j                  j                  j                  «       ŒH | |fS )Nr²  rT   r‰   r³  r   r´  )ru  r-   r   rN   r�   rŽ   rx   rŸ   rf   ra   rb   rx  r   r¢  r©  rª  )rÑ  rÐ  r   rš   rÒ  rj   r˜   r—   s         €€r"   Ú_get_real_program_fetch_listzDExecutor._prepare_pipeline_ctx.<locals>._get_real_program_fetch_list
  sÚ   ø€ Ø"×0Ñ0Ð1BÑCˆLØ ˆOÛ'�	Ü˜i¬Ô2Ø%.§^¡^‘Nà%.�NØ! \×%>Ñ%>Ó%@×%EÑ%EÒEØ#×*Ñ*¨9Õ5ð (ô /Ø$ØØ*Ø$Ø&ôˆLð &×+Ñ+¨AÓ.ˆJØ —n”n�ð —7‘7˜gÓ%Ø—L‘LØ!Ü×7Ñ7×>Ñ>×GÑGõð	 %ð   Ð0Ð0r!   r²  rµ  Fr·  )ru  rû   rµ  r¢   rª  rÀ  rÁ  r›  rÂ  r  r  rÃ  r£  rÅ  r™  rÄ  rJ   rl  rÉ  )r  r—   rl  r'   r¦  rÍ  r§  r˜   r}   r¨  rÎ  rÖ  rD  rÈ  rÚ  rÜ  rÑ  rÐ  rg  Útrainer_descr  r¢   s    `     `             @r"   Ú_prepare_pipeline_ctxzExecutor._prepare_pipeline_ctxá	  sy  ú€ ð ×$Ñ$Ð0Ð0Ð0ØˆÐJÐ JÓJˆä1°'¸4ÀÓLˆ	Ø×!Ñ! )Ó,ˆÙ  ØˆJãõ	ñ “.ˆõ	1ñ: )EÓ(FÑ%ˆ�oà3?ˆ×ÑÐ/Ñ0Øˆ
à×.Ñ.ØØØØØØ!Ø!Ø%ð /ó 	
‰ˆˆwð 	×Ñ˜8Ô$Ø×!Ñ!Ô#ð ×Ñ Ñ&¨7×+=Ñ+=×+HÒ+HÜ�O‰OÐNÔOØ×,Ñ,¨W×-?Ñ-?×-JÑ-JÔKà—}‘}“ˆØ×1Ñ1×BÑBØ�L‰L˜,¨¨w¯©ó
Ðð �oÐ'7Ð8ˆÙØ×Ñ 	¨3Ô/àˆ
r!   rÒ   c                 óÌ  — d|v r|d   nd}t        t        j                  dd«      «      }t        j                  dd«      j                  d«      }	t	        |	«      }
d|v sd	|v sJ d
«       ‚d	|v r<d|v sJ d«       ‚t        d«       |d	   D �cg c]  }|j                  «       ‘Œ }}|d   }nÏ|d   }|dk(  rbddlm} d|vsd|d   vs|d   d   dk(  rt        j                  d«        ||||j                  dd«      |j                  di «      |
|«      \  }}nY|dk(  rCddlm} d|v rd|d   v r|d   d   dk(  sJ d«       ‚d|v r|d   dk(  sJ d«       ‚ |||«      \  }}ndt        |«      z   dz   ‚||d	<   ||d<   t        j                  «       }|j!                  | j"                  «       d|v r|d   ng }| j$                  j'                  ||j(                  |||||||«	       y c c}w )NrÙ  r
   rÓ   r   rÑ   rÒ   rÉ   Ú	schedulerÚtasksz�Fleet executor need configuration for scheduler, you can choose from 1F1B or Origin. Or you can provide a list of task nodes to init fleet executor directly.Útask_id_to_rankzUIf you provide tasks to init fleet executor, task_id_to_rank should also be provided.z/fleet executor will use user defined task nodesÚ1F1B)Úrun1f1bÚdist_strategyÚ	pp_degreez)Using 1F1B scheduler with pp_degree == 1.ÚOrigin)ÚoriginzBFor pipeline mode, the scheduler should be 1F1B instead of Origin.z=For origin scheduler mode, the num micro batches should be 1.zEFleet_executor only supports 1F1B and Origin scheduler, but received Ú.r   )rØ   rÙ   rÚ   rÖ   r3   r)  Ú	task_nodeÚ-paddle.distributed.fleet.fleet_executor_utilsrä  r”   r•   r°  rè  r|   r   r3  r5  r  r   ÚinitrJ   )r  Ú
carrier_idr—   r'   r  Úmicro_scope_listr  rÙ  rÛ   rã   rå   Útaskrá  râ  rà  rä  rè  r  Úinference_root_scope_varss                      r"   Ú_prepare_fleet_executor_carrierz(Executor._prepare_fleet_executor_carrierO
  sŒ  € ð # iÑ/ð Ð)Ò*àð 	ô
 ”r—y‘yÐ!4°aÓ8Ó9ˆÜŸI™IÐ&@À"ÓE×KÑKÈCÓPÐÜÐ%Ó&ˆà˜iÑ'¨7°iÑ+?ð 	
ðWó	
Ð?ð �iÑØ$¨	Ñ1ð ð<óÐ1ô ÐCÔDØ2;¸GÒ2DÓEÑ2D¨$�T—^‘^Õ%Ð2DˆEÐEØ'Ð(9Ñ:‰Oà! +Ñ.ˆIØ˜FÒ"õð
 $¨9Ñ4Ø"¨)°OÑ*DÑDØ  Ñ1°+Ñ>À!ÒCä—M‘MÐ"MÔNÙ)0ØØØ—M‘MÐ"5°qÓ9Ø—M‘M /°2Ó6ØØ,ó*Ñ&�‘ð ˜hÒ&ÝPð $ yÑ0Ø# y°Ñ'AÑAð " /Ñ2°;Ñ?À1ÒDð\à[ó\ØDà&¨)Ñ3à!Ð"5Ñ6¸!Ò;ðWàVóWØ;á)/°¸Ó)BÑ&�‘à`ÔcfØódñ àñð ð "'ˆI�gÑØ+:ˆIÐ'Ñ(Ü—
‘
“ˆØ�‰˜Ÿ
™
Ô#ð '2°YÑ&>ˆI�kÒ"ÀBð 	"ð 	×Ñ×!Ñ!ØØ�L‰LØØØØØØ%Øõ
	
ùòg Fs   ÂG!c                 óö	  — t        |||«      }| j                  |«      }	| j                  |«      }
| j                  |«      }|j                  d   }|
€t        «       }
| j                  ||
«       |€Xg }d|v rR|d   rMt        t        |d   «      «      D ]!  }|j                  |
j                  «       «       Œ# | j                  ||«       |	�€E|j                  sJ d«       ‚|€g n|}|}d|j                  v r|j                  d   }t        |||||¬«      }	|	j                  d«      }|j                  D ]F  }|j                  dk(  sŒ|j!                  d	t"        j$                  j&                  j(                  «       ŒH | j+                  ||	«       |j                  d   }d
|v �r|d
   d   }t-        d|j/                  «       «       |j1                  «       }| j3                  |||¬«      }|j5                  |«       |d
   d   }t-        d|j/                  «       «       |j1                  «       }| j7                  |||¬«      }|j                  d«      }|j                  D ]F  }|j                  dk(  sŒ|j!                  d	t"        j$                  j&                  j(                  «       ŒH |j5                  |«       g }d|v r@|d   r;t        t        |d   «      «      D ]!  }|j                  |
j                  «       «       Œ# | j9                  ||	|
|||¬«       |r| j;                  |	|||
«       ddlm} tA        |d«      rÁ|jB                  }tE        ||«      sJ d«       ‚ |«       }|jG                  «       jH                  |jJ                     }tM        jN                  |g«      jQ                  tS        |jT                  «      «      }t#        jV                  |
|jJ                  «      }|jY                  || jZ                  «       | j\                  j_                  |«       d|v reg }|D ]\  }g } |d   D ]<  }!d }	 t#        jV                  ||!«      }|rta        |«      }|sŒ,| j                  |«       Œ> | sŒL|j                  | «       Œ^ |S |r:|
jc                  |«      ji                  «       }#|#jk                  «       }$ta        |$«      S y #  |jc                  |!«      }"|"je                  «       }|rta        |«      }ntg        |«      }Y Œ©xY w)Nr  Úinference_generationrÙ  z2program should have _pipeline_opt to start carrierr²  r³  r   r‰   r´  rá  zInserting feed ops for task)r—   rT   r™   rv  zInserting fetch ops for task)r—   r˜   rš   )r—   r'   r  rî  r  r$  rh  r&  r   )6rû   rº  r³  rÔ  ru  r#   rÏ  rC   rØ   rx   Ú	new_scoperÒ  rŸ   rf   ra   rb   rx  r   r¢  r©  rª  r½  r)  Útask_idÚget_programÚ_add_feed_opsÚset_programÚ_add_fetch_opsrñ  rã  r0  r%  rs  rh  r-   r�   rŽ   r1  r6   r7   r  r   rQ   r2  r	  r  r   r=  r/   r¾   Úget_lod_tensor_arrayr0   rÌ  r>  )%r  r—   rT   r™   rš   r˜   r  rÁ   rD  Úcached_programÚcached_scopeÚmicro_cached_scopesr  r
  Ú	real_feedrÑ  rÒ  rj   Ú	feed_taskÚfeed_programÚ
fetch_taskÚfetch_programrî  rE   r%  rh  rL  rM  r
  r9   Úresult_listr'   Úscope_result_listrP  rS   rÖ  rA  s%                                        r"   r*  z"Executor._run_using_fleet_executorª
  s  € ô 2°'¸4ÀÓLˆ	Ø×0Ñ0°Ó;ˆØ×,Ñ,¨YÓ7ˆØ"×:Ñ:¸9ÓEÐØ×)Ñ)¨+Ñ6ˆ	ØÐÜ'›>ˆLØ×!Ñ! )¨\Ô:ØÐ&Ø"$Ðà&¨)Ñ3ØÐ4Ò5äœs 9Ð-@Ñ#AÓBÖC�AØ'×.Ñ.¨|×/EÑ/EÓ/GÕHð Dà×,Ñ,¨YÐ8KÔLØÑ!à×%Ò%ðDàCóDØ%à"˜l™°ˆIØ"ˆLØ  G×$9Ñ$9Ñ9Ø&×4Ñ4Ð5FÑG�Ü0Ø$ØØ%Ø+Ø-ôˆNð (×-Ñ-¨aÓ0ˆJØ —n”n�ð —7‘7˜gÓ%Ø—L‘LØ!Ü×7Ñ7×>Ñ>×GÑGõð	 %ð ×#Ñ# I¨~Ô>Ø×-Ñ-¨kÑ:ˆIØ˜)Ò#ð & gÑ.¨qÑ1�	ÜÐ3°Y×5FÑ5FÓ5HÔIØ(×4Ñ4Ó6�Ø#×1Ñ1Ø(Ø"Ø"/ð  2ó  �ð
 ×%Ñ% lÔ3ð ' wÑ/°Ñ3�
ÜÐ4°j×6HÑ6HÓ6JÔKØ *× 6Ñ 6Ó 8�Ø $× 3Ñ 3Ø)Ø)Ø#1ð !4ó !�ð
 +×0Ñ0°Ó3�
Ø$Ÿ.œ.�Bð —w‘w 'Ó)ØŸ™Ø%Ü ×;Ñ;×BÑB×KÑKõð	 )ð ×&Ñ& }Ô5à!Ðà&¨)Ñ3ØÐ4Ò5äœs 9Ð-@Ñ#AÓBÖC�AØ$×+Ñ+¨L×,BÑ,BÓ,DÕEð Dð ×0Ñ0ØØ&Ø"Ø#Ø!4Ø)Að 1ô ñ ð �O‰O˜N¨D°-ÀÔNå3ä�7˜NÔ+Ø"×/Ñ/ˆLÜ˜l¨KÔ8ÐOÐ:OÓOÐ8Ù#“~ˆHØ×)Ñ)Ó+×0Ñ0°×1GÑ1GÑHˆFÜ—8‘8˜X˜JÓ'×.Ñ.¬}¸V¿\¹\Ó/JÓKˆDÜ×-Ñ-Ø˜l×4Ñ4óˆFð �J‰J�t˜TŸZ™ZÔ(à×Ñ× Ñ  Ô+à˜)Ñ#ð
 ˆKÛ,�Ø$&Ð!Ø(¨Ô5�GØ!�Fð
2Ü!%×!9Ñ!9¸%ÀÓ!I˜Ù'Ü%-¨fÓ%5˜Fò Ø)×0Ñ0°Õ8ð  6ò" %Ø×&Ñ&Ð'8Õ9ð) -ð* ÐáØ×'Ñ'¨Ó7×FÑFÓHˆCØ×'Ñ'Ó)ˆGÜ˜GÓ$Ð$Øøð'2Ø#Ÿn™n¨WÓ5˜Ø!$×!9Ñ!9Ó!;˜Ù'Ü%-¨fÓ%5™Fä%)¨&£\˜Füs   Ð,#R:Ò:<S8c                 óâ  — |j                  «       }|j                  «       }||j                  v r|j                  |«      }n6|j	                  |t
        j                  j                  j                  d¬«      }t        |||«      skt        |«      D ]]  \  }}|j                  |«      r/|j                  |«      }	|j                  dd|gid|	gid|i¬«       ŒFt        j                  d|z  «       Œ_ |S )	NTr‚   rT   r^   r_   rn   r„   r‡   )rŒ   r�   rŽ   rS   r�   r   r=   r>   r�   rl   r{   r’   r“   r”   r•   )
r  r—   rT   r™   rœ   r�   r�   rE   rN   rž   s
             r"   r÷  zExecutor._add_feed_opsN  sö   € Ø—m‘m“oˆà"×/Ñ/Ó1ˆà˜L×-Ñ-Ñ-Ø#×'Ñ'¨Ó6‰Hà#×.Ñ.Ø"Ü—\‘\×)Ñ)×8Ñ8Ø ð /ó ˆHô " ,°°mÔDÜ$ Tž?‘��4Ø×'Ñ'¨Ô-Ø&×*Ñ*¨4Ó0�CØ ×,Ñ,Ø#Ø # h ZÐ0Ø!&¨¨ Ø$ a˜jð	 -õ ô —M‘MØcØñõð +ð Ðr!   c                 óÔ  — |j                  «       }|j                  «       }||j                  v r|j                  |«      }n6|j	                  |t
        j                  j                  j                  d¬«      }|rd}nd}t        ||||«      s\t        |«      D ]N  \  }	}
t        |
t        t        f«      sJ d|	› dt        |
«      › �«       ‚|j                  |d|
gid|gid	|	i¬
«       ŒP |S )NTr‚   rˆ   r‰   rŠ   r‹   r^   r_   rn   r„   )rŒ   r�   rŽ   rS   r�   r   r=   r>   r‘   rv   r{   r-   r   r|   rb   r–   )rö  r—   r˜   rš   r›   rœ   r�   r   rr   rE   rS   s              r"   rù  zExecutor._add_fetch_opso  s  € ð —m‘m“oˆà"×/Ñ/Ó1ˆà˜\×.Ñ.Ñ.Ø$×(Ñ(¨Ó8‰Ià$×/Ñ/Ø#Ü—\‘\×)Ñ)×4Ñ4Ø ð 0ó ˆIñ Ø!‰HàˆHô #Ø˜* n°hô
ô $ JÖ/‘��3Ü!Øœ(¤C˜ôð Bà/°¨s°#´d¸3³i°[ÐAóBð ð ×&Ñ&Ø!Ø # ˜<Ø" Y KÐ0Ø  !˜*ð	 'õ ð	 0ð Ðr!   c                 óþ   — |j                  «       }|j                  «       }t        |j                  «      }t	        t        |«      «      D ]0  }|j                  |   j                  |k(  sŒ |j                  |«       Œ2 |S r%   )rŒ   r�   r3   ra   ÚreversedrC   rb   Ú
_remove_op)rö  r—   Úfetch_op_namerœ   r�   Úop_numru   s          r"   Ú_remove_fetch_opszExecutor._remove_fetch_ops–  sm   € à—m‘m“oˆØ"×/Ñ/Ó1ˆÜ�\×%Ñ%Ó&ˆÜœE &›MÖ*ˆCØ×Ñ Ñ$×)Ñ)¨]Ó:Ø×'Ñ'¨Õ,ð +ð Ðr!   c                 óÐ  — | j                  |||||||||	|
|«      \  }}}ddlm} t        |d«      rÁ|j                  }t        ||«      sJ d«       ‚ |«       }|j                  «       j                  |j                     }t        j                  |g«      j                  t        |j                  «      «      }t        j                  ||j                  «      }|j!                  || j"                  «       | j$                  j'                  |«       |s| j$                  j)                  |«       |r:|j+                  d«      j-                  «       }|j/                  «       }t1        |«      S y )Nr   r$  rh  r&  r‰   )rÞ  r0  r%  rs  rh  r-   r�   rŽ   r1  r6   r7   r  r   rQ   r   r2  r	  r  r™  rÈ  r  r¾   rÌ  r>  r/   )r  r—   rl  r'   r¦  rÍ  r§  r˜   r}   r¨  rÎ  rÖ  rÐ  r  r%  rh  rL  rM  r
  r9   rÖ  rA  s                         r"   r+  zExecutor._run_pipeline¡  sD  € ð 48×3MÑ3MØØØØØØØØØØØó4
Ñ0ˆˆÐ 0õ 	4ä�7˜NÔ+Ø"×/Ñ/ˆLÜ˜l¨KÔ8ÐOÐ:OÓOÐ8Ù#“~ˆHØ×)Ñ)Ó+×0Ñ0°×1GÑ1GÑHˆFÜ—8‘8˜X˜JÓ'×.Ñ.¬}¸V¿\¹\Ó/JÓKˆDÜ×-Ñ-¨e°\×5KÑ5KÓLˆFØ�J‰J�t˜TŸZ™ZÔ(à×Ñ×/Ñ/Ð0@ÔAá Ø×"Ñ"×2Ñ2Ð3CÔDáØ—.‘. Ó)×8Ñ8Ó:ˆCØ×'Ñ'Ó)ˆGÜ˜GÓ$Ð$àr!   c
                 ó6   — | j                  ||||d|||||	«
      S )ak  
        Infer from a pre-defined Dataset. Dataset is defined in paddle.base.dataset.
        Given a program, either a program or compiled program, infer_from_dataset will
        consume all data samples in dataset. Input scope can be given by users. By default,
        scope is global_scope(). The total number of thread run in training is `thread`.
        Thread number used in training will be minimum value of threadnum in Dataset and
        the value of thread in this interface. Debug can be set so that executor will display
        Run-Time for all operators and the throughputs of current infer task.

        The document of infer_from_dataset is almost the same as train_from_dataset,
        except that in distributed training, push gradients will be disabled in infer_from_dataset.
        infer_from_dataset() can be used for evaluation in multi-threadvery easily.

        Args:
            program(Program|CompiledProgram): the program that needs to be run,
                if not provided, then default_main_program (not compiled) will be used.
            dataset(paddle.base.Dataset): dataset created outside this function,
                a user should provide a well-defined dataset before calling this function.
                Please check the document of Dataset if needed. default is None
            scope(Scope): the scope used to run this program, you can switch it to different scope
                for each run. default is global_scope
            thread(int): number of thread a user wants to run in this function. Default is 0, which
                means using thread num of dataset
            debug(bool): whether a user wants to run infer_from_dataset, default is False
            fetch_list(Tensor List): fetch Tensor list, each Tensor will be printed during
                training, default is None
            fetch_info(String List): print information for each Tensor, default is None
            print_period(int): the number of mini-batches for each print, default is 100
            fetch_handler(FetchHandler): a user define class for fetch output.

        Returns:
            None

        Examples:

            .. code-block:: python

                >>> import paddle

                >>> paddle.enable_static()
                >>> place = paddle.CPUPlace()  # you can set place = paddle.CUDAPlace(0) to use gpu
                >>> exe = paddle.static.Executor(place)
                >>> x = paddle.static.data(name="x", shape=[None, 10, 10], dtype="int64")
                >>> y = paddle.static.data(name="y", shape=[None, 1], dtype="int64", lod_level=1)
                >>> dataset = paddle.base.DatasetFactory().create_dataset()
                >>> dataset.set_use_var([x, y])
                >>> dataset.set_thread(1)
                >>> # you should set your own filelist, e.g. filelist = ["dataA.txt"]
                >>> filelist = []
                >>> dataset.set_filelist(filelist)
                >>> exe.run(paddle.static.default_startup_program())
                >>> exe.infer_from_dataset(program=paddle.static.default_main_program(),
                ...                         dataset=dataset)
        T©r×  ©
r  r—   rl  r'   r¦  r§  r˜   r}   r¨  rÎ  s
             r"   Úinfer_from_datasetzExecutor.infer_from_datasetÔ  s6   € ðD ×%Ñ%ØØØØØØØØØØó
ð 	
r!   c           
      óH  — | j                  |d |d||||¬«      \  }}|j                  d«       |j                  «        | j                  ||¬«       | j                  j                  |j                  |j                  «       |d «      }	| j                  j                  |	«       |	S )Nr
   rµ  Fr¶  )	rª  rÀ  rÁ  ri  r™  rÄ  rJ   rÅ  rÈ  )
r  r—   r'   r§  r˜   r}   r¨  rÎ  rg  r  s
             r"   Ústart_heter_trainerzExecutor.start_heter_trainer#  s­   € ð ×.Ñ.ØØØØØØ!Ø!Ø%ð /ó 	
‰ˆˆwð 	×Ñ˜5Ô!Ø×!Ñ!Ô#à×Ñ g°wÐÔ?à×1Ñ1×BÑBØ�L‰L˜'Ÿ-™-›/¨5°$ó
Ðð 	×Ñ×/Ñ/Ð0@ÔAð  Ðr!   c
                 ó6   — | j                  ||||d|||||	«
      S )aº  
        Train from a pre-defined Dataset. Dataset is defined in paddle.base.dataset.
        Given a program, either a program or compiled program, train_from_dataset will
        consume all data samples in dataset. Input scope can be given by users. By default,
        scope is global_scope(). The total number of thread run in training is `thread`.
        Thread number used in training will be minimum value of threadnum in Dataset and
        the value of thread in this interface. Debug can be set so that executor will display
        Run-Time for all operators and the throughputs of current training task.

        Note: train_from_dataset will destroy all resources created within executor for each run.

        Args:
            program(Program|CompiledProgram): the program that needs to be run,
                if not provided, then default_main_program (not compiled) will be used.
            dataset(paddle.base.Dataset): dataset created outside this function,
                a user should provide a well-defined dataset before calling this function.
                Please check the document of Dataset if needed.
            scope(Scope): the scope used to run this program, you can switch it to different scope
                for each run. default is global_scope
            thread(int): number of thread a user wants to run in this function. Default is 0, which
                means using thread num of dataset
            debug(bool): whether a user wants to run train_from_dataset
            fetch_list(Tensor List): fetch Tensor list, each variable will be printed
                during training
            fetch_info(String List): print information for each Tensor, its length should be equal
                to fetch_list
            print_period(int): the number of mini-batches for each print, default is 100
            fetch_handler(FetchHandler): a user define class for fetch output.

        Returns:
            None

        Examples:

            .. code-block:: python

                >>> import paddle

                >>> paddle.enable_static()
                >>> place = paddle.CPUPlace() # you can set place = paddle.CUDAPlace(0) to use gpu
                >>> exe = paddle.static.Executor(place)
                >>> x = paddle.static.data(name="x", shape=[None, 10, 10], dtype="int64")
                >>> y = paddle.static.data(name="y", shape=[None, 1], dtype="int64", lod_level=1)
                >>> dataset = paddle.base.DatasetFactory().create_dataset()
                >>> dataset.set_use_var([x, y])
                >>> dataset.set_thread(1)
                >>> # you should set your own filelist, e.g. filelist = ["dataA.txt"]
                >>> filelist = []
                >>> dataset.set_filelist(filelist)
                >>> exe.run(paddle.static.default_startup_program())
                >>> exe.train_from_dataset(program=paddle.static.default_main_program(),
                ...                         dataset=dataset)
        Fr  r  s
             r"   Útrain_from_datasetzExecutor.train_from_datasetO  s6   € ðB ×%Ñ%ØØØØØØØØØØó
ð 	
r!   r%   )NNN)	NNNrT   r‰   NTFF)NN)NNNr   FNNéd   )
NNNr   FFNNr  N)NNNr   FFNNr  NF)NNrT   r‰   NFT©F©r‰   )	NNNr   FNNr  N)NNFNNr  N)4r,  r-  r.  Ú__doc__r  r«  r®  r³  rµ  r·  rº  r½  r¿  rÁ  rÃ  rÅ  rÉ  rÌ  rÏ  r0   rÒ  rÔ  r×  rã  rë  rï  Úclassmethodrø  r  r  r­  r  r=  r  r  r>  r(  ri  rr  r–  rª  r×  rÞ  rñ  r*  r÷  rù  r  r+  r  r  r  r    r!   r"   r�  r�  b  sŽ  „ ñ=ó~!2òFAò
%ò>ò<ò@ò@ò9òGò@òMòFò-ò5ò3ðAÀtó AòCò
ò
6òpò<ð ñ4*ó ð4*ðl à?Cò;ó ð;ðz ñ,ó ð,ð\ò+ò6	$ð ØØØØØØØØóqòfe<òN\ò|ò"óHBòò&AðJ ØØØØØØØóLð` ØØØØØØØØØóhðX ØØØØØØØØØØólð` ØØØØØ!&óY
ðz ØØØØØ!&ØóbòHðB à?Dò$ó ð$ðL òó ðð ØØØØØØØØØØó1ðj ØØØØØØØØóM
ðb ØØØØØØó* ð\ ØØØØØØØØôL
r!   r�  r  )r
   r  )r¡   )NTr%   )Lr:   r  rÙ   r"  r”   Ú	functoolsr   Únumpyr6   r¢   r   r   r   rë   r   r	   rÒ   r   r   r   r   Údata_feederr   r   r   r   r   r   r   r   r   r   Úincubate.checkpointr   r<  Útrainer_factoryr   r   Úwrapped_decoratorr   Ú__all__ÚScoper   ÚNativeConfigÚInferNativeConfigÚAnalysisConfigÚInferAnalysisConfigr#   r)   r+   r/   rA   rF   rY   r\   rl   rv   r€   rŸ   r§   r¬   rº   rÂ   r¿   ré   rï   rû   r  rí   r  r  r  r  r1  rK  r�  r    r!   r"   Ú<module>r'     s`  ðó Û Û 	Û 
Û Ý ã å ÷ó ÷ 5Ó 4Ý &÷÷ ÷ õ 8ß @Ý <à
€à
ˆ$�*‰*‹,€Ø×%Ñ%Ð Ø×)Ñ)Ð òò,ð ñ'ó ð'óT+ò\ò$ óF.ób/òd%ðR 7>ó*ð\ 7Dó%ðR LQó>òB'ò(7ò
ó*òDò8ò&
òò(,ò<ó5òpñ, ƒñó ð÷
ñ 
÷8+ñ +÷\F ñ F ÷Ry 
ò y 
r!   