
    9iY/              
          S SK r S SKrS SKJrJr  S SKJrJrJrJ	r	  S SK
r
S SKJs  Js  Js  Jr  S SKJr  S SKJrJr  S SKJr  S SKJr  S SKJrJrJr  S S	KJr  S S
K J!r!  S SK"J#r#  S SK$J%r%  S SK&J'r'  / SQr(\%" \)5      r*\ " S S5      5       r+ " S S5      r,S\	\\-S4   S\.\   S\-4S jr/S\!S\0\\-   \\1   4   4S jr2S\+S\	\\-S4   S\.\   S\3\1\4   4S jr4g)    N)	dataclassfield)AnyCallableOptionalUnion)get_default_numa_options)eventsmetrics)
WorkerSpec)LocalElasticAgent)DefaultLogsSpecs	LogsSpecsSignalException)ChildFailedError)RendezvousParameters)parse_rendezvous_endpoint)
get_logger)NumaOptions)LaunchConfigelastic_launchlaunch_agentc                   L   \ rS rSr% Sr\\S'   \\S'   \\S'   Sr\\	   \S'   Sr
\\S	'   S
r\\S'   Sr\\S'   Sr\\S'   \" \S9r\\\4   \S'   Sr\\S'   Sr\\S'   Sr\\S'   Sr\\S'   Sr\\   \S'   \" \S9r\\\4   \S'   Sr\\   \S'   Sr\\S'   Sr\\   \S'   S rS rg)!r   %   aw  
Creates a rendezvous config.

Args:
    min_nodes: Minimum amount of nodes that the user function will
                    be launched on. Elastic agent ensures that the user
                    function start only when the min_nodes amount enters
                    the rendezvous.
    max_nodes: Maximum amount of nodes that the user function
                    will be launched on.
    nproc_per_node: On each node the elastic agent will launch
                        this amount of workers that will execute user
                        defined function.
    rdzv_backend: rdzv_backend to use in the rendezvous (zeus-adapter, etcd).
    rdzv_endpoint: The endpoint of the rdzv sync. storage.
    rdzv_configs: Key, value pair that specifies rendezvous specific configuration.
    rdzv_timeout: Legacy argument that specifies timeout for the rendezvous. It is going
        to be removed in future versions, see the note below. The default timeout is 900 seconds.
    run_id: The unique run id of the job (if not passed a unique one will be
            deduced from run environment - flow workflow id in flow - or auto generated).
    role: User defined role of the worker (defaults to "trainer").
    max_restarts: The maximum amount of restarts that elastic agent will conduct
                on workers before failure.
    monitor_interval: The interval in seconds that is used by the elastic_agent
                    as a period of monitoring workers.
    start_method: The method is used by the elastic agent to start the
                workers (spawn, fork, forkserver).
    metrics_cfg: configuration to initialize metrics.
    local_addr: address of the local node if any. If not set, a lookup on the local
            machine's FQDN will be performed.
    local_ranks_filter: ranks for which to show logs in console. If not set, show from all.
    event_log_handler: name of the event logging handler as registered in
      `elastic/events/handlers.py <https://docs.pytorch.org/docs/stable/elastic/events.html>`_.


.. note::
    `rdzv_timeout` is a legacy argument that will be removed in future.
    Set the timeout via `rdzv_configs['timeout']`

	min_nodes	max_nodesnproc_per_nodeN
