Ho actually the stack trace points to ToDenseBackward indeed. So the .to_dense() might be the issue here.
But as mentioned above, the backward for sparse Tensor is not well supported I’m afraid.
You can try to do to_dense().clone().sum(1)    ?