-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
add onnx export module, test=develop #27831
Conversation
Thanks for your contribution! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
文档方面需要使用最新的API,去掉fluid
python/paddle/onnx/export.py
Outdated
return x * y, x / y | ||
|
||
def export_with_input_spec(): | ||
paddle.fluid.enable_dygraph() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
没有使用最新版本的API
python/paddle/onnx/export.py
Outdated
def export_with_input_variable(): | ||
paddle.fluid.enable_dygraph() | ||
model = Model() | ||
x = paddle.fluid.dygraph.to_variable(np.array([1]).astype('float32'), name='x') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
后面没有to_variable
方法,统一使用paddle.to_tensor
python/paddle/onnx/export.py
Outdated
__all__ = ['export'] | ||
|
||
|
||
def export(layer, save_file, input_spec=None, opset_version=9, **kwargs): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
竞品的函数是否有返回值?还是只是到处文件就结束?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
看了一下torch,mxnet和oneflow都是写到文件里面,没有返回onnx的proto对象。
811405c
to
8d7a901
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
整体修改注释和细节问题。
|
||
def test_prune_graph(self): | ||
model = Logic() | ||
# prune model with input_spec and output_spec, which need to static and run model before export. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
代码注释请使用标注的英文语法注释,首字母大写
python/paddle/onnx/export.py
Outdated
raise ValueError( | ||
"The input path MUST be format of dirname/file_prefix " | ||
"[dirname\\file_prefix in Windows system], but received " | ||
"file_prefix is empty string.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里你的warning对path做了重命名为file_prefix,其实用户不知道这个变量是啥,用户只看到path这个变量。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
所以考虑修改下这个ERROR让他更有提示意义
python/paddle/onnx/export.py
Outdated
""" | ||
Export Layer as ONNX format model, which can be used for inference. | ||
Now, it supports a limited operater set and dynamic models.(e.g., MobileNet.) | ||
More features and introduction, Please reference `Github <https://github.com/PaddlePaddle/paddle2onnx>`_ . |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
注释这里
Please reference xxxx
-> Please refer to xxxx
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
python/paddle/onnx/export.py
Outdated
|
||
def export(layer, path, input_spec=None, opset_version=9, **configs): | ||
""" | ||
Export Layer as ONNX format model, which can be used for inference. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Export Layer as -> Export Layer to
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
which can be used for inference with onnxruntime.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
python/paddle/onnx/export.py
Outdated
def export(layer, path, input_spec=None, opset_version=9, **configs): | ||
""" | ||
Export Layer as ONNX format model, which can be used for inference. | ||
Now, it supports a limited operater set and dynamic models.(e.g., MobileNet.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
去掉这行注释,改为参考某一个paddle2onnx某个固定的README,了解最新支持的model zoo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
直接删除了这一段描述,准备把op和模型支持的列表到时候写到教程里面。另外现在model_zoo还没有动态图的doc,等完善了再加上
python/paddle/onnx/export.py
Outdated
method, which can be described by InputSpec or example Tensor. If None, all input variables of | ||
the original Layer's forward method would be the inputs of the exported ``ONNX`` model. Default None. | ||
opset_version(int, optional): Opset version of exported ONNX model. | ||
Now, stable supported opset version include 9, 10, 11. Default 9. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Default 9 -> Default: 9
python/paddle/onnx/export.py
Outdated
def forward(self, x): | ||
return self._linear(x) | ||
|
||
# export model with InputSpec, which supports set dynamic shape for inputs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
注释中的注释也同意下语法规范。对于Paddle内部变量,需要用``阔起来,如InputSpec
简化下语法表达。
Export model with InputSpec
to support dynamic input shape.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
尽量用短句注释
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
python/paddle/onnx/export.py
Outdated
else: | ||
return y | ||
|
||
# export model with Tensor, which supports prune model by set 'output_spec' with output of model. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Export model with paddle.Tensor
as input_spec
, and model output as output_spec
, onnx exporter will automatically prune out the inference model.
python/paddle/__init__.py
Outdated
@@ -271,6 +271,8 @@ | |||
from . import static | |||
from . import amp | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
为什么这里要莫名的空行?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
去掉了空行
python/paddle/__init__.py
Outdated
@@ -271,6 +271,8 @@ | |||
from . import static | |||
from . import amp | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
为什么这里要莫名的空行
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
只剩一点英文小意见。
python/paddle/onnx/export.py
Outdated
def export(layer, path, input_spec=None, opset_version=9, **configs): | ||
""" | ||
Export Layer to ONNX format, which can be inferenced by onnxruntime or other backends. | ||
More details, Please refer to `paddle2onnx <https://github.com/PaddlePaddle/paddle2onnx>`_ . |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mode deteils -> For more details,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
python/paddle/onnx/export.py
Outdated
|
||
def export(layer, path, input_spec=None, opset_version=9, **configs): | ||
""" | ||
Export Layer to ONNX format, which can be inferenced by onnxruntime or other backends. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
which can be inferenced -> which can use for inference via onnxruntime or other backends.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
python/paddle/onnx/export.py
Outdated
else: | ||
return y | ||
|
||
# Export model with 'Tensor' to support prune model by set 'output_spec'. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pruned model
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
TODO:review doc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
PR types
New features
PR changes
APIs
Describe
Add onnx export module by lazy import paddle2onnx.
API中文文档预览:
暂缺API英文文档预览