High severity intermediate · Fix: 15-30 min

RuntimeError

torch.onnx.errors.RuntimeError

What this error means
PyTorch ONNX export fails because the model uses a custom operator not supported or registered in the ONNX export environment.

Stack trace

traceback
RuntimeError: Exporting the operator 'my_custom_op' to ONNX is not supported. Please register a symbolic function for this operator or disable export of this operator.
QUICK FIX
Register a symbolic function for your custom operator with torch.onnx.register_custom_op_symbolic before exporting.

Why it happens

PyTorch's ONNX exporter requires all operators used in the model to have corresponding symbolic functions that define how to translate them into ONNX graph nodes. Custom operators without registered symbolic functions cause the exporter to fail because it cannot map them to ONNX operators.

Detection

Monitor ONNX export logs for RuntimeError mentioning unsupported operators. Add validation to check if all custom ops have symbolic registrations before export.

Causes & fixes

1

Custom PyTorch operator lacks a registered ONNX symbolic function.

✓ Fix

Implement and register a symbolic function for the custom operator using torch.onnx.register_custom_op_symbolic.

2

Using an outdated PyTorch version that does not support the custom operator export.

✓ Fix

Upgrade PyTorch to a version that supports custom operator symbolic registration or includes the operator.

3

Attempting to export a model with dynamic control flow or unsupported ops without fallback.

✓ Fix

Refactor the model to avoid unsupported ops or implement symbolic functions; alternatively, use torch.onnx.export with opset_version supporting the ops.

Code: broken vs fixed

Broken - triggers the error
python
import torch
class MyModel(torch.nn.Module):
    def forward(self, x):
        return torch.ops.my_namespace.my_custom_op(x)

model = MyModel()
torch.onnx.export(model, torch.randn(1,3,224,224), "model.onnx")  # This line raises RuntimeError
Fixed - works correctly
python
import os
import torch

# Register symbolic function for the custom op
from torch.onnx import register_custom_op_symbolic

def symbolic_my_custom_op(g, x):
    return g.op("MyNamespace::MyCustomOp", x)

register_custom_op_symbolic("my_namespace::my_custom_op", symbolic_my_custom_op, 9)

class MyModel(torch.nn.Module):
    def forward(self, x):
        return torch.ops.my_namespace.my_custom_op(x)

model = MyModel()
torch.onnx.export(model, torch.randn(1,3,224,224), "model.onnx")  # Fixed: symbolic registered
Added a symbolic function registration for the custom operator so ONNX exporter knows how to translate it.

Workaround

Wrap the custom operator call in a torch.jit.script function and export the scripted model, or replace the custom op with supported PyTorch ops temporarily.

Prevention

Design models using only operators with existing ONNX symbolic support or always register symbolic functions for custom ops before export.

Python 3.7+ · torch >=1.7.0 · tested on 1.12.0
Verified 2026-04
Verify ↗

Community Notes

No notes yetBe the first to share a version-specific fix or tip.