Scalar Tensor lowering to Fake Tensor inside Inductor
Labels: triaged, module: inductor, module: dynamo

### 🐛 Describe the bug

In PR: https://github.com/pytorch/pytorch/pull/105894, we change quantization `scale`, `zero point` from scalar to scalar tensor.  However, the scalar tensor of `scale` has lowered as fake tensor and failed to execute.
Here is the software component to reproduce this issue:

- Test pytorch branch to reproduce this issue: https://github.com/leslie-fang-intel/pytorch/tree/leslie/quant_scale_scalar_tensor
- Test script: https://gist.github.com/leslie-fang-intel/a3220284b5206b7a54ffcb990f664286
- Inductor generated code is: https://gist.github.com/leslie-fang-intel/e801ff6aa7b521d52a3e729e748775e3
- Error message is:

```
  File "/home/lesliefang/pytorch_1_7_1/inductor_quant/pytorch/torch/_inductor/compile_fx.py", line 861, in wrapper
    return optimized_function(args_new)
  File "/home/lesliefang/pytorch_1_7_1/inductor_quant/pytorch/torch/_inductor/codecache.py", line 370, in __call__
    return self.get_current_callable()(inputs)
  File "/home/lesliefang/pytorch_1_7_1/inductor_quant/pytorch/torch/_inductor/codecache.py", line 397, in _run_from_cache
    return compiled_graph.compiled_artifact(inputs)
  File "/tmp/torchinductor_root/i7/ci7tla2nhhmckgf4wli4jnteqsxiupg6w7rnvac3hj7z3nmrpewb.py", line 123, in call
    buf1 = torch.ops.onednn.qconv2d_pointwise.tensor(buf0, constant3, constant4, constant2, constant0, constant1, None, [1, 1], [0, 0], [1, 1], 1, None, None, True, 'none', [], '')
  File "/home/lesliefang/pytorch_1_7_1/inductor_quant/pytorch/torch/_ops.py", line 435, in __call__
    return self._op(*args, **kwargs or {})
  File "/home/lesliefang/pytorch_1_7_1/inductor_quant/pytorch/torch/utils/_stats.py", line 20, in wrapper
    return fn(*args, **kwargs)
  File "/home/lesliefang/pytorch_1_7_1/inductor_quant/pytorch/torch/_subclasses/fake_tensor.py", line 1077, in __torch_dispatch__
    return func(*args, **kwargs)
  File "/home/lesliefang/pytorch_1_7_1/inductor_quant/pytorch/torch/_ops.py", line 435, in __call__
    return self._op(*args, **kwargs or {})
  File "/home/lesliefang/pytorch_1_7_1/inductor_quant/pytorch/torch/utils/_stats.py", line 20, in wrapper
    return fn(*args, **kwargs)
  File "/home/lesliefang/pytorch_1_7_1/inductor_quant/pytorch/torch/_subclasses/fake_tensor.py", line 1199, in __torch_dispatch__
    return self.dispatch(func, types, args, kwargs)
  File "/home/lesliefang/pytorch_1_7_1/inductor_quant/pytorch/torch/_subclasses/fake_tensor.py", line 1310, in dispatch
    ) = self.validate_and_convert_non_fake_tensors(func, converter, args, kwargs)
  File "/home/lesliefang/pytorch_1_7_1/inductor_quant/pytorch/torch/_subclasses/fake_tensor.py", line 1503, in validate_and_convert_non_fake_tensors
    args, kwargs = tree_map_only(
  File "/home/lesliefang/pytorch_1_7_1/inductor_quant/pytorch/torch/utils/_pytree.py", line 397, in tree_map_only
    return tree_map(map_only(ty)(fn), pytree)
  File "/home/lesliefang/pytorch_1_7_1/inductor_quant/pytorch/torch/utils/_pytree.py", line 327, in tree_map
    return tree_unflatten([fn(i) for i in flat_args], spec)
  File "/home/lesliefang/pytorch_1_7_1/inductor_quant/pytorch/torch/utils/_pytree.py", line 327, in <listcomp>
    return tree_unflatten([fn(i) for i in flat_args], spec)
  File "/home/lesliefang/pytorch_1_7_1/inductor_quant/pytorch/torch/utils/_pytree.py", line 378, in inner
    return f(x)
  File "/home/lesliefang/pytorch_1_7_1/inductor_quant/pytorch/torch/_subclasses/fake_tensor.py", line 1491, in validate
    raise Exception(
Exception: Please convert all Tensors to FakeTensors first or instantiate FakeTensorMode with 'allow_non_fake_inputs'. Found in onednn.qconv2d_pointwise.tensor(tensor([...], size=(1, 3, 8, 8), dtype=torch.uint8), FakeTensor(..., size=()), FakeTensor(..., size=(), dtype=torch.int64), tensor([...], size=(128, 3, 3, 3), dtype=torch.int8, layout=torch._mkldnn), tensor([...], size=(128,)), tensor([...], size=(128,)), None, [1, 1], [0, 0], [1, 1], 1, None, None, True, 'none', [], '')
```

