KEMBAR78
Cannot construct `torch.sparse_coo_tensor` (but `scipy.sparse.coo_matrix` works fine): `TypeError: only integer tensors of a single element can be converted to an index` · Issue #109108 · pytorch/pytorch · GitHub
Skip to content

Cannot construct torch.sparse_coo_tensor (but scipy.sparse.coo_matrix works fine): TypeError: only integer tensors of a single element can be converted to an index #109108

@vadimkantorov

Description

@vadimkantorov

🐛 Describe the bug

Also, note the strange warning when using weights_only=True.
bug.pt.gz

import gzip
import torch
import scipy

bug = torch.load(gzip.open('bug.pt.gz', 'rb'), weights_only=True)
#  /home/vadimkantorov/.local/lib/python3.8/site-packages/torch/_utils.py:841: UserWarning: TypedStorage is deprecated. It will be removed in the future and UntypedStorage will be the only storage class. This should only matter to you if you are using storages directly.  To access UntypedStorage directly, use tensor.untyped_storage() instead of tensor.storage()
#  return self.fget.__get__(instance, owner)()

scipy.sparse.coo_matrix((bug['values'], (bug['rowinds'], bug['colinds'])), shape=bug['shape'])
# ok

torch.sparse_coo_tensor((bug['rowinds'], bug['colinds']), bug['values'], size=bug['shape'])
# TypeError: only integer tensors of a single element can be converted to an index

Same error appears in #43949 in a completely different context. This error is extremely mysterious and weird.

Versions

2.1.0.dev20230802+cpu

cc @alexsamardzic @nikitaved @pearu @cpuhrsch @amjames @bhosmer

Metadata

Metadata

Assignees

No one assigned

    Labels

    module: scipy compatibilitymodule: sparseRelated to torch.sparsetriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions