ONNX model different to pytorch and jit trace output
Labels: module: onnx, triaged

### 🐛 Describe the bug

When exporting a model from [https://github.com/sw-gong/spiralnet_plus](https://github.com/sw-gong/spiralnet_plus) using onnx, the onnx model produces a different output than the original model, or script created with the jit tracer. The onnx exporter does not give any warnings or something similar.
I modified the network of the original project slightly.

The model is exported using the following code:
```    
dummy_input = torch.ones((1, num_value)).to(device)
with torch.no_grad():
    torch.onnx.export(model, dummy_input, fileName, opset_version=12) 
``` 

To reproduce, please download the minimal version of this project from gdrive ([spiralMini](https://drive.google.com/drive/folders/1rSnYQbDi2gMInePNwUOSzk-Z0lTBWxx0?usp=sharing)) and execute main.py .
It creates a onnx file and a jit trace and runs them and the original model. It then asserts the results to the original.

It tested this with the environment below and a Ubuntu installation with pytorch 2.0.0 with the same error.

### Versions

PyTorch version: 1.12.1
Is debug build: False
CUDA used to build PyTorch: 11.6
ROCM used to build PyTorch: N/A

OS: Microsoft Windows 10 Pro
GCC version: Could not collect
Clang version: Could not collect
CMake version: version 3.26.0
Libc version: N/A

Python version: 3.9.16 (main, Jan 11 2023, 16:16:36) [MSC v.1916 64 bit (AMD64)] (64-bit runtime)
Python platform: Windows-10-10.0.19045-SP0
Is CUDA available: True
CUDA runtime version: 11.7.99
CUDA_MODULE_LOADING set to:
GPU models and configuration: GPU 0: NVIDIA GeForce GTX 1080 Ti
Nvidia driver version: 528.02
cuDNN version: Could not collect
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

CPU:
Architecture=9
CurrentClockSpeed=4200
DeviceID=CPU0
Family=198
L2CacheSize=1024
L2CacheSpeed=
Manufacturer=GenuineIntel
MaxClockSpeed=4200
Name=Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz
ProcessorType=3
Revision=

Versions of relevant libraries:
[pip3] numpy==1.23.5
[pip3] torch==1.12.1
[pip3] torch-cluster==1.6.0
[pip3] torch-geometric==2.1.0.post1
[pip3] torch-scatter==2.0.9
[pip3] torch-sparse==0.6.15
[pip3] torchaudio==0.12.1
[pip3] torchvision==0.13.1
[conda] blas                      1.0                         mkl
[conda] cudatoolkit               11.6.0              hc0ea762_10    conda-forge
[conda] mkl                       2021.4.0           haa95532_640
[conda] mkl-include               2022.1.0           h6a75c08_874    conda-forge
[conda] mkl-service               2.4.0            py39h2bbff1b_0
[conda] mkl_fft                   1.3.1            py39h277e83a_0
[conda] mkl_random                1.2.2            py39hf11a4ad_0
[conda] numpy                     1.23.5           py39h3b20f71_0
[conda] numpy-base                1.23.5           py39h4da318b_0
[conda] pyg                       2.1.0           py39_torch_1.12.0_cu116    pyg
[conda] pytorch                   1.12.1          py3.9_cuda11.6_cudnn8_0    pytorch
[conda] pytorch-cluster           1.6.0           py39_torch_1.12.0_cu116    pyg
[conda] pytorch-mutex             1.0                        cuda    pytorch
[conda] pytorch-scatter           2.0.9           py39_torch_1.12.0_cu116    pyg
[conda] pytorch-sparse            0.6.15          py39_torch_1.12.0_cu116    pyg
[conda] torchaudio                0.12.1               py39_cu116    pytorch
[conda] torchvision               0.13.1               py39_cu116    pytorch