Conversion to DoubleTensor on print?

Does PyTorch convert all tensors to DoubleTensors on print? I created a tensor of size (4000, 259200) and type ByteTensor, and while I have it sitting in memory alright, when I try to print it, it throws the error you can see below. I’m using Ubuntu 16.04 and PyTorch 0.2.0.post3. My machine has ~8GB RAM and the same for swap. To replicate, use the following:

import torch
X = torch.zeros((4000, 259200)).type(torch.ByteTensor)
print(X)

ERROR BELOW

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
~/venvs_class/vision_class/lib/python3.5/site-packages/IPython/core/formatters.py in __call__(self, obj)
    700                 type_pprinters=self.type_printers,
    701                 deferred_pprinters=self.deferred_printers)
--> 702             printer.pretty(obj)
    703             printer.flush()
    704             return stream.getvalue()

~/venvs_class/vision_class/lib/python3.5/site-packages/IPython/lib/pretty.py in pretty(self, obj)
    393                             if callable(meth):
    394                                 return meth(obj, self, cycle)
--> 395             return _default_pprint(obj, self, cycle)
    396         finally:
    397             self.end_group()

~/venvs_class/vision_class/lib/python3.5/site-packages/IPython/lib/pretty.py in _default_pprint(obj, p, cycle)
    508     if _safe_getattr(klass, '__repr__', None) is not object.__repr__:
    509         # A user-provided repr. Find newlines and replace them with p.break_()
--> 510         _repr_pprint(obj, p, cycle)
    511         return
    512     p.begin_group(1, '<')

~/venvs_class/vision_class/lib/python3.5/site-packages/IPython/lib/pretty.py in _repr_pprint(obj, p, cycle)
    699     """A pprint that just redirects to the normal repr function."""
    700     # Find newlines and replace them with p.break_()
--> 701     output = repr(obj)
    702     for idx,output_line in enumerate(output.splitlines()):
    703         if idx:

~/venvs_class/vision_class/lib/python3.5/site-packages/torch/tensor.py in __repr__(self)
    131 
    132     def __repr__(self):
--> 133         return str(self)
    134 
    135     def __str__(self):

~/venvs_class/vision_class/lib/python3.5/site-packages/torch/tensor.py in __str__(self)
    138         # characters to replace unicode characters with.
    139         if sys.version_info > (3,):
--> 140             return _tensor_str._str(self)
    141         else:
    142             if hasattr(sys.stdout, 'encoding'):

~/venvs_class/vision_class/lib/python3.5/site-packages/torch/_tensor_str.py in _str(self)
    286         strt = _vector_str(self)
    287     elif self.ndimension() == 2:
--> 288         strt = _matrix_str(self)
    289     else:
    290         strt = _tensor_str(self)

~/venvs_class/vision_class/lib/python3.5/site-packages/torch/_tensor_str.py in _matrix_str(self, indent, formatter, force_truncate)
    205     if formatter is None:
    206         fmt, scale, sz = _number_format(self,
--> 207                                         min_sz=5 if not print_full_mat else 0)
    208     else:
    209         fmt, scale, sz = formatter

~/venvs_class/vision_class/lib/python3.5/site-packages/torch/_tensor_str.py in _number_format(tensor, min_sz)
     68 def _number_format(tensor, min_sz=-1):
     69     min_sz = max(min_sz, 2)
---> 70     tensor = torch.DoubleTensor(tensor.size()).copy_(tensor).abs_().view(tensor.nelement())
     71 
     72     pos_inf_mask = tensor.eq(float('inf'))

RuntimeError: $ Torch: not enough memory: you tried to allocate 7GB. Buy new RAM! at /pytorch/torch/lib/TH/THGeneral.c:270

It seems so…
Temporary Solution: Don’t print it :sweat: