Repository: pytorch
Issue: torch.equal does not support sparse tensors
Labels: module: sparse,triaged

## 🐛 Bug

torch.equal(input,other) does not support sparse tensors.

## To Reproduce

```python
if __name__ == "__main__":
    x = torch.rand(4, 4).to_sparse()
    assert torch.equal(x, x)
```

```
Traceback (most recent call last):
  File "benchmarks/distributed/rpc/parameter_server/test.py", line 82, in <module>
    assert torch.equal(x, y)
NotImplementedError: Could not run 'aten::equal' with arguments from the 'SparseCPU' 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 https://fburl.com/ptmfixes for possible resolutions. 'aten::equal' is only available for these backends: [CPU, CUDA, QuantizedCPU, BackendSelect, Python, Named, Conjugate, Negative, ADInplaceOrView, AutogradOther, AutogradCPU, AutogradCUDA, AutogradXLA, AutogradLazy, AutogradXPU, AutogradMLC, AutogradHPU, AutogradNestedTensor, AutogradPrivateUse1, AutogradPrivateUse2, AutogradPrivateUse3, Tracer, UNKNOWN_TENSOR_TYPE_ID, Autocast, Batched, VmapMode].

CPU: registered at /fsx/users/gcramer/work/pytorch/build/aten/src/ATen/RegisterCPU.cpp:22545 [kernel]
CUDA: registered at /fsx/users/gcramer/work/pytorch/build/aten/src/ATen/RegisterCUDA.cpp:30514 [kernel]
QuantizedCPU: registered at /fsx/users/gcramer/work/pytorch/build/aten/src/ATen/RegisterQuantizedCPU.cpp:1060 [kernel]
BackendSelect: fallthrough registered at /fsx/users/gcramer/work/pytorch/aten/src/ATen/core/BackendSelectFallbackKernel.cpp:3 [backend fallback]
Python: registered at /fsx/users/gcramer/work/pytorch/aten/src/ATen/core/PythonFallbackKernel.cpp:38 [backend fallback]
Named: fallthrough registered at /fsx/users/gcramer/work/pytorch/aten/src/ATen/core/NamedRegistrations.cpp:11 [kernel]
Conjugate: registered at /fsx/users/gcramer/work/pytorch/aten/src/ATen/ConjugateFallback.cpp:26 [backend fallback]
Negative: registered at /fsx/users/gcramer/work/pytorch/aten/src/ATen/native/NegateFallback.cpp:26 [backend fallback]
ADInplaceOrView: fallthrough registered at /fsx/users/gcramer/work/pytorch/aten/src/ATen/core/VariableFallbackKernel.cpp:64 [backend fallback]
AutogradOther: registered at /fsx/users/gcramer/work/pytorch/torch/csrc/autograd/generated/VariableType_3.cpp:12635 [autograd kernel]
AutogradCPU: registered at /fsx/users/gcramer/work/pytorch/torch/csrc/autograd/generated/VariableType_3.cpp:12635 [autograd kernel]
AutogradCUDA: registered at /fsx/users/gcramer/work/pytorch/torch/csrc/autograd/generated/VariableType_3.cpp:12635 [autograd kernel]
AutogradXLA: registered at /fsx/users/gcramer/work/pytorch/torch/csrc/autograd/generated/VariableType_3.cpp:12635 [autograd kernel]
AutogradLazy: registered at /fsx/users/gcramer/work/pytorch/torch/csrc/autograd/generated/VariableType_3.cpp:12635 [autograd kernel]
AutogradXPU: registered at /fsx/users/gcramer/work/pytorch/torch/csrc/autograd/generated/VariableType_3.cpp:12635 [autograd kernel]
AutogradMLC: registered at /fsx/users/gcramer/work/pytorch/torch/csrc/autograd/generated/VariableType_3.cpp:12635 [autograd kernel]
AutogradHPU: registered at /fsx/users/gcramer/work/pytorch/torch/csrc/autograd/generated/VariableType_3.cpp:12635 [autograd kernel]
AutogradNestedTensor: registered at /fsx/users/gcramer/work/pytorch/torch/csrc/autograd/generated/VariableType_3.cpp:12635 [autograd kernel]
AutogradPrivateUse1: registered at /fsx/users/gcramer/work/pytorch/torch/csrc/autograd/generated/VariableType_3.cpp:12635 [autograd kernel]
AutogradPrivateUse2: registered at /fsx/users/gcramer/work/pytorch/torch/csrc/autograd/generated/VariableType_3.cpp:12635 [autograd kernel]
AutogradPrivateUse3: registered at /fsx/users/gcramer/work/pytorch/torch/csrc/autograd/generated/VariableType_3.cpp:12635 [autograd kernel]
Tracer: registered at /fsx/users/gcramer/work/pytorch/torch/csrc/autograd/generated/TraceType_3.cpp:11391 [kernel]
UNKNOWN_TENSOR_TYPE_ID: fallthrough registered at /fsx/users/gcramer/work/pytorch/aten/src/ATen/autocast_mode.cpp:455 [backend fallback]
Autocast: fallthrough registered at /fsx/users/gcramer/work/pytorch/aten/src/ATen/autocast_mode.cpp:294 [backend fallback]
Batched: registered at /fsx/users/gcramer/work/pytorch/aten/src/ATen/BatchingRegistrations.cpp:1016 [backend fallback]
VmapMode: fallthrough registered at /fsx/users/gcramer/work/pytorch/aten/src/ATen/VmapModeRegistrations.cpp:33 [backend fallback]
```

