你可以看到這個筆記本在kaggle中是可以訓練的,使用kaggle的16gb vram限制:https://www.kaggle.com/firefliesqn/g2net-gpu-newbie
我剛剛嘗試在安裝了torch 1.8的rtx3090 gpu上本地運行這個相同的筆記本,同樣的筆記本分配了大約23.3gb的vram,為什么會這樣,我怎樣才能像kaggle一樣優化我的本地環境? 即使我比kaggle中使用的批處理大小減少,我的筆記本在本地仍然分配了大約23gb的vram
在kggle中我看到安裝了torch 1.7,tensorflow 2.4,在本地因為我使用rtx3090所以建議使用新版本的torch和tf,因此我使用了torch 1.8.1和tensorflow 2.6uj5u.com熱心網友回復:默認情況下,TensorFlow分配了檢測到的最大可用記憶體。
當使用TensorFlow時,可以通過下面的片段來限制使用的記憶體:
gpus = tf.config.experimental.list_physical_devices('GPU'/span>)
if gpus:
# 限制TensorFlow只在第一個GPU上分配12GB的記憶體。
try:
tf.config.experimental.set_virtual_device_configuration(gpus[0],
[tf.config.experimental.VirtualDeviceConfiguration(memory_limit=12288)]。
其中12228=1024x12
另一個解決方案(見下面的討論)是使用(對OP有效)(只在你沒有特定的要使用的記憶體上限時使用) :
tf.config.experimental.set_memory_growth(physical_devices[0], True)
https://www.tensorflow.org/api_docs/python/tf/config/experimental/set_memory_growth
在PyTorch中,這就更簡單了:
import torch
# use 1/2 memory of the GPU 0 (should allocate very similar amount like TF)
torch.cuda.set_per_process_memory_fraction(0.5, 0)
#可以用檢查。
total_memory_available = torch.cuda.get_device_properties(0) .total_memory
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/328131.html
標籤:
