Repository: pytorch
Issue: No checks when running torch.nn.functional.ctc_loss with bogus inputs
Labels: module: loss,module: cpu,triaged

### 🐛 Describe the bug

Different results on CPU and GPU

```
results = dict()
import torch
arg_1_tensor = torch.rand([150, 64, 101], dtype=torch.float64)
arg_1 = arg_1_tensor.clone()
arg_2_tensor = torch.randint(-2,32768,[64, 15], dtype=torch.int64)
arg_2 = arg_2_tensor.clone()
arg_3_0 = 116
arg_3_1 = 150
arg_3_2 = 150
arg_3_3 = 150
arg_3_4 = 150
arg_3_5 = 150
arg_3_6 = 150
arg_3_7 = 150
arg_3_8 = 150
arg_3_9 = 150
arg_3_10 = 150
arg_3_11 = 150
arg_3_12 = 150
arg_3_13 = 150
arg_3_14 = 150
arg_3_15 = 150
arg_3_16 = 150
arg_3_17 = 150
arg_3_18 = 150
arg_3_19 = 150
arg_3_20 = 150
arg_3_21 = 150
arg_3_22 = 150
arg_3_23 = 150
arg_3_24 = 150
arg_3_25 = 150
arg_3_26 = 150
arg_3_27 = 150
arg_3_28 = 150
arg_3_29 = 150
arg_3_30 = 150
arg_3_31 = 150
arg_3_32 = 150
arg_3_33 = 150
arg_3_34 = 150
arg_3_35 = 150
arg_3_36 = 150
arg_3_37 = 150
arg_3_38 = 150
arg_3_39 = 150
arg_3_40 = 150
arg_3_41 = 150
arg_3_42 = 150
arg_3_43 = 150
arg_3_44 = 150
arg_3_45 = 150
arg_3_46 = 150
arg_3_47 = 150
arg_3_48 = 150
arg_3_49 = 150
arg_3_50 = 150
arg_3_51 = 150
arg_3_52 = 150
arg_3_53 = 150
arg_3_54 = 150
arg_3_55 = 150
arg_3_56 = 150
arg_3_57 = 150
arg_3_58 = 150
arg_3_59 = 150
arg_3_60 = 150
arg_3_61 = 150
arg_3_62 = 150
arg_3_63 = 150
arg_3 = [arg_3_0,arg_3_1,arg_3_2,arg_3_3,arg_3_4,arg_3_5,arg_3_6,arg_3_7,arg_3_8,arg_3_9,arg_3_10,arg_3_11,arg_3_12,arg_3_13,arg_3_14,arg_3_15,arg_3_16,arg_3_17,arg_3_18,arg_3_19,arg_3_20,arg_3_21,arg_3_22,arg_3_23,arg_3_24,arg_3_25,arg_3_26,arg_3_27,arg_3_28,arg_3_29,arg_3_30,arg_3_31,arg_3_32,arg_3_33,arg_3_34,arg_3_35,arg_3_36,arg_3_37,arg_3_38,arg_3_39,arg_3_40,arg_3_41,arg_3_42,arg_3_43,arg_3_44,arg_3_45,arg_3_46,arg_3_47,arg_3_48,arg_3_49,arg_3_50,arg_3_51,arg_3_52,arg_3_53,arg_3_54,arg_3_55,arg_3_56,arg_3_57,arg_3_58,arg_3_59,arg_3_60,arg_3_61,arg_3_62,arg_3_63,]
arg_4_0 = 15
arg_4_1 = 15
arg_4_2 = 15
arg_4_3 = 15
arg_4_4 = 15
arg_4_5 = 15
arg_4_6 = 15
arg_4_7 = 15
arg_4_8 = 15
arg_4_9 = 15
arg_4_10 = 15
arg_4_11 = 15
arg_4_12 = 15
arg_4_13 = 15
arg_4_14 = 15
arg_4_15 = 15
arg_4_16 = 15
arg_4_17 = 15
arg_4_18 = 15
arg_4_19 = 15
arg_4_20 = 15
arg_4_21 = 15
arg_4_22 = 15
arg_4_23 = 15
arg_4_24 = 15
arg_4_25 = 15
arg_4_26 = 15
arg_4_27 = 15
arg_4_28 = 15
arg_4_29 = 15
arg_4_30 = 15
arg_4_31 = 15
arg_4_32 = 15
arg_4_33 = 15
arg_4_34 = 15
arg_4_35 = 15
arg_4_36 = 15
arg_4_37 = 15
arg_4_38 = 15
arg_4_39 = 15
arg_4_40 = 15
arg_4_41 = 15
arg_4_42 = 15
arg_4_43 = 15
arg_4_44 = 15
arg_4_45 = 15
arg_4_46 = 15
arg_4_47 = 15
arg_4_48 = 15
arg_4_49 = 15
arg_4_50 = 15
arg_4_51 = 15
arg_4_52 = 15
arg_4_53 = 15
arg_4_54 = 15
arg_4_55 = 15
arg_4_56 = 15
arg_4_57 = 15
arg_4_58 = 15
arg_4_59 = 15
arg_4_60 = 15
arg_4_61 = 15
arg_4_62 = 15
arg_4_63 = 15
arg_4 = [arg_4_0,arg_4_1,arg_4_2,arg_4_3,arg_4_4,arg_4_5,arg_4_6,arg_4_7,arg_4_8,arg_4_9,arg_4_10,arg_4_11,arg_4_12,arg_4_13,arg_4_14,arg_4_15,arg_4_16,arg_4_17,arg_4_18,arg_4_19,arg_4_20,arg_4_21,arg_4_22,arg_4_23,arg_4_24,arg_4_25,arg_4_26,arg_4_27,arg_4_28,arg_4_29,arg_4_30,arg_4_31,arg_4_32,arg_4_33,arg_4_34,arg_4_35,arg_4_36,arg_4_37,arg_4_38,arg_4_39,arg_4_40,arg_4_41,arg_4_42,arg_4_43,arg_4_44,arg_4_45,arg_4_46,arg_4_47,arg_4_48,arg_4_49,arg_4_50,arg_4_51,arg_4_52,arg_4_53,arg_4_54,arg_4_55,arg_4_56,arg_4_57,arg_4_58,arg_4_59,arg_4_60,arg_4_61,arg_4_62,arg_4_63,]
try:
  results["res_cpu"] = torch.nn.functional.ctc_loss(arg_1,arg_2,arg_3,arg_4,)
except Exception as e:
  print("Error:"+str(e))
arg_1 = arg_1_tensor.clone().cuda()
arg_2 = arg_2_tensor.clone().cuda()
arg_3 = [arg_3_0,arg_3_1,arg_3_2,arg_3_3,arg_3_4,arg_3_5,arg_3_6,arg_3_7,arg_3_8,arg_3_9,arg_3_10,arg_3_11,arg_3_12,arg_3_13,arg_3_14,arg_3_15,arg_3_16,arg_3_17,arg_3_18,arg_3_19,arg_3_20,arg_3_21,arg_3_22,arg_3_23,arg_3_24,arg_3_25,arg_3_26,arg_3_27,arg_3_28,arg_3_29,arg_3_30,arg_3_31,arg_3_32,arg_3_33,arg_3_34,arg_3_35,arg_3_36,arg_3_37,arg_3_38,arg_3_39,arg_3_40,arg_3_41,arg_3_42,arg_3_43,arg_3_44,arg_3_45,arg_3_46,arg_3_47,arg_3_48,arg_3_49,arg_3_50,arg_3_51,arg_3_52,arg_3_53,arg_3_54,arg_3_55,arg_3_56,arg_3_57,arg_3_58,arg_3_59,arg_3_60,arg_3_61,arg_3_62,arg_3_63,]
arg_4 = [arg_4_0,arg_4_1,arg_4_2,arg_4_3,arg_4_4,arg_4_5,arg_4_6,arg_4_7,arg_4_8,arg_4_9,arg_4_10,arg_4_11,arg_4_12,arg_4_13,arg_4_14,arg_4_15,arg_4_16,arg_4_17,arg_4_18,arg_4_19,arg_4_20,arg_4_21,arg_4_22,arg_4_23,arg_4_24,arg_4_25,arg_4_26,arg_4_27,arg_4_28,arg_4_29,arg_4_30,arg_4_31,arg_4_32,arg_4_33,arg_4_34,arg_4_35,arg_4_36,arg_4_37,arg_4_38,arg_4_39,arg_4_40,arg_4_41,arg_4_42,arg_4_43,arg_4_44,arg_4_45,arg_4_46,arg_4_47,arg_4_48,arg_4_49,arg_4_50,arg_4_51,arg_4_52,arg_4_53,arg_4_54,arg_4_55,arg_4_56,arg_4_57,arg_4_58,arg_4_59,arg_4_60,arg_4_61,arg_4_62,arg_4_63,]
try:
  results["res_gpu"] = torch.nn.functional.ctc_loss(arg_1,arg_2,arg_3,arg_4,)
except Exception as e:
  print("Error:"+str(e))

print(results)
```

