Long vs Flatten

I’m evaluating the performance of my model using the cross-entropy loss. I flatten my target variables using flatten construct from torch to get a [x,1] tensor object. I received a Runtime Error: Expected object of scalar type Long by got a scalar type Int for argument #2 target.

I was able to fix using the scalar type long. I still don’t understand why it didn’t work since borth functions produce the same shape? What’s the difference betweeen Long vs Flatten in Pytorch?

Calling tensor.long() returns a LongTensor, which is the tensor data type.
The error message explains, that you are passing an IntTensor instead of a LongTensor.
The data type is independent of the tensor shape.

1 Like

I was able to address the error, but didn’t know the difference between the two types. From what I was able to gather a LongTensor is a 64bit integer vs an IntTensor is a 32bit integer. Did i miss anything else?

Your understanding is correct. :slight_smile:

1 Like