§
    ŠŠtj2  ã                   ó   — d dl Z ddlmZmZ eez  e j        z  ZdgZ	dede j        fd„Z
deeef         dee j        e j        f         fd	„Zd
ee         dee j                 fd„Zerd dlmZ neZ G d„ de¦  «        ZdS )é    Né   )Ú_is_tensorpipe_availableÚ	constantsÚTensorPipeRpcBackendOptionsÚdeviceÚreturnc                 ót   — t          j        | ¦  «        } | j        dk    rt          d| j        › d�¦  «        ‚| S )NÚcudazA`set_devices` expect a list of CUDA devices, but got device type ú.)Útorchr   ÚtypeÚ
ValueError)r   s    ú[/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/torch/distributed/rpc/options.pyÚ
_to_devicer      sP   € ÝŒ\˜&Ñ!Ô!€FØ„{�fÒÐÝð*Ø!œ;ð*ð *ð *ñ
ô 
ð 	
ð €Mó    Ú
device_mapc           	      óê   — i }i }|                       ¦   «         D ]Y\  }}t          j        |¦  «        t          j        |¦  «        }}||v rt          d|› d||         › d|› �¦  «        ‚|||<   |||<   ŒZ|S )Nz9`device_map` only supports 1-to-1 mapping, trying to map ú and ú to )Úitemsr   r   r   )r   Úfull_device_mapÚreverse_mapÚkÚvs        r   Ú_to_device_mapr      s·   € ð 9;€OØ46€KØ× Ò Ñ"Ô"ð ð ‰ˆˆ1ÝŒ|˜A‰Œ¥¤¨Q¡¤ˆ1ˆØ�ÐÐÝðAØ!"ðAð AØ)4°Q¬ðAð AØ=>ðAð Añô ð ð ˆ˜ÑØˆ�A‰ˆØÐr   Údevicesc                 óF   — t          t          t          | ¦  «        ¦  «        S )N)ÚlistÚmapr   )r   s    r   Ú_to_device_listr    '   s   € Ý••J Ñ(Ô(Ñ)Ô)Ð)r   )Ú _TensorPipeRpcBackendOptionsBasec                   óð   ‡ — e Zd ZdZej        ej        ej        dddddœdede	de
dee
eeef         f         dz  dee         dz  d	edz  d
edz  fˆ fd„Zde
deeef         fˆ fd„Zdee         fd„Zˆ xZS )r   a'  
    The backend options for
    :class:`~torch.distributed.rpc.TensorPipeAgent`, derived from
    :class:`~torch.distributed.rpc.RpcBackendOptions`.

    Args:
        num_worker_threads (int, optional): The number of threads in the
            thread-pool used by
            :class:`~torch.distributed.rpc.TensorPipeAgent` to execute
            requests (default: 16).
        rpc_timeout (float, optional): The default timeout, in seconds,
            for RPC requests (default: 60 seconds). If the RPC has not
            completed in this timeframe, an exception indicating so will
            be raised. Callers can override this timeout for individual
            RPCs in :meth:`~torch.distributed.rpc.rpc_sync` and
            :meth:`~torch.distributed.rpc.rpc_async` if necessary.
        init_method (str, optional): The URL to initialize the distributed
            store used for rendezvous. It takes any value accepted for the
            same argument of :meth:`~torch.distributed.init_process_group`
            (default: ``env://``).
        device_maps (Dict[str, Dict], optional): Device placement mappings from
            this worker to the callee. Key is the callee worker name and value
            the dictionary (``Dict`` of ``int``, ``str``, or ``torch.device``)
            that maps this worker's devices to the callee worker's devices.
            (default: ``None``)
        devices (List[int, str, or ``torch.device``], optional): all local
            CUDA devices used by RPC agent. By Default, it will be initialized
            to all local devices from its own ``device_maps`` and corresponding
            devices from its peers' ``device_maps``. When processing CUDA RPC
            requests, the agent will properly synchronize CUDA streams for
            all devices in this ``List``.
    N)Únum_worker_threadsÚrpc_timeoutÚinit_methodÚdevice_mapsr   Ú_transportsÚ	_channelsr#   r$   r%   r&   r   r'   r(   c          	      óÀ   •— |€i nd„ |                      ¦   «         D ¦   «         }|€g nt          |¦  «        }	t          ¦   «                              |||||||	¦  «         d S )Nc                 ó4   — i | ]\  }}|t          |¦  «        “ŒS © )r   )Ú.0r   r   s      r   ú
<dictcomp>z8TensorPipeRpcBackendOptions.__init__.<locals>.<dictcomp>b   s&   € ÐGÐGÐG©4¨1¨a�!•^ AÑ&Ô&ÐGÐGÐGr   )r   r    ÚsuperÚ__init__)Úselfr#   r$   r%   r&   r   r'   r(   Úfull_device_mapsÚfull_device_listÚ	__class__s             €r   r/   z$TensorPipeRpcBackendOptions.__init__T   s‡   ø€ ð Ð"ð ˆBàGÐG°;×3DÒ3DÑ3FÔ3FÐGÑGÔGð 	ð
 ") ˜2˜2µoÀgÑ6NÔ6NÐÝ‰Œ×ÒØØØØØØØñ	
