Repository: pytorch
Issue: Inconsistent behavior of torch.einsum on float32 and complex128
Labels: triaged,module: complex,module: linear algebra

### 🐛 Describe the bug

An einsum operation that can be done with a `dot` operation fails with float32 and complex128, while other operations work:

```python
import pytest, torch
a = torch.tensor([1, 1], dtype=torch.float32)
b = torch.tensor([1+1j, 1], dtype=torch.complex128)

torch.einsum('i,i->i', a, b)  # Returns a complex128 tensor
with pytest.raises(RuntimeError):
    torch.einsum('i,i->', a, b)  # Fails
```

I tried some more combinations and some work, while others don't work.
(Probably the combination of multiplication and summation on a shared dimension is the issue, i.e. something that can be done with `dot`)

I expected, that it either always fails or always works. In my case, the toy example was working, while the productive example failed.

### Versions

Collecting environment information...
PyTorch version: 2.1.2+cpu
Is debug build: False
CUDA used to build PyTorch: None
ROCM used to build PyTorch: N/A

OS: Ubuntu 20.04.6 LTS (x86_64)
GCC version: (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0
Clang version: Could not collect
CMake version: version 3.27.2
Libc version: glibc-2.31

Python version: 3.11.4 (main, Jul  5 2023, 13:45:01) [GCC 11.2.0] (64-bit runtime)
Python platform: Linux-5.4.0-166-generic-x86_64-with-glibc2.31
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:
Architektur:                        x86_64
CPU Operationsmodus:                32-bit, 64-bit
Byte-Reihenfolge:                   Little Endian
Adressgrößen:                       39 bits physical, 48 bits virtual
CPU(s):                             4
Liste der Online-CPU(s):            0-3
Thread(s) pro Kern:                 2
Kern(e) pro Socket:                 2
Sockel:                             1
NUMA-Knoten:                        1
Anbieterkennung:                    GenuineIntel
Prozessorfamilie:                   6
Modell:                             142
Modellname:                         Intel(R) Core(TM) i7-7500U CPU @ 2.70GHz
Stepping:                           9
CPU MHz:                            3288.582
Maximale Taktfrequenz der CPU:      3500,0000
Minimale Taktfrequenz der CPU:      400,0000
BogoMIPS:                           5799.77
Virtualisierung:                    VT-x
L1d Cache:                          64 KiB
L1i Cache:                          64 KiB
L2 Cache:                           512 KiB
L3 Cache:                           4 MiB
NUMA-Knoten0 CPU(s):                0-3
Vulnerability Gather data sampling: Mitigation; Microcode
Vulnerability Itlb multihit:        KVM: Mitigation: Split huge pages
Vulnerability L1tf:                 Mitigation; PTE Inversion; VMX conditional cache flushes, SMT vulnerable
Vulnerability Mds:                  Mitigation; Clear CPU buffers; SMT vulnerable
Vulnerability Meltdown:             Mitigation; PTI
Vulnerability Mmio stale data:      Mitigation; Clear CPU buffers; SMT vulnerable
Vulnerability Retbleed:             Mitigation; IBRS
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; IBRS, IBPB conditional, STIBP conditional, RSB filling, PBRSB-eIBRS Not affected
Vulnerability Srbds:                Mitigation; Microcode
Vulnerability Tsx async abort:      Not affected
Markierungen:                       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 est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid mpx rdseed adx smap clflushopt intel_pt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp md_clear flush_l1d arch_capabilities

Versions of relevant libraries:
[pip3] mypy-extensions==1.0.0
[pip3] numpy==1.24.4
[pip3] padertorch==0.0.0
[pip3] pytorch-lightning==2.0.9
[pip3] pytorch-metric-learning==2.3.0
[pip3] pytorch-wpe==0.0.1
[pip3] torch==2.1.2+cpu
[pip3] torch-audiomentations==0.11.0
[pip3] torch-complex==0.1.2
[pip3] torch-pitch-shift==1.2.4
[pip3] torchaudio==2.1.2+cpu
[pip3] torchmetrics==1.2.0
[pip3] torchvision==0.16.2+cpu
[pip3] triton==2.0.0
[conda] numpy                     1.24.4                   pypi_0    pypi
[conda] pytorch-lightning         2.0.9                    pypi_0    pypi
[conda] pytorch-metric-learning   2.3.0                    pypi_0    pypi
[conda] torch                     2.1.2+cpu                pypi_0    pypi
[conda] torch-audiomentations     0.11.0                   pypi_0    pypi
[conda] torch-pitch-shift         1.2.4                    pypi_0    pypi
[conda] torchaudio                2.1.2+cpu                pypi_0    pypi
[conda] torchmetrics              1.2.0                    pypi_0    pypi
[conda] torchvision               0.16.2+cpu               pypi_0    pypi
[conda] triton                    2.0.0                    pypi_0    pypi


cc @ezyang @anjali411 @dylanbespalko @mruberry @Lezcano @nikitaved @jianyuh @pearu @walterddr @xwang233