From the error message, looks like the second/third parameter as `x_scale` and `x_zp` has been converted as `FakeTensor`.


### Versions

```
(inductor_quant) [root@CPX-4 inductor_quant]# python collect_env.py
Collecting environment information...
PyTorch version: 2.1.0a0+git0f71239
Is debug build: False
CUDA used to build PyTorch: None
ROCM used to build PyTorch: N/A

OS: CentOS Linux 7 (Core) (x86_64)
GCC version: (GCC) 11.2.1 20210728 (Red Hat 11.2.1-1)
Clang version: Could not collect
CMake version: version 3.22.1
Libc version: glibc-2.17

Python version: 3.8.10 (default, Jun  4 2021, 15:09:15)  [GCC 7.5.0] (64-bit runtime)
Python platform: Linux-4.19.5-1.el7.elrepo.x86_64-x86_64-with-glibc2.17
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
Byte Order:            Little Endian
CPU(s):                56
On-line CPU(s) list:   0-55
Thread(s) per core:    1
Core(s) per socket:    28
Socket(s):             2
NUMA node(s):          2
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 85
Model name:            Intel Genuine CPU
Stepping:              10
CPU MHz:               1200.521
CPU max MHz:           2900.0000
CPU min MHz:           1200.0000
BogoMIPS:              5800.00
Virtualization:        VT-x
L1d cache:             32K
L1i cache:             32K
L2 cache:              1024K
L3 cache:              39424K
NUMA node0 CPU(s):     0-27
NUMA node1 CPU(s):     28-55
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 hle avx2 smep bmi2 erms invpcid rtm 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 arat pln pts hwp hwp_act_window hwp_epp hwp_pkg_req pku ospke avx512_vnni flush_l1d arch_capabilities

Versions of relevant libraries:
[pip3] mypy==1.4.1
[pip3] mypy-extensions==1.0.0
[pip3] numpy==1.24.3
[pip3] torch==2.1.0a0+git7ae3928
[pip3] torchvision==0.16.0a0+08c9938
[conda] mkl                       2023.0.0            intel_25398    intel
[conda] mkl-include               2023.0.0                  <pip>
[conda] mkl-include               2023.0.0            intel_25398    intel
[conda] mkl-service               2.4.0           py38h3605609_14    intel
[conda] mkl-static                2023.0.0                  <pip>
[conda] mkl_fft                   1.3.1           py38hcab1719_22    intel
[conda] mkl_random                1.2.2           py38hbf47bc3_22    intel
[conda] mkl_umath                 0.1.1           py38hf66a691_32    intel
[conda] numpy                     1.24.3                    <pip>
[conda] numpy                     1.22.3           py38hf0956d0_5    intel
[conda] numpy-base                1.22.3           py38h45c9ace_5    intel

```

cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @Xia-Weiwen @wenzhe-nrv @jiayisunx @peterbell10 @ipiszy @ngimel @yf225 @chenyang78 @kadeng @muchulee8 @aakhundov @anijain2305