The problem of insufficient video memory for running deep learning in Pytorch

When running the program, I always encounter the problem of insufficient video memory.
insert image description here




After consulting the information, I added these two lines at the beginning of the code

torch.cuda.set_per_process_memory_fraction(0.5, 0)
torch.cuda.empty_cache()


I was able to run for a while longer than before, but soon said that the video memory was insufficient, so I tried to clear the cache before each training iteration, that is
def train_iter(self):
        # ...

        for epoch in range(config.n_epochs):   # 每次迭代开始前
            torch.cuda.empty_cache()    #  新增代码
      		#...

problem solved

Guess you like

Origin blog.csdn.net/weixin_51930942/article/details/127816764