Repository: pytorch
Issue: [dynamo][inline inbuilt nn modules]`torch.func.functional_call` doesn't work with compiled models
Labels: triaged,actionable,module: correctness (silent),weeks,oncall: pt2,module: dynamo,dynamo-must-fix

### 🐛 Describe the bug

When creating a custom model with `nn.Module` and compiling it with `torch.compile()`, the output of `torch.func.functional_call()` remains the same even if providing different `parameter_and_buffer_dicts`. Below is an example:
```python
import torch
import torch.nn as nn


class LinearNet(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear = nn.Linear(1, 3)

    def forward(self, x):
        return self.linear(x)


inputs = torch.randn(1, 1)

print('instantiate w/ nn.Module + compile:')
model = torch.compile(LinearNet())
params = dict(model.named_parameters())
print(torch.func.functional_call(model, params, inputs))
# set parameters to 0 so that outputs should also be 0
for name, param in params.items():
    params[name] = torch.zeros_like(param)
print(torch.func.functional_call(model, params, inputs))

print('instantiate w/ nn.Linear + compile:')
model = torch.compile(nn.Linear(1, 3))
params = dict(model.named_parameters())
print(torch.func.functional_call(model, params, inputs))
for name, param in params.items():
    params[name] = torch.zeros_like(param)
print(torch.func.functional_call(model, params, inputs))

print('instantiate w/ nn.Module + no compile:')
model = LinearNet()
params = dict(model.named_parameters())
print(torch.func.functional_call(model, params, inputs))
for name, param in params.items():
    params[name] = torch.zeros_like(param)
print(torch.func.functional_call(model, params, inputs))

```
Outputs:
```
instantiate w/ nn.Module + compile:
tensor([[-0.2246,  0.4658,  0.3510]], grad_fn=<CompiledFunctionBackward>)
tensor([[-0.2246,  0.4658,  0.3510]], grad_fn=<CompiledFunctionBackward>)
instantiate w/ nn.Linear + compile:
tensor([[ 0.3361,  0.3872, -0.6998]], grad_fn=<AddmmBackward0>)
tensor([[0., 0., 0.]])
instantiate w/ nn.Module + no compile:
tensor([[-0.2540, -0.5778,  1.1222]], grad_fn=<AddmmBackward0>)
tensor([[0., 0., 0.]])
```
Updates: In PyTorch 2.2, the 2nd result for "nn.Linear + compile" becomes non-zero.
<details>
<summary>Versions</summary>

PyTorch version: 2.0.0
Is debug build: False
CUDA used to build PyTorch: 11.7
ROCM used to build PyTorch: N/A

OS: Ubuntu 22.04.2 LTS (x86_64)
GCC version: (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0
Clang version: Could not collect
CMake version: Could not collect
Libc version: glibc-2.35

Python version: 3.10.10 (main, Mar 21 2023, 18:45:11) [GCC 11.2.0] (64-bit runtime)
Python platform: Linux-5.19.0-38-generic-x86_64-with-glibc2.35
Is CUDA available: True
CUDA runtime version: Could not collect
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration: GPU 0: NVIDIA RTX A5000
Nvidia driver version: 530.30.02
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:                   46 bits physical, 48 bits virtual
Byte Order:                      Little Endian
CPU(s):                          20
On-line CPU(s) list:             0-19
Vendor ID:                       GenuineIntel
Model name:                      12th Gen Intel(R) Core(TM) i7-12700
CPU family:                      6
Model:                           151
Thread(s) per core:              2
Core(s) per socket:              12
Socket(s):                       1
Stepping:                        2
CPU max MHz:                     4900.0000
CPU min MHz:                     800.0000
BogoMIPS:                        4224.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 tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl vmx smx 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 bmi1 avx2 smep bmi2 erms invpcid rdseed adx smap clflushopt clwb intel_pt sha_ni xsaveopt xsavec xgetbv1 xsaves split_lock_detect avx_vnni dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp hwp_pkg_req hfi umip pku ospke waitpkg gfni vaes vpclmulqdq tme rdpid movdiri movdir64b fsrm md_clear serialize pconfig arch_lbr ibt flush_l1d arch_capabilities
Virtualization:                  VT-x
L1d cache:                       512 KiB (12 instances)
L1i cache:                       512 KiB (12 instances)
L2 cache:                        12 MiB (9 instances)
L3 cache:                        25 MiB (1 instance)
NUMA node(s):                    1
NUMA node0 CPU(s):               0-19
Vulnerability Itlb multihit:     Not affected
Vulnerability L1tf:              Not affected
Vulnerability Mds:               Not affected
Vulnerability Meltdown:          Not affected
Vulnerability Mmio stale data:   Not affected
Vulnerability Retbleed:          Not affected
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:             Not affected
Vulnerability Tsx async abort:   Not affected

Versions of relevant libraries:
[pip3] numpy==1.23.5
[pip3] torch==2.0.0
[pip3] torchaudio==2.0.0
[pip3] torchvision==0.15.0
[pip3] triton==2.0.0
[conda] blas                      1.0                         mkl  
[conda] ffmpeg                    4.3                  hf484d3e_0    pytorch
[conda] mkl                       2021.4.0           h06a4308_640  
[conda] mkl-service               2.4.0           py310h7f8727e_0  
[conda] mkl_fft                   1.3.1           py310hd6ae3a3_0  
[conda] mkl_random                1.2.2           py310h00e6091_0  
[conda] numpy                     1.23.5          py310hd5efca6_0  
[conda] numpy-base                1.23.5          py310h8e6c178_0  
[conda] pytorch                   2.0.0           py3.10_cuda11.7_cudnn8.5.0_0    pytorch
[conda] pytorch-cuda              11.7                 h778d358_3    pytorch
[conda] pytorch-mutex             1.0                        cuda    pytorch
[conda] torchaudio                2.0.0               py310_cu117    pytorch
[conda] torchtriton               2.0.0                     py310    pytorch
[conda] torchvision               0.15.0              py310_cu117    pytorch
</details>

cc @ezyang @gchanan @zou3519 @kadeng @msaroufim @bdhirsh @anijain2305 @chauhang @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @chenyang78 @aakhundov @soumith @wconstab @ngimel @Xia-Weiwen @desertfire