Could not run 'aten::zero_' with arguments from the 'SparseCsrCPU' backend.

When applying backward method on loss loss.backward(), I get the error:

--> 363 torch.autograd.backward(self, gradient, retain_graph, create_graph, inputs=inputs)

File ~/miniconda3/lib/python3.9/site-packages/torch/autograd/, in backward(tensors, grad_tensors, retain_graph, create_graph, grad_variables, inputs)
    168     retain_graph = create_graph
    170 # The reason we repeat same the comment below is that
    171 # some Python versions print out the first line of a multi-line function
    172 # calls in the traceback and some print out the last line
--> 173 Variable._execution_engine.run_backward(  # Calls into the C++ engine to run the backward pass
    174     tensors, grad_tensors_, retain_graph, create_graph, inputs,
    175     allow_unreachable=True, accumulate_grad=True)

NotImplementedError: Could not run 'aten::zero_' with arguments from the 'SparseCsrCPU' backend. This could be because the operator doesn't exist for this backend, or was omitted during the selective/custom build process (if using custom build). If you are a Facebook employee using PyTorch on mobile, please visit for possible resolutions. 'aten::zero_' is only available for these backends: [CPU, Meta, MkldnnCPU, SparseCPU, BackendSelect, Python, Named, Conjugate, Negative, ZeroTensor, ADInplaceOrView, AutogradOther, AutogradCPU, AutogradCUDA, AutogradXLA, AutogradLazy, AutogradXPU, AutogradMLC, AutogradHPU, AutogradNestedTensor, AutogradPrivateUse1, AutogradPrivateUse2, AutogradPrivateUse3, Tracer, AutocastCPU, Autocast, Batched, VmapMode, Functionalize].

I understand that fed input data was not dense numpy array but sparse csr torch.sparse_csr_tensor(X.indptr, X.indices,, X.shape, dtype=torch.float32). Is this is an issue? Everything works except loss.backward().

Could you post a minimal, executable code snippet which would reproduce this issue, please?
I’m unsure if it’s a known limitation or if it’s a bug (and e.g. internally the tensor should be dense in the backward pass).