# What does batch\_size argument in PyTorch mean?

**URL:** <https://discuss.pytorch.org/t/what-does-batch-size-argument-in-pytorch-mean/45614>\
**Category:** Uncategorized\
**Created:** [May 19, 2019, 5:20am UTC](https://discuss.pytorch.org/t/what-does-batch-size-argument-in-pytorch-mean/45614 "2019-05-19T05:20:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![scarecrow21](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/s/a8b319/32.png) [@scarecrow21](https://discuss.pytorch.org/u/scarecrow21)\
**Post date:** [May 19, 2019, 5:20am UTC](https://discuss.pytorch.org/t/what-does-batch-size-argument-in-pytorch-mean/45614/1 "2019-05-19T05:20:29Z")

</div>

For example, If I have a dataset with 10 rows. I want to train an MLP/RNN/CNN on this using mini batches.

So, let’s say, I take 2 rows at a time to train. 2 x 5 = 10. So, I train my model with batches where each batch contains 2 rows. So, number of batches = 5 and number of rows per batch is 2.

Is my batch\_size 2? or is it 5?

In the dataloader, should my batch\_size = 2 or batch\_size = 5?

---

<div class="post-metadata">

**Author:** ![InnovArul](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/innovarul/32/5282_2.png) [@InnovArul](https://discuss.pytorch.org/u/InnovArul)\
**Post date:** [May 19, 2019, 8:39am UTC](https://discuss.pytorch.org/t/what-does-batch-size-argument-in-pytorch-mean/45614/2 "2019-05-19T08:39:33Z")

</div>

In your example, `batch_size=2`.  
Once you give the `batch_size`, `Dataloader` will take care of splitting the dataset into batches (5 in your case) and provide it to you.

---

<div class="post-metadata">

**Author:** ![scarecrow21](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/s/a8b319/32.png) [@scarecrow21](https://discuss.pytorch.org/u/scarecrow21)\
**Post date:** [May 19, 2019, 11:54am UTC](https://discuss.pytorch.org/t/what-does-batch-size-argument-in-pytorch-mean/45614/3 "2019-05-19T11:54:45Z")

</div>

Thank you for clarifying! 🙂

---

<div class="post-metadata">

**Author:** ![scarecrow21](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/s/a8b319/32.png) [@scarecrow21](https://discuss.pytorch.org/u/scarecrow21)\
**Post date:** [May 20, 2019, 1:02am UTC](https://discuss.pytorch.org/t/what-does-batch-size-argument-in-pytorch-mean/45614/4 "2019-05-20T01:02:50Z")

</div>

The same definition of batch\_size holds in case of an RNN as well?

---

<div class="post-metadata">

**Author:** ![InnovArul](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/innovarul/32/5282_2.png) [@InnovArul](https://discuss.pytorch.org/u/InnovArul)\
**Post date:** [May 20, 2019, 8:12pm UTC](https://discuss.pytorch.org/t/what-does-batch-size-argument-in-pytorch-mean/45614/5 "2019-05-20T20:12:53Z")

</div>

Yes. The same definition of `batch_size` applies to the RNN as well.  
But the addition of `time steps` might make things a bit tricky (RNNs take input as `batch x time x dim` as input, assuming all the data instances in the batch are padded to have same number of time steps).

Also, take care of `batch_first=True/False` option in RNNs.