Output: 

```
tensor(-10.2912, dtype=torch.float64), 'res_gpu': tensor(-25.2783, device='cuda:0', dtype=torch.float64)
```

### Versions

```
PyTorch version: 1.12.0
Is debug build: False
CUDA used to build PyTorch: 10.2
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: Could not collect
CMake version: Could not collect
Libc version: glibc-2.35

Python version: 3.9.16 (main, May 15 2023, 23:46:34)  [GCC 11.2.0] (64-bit runtime)
Python platform: Linux-6.2.0-26-generic-x86_64-with-glibc2.35
Is CUDA available: True
CUDA runtime version: Could not collect
CUDA_MODULE_LOADING set to: 
GPU models and configuration: GPU 0: NVIDIA GeForce GTX 1660 Ti
Nvidia driver version: 535.86.05
cuDNN version: Could not collect
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:                   39 bits physical, 48 bits virtual
Byte Order:                      Little Endian
CPU(s):                          16
On-line CPU(s) list:             0-15
Vendor ID:                       GenuineIntel
Model name:                      Intel(R) Core(TM) i7-10700F CPU @ 2.90GHz
CPU family:                      6
Model:                           165
Thread(s) per core:              2
Core(s) per socket:              8
Socket(s):                       1
Stepping:                        5
CPU max MHz:                     4800.0000
CPU min MHz:                     800.0000
BogoMIPS:                        5799.77
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 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 ssbd ibrs ibpb stibp ibrs_enhanced tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust sgx 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 pku ospke sgx_lc md_clear flush_l1d arch_capabilities
Virtualization:                  VT-x
L1d cache:                       256 KiB (8 instances)
L1i cache:                       256 KiB (8 instances)
L2 cache:                        2 MiB (8 instances)
L3 cache:                        16 MiB (1 instance)
NUMA node(s):                    1
NUMA node0 CPU(s):               0-15
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 store bypass: Mitigation; Speculative Store Bypass disabled via prctl
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:             Mitigation; Microcode
Vulnerability Tsx async abort:   Not affected

Versions of relevant libraries:
[pip3] numpy==1.25.0
[pip3] torch==1.12.0
[pip3] torchaudio==0.12.0
[pip3] torchvision==0.13.0
[conda] blas                      1.0                         mkl  
[conda] cudatoolkit               10.2.89              hfd86e86_1  
[conda] ffmpeg                    4.3                  hf484d3e_0    pytorch
[conda] mkl                       2023.1.0         h6d00ec8_46342  
[conda] mkl-service               2.4.0            py39h5eee18b_1  
[conda] mkl_fft                   1.3.6            py39h417a72b_1  
[conda] mkl_random                1.2.2            py39h417a72b_1  
[conda] numpy                     1.25.0           py39h5f9d8c6_0  
[conda] numpy-base                1.25.0           py39hb5e798b_0  
[conda] pytorch                   1.12.0          py3.9_cuda10.2_cudnn7.6.5_0    pytorch
[conda] pytorch-mutex             1.0                        cuda    pytorch
[conda] torchaudio                0.12.0               py39_cu102    pytorch
[conda] torchvision               0.13.0               py39_cu102    pytorch
```

cc @jgong5 @mingfeima @XiaobingSuper @sanchitintel @ashokei @jingxu10