Repository: pytorch
Issue: torch.jit.script not work for ParameterDict.items 
Labels: oncall: jit

### 🐛 Describe the bug

As it says in the title, using `ParameterDict.items()` will break `torch.jit.script` as seen below
```
import torch
from torch import nn 

class MyModule(nn.Module):
    def __init__(self):
        super().__init__()
        self.parameter_dict = nn.ParameterDict(
            {str(i): nn.Parameter(torch.tensor(float(i))) for i in range(10)})
        
    def forward(self, x):
        z = x
        for k, v in self.parameter_dict.items():
            z = v * x + z
        return z

m = MyModule()
torch.jit.script(m)
```
Raise:
```
RuntimeError: 
Unknown type constructor Iterable:
  File "/home/gegejun/anaconda3/envs/gpu/lib/python3.9/site-packages/torch/nn/modules/container.py", line 834
    def items(self) -> Iterable[Tuple[str, Any]]:
                       ~~~~~~~~~~~~~~~~~~~~~~~~~ <--- HERE
        r"""Return an iterable of the ParameterDict key/value pairs."""
        return ((k, self[k]) for k in self._keys)
'ParameterDict.items' is being compiled since it was called from 'MyModule.forward'
  File "/tmp/ipykernel_3141/4073268505.py", line 12
    def forward(self, x):
        z = x
        for k, v in self.parameter_dict.items():
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            z = v * x + z
            ~~~~~~~~~~~~~ <--- HERE
        return z
```

### Versions

PyTorch version: 2.2.2+cu121
Is debug build: False
CUDA used to build PyTorch: 12.1
ROCM used to build PyTorch: N/A

OS: Ubuntu 20.04.4 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.23.1
Libc version: glibc-2.31

Python version: 3.9.12 (main, Apr  5 2022, 06:56:58)  [GCC 7.5.0] (64-bit runtime)
Python platform: Linux-5.10.102.1-microsoft-standard-WSL2-x86_64-with-glibc2.31
Is CUDA available: True
CUDA runtime version: 12.1.66
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration: GPU 0: NVIDIA GeForce RTX 2070
Nvidia driver version: 551.86
cuDNN version: Probably one of the following:
/usr/local/cuda-11.6/targets/x86_64-linux/lib/libcudnn.so.8.3.3
/usr/local/cuda-11.6/targets/x86_64-linux/lib/libcudnn_adv_infer.so.8.3.3
/usr/local/cuda-11.6/targets/x86_64-linux/lib/libcudnn_adv_train.so.8.3.3
/usr/local/cuda-11.6/targets/x86_64-linux/lib/libcudnn_cnn_infer.so.8.3.3
/usr/local/cuda-11.6/targets/x86_64-linux/lib/libcudnn_cnn_train.so.8.3.3
/usr/local/cuda-11.6/targets/x86_64-linux/lib/libcudnn_ops_infer.so.8.3.3
/usr/local/cuda-11.6/targets/x86_64-linux/lib/libcudnn_ops_train.so.8.3.3
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:                   39 bits physical, 48 bits virtual
CPU(s):                          12
On-line CPU(s) list:             0-11
Thread(s) per core:              2
Core(s) per socket:              6
Socket(s):                       1
Vendor ID:                       GenuineIntel
CPU family:                      6
Model:                           158
Model name:                      Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz
Stepping:                        10
CPU MHz:                         3192.010
BogoMIPS:                        6384.02
Virtualization:                  VT-x
Hypervisor vendor:               Microsoft
Virtualization type:             full
L1d cache:                       192 KiB
L1i cache:                       192 KiB
L2 cache:                        1.5 MiB
L3 cache:                        12 MiB
Vulnerability Itlb multihit:     KVM: Mitigation: VMX disabled
Vulnerability L1tf:              Mitigation; PTE Inversion; VMX conditional cache flushes, SMT vulnerable
Vulnerability Mds:               Mitigation; Clear CPU buffers; SMT Host state unknown
Vulnerability Meltdown:          Mitigation; PTI
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; Full generic retpoline, IBPB conditional, IBRS_FW, STIBP conditional, RSB filling
Vulnerability Srbds:             Unknown: Dependent on hypervisor status
Vulnerability Tsx async abort:   Mitigation; Clear CPU buffers; 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 cpuid pni pclmulqdq vmx ssse3 fma cx16 pcid sse4_1 sse4_2 movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi ept vpid ept_ad fsgsbase bmi1 hle avx2 smep bmi2 erms invpcid rtm rdseed adx smap clflushopt xsaveopt xsavec xgetbv1 xsaves md_clear flush_l1d arch_capabilities

Versions of relevant libraries:
[pip3] numpy==1.21.5
[pip3] pytorch-lightning==2.0.7
[pip3] torch==2.2.2
[pip3] torch_cluster==1.6.3+pt22cu121
[pip3] torch_geometric==2.5.2
[pip3] torch-runstats==0.2.0
[pip3] torch_scatter==2.1.2+pt22cu121
[pip3] torch_sparse==0.6.18+pt22cu121
[pip3] torch_spline_conv==1.2.2+pt22cu121
[pip3] torch-tb-profiler==0.4.0
[pip3] torchaudio==2.2.1+cu121
[pip3] torchmetrics==1.0.3
[pip3] torchvision==0.17.1+cu121
[pip3] triton==2.2.0
[pip3] xitorch==0.3.0
[conda] blas                      1.0                         mkl    http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
[conda] cudatoolkit               11.3.1               h2bc3f7f_2    http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
[conda] ffmpeg                    4.3                  hf484d3e_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch
[conda] mkl                       2021.4.0           h06a4308_640    http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
[conda] mkl-service               2.4.0            py39h7f8727e_0    http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
[conda] mkl_fft                   1.3.1            py39hd3c417c_0    http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
[conda] mkl_random                1.2.2            py39h51133e4_0    http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
[conda] numpy                     1.21.5           py39he7a7128_1    http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
[conda] numpy-base                1.21.5           py39hf524024_1    http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
[conda] pytorch-lightning         2.0.7                    pypi_0    pypi
[conda] pytorch-mutex             1.0                        cuda    https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch
[conda] torch                     2.2.2                    pypi_0    pypi
[conda] torch-cluster             1.6.3+pt22cu121          pypi_0    pypi
[conda] torch-geometric           2.5.2                    pypi_0    pypi
[conda] torch-runstats            0.2.0                    pypi_0    pypi
[conda] torch-scatter             2.1.2+pt22cu121          pypi_0    pypi
[conda] torch-sparse              0.6.18+pt22cu121          pypi_0    pypi
[conda] torch-spline-conv         1.2.2+pt22cu121          pypi_0    pypi
[conda] torch-tb-profiler         0.4.0                    pypi_0    pypi
[conda] torchaudio                2.2.1+cu121              pypi_0    pypi
[conda] torchmetrics              1.0.3                    pypi_0    pypi
[conda] torchvision               0.17.1+cu121             pypi_0    pypi
[conda] triton                    2.2.0                    pypi_0    pypi
[conda] xitorch                   0.3.0                    pypi_0    pypi

cc @EikanWang @jgong5 @wenzhe-nrv @sanchitintel