Solved by ptrblck in post #2 
              
              
                You could replace it with x.sum().data[0]. 
The probably better approach would be to port the code to the latest PyTorch version, as you might encounter already solved bugs etc.