```python
if __name__ == "__main__":
    x = torch.rand(4, 4).to_sparse_csr()
    assert torch.equal(x, x)
```

```
Traceback (most recent call last):
  File "test.py", line 81, in <module>
    assert torch.equal(x, x)
NotImplementedError: Could not run 'aten::equal' 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 https://fburl.com/ptmfixes for possible resolutions. 'aten::equal' is only available for these backends: [CPU, CUDA, QuantizedCPU, BackendSelect, Python, Named, Conjugate, Negative, ADInplaceOrView, AutogradOther, AutogradCPU, AutogradCUDA, AutogradXLA, AutogradLazy, AutogradXPU, AutogradMLC, AutogradHPU, AutogradNestedTensor, AutogradPrivateUse1, AutogradPrivateUse2, AutogradPrivateUse3, Tracer, UNKNOWN_TENSOR_TYPE_ID, Autocast, Batched, VmapMode].

CPU: registered at /fsx/users/gcramer/work/pytorch/build/aten/src/ATen/RegisterCPU.cpp:22545 [kernel]
CUDA: registered at /fsx/users/gcramer/work/pytorch/build/aten/src/ATen/RegisterCUDA.cpp:30514 [kernel]
QuantizedCPU: registered at /fsx/users/gcramer/work/pytorch/build/aten/src/ATen/RegisterQuantizedCPU.cpp:1060 [kernel]
BackendSelect: fallthrough registered at /fsx/users/gcramer/work/pytorch/aten/src/ATen/core/BackendSelectFallbackKernel.cpp:3 [backend fallback]
Python: registered at /fsx/users/gcramer/work/pytorch/aten/src/ATen/core/PythonFallbackKernel.cpp:38 [backend fallback]
Named: fallthrough registered at /fsx/users/gcramer/work/pytorch/aten/src/ATen/core/NamedRegistrations.cpp:11 [kernel]
Conjugate: registered at /fsx/users/gcramer/work/pytorch/aten/src/ATen/ConjugateFallback.cpp:26 [backend fallback]
Negative: registered at /fsx/users/gcramer/work/pytorch/aten/src/ATen/native/NegateFallback.cpp:26 [backend fallback]
ADInplaceOrView: fallthrough registered at /fsx/users/gcramer/work/pytorch/aten/src/ATen/core/VariableFallbackKernel.cpp:64 [backend fallback]
AutogradOther: registered at /fsx/users/gcramer/work/pytorch/torch/csrc/autograd/generated/VariableType_3.cpp:12635 [autograd kernel]
AutogradCPU: registered at /fsx/users/gcramer/work/pytorch/torch/csrc/autograd/generated/VariableType_3.cpp:12635 [autograd kernel]
AutogradCUDA: registered at /fsx/users/gcramer/work/pytorch/torch/csrc/autograd/generated/VariableType_3.cpp:12635 [autograd kernel]
AutogradXLA: registered at /fsx/users/gcramer/work/pytorch/torch/csrc/autograd/generated/VariableType_3.cpp:12635 [autograd kernel]
AutogradLazy: registered at /fsx/users/gcramer/work/pytorch/torch/csrc/autograd/generated/VariableType_3.cpp:12635 [autograd kernel]
AutogradXPU: registered at /fsx/users/gcramer/work/pytorch/torch/csrc/autograd/generated/VariableType_3.cpp:12635 [autograd kernel]
AutogradMLC: registered at /fsx/users/gcramer/work/pytorch/torch/csrc/autograd/generated/VariableType_3.cpp:12635 [autograd kernel]
AutogradHPU: registered at /fsx/users/gcramer/work/pytorch/torch/csrc/autograd/generated/VariableType_3.cpp:12635 [autograd kernel]
AutogradNestedTensor: registered at /fsx/users/gcramer/work/pytorch/torch/csrc/autograd/generated/VariableType_3.cpp:12635 [autograd kernel]
AutogradPrivateUse1: registered at /fsx/users/gcramer/work/pytorch/torch/csrc/autograd/generated/VariableType_3.cpp:12635 [autograd kernel]
AutogradPrivateUse2: registered at /fsx/users/gcramer/work/pytorch/torch/csrc/autograd/generated/VariableType_3.cpp:12635 [autograd kernel]
AutogradPrivateUse3: registered at /fsx/users/gcramer/work/pytorch/torch/csrc/autograd/generated/VariableType_3.cpp:12635 [autograd kernel]
Tracer: registered at /fsx/users/gcramer/work/pytorch/torch/csrc/autograd/generated/TraceType_3.cpp:11391 [kernel]
UNKNOWN_TENSOR_TYPE_ID: fallthrough registered at /fsx/users/gcramer/work/pytorch/aten/src/ATen/autocast_mode.cpp:455 [backend fallback]
Autocast: fallthrough registered at /fsx/users/gcramer/work/pytorch/aten/src/ATen/autocast_mode.cpp:294 [backend fallback]
Batched: registered at /fsx/users/gcramer/work/pytorch/aten/src/ATen/BatchingRegistrations.cpp:1016 [backend fallback]
VmapMode: fallthrough registered at /fsx/users/gcramer/work/pytorch/aten/src/ATen/VmapModeRegistrations.cpp:33 [backend fallback]
```

