Ë
    [^(hí  ã                   óŠ   — d dl Z d dlmZ d dlmZ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y)é    N)ÚIterator)ÚOptionalÚTypeVar)ÚDataset)ÚSamplerÚDistributedSamplerÚ_T_coT)Ú	covariantc                   óz   — e Zd ZdZ	 	 	 	 	 ddedee   dee   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y)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)
    NÚdatasetÚnum_replicasÚrankÚshuffleÚseedÚ	drop_lastÚreturnc                 ó  — |€3t        j                  «       st        d«      ‚t        j                  «       }|€3t        j                  «       st        d«      ‚t        j                  «       }||k\  s|dk  rt        d|› d|dz
  › d�«      ‚|| _        || _        || _        d| _	        || _
        | j                  rmt        | j                  «      | j                  z  dk7  rHt        j                  t        | j                  «      | j                  z
  | j                  z  «      | _        n:t        j                  t        | j                  «      | j                  z  «      | _        | j                  | j                  z  | _        || _        || _        y )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/skyplay_api_hub/venv/lib/python3.12/site-packages/torch/utils/data/distributed.pyÚ__init__zDistributedSampler.__init__B   sZ  € ð ÐÜ×$Ñ$Ô&Ü"Ð#QÓRÐRÜ×.Ñ.Ó0ˆLØˆ<Ü×$Ñ$Ô&Ü"Ð#QÓRÐRÜ—=‘=“?ˆDØ�<Ò 4¨!¢8ÜØ ˜vÐ%JÈ<ÐZ[ÑK[ÐJ\Ð\]Ð^óð ð ˆŒØ(ˆÔØˆŒ	ØˆŒ
Ø"ˆŒð �>Š>œc $§,¡,Ó/°$×2CÑ2CÑCÀqÒHô  $Ÿy™yÜ�T—\‘\Ó" T×%6Ñ%6Ñ6¸$×:KÑ:KÑKó ˆDÕô  $Ÿy™y¬¨T¯\©\Ó):¸T×=NÑ=NÑ)NÓOˆDÔØ×*Ñ*¨T×->Ñ->Ñ>ˆŒØˆŒØˆ�	ó    c                 ó  — | j                   rut        j                  «       }|j                  | j                  | j
                  z   «       t        j                  t        | j                  «      |¬«      j                  «       }n't        t        t        | j                  «      «      «      }| j                  sZ| j                  t        |«      z
  }|t        |«      k  r	||d | z  }n:||t        j                  |t        |«      z  «      z  d | z  }n|d | j                   }t        |«      | j                  k(  sJ ‚|| j                   | j                  | j"                  …   }t        |«      | j$                  k(  sJ ‚t'        |«      S )N)Ú	generator)r   ÚtorchÚ	GeneratorÚmanual_seedr   r   Úrandpermr   r   ÚtolistÚlistÚranger   r!   r   r   r   r   r    Úiter)r"   ÚgÚindicesÚpadding_sizes       r#   Ú__iter__zDistributedSampler.__iter__k   s7  € Ø�<Š<ä—‘Ó!ˆAØ�M‰M˜$Ÿ)™) d§j¡jÑ0Ô1Ü—n‘n¤S¨¯©Ó%6À!ÔD×KÑKÓM‰Gäœ5¤ T§\¡\Ó!2Ó3Ó4ˆGà�~Š~àŸ?™?¬S°«\Ñ9ˆLØœs 7›|Ò+Ø˜7 = LÐ1Ñ1‘à˜G¤d§i¡i°¼sÀ7»|Ñ0KÓ&LÑLØ!�\ðñ ‘ð
 Ð/ §¡Ð0ˆGÜ�7‹|˜tŸ™Ò.Ð.Ð.ð ˜$Ÿ)™) d§o¡o¸×8IÑ8IÐIÑJˆÜ�7‹|˜t×/Ñ/Ò/Ð/Ð/ä�G‹}Ðr%   c                 ó   — | j                   S )N)r    )r"   s    r#   Ú__len__zDistributedSampler.__len__ˆ   s   € Ø×ÑÐr%   r   c                 ó   — || _         y)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   r   ÚintÚboolr$   r   r	   r3   r5   r7   © r%   r#   r   r      sš   „ ñ.ðf '+Ø"ØØØñ'àð'ð ˜s‘mð'ð �s‰mð	'ð
 ð'ð ð'ð ð'ð 
ó'ðR˜( 5™/ó ð: ˜ó  ð˜sð  tô r%   )r   Úcollections.abcr   Útypingr   r   r(   Útorch.distributedÚdistributedr   Útorch.utils.data.datasetr   Útorch.utils.data.samplerr   Ú__all__r	   r   r>   r%   r#   ú<module>rF      sD   ðÛ Ý $ß $ã Ý  Ý ,Ý ,ð  Ð
 €ñ 	� 4Ô(€ôE˜ ™õ Er%   