Export to ONNX with export_modules_as_functions works wrong
Labels: module: onnx, triaged

### 🐛 Describe the bug

Export to onnx with `export_modules_as_functions` provides wrong types in  some cases. Here is short example which result that first `some_op` has type `SomeOp.1` but second `SomeOp`.

```python
class SomeOp(torch.nn.Module):
    def __init__(self):
        super(SomeOp, self).__init__()

    def forward(self, x: torch.Tensor, y: torch.Tensor) -> torch.Tensor:
        height, width = x.shape[2:]
        res = torch.cat([y[:, 0:1, :, :] / width, y[:, 1:2, :, :] / height], 1)
        return res


class TestNet(torch.nn.Module):
    def __init__(self):
        super().__init__()

        self.conv = torch.nn.Conv2d(2, 2, 1)
        self.some_op = SomeOp()

    def forward(self, x, y):
        return self.some_op(self.some_op(x, y), y)

net = TestNet()
x = torch.rand((1, 2, 16, 16))
y = torch.rand((1, 2, 16, 16))
onnx_path = os.path.join(this_dir, 'test.onnx')
torch.onnx.export(net, (x, y), onnx_path,
                      verbose=True, opset_version=16,
                      export_modules_as_functions={SomeOp})
```

Result graph:
```
Exported graph: graph(%onnx::Slice_1 : Float(1, 2, 16, 16, strides=[512, 256, 16, 1], requires_grad=0, device=cpu)):
   = onnx::LocalFunctionDef[graph=<Graph>, name="SomeOp.1", domain="__main__", attributes=annotate(List[str], [])]()
   = onnx::LocalFunctionDef[graph=<Graph>, name="SomeOp", domain="__main__", attributes=annotate(List[str], [])]()
  %/some_op/SomeOp.1_output_0 : Float(1, 1, 16, 16, strides=[512, 256, 16, 1], requires_grad=0, device=cpu), %/some_op/SomeOp.1_output_1 : Float(1, 1, 16, 16, strides=[512, 256, 16, 1], requires_grad=0, device=cpu) = __main__::SomeOp.1[onnx_name="/some_op/SomeOp.1"](%onnx::Slice_1), scope: __main__.TestNet::/__main__.SomeOp::some_op
  %19 : Float(1, 2, 16, 16, strides=[512, 256, 16, 1], requires_grad=0, device=cpu) = __main__::SomeOp[onnx_name="/some_op_1/SomeOp"](%/some_op/SomeOp.1_output_0, %/some_op/SomeOp.1_output_1), scope: __main__.TestNet::/__main__.SomeOp::some_op
  return (%19)
```

<img width="230" alt="image" src="https://user-images.githubusercontent.com/2921717/204782411-3cd94964-0fca-4362-ba05-91d748188b0c.png">


### Versions

PyTorch version: 1.13.0
Is debug build: False
CUDA used to build PyTorch: None
ROCM used to build PyTorch: N/A

OS: macOS 12.4 (x86_64)
GCC version: Could not collect
Clang version: 13.1.6 (clang-1316.0.21.2.5)
CMake version: version 3.24.2
Libc version: N/A

Python version: 3.10.6 | packaged by conda-forge | (main, Aug 22 2022, 20:43:44) [Clang 13.0.1 ] (64-bit runtime)
Python platform: macOS-12.4-x86_64-i386-64bit
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

Versions of relevant libraries:
[pip3] numpy==1.23.5
[pip3] torch==1.13.0
[conda] libblas                   3.9.0              16_osx64_mkl    conda-forge
[conda] libcblas                  3.9.0              16_osx64_mkl    conda-forge
[conda] liblapack                 3.9.0              16_osx64_mkl    conda-forge
[conda] liblapacke                3.9.0              16_osx64_mkl    conda-forge
[conda] mkl                       2022.1.0           hf3af037_209
[conda] numpy                     1.23.5                   pypi_0    pypi
[conda] torch                     1.13.0                   pypi_0    pypi