/usr/local/lib64/python3.6/site-packages/torch/utils/data/__pycache__
NameSizeModeActions
backward_compatibility.cpython-36.pyc4740644editdlrm
dataloader.cpython-36.pyc241450644editdlrm
dataloader_experimental.cpython-36.pyc42840644editdlrm
dataset.cpython-36.pyc170510644editdlrm
distributed.cpython-36.pyc48510644editdlrm
graph.cpython-36.pyc12660644editdlrm
sampler.cpython-36.pyc90120644editdlrm
sharding.cpython-36.pyc10110644editdlrm
_decorator.cpython-36.pyc60310644editdlrm
_typing.cpython-36.pyc98520644editdlrm
__init__.cpython-36.pyc14770644editdlrm
Edit: /usr/local/lib64/python3.6/site-packages/torch/utils/data/__pycache__/distributed.cpython-36.pyc (4851B)
3 Eg9@sbddlZddlmZmZmZddlZddlmZmZddl j Z edddZ Gdd d ee Z dS) N)TypeVarOptionalIterator)SamplerDatasetT_coT) covariantc @sdeZdZdZdeeeeeeeeddddZe e d d d Z ed d d Z eddddZ dS)DistributedSampleraSampler 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. 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:: >>> 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) NTrF)dataset num_replicasrankshuffleseed drop_lastreturncCs|dkr tjstdtj}|dkr@tjs8tdtj}||ksP|dkrdtdj||d||_||_||_ d|_ ||_ |j rt |j|jdkrt jt |j|j|j|_nt jt |j|j|_|j|j|_||_||_dS)Nz,Requires distributed package to be availablerz7Invalid rank {}, rank should be in the interval [0, {}]r)distZ is_available RuntimeErrorZget_world_sizeZget_rank ValueErrorformatr r r epochrlenmathceil num_samples total_sizerr)selfr r r rrrrH/usr/local/lib64/python3.6/site-packages/torch/utils/data/distributed.py__init__;s0zDistributedSampler.__init__)rcCs|jr:tj}|j|j|jtjt|j|dj }nt t t|j}|j s|j t|}|t|kr~||d|7}q||tj|t|d|7}n|d|j }t||j kst||j|j |j}t||jkstt|S)N) generator)rtorch GeneratorZ manual_seedrrZrandpermrr tolistlistrangerrrrAssertionErrorr r riter)rgindicesZ padding_sizerrr__iter__^s $zDistributedSampler.__iter__cCs|jS)N)r)rrrr__len__yszDistributedSampler.__len__)rrcCs ||_dS)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)rrrrr set_epoch|s zDistributedSampler.set_epoch)NNTrF)__name__ __module__ __qualname____doc__rrintboolrrrr*r+r,rrrrr s-$!r )rtypingrrrr!rrZtorch.distributedZ distributedrrr rrrrs