OK, I just realized what’s going on here. I misunderstood the code snippet you list in the original post. If you see an OOM, you create an empty tensor. This is why the error triggers. Instead of torch.ones(0), you’ll want to use torch.zeros(1).