Skip to content

RuntimeError: ONNX export failed: Couldn't export operator aten::adaptive_avg_pool3d #14395

Closed
@John1231983

Description

@John1231983

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

Activity

houseroad

houseroad commented on Dec 4, 2018

@houseroad
Member

Seems the symbolic is missing. @zrphercule would you like to take a look?

zrphercule

zrphercule commented on Dec 4, 2018

@zrphercule
Contributor

@zrphercule Sure, let me take a look.

zrphercule

zrphercule commented on Dec 4, 2018

@zrphercule
Contributor

@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

John1231983 commented on Dec 5, 2018

@John1231983
Author

@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 error

zrphercule

zrphercule commented on Dec 5, 2018

@zrphercule
Contributor

@John1231983 For specifically, what is your command of converting AdaptiveAvgPool3d from pytorch to caffe2? Like, "onnx.export(....)" or similar command?

John1231983

John1231983 commented on Dec 5, 2018

@John1231983
Author

Yes. I used it. This is code

torch_out = torch.onnx._export(model,
                                   input,
                                   "model_caff2.onnx",
                                   export_params=False)
zrphercule

zrphercule commented on Dec 5, 2018

@zrphercule
Contributor

@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

haiyang-tju commented on Jun 12, 2019

@haiyang-tju

Great! It works.

haiyang-tju

haiyang-tju commented on Jun 12, 2019

@haiyang-tju

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:

import onnx
import caffe2.python.onnx.backend as onnx_caffe2_backend
model = onnx.load(onnx_file_path)
prepared_backend = onnx_caffe2_backend.prepare(model)
W = {model.graph.input[0].name: input_tensor.data.numpy()}
c2_out = prepared_backend.run(W)[0]
pietern

pietern commented on Jun 12, 2019

@pietern
Contributor

@houseroad Can you take a look at this as well?

added
triagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module
on Jun 12, 2019
PatrickNa

PatrickNa commented on Sep 23, 2020

@PatrickNa

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

luvwinnie commented on Jan 4, 2021

@luvwinnie

I think this is related to this issue

2 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    module: onnxRelated to torch.onnxtriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @pietern@garymm@luvwinnie@PatrickNa@pytorchbot

        Issue actions

          RuntimeError: ONNX export failed: Couldn't export operator aten::adaptive_avg_pool3d · Issue #14395 · pytorch/pytorch