OutOfMemoryError: CUDA out of memory with a gan

Hello, I have been trying to setup this gan but i cannot escape this error: error - Pastebin.com (sometimes it’s not the same line)

I have tried gc.collect but maybe i misplaced it. I also tried to have as little as possible things on the gpu in my training loop but nothing seems to work.

I code on a kaggle notebook.

here’s my code: View paste IVMQ

Is the suspicion that there is a leak?

Taking a memory trace (Understanding GPU Memory 1: Visualizing All Allocations over Time | PyTorch) can help confirm this + identify which tensor is being kept alive.