Ë
    ùÿæi3  ã                   ó†   — 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y)é    N)ÚIterator)ÚTypeVar)ÚDataset)ÚSamplerÚDistributedSamplerÚ_T_coT)Ú	covariantc                   óz   — 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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          úq/Volumes/fast/ai/experiments/voice-extract-mac/.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                  k7  r%t!        dt        |«      › d| j                  › d�«      ‚|| j"                  | j                  | j$                  …   }t        |«      | j&                  k7  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‡  € Ø�<Š<ä—‘Ó!ˆ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Üˆw‹<˜4Ÿ?™?Ò*Ü Ø%¤c¨'£l ^Ð3PÐQU×Q`ÑQ`ÐPaÐabÐcóð ð
 ˜$Ÿ)™) d§o¡o¸×8IÑ8IÐIÑJˆÜˆw‹<˜4×+Ñ+Ò+Ü Ø0´°W³°Ð>\Ð]a×]mÑ]mÐ\nÐnoÐpóð ô
 �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   Ú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      sD   ðÛ Ý $Ý ã Ý  Ý ,Ý ,ð  Ð
 €ñ 	� 4Ô(€ôL˜ ™õ Lr$   