# How to quickly determine memory requirements for model

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-quickly-determine-memory-requirements-for-model%2F43426%3E%5C
**Category:** Beginners\
**Created:** [June 15, 2023, 10:25pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-quickly-determine-memory-requirements-for-model%2F43426 "2023-06-15T22:25:45Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![cmr99](https://avatars.discourse-cdn.com/v4/letter/c/3be4f8/32.png) [@cmr99](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fcmr99)%5C
**Post date:** [June 15, 2023, 10:25pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-quickly-determine-memory-requirements-for-model%2F43426%2F1 "2023-06-15T22:25:45Z")

</div>

Hey all - as I browse models for those that suit my project, I am trying to quickly determine the memory requirements for running each model locally. This seems like something many users would want to do and so there should be an obvious place to look on a model card to make this determination, but I don’t see any such place. I don’t even see a place where the parameter count is consistently stated. How should I approach this?

---

<div class="post-metadata">

**Author:** ![mariosasko](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/mariosasko/32/31548_2.png) [@mariosasko](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fmariosasko)%5C
**Post date:** [June 19, 2023, 4:23pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-quickly-determine-memory-requirements-for-model%2F43426%2F2 "2023-06-19T16:23:40Z")

</div>

Hi! You can find this info by checking the size of `pytorch_model.bin` (or `tf_model.h5`/`flax_model.msgpack` for TF/Flax models). These files can be sharded sometimes (if `pytorch_model.bin.index.json` is present), in which case you need to sum up all the shards listed in the index file.

PS: For the parameter count to be displayed, the weights must be saved in the `safetensors` format.

---

<div class="post-metadata">

**Author:** ![cmr99](https://avatars.discourse-cdn.com/v4/letter/c/3be4f8/32.png) [@cmr99](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fcmr99)%5C
**Post date:** [June 24, 2023, 9:40am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-quickly-determine-memory-requirements-for-model%2F43426%2F3 "2023-06-24T09:40:32Z")

</div>

Thanks very much for the help.

---

<div class="post-metadata">

**Author:** ![pvelosipednikov](https://avatars.discourse-cdn.com/v4/letter/p/90db22/32.png) [@pvelosipednikov](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fpvelosipednikov)%5C
**Post date:** [September 21, 2023, 6:07pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-quickly-determine-memory-requirements-for-model%2F43426%2F4 "2023-09-21T18:07:10Z")

</div>

How would I determine these requirements when I’m finetuning a model? I’m finetuning a 780 MB model with a 5 MB dataset. On my local machine this runs fine (16 GB ram) but when I use a GPU (Tesla T4 with 16 GB of GPU ram), I immediately get an OOM error when I launch `trainer.train()`.

---

<div class="post-metadata">

**Author:** ![MattiLinnanvuori](https://avatars.discourse-cdn.com/v4/letter/m/ec9cab/32.png) [@MattiLinnanvuori](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FMattiLinnanvuori)%5C
**Post date:** [September 24, 2023, 11:17am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-quickly-determine-memory-requirements-for-model%2F43426%2F5 "2023-09-24T11:17:56Z")

</div>

Have you tried Model Memory Calculator? [Model Memory Utility - a Hugging Face Space by hf-accelerate](https://huggingface.co/spaces/hf-accelerate/model-memory-usage)

---

<div class="post-metadata">

**Author:** ![pvelosipednikov](https://avatars.discourse-cdn.com/v4/letter/p/90db22/32.png) [@pvelosipednikov](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fpvelosipednikov)%5C
**Post date:** [September 24, 2023, 12:57pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-quickly-determine-memory-requirements-for-model%2F43426%2F6 "2023-09-24T12:57:43Z")

</div>

Nice link, thanks.

So finetuning should consume less memory than training, and training the model I’m using is just 4.57 GB according to the calculator. So I’m probably misunderstanding something about the model architecture since I have 16 GB GPU RAM.

 ![image](https://us1.discourse-cdn.com/hellohellohello/original/3X/a/4/a45c0e8c559ac154a5b6995196cce0c0aee92e8c.png)

---

<div class="post-metadata">

**Author:** ![hvinay](https://avatars.discourse-cdn.com/v4/letter/h/ccd318/32.png) [@hvinay](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fhvinay)%5C
**Post date:** [November 7, 2023, 5:44am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-quickly-determine-memory-requirements-for-model%2F43426%2F8 "2023-11-07T05:44:55Z")

</div>

> [@pvelosipednikov](#):
>
> hould consume less memory than training, and training the model I’m using is just 4.57 GB according to t

Total memory required during training/tuning should depend on the batch size right? Why batch size is not an input to this utility?

---

<div class="post-metadata">

**Author:** ![odiouschipmunk](https://avatars.discourse-cdn.com/v4/letter/o/f6c823/32.png) [@odiouschipmunk](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fodiouschipmunk)%5C
**Post date:** [August 28, 2024, 7:27pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-quickly-determine-memory-requirements-for-model%2F43426%2F9 "2024-08-28T19:27:29Z")

</div>

The batch size is automatically set to one as said in, “When training on a batch size of 1”.
