[ONNX] Onnx file loads very slowly with onnxruntime, which is exported (dynamic_shapes=True) with torch.onnx_dynamo_export
.
#6016
Labels
torch.onnx_dynamo_export
.
#6016
I trained an inpainting model which has
torch.rfftn
/torch.irfftn
modules and accepts image data with shape-[b, 4, h, w]. For some reason thetorch.onnx.export
can't export operators with complex tenors. I tried to make dynamic export successfully withtorch.onnx.dynamo_export
, but it takes a long time for onnxruntime to load it, here is my model: onnxenvironment:
model.py:
export.py:
I modified some codes to make it pass, and successfully export a dynamic-model onnx. But it takes about 1min to load the dynamic-model onnx file with onnxruntime for inference, which is too slowly and can't be accept in my task.
For dynamic exporting, I modified several codes as follows:
comment 2 line of codes in _subclasses/fake_tensor.py of torch (2.1.1) package, find the function
stride_incorrect_op
:Then, execute the export.py will raise another error:
I register the function
complex()
in my export.py:export.py:
For dynamic shape inference, in function_libs/torch_lib/ops/fft.py of package onnxscript in virtual environment, I add a function
_ifftn_onnx()
:_ifftn_onnx():
Then, find the function
aten__fft_c2r()
, replace the original implementation.Last, for the sake of the correct result, I have to finish the normalization of
_ifftn_onnx()
(not finished in 2.) in my model:in FourierUnit of model.py:
After the 3 steps, I successfully export my dynamic model, but it is very slowly using onnxruntime for inference when execute
ort.InferenceSession(onnx_file, providers=['CPUExecutionProvider'])
. I don't know how to handle this, here is the visualization of my onnx file:visualization:
It has a big subgraph in it due to
torch._dynamo
? Maybe it's the reason why onnxruntime loading the onnx file so slowly? Would anyone give some help?The text was updated successfully, but these errors were encountered: