[Request Feature] Printing Tensor with size and location information

Hello I don’t know where I put this kind of suggestion, therefore I put it in “Uncategorized”. In many deep learning implementation we really need to concern about tensor size. We need to know the size of input, and the size of output for function. Therefore in pytorch version up to 0.3 when I called print function, pytorch will showing content and also size of the tensor. This is co convenient for me because I immediate know my tensor size, also the type of tensor, and content just for single print, no need to call tensor.size() anymore.
image

However in pytorch 0.4 I only get the content of the tensor. I need to use tensor.size again and again to debug my code. Here is the example of the print operation (*I use a different tensor).
image

In version 0.4 no information available, it just the content. Even I also don’t know my tensor type. However I am so appreciated for giving the tensor location information like GPU device.
image

The request feature for print function:

  • Print the size and type of tensor also not only the content.
  • Print the tensor location for example whether it is in GPU or CPU. If it is on GPU please tell us which device is the location.

This is just suggestion I really appreciate the consideration for adding this. This is so convenient for debugging in my opinion, because many people mistake lies on tensor size format like [batch, channel, height, width] and also most of them doing like this the training data is in GPU but the testing is in CPU. Another mistake like tensor type for example when doing temperature prediction most of the temperature is in float but maybe user forget to change their tensor into float type so the tensor still in integer type, by giving the type of tensor it will help much.

Keep up the good work, can’t wait to see Pytorch 1.0 :grinning:

-Thank you-

I think the former was a conscious decision because size used to show up in too many places where it isn’t useful. (Personally, I usually want to print either the size or the contents, but hardly ever both.) Also it’s easy to print both.
The latter is already there: no device annotation means CPU, device=cuda:xx means GPU. I’m not sure what you miss there.
dtype is implied if it is the default you would get from a constructor (with “.” means float, without long) or show dtype is show.

Best regards

Thomas

Hi @tom thank you for your reply. Yes I have stated in my post that I appreciate the feature for device location. My post is just a suggestion maybe many people have the other style, but for me by only use print command it will be more convenient because I just need 1 print function to know all information, beside printing type and dimension is just need 1 extra line in the print output. Thank you for your information about the dot “.” which means it is float, I just know about it -_- . I just hope that maybe next pytorch they add it all in print function however if many pytorch users want it seperated, I am still OK with it. It just about people coding style, but here I just suggest maybe if we print it in 1 function it will be more convenient in debugging for some people. :v:

What’s wrong with print(x, x.size())?

1 Like

@tom Nothing wrong it just taking longer time and boring to type it long for some peoples like me :joy: its faster for me to type print(x) rather than print(x, x.size(),x.type()) or for people not familiar with python they will type print for all of it like print(x), print(x.size()),print(x.type()) hahahaha :stuck_out_tongue_winking_eye: