🐥

【Nvidia】How to release VRAM of GPU

2024/07/24に公開

When using the GPU with various codes, it is possible that VRAM may still be in use somewhere even after you think you have released it.
Then, the program outputs the error like this:
・Error

RESOURCE_EXHAUSTED: Out of memory while trying to allocate XXXXXXXXX bytes.

This time, I will introduce a method to release all VRAM(for Nvidia GPU).

Check the memory usage

・Check

nvidia-smi

・Memory Usage(Output)

...
1591MiB /  16376MiB
...

Release the VRAM

・Install lsof

sudo apt-get install lsof

・Release

kill -9 $(lsof -t /dev/nvidia*)

After this, maybe you can use the GPU comfortably.

Discussion