Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【Hackathon 6th No.56】Add deform conv2d op #1256

Merged
merged 11 commits into from
May 29, 2024

Conversation

xiaoyewww
Copy link
Contributor

Details:
add deform conv2d op

@xiaoyewww
Copy link
Contributor Author

@Zheng-Bicheng 具体接入的时候有几个问题需要请教一下:
    // 1. 这个变量名称映射paddle的是哪个呢?看上去是ops.yaml和op_compat.yaml吗?
    // 2. c++ api上没有bias,这个是def deformable_conv调用C_ops后再加上的,这里怎么处理呢?optional的输入也要全写入吗
    // 3. 这个opsetx怎么具体对应起来呢?跟onnx似乎对不上

@xiaoyewww
Copy link
Contributor Author

另外这个仓库pre-commit还在使用吗,昨天配置的时候一直遇到网络的问题

@Zheng-Bicheng
Copy link
Collaborator

目前PR存在的问题

  • ONNX DeformConv只支持 opset19+,因此需要升级 opset 版本,这个将由 @Zheng-Bicheng 来做支持
  • OpsetX()函数的调用过程默认从当前模型的 Opset 版本 向下一级一级往下降。例如当前的Opset版本是16,那么Paddle2ONNX会先看Opset16()这个有没有实现,没有的话就会去调用Opset15(),最低调用到Opset7()
  • Bias我看了下是可选的,可以暂时不用管它,传一个默认的参数(猜测过去应该是0),其他的函数有类似的逻辑,我晚上回去截图给你
  • **变量名称映射 paddle **我没明白是什么意思

@Zheng-Bicheng
Copy link
Collaborator

另外这个仓库pre-commit还在使用吗,昨天配置的时候一直遇到网络的问题

这个确实暂时用不了,先不管他,保持一个文件内的代码格式变化不要太大就好了

@xiaoyewww
Copy link
Contributor Author

xiaoyewww commented May 23, 2024

目前PR存在的问题

  • ONNX DeformConv只支持 opset19+,因此需要升级 opset 版本,这个将由 @Zheng-Bicheng 来做支持
  • OpsetX()函数的调用过程默认从当前模型的 Opset 版本 向下一级一级往下降。例如当前的Opset版本是16,那么Paddle2ONNX会先看Opset16()这个有没有实现,没有的话就会去调用Opset15(),最低调用到Opset7()
  • Bias我看了下是可选的,可以暂时不用管它,传一个默认的参数(猜测过去应该是0),其他的函数有类似的逻辑,我晚上回去截图给你
  • **变量名称映射 paddle **我没明白是什么意思

还有几个问题

  • 这里的opset 版本我没弄清楚是跟onnx什么关系,比如deformconv,onnx只支持19+,我们也只需要定义Opset19吗,但我看conv2d是Opset7,但是onnx上opset1就支持了。
  • 变量名称映射,我是指GetAttr这里面的属性获取的第一个参数是怎么来的。

@Zheng-Bicheng
Copy link
Collaborator

这里的opset 版本我没弄清楚是跟onnx什么关系,比如deformconv,onnx只支持19+,我们也只需要定义Opset19吗,但我看conv2d是Opset7,但是onnx上opset1就支持了。

opset和onnx版本绑定,一个onnx版本对应一个opset,Paddle2ONNX默认从opset7开始支持,目前Paddle2ONNX支持的最高opset是18,因此需要升级

@Zheng-Bicheng
Copy link
Collaborator

变量名称映射,我是指GetAttr这里面的属性获取的第一个参数是怎么来的。

可以用netron可视化静态图模型获取

@xiaoyewww xiaoyewww changed the title 【WIP】【Hackathon 6th No.58】Add deform conv2d op 【Hackathon 6th No.58】Add deform conv2d op May 23, 2024
@xiaoyewww
Copy link
Contributor Author

xiaoyewww commented May 23, 2024

@Zheng-Bicheng 那我目前这边测例无法通过就不用改了吗,请麻烦看一下还有哪里需要修改。

目前单测报的是版本不支持的问题:

[Paddle2ONNX] Start to parse PaddlePaddle model...
[Paddle2ONNX] Model file path: deform_conv2d/cliped_model.pdmodel
[Paddle2ONNX] Parameters file path: 
[Paddle2ONNX] Start to parsing Paddle model...
[ERROR] Paddle2ONNX now only support opset version in range of [7, 18].


--------------------------------------
C++ Traceback (most recent call last):
--------------------------------------
0   paddle2onnx::Export(char const*, char const*, char**, int*, int, bool, bool, bool, bool, bool, paddle2onnx::CustomOp*, int, char const*, char**, int*, char const*, bool*, bool, char**, int)

----------------------
Error Message Summary:
----------------------
FatalError: `Process abort signal` is detected by the operating system.
  [TimeInfo: *** Aborted at 1716473326 (unix time) try "date -d @1716473326" if you are using GNU date ***]
  [SignalInfo: *** SIGABRT (@0x7b3da) received by PID 504794 (TID 0x7f2e08d8e4c0) from PID 504794 ***]

[1]    504794 abort (core dumped)  python tests/test_deform_conv2d.py

@Zheng-Bicheng
Copy link
Collaborator

那我目前这边测例无法通过就不用改了吗,请麻烦看一下还有哪里需要修改。

我今天会添加Paddle2ONNX对OP19的支持,到时候你再测试下

@Zheng-Bicheng
Copy link
Collaborator

在这个 PR 中更新 opset 版本到支持19

paddle2onnx/mapper/nn/deform_conv2d.h Outdated Show resolved Hide resolved
paddle2onnx/mapper/nn/deform_conv2d.h Outdated Show resolved Hide resolved
@xiaoyewww
Copy link
Contributor Author

/root/miniconda3/envs/paddle_onnx/lib/python3.9/site-packages/paddle/static/io.py:610: UserWarning: no variable in your model, please ensure there are any variables in your model to save
  warnings.warn(
[Paddle2ONNX] Start to parse PaddlePaddle model...
[Paddle2ONNX] Model file path: deform_conv2d/cliped_model.pdmodel
[Paddle2ONNX] Parameters file path: 
[Paddle2ONNX] Start to parsing Paddle model...
[Paddle2ONNX] Use opset_version = 19 for ONNX export.
[Paddle2ONNX] The exported ONNX model is invalid.
[Paddle2ONNX] Model checker error log: No Op registered for DeformConv with domain_version of 19

==> Context: Bad node spec for node. Name: p2o.DeformConv.0 OpType: DeformConv
[Paddle2ONNX] PaddlePaddle model is exported as ONNX format now.
Traceback (most recent call last):
  File "/wuzp/Paddle2ONNX/tests/test_deform_conv2d.py", line 41, in <module>
    test_deform_conv2d()
  File "/wuzp/Paddle2ONNX/tests/test_deform_conv2d.py", line 37, in test_deform_conv2d
    obj.run()
  File "/wuzp/Paddle2ONNX/tests/onnxbase.py", line 420, in run
    res_fict[str(v)] = self._mk_onnx_res(ver=v)
  File "/wuzp/Paddle2ONNX/tests/onnxbase.py", line 300, in _mk_onnx_res
    sess = InferenceSession(
  File "/root/miniconda3/envs/paddle_onnx/lib/python3.9/site-packages/onnxruntime/capi/onnxruntime_inference_collection.py", line 419, in __init__
    self._create_inference_session(providers, provider_options, disabled_optimizers)
  File "/root/miniconda3/envs/paddle_onnx/lib/python3.9/site-packages/onnxruntime/capi/onnxruntime_inference_collection.py", line 483, in _create_inference_session
    sess.initialize_session(providers, provider_options, disabled_optimizers)
onnxruntime.capi.onnxruntime_pybind11_state.NotImplemented: [ONNXRuntimeError] : 9 : NOT_IMPLEMENTED : Could not find an implementation for DeformConv(19) node with name 'p2o.DeformConv.0'

上面还是报错了,这里有点困惑,其实我上面只输入了三个参数。X W offset,另外的bias和mask其实一开始没填,还是报同样的错。

我参考看了一下conv2d,这里面其实也只有两个输入参数,但是ONNX上是输入参数也是2~3个。

  auto node = helper_->MakeNode(
      "Conv", {input_info[0].name, kernel_info[0].name}, {output_info[0].name});

@Zheng-Bicheng
Copy link
Collaborator

Model checker error log: No Op registered for DeformConv with domain_version of 19

这个我看了下好像是第三方库onnx的报错,我再看看原因。

@Zheng-Bicheng
Copy link
Collaborator

Model checker error log: No Op registered for DeformConv with domain_version of 19

补充修复:

@Zheng-Bicheng Zheng-Bicheng self-requested a review May 24, 2024 13:46
@Zheng-Bicheng
Copy link
Collaborator

ONNXRuntime暂时没有对DeformConv进行实现,考虑实现后再合入这个PR

@Zheng-Bicheng Zheng-Bicheng changed the title 【Hackathon 6th No.58】Add deform conv2d op 【Hackathon 6th No.56】Add deform conv2d op May 29, 2024
mask = paddle.rand((8, kh * kw, 26, 26))
weight = paddle.rand((16, 1, kh, kw))
obj.set_input_data("input_data", input, offset, weight, mask)
obj.run()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest comment out this line, and go ahead on merging this PR.

@Zheng-Bicheng
Copy link
Collaborator

或者在这里加入一下你的test的名字吧,也不用注释了

@xiaoyewww
Copy link
Contributor Author

@Zheng-Bicheng @jzhang533 已注释,麻烦review一下,感谢~

Copy link
Collaborator

@Zheng-Bicheng Zheng-Bicheng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Zheng-Bicheng Zheng-Bicheng merged commit c855146 into PaddlePaddle:develop May 29, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants