Latest / Big Iron Radio / Homelab Brief - GPU Memory Fragmentation and OOM During Inference
Transcript
- 0:02Welcome to the Homelab Brief from Big Iron.
- 0:06Today, the maddening out-of-memory error that fires when NVIDIA SMI swears, you have plenty of RAM-free.
- 0:14Quick note, this is an AI voice drawn from a Big Iron guide.
- 0:18Links below.
- 0:20That contradiction has a name.
- 0:23Fragmentation.
- 0:24GPU frameworks use a caching allocator.
- 0:27It grabs big blocks of RAM up front and subdivides them for you.
- 0:32Over time, as allocations come and go, the free space becomes non-contiguous.
- 0:37So an allocation fails because no single contiguous gap is large enough, even though the total free memory exceeds what you asked for.
- 0:46It's not a bug.
- 0:48It's Swiss cheese.
- 0:49You can diagnose it straight from the error message.
- 0:52If the reported free memory is larger than the allocation that failed, that's fragmentation and it's fixable.
- 0:59If the free memory is smaller than the request, that's a genuine shortage, and no trick saves you you have to shrink the workload.
- 1:07Read those two numbers first.
- 1:10One tooling warning.
- 1:11NVIDIA SMI will mislead you here.
- 1:14It shows reserved memory and literally cannot see fragmentation.
- 1:18To actually understand what's happening, use Torch, CUDA, memory summary that's the view that shows the fragmented reality.
- 1:26And the big fix, the one that resolves most cases.
- 1:30Set the environment variable PyTorch, CUDA a la CONF, to expandable segments true.
- 1:35That switches the allocator to a growable address region instead of fixed blocks, which largely eliminates fragmentation.
- 1:44One end var, and the phantom OOMs mostly vanish.
- 1:48So the workflow.
- 1:50Hit an OOM with free memory to spare.
- 1:52Confirm free is bigger than the failed request.
- 1:55Flip on expandable segments and move on.
- 1:58The full deep dives in the show notes.
- 2:00That's your brief.
- 2:01Wolf.