# ValueError: Expected input batch\_size (16) to match target batch\_size (64)

**URL:** <https://discuss.huggingface.co/t/valueerror-expected-input-batch-size-16-to-match-target-batch-size-64/1569>\
**Category:** Beginners\
**Created:** [October 15, 2020, 8:06pm UTC](https://discuss.huggingface.co/t/valueerror-expected-input-batch-size-16-to-match-target-batch-size-64/1569 "2020-10-15T20:06:01Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![laurb](https://avatars.discourse-cdn.com/v4/letter/l/e47c2d/32.png) [@laurb](https://discuss.huggingface.co/u/laurb)\
**Post date:** [October 15, 2020, 8:06pm UTC](https://discuss.huggingface.co/t/valueerror-expected-input-batch-size-16-to-match-target-batch-size-64/1569/1 "2020-10-15T20:06:01Z")

</div>

I’ve modeled my training script on the information in the finetuning with custom datasets documentation ([https://huggingface.co/transformers/custom\_datasets.html](https://huggingface.co/transformers/custom_datasets.html)).  
I have both a custom dataset and a custom model (I used the run\_language\_modeling.py script to pretrain the roberta-base model with our raw texts).

when I run trainer.train() I get the error: ValueError: Expected input batch\_size (16) to match target batch\_size (64), when the model is computing the loss on a training\_step

I don’t know where target batch\_size is being set. The input batch\_size matches the value I have for per\_device\_train\_batch\_size.

Does anyone have an idea?

---

<div class="post-metadata">

**Author:** ![laurb](https://avatars.discourse-cdn.com/v4/letter/l/e47c2d/32.png) [@laurb](https://discuss.huggingface.co/u/laurb)\
**Post date:** [October 16, 2020, 10:12am UTC](https://discuss.huggingface.co/t/valueerror-expected-input-batch-size-16-to-match-target-batch-size-64/1569/2 "2020-10-16T10:12:46Z")

</div>

Tried this using roberta-base as the model as well, and get the same error.

---

<div class="post-metadata">

**Author:** ![Rainiefantasy](https://avatars.discourse-cdn.com/v4/letter/r/9dc877/32.png) [@Rainiefantasy](https://discuss.huggingface.co/u/Rainiefantasy)\
**Post date:** [September 14, 2021, 1:46am UTC](https://discuss.huggingface.co/t/valueerror-expected-input-batch-size-16-to-match-target-batch-size-64/1569/3 "2021-09-14T01:46:17Z")

</div>

Hey Laurb,

Sorry I know this is an old post, but did you manage to resolve this? I’ve got the same issue when using DistilBert using custom dataset as in their tutorial. ☹  
ValueError: Expected input batch\_size (16) to match target batch\_size (2848).

---

<div class="post-metadata">

**Author:** ![laurb](https://avatars.discourse-cdn.com/v4/letter/l/e47c2d/32.png) [@laurb](https://discuss.huggingface.co/u/laurb)\
**Post date:** [September 16, 2021, 11:08am UTC](https://discuss.huggingface.co/t/valueerror-expected-input-batch-size-16-to-match-target-batch-size-64/1569/4 "2021-09-16T11:08:09Z")

</div>

Sorry. I did resolve it, but have no memory of how. I’m up to using transformers 4.9.2 now and do not have the issue and do not need to make changes to their run\_classification script. (I’m using the pytorch version).

---

<div class="post-metadata">

**Author:** ![nicir](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/nicir/32/5702_2.png) [@nicir](https://discuss.huggingface.co/u/nicir)\
**Post date:** [September 27, 2022, 7:31am UTC](https://discuss.huggingface.co/t/valueerror-expected-input-batch-size-16-to-match-target-batch-size-64/1569/5 "2022-09-27T07:31:29Z")

</div>

Hello Rainiefantasy,

I know this is an old issue but have you also managed to resolve this problem? Maybe you remember. I have the exact same problem…

Thank you!

---

<div class="post-metadata">

**Author:** ![massisenergy](https://avatars.discourse-cdn.com/v4/letter/m/ecb155/32.png) [@massisenergy](https://discuss.huggingface.co/u/massisenergy)\
**Post date:** [January 6, 2023, 8:44am UTC](https://discuss.huggingface.co/t/valueerror-expected-input-batch-size-16-to-match-target-batch-size-64/1569/6 "2023-01-06T08:44:53Z")

</div>

Hello,

I am having similar issue while running `trainer.train()`:

> ValueError: Expected input batch\_size (664) to match target batch\_size (8).

Checkpoint: `bert-base-uncased`  
Dataset: `jmamou/augmented-glue-sst2`

Can anyone please help?  
Thanks,

---

<div class="post-metadata">

**Author:** ![zbeloki](https://avatars.discourse-cdn.com/v4/letter/z/e36b37/32.png) [@zbeloki](https://discuss.huggingface.co/u/zbeloki)\
**Post date:** [February 27, 2023, 11:31am UTC](https://discuss.huggingface.co/t/valueerror-expected-input-batch-size-16-to-match-target-batch-size-64/1569/7 "2023-02-27T11:31:53Z")

</div>

In my case it was because I was trying to train as a multi-label classification model by encoding the labels with sklearn’s MultiLabelBinarizer but forgot to set the config parameter for multilabel setting to the model:

> model.config.problem\_type = “multi\_label\_classification”

---

<div class="post-metadata">

**Author:** ![Raisa06](https://avatars.discourse-cdn.com/v4/letter/r/ecccb3/32.png) [@Raisa06](https://discuss.huggingface.co/u/Raisa06)\
**Post date:** [November 7, 2023, 5:50am UTC](https://discuss.huggingface.co/t/valueerror-expected-input-batch-size-16-to-match-target-batch-size-64/1569/8 "2023-11-07T05:50:25Z")

</div>

Hi,

I’m also facing same issue while running trainer.train()

Using bert-base-uncased

Basically I’ve done the sliding windows for splitting the dataset as we have the maximum sequence length for the tokenizer.

Ideally sliding windows are generated and we have mapped to respective labels.

While the trainer.train() I’m getting the below error,

> ValueError: Expected input batch\_size (2040) to match target batch\_size (6392)

Can anyone please help with the error?

Thanks
