Well, what’s your GPU memory consumption is reported before you run this function? (nvidia-smi, or whatever other reporting tool do you use)
If it’s the first call, then you should have 100% GPU available before you do that call. I assume you’re with your own GPU card.
If you use some kind of online service, then it’s a different story.
If you start with GPU RAM already used up you should kill the previous processes if they didn’t quit.
Alternatively, it’s possible that you have 100% GPU RAM available but your very first variable is already bigger than the available GPU RAM.
It’s just very hard to diagnose your issue w/o you telling the full story - setup, size of GPU, local/online, etc.
In any case add some code to measure available RAM at the beginning of your code and an assert for it to bail if it can’t detect a sufficient amount of GPU RAM available, telling you to clean up any run-away processes if any.