ó
    "Eñi3  ã                   ó€   • S SK r S SKJr  S SKJr  S SKrS SKJr  S SK	J
r
  S SKJr  S/r\" SSS	9r " S
 S\\   5      rg)é    N)ÚIterator)ÚTypeVar)ÚDataset)ÚSamplerÚDistributedSamplerÚ_T_coT)Ú	covariantc                   óŒ   • \ rS rSrSr     SS\S\S-  S\S-  S\S\S	\S
S4S jjrS
\	\
   4S jrS
\4S jrS\S
S4S jrSrg)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                 ó@  • Uc:  [         R                  " 5       (       d  [        S5      e[         R                  " 5       nUc:  [         R                  " 5       (       d  [        S5      e[         R                  " 5       nX2:¼  d  US:  a  [        SU SUS-
   S35      eXl        X l        X0l        SU l	        X`l
        U R                  (       ao  [        U R                  5      U R                  -  S:w  aI  [        R                  " [        U R                  5      U R                  -
  U R                  -  5      U l        O;[        R                  " [        U R                  5      U R                  -  5      U l        U R                  U R                  -  U l        X@l        XPl        g )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          ÚY/home/mande/repo/quber/.venv/lib/python3.13/site-packages/torch/utils/data/distributed.pyÚ__init__ÚDistributedSampler.__init__B   sR  € ð ÑÜ×$Ò$×&Ñ&Ü"Ð#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                 ó¦  • U R                   (       at  [        R                  " 5       nUR                  U R                  U R
                  -   5        [        R                  " [        U R                  5      US9R                  5       nO'[        [        [        U R                  5      5      5      nU R                  (       dZ  U R                  [        U5      -
  nU[        U5      ::  a  X"S U -  nO:X"[        R                  " U[        U5      -  5      -  S U -  nOUS U R                   n[        U5      U R                  :w  a%  [!        S[        U5       SU R                   S35      eX R"                  U R                  U R$                  2   n[        U5      U R&                  :w  a%  [!        S[        U5       SU R&                   S35      e[)        U5      $ )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__Ú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›|Ó+Ø = LÐ1Ñ1‘à¤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                 ó   • U R                   $ )N)r    )r"   s    r#   Ú__len__ÚDistributedSampler.__len__�   s   € Ø×ÑÐr&   r   c                 ó   • Xl         g)zù
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_epochÚDistributedSampler.set_epoch’   s	   € ð �
r&   )	r   r   r   r   r    r   r   r   r!   )NNTr   F)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   ÚintÚboolr$   r   r   r6   r9   r<   Ú__static_attributes__© 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   rF   r&   r#   Ú<module>rN      sD   ðÛ Ý $Ý ã Ý  Ý ,Ý ,ð  Ð
 €ñ 	� 4Ñ(€ôL˜ ™õ Lr&   