Repository: pytorch
Issue: Segmentation fault (core dumped) in `torch.fused_moving_avg_obs_fake_quant`
Labels: module: crash,oncall: quantization,actionable,module: edge cases

### 🐛 Describe the bug

`torch.fused_moving_avg_obs_fake_quant` causes Segmentation fault with specific input.

Test code:
```python
import torch

self = torch.full((1,), 0.5, dtype=torch.float64, requires_grad=False)
observer_on = torch.full((1,), 1, dtype=torch.int32, requires_grad=False)
fake_quant_on = torch.full((1,), 1, dtype=torch.int64, requires_grad=False)
running_min = torch.full((1,), 0.5, dtype=torch.float64, requires_grad=False)
running_max = torch.full((1,), 0.5, dtype=torch.float64, requires_grad=False)
scale = torch.full((1,), 0.5, dtype=torch.float64, requires_grad=False)
zero_point = torch.full((1,), 0.5, dtype=torch.float64, requires_grad=False)
averaging_const = 0
quant_min = 0
quant_max = 0
ch_axis = -1250999896764
per_row_fake_quant = True
symmetric_quant = True
torch.fused_moving_avg_obs_fake_quant(self, observer_on, fake_quant_on, running_min, running_max, scale, zero_point, averaging_const, quant_min, quant_max, ch_axis, per_row_fake_quant, symmetric_quant)

```

