Repository: pytorch
Issue: Torch compile fx graph is not removing constant propagation
Labels: triaged,oncall: pt2,module: inductor

### 🐛 Describe the bug

I am running GPTJ-6B model what i have input certain nodes got input from constants, it can be eliminated, but it didnot is there any why to eliminate.

```
     # File: /home/tiru/work/vsim/lib/python3.8/site-packages/transformers/models/gptj/modeling_gptj.py:600, code: position_ids = torch.arange(past_length, input_shape[-1] + past_length, dtype=torch.long, device=device)
        iota: "i64[19]" = torch.ops.prims.iota.default(19, start = 0, step = 1, dtype = torch.int64, device = device(type='cpu'), requires_grad = False)
        
        # File: /home/tiru/work/vsim/lib/python3.8/site-packages/transformers/models/gptj/modeling_gptj.py:601, code: position_ids = position_ids.unsqueeze(0)
        unsqueeze: "i64[1, 19]" = torch.ops.aten.unsqueeze.default(iota, 0);  iota = None
        
        # File: /home/tiru/work/vsim/lib/python3.8/site-packages/transformers/models/gptj/modeling_gptj.py:630, code: inputs_embeds = self.wte(input_ids)
        embedding: "f32[1, 19, 4096]" = torch.ops.aten.embedding.default(arg0_1, view);  arg0_1 = view = None
        
        # File: /home/tiru/work/vsim/lib/python3.8/site-packages/transformers/models/gptj/modeling_gptj.py:638, code: hidden_states = self.drop(hidden_states)
        clone: "f32[1, 19, 4096]" = torch.ops.aten.clone.default(embedding);  embedding = None
        
        # File: /home/tiru/work/vsim/lib/python3.8/site-packages/transformers/models/gptj/modeling_gptj.py:310, code: hidden_states = self.ln_1(hidden_states)
        mean: "f32[1, 19, 1]" = torch.ops.aten.mean.dim(clone, [-1], True)
        sub: "f32[1, 19, 4096]" = torch.ops.aten.sub.Tensor(clone, mean);  mean = None
        pow_1: "f32[1, 19, 4096]" = torch.ops.aten.pow.Tensor_Scalar(sub, 2.0)
        mean_1: "f32[1, 19, 1]" = torch.ops.aten.mean.dim(pow_1, [-1], True);  pow_1 = None
        add: "f32[1, 19, 1]" = torch.ops.aten.add.Tensor(mean_1, 1e-05);  mean_1 = None
        rsqrt: "f32[1, 19, 1]" = torch.ops.aten.rsqrt.default(add);  add = None
        mul: "f32[1, 19, 4096]" = torch.ops.aten.mul.Tensor(sub, rsqrt);  sub = rsqrt = None
        mul_1: "f32[1, 19, 4096]" = torch.ops.aten.mul.Tensor(mul, arg1_1);  mul = arg1_1 = None
        add_1: "f32[1, 19, 4096]" = torch.ops.aten.add.Tensor(mul_1, arg2_1);  mul_1 = arg2_1 = None
        
        # File: /home/tiru/work/vsim/lib/python3.8/site-packages/transformers/models/gptj/modeling_gptj.py:207, code: query = self.q_proj(hidden_states)
        permute: "f32[4096, 4096]" = torch.ops.aten.permute.default(arg3_1, [1, 0]);  arg3_1 = None
        view_1: "f32[19, 4096]" = torch.ops.aten.view.default(add_1, [19, 4096])
        mm: "f32[19, 4096]" = torch.ops.aten.mm.default(view_1, permute);  view_1 = permute = None
        view_2: "f32[1, 19, 4096]" = torch.ops.aten.view.default(mm, [1, 19, 4096]);  mm = None
        
        # File: /home/tiru/work/vsim/lib/python3.8/site-packages/transformers/models/gptj/modeling_gptj.py:208, code: key = self.k_proj(hidden_states)
        permute_1: "f32[4096, 4096]" = torch.ops.aten.permute.default(arg4_1, [1, 0]);  arg4_1 = None
        view_3: "f32[19, 4096]" = torch.ops.aten.view.default(add_1, [19, 4096])
        mm_1: "f32[19, 4096]" = torch.ops.aten.mm.default(view_3, permute_1);  view_3 = permute_1 = None
        view_4: "f32[1, 19, 4096]" = torch.ops.aten.view.default(mm_1, [1, 19, 4096]);  mm_1 = None
        
        # File: /home/tiru/work/vsim/lib/python3.8/site-packages/transformers/models/gptj/modeling_gptj.py:209, code: value = self.v_proj(hidden_states)
        permute_2: "f32[4096, 4096]" = torch.ops.aten.permute.default(arg5_1, [1, 0]);  arg5_1 = None
        view_5: "f32[19, 4096]" = torch.ops.aten.view.default(add_1, [19, 4096])
        mm_2: "f32[19, 4096]" = torch.ops.aten.mm.default(view_5, permute_2);  view_5 = permute_2 = None
        view_6: "f32[1, 19, 4096]" = torch.ops.aten.view.default(mm_2, [1, 19, 4096]);  mm_2 = None
        
        # File: /home/tiru/work/vsim/lib/python3.8/site-packages/transformers/models/gptj/modeling_gptj.py:122, code: tensor = tensor.view(new_shape)
        view_7: "f32[1, 19, 16, 256]" = torch.ops.aten.view.default(view_2, [1, 19, 16, 256]);  view_2 = None
        
        # File: /home/tiru/work/vsim/lib/python3.8/site-packages/transformers/models/gptj/modeling_gptj.py:122, code: tensor = tensor.view(new_shape)
        view_8: "f32[1, 19, 16, 256]" = torch.ops.aten.view.default(view_4, [1, 19, 16, 256]);  view_4 = None
        
        # File: /home/tiru/work/vsim/lib/python3.8/site-packages/transformers/models/gptj/modeling_gptj.py:122, code: tensor = tensor.view(new_shape)
        view_9: "f32[1, 19, 16, 256]" = torch.ops.aten.view.default(view_6, [1, 19, 16, 256]);  view_6 = None
        
        # File: /home/tiru/work/vsim/lib/python3.8/site-packages/transformers/models/gptj/modeling_gptj.py:128, code: return tensor.permute(0, 2, 1, 3)  # (batch, head, seq_length, head_features)
        permute_3: "f32[1, 16, 19, 256]" = torch.ops.aten.permute.default(view_9, [0, 2, 1, 3]);  view_9 = None
        
        # File: /home/tiru/work/vsim/lib/python3.8/site-packages/transformers/models/gptj/modeling_gptj.py:192, code: return embed_positions.repeat(position_ids.shape[0], 1, 1)
        repeat: "f32[1, 2048, 64]" = torch.ops.aten.repeat.default(arg285_1, [1, 1, 1]);  arg285_1 = None
        
        # File: /home/tiru/work/vsim/lib/python3.8/site-packages/transformers/models/gptj/modeling_gptj.py:222, code: repeated_position_ids = position_ids.unsqueeze(-1).repeat(1, 1, embed_positions.shape[-1])
        unsqueeze_1: "i64[1, 19, 1]" = torch.ops.aten.unsqueeze.default(unsqueeze, -1)
        repeat_1: "i64[1, 19, 64]" = torch.ops.aten.repeat.default(unsqueeze_1, [1, 1, 64]);  unsqueeze_1 = None
        
        # File: /home/tiru/work/vsim/lib/python3.8/site-packages/transformers/models/gptj/modeling_gptj.py:223, code: sincos = torch.gather(embed_positions, 1, repeated_position_ids)
        gather: "f32[1, 19, 64]" = torch.ops.aten.gather.default(repeat, 1, repeat_1);  repeat = repeat_1 = None

```

