Repository: pytorch
Issue: torch.onnx.dynamo_export
Labels: module: onnx,triaged

### 🐛 Describe the bug

I tried to use torch.onnx.dynamo_export to convert my model that contains the torch.fft.rfft operation. After using fourier, an error occurred during batchnormalize. I checked that my input was tensor and had grad_fn. I would like to ask this How to deal with segmentation fault messages?


error :
/home/dgxadmin/anaconda3/envs/oct/lib/python3.10/site-packages/torch/onnx/_internal/exporter.py:137: UserWarning: torch.onnx.dynamo_export only implements opset version 18 for now. If you need to use a different opset version, please register them with register_custom_op.
  warnings.warn(
Traceback (most recent call last):
  File "/home/dgxadmin/anaconda3/envs/oct/lib/python3.10/site-packages/torch/onnx/_internal/exporter.py", line 1433, in dynamo_export
    ).export()
  File "/home/dgxadmin/anaconda3/envs/oct/lib/python3.10/site-packages/torch/onnx/_internal/exporter.py", line 1175, in export
    graph_module = self.options.fx_tracer.generate_fx(
  File "/home/dgxadmin/anaconda3/envs/oct/lib/python3.10/site-packages/torch/onnx/_internal/fx/dynamo_graph_extractor.py", line 232, in generate_fx
    return self.pre_export_passes(options, model, graph_module, updated_model_args)  # type: ignore[return-value]
  File "/home/dgxadmin/anaconda3/envs/oct/lib/python3.10/site-packages/torch/onnx/_internal/fx/dynamo_graph_extractor.py", line 242, in pre_export_passes
    return exporter.common_pre_export_passes(
  File "/home/dgxadmin/anaconda3/envs/oct/lib/python3.10/site-packages/torch/onnx/_internal/exporter.py", line 1472, in common_pre_export_passes
    module = passes.Functionalize(
  File "/home/dgxadmin/anaconda3/envs/oct/lib/python3.10/site-packages/torch/onnx/_internal/diagnostics/infra/decorator.py", line 151, in wrapper
    ctx.log_and_raise_if_error(diag)
  File "/home/dgxadmin/anaconda3/envs/oct/lib/python3.10/site-packages/torch/onnx/_internal/diagnostics/infra/context.py", line 366, in log_and_raise_if_error
    raise diagnostic.source_exception
  File "/home/dgxadmin/anaconda3/envs/oct/lib/python3.10/site-packages/torch/onnx/_internal/diagnostics/infra/decorator.py", line 135, in wrapper
    return_values = fn(*args, **kwargs)
  File "/home/dgxadmin/anaconda3/envs/oct/lib/python3.10/site-packages/torch/onnx/_internal/fx/_pass.py", line 275, in run
    module = self._run(*args, **kwargs)
  File "/home/dgxadmin/anaconda3/envs/oct/lib/python3.10/site-packages/torch/onnx/_internal/fx/passes/functionalization.py", line 123, in _run
    graph_module = proxy_tensor.make_fx(
  File "/home/dgxadmin/anaconda3/envs/oct/lib/python3.10/site-packages/torch/fx/experimental/proxy_tensor.py", line 871, in wrapped
    t = dispatch_trace(wrap_key(func, args, fx_tracer, pre_dispatch), tracer=fx_tracer, concrete_args=tuple(phs))
  File "/home/dgxadmin/anaconda3/envs/oct/lib/python3.10/site-packages/torch/_compile.py", line 24, in inner
    return torch._dynamo.disable(fn, recursive)(*args, **kwargs)
  File "/home/dgxadmin/anaconda3/envs/oct/lib/python3.10/site-packages/torch/_dynamo/eval_frame.py", line 489, in _fn
    return fn(*args, **kwargs)
  File "/home/dgxadmin/anaconda3/envs/oct/lib/python3.10/site-packages/torch/_dynamo/external_utils.py", line 17, in inner
    return fn(*args, **kwargs)
  File "/home/dgxadmin/anaconda3/envs/oct/lib/python3.10/site-packages/torch/fx/experimental/proxy_tensor.py", line 483, in dispatch_trace
    graph = tracer.trace(root, concrete_args)
  File "/home/dgxadmin/anaconda3/envs/oct/lib/python3.10/site-packages/torch/_dynamo/eval_frame.py", line 489, in _fn
    return fn(*args, **kwargs)
  File "/home/dgxadmin/anaconda3/envs/oct/lib/python3.10/site-packages/torch/_dynamo/external_utils.py", line 17, in inner
    return fn(*args, **kwargs)
  File "/home/dgxadmin/anaconda3/envs/oct/lib/python3.10/site-packages/torch/fx/_symbolic_trace.py", line 821, in trace
    (self.create_arg(fn(*args)),),
  File "/home/dgxadmin/anaconda3/envs/oct/lib/python3.10/site-packages/torch/fx/experimental/proxy_tensor.py", line 519, in wrapped
    out = f(*tensors)
  File "<string>", line 1, in <lambda>
  File "/home/dgxadmin/anaconda3/envs/oct/lib/python3.10/site-packages/torch/onnx/_internal/fx/passes/functionalization.py", line 86, in wrapped
    out = function(*inputs_functional)
  File "/home/dgxadmin/anaconda3/envs/oct/lib/python3.10/site-packages/torch/onnx/_internal/fx/passes/_utils.py", line 30, in wrapped
    return torch.fx.Interpreter(graph_module).run(*args)
  File "/home/dgxadmin/anaconda3/envs/oct/lib/python3.10/site-packages/torch/fx/interpreter.py", line 138, in run
    self.env[node] = self.run_node(node)
  File "/home/dgxadmin/anaconda3/envs/oct/lib/python3.10/site-packages/torch/fx/interpreter.py", line 195, in run_node
    return getattr(self, n.op)(n.target, args, kwargs)
  File "/home/dgxadmin/anaconda3/envs/oct/lib/python3.10/site-packages/torch/fx/interpreter.py", line 267, in call_function
    return target(*args, **kwargs)
  File "/home/dgxadmin/anaconda3/envs/oct/lib/python3.10/site-packages/torch/_ops.py", line 513, in __call__
    return self._op(*args, **(kwargs or {}))
RuntimeError: false INTERNAL ASSERT FAILED at "/opt/conda/conda-bld/pytorch_1708025831440/work/build/aten/src/ATen/RegisterFunctionalization_2.cpp":8038, please report a bug to PyTorch. mutating a non-functional tensor with a functional tensor is not allowed. Please ensure that all of your inputs are wrapped inside of a functionalize() call.

While executing %_native_batch_norm_legit : [num_users=3] = call_function[target=torch.ops.aten._native_batch_norm_legit.default](args = (%convolution, %_param_constant1, %_param_constant2, %_tensor_constant1, %_tensor_constant2, True, 0.1, 1e-05), kwargs = {})
Original traceback:
  File "/home/dgxadmin/OCT/mymodel.py", line 134, in forward
    output = self.fu(x)
  File "/home/dgxadmin/anaconda3/envs/oct/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1520, in _call_impl
    return forward_call(*args, **kwargs)
  File "/home/dgxadmin/OCT/mymodel.py", line 89, in forward
    ffted = self.bn(ffted)


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/dgxadmin/OCT/mymodel.py", line 159, in <module>
    onnx_program = torch.onnx.dynamo_export(model, input)
  File "/home/dgxadmin/anaconda3/envs/oct/lib/python3.10/site-packages/torch/onnx/_internal/exporter.py", line 1444, in dynamo_export
    raise OnnxExporterError(
torch.onnx.OnnxExporterError: Failed to export the model to ONNX. Generating SARIF report at 'report_dynamo_export.sarif'. SARIF is a standard format for the output of static analysis tools. SARIF logs can be loaded in VS Code SARIF viewer extension, or SARIF web viewer (https://microsoft.github.io/sarif-web-component/). Please report a bug on PyTorch Github: https://github.com/pytorch/pytorch/issues

### Versions

# packages in environment at /home/dgxadmin/anaconda3/envs/oct:
#
# Name                    Version                   Build  Channel
_libgcc_mutex             0.1                        main  
_openmp_mutex             5.1                       1_gnu  
blas                      1.0                         mkl  
bzip2                     1.0.8                h7b6447c_0  
ca-certificates           2023.12.12           h06a4308_0  
certifi                   2024.2.2                 pypi_0    pypi
charset-normalizer        2.0.4              pyhd3eb1b0_0  
contourpy                 1.2.0                    pypi_0    pypi
cuda-cudart               11.8.89                       0    nvidia
cuda-cupti                11.8.87                       0    nvidia
cuda-libraries            11.8.0                        0    nvidia
cuda-nvrtc                11.8.89                       0    nvidia
cuda-nvtx                 11.8.86                       0    nvidia
cuda-runtime              11.8.0                        0    nvidia
cycler                    0.12.1                   pypi_0    pypi
ffmpeg                    4.3                  hf484d3e_0    pytorch
filelock                  3.13.1                   pypi_0    pypi
fonttools                 4.49.0                   pypi_0    pypi
freetype                  2.12.1               h4a9f257_0  
fsspec                    2024.2.0                 pypi_0    pypi
gmp                       6.2.1                h295c915_3  
gmpy2                     2.1.2                    pypi_0    pypi
gnutls                    3.6.15               he1e5248_0  
idna                      3.4                      pypi_0    pypi
imageio                   2.34.0                   pypi_0    pypi
intel-openmp              2023.1.0         hdb19cb5_46306  
jinja2                    3.1.3                    pypi_0    pypi
jpeg                      9e                   h5eee18b_1  
kiwisolver                1.4.5                    pypi_0    pypi
kornia                    0.7.1                    pypi_0    pypi
lame                      3.100                h7b6447c_0  
lazy-loader               0.3                      pypi_0    pypi
lcms2                     2.12                 h3be6417_0  
ld_impl_linux-64          2.38                 h1181459_1  
lerc                      3.0                  h295c915_0  
libcublas                 11.11.3.6                     0    nvidia
libcufft                  10.9.0.58                     0    nvidia
libcufile                 1.8.1.2                       0    nvidia
libcurand                 10.3.4.107                    0    nvidia
libcusolver               11.4.1.48                     0    nvidia
libcusparse               11.7.5.86                     0    nvidia
libdeflate                1.17                 h5eee18b_1  
libffi                    3.4.4                h6a678d5_0  
libgcc-ng                 11.2.0               h1234567_1  
libgomp                   11.2.0               h1234567_1  
libiconv                  1.16                 h7f8727e_2  
libidn2                   2.3.4                h5eee18b_0  
libjpeg-turbo             2.0.0                h9bf148f_0    pytorch
libnpp                    11.8.0.86                     0    nvidia
libnvjpeg                 11.9.0.86                     0    nvidia
libpng                    1.6.39               h5eee18b_0  
libstdcxx-ng              11.2.0               h1234567_1  
libtasn1                  4.19.0               h5eee18b_0  
libtiff                   4.5.1                h6a678d5_0  
libunistring              0.9.10               h27cfd23_0  
libuuid                   1.41.5               h5eee18b_0  
libwebp-base              1.3.2                h5eee18b_0  
llvm-openmp               14.0.6               h9e868ea_0  
lz4-c                     1.9.4                h6a678d5_0  
markupsafe                2.1.3                    pypi_0    pypi
matplotlib                3.8.2                    pypi_0    pypi
mkl                       2023.1.0         h213fc3f_46344  
mkl-fft                   1.3.8                    pypi_0    pypi
mkl-random                1.2.4                    pypi_0    pypi
mkl-service               2.4.0                    pypi_0    pypi
mkl_fft                   1.3.8           py310h5eee18b_0  
mkl_random                1.2.4           py310hdb19cb5_0  
mpc                       1.1.0                h10f8cd9_1  
mpfr                      4.0.2                hb69a4c5_1  
mpmath                    1.3.0                    pypi_0    pypi
ncurses                   6.4                  h6a678d5_0  
nettle                    3.7.3                hbbd107a_1  
networkx                  3.1                      pypi_0    pypi
numpy                     1.26.3                   pypi_0    pypi
numpy-base                1.26.3          py310hb5e798b_0  
onnx                      1.15.0                   pypi_0    pypi
onnxscript                0.1.0.dev20240223          pypi_0    pypi
opencv-python             4.9.0.80                 pypi_0    pypi
openh264                  2.1.1                h4ff587b_0  
openjpeg                  2.4.0                h3ad879b_0  
openssl                   3.0.13               h7f8727e_0  
packaging                 23.2                     pypi_0    pypi
pillow                    10.2.0                   pypi_0    pypi
pip                       23.3.1                   pypi_0    pypi
protobuf                  4.25.3                   pypi_0    pypi
pyparsing                 3.1.1                    pypi_0    pypi
python                    3.10.13              h955ad1f_0  
python-dateutil           2.8.2                    pypi_0    pypi
pytorch                   2.2.1           py3.10_cuda11.8_cudnn8.7.0_0    pytorch
pytorch-cuda              11.8                 h7e8668a_5    pytorch
pytorch-mutex             1.0                        cuda    pytorch
pyyaml                    6.0.1                    pypi_0    pypi
readline                  8.2                  h5eee18b_0  
requests                  2.31.0                   pypi_0    pypi
scikit-image              0.22.0                   pypi_0    pypi
scipy                     1.12.0                   pypi_0    pypi
setuptools                68.2.2                   pypi_0    pypi
six                       1.16.0                   pypi_0    pypi
sqlite                    3.41.2               h5eee18b_0  
sympy                     1.12                     pypi_0    pypi
tbb                       2021.8.0             hdb19cb5_0  
tifffile                  2024.2.12                pypi_0    pypi
tk                        8.6.12               h1ccaba5_0  
torch                     2.2.1                    pypi_0    pypi
torchaudio                2.2.1                    pypi_0    pypi
torchinfo                 1.8.0                    pypi_0    pypi
torchtriton               2.2.0                     py310    pytorch
torchvision               0.17.1                   pypi_0    pypi
tqdm                      4.66.1                   pypi_0    pypi
triton                    2.2.0                    pypi_0    pypi
typing-extensions         4.9.0                    pypi_0    pypi
typing_extensions         4.9.0           py310h06a4308_1  
tzdata                    2023d                h04d1e81_0  
urllib3                   2.1.0                    pypi_0    pypi
wheel                     0.41.2                   pypi_0    pypi
xz                        5.4.5                h5eee18b_0  
yaml                      0.2.5                h7b6447c_0  
zlib                      1.2.13               h5eee18b_0  
zstd                      1.5.5                hc292b87_0