Error log:
```
AddressSanitizer:DEADLYSIGNAL
=================================================================
==69045==ERROR: AddressSanitizer: SEGV on unknown address 0x76e3d2a0a8b0 (pc 0x7f86e5632cd6 bp 0x7ffdfddcfef0 sp 0x7ffdfddcfd90 T0)
==69045==The signal is caused by a WRITE memory access.
    #0 0x7f86e5632cd6 in at::native::fused_moving_avg_obs_fake_quant_cpu(at::Tensor const&, at::Tensor const&, at::Tensor const&, at::Tensor&, at::Tensor&, at::Tensor&, at::Tensor&, double, long, long, long, bool, bool) (/usr/local/lib/python3.11/dist-packages/torch/lib/libtorch_cpu.so+0x1d28cd6)
    #1 0x7f86e60290c4 in c10::impl::wrap_kernel_functor_unboxed_<c10::impl::detail::WrapFunctionIntoFunctor_<c10::CompileTimeFunctionPointer<std::tuple<at::Tensor, at::Tensor> (at::Tensor const&, at::Tensor const&, at::Tensor const&, at::Tensor&, at::Tensor&, at::Tensor&, at::Tensor&, double, long, long, long, bool, bool), &at::(anonymous namespace)::(anonymous namespace)::wrapper_CPU___fused_moving_avg_obs_fq_helper>, std::tuple<at::Tensor, at::Tensor>, c10::guts::typelist::typelist<at::Tensor const&, at::Tensor const&, at::Tensor const&, at::Tensor&, at::Tensor&, at::Tensor&, at::Tensor&, double, long, long, long, bool, bool> >, std::tuple<at::Tensor, at::Tensor> (at::Tensor const&, at::Tensor const&, at::Tensor const&, at::Tensor&, at::Tensor&, at::Tensor&, at::Tensor&, double, long, long, long, bool, bool)>::call(c10::OperatorKernel*, c10::DispatchKeySet, at::Tensor const&, at::Tensor const&, at::Tensor const&, at::Tensor&, at::Tensor&, at::Tensor&, at::Tensor&, double, long, long, long, bool, bool) (/usr/local/lib/python3.11/dist-packages/torch/lib/libtorch_cpu.so+0x271f0c4)
    #2 0x7f86e588c5c1 in at::_ops::_fused_moving_avg_obs_fq_helper::redispatch(c10::DispatchKeySet, at::Tensor const&, at::Tensor const&, at::Tensor const&, at::Tensor&, at::Tensor&, at::Tensor&, at::Tensor&, double, long, long, long, bool, bool) (/usr/local/lib/python3.11/dist-packages/torch/lib/libtorch_cpu.so+0x1f825c1)
    #3 0x7f86e78b6586 in torch::autograd::VariableType::(anonymous namespace)::_fused_moving_avg_obs_fq_helper(c10::DispatchKeySet, at::Tensor const&, at::Tensor const&, at::Tensor const&, at::Tensor&, at::Tensor&, at::Tensor&, at::Tensor&, double, long, long, long, bool, bool) (/usr/local/lib/python3.11/dist-packages/torch/lib/libtorch_cpu.so+0x3fac586)
    #4 0x7f86e78b6df6 in c10::impl::wrap_kernel_functor_unboxed_<c10::impl::detail::WrapFunctionIntoFunctor_<c10::CompileTimeFunctionPointer<std::tuple<at::Tensor, at::Tensor> (c10::DispatchKeySet, at::Tensor const&, at::Tensor const&, at::Tensor const&, at::Tensor&, at::Tensor&, at::Tensor&, at::Tensor&, double, long, long, long, bool, bool), &torch::autograd::VariableType::(anonymous namespace)::_fused_moving_avg_obs_fq_helper>, std::tuple<at::Tensor, at::Tensor>, c10::guts::typelist::typelist<c10::DispatchKeySet, at::Tensor const&, at::Tensor const&, at::Tensor const&, at::Tensor&, at::Tensor&, at::Tensor&, at::Tensor&, double, long, long, long, bool, bool> >, std::tuple<at::Tensor, at::Tensor> (c10::DispatchKeySet, at::Tensor const&, at::Tensor const&, at::Tensor const&, at::Tensor&, at::Tensor&, at::Tensor&, at::Tensor&, double, long, long, long, bool, bool)>::call(c10::OperatorKernel*, c10::DispatchKeySet, at::Tensor const&, at::Tensor const&, at::Tensor const&, at::Tensor&, at::Tensor&, at::Tensor&, at::Tensor&, double, long, long, long, bool, bool) (/usr/local/lib/python3.11/dist-packages/torch/lib/libtorch_cpu.so+0x3facdf6)
    #5 0x7f86e593efee in at::_ops::_fused_moving_avg_obs_fq_helper::call(at::Tensor const&, at::Tensor const&, at::Tensor const&, at::Tensor&, at::Tensor&, at::Tensor&, at::Tensor&, double, long, long, long, bool, bool) (/usr/local/lib/python3.11/dist-packages/torch/lib/libtorch_cpu.so+0x2034fee)
    #6 0x7f86e5632093 in at::native::fused_moving_avg_obs_fake_quant(at::Tensor const&, at::Tensor const&, at::Tensor const&, at::Tensor&, at::Tensor&, at::Tensor&, at::Tensor&, double, long, long, long, bool, bool) (/usr/local/lib/python3.11/dist-packages/torch/lib/libtorch_cpu.so+0x1d28093)
    #7 0x7f86e63b10c4 in c10::impl::wrap_kernel_functor_unboxed_<c10::impl::detail::WrapFunctionIntoFunctor_<c10::CompileTimeFunctionPointer<at::Tensor (at::Tensor const&, at::Tensor const&, at::Tensor const&, at::Tensor&, at::Tensor&, at::Tensor&, at::Tensor&, double, long, long, long, bool, bool), &at::(anonymous namespace)::(anonymous namespace)::wrapper_CompositeImplicitAutograd__fused_moving_avg_obs_fake_quant>, at::Tensor, c10::guts::typelist::typelist<at::Tensor const&, at::Tensor const&, at::Tensor const&, at::Tensor&, at::Tensor&, at::Tensor&, at::Tensor&, double, long, long, long, bool, bool> >, at::Tensor (at::Tensor const&, at::Tensor const&, at::Tensor const&, at::Tensor&, at::Tensor&, at::Tensor&, at::Tensor&, double, long, long, long, bool, bool)>::call(c10::OperatorKernel*, c10::DispatchKeySet, at::Tensor const&, at::Tensor const&, at::Tensor const&, at::Tensor&, at::Tensor&, at::Tensor&, at::Tensor&, double, long, long, long, bool, bool) (/usr/local/lib/python3.11/dist-packages/torch/lib/libtorch_cpu.so+0x2aa70c4)
    #8 0x7f86e5e3fbe0 in at::_ops::fused_moving_avg_obs_fake_quant::call(at::Tensor const&, at::Tensor const&, at::Tensor const&, at::Tensor&, at::Tensor&, at::Tensor&, at::Tensor&, double, long, long, long, bool, bool) (/usr/local/lib/python3.11/dist-packages/torch/lib/libtorch_cpu.so+0x2535be0)
    #9 0x7f86efd5aca3 in torch::autograd::THPVariable_fused_moving_avg_obs_fake_quant(_object*, _object*, _object*) (/usr/local/lib/python3.11/dist-packages/torch/lib/libtorch_python.so+0x681ca3)
    #10 0x51ad66  (/usr/bin/python3.11+0x51ad66)
    #11 0x4e75db in _PyObject_MakeTpCall (/usr/bin/python3.11+0x4e75db)
    #12 0x4fb151 in _PyEval_EvalFrameDefault (/usr/bin/python3.11+0x4fb151)
    #13 0x62e1b3  (/usr/bin/python3.11+0x62e1b3)
    #14 0x4f3a66 in PyEval_EvalCode (/usr/bin/python3.11+0x4f3a66)
    #15 0x647c36  (/usr/bin/python3.11+0x647c36)
    #16 0x64534f  (/usr/bin/python3.11+0x64534f)
    #17 0x650d14  (/usr/bin/python3.11+0x650d14)
    #18 0x650a63 in _PyRun_SimpleFileObject (/usr/bin/python3.11+0x650a63)
    #19 0x650832 in _PyRun_AnyFileObject (/usr/bin/python3.11+0x650832)
    #20 0x64f786 in Py_RunMain (/usr/bin/python3.11+0x64f786)
    #21 0x61ee0c in Py_BytesMain (/usr/bin/python3.11+0x61ee0c)
    #22 0x7f86f40eed8f  (/lib/x86_64-linux-gnu/libc.so.6+0x29d8f)
    #23 0x7f86f40eee3f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e3f)
    #24 0x61ec94 in _start (/usr/bin/python3.11+0x61ec94)

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV (/usr/local/lib/python3.11/dist-packages/torch/lib/libtorch_cpu.so+0x1d28cd6) in at::native::fused_moving_avg_obs_fake_quant_cpu(at::Tensor const&, at::Tensor const&, at::Tensor const&, at::Tensor&, at::Tensor&, at::Tensor&, at::Tensor&, double, long, long, long, bool, bool)
==69045==ABORTING
```

