# TF bert-base-uncased reserves large memory space

**URL:** <https://discuss.huggingface.co/t/tf-bert-base-uncased-reserves-large-memory-space/19553>\
**Category:** 🤗Transformers\
**Created:** [June 24, 2022, 1:54am UTC](https://discuss.huggingface.co/t/tf-bert-base-uncased-reserves-large-memory-space/19553 "2022-06-24T01:54:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jasonyux](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/jasonyux/32/5176_2.png) [@jasonyux](https://discuss.huggingface.co/u/jasonyux)\
**Post date:** [June 24, 2022, 1:54am UTC](https://discuss.huggingface.co/t/tf-bert-base-uncased-reserves-large-memory-space/19553/1 "2022-06-24T01:54:09Z")

</div>

I wanted to do some text classification task using tensorflow so I did

```auto
model = TFBertForSequenceClassification.from_pretrained("bert-base-uncased")

```

but then I immediately checked memory usage (before the above operation there were only 2 MB usage):

```auto
| 0 NVIDIA GeForce ... On | 00000000:01:00.0 Off | N/A |
| 30% 53C P2 128W / 350W | 22999MiB / 24265MiB | 0% Default |

```

Is this normal that it is taking like 20GB of space? I looked up online and it seems that those simple bert models should take only around a few GB? This makes it very prohibitive to train with a large batch size (I wanted to use `BATCH_SIZE=64`). Any idea why this happens/how to ask tf not to reserve so much memory?

---

<div class="post-metadata">

**Author:** ![jasonyux](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/jasonyux/32/5176_2.png) [@jasonyux](https://discuss.huggingface.co/u/jasonyux)\
**Post date:** [June 24, 2022, 2:10am UTC](https://discuss.huggingface.co/t/tf-bert-base-uncased-reserves-large-memory-space/19553/2 "2022-06-24T02:10:10Z")

</div>

It seems to be a tensorflow “feature” that it will automatically reserves the entirety of the gpu. I found the solution is to do:

```auto
gpus = tf.config.list_physical_devices('GPU')
for gpu in gpus: # so tf does not map all gpu space
	tf.config.experimental.set_memory_growth(gpu, True)

```
