Closed
Description
I am converting the pytorch model to caffe2 using ONNX. It has one operator that is avg_pool3d does not support. I used the code in pytorch
avg_pool = nn.AdaptiveAvgPool3d(1)
I installed the newest caffe2 yesterday. How should I fix it?
/home/john/anaconda3/lib/python3.6/site-packages/torch/onnx/utils.py:501: UserWarning: ONNX export failed on ATen operator adaptive_avg_pool3d because torch.onnx.symbolic.adaptive_avg_pool3d does not exist
.format(op_name, op_name))
Traceback (most recent call last):
File "convert_pytorch2caffe2.py", line 52, in <module>
export_params=True)
File "/home/john/anaconda3/lib/python3.6/site-packages/torch/onnx/__init__.py", line 22, in _export
return utils._export(*args, **kwargs)
File "/home/john/anaconda3/lib/python3.6/site-packages/torch/onnx/utils.py", line 287, in _export
proto, export_map = graph.export(params, _onnx_opset_version, defer_weight_export, operator_export_type)
RuntimeError: ONNX export failed: Couldn't export operator aten::adaptive_avg_pool3d
Defined at:
/home/john/anaconda3/lib/python3.6/site-packages/torch/nn/functional.py(581): adaptive_avg_pool3d
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
houseroad commentedon Dec 4, 2018
Seems the symbolic is missing. @zrphercule would you like to take a look?
zrphercule commentedon Dec 4, 2018
@zrphercule Sure, let me take a look.
zrphercule commentedon Dec 4, 2018
@John1231983 I wonder how you export AdaptiveAvgPool3d? This op is not supported in operator_export_type=ONNX, but is supported in operator_export_type=ONNX_ATEN_FALLBACK.
John1231983 commentedon Dec 5, 2018
@zrphercule : I trained the model on pytorch with the
AdaptiveAvgPool3d
layer. Then I install onnx from caffe2 to convert the model to caffe2 format. I got the above errorzrphercule commentedon Dec 5, 2018
@John1231983 For specifically, what is your command of converting AdaptiveAvgPool3d from pytorch to caffe2? Like, "onnx.export(....)" or similar command?
John1231983 commentedon Dec 5, 2018
Yes. I used it. This is code
zrphercule commentedon Dec 5, 2018
@John1231983 I see. Since you are exporting models from pytorch, we have some specially support called Aten for this scenario. I suggest you to take a try of using:
torch_out = torch.onnx._export(model,
input,
"model_caff2.onnx",
export_params=False,
operator_export_type=torch.onnx.OperatorExportTypes.ONNX_ATEN_FALLBACK
)
This param will allow you to use ops in Aten when cannot find it in ONNX operator set. It only works when you are exporting models from pytorch, and importing with caffe2.
Please let me know if it works or not :)
haiyang-tju commentedon Jun 12, 2019
Great! It works.
haiyang-tju commentedon Jun 12, 2019
But when I run the exported onnx model in caffe2, it gives me the RuntimeError:
RuntimeError: [enforce fail at aten_op.h:14251] . Attempting to run unknown ATen operator configuration: adaptive_avg_pool3d-2
@zrphercule would you like to take a look? Thanks.
the running code script as follows:
pietern commentedon Jun 12, 2019
@houseroad Can you take a look at this as well?
PatrickNa commentedon Sep 23, 2020
A similar error appears when the onnx model is tried to be loaded with onnxruntime:
Fail: [ONNXRuntimeError] : 1 : FAIL : Fatal error: ATen is not a registered function/op
luvwinnie commentedon Jan 4, 2021
I think this is related to this issue
2 remaining items