this is my error :

  File "D:\python\RDANET\main.py", line 197, in <module>
    fire.Fire(train)

  File "d:\anaconda3\lib\site-packages\fire\core.py", line 138, in Fire
    component_trace = _Fire(component, args, parsed_flag_args, context, name)

  File "d:\anaconda3\lib\site-packages\fire\core.py", line 463, in _Fire
    component, remaining_args = _CallAndUpdateTrace(

  File "d:\anaconda3\lib\site-packages\fire\core.py", line 672, in _CallAndUpdateTrace
    component = fn(*varargs, **kwargs)
  File "D:\python\RDANET\main.py", line 112, in train
    optimizer.step()

  File "d:\anaconda3\lib\site-packages\torch\autograd\grad_mode.py", line 26, in decorate_context
    return func(*args, **kwargs)

  File "d:\anaconda3\lib\site-packages\torch\optim\adam.py", line 91, in step
    state['exp_avg_sq'] = torch.zeros_like(p, memory_format=torch.preserve_format)

RuntimeError: CUDA out of memory. Tried to allocate 1.35 GiB (GPU 0; 15.92 GiB total capacity; 12.89 GiB already allocated; 1.22 GiB free; 13.67 GiB reserved in total by PyTorch)

Is this the storing tensors without detaching them you mentioned?
thank you very much
and the code is my model forward:
image_size = [400,190] , block_nums = 8, num_classes=1000
        x = self.maxpool(F.leaky_relu(self.conv1_1(x)))
        x = self.maxpool(F.leaky_relu(self.conv2_1(x)))
        x = self.maxpool(F.leaky_relu(self.conv3_2(F.leaky_relu(self.conv3_1(x)))))
        x = self.maxpool(F.leaky_relu(self.conv4_2(F.leaky_relu(self.conv4_1(x)))))
        x = self.maxpool(F.leaky_relu(self.conv5_2(F.leaky_relu(self.conv5_1(x)))))
        x = self.dropout(x)
        x = x.view(x.size(0), 512 * 12 * 5)
        x = F.leaky_relu(self.fc1(x))
        x = F.leaky_relu(self.fc2(x))
        x = x.reshape(x.size(0),-1, int(self.image_size[0]/2), int(self.image_size[1]/2))
        # print('x:',x.size())
        '''
        
        x = self.res1(x)
        out = self.res2(x)
        out = self.res3(out)
        out = out + x
        out = self.res4(out)
        # print('res4:',out.size())
        #shuffle
        # print(out.shape)
        out = self.shuffle(out)
        # print(out.shape)
        # print('shuffle:',out.size())
        out = self.res5(out)
        # print(out.shape)
        out = np.squeeze(out)
        # print(out.shape)
        return out