‘CUDA error: out of memory’ after some epochs

Hi, I am facing this error of CUDA out-of-memory error, I tried resolving it by reducing the batch size but still I am getting the same out-of-memory error after one epoch.
I am using Imagenet100 dataset having shape as [64, 3, 224, 224]
training script -

def train(args, model, device, train_loader, optimizer, epoch):
    for batch_idx, (data, target) in enumerate(train_loader):
        data, target = data.to(device), target.to(device)
        output = model(data)
        loss = F.nll_loss(output, target)
        if batch_idx % args.log_interval == 0:
            print('Train Epoch: {} [{}/{} ({:.0f}%)]\tLoss: {:.6f}\tt : {}'.format(
                epoch, batch_idx * len(data), len(train_loader.dataset),
                100. * batch_idx / len(train_loader), loss.item(), model.sensor.t))
            if args.dry_run:

model used -

class Net(nn.Module):
    def __init__(self):
        super(Net, self).__init__()
        self.convnext = models.convnext_tiny()
        self.fc1 = nn.Linear(1000, 100)

    def forward(self, x):
        x = self.convnext(x)
        x = self.fc1(x)
        output = F.log_softmax(x, dim=1)
        return output

The code doesn’t indicate any obvious error, but you could check if the memory usage increases in each iteration or where exactly the GPU runs out of memory.

I am running this in Colab and the GPU usage is around 6.9 GB. After one epoch I get the output as torch.cuda.OutOfMemoryError: CUDA out of memory. Tried to allocate 8.97 GiB (GPU 0; 14.75 GiB total capacity; 10.00 GiB already allocated;…