# How to dynamically load the required batch into GPU memory?

**URL:** <https://community.konduit.ai/t/how-to-dynamically-load-the-required-batch-into-gpu-memory/3290>\
**Category:** DL4J\
**Created:** [November 25, 2024, 8:54am UTC](https://community.konduit.ai/t/how-to-dynamically-load-the-required-batch-into-gpu-memory/3290 "2024-11-25T08:54:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cqiaoYc](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/cqiaoyc/32/738_2.png) [@cqiaoYc](https://community.konduit.ai/u/cqiaoYc)\
**Post date:** [November 25, 2024, 8:54am UTC](https://community.konduit.ai/t/how-to-dynamically-load-the-required-batch-into-gpu-memory/3290/1 "2024-11-25T08:54:18Z")

</div>

When the dataset is large, memory capacity is sufficient, but GPU memory (VRAM) is limited, how to efficiently utilize VRAM?  
Store the sample data in memory first, and during training, dynamically load the required batch into GPU memory. After completing the training for that batch, release the GPU memory.

---

<div class="post-metadata">

**Author:** ![agibsonccc](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/agibsonccc/32/697_2.png) [@agibsonccc](https://community.konduit.ai/u/agibsonccc)\
**Post date:** [November 25, 2024, 9:15pm UTC](https://community.konduit.ai/t/how-to-dynamically-load-the-required-batch-into-gpu-memory/3290/2 "2024-11-25T21:15:03Z")

</div>

@cqiaoYc usually we preload that using an asyncdatasetiterator. You want a batch size and at most the next batch preloaded in the background. Your batch size is determined by what works well in training (different batch sizes _can_ affect network quality)  
and what your hardware allows.

---

<div class="post-metadata">

**Author:** ![cqiaoYc](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/cqiaoyc/32/738_2.png) [@cqiaoYc](https://community.konduit.ai/u/cqiaoYc)\
**Post date:** [November 26, 2024, 1:05am UTC](https://community.konduit.ai/t/how-to-dynamically-load-the-required-batch-into-gpu-memory/3290/3 "2024-11-26T01:05:50Z")

</div>

I know what to do now. Thank you very much.