ô 	
ð 	
ð 	
ð 	
r   Útor   c           
      óL  •— t          |¦  «        }t          ¦   «         j        }||v rZ|                     ¦   «         D ]E\  }}|||         v r6|||         |         k    r$t	          d|› d|› d||         |         › �¦  «        ‚ŒFt          ¦   «                              ||¦  «         dS )a0  
        Set device mapping between each RPC caller and callee pair. This
        function can be called multiple times to incrementally add
        device placement configurations.

        Args:
            to (str): Callee name.
            device_map (Dict of int, str, or torch.device): Device placement
                mappings from this worker to the callee. This map must be
                invertible.

        Example:
            >>> # xdoctest: +SKIP("distributed")
            >>> # both workers
            >>> def add(x, y):
            >>>     print(x)  # tensor([1., 1.], device='cuda:1')
            >>>     return x + y, (x + y).to(2)
            >>>
            >>> # on worker 0
            >>> options = TensorPipeRpcBackendOptions(
            >>>     num_worker_threads=8,
            >>>     device_maps={"worker1": {0: 1}}
            >>> # maps worker0's cuda:0 to worker1's cuda:1
            >>> )
            >>> options.set_device_map("worker1", {1: 2})
            >>> # maps worker0's cuda:1 to worker1's cuda:2
            >>>
            >>> rpc.init_rpc(
            >>>     "worker0",
            >>>     rank=0,
            >>>     world_size=2,
            >>>     backend=rpc.BackendType.TENSORPIPE,
            >>>     rpc_backend_options=options
            >>> )
            >>>
            >>> x = torch.ones(2)
            >>> rets = rpc.rpc_sync("worker1", add, args=(x.to(0), 1))
            >>> # The first argument will be moved to cuda:1 on worker1. When
            >>> # sending the return value back, it will follow the invert of
            >>> # the device map, and hence will be moved back to cuda:0 and
            >>> # cuda:1 on worker0
            >>> print(rets[0])  # tensor([2., 2.], device='cuda:0')
            >>> print(rets[1])  # tensor([2., 2.], device='cuda:1')
        z=`set_device_map` only supports 1-to-1 mapping, trying to map r   r   N)r   r.   r&   r   r   Ú_set_device_map)r0   r4   r   r   Úcurr_device_mapsr   r   r3   s          €r   Úset_device_mapz*TensorPipeRpcBackendOptions.set_device_mapo   sã   ø€ õZ )¨Ñ4Ô4ˆÝ ™7œ7Ô.ÐàÐ!Ð!Ð!Ø'×-Ò-Ñ/Ô/ð ð ‘��1ØÐ(¨Ô,Ð,Ð,°Ð6FÀrÔ6JÈ1Ô6MÒ1MÐ1MÝ$ðLØ#$ðLð LØ*+ðLð LØ2BÀ2Ô2FÀqÔ2IðLð Lñô ð øõ
 	‰Œ×Ò  OÑ4Ô4Ð4Ð4Ð4r   c                 ó.   — t          |¦  «        | _        dS )ab  
        Set local devices used by the TensorPipe RPC agent. When processing
        CUDA RPC requests, the TensorPipe RPC agent will properly synchronize
        CUDA streams for all devices in this ``List``.

        Args:
            devices (List of int, str, or torch.device): local devices used by
                the TensorPipe RPC agent.
        N)r    r   )r0   r   s     r   Úset_devicesz'TensorPipeRpcBackendOptions.set_devices©   s   € õ ' wÑ/Ô/ˆŒˆˆr   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úrpc_contantsÚDEFAULT_NUM_WORKER_THREADSÚDEFAULT_RPC_TIMEOUT_SECÚDEFAULT_INIT_METHODÚintÚfloatÚstrÚdictÚ
DeviceTyper   r/   r8   r:   Ú__classcell__)r3   s   @r   r   r   2   s:  ø€ € € € € ðð ðH #/Ô"IØ)ÔAØ'Ô;ØFJØ+/Ø#'Ø!%ð
ð 
ð 
ð  ð
ð ð	
ð
 ð
ð ˜#˜t J°
Ð$:Ô;Ð;Ô<¸tÑCð
ð �jÔ! DÑ(ð
ð ˜D‘[ð
ð ˜$‘;ð
ð 
ð 
ð 
ð 
ð 
ð685 ð 85°$°zÀ:Ð7MÔ2Nð 85ð 85ð 85ð 85ð 85ð 85ðt
0 4¨
Ô#3ð 
0ð 
0ð 
0ð 
0ð 
0ð 
0ð 
0ð 
0r   )r   Ú r   r   r?   rC   rE   r   rG   Ú__all__r   rF   r   r   r    Útorch._C._distributed_rpcr!   Úobjectr   r+   r   r   ú<module>rM      s2  ðà €€€à AÐ AÐ AÐ AÐ AÐ AÐ AÐ Að �3‰Y˜œÑ%€
à(Ð
)€ð�zð  e¤lð ð ð ð ðØ�Z Ð+Ô,ðà	ˆ%Œ,˜œÐ
$Ô%ðð ð ð ð"*˜T *Ô-ð *°$°u´|Ô2Dð *ð *ð *ð *ð ð .ØJÐJÐJÐJÐJÐJÐJà'-Ð$ðA0ð A0ð A0ð A0ð A0Ð"Bñ A0ô A0ð A0ð A0ð A0r   