Relative Content

Tag Archive for pytorch

torch.cuda.OutOfMemoryError when training model on GPU, but not for larger batch sizes on CPU

I am working on training a MultiModal model in PyTorch. I have a training loop which runs just fine (albeit slowly) on my CPU (I tested up to batch size = 32). However, when I try to run it on a GPU (Tesla P40), it only works up to batch size = 2. With larger batch sizes it throws a torch.cuda.OutOfMemoryError. I am working with pre embedded video and audio, and pre tokenized text. Is it possible that the GPU can really not handle batch sizes larger than 2 or could there be something wrong in my code? Do you have any advice on how I might go about troubleshooting? I apologize for this simple question, it is my first time working with a GPU cluster. I am running this code on my university’s GPU cluster and have double checked that the GPU I am using is not being used by anyone else.

Correct way to swap PyTorch tensors without copying

I have two PyTorch tensors x, y with the same dimensions. I would like to swap the data behind the two tensors, ideally without having to copy. The purpose of this is to have code elsewhere that holds onto the tensor x to now read & write the data y and vice-versa.