## Expected behavior

torch.equal(input, other) evaluates the sparse tensors and returns a result.

## Environment

```
Collecting environment information...
PyTorch version: 1.10.0a0+git6f899c1
Is debug build: False
CUDA used to build PyTorch: 11.1
ROCM used to build PyTorch: N/A

OS: Ubuntu 18.04.5 LTS (x86_64)
GCC version: (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
Clang version: Could not collect
CMake version: version 3.21.1

Python version: 3.6 (64-bit runtime)
Is CUDA available: True
CUDA runtime version: 11.1.105
GPU models and configuration: 
GPU 0: A100-SXM4-40GB
GPU 1: A100-SXM4-40GB
GPU 2: A100-SXM4-40GB
GPU 3: A100-SXM4-40GB
GPU 4: A100-SXM4-40GB
GPU 5: A100-SXM4-40GB
GPU 6: A100-SXM4-40GB
GPU 7: A100-SXM4-40GB

Nvidia driver version: 450.119.03
cuDNN version: Probably one of the following:
/usr/local/cuda-10.1/targets/x86_64-linux/lib/libcudnn.so.7.6.5
/usr/local/cuda-10.2/targets/x86_64-linux/lib/libcudnn.so.7.6.5
/usr/local/cuda-11.0/targets/x86_64-linux/lib/libcudnn.so.8.0.5
/usr/local/cuda-11.0/targets/x86_64-linux/lib/libcudnn_adv_infer.so.8.0.5
/usr/local/cuda-11.0/targets/x86_64-linux/lib/libcudnn_adv_train.so.8.0.5
/usr/local/cuda-11.0/targets/x86_64-linux/lib/libcudnn_cnn_infer.so.8.0.5
/usr/local/cuda-11.0/targets/x86_64-linux/lib/libcudnn_cnn_train.so.8.0.5
/usr/local/cuda-11.0/targets/x86_64-linux/lib/libcudnn_ops_infer.so.8.0.5
/usr/local/cuda-11.0/targets/x86_64-linux/lib/libcudnn_ops_train.so.8.0.5
/usr/local/cuda-11.1/targets/x86_64-linux/lib/libcudnn.so.8.0.5
/usr/local/cuda-11.1/targets/x86_64-linux/lib/libcudnn_adv_infer.so.8.0.5
/usr/local/cuda-11.1/targets/x86_64-linux/lib/libcudnn_adv_train.so.8.0.5
/usr/local/cuda-11.1/targets/x86_64-linux/lib/libcudnn_cnn_infer.so.8.0.5
/usr/local/cuda-11.1/targets/x86_64-linux/lib/libcudnn_cnn_train.so.8.0.5
/usr/local/cuda-11.1/targets/x86_64-linux/lib/libcudnn_ops_infer.so.8.0.5
/usr/local/cuda-11.1/targets/x86_64-linux/lib/libcudnn_ops_train.so.8.0.5
HIP runtime version: N/A
MIOpen runtime version: N/A
```

## Additional context

<!-- Add any other context about the problem here. -->


cc @nikitaved @pearu @cpuhrsch @IvanYashchuk