Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

batch size setting during training

Tags:

gpu

keras

When I am training using keras + tensorflow-gpu, and I set the batch_size to 128, which is the max size the gpu could accept, otherwise, there's OOM problem. My question is when the batch_size is 128, the pics size is 128*224*224*3*4(the img size is 224*224, in RGB channel), total is around 10M Bytes, which I think is too small compared to the memory of GPU. Is there any explanation for it?

like image 703
Xingyu Gu Avatar asked Mar 21 '26 22:03

Xingyu Gu


2 Answers

You are forgetting 3 more things which also require GPU memory.

  1. Your Model weights.

  2. Temporary variables during calculation of gradients.

These two take up a huge chunk of memory. This is why even though your batch consumes 10M.

  1. There are so many other minute things that require GPU memory.
like image 193
Vikas NS Avatar answered Mar 24 '26 10:03

Vikas NS


The image is uint where is tensor is float64 which increases size by eight times. Forward path, gradients, and other tensors use a significant chunk of memory.

You can compute memory required for your model as given here

like image 29
Mohbat Tharani Avatar answered Mar 24 '26 11:03

Mohbat Tharani



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!