Repository: pytorch
Issue: [torch.export] _insert_copy_for_mutations can't generate proper copy nodes for pure inplace ops
Labels: oncall: pt2,oncall: export

### 🐛 Describe the bug

I am using the simplest `nn.Relu(inpleace=True)`  to make a call to torch.export, and the following error occurs:
```
RuntimeError: Could not find input in either buffer or input nodes
```
My test code is as follows:
```
def ori_test():
    x = torch.rand(2,3)
    m = torch.nn.ReLU(inplace=True).eval()
    m = torch.export.export(m, (x,))
    mm = m.module() # error occurs
```

After debugging, I realised that the root cause was that `torch.export.export` was modifying the graph in a way that didn't strictly correspond to the rules in `class Graph`.

The generated  graph is as follows:
```
graph():
    %arg0_1 : [num_users=1] = placeholder[target=arg0_1]
    %relu : [num_users=1] = call_function[target=torch.ops.aten.relu.default](args = (%arg0_1,), kwargs = {})
    return (relu, relu)
```
It's ok. However, in `placeholder_naming_pass`, it get original args name "input" in aten and modified the structure of the graph into this
```
graph():
    %input : [num_users=1] = placeholder[target=input]
    %relu : [num_users=1] = call_function[target=torch.ops.aten.relu.default](args = (%input,), kwargs = {})
    return (relu, relu)
```
**str "input" is confilicted with `builtins.__dict__`**. Thus, when it comes into `_unlift_exported_program_lifted_states`, it calls "copy.deepcopy", which is a method of `Graph`.  In the process of copying, `_is_illegal_name` checks for naming conflicts, resulting in the diagram being modified as follows:
```
graph():
    %input_1 : [num_users=1] = placeholder[target=input]
    %relu : [num_users=1] = call_function[target=torch.ops.aten.relu.default](args = (%input_1,), kwargs = {})
    return (relu, relu)
```
**This ultimately causes `_insert_copy_for_mutations` to fail to insert the copy node properly due to `input_name_to_node` mismatch.**

If possible, I think the same appropriate check should be added to `placeholder_naming_pass`  to avoid this, although it may not be fully consistent with the naming in the original function.

Can any of the team members give some advice?



### Versions

Collecting environment information...
PyTorch version: 2.5.1+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.28.4
Libc version: glibc-2.31

Python version: 3.11.11 (main, Dec 11 2024, 16:28:39) [GCC 11.2.0] (64-bit runtime)
Python platform: Linux-5.4.0-200-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:
Architecture:                       x86_64
CPU op-mode(s):                     32-bit, 64-bit
Byte Order:                         Little Endian
Address sizes:                      46 bits physical, 48 bits virtual
CPU(s):                             96
On-line CPU(s) list:                0-95
Thread(s) per core:                 2
Core(s) per socket:                 24
Socket(s):                          2
NUMA node(s):                       2
Vendor ID:                          GenuineIntel
CPU family:                         6
Model:                              85
Model name:                         Intel(R) Xeon(R) Platinum 8369HB CPU @ 3.30GHz
Stepping:                           11
CPU MHz:                            3800.073
CPU max MHz:                        4200.0000
CPU min MHz:                        1200.0000
BogoMIPS:                           6600.06
Hypervisor vendor:                  KVM
Virtualization type:                full
L1d cache:                          1.5 MiB
L1i cache:                          1.5 MiB
L2 cache:                           48 MiB
L3 cache:                           66 MiB
NUMA node0 CPU(s):                  0-47
NUMA node1 CPU(s):                  48-95
Vulnerability Gather data sampling: Unknown: Dependent on hypervisor status
Vulnerability Itlb multihit:        KVM: Vulnerable
Vulnerability L1tf:                 Mitigation; PTE Inversion
Vulnerability Mds:                  Vulnerable: Clear CPU buffers attempted, no microcode; SMT Host state unknown
Vulnerability Meltdown:             Mitigation; PTI
Vulnerability Mmio stale data:      Vulnerable: Clear CPU buffers attempted, no microcode; SMT Host state unknown
Vulnerability Retbleed:             Vulnerable
Vulnerability Spec store bypass:    Vulnerable
Vulnerability Spectre v1:           Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2:           Mitigation; Retpolines; STIBP disabled; RSB filling; PBRSB-eIBRS Not affected; BHI Retpoline
Vulnerability Srbds:                Not affected
Vulnerability Tsx async abort:      Vulnerable: Clear CPU buffers attempted, no microcode; SMT Host state unknown
Flags:                              fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq monitor ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch invpcid_single pti fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx avx512f avx512dq rdseed adx smap clflushopt clwb avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves avx512_bf16 ida arat avx512_vnni

Versions of relevant libraries:
[pip3] intel_extension_for_pytorch==2.5.0
[pip3] numpy==1.26.3
[pip3] torch==2.5.1+cpu
[pip3] torchaudio==2.5.1+cpu
[pip3] torchvision==0.20.1+cpu
[conda] intel-extension-for-pytorch 2.5.0                    pypi_0    pypi
[conda] mkl-include               2025.0.1                 pypi_0    pypi
[conda] mkl-static                2025.0.1                 pypi_0    pypi
[conda] numpy                     1.26.3                   pypi_0    pypi
[conda] torch                     2.5.1+cpu                pypi_0    pypi
[conda] torchaudio                2.5.1+cpu                pypi_0    pypi
[conda] torchvision               0.20.1+cpu               pypi_0    pypi

cc @chauhang @penguinwu @avikchaudhuri @gmagogsfm @zhxchen17 @tugsbayasgalan @angelayi @suo @ydwu4