Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overflow when unpacking long - Pytorch

I am running the following code

import torch
from __future__ import print_function
x = torch.empty(5, 3)
print(x)

on an Ubuntu machine in CPU mode, which gives me following error, what would be the reason and how to fix

      x = torch.empty(5, 3)
----> print(x)

/usr/local/lib/python3.6/dist-packages/torch/tensor.py in __repr__(self)
     55         # characters to replace unicode characters with.
     56         if sys.version_info > (3,):
---> 57             return torch._tensor_str._str(self)
     58         else:
     59             if hasattr(sys.stdout, 'encoding'):

/usr/local/lib/python3.6/dist-packages/torch/_tensor_str.py in _str(self)
    216             suffix = ', dtype=' + str(self.dtype) + suffix
    217 
--> 218         fmt, scale, sz = _number_format(self)
    219         if scale != 1:
    220             prefix = prefix + SCALE_FORMAT.format(scale) + ' ' * indent

/usr/local/lib/python3.6/dist-packages/torch/_tensor_str.py in _number_format(tensor, min_sz)
     94     # TODO: use fmod?
     95     for value in tensor:
---> 96         if value != math.ceil(value.item()):
     97             int_mode = False
     98             break

RuntimeError: Overflow when unpacking long
like image 963
Jibin Mathew Avatar asked May 31 '18 06:05

Jibin Mathew


1 Answers

Since, torch.empty() gives uninitialized memory, so you may or may not get a large value from it. Try

x = torch.rand(5, 3)
print(x)

this would give the response.

like image 198
Jibin Mathew Avatar answered Oct 13 '22 20:10

Jibin Mathew