# Redefining model with fewer parameters → out of memory (OOM)?

**URL:** <https://discuss.pytorch.org/t/redefining-model-with-fewer-parameters-out-of-memory-oom/216793>\
**Category:** Memory Format\
**Created:** [February 17, 2025, 11:50pm UTC](https://discuss.pytorch.org/t/redefining-model-with-fewer-parameters-out-of-memory-oom/216793 "2025-02-17T23:50:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Geremia](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/geremia/32/70165_2.png) [@Geremia](https://discuss.pytorch.org/u/Geremia)\
**Post date:** [February 17, 2025, 11:50pm UTC](https://discuss.pytorch.org/t/redefining-model-with-fewer-parameters-out-of-memory-oom/216793/1 "2025-02-17T23:50:52Z")

</div>

Why when I redefine my model to have fewer parameters and retrain (after training once before) does PyTorch sometimes through an OOM error?

In other words: How do I tune model hyperparameters without running into OOM errors?

Do I have to reset the computational graph / saved gradients in the dataset’s tensors? If so, how?

---

<div class="post-metadata">

**Author:** ![Geremia](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/geremia/32/70165_2.png) [@Geremia](https://discuss.pytorch.org/u/Geremia)\
**Post date:** [February 19, 2025, 10:58pm UTC](https://discuss.pytorch.org/t/redefining-model-with-fewer-parameters-out-of-memory-oom/216793/2 "2025-02-19T22:58:35Z")

</div>

When I make too big of a model and training throws an OOM error when passing an batch to it, I have to `del model` and run

```python
gc.collect()
torch.cuda.empty_cache()

```
