Repository: pytorch
Issue: torch.export doesn't handle functools.partial correctly.
Labels: low priority,triaged,module: dynamo,oncall: export

### 🐛 Describe the bug

I would like to use `functools.partial` along with `torch.export` to simplify graph export, but torch.export doesn't seem to handle functools.partial as expected. A minimal reproducible example below:

```python
import torch
import functools

EXAMPLE_ARGS = (
        torch.randn(4, 4), torch.randn(4, 4), torch.randn(4)
        )

# some common function that can be parameterized.
def linear_common(x: torch.Tensor, w: torch.Tensor, b:torch.Tensor, relu_en):

    y = torch.ops.aten.linear(x, w, b)
    if relu_en:
        y = torch.ops.aten.relu(y)
    return y

# Case-A parameterize explicitly.
def linear_common_relu(x: torch.Tensor, w: torch.Tensor, b:torch.Tensor):
    return linear_common(x, w, b, relu_en=True)
m0 = torch.export.export(linear_common_relu, EXAMPLE_ARGS)
print('m0')
print('--')
print(m0.module().code)

# Case-B: Use functools.partial
print('m1')
print('--')
m1 = torch.export.export(functools.partial(linear_common, relu_en=True), EXAMPLE_ARGS)
print(m1.module().code)
```
In the above example Case-A works correctly, while Case-B produces the following error in my torch environment (Version: `2.2.0.dev20231010+cpu`).

```
[2024-01-22 18:17:43,850] torch._dynamo.eval_frame: [WARNING] could not determine __code__ for functools.partial(<function linear_common at 0x7fc04dc731f0>, relu_en=True)
[2024-01-22 18:17:43,871] torch._dynamo.eval_frame: [WARNING] could not determine __code__ for functools.partial(<function linear_common at 0x7fc04dc731f0>, relu_en=True)
Traceback (most recent call last):
  File "tests/repro/partial.py", line 26, in <module>
    m1 = torch.export.export(functools.partial(linear_common, relu_en=True), EXAMPLE_ARGS)
  File "/local/mnt/workspace/.executorch/lib/python3.8/site-packages/torch/export/__init__.py", line 586, in export
    return export__RC__(f, args, kwargs, dynamic_shapes=dynamic_shapes)
  File "/local/mnt/workspace/.executorch/lib/python3.8/site-packages/torch/_export/__init__.py", line 95, in export__RC__
    return export(f, args, kwargs)
  File "/local/mnt/workspace/.executorch/lib/python3.8/site-packages/torch/_export/__init__.py", line 470, in export
    return _export(
  File "/local/mnt/workspace/.executorch/lib/python3.8/site-packages/torch/_export/__init__.py", line 537, in _export
    gm_torch_level, _ = torch._dynamo.export(
  File "/local/mnt/workspace/.executorch/lib/python3.8/site-packages/torch/_dynamo/eval_frame.py", line 1221, in inner
    and not skipfiles.check(inspect.getsourcefile(call_to_inspect))
  File "/usr/lib/python3.8/inspect.py", line 696, in getsourcefile
    filename = getfile(object)
  File "/local/mnt/workspace/.executorch/lib/python3.8/site-packages/torch/package/package_importer.py", line 696, in _patched_getfile
    return _orig_getfile(object)
  File "/usr/lib/python3.8/inspect.py", line 676, in getfile
    raise TypeError('module, class, method, function, traceback, frame, or '
TypeError: module, class, method, function, traceback, frame, or code object was expected, got partial
```

# Expected Result

Both Case-A and Case-B works as expected. As our libraries get more complicated, having to define each specialization explicitly creates quite a bit of unnecessary repetition and verbosity. If `functools.partial` won't be supported, is there any other way to achieve the similar effect as Case-B?


### Versions

PyTorch version: 2.2.0.dev20231010+cpu
Is debug build: False
CUDA used to build PyTorch: Could not collect
ROCM used to build PyTorch: N/A

OS: Ubuntu 20.04.6 LTS (x86_64)
GCC version: (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0
Clang version: Could not collect
CMake version: version 3.28.1
Libc version: glibc-2.31

Python version: 3.8.10 (default, May 26 2023, 14:05:08)  [GCC 9.4.0] (64-bit runtime)
Python platform: Linux-5.4.0-146-generic-x86_64-with-glibc2.29
Is CUDA available: False
CUDA runtime version: Could not collect
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: GPU 0: GRID A100D-10C
Nvidia driver version: 525.60.13
cuDNN version: Could not collect
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

Versions of relevant libraries:
[pip3] executorch==0.1.0
[pip3] numpy==1.24.4
[pip3] torch==2.2.0.dev20231010+cpu
[pip3] torchaudio==2.2.0.dev20231010+cpu
[pip3] torchsr==1.0.4
[pip3] torchvision==0.17.0.dev20231010+cpu
[conda] Could not collect


cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @chenyang78 @aakhundov @kadeng @avikchaudhuri @gmagogsfm @zhxchen17 @tugsbayasgalan @angelayi @suo @ydwu4