Skip to content

torch.quantize_per_tensor not implemented for SparseCPU tensors #160631

@springcrane

Description

@springcrane

🐛 Describe the bug

torch.quantize_per_tensor() fails when applied to a sparse COO tensor. The operator aten::quantize_per_tensor is not implemented for the SparseCPU backend, preventing quantization of sparse tensors on CPU.
import torch

Create a sparse tensor

indices = torch.tensor([[0, 1, 2], [2, 0, 1]])
values = torch.tensor([3, 4, 5], dtype=torch.float32)
sparse_tensor = torch.sparse_coo_tensor(indices, values, size=(3, 3))

Attempt to quantize it

quant_sparse = torch.quantize_per_tensor(sparse_tensor, scale=1.0, zero_point=0, dtype=torch.quint8)

Versions

NotImplementedError: Could not run 'aten::quantize_per_tensor' with arguments from the 'SparseCPU' backend.
'aten::quantize_per_tensor' is only available for these backends: [CPU, CUDA, Meta, BackendSelect, ...]

cc @alexsamardzic @nikitaved @pearu @cpuhrsch @amjames @bhosmer @jcaip @jerryzh168 @jianyuh @raghuramank100 @jamesr66a @vkuzo @jgong5 @Xia-Weiwen @leslie-fang-intel @msaroufim

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions