Pytorch釋放顯存占用方式
如果在python內(nèi)調(diào)用pytorch有可能顯存和GPU占用不會被自動釋放,此時需要加入如下代碼
torch.cuda.empty_cache()
我們來看一下官方文檔的說明
Releases all unoccupied cached memory currently held by the caching allocator so that those can be used in other GPU application and visible in nvidia-smi.
Note
empty_cache() doesn't increase the amount of GPU memory available for PyTorch. See Memory management for more details about GPU memory management.
此外還可以使用
memory_allocated()和max_memory_allocated()
觀察顯存占用,并使用
memory_cached()和 max_memory_cached()
觀察由緩存分配器管理的內(nèi)存。
以上這篇Pytorch釋放顯存占用方式就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
CentOS下Python3的安裝及創(chuàng)建虛擬環(huán)境的方法
這篇文章主要介紹了CentOS下Python3的安裝及創(chuàng)建虛擬環(huán)境的方法,本文給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下2018-11-11
簡單介紹Python中的try和finally和with方法
這篇文章主要介紹了Python中的try和finally和with方法,是Python學(xué)習(xí)當中的基礎(chǔ)知識,需要的朋友可以參考下2015-05-05

