Repository: pytorch
Issue: ```torch.tensordot```: Internal assert failed
Labels: module: sparse,triaged

### 🐛 Describe the bug

Test code:
```python
import torch

temp_self = torch.randn([1,1,1,1], dtype=torch.float16)
self = temp_self.to_sparse(layout=torch.sparse_csr)

other = torch.randn([1,1,1,1], dtype=torch.float16)

torch.tensordot(self, other, ([0,0,0,0], [0,0,0,2]))
```

Error log:
```
/home/yonghyeon/pytorch_err_case_py/tensordot.py:4: UserWarning: Sparse CSR tensor support is in beta state. If you miss a functionality in the sparse tensor support, please submit a feature request to https://github.com/pytorch/pytorch/issues. (Triggered internally at /home/yonghyeon/pytorch/pytorch-asan/aten/src/ATen/SparseCsrTensorImpl.cpp:55.)
  self = temp_self.to_sparse(layout=torch.sparse_csr)
Traceback (most recent call last):
  File "/home/yonghyeon/pytorch_err_case_py/tensordot.py", line 8, in <module>
    torch.tensordot(self, other, ([0,0,0,0], [0,0,0,2]))
  File "/home/yonghyeon/pytorch/pytorch-asan/torch/functional.py", line 1208, in tensordot
    return _VF.tensordot(a, b, dims_a, dims_b)  # type: ignore[attr-defined]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: input_dim == 2 INTERNAL ASSERT FAILED at "/home/yonghyeon/pytorch/pytorch-asan/aten/src/ATen/native/sparse/SparseCsrTensorMath.cpp":1314, please report a bug to PyTorch.
```

Test code (c++):
```cpp
#include <torch/torch.h>

int main() {
  torch::TensorOptions toptions = torch::TensorOptions();
  toptions = toptions.dtype(torch::kFloat16);
  
  auto temp_self = torch::randn({1,1,1,1}, toptions);
  torch::Tensor self = temp_self.to_sparse(c10::Layout::SparseCsr);  

  torch::Tensor other = torch::randn({1,1,1,1}, toptions);

  at::tensordot(self, other, {0,0,0,0}, {0,0,0,2});

  return 0;
}
```

