Skip to content

[Feature] Sparse tensor persistence/save. #16667

@sebftw

Description

@sebftw

🚀 Feature

I want to be able to save a model with sparse tensors.

Motivation

I have a module where one of the parameters may be sparse. (It is an option)
All of the parameters are stored with register_buffer, so they are present in the state dict. But when one of them are sparse it cannot be saved to disk.
It throws the error RuntimeError: sparse tensors do not have storage for example simply on torch.save(torch.sparse.FloatTensor(), 'sparse.pt').

Pitch

It would be nice if the sparse matrices worked interchangeably with the dense counterparts.
torch.save(torch.sparse.FloatTensor(), 'sparse.pt') should just store the tensor.

Alternatives

Alternatively a quick fix would be to simply convert the tensor to dense and then store that.

Metadata

Metadata

Assignees

Labels

featureA request for a proper, new feature.high prioritymodule: 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