§
    :zni6  ã                   óŽ   — d dl Z d dlmZmZmZ d dlZddlmZmZ d dl	m
Z dgZ edd¬¦  «        Z G d	„ dee         ¦  «        ZdS )
é    N)ÚTypeVarÚOptionalÚIteratoré   )ÚSamplerÚDatasetÚDistributedSamplerÚT_coT)Ú	covariantc                   óŠ   — 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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, r   ú])Ú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          ú|/var/www/html/cool-property-finder/image-detection-backend/venv/lib/python3.11/site-packages/torch/utils/data/distributed.pyÚ__init__zDistributedSampler.__init__>   s{  € ð ÐÝÔ$Ñ&Ô&ð 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    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__`   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àŒ~ð 		0àœ?­S°©\¬\Ñ9ˆLØ�s 7™|œ|Ò+Ð+Ø˜7 = L =Ô1Ñ1��à˜G¥d¤i°½sÀ7¹|¼|Ñ0KÑ&LÔ&LÑLÈmÈ|ÈmÔ\Ñ\��ð Ð.˜tœÐ.Ô/ˆGÝ�7‰|Œ|˜tœÒ.Ð.Ð.Ð.ð ˜$œ) D¤O°DÔ4EÐEÔFˆÝ�7‰|Œ|˜tÔ/Ò/Ð/Ð/Ð/å�G‰}Œ}Ðr%   c                 ó   — | j         S )N)r    )r"   s    r#   Ú__len__zDistributedSampler.__len__{   s   € ØÔÐr%   r   c                 ó   — || _         dS )a)  
        Sets 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à   € € € € € ð.ð .ð` HLØ=AØ27ð ð   ð  °xÀ´}ð  Ø ”}ð Ø6:ð àð à+/ð à<@ð ð  ð  ð  ðD˜( 4œ.ð ð ð ð ð6 ˜ð  ð  ð  ð  ð	˜sð 	 tð 	ð 	ð 	ð 	ð 	ð 	r%   )r   Útypingr   r   r   r(   Ú r   r   Útorch.distributedÚdistributedr   Ú__all__r
   r	   r>   r%   r#   ú<module>rD      s½   ðØ €€€Ø .Ð .Ð .Ð .Ð .Ð .Ð .Ð .Ð .Ð .à €€€Ø Ð Ð Ð Ð Ð Ð Ð Ø  Ð  Ð  Ð  Ð  Ð  àÐ
"€à€wˆv Ð&Ñ&Ô&€ðzð zð zð zð z˜ œñ zô zð zð zð zr%   