# Trainer error for "albert-base-v2" due to batch size mismatch

**URL:** <https://discuss.huggingface.co/t/trainer-error-for-albert-base-v2-due-to-batch-size-mismatch/20124>\
**Category:** 🤗Transformers\
**Created:** [July 7, 2022, 10:14pm UTC](https://discuss.huggingface.co/t/trainer-error-for-albert-base-v2-due-to-batch-size-mismatch/20124 "2022-07-07T22:14:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![saebom](https://avatars.discourse-cdn.com/v4/letter/s/977dab/32.png) [@saebom](https://discuss.huggingface.co/u/saebom)\
**Post date:** [July 7, 2022, 10:14pm UTC](https://discuss.huggingface.co/t/trainer-error-for-albert-base-v2-due-to-batch-size-mismatch/20124/1 "2022-07-07T22:14:57Z")

</div>

Hi all,

Previously I have been fine-tuning “bert-base-uncased” on my custom dataset (loaded from a csv file with datasets.load\_dataset), and everything works fine when I use BERT with the Hugging Face Trainer. I have recently tried replacing “bert-base-uncased” with “albert-base-v2” (in both the model and tokenizer), but I have been stuck on this error message when trying to run ALBERT:

```auto
Expected input batch_size (4096) to match target batch_size (8)

```

Since per\_device\_train\_batch\_size=8, I am certain that the input dimension comes from 8 \* 512 = 4096 where 512 is the length of an embedded vector, I think. It seems like the issue is that somewhere along the way in the model the batch matrix of embedded vectors gets smushed down to one vector.

I have tried everything to fix this bug, but I cannot work it out. My set up for the fine-tuning is exactly the same as the PyTorch set-up in [[Fine-tune a pretrained model](https://huggingface.co/docs/transformers/training)]. Any advice would be greatly appreciated

---

<div class="post-metadata">

**Author:** ![zzj0402](https://avatars.discourse-cdn.com/v4/letter/z/96bed5/32.png) [@zzj0402](https://discuss.huggingface.co/u/zzj0402)\
**Post date:** [April 11, 2023, 4:22am UTC](https://discuss.huggingface.co/t/trainer-error-for-albert-base-v2-due-to-batch-size-mismatch/20124/2 "2023-04-11T04:22:13Z")

</div>

You are not alone. Keep me posted. I am poking around the dataset batching mechanism but no luck.
