# OOM when allocating tensor with shape

**URL:** <https://discuss.ai.google.dev/t/oom-when-allocating-tensor-with-shape/31989>\
**Category:** General Discussion\
**Tags:** keras, models, help\_request\
**Created:** [February 5, 2022, 6:23am UTC](https://discuss.ai.google.dev/t/oom-when-allocating-tensor-with-shape/31989 "2022-02-05T06:23:49Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![as\_ry](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/as_ry/32/10632_2.png) [@as\_ry](https://discuss.ai.google.dev/u/as_ry)\
**Post date:** [February 5, 2022, 6:23am UTC](https://discuss.ai.google.dev/t/oom-when-allocating-tensor-with-shape/31989/1 "2022-02-05T06:23:49Z")

</div>

i tried to update the weighs layer of embedding in the keras model but this size  
`(1393860, 768)`  
by

```auto
 se1 = Embedding(1393860, 768, mask_zero=True)
 model.layers[1].set_weights([embedding_matrix])    
 model.layers[1].trainable = False

```

but got  
`tensorflow.python.framework.errors_impl.ResourceExhaustedError: OOM when allocating tensor with shape[1393860,768] and type float on /job:localhost/replica:0/task:0/device:GPU:0 by allocator GPU_0_bfc [Op:RandomUniform]`

---

<div class="post-metadata">

**Author:** ![emrullah\_polat](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/emrullah_polat/32/9581_2.png) [@emrullah\_polat](https://discuss.ai.google.dev/u/emrullah_polat)\
**Post date:** [February 7, 2022, 12:01pm UTC](https://discuss.ai.google.dev/t/oom-when-allocating-tensor-with-shape/31989/3 "2022-02-07T12:01:29Z")

</div>

what is your gpu ? I was getting this error while i give huge train data size to GPU

---

<div class="post-metadata">

**Author:** ![as\_ry](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/as_ry/32/10632_2.png) [@as\_ry](https://discuss.ai.google.dev/u/as_ry)\
**Post date:** [February 7, 2022, 1:27pm UTC](https://discuss.ai.google.dev/t/oom-when-allocating-tensor-with-shape/31989/4 "2022-02-07T13:27:19Z")

</div>

i’m using rtx 2060 with 32 GB RAM

---

<div class="post-metadata">

**Author:** ![emrullah\_polat](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/emrullah_polat/32/9581_2.png) [@emrullah\_polat](https://discuss.ai.google.dev/u/emrullah_polat)\
**Post date:** [February 7, 2022, 1:35pm UTC](https://discuss.ai.google.dev/t/oom-when-allocating-tensor-with-shape/31989/5 "2022-02-07T13:35:20Z")

</div>

can you try this value with little value that suitable for the model ?

---

<div class="post-metadata">

**Author:** ![as\_ry](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/as_ry/32/10632_2.png) [@as\_ry](https://discuss.ai.google.dev/u/as_ry)\
**Post date:** [February 7, 2022, 7:42pm UTC](https://discuss.ai.google.dev/t/oom-when-allocating-tensor-with-shape/31989/6 "2022-02-07T19:42:02Z")

</div>

excuse me I didn’t get what do you mean? the model is working with values that have fewer numbers than those as I’m using Bert to get word-embedding for 150000 sentences. when i used 150000 sentences it worked but now I need to use the words themselves that have 13 million and 93860 words but got a problem with GPU.

---

<div class="post-metadata">

**Author:** ![emrullah\_polat](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/emrullah_polat/32/9581_2.png) [@emrullah\_polat](https://discuss.ai.google.dev/u/emrullah_polat)\
**Post date:** [February 8, 2022, 7:34am UTC](https://discuss.ai.google.dev/t/oom-when-allocating-tensor-with-shape/31989/8 "2022-02-08T07:34:09Z")

</div>

I guess your gpu memory is not enough this data size. But I dont know if there is a way. I would tried for train data Batch size and reduced 64 batch to 32 batch.

---

<div class="post-metadata">

**Author:** ![as\_ry](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/as_ry/32/10632_2.png) [@as\_ry](https://discuss.ai.google.dev/u/as_ry)\
**Post date:** [February 8, 2022, 10:26am UTC](https://discuss.ai.google.dev/t/oom-when-allocating-tensor-with-shape/31989/10 "2022-02-08T10:26:31Z")

</div>

i tried to reduce batsh\_size but error still

---

<div class="post-metadata">

**Author:** ![fdd](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/fdd/32/16733_2.png) [@fdd](https://discuss.ai.google.dev/u/fdd)\
**Post date:** [January 2, 2024, 2:37am UTC](https://discuss.ai.google.dev/t/oom-when-allocating-tensor-with-shape/31989/12 "2024-01-02T02:37:52Z")

</div>

Hello, I’ve encountered the same issue. Have you resolved it? If you have, could you please let me know how to fix it?
