拆包时溢出 - Pytorch

Jib*_*hew 8 python-3.x deep-learning pytorch

我正在运行以下代码

import torch
from __future__ import print_function
x = torch.empty(5, 3)
print(x)
Run Code Online (Sandbox Code Playgroud)

在CPU模式下的Ubuntu机器上,它给我跟随错误,原因是什么以及如何修复

      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
Run Code Online (Sandbox Code Playgroud)

Jib*_*hew 5

由于 torch.empty() 提供了未初始化的内存,因此您可能会也可能不会从中获得很大的价值。尝试

x = torch.rand(5, 3)
print(x)
Run Code Online (Sandbox Code Playgroud)

这将给出响应。