Unsupported FX node: <built-in function mod>

Hello!

I am trying to export the Surya OCR model to the ONNX format in order to improve its inference latency on CPU with TorchDynamo. The export procedure works as expected with the default export option, but with the dynamic_shapes=True option, it does not work anymore:

torch.onnx.dynamo_export(model, **kwargs) # OK

export_options = torch.onnx.ExportOptions(dynamic_shapes=True)
torch.onnx.dynamo_export(model, **kwargs, export_options=export_options) # ERROR

The error I have is:

torch.onnx._internal.diagnostics.infra.context.RuntimeErrorWithDiagnostic: Unsupported FX > nodes: {‘call_function’: [‘built-in function mod’]}.

I do not understand the error, as the modulus operator is supposed to be supported for the ONNX export, and works as expected on smaller networks that uses modulus.

I cannot provide the full code, as the whole model is gigantic, but I can provide further information if necessary, of course.

Thank you!

I’m wondering if there’s a solution to this?

I’m seeing the same error when trying to export the “BertEncoder” in “transformers.models.bert.modeling_bert.BertEncoder”.