Your assumption sounds reasonable, since the first backward call will use additional memory to store the gradients.
You could reduce the batch size and rerun it or alternatively you could also trade compute for memory via torch.utils.checkpoint.
The malloc stack trace points again to the CUDACachingAllocator, so you can ignore this message, as the RuntimeError was already raised.