Repository: pytorch
Issue: ONNX export of any TorchScript submodule (scripted or traced) fails with "Modules that are called during a trace must be registered as submodules of the thing being traced" 
Labels: oncall: jit,module: onnx

### 🐛 Describe the bug

This is re-spin of #47887, making sure it gets the attention it deserves.
This bug prevents any use of scripted modules in ONNX export. 
Here is extended repro source - it illustrates the fact neither script nor trace works, and the fact that the memory address the exporter complains about, does not belong to original unscripted module. 

```
import torch

class Inner(torch.nn.Module):
    def forward(self, x):
        return (x, )

class Outer(torch.nn.Module):
    def __init__(self):   
        super().__init__()
        i = Inner()
        self.inner = torch.jit.script(i)
        # self.inner = torch.jit.trace(i, torch.zeros(1))                                                                                                                                            
        print (hex(id(i)), hex(id(self.inner)))

    def forward(self, x):   
        return self.inner(x)
```
x = torch.zeros(1)
m = Outer()
print (hex(id(m)), hex(id(m.inner)))
for idx, mm in enumerate(m.modules()):
    print(idx, '->', mm)
torch.onnx.export(m, (x,), 'test.onnx')



### Versions

root@30f44d0dcd3f:/git/radtts# python collect_env.py
Collecting environment information...
PyTorch version: 1.13.0a0+d321be6
Is debug build: False
CUDA used to build PyTorch: 11.7
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.3
Libc version: glibc-2.31

Python version: 3.8.13 | packaged by conda-forge | (default, Mar 25 2022, 06:04:10)  [GCC 10.3.0] (64-bit runtime)
Python platform: Linux-5.15.0-46-generic-x86_64-with-glibc2.10
Is CUDA available: True
CUDA runtime version: 11.7.99
GPU models and configuration: GPU 0: NVIDIA RTX A5000
Nvidia driver version: 515.65.01
cuDNN version: Probably one of the following:
/usr/lib/x86_64-linux-gnu/libcudnn.so.8.5.0
/usr/lib/x86_64-linux-gnu/libcudnn_adv_infer.so.8.5.0
/usr/lib/x86_64-linux-gnu/libcudnn_adv_train.so.8.5.0
/usr/lib/x86_64-linux-gnu/libcudnn_cnn_infer.so.8.5.0
/usr/lib/x86_64-linux-gnu/libcudnn_cnn_train.so.8.5.0
/usr/lib/x86_64-linux-gnu/libcudnn_ops_infer.so.8.5.0
/usr/lib/x86_64-linux-gnu/libcudnn_ops_train.so.8.5.0
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

Versions of relevant libraries:
[pip3] k2==1.19.dev20220911+cuda11.7.torch1.13.0a0
[pip3] numpy==1.22.4
[pip3] pytorch-lightning==1.7.5
[pip3] pytorch-quantization==2.1.2
[pip3] torch==1.13.0a0+d321be6
[pip3] torch-tensorrt==1.2.0a0
[pip3] torchaudio==0.13.0
[pip3] torchmetrics==0.9.3
[pip3] torchvision==0.14.0a0
[conda] k2                        1.19.dev20220911+cuda11.7.torch1.13.0a0          pypi_0    pypi
[conda] mkl                       2020.4             h726a3e6_304    conda-forge
[conda] mkl-include               2020.4             h726a3e6_304    conda-forge
[conda] numpy                     1.22.4           py38h99721a1_0    conda-forge
[conda] pytorch-lightning         1.7.5                    pypi_0    pypi
[conda] pytorch-quantization      2.1.2                    pypi_0    pypi
[conda] torch                     1.13.0a0+d321be6          pypi_0    pypi
[conda] torch-tensorrt            1.2.0a0                  pypi_0    pypi
[conda] torchaudio                0.13.0                   pypi_0    pypi
[conda] torchmetrics              0.9.3                    pypi_0    pypi
[conda] torchvision               0.14.0a0                 pypi_0    pypi