logs_specs run_iddefault_rolerolerdzv_endpointetcdrdzv_backend)default_factoryrdzv_configsrdzv_timeout   max_restartsg?monitor_intervalspawnstart_methodlog_line_prefix_templatemetrics_cfg
local_addrnullevent_log_handlernuma_optionsc                    SnU R                   S:w  a  U R                   U R                  S'   OSU R                  ;  a  XR                  S'   U R                  c  [        5       U l        U R                  c  [
        R                  R                  5       (       a]  [
        R                  R                  5       U R                  :X  a0  [        5       U l        [        R                  SU R                  5        g g g g )Ni  r(   timeoutzUsing default numa options = %r)r)   r'   r   r   r4   torchcudais_availabledevice_countr   r	   loggerinfo)selfdefault_timeouts     ^/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/torch/distributed/launcher/api.py__post_init__LaunchConfig.__post_init__c   s    "+/+<+<Di(d///+:i( ??".0DO %

''))

'')T-@-@@ 8 :DKK94;L;LM A * &    )r   r4   ) __name__
__module____qualname____firstlineno____doc__int__annotations__r   r   r   r    strr"   r#   r%   r   dictr'   r   r)   r+   r,   floatr.   r/   r0   r1   r3   r4   r   r@   __static_attributes__ rB   r?   r   r   %   s    'R NN&*J#*FCD#M3L##(#>L$sCx.>L#L#!e!L#.2hsm2"'"=Kc3h= $J$#s#*.L(;'.NrB   r   c                   <    \ rS rSrSrS\S\\\S4   4S jr	S r
Srg)	r   x   a  
Launches an torchelastic agent on the container that invoked the entrypoint.

    1. Pass the ``entrypoint`` arguments as non ``kwargs`` (e.g. no named parameters)/
       ``entrypoint`` can be a function or a command.
    2. The return value is a map of each worker's output mapped
       by their respective global rank.

Usage

::

def worker_fn(foo):
    # ...

def main():
    # entrypoint is a function.
    outputs = elastic_launch(LaunchConfig, worker_fn)(foo)
    # return rank 0's output
    return outputs[0]

    # entrypoint is a command and ``script.py`` is the python module.
    outputs = elastic_launch(LaunchConfig, "script.py")(args)
    outputs = elastic_launch(LaunchConfig, "python")("script.py")