in the above graph input to gather both are repeat are constants , can be it eliminated ?

### Error logs

_No response_

### Minified repro

_No response_

### Versions

Collecting environment information...
PyTorch version: 2.2.0+cu121
Is debug build: False
CUDA used to build PyTorch: 12.1
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.0
Libc version: glibc-2.31

Python version: 3.8.10 (default, Nov 22 2023, 10:22:35)  [GCC 9.4.0] (64-bit runtime)
Python platform: Linux-5.4.0-171-generic-x86_64-with-glibc2.29
Is CUDA available: True
CUDA runtime version: Could not collect
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration: 
GPU 0: NVIDIA A100 80GB PCIe
GPU 1: NVIDIA A100 80GB PCIe

Nvidia driver version: 545.23.08
cuDNN version: Probably one of the following:
/usr/lib/x86_64-linux-gnu/libcudnn.so.8.9.7
/usr/lib/x86_64-linux-gnu/libcudnn_adv_infer.so.8.9.7
/usr/lib/x86_64-linux-gnu/libcudnn_adv_train.so.8.9.7
/usr/lib/x86_64-linux-gnu/libcudnn_cnn_infer.so.8.9.7
/usr/lib/x86_64-linux-gnu/libcudnn_cnn_train.so.8.9.7
/usr/lib/x86_64-linux-gnu/libcudnn_ops_infer.so.8.9.7
/usr/lib/x86_64-linux-gnu/libcudnn_ops_train.so.8.9.7
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
Address sizes:                      46 bits physical, 57 bits virtual
CPU(s):                             128
On-line CPU(s) list:                0-127
Thread(s) per core:                 2
Core(s) per socket:                 32
Socket(s):                          2
NUMA node(s):                       2
Vendor ID:                          GenuineIntel
CPU family:                         6
Model:                              106
Model name:                         Intel(R) Xeon(R) Gold 6338 CPU @ 2.00GHz
Stepping:                           6
CPU MHz:                            800.000
CPU max MHz:                        3200.0000
CPU min MHz:                        800.0000
BogoMIPS:                           4000.00
Virtualization:                     VT-x
L1d cache:                          3 MiB
L1i cache:                          2 MiB
L2 cache:                           80 MiB
L3 cache:                           96 MiB
NUMA node0 CPU(s):                  0-31,64-95
NUMA node1 CPU(s):                  32-63,96-127
Vulnerability Gather data sampling: Mitigation; Microcode
Vulnerability Itlb multihit:        Not affected
Vulnerability L1tf:                 Not affected
Vulnerability Mds:                  Not affected
Vulnerability Meltdown:             Not affected
Vulnerability Mmio stale data:      Mitigation; Clear CPU buffers; SMT vulnerable
Vulnerability Retbleed:             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:      Not affected
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 invpcid_single 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 rdt_a avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb intel_pt avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local wbnoinvd dtherm ida arat pln pts hwp hwp_act_window hwp_epp hwp_pkg_req avx512vbmi umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg tme avx512_vpopcntdq rdpid md_clear pconfig flush_l1d arch_capabilities

Versions of relevant libraries:
[pip3] numpy==1.24.4
[pip3] onnx==1.14.0
[pip3] onnx-graphsurgeon==0.3.27
[pip3] onnx2pytorch==0.4.1
[pip3] onnxruntime==1.15.1
[pip3] optree==0.10.0
[pip3] torch==2.2.0
[pip3] torch-pac==0.0.1.dev0
[pip3] torch-tb-profiler==0.4.3
[pip3] torch-xla==1.0
[pip3] torchvision==0.16.2
[pip3] triton==2.2.0
[conda] mkl                       2021.4.0           h06a4308_640  
[conda] mkl-include               2023.1.0         h06a4308_46344  
[conda] numpy                     1.26.3                   pypi_0    pypi
[conda] torch                     2.1.2                    pypi_0    pypi
[conda] triton                    2.1.0                    pypi_0    pypi

cc @ezyang @msaroufim @bdhirsh @anijain2305 @zou3519 @chauhang @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @peterbell10 @ipiszy @yf225 @chenyang78 @kadeng @muchulee8 @aakhundov @ColinPeppler @amjames @desertfire