Error log:
```
[W SparseCsrTensorImpl.cpp:55] Warning: Sparse CSR tensor support is in beta state. If you miss a functionality in the sparse tensor support, please submit a feature request to https://github.com/pytorch/pytorch/issues. (function operator())
terminate called after throwing an instance of 'c10::Error'
  what():  input_dim == 2 INTERNAL ASSERT FAILED at "/home/yonghyeon/pytorch/pytorch-asan/aten/src/ATen/native/sparse/SparseCsrTensorMath.cpp":1314, please report a bug to PyTorch. 
Exception raised from reduce_sparse_csr_cpu_template at /home/yonghyeon/pytorch/pytorch-asan/aten/src/ATen/native/sparse/SparseCsrTensorMath.cpp:1314 (most recent call first):
frame #0: <unknown function> + 0x1e7a6e (0x7fb867910a6e in /home/yonghyeon/pytorch/pytorch-asan/build/lib/libc10.so)
frame #1: <unknown function> + 0x1e7a20 (0x7fb867910a20 in /home/yonghyeon/pytorch/pytorch-asan/build/lib/libc10.so)
frame #2: <unknown function> + 0x1e79b0 (0x7fb8679109b0 in /home/yonghyeon/pytorch/pytorch-asan/build/lib/libc10.so)
frame #3: <unknown function> + 0x1e7860 (0x7fb867910860 in /home/yonghyeon/pytorch/pytorch-asan/build/lib/libc10.so)
frame #4: <unknown function> + 0x1e9286 (0x7fb867912286 in /home/yonghyeon/pytorch/pytorch-asan/build/lib/libc10.so)
frame #5: c10::Error::Error(c10::SourceLocation, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >) + 0x1b7 (0x7fb86790e4d7 in /home/yonghyeon/pytorch/pytorch-asan/build/lib/libc10.so)
frame #6: c10::detail::torchCheckFail(char const*, char const*, unsigned int, char const*) + 0x259 (0x7fb867907ca9 in /home/yonghyeon/pytorch/pytorch-asan/build/lib/libc10.so)
frame #7: ./reproduce_tensordot() [0x40d34e]
frame #8: <unknown function> + 0x563b8ed (0x7fb86d14a8ed in /home/yonghyeon/pytorch/pytorch-asan/build/lib/libtorch_cpu.so)
frame #9: <unknown function> + 0x55c0f28 (0x7fb86d0cff28 in /home/yonghyeon/pytorch/pytorch-asan/build/lib/libtorch_cpu.so)
frame #10: <unknown function> + 0x55bede8 (0x7fb86d0cdde8 in /home/yonghyeon/pytorch/pytorch-asan/build/lib/libtorch_cpu.so)
frame #11: at::native::_sparse_csr_sum_cpu(at::Tensor const&, c10::ArrayRef<long>, bool, std::optional<c10::ScalarType>) + 0x483 (0x7fb86d0cc163 in /home/yonghyeon/pytorch/pytorch-asan/build/lib/libtorch_cpu.so)
frame #12: <unknown function> + 0xd051930 (0x7fb874b60930 in /home/yonghyeon/pytorch/pytorch-asan/build/lib/libtorch_cpu.so)
frame #13: <unknown function> + 0xd0529aa (0x7fb874b619aa in /home/yonghyeon/pytorch/pytorch-asan/build/lib/libtorch_cpu.so)
frame #14: <unknown function> + 0x7fa7709 (0x7fb86fab6709 in /home/yonghyeon/pytorch/pytorch-asan/build/lib/libtorch_cpu.so)
frame #15: at::_ops::_sparse_csr_sum_dim_dtype::call(at::Tensor const&, c10::ArrayRef<long>, bool, std::optional<c10::ScalarType>) + 0x1964 (0x7fb86f51d374 in /home/yonghyeon/pytorch/pytorch-asan/build/lib/libtorch_cpu.so)
frame #16: <unknown function> + 0x4ae6fa0 (0x7fb86c5f5fa0 in /home/yonghyeon/pytorch/pytorch-asan/build/lib/libtorch_cpu.so)
frame #17: at::native::sum_sparse_compressed(at::Tensor const&, c10::OptionalArrayRef<long>, bool, std::optional<c10::ScalarType>) + 0x544 (0x7fb86c5cb7b4 in /home/yonghyeon/pytorch/pytorch-asan/build/lib/libtorch_cpu.so)
frame #18: <unknown function> + 0xd040bfb (0x7fb874b4fbfb in /home/yonghyeon/pytorch/pytorch-asan/build/lib/libtorch_cpu.so)
frame #19: <unknown function> + 0xd041bab (0x7fb874b50bab in /home/yonghyeon/pytorch/pytorch-asan/build/lib/libtorch_cpu.so)
frame #20: <unknown function> + 0x7f7a8c0 (0x7fb86fa898c0 in /home/yonghyeon/pytorch/pytorch-asan/build/lib/libtorch_cpu.so)
frame #21: <unknown function> + 0x7f7a0b8 (0x7fb86fa890b8 in /home/yonghyeon/pytorch/pytorch-asan/build/lib/libtorch_cpu.so)
frame #22: at::_ops::sum_dim_IntList::redispatch(c10::DispatchKeySet, at::Tensor const&, c10::OptionalArrayRef<long>, bool, std::optional<c10::ScalarType>) + 0xa40 (0x7fb86f860ae0 in /home/yonghyeon/pytorch/pytorch-asan/build/lib/libtorch_cpu.so)
frame #23: <unknown function> + 0x1244d7d8 (0x7fb879f5c7d8 in /home/yonghyeon/pytorch/pytorch-asan/build/lib/libtorch_cpu.so)
frame #24: <unknown function> + 0x124054d6 (0x7fb879f144d6 in /home/yonghyeon/pytorch/pytorch-asan/build/lib/libtorch_cpu.so)
frame #25: <unknown function> + 0x12403f36 (0x7fb879f12f36 in /home/yonghyeon/pytorch/pytorch-asan/build/lib/libtorch_cpu.so)
frame #26: <unknown function> + 0x1240643b (0x7fb879f1543b in /home/yonghyeon/pytorch/pytorch-asan/build/lib/libtorch_cpu.so)
frame #27: <unknown function> + 0x7f7a8c0 (0x7fb86fa898c0 in /home/yonghyeon/pytorch/pytorch-asan/build/lib/libtorch_cpu.so)
frame #28: at::_ops::sum_dim_IntList::call(at::Tensor const&, c10::OptionalArrayRef<long>, bool, std::optional<c10::ScalarType>) + 0x17dd (0x7fb86f4e677d in /home/yonghyeon/pytorch/pytorch-asan/build/lib/libtorch_cpu.so)
frame #29: <unknown function> + 0x2d42dab (0x7fb86a851dab in /home/yonghyeon/pytorch/pytorch-asan/build/lib/libtorch_cpu.so)
frame #30: at::native::tensordot(at::Tensor const&, at::Tensor const&, c10::ArrayRef<long>, c10::ArrayRef<long>) + 0xe40 (0x7fb86bf821a0 in /home/yonghyeon/pytorch/pytorch-asan/build/lib/libtorch_cpu.so)
frame #31: <unknown function> + 0xb2893f5 (0x7fb872d983f5 in /home/yonghyeon/pytorch/pytorch-asan/build/lib/libtorch_cpu.so)
frame #32: <unknown function> + 0xb28a0fe (0x7fb872d990fe in /home/yonghyeon/pytorch/pytorch-asan/build/lib/libtorch_cpu.so)
frame #33: <unknown function> + 0x7387a58 (0x7fb86ee96a58 in /home/yonghyeon/pytorch/pytorch-asan/build/lib/libtorch_cpu.so)
frame #34: at::_ops::tensordot::call(at::Tensor const&, at::Tensor const&, c10::ArrayRef<long>, c10::ArrayRef<long>) + 0x1120 (0x7fb86e9b2b30 in /home/yonghyeon/pytorch/pytorch-asan/build/lib/libtorch_cpu.so)
frame #35: ./reproduce_tensordot() [0x407b85]
frame #36: main + 0xd3c (0x40524c in ./reproduce_tensordot)
frame #37: <unknown function> + 0x29d90 (0x7fb85de4cd90 in /lib/x86_64-linux-gnu/libc.so.6)
frame #38: __libc_start_main + 0x80 (0x7fb85de4ce40 in /lib/x86_64-linux-gnu/libc.so.6)
frame #39: _start + 0x25 (0x404445 in ./reproduce_tensordot)

Aborted (core dumped)
```

### Versions

PyTorch version: 2.3.0a0+git03969cb
Is debug build: True
CUDA used to build PyTorch: None
ROCM used to build PyTorch: N/A

OS: Ubuntu 22.04.2 LTS (x86_64)
GCC version: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
Clang version: 12.0.1
CMake version: version 3.26.4
Libc version: glibc-2.35

Python version: 3.12.0 | packaged by Anaconda, Inc. | (main, Oct  2 2023, 17:29:18) [GCC 11.2.0] (64-bit runtime)
Python platform: Linux-5.15.0-89-generic-x86_64-with-glibc2.35
Is CUDA available: False
CUDA runtime version: No CUDA
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

CPU:
Architecture:                       x86_64
CPU op-mode(s):                     32-bit, 64-bit
Address sizes:                      46 bits physical, 48 bits virtual
Byte Order:                         Little Endian
CPU(s):                             96
On-line CPU(s) list:                0-95
Vendor ID:                          GenuineIntel
Model name:                         Intel(R) Xeon(R) Gold 6248R CPU @ 3.00GHz
CPU family:                         6
Model:                              85
Thread(s) per core:                 2
Core(s) per socket:                 24
Socket(s):                          2
Stepping:                           7
CPU max MHz:                        4000.0000
CPU min MHz:                        1200.0000
BogoMIPS:                           6000.00
Flags:                              fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb cat_l3 cdp_l3 invpcid_single intel_ppin ssbd mba ibrs ibpb stibp ibrs_enhanced tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid cqm mpx rdt_a avx512f avx512dq rdseed adx smap clflushopt clwb intel_pt avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local dtherm ida arat pln pts pku ospke avx512_vnni md_clear flush_l1d arch_capabilities
Virtualization:                     VT-x
L1d cache:                          1.5 MiB (48 instances)
L1i cache:                          1.5 MiB (48 instances)
L2 cache:                           48 MiB (48 instances)
L3 cache:                           71.5 MiB (2 instances)
NUMA node(s):                       2
NUMA node0 CPU(s):                  0-23,48-71
NUMA node1 CPU(s):                  24-47,72-95
Vulnerability Gather data sampling: Mitigation; Microcode
Vulnerability Itlb multihit:        KVM: Mitigation: VMX disabled
Vulnerability L1tf:                 Not affected
Vulnerability Mds:                  Not affected
Vulnerability Meltdown:             Not affected
Vulnerability Mmio stale data:      Mitigation; Clear CPU buffers; SMT vulnerable
Vulnerability Retbleed:             Mitigation; Enhanced IBRS
Vulnerability Spec rstack overflow: Not affected
Vulnerability Spec store bypass:    Mitigation; Speculative Store Bypass disabled via prctl and seccomp
Vulnerability Spectre v1:           Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2:           Mitigation; Enhanced IBRS, IBPB conditional, RSB filling, PBRSB-eIBRS SW sequence
Vulnerability Srbds:                Not affected
Vulnerability Tsx async abort:      Mitigation; TSX disabled

Versions of relevant libraries:
[pip3] numpy==1.26.2
[pip3] optree==0.10.0
[pip3] torch==2.3.0a0+git03969cb
[conda] mkl                       2023.1.0         h213fc3f_46344  
[conda] mkl-include               2023.1.0         h06a4308_46344  
[conda] numpy                     1.26.2                   pypi_0    pypi
[conda] optree                    0.10.0                   pypi_0    pypi
[conda] torch                     2.3.0a0+git03969cb           dev_0    <develop>

cc @alexsamardzic @nikitaved @pearu @cpuhrsch @amjames @bhosmer @jcaip