# Double expected memory usage

**URL:** <https://discuss.huggingface.co/t/double-expected-memory-usage/15190>\
**Category:** Beginners\
**Created:** [February 28, 2022, 6:41am UTC](https://discuss.huggingface.co/t/double-expected-memory-usage/15190 "2022-02-28T06:41:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ryulord](https://avatars.discourse-cdn.com/v4/letter/r/77aa72/32.png) [@Ryulord](https://discuss.huggingface.co/u/Ryulord)\
**Post date:** [February 28, 2022, 6:41am UTC](https://discuss.huggingface.co/t/double-expected-memory-usage/15190/1 "2022-02-28T06:41:59Z")

</div>

I’ve used a few different models through Huggingface and consistently noticed approximately double expected memory usage. For example, the below code uses a model that has a 1.5 GB model file so I expect about 1.5 GB of memory usage. Instead, I see memory usage increase by about 3 GB. Is there something I’m misunderstanding or doing incorrectly?

```auto
from transformers import pipeline
from time import sleep

classifier = pipeline('zero-shot-classification', model='facebook/bart-large-mnli')
print('Done loading!')
sleep(10)

```

---

<div class="post-metadata">

**Author:** ![samr](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@samr](https://discuss.huggingface.co/u/samr)\
**Post date:** [August 17, 2022, 5:59pm UTC](https://discuss.huggingface.co/t/double-expected-memory-usage/15190/2 "2022-08-17T17:59:50Z")

</div>

So the bad news it is six months after you posted this. But I’ve been reading the [docs](https://huggingface.co/docs/transformers/v4.21.1/en/main_classes/model#transformers.PreTrainedModel.from_pretrained), which say that this happens because the model is loaded and then the full weights are loaded, which takes twice the RAM of the model.

Happily, in v \>=4.2.0 (released June 2022) you can use `low_cpu_mem_usage=True` in your `from_pretrained()` call to address this:

> This option can be activated with `low_cpu_mem_usage=True` . The model is first created on the Meta device (with empty weights) and the state dict is then loaded inside it (shard by shard in the case of a sharded checkpoint). This way the maximum RAM used is the full size of the model only.

```python
from transformers import AutoModelForSeq2SeqLM

t0pp = AutoModelForSeq2SeqLM.from_pretrained("bigscience/T0pp", low_cpu_mem_usage=True)

```
