Roc*_*etq 10 python gpu out-of-memory python-3.x pytorch
我有某种高级代码,因此模型训练等由pipeline_network课程来包装。我的主要目标是每折一次训练新模型。
for train_idx, valid_idx in cv.split(meta_train[DEPTH_COLUMN].values.reshape(-1)):
meta_train_split, meta_valid_split = meta_train.iloc[train_idx], meta_train.iloc[valid_idx]
pipeline_network = unet(config=CONFIG, suffix = 'fold' + str(fold), train_mode=True)
Run Code Online (Sandbox Code Playgroud)
但是然后我继续进行第二次折叠,所有故障都出自gpu内存:
RuntimeError: cuda runtime error (2) : out of memory at /pytorch/torch/lib/THC/generic/THCStorage.cu:58
Run Code Online (Sandbox Code Playgroud)
在纪元结束时,我尝试手动删除该管道,但没有运气:
def clean_object_from_memory(obj): #definition
del obj
gc.collect()
torch.cuda.empty_cache()
clean_object_from_memory( clean_object_from_memory) # calling
Run Code Online (Sandbox Code Playgroud)
调用它也没有帮助:
def dump_tensors(gpu_only=True):
torch.cuda.empty_cache()
total_size = 0
for obj in gc.get_objects():
try:
if torch.is_tensor(obj):
if not gpu_only or obj.is_cuda:
del obj
gc.collect()
elif hasattr(obj, "data") and torch.is_tensor(obj.data):
if not gpu_only or obj.is_cuda:
del obj
gc.collect()
except Exception as e:
pass
Run Code Online (Sandbox Code Playgroud)
如何重置pytorch,然后继续进行下一个折叠?
| 归档时间: |
|
| 查看次数: |
2563 次 |
| 最近记录: |