§
    Pzniú*  ã            
       óâ  — d dl Z d dlZd dlmZmZ d dlmZmZmZm	Z	m
Z
mZmZ d dlmc mc mc mZ d dlmZmZ d dlmZ d dlmZ d dlmZmZ d dlmZ d d	lm Z  d d
l!m"Z" d dl#m$Z$ g d¢Z% e$e&¦  «        Z'e G d„ d¦  «        ¦   «         Z( G d„ d¦  «        Z)deee*df         de	e         de*fd„Z+de dee
e*         e
e,         f         fd„Z-de(deee*df         de	e         dee,ef         fd„Z.dS )é    N)Ú	dataclassÚfield)ÚAnyÚCallableÚDictÚListÚOptionalÚTupleÚUnion)ÚeventsÚmetrics)Ú
WorkerSpec)ÚLocalElasticAgent)ÚSignalExceptionÚStd)ÚChildFailedError)ÚRendezvousParameters)Úparse_rendezvous_endpoint)Ú
get_logger)ÚLaunchConfigÚelastic_launchÚlaunch_agentc                   ó°  — e Zd ZU dZeed<   eed<   eed<   dZeed<   dZeed<   dZ	eed	<   d
Z
eed<    ee¬¦  «        Zeeef         ed<   dZeed<   dZeed<   dZeed<   dZeed<   dZee         ed<   ej        Zeeeeef         f         ed<   ej        Zeeeeef         f         ed<    ee¬¦  «        Zeeef         ed<   dZee         ed<   d„ ZdS )r   aŸ	  
    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).
        log_dir: base log directory where log files are written. If not set,
                one is created in a tmp dir but NOT removed on exit.
        redirects: configuration to redirect stdout/stderr to log files.
                Pass a single ``Std`` enum to redirect all workers,
                or a mapping keyed by local_rank to selectively redirect.
        tee: configuration to "tee" stdout/stderr to console + log file.
        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.
    ..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_nodeÚ Úrun_idÚdefault_roleÚroleÚrdzv_endpointÚetcdÚrdzv_backend)Údefault_factoryÚrdzv_configséÿÿÿÿÚrdzv_timeouté   Úmax_restartsé   Úmonitor_intervalÚspawnÚstart_methodNÚlog_dirÚ	redirectsÚteeÚmetrics_cfgÚ
local_addrc                 ól   — d}| j         dk    r| j         | j        d<   d S d| j        vr|| j        d<   d S d S )Ni„  r&   Útimeout)r'   r%   )ÚselfÚdefault_timeouts     ú~/var/www/html/cool-property-finder/image-detection-backend/venv/lib/python3.11/site-packages/torch/distributed/launcher/api.pyÚ__post_init__zLaunchConfig.__post_init__Z   sT   € ØˆØÔ Ò"Ð"Ø+/Ô+<ˆDÔ˜iÑ(Ð(Ð(Ø˜dÔ/Ð/Ð/Ø+:ˆDÔ˜iÑ(Ð(Ð(ð 0Ð/ó    )Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚintÚ__annotations__r   Ústrr    r!   r#   r   Údictr%   r   r   r'   r)   r+   Úfloatr-   r.   r	   r   ÚNONEr/   r   r0   r1   r2   r8   © r9   r7   r   r      s‹  € € € € € € ð(ð (ðT €N€N�NØ€N€N�NØÐÐÑØ€FˆCÐÐÑØ€Dˆ#ÐÐÑØ€M�3ÐÐÑØ€L�#ÐÐÑØ#( 5¸Ð#>Ñ#>Ô#>€L�$�s˜C�x”.Ð>Ð>Ñ>Ø€L�#ÐÐÑØ€L�#ÐÐÑØ Ð�eÐ Ð Ñ Ø€L�#ÐÐÑØ!€GˆX�cŒ]Ð!Ð!Ñ!Ø,/¬H€Iˆu�S˜$˜s C˜xœ.Ð(Ô)Ð4Ð4Ñ4Ø&)¤h€Cˆˆs�D˜˜c˜”NÐ"Ô	#Ð.Ð.Ñ.Ø"' %¸Ð"=Ñ"=Ô"=€K��c˜3�h”Ð=Ð=Ñ=Ø $€J�˜”Ð$Ð$Ñ$ð;ð ;ð ;ð ;ð ;r9   r   c                   ó:   — e Zd ZdZdedeeedf         fd„Zd„ Z	dS )r   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                 ó"   — || _         || _        d S ©N)Ú_configÚ_entrypoint)r5   rF   rG   s      r7   Ú__init__zelastic_launch.__init__}   s   € ð
 ˆŒØ%ˆÔÐÐr9   c                 óR   — t          | j        | j        t          |¦  «        ¦  «        S rI   )r   rJ   rK   Úlist)r5   Úargss     r7   Ú__call__zelastic_launch.__call__…   s   € Ý˜DœL¨$Ô*:½DÀ¹J¼JÑGÔGÐGr9   )
r:   r;   r<   r=   r   r   r   r@   rL   rP   rD   r9   r7   r   r   b   sd   € € € € € ðð ð4&àð&ð ˜( C¨Ð-Ô.ð&ð &ð &ð &ðHð Hð Hð Hð Hr9   r   rG   rO   Úreturnc                 óÀ   — t          | t          ¦  «        r| j        S t          | t          ¦  «        r,| t          j        k    rt          d„ |D ¦   «         d¦  «        S | S dS )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   ó2   K  — | ]}|d          dk    ¯|V — ŒdS )r   ú-NrD   )Ú.0Úargs     r7   ú	<genexpr>z'_get_entrypoint_name.<locals>.<genexpr>˜   s*   è è € Ð>Ð> °°A´¸#²°˜°°°°Ð>Ð>r9   r   )Ú
isinstancer   r:   r@   ÚsysÚ
executableÚnext)rG   rO   s     r7   Ú_get_entrypoint_namer\   ‰   sh   € õ �*�hÑ'Ô'ð ØÔ"Ð"Ý	�J¥Ñ	$Ô	$ð Ø�œÒ'Ð'ÝÐ>Ð>¨Ð>Ñ>Ô>ÀÑCÔCÐCàÐàˆrr9   Úrdzv_parametersc                 óÖ   — | j         dk    rdS | j        }|                     ¦   «         }|st          d¦  «        ‚t	          |d¬¦  «        \  }}|dk    rt          d|› d�¦  «        ‚||fS )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   )r]   rb   Úmaster_addrÚmaster_ports       r7   Ú_get_addr_and_portrg   Ÿ   s�   € ð Ô (Ò*Ð*Øˆ|ØÔ'€HØ�~Š~ÑÔ€HØð 
ÝØYñ
ô 
ð 	
õ  9¸ÐPRÐSÑSÔSÑ€K�Ø�bÒÐÝØT¨HÐTÐTÐTñ
ô 
ð 	
ð ˜Ð%Ð%r9   rF   c                 óŒ  — | j         sGt          t          j        ¦   «         j        ¦  «        }t
                               d|¦  «         || _         t          ||¦  «        }t
                               d|| j	        | j
        | j        | j         | j        | j        | j        | j        | j        | j        | j        dœ¦  «         t'          d
| j        | j        | j         | j	        | j
        | j        dœ| j        ¤Ž}t+          |¦  «        \  }}t-          | j        | j        |t1          |¦  «        t3          j        |¦  «        | j        | j        | j        | j        ||| j        ¬¦  «        }t;          || j        | j        ¬¦  «        }	d}
	 t?          j         t?          j!        | j        ¦  «        ¦  «         |	 "                    ¦   «         }tG          j$        |	 %                    ¦   «         ¦  «         | &                    ¦   «         rtO          ||j(        ¬¦  «        ‚|j)        |
r|j*         +                    ¦   «          S S # tN          $ r ‚ tX          $ r* d	}
tG          j$        |	 -                    ¦   «         ¦  «         ‚ t\          $ r( tG          j$        |	 -                    ¦   «         ¦  «         ‚ w xY w# |
r|j*         +                    ¦   «          w w xY w)Nz3config has no run_id, generated a random run_id: %saê  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
)rG   r   r   r   r   r#   r!   r%   r)   r+   r.   r1   )ra   rb   r   r   r   r2   )r    Úlocal_world_sizerG   rO   Úrdzv_handlerr)   r+   r/   r0   re   rf   r2   )Úspecr-   r.   T)ÚnameÚfailuresFrD   )/r   r@   ÚuuidÚuuid4r>   ÚloggerÚwarningr\   Úinfor   r   r   r#   r!   r%   r)   r+   r.   r1   r   r2   rg   r   r    ÚtupleÚrdzv_registryÚget_rendezvous_handlerr/   r0   r   r-   r   Úinitialize_metricsÚMetricsConfigÚrunr   ÚrecordÚget_event_succeededÚ	is_failedr   rm   Úreturn_valuesrj   Úshutdownr   Úget_event_failedÚ	Exception)rF   rG   rO   r   Úentrypoint_namer]   re   rf   rk   ÚagentÚshutdown_rdzvÚresults               r7   r   r   ²   s  € ð
 Œ=ð Ý•T”Z‘\”\Ô%Ñ&Ô&ˆÝ�ŠÐLÈfÑUÔUÐUØˆŒå*¨:°tÑ<Ô<€Oå
