When shuffle is True for DataLoader what is the default Sampler?

username: Intel_Novel
cooked: <p>When shuffle is <code>True</code> for <code>DataLoader</code> class what is the default Sampler then?<br>
From the docs:</p>
<pre><code class="lang-auto">shuffle (bool, optional): set to ``True`` to have the data reshuffled
            at every epoch (default: ``False``).
</code></pre>
<p>If I don’t set the Sampler one must be used by default. Can you give any clue?</p>

username: ptrblck
cooked: <p>If no sampler was specified and <code>shuffle=True</code>, the <code>RandomSampler</code> will be used as shown in <a href="https://github.com/pytorch/pytorch/blob/e5742494f6080c8e6f43c37689fc18a7c4b39dfd/torch/utils/data/dataloader.py#L145" rel="nofollow noopener">this line of code</a>.</p>

username: Intel_Novel
cooked: <p>Thanks, from there I also saw  one interesting line<br>
<code>if batch_sampler is None:</code></p>
<p>So if we set the <code>batch_sampler=bs</code> where <code>bs</code> is instance of the class <code>BatchSampler</code> we are OK?</p>
<p>So I guess if we do have <code>batch_size</code> greater than 1 for our <code>DataLoader</code> it is more common to use the <code>BatchSampler</code>?</p>

username: ptrblck
cooked: <p>Yes, if no <code>batch_sampler</code> was provided, the <code>sampler</code> (either default or passed) will be wrapped in a <code>BatchSampler</code> instance.</p>

username: Jaideep_Valani
cooked: <p><a class="mention" href="/u/ptrblck">@ptrblck</a> if i dont give sampler and shuffle is also false.<br>
How are items retrieved by dataloader.</p>

username: BaruchG
cooked: <p>Using the SequentialSampler as shown in <a href="https://github.com/pytorch/pytorch/blob/e5742494f6080c8e6f43c37689fc18a7c4b39dfd/torch/utils/data/dataloader.py#L147" rel="nofollow noopener">this</a> line, a couple lines below the above.  You can find more information about it at <a href="https://pytorch.org/docs/stable/data.html#torch.utils.data.SequentialSampler" rel="nofollow noopener">https://pytorch.org/docs/stable/data.html#torch.utils.data.SequentialSampler</a></p>

username: Jaideep_Valani
cooked: <p>Thanks I use that  but dont know why i get an error</p>
<aside class="quote quote-modified" data-post="1" data-topic="94088">
  <div class="title">
    <div class="quote-controls"></div>
    <img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/jaideep_valani/48/8482_2.png" class="avatar">
    <a href="https://discuss.pytorch.org/t/error-with-sequential-sampler/94088">Error With Sequential Sampler</a> <a class="badge-category__wrapper " href="/c/vision/5"><span data-category-id="5" data-drop-close="true" class="badge-category " title="Topics related to either pytorch/vision or vision research related topics"><span class="badge-category__name">vision</span></span></a>
  </div>
  <blockquote>
    When dataloader iterates through the below loader ,i get an error saying 
index 307 is out of bounds for axis 0 with size 307 
but with RandomSampler i dont get any error. size of valid set array is 307 . 
for tr_idx, val_idx in tqdm(kf.split(z)):

    train_dataset = DatasetRetriever(
        train_arrays=z[tr_idx],#.index.values,
        targets= y[tr_idx]

    )

    valid_dataset = DatasetRetriever(
        train_arrays=z[val_idx],#.index.values,
        targets= y[val_idx]

    )

valid_loa…
  </blockquote>
</aside>