Solved by shawnbzhang in post #2 
              
              
                So I found out why this error was occurring. It was because earlier in my code, I had the following line: 
torch.set_default_tensor_type('torch.cuda.FloatTensor')