Repository: pytorch
Issue: RuntimeError: derivative for aten::_spdiags is not implemented
Labels: module: sparse,module: autograd,triaged

### 🚀 The feature, motivation and pitch

The backward for the torch.sparse.spdiags method does not seem to be implemented.
Do you have a fix that I can use in my networks?
Below is a typical sparse matrix that I am trying to use with the backward error. 


```python
import torch
from torch import nn

class Test(nn.Module):
    def __init__(self) -> None:
        super(Test,self).__init__()

        self.x_E_i = nn.Parameter(torch.Tensor(1,))
        self.N_time = 10
        self.init_parameters()

    def init_parameters(self):
        x_E_i_ini = torch.rand(self.x_E_i.shape)

    def forward(self,x):
        """"x shape : (btc)"""
        diags = torch.exp(-x/self.x_E_i)
        D1 = torch.sparse.spdiags(diags,offsets=torch.tensor([0]),shape=(diags.shape[0],diags.shape[0]))
        return D1.to_dense()

if __name__ == "__main__":
    x = torch.rand((10),requires_grad=True)
    tt = Test()

    y = tt(x)
    print(y.shape)
    check = torch.autograd.gradcheck(tt,x.double())
    print(check)
```



```
torch.Size([10, 10])
Traceback (most recent call last):
  File "TestPytorch.py", line 27, in <module>
    check = torch.autograd.gradcheck(tt,x.double())
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "anaconda3/envs/reinf/lib/python3.11/site-packages/torch/autograd/gradcheck.py", line 2051, in gradcheck
    return _gradcheck_helper(**args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "anaconda3/envs/reinf/lib/python3.11/site-packages/torch/autograd/gradcheck.py", line 2080, in _gradcheck_helper
    _gradcheck_real_imag(
  File "anaconda3/envs/reinf/lib/python3.11/site-packages/torch/autograd/gradcheck.py", line 1482, in _gradcheck_real_imag
    gradcheck_fn(
  File "anaconda3/envs/reinf/lib/python3.11/site-packages/torch/autograd/gradcheck.py", line 1617, in _slow_gradcheck
    analytical = _check_analytical_jacobian_attributes(
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "anaconda3/envs/reinf/lib/python3.11/site-packages/torch/autograd/gradcheck.py", line 768, in _check_analytical_jacobian_attributes
    vjps1 = _compute_analytical_jacobian_rows(vjp_fn, output.clone())
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "anaconda3/envs/reinf/lib/python3.11/site-packages/torch/autograd/gradcheck.py", line 884, in _compute_analytical_jacobian_rows
    grad_inputs = vjp_fn(grad_out_base)
                  ^^^^^^^^^^^^^^^^^^^^^
  File "anaconda3/envs/reinf/lib/python3.11/site-packages/torch/autograd/gradcheck.py", line 759, in vjp_fn
    return torch.autograd.grad(
           ^^^^^^^^^^^^^^^^^^^^
  File "anaconda3/envs/reinf/lib/python3.11/site-packages/torch/autograd/__init__.py", line 394, in grad
    result = Variable._execution_engine.run_backward(  # Calls into the C++ engine to run the backward pass
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: derivative for aten::_spdiags is not implemented
```

### Alternatives

_No response_

### Additional context

_No response_

cc @alexsamardzic @nikitaved @pearu @cpuhrsch @amjames @bhosmer @jcaip @ezyang @albanD @gqchen @soulitzer @Lezcano @Varal7