§
    �Štj3  ã                   óš   — d dl Z d dlmZ d dlmZ d dlZd dlmZ d dl	m
Z
 d dlmZ dgZ edd¬	¦  «        Z G d
„ dee         ¦  «        ZdS )é    N)ÚIterator)ÚTypeVar)ÚDataset)ÚSamplerÚDistributedSamplerÚ_T_coT)Ú	covariantc                   ó‚   — e Zd ZdZ	 	 	 	 	 ddededz  dedz  d	ed
ededdfd„Zdee	         fd„Z
defd„Zdeddfd„ZdS )r   a'	  Sampler that restricts data loading to a subset of the dataset.

    It is especially useful in conjunction with
    :class:`torch.nn.parallel.DistributedDataParallel`. In such a case, each
    process can pass a :class:`~torch.utils.data.DistributedSampler` instance as a
    :class:`~torch.utils.data.DataLoader` sampler, and load a subset of the
    original dataset that is exclusive to it.

    .. note::
        Dataset is assumed to be of constant size and that any instance of it always
        returns the same elements in the same order.

    Args:
        dataset: Dataset used for sampling.
        num_replicas (int, optional): Number of processes participating in
            distributed training. By default, :attr:`world_size` is retrieved from the
            current distributed group.
        rank (int, optional): Rank of the current process within :attr:`num_replicas`.
            By default, :attr:`rank` is retrieved from the current distributed
            group.
        shuffle (bool, optional): If ``True`` (default), sampler will shuffle the
            indices.
        seed (int, optional): random seed used to shuffle the sampler if
            :attr:`shuffle=True`. This number should be identical across all
            processes in the distributed group. Default: ``0``.
        drop_last (bool, optional): if ``True``, then the sampler will drop the
            tail of the data to make it evenly divisible across the number of
            replicas. If ``False``, the sampler will add extra indices to make
            the data evenly divisible across the replicas. Default: ``False``.

    .. warning::
        In distributed mode, calling the :meth:`set_epoch` method at
        the beginning of each epoch **before** creating the :class:`DataLoader` iterator
        is necessary to make shuffling work properly across multiple epochs. Otherwise,
        the same ordering will be always used.

    Example::

        >>> # xdoctest: +SKIP
        >>> sampler = DistributedSampler(dataset) if is_distributed else None
        >>> loader = DataLoader(dataset, shuffle=(sampler is None),
        ...                     sampler=sampler)
        >>> for epoch in range(start_epoch, n_epochs):
        ...     if is_distributed:
        ...         sampler.set_epoch(epoch)
        ...     train(loader)
    NTr   FÚdatasetÚnum_replicasÚrankÚshuffleÚseedÚ	drop_lastÚreturnc                 óâ  — |€5t          j        ¦   «         st          d¦  «        ‚t          j        ¦   «         }|€5t          j        ¦   «         st          d¦  «        ‚t          j        ¦   «         }||k    s|dk     rt          d|› d|dz
  › d�¦  «        ‚|| _        || _        || _        d| _	        || _
        | j
        r\t          | j        ¦  «        | j        z  dk    r<t          j        t          | j        ¦  «        | j        z
  | j        z  ¦  «        | _        n3t          j        t          | j        ¦  «        | j        z  ¦  «        | _        | j        | j        z  | _        || _        || _        d S )Nz,Requires distributed package to be availabler   zInvalid rank z%, rank should be in the interval [0, é   ú])ÚdistÚis_availableÚRuntimeErrorÚget_world_sizeÚget_rankÚ
ValueErrorr   r   r   Úepochr   ÚlenÚmathÚceilÚnum_samplesÚ
total_sizer   r   )Úselfr   r   r   r   r   r   s          úZ/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/torch/utils/data/distributed.pyÚ__init__zDistributedSampler.__init__B   sz  € ð ÐÝÔ$Ñ&Ô&ð SÝ"Ð#QÑRÔRÐRÝÔ.Ñ0Ô0ˆLØˆ<ÝÔ$Ñ&Ô&ð SÝ"Ð#QÑRÔRÐRÝ”=‘?”?ˆDØ�<ÒÐ 4¨!¢8 8ÝØ^ Ð^Ð^È<ÐZ[ÑK[Ð^Ð^Ð^ñô ð ð ˆŒØ(ˆÔØˆŒ	ØˆŒ
Ø"ˆŒð Œ>ð 	P�c $¤,Ñ/Ô/°$Ô2CÑCÀqÒHÐHõ  $œyÝ�T”\Ñ"Ô" TÔ%6Ñ6¸$Ô:KÑKñ ô  ˆDÔÐõ  $œy­¨T¬\Ñ):Ô):¸TÔ=NÑ)NÑOÔOˆDÔØÔ*¨TÔ->Ñ>ˆŒØˆŒØˆŒ	ˆ	ˆ	ó    c                 ó   — | j         rpt          j        ¦   «         }|                     | j        | j        z   ¦  «         t          j        t          | j        ¦  «        |¬¦  «         	                    ¦   «         }n.t          t          t          | j        ¦  «        ¦  «        ¦  «        }| j        sk| j        t          |¦  «        z
  }|t          |¦  «        k    r||d |…         z  }nB||t          j        |t          |¦  «        z  ¦  «        z  d |…         z  }n|d | j        …         }t          |¦  «        | j        k    r(t!          dt          |¦  «        › d| j        › d�¦  «        ‚|| j        | j        | j        …         }t          |¦  «        | j        k    r(t!          dt          |¦  «        › d| j        › d�¦  «        ‚t)          |¦  «        S )N)Ú	generatorzNumber of indices (z) does not match total_size (ú)zNumber of subsampled indices (z) does not match num_samples ()r   ÚtorchÚ	GeneratorÚmanual_seedr   r   Úrandpermr   r   ÚtolistÚlistÚranger   r    r   r   ÚAssertionErrorr   r   r   Úiter)r!   ÚgÚindicesÚpadding_sizes       r"   Ú__iter__zDistributedSampler.__iter__k   s¼  € ØŒ<ð 	5å”Ñ!Ô!ˆAØ�MŠM˜$œ) d¤jÑ0Ñ1Ô1Ð1Ý”n¥S¨¬Ñ%6Ô%6À!ÐDÑDÔD×KÒKÑMÔMˆGˆGå�5¥ T¤\Ñ!2Ô!2Ñ3Ô3Ñ4Ô4ˆGàŒ~ð 	1àœ?­S°©\¬\Ñ9ˆLØ�s 7™|œ|Ò+Ð+Ø˜7 = L =Ô1Ñ1��à˜G¥d¤i°½sÀ7¹|¼|Ñ0KÑ&LÔ&LÑLØ!�\�Môñ ��ð
 Ð/ ¤Ð/Ô0ˆGÝˆw‰<Œ<˜4œ?Ò*Ð*Ý Øc¥c¨'¡l¤lÐcÐcÐQUÔQ`ÐcÐcÐcñô ð ð
 ˜$œ) d¤o¸Ô8IÐIÔJˆÝˆw‰<Œ<˜4Ô+Ò+Ð+Ý Øpµ°W±´ÐpÐpÐ]aÔ]mÐpÐpÐpñô ð õ
 �G‰}Œ}Ðr$   c                 ó   — | j         S )N)r   )r!   s    r"   Ú__len__zDistributedSampler.__len__�   s   € ØÔÐr$   r   c                 ó   — || _         dS )a1  
        Set the epoch for this sampler.

        When :attr:`shuffle=True`, this ensures all replicas
        use a different random ordering for each epoch. Otherwise, the next iteration of this
        sampler will yield the same ordering.

        Args:
            epoch (int): Epoch number.
        N)r   )r!   r   s     r"   Ú	set_epochzDistributedSampler.set_epoch’   s   € ð ˆŒ
ˆ
ˆ
r$   )NNTr   F)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚintÚboolr#   r   r   r4   r6   r8   © r$   r"   r   r      só   € € € € € ð.ð .ðf $(ØØØØð'ð 'àð'ð ˜D‘jð'ð �D‰jð	'ð
 ð'ð ð'ð ð'ð 
ð'ð 'ð 'ð 'ðR"˜( 5œ/ð "ð "ð "ð "ðH ˜ð  ð  ð  ð  ð˜sð  tð ð ð ð ð ð r$   )r   Úcollections.abcr   Útypingr   r(   Útorch.distributedÚdistributedr   Útorch.utils.data.datasetr   Útorch.utils.data.samplerr   Ú__all__r   r   r?   r$   r"   ú<module>rG      sÓ   ðØ €€€Ø $Ð $Ð $Ð $Ð $Ð $Ø Ð Ð Ð Ð Ð à €€€Ø  Ð  Ð  Ð  Ð  Ð  Ø ,Ð ,Ð ,Ð ,Ð ,Ð ,Ø ,Ð ,Ð ,Ð ,Ð ,Ð ,ð  Ð
 €ð 	ˆ� 4Ð(Ñ(Ô(€ðLð Lð Lð Lð L˜ œñ Lô Lð Lð Lð Lr$   