config
entrypointNc                     Xl         X l        g N_config_entrypoint)r=   rQ   rR   s      r?   __init__elastic_launch.__init__   s    
 %rB   c                 V    [        U R                  U R                  [        U5      5      $ rT   )r   rV   rW   list)r=   argss     r?   __call__elastic_launch.__call__   s    DLL$*:*:DJGGrB   rU   )rC   rD   rE   rF   rG   r   r   r   rJ   rX   r]   rM   rN   rB   r?   r   r   x   s0    4&& (C-.&HrB   r   rR   r\   returnc                     [        U [        5      (       a  U R                  $ [        U [        5      (       a)  U [        R
                  :X  a  [        S U 5       S5      $ U $ g)a  Retrieve entrypoint name with the rule:
1. If entrypoint is a function, use ``entrypoint.__qualname__``.
2. If entrypoint is a string, check its value:
    2.1 if entrypoint equals to ``sys.executable`` (like "python"), use the first element from ``args``
        which does not start with hifen letter (for example, "-u" will be skipped).
    2.2 otherwise, use ``entrypoint`` value.
3. Otherwise, return empty string.
c              3   :   #    U  H  oS    S:w  d  M  Uv   M     g7f)r   -NrN   ).0args     r?   	<genexpr>'_get_entrypoint_name.<locals>.<genexpr>   s     >A#s   	r   )
isinstancer   rC   rJ   sys
executablenext)rR   r\   s     r?   _get_entrypoint_namerk      sR     *h''"""	J	$	$'>>CCrB   rdzv_parametersc                     U R                   S:w  a  gU R                  nUR                  5       nU(       d  [        S5      e[	        USS9u  p#US:X  a  [        SU S35      eX#4$ )Nstatic)NNzKEndpoint is missing in endpoint. Try to add --master-addr and --master-portr(   )default_portzport is missing in endpoint: z. Try to specify --master-port)backendendpointstrip
ValueErrorr   )rl   rq   master_addrmaster_ports       r?   _get_addr_and_portrv      s~     (*''H~~HY
 	
  9PRSKb+H:5ST
 	
 %%rB   rQ   c                    U R                   (       dD  [        [        R                  " 5       R                  5      n[
        R                  SU5        X0l         [        X5      n[
        R                  SUU R                  U R                  U R                  U R                   U R                  U R                  U R                  U R                  U R                   U R"                  R$                  U R&                  U R(                  U R*                  S.5        [-        S
U R                  U R                  U R                   U R                  U R                  U R.                  S.U R                  D6n[1        U5      u  pg[3        U R4                  U R                  U[7        U5      [8        R:                  " U5      U R                  U R                   UUU R.                  U R(                  U R*                  S9n[=        UU R"                  U R>                  U R@                  S9n	Sn
 [B        RD                  " [B        RF                  " U R&                  5      5        U	RI                  5       n[J        RL                  " U	RO                  5       U R(                  5        URQ                  5       (       a  [S        UURT                  S9eURV                  U
(       a  URX                  R[                  5         $ $ ! [R         a    e [\         a3    S	n
[J        RL                  " U	R_                  5       U R(                  5        e [`         a1    [J        RL                  " U	R_                  5       U R(                  5        e f = f! U
(       a  URX                  R[                  5         f f = f)Nz3config has no run_id, generated a random run_id: %saW  Starting elastic_operator with launch configs:
  entrypoint         : %(entrypoint)s
  min_nodes          : %(min_nodes)s
  max_nodes          : %(max_nodes)s
  nproc_per_node     : %(nproc_per_node)s
  run_id             : %(run_id)s
  rdzv_backend       : %(rdzv_backend)s
  rdzv_endpoint      : %(rdzv_endpoint)s
  rdzv_configs       : %(rdzv_configs)s
  max_restarts       : %(max_restarts)s
  monitor_interval   : %(monitor_interval)s
  log_dir            : %(log_dir)s
  metrics_cfg        : %(metrics_cfg)s
  event_log_handler  : %(event_log_handler)s
  numa_options       : %(numa_options)s
)rR   r   r   r   r    r%   r#   r'   r+   r,   log_dirr0   r3   r4   )rp   rq   r    r   r   r1   )r"   local_world_sizerR   r\   rdzv_handlerr+   r,   rt   ru   r1   r3   r4   )specr   r.   r/   T)namefailuresFrN   )1r    rJ   uuiduuid4rH   r;   warningrk   r<   r   r   r   r%   r#   r'   r+   r,   r   root_log_dirr0   r3   r4   r   r1   rv   r   r"   tuplerdzv_registryget_rendezvous_handlerr   r.   r/   r   initialize_metricsMetricsConfigrunr
   recordget_event_succeeded	is_failedr   r}   return_valuesrz   shutdownr   get_event_failed	Exception)rQ   rR   r\   r    entrypoint_namerl   rt   ru   r{   agentshutdown_rdzvresults               r?   r   r      s   
 ==TZZ\%%&LfU*:<O
KK	4  *))))$33mm"//#11"//"// & 7 7((55!--!'!9!9"//	
! D + ##%%}}""""$$ 

O  2/BK[[..4["99/J((00$$ 22((D $$((!'!@!@	E M )""7#8#89K9K#LMe//163K3KL
 #$ 
 ## &&(     e,,.0H0HI e,,.0H0HI &&( s   B'K% %B M%%M( ($N)5rh   r~   dataclassesr   r   typingr   r   r   r   r7   -torch.distributed.elastic.rendezvous.registrydistributedelastic
rendezvousregistryr   torch._utils_internalr	   torch.distributed.elasticr
   r   *torch.distributed.elastic.agent.server.apir   :torch.distributed.elastic.agent.server.local_elastic_agentr   )torch.distributed.elastic.multiprocessingr   r   r   0torch.distributed.elastic.multiprocessing.errorsr   $torch.distributed.elastic.rendezvousr   *torch.distributed.elastic.rendezvous.utilsr   'torch.distributed.elastic.utils.loggingr   torch.numa.bindingr   __all__rC   r;   r   r   rJ   r[   rk   r   rH   rv   rK   r   rN   rB   r?   <module>r      s     ( 1 1  E E : 5 A X 
 N E P > * =	H	 ON ON ONd$H $HNhT)*26s),&)&
8C=(3-'(&&q)q)hT)*q) s)q) 
#s(^	q)rB   