‡K‚Kð	1ð *ØÔ)ØÔ)Ø$Ô3Ø”mØ"Ô/Ø#Ô1Ø"Ô/Ø"Ô/Ø &Ô 7Ø”~Ø!Ô-ð	
ð 	
ñô ð õ< +ð ØÔ#ØÔ%ØŒ}ØÔ"ØÔ"ØÔ$ðð ð Ô
ðð €Oõ  2°/ÑBÔBÑ€K�åØŒ[ØÔ.ØÝ�4‰[Œ[Ý"Ô9¸/ÑJÔJØÔ(ØÔ0ØÔ"ØŒJØØØÔ$ðñ ô €Dõ Ø Ô 3¸V¼^ðñ ô €Eð €Mð )ÝÔ"¥7Ô#8¸Ô9KÑ#LÔ#LÑMÔMÐMà—’‘”ˆåŒ�e×/Ò/Ñ1Ô1Ñ2Ô2Ð2à×ÒÑÔð 	õ
 #Ø$Øœðñ ô ð ð
 Ô#ð ð 	)ØÔ×&Ò&Ñ(Ô(Ð(Ð(ð	)øõ ð ð ð ØÝð ð ð ð ˆÝŒ�e×,Ò,Ñ.Ô.Ñ/Ô/Ð/ØÝð ð ð ÝŒ�e×,Ò,Ñ.Ô.Ñ/Ô/Ð/Øðøøøøð ð 	)ØÔ×&Ò&Ñ(Ô(Ð(Ð(ð	)øøøs   ÆBH4 È4A.J"Ê"J% Ê%K)/rY   rn   Údataclassesr   r   Útypingr   r   r   r   r	   r
   r   Ú-torch.distributed.elastic.rendezvous.registryÚdistributedÚelasticÚ
rendezvousÚregistryrt   Útorch.distributed.elasticr   r   Ú*torch.distributed.elastic.agent.server.apir   Ú:torch.distributed.elastic.agent.server.local_elastic_agentr   Ú)torch.distributed.elastic.multiprocessingr   r   Ú0torch.distributed.elastic.multiprocessing.errorsr   Ú$torch.distributed.elastic.rendezvousr   Ú*torch.distributed.elastic.rendezvous.utilsr   Ú'torch.distributed.elastic.utils.loggingr   Ú__all__r:   rp   r   r   r@   r\   r>   rg   r   rD   r9   r7   ú<module>r”      sŽ  ðð €
€
€
Ø €€€Ø (Ð (Ð (Ð (Ð (Ð (Ð (Ð (Ø DÐ DÐ DÐ DÐ DÐ DÐ DÐ DÐ DÐ DÐ DÐ DÐ DÐ DÐ DÐ DÐ DÐ Dà EÐ EÐ EÐ EÐ EÐ EÐ EÐ EÐ EÐ EÐ EÐ EÐ EÐ EÐ EØ 5Ð 5Ð 5Ð 5Ð 5Ð 5Ð 5Ð 5Ø AÐ AÐ AÐ AÐ AÐ AØ XÐ XÐ XÐ XÐ XÐ XØ JÐ JÐ JÐ JÐ JÐ JÐ JÐ JØ MÐ MÐ MÐ MÐ MÐ MØ EÐ EÐ EÐ EÐ EÐ EØ PÐ PÐ PÐ PÐ PÐ PØ >Ð >Ð >Ð >Ð >Ð >à
<Ð
<Ð
<€à	ˆ�HÑ	Ô	€ð ðB;ð B;ð B;ð B;ð B;ñ B;ô B;ñ „ðB;ðJ$Hð $Hð $Hð $Hð $Hñ $Hô $Hð $HðNØ�h  TÐ)Ô*ðØ26°s´)ðàðð ð ð ð,&Ø)ð&à
ˆ8�CŒ=˜( 3œ-Ð'Ô(ð&ð &ð &ð &ð&j)Øðj)à�h  TÐ)Ô*ðj)ð ˆsŒ)ðj)ð 
ˆ#ˆsˆ(„^ð	j)ð j)ð j)ð j)ð j)ð j)r9   