i see this exception mentioned in some older and more exotic contexts but this is as straight-forward as it gets:
import torch
for package in [torch]:
print(package.__name__, package.__version__)
tstList = [10,20,30,40,50]
tstTensor = torch.tensor(tstList)
print('tst',type(tstTensor),tstTensor)
tstLongTensor = torch.tensor(tstList,dtype=torch.int64)
print('long',type(tstLongTensor),tstLongTensor)
tstLng2Tensor = torch.tensor(tstList).type(torch.int64)
print('long2',type(tstLng2Tensor),tstLng2Tensor)
indexedTst = [10239237003504588839, 9921686513378912864, 11901859001352538922, 4316640507316845735, 7162342725099726394, 17494803046312582752]
idxTensor = torch.tensor(indexedTst)
print('idx',type(idxTensor),idxTensor)
works fine until it’s given long ints:
torch 2.3.0
tst <class 'torch.Tensor'> tensor([10, 20, 30, 40, 50])
long <class 'torch.Tensor'> tensor([10, 20, 30, 40, 50])
long2 <class 'torch.Tensor'> tensor([10, 20, 30, 40, 50])
Traceback (most recent call last):
File ".../tstTensor.py", line 33, in <module>
main()
File ".../tstTensor.py", line 29, in main
idxTensor = torch.tensor(indexedTst)
^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: Overflow when unpacking long
version info:
- Python 3.11.9 (main, Apr 19 2024, 11:43:47) [Clang 14.0.6 ] on darwin
- same exception using device=
cpu
ormps