### Versions

PyTorch version: 2.3.0a0
Is debug build: False
CUDA used to build PyTorch: None
ROCM used to build PyTorch: N/A

OS: Ubuntu 22.04.4 LTS (x86_64)
GCC version: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
Clang version: Could not collect
CMake version: version 3.22.1
Libc version: glibc-2.35

Python version: 3.11.0rc1 (main, Aug 12 2022, 10:02:14) [GCC 11.2.0] (64-bit runtime)
Python platform: Linux-5.15.0-91-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): 80
On-line CPU(s) list: 0-79
Vendor ID: GenuineIntel
Model name: Intel(R) Xeon(R) Gold 5218R CPU @ 2.10GHz
CPU family: 6
Model: 85
Thread(s) per core: 2
Core(s) per socket: 20
Socket(s): 2
Stepping: 7
CPU max MHz: 4000.0000
CPU min MHz: 800.0000
BogoMIPS: 4200.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.3 MiB (40 instances)
L1i cache: 1.3 MiB (40 instances)
L2 cache: 40 MiB (40 instances)
L3 cache: 55 MiB (2 instances)
NUMA node(s): 2
NUMA node0 CPU(s): 0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,62,64,66,68,70,72,74,76,78
NUMA node1 CPU(s): 1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59,61,63,65,67,69,71,73,75,77,79
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.4
[pip3] optree==0.11.0
[pip3] torch==2.3.0a0+git97ff6cf
[conda] No relevant packages

cc @jerryzh168 @jianyuh @raghuramank100 @jamesr66a @vkuzo @jgong5 @Xia-Weiwen @leslie-fang-intel @msaroufim