From 1c4043b83ce17e14435eba40d4fccf7b8d3ccb04 Mon Sep 17 00:00:00 2001 From: 0x3878f <1757941716@qq.com> Date: Mon, 30 Dec 2024 09:19:14 +0000 Subject: [PATCH] update some docs --- README.md | 12 ++--- README_en.md | 14 +++--- docs/en/compile_local.md | 60 +++++++++++++----------- docs/zh/Paddle2ONNX_Development_Guide.md | 26 +++++----- docs/zh/compile_local.md | 47 ++++++++++--------- 5 files changed, 83 insertions(+), 76 deletions(-) diff --git a/README.md b/README.md index 6174fd813..e508ce917 100644 --- a/README.md +++ b/README.md @@ -8,9 +8,9 @@ Paddle2ONNX 支持将 **PaddlePaddle** 模型格式转化到 **ONNX** 模型格 ## 2 Paddle2ONNX 环境依赖 -Paddle2ONNX 本身不依赖其他组件,但是我们建议您在以下环境下使用 Paddle2ONNX : +Paddle2ONNX 依赖PaddlePaddle3.0,我们建议您在以下环境下使用 Paddle2ONNX : -- PaddlePaddle == 2.6.0 +- PaddlePaddle == 3.0.0b2 - onnxruntime >= 1.10.0 ## 3 安装 Paddle2ONNX @@ -29,7 +29,7 @@ pip install paddle2onnx Paddle2ONNX 在导出模型时,需要传入部署模型格式,包括两个文件 -- `model_name.pdmodel`: 表示模型结构 +- `model_name.json`: 表示模型结构 - `model_name.pdiparams`: 表示模型参数 ### 4.2 调整Paddle模型 @@ -42,8 +42,8 @@ Paddle2ONNX 在导出模型时,需要传入部署模型格式,包括两个 ```bash paddle2onnx --model_dir model_dir \ - --model_filename inference.pdmodel \ - --params_filename inference.pdiparams \ + --model_filename model.json \ + --params_filename model.pdiparams \ --save_file model.onnx ``` @@ -55,7 +55,7 @@ paddle2onnx --model_dir model_dir \ | --model_filename | **[可选]** 配置位于 `--model_dir` 下存储网络结构的文件名 | | --params_filename | **[可选]** 配置位于 `--model_dir` 下存储模型参数的文件名称 | | --save_file | 指定转换后的模型保存目录路径 | -| --opset_version | **[可选]** 配置转换为 ONNX 的 OpSet 版本,目前支持 7~16 等多个版本,默认为 9 | +| --opset_version | **[可选]** 配置转换为 ONNX 的 OpSet 版本,目前支持 7~19 等多个版本,默认为 9 | | --enable_onnx_checker | **[可选]** 配置是否检查导出为 ONNX 模型的正确性, 建议打开此开关, 默认为 True | | --enable_auto_update_opset | **[可选]** 是否开启 opset version 自动升级功能,当低版本 opset 无法转换时,自动选择更高版本的 opset进行转换, 默认为 True | | --deploy_backend | **[可选]** 量化模型部署的推理引擎,支持 onnxruntime/rknn/tensorrt, 默认为 onnxruntime | diff --git a/README_en.md b/README_en.md index 9e6e2d407..24b65c0b3 100644 --- a/README_en.md +++ b/README_en.md @@ -8,9 +8,9 @@ Paddle2ONNX supports the conversion of PaddlePaddle model format to ONNX model f ## 2 Paddle2ONNX Environment Dependencies -Paddle2ONNX itself does not depend on other components, but we recommend using Paddle2ONNX in the following environments: +Paddle2ONNX depends on paddle3.0, we recommend using Paddle2ONNX in the following environments: -- PaddlePaddle == 2.6.0 +- PaddlePaddle == 3.0.0b2 - onnxruntime >= 1.10.0 ## 3 Install Paddle2ONNX @@ -28,7 +28,7 @@ If you wish to conduct secondary development on Paddle2ONNX, please follow the [ ### 4.1 Get the PaddlePaddle Deployment Model When Paddle2ONNX exports the model, it needs to pass in the deployment model format, including two files -- `model_name.pdmodel`: Indicates the model structure +- `model_name.json`: Indicates the model structure - `model_name.pdiparams`: Indicates model parameters ### 4.2 Adjusting Paddle Models @@ -40,8 +40,8 @@ If adjustments to the input and output of Paddle models are needed, you can visi You can convert Paddle models to ONNX models using the command line with the following command: ```bash -paddle2onnx --model_dir saved_inference_model \ - --model_filename model.pdmodel \ +paddle2onnx --model_dir model_dir \ + --model_filename model.json \ --params_filename model.pdiparams \ --save_file model.onnx ``` @@ -54,8 +54,8 @@ The adjustable conversion parameters are listed in the following table: | --model_filename | **[Optional]** Configure the filename to store the network structure under `--model_dir` | | --params_filename | **[Optional]** Configure the name of the file to store model parameters under `--model_dir` | | --save_file | Specify the converted model save directory path | -| --opset_version | **[Optional]** Configure the OpSet version converted to ONNX, currently supports multiple versions such as 7~16, the default is 9 | -| --enable_onnx_checker | **[Optional]** Configure whether to check the correctness of the exported ONNX model, it is recommended to turn on this switch, the default is False | +| --opset_version | **[Optional]** Configure the OpSet version converted to ONNX, currently supports multiple versions such as 7~19, the default is 9 | +| --enable_onnx_checker | **[Optional]** Configure whether to check the correctness of the exported ONNX model, it is recommended to turn on this switch, the default is True | | --enable_auto_update_opset | **[Optional]** Whether to enable the opset version automatic upgrade function, when the lower version of the opset cannot be converted, automatically select the higher version of the opset for conversion, the default is True | | --deploy_backend | **[Optional]** Inference engine for quantitative model deployment, supports onnxruntime/rknn/tensorrt, the default is onnxruntime | | --save_calibration_file | **[Optional]** TensorRT 8.X version deploys the cache file that needs to be read to save the path of the quantitative model, the default is calibration.cache | diff --git a/docs/en/compile_local.md b/docs/en/compile_local.md index 07348645f..c529766d3 100644 --- a/docs/en/compile_local.md +++ b/docs/en/compile_local.md @@ -2,8 +2,8 @@ The compilation and installation of Paddle2ONNX require ensuring that the environment meets the following requirements: -- cmake >= 3.18.0 -- protobuf >= 3.16.0 +- cmake >= 3.16.0 +- protobuf >= 4.22.0 ## 1 Install on Linux/Mac @@ -12,25 +12,30 @@ The compilation and installation of Paddle2ONNX require ensuring that the enviro ```bash git clone https://github.com/protocolbuffers/protobuf.git cd protobuf -git checkout v3.16.0 +git checkout v4.22.0 +git submodule update --init mkdir build_source && cd build_source -cmake ../cmake -DCMAKE_INSTALL_PREFIX=${PWD}/installed_protobuf_lib -Dprotobuf_BUILD_SHARED_LIBS=OFF -DCMAKE_POSITION_INDEPENDENT_CODE=ON -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=Release -make -j8 +cmake ../cmake -DCMAKE_INSTALL_PREFIX=`pwd`/installed_protobuf_lib -Dprotobuf_BUILD_SHARED_LIBS=OFF -DCMAKE_POSITION_INDEPENDENT_CODE=ON -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_STANDARD=14 +make -j make install -# 将编译目录加入环境变量 +# set the library to environment export PATH=${PWD}/installed_protobuf_lib/bin:${PATH} ``` -### 1.2 Install Paddle2ONNX +### 1.2 Install Protobuf ```bash -git clone https://github.com/PaddlePaddle/Paddle2ONNX.git -cd Paddle2ONNX -git submodule init -git submodule update +python -m pip install --pre paddlepaddle -i https://www.paddlepaddle.org.cn/packages/nightly/cpu/ +``` -pip install setuptools wheel auditwheel auditwheel-symbols build +### 1.3 Install Paddle2ONNX + +```bash +git clone -b test_pir https://github.com/PaddlePaddle/Paddle2ONNX.git +cd Paddle2ONNX +git submodule update --init +export PIP_EXTRA_INDEX_URL="https://www.paddlepaddle.org.cn/packages/nightly/cpu/" python -m build pip install dist/*.whl ``` @@ -39,37 +44,36 @@ If you are developing the Paddle2ONNX project locally, you can use `pip install ## 2 Install on Windows -Make sure you have installed Visual Studio 2019 first +**Note that the prerequisite for compiling and installing Windows is that Visual Studio 2019 is already installed in the system** -### 2.1 Open VS command tool +### 2.1 Open Visual Studio Command Prompt -Find **x64 Native Tools Command Prompt for VS 2019** in system menu, and open it +In the system menu, find **x64 Native Tools Command Prompt for VS 2019** and open it. ### 2.2 Install Protobuf -Notice: Please change the `-DCMAKE_INSTALL_PREFIX` to your custom path +Note that the `-DCMAKE_INSTALL_PREFIX` in the following cmake command specifies your actual set path. ```bash git clone https://github.com/protocolbuffers/protobuf.git cd protobuf -git checkout v3.16.0 -cd cmake -cmake -G "Visual Studio 16 2019" -A x64 -DCMAKE_INSTALL_PREFIX=D:\Paddle\installed_protobuf_lib -Dprotobuf_MSVC_STATIC_RUNTIME=OFF -Dprotobuf_BUILD_SHARED_LIBS=OFF -Dprotobuf_BUILD_TESTS=OFF -Dprotobuf_BUILD_EXAMPLES=OFF . -msbuild protobuf.sln /m /p:Configuration=Release /p:Platform=x64 -msbuild INSTALL.vcxproj /p:Configuration=Release /p:Platform=x64 - -# Add the library to environment -set PATH=D:\Paddle\installed_protobuf_lib\bin;%PATH% +git checkout v4.22.0 +git submodule update --init --recursive +mkdir build +cd build +cmake -G "Visual Studio 16 2019" -DCMAKE_INSTALL_PREFIX=%CD%\protobuf_install -Dprotobuf_MSVC_STATIC_RUNTIME=OFF -Dprotobuf_BUILD_SHARED_LIBS=OFF -Dprotobuf_BUILD_TESTS=OFF -Dprotobuf_BUILD_EXAMPLES=OFF .. +cmake --build . --config Release --target install +# set the library to environment +set PATH=%CD%\protobuf_install\bin;%PATH% ``` ### 2.3 Install Paddle2ONNX ```bash -git clone https://github.com/PaddlePaddle/Paddle2ONNX.git +git clone -b test_pir https://github.com/PaddlePaddle/Paddle2ONNX.git cd Paddle2ONNX -git submodule init -git submodule update - +git submodule update --init +set PIP_EXTRA_INDEX_URL=https://www.paddlepaddle.org.cn/packages/nightly/cpu/ pip install setuptools wheel auditwheel auditwheel-symbols build python -m build pip install dist/*.whl diff --git a/docs/zh/Paddle2ONNX_Development_Guide.md b/docs/zh/Paddle2ONNX_Development_Guide.md index 01b2c2fac..37608520f 100644 --- a/docs/zh/Paddle2ONNX_Development_Guide.md +++ b/docs/zh/Paddle2ONNX_Development_Guide.md @@ -92,9 +92,9 @@ namespace paddle2onnx { class RollMapper : public Mapper { public: - RollMapper(const PaddleParser& p, OnnxHelper* helper, int64_t block_id, - int64_t op_id) - : Mapper(p, helper, block_id, op_id) {} + RollMapper(const PaddlePirParser& p, OnnxHelper* helper, int64_t op_id, + bool if_in_cf_block) + : Mapper(p, helper, op_id, if_in_cf_block) {} void Opset7() override; }; @@ -102,18 +102,18 @@ class RollMapper : public Mapper { ``` > 注: -> * Paddle2ONNX 需要实现 Opset version 7~16,如果实现的 OP 不是从 Opset version 7 开始,或者由于 Paddle OP 中的某些属性导致无法导出为ONNX,则需要重写基类中的 GetMinOpsetVersion 函数,该函数返回 -1 表示该 OP 无法导出为 ONNX,否则表示导出该 OP 所需的最小 Opset version -> * OpsetX 函数表示 opset version 为 x 时的转换实现函数,如果定义了 Opset7 和 Opset10 两个转换方法,意味着用户指定转出 opset version 7~9 时,使用 Opset7 中的转换逻辑实现转换,用户指定 opset version 10~16 时,使用 Opset10 中的转换逻辑实现转换 +> * Paddle2ONNX 需要实现 Opset version 7~19,如果实现的 OP 不是从 Opset version 7 开始,或者由于 Paddle OP 中的某些属性导致无法导出为ONNX,则需要重写基类中的 GetMinOpsetVersion 函数,该函数返回 -1 表示该 OP 无法导出为 ONNX,否则表示导出该 OP 所需的最小 Opset version +> * OpsetX 函数表示 opset version 为 x 时的转换实现函数,如果定义了 Opset7 和 Opset10 两个转换方法,意味着用户指定转出 opset version 7~9 时,使用 Opset7 中的转换逻辑实现转换,用户指定 opset version 10~19 时,使用 Opset10 中的转换逻辑实现转换 -然后我们在 roll.cc 中添加实现。首先我们需要使用 **REGISTER_MAPPER** 宏来注册算子,第一个参数填写我们获取到的算子名称(这里是 roll ),第二个参数填写转换类的名称(这里是 RollMapper ) +然后我们在 roll.cc 中添加实现。首先我们需要使用 **REGISTER_PIR_MAPPER** 宏来注册算子,第一个参数填写我们获取到的算子名称(这里是 roll ),第二个参数填写转换类的名称(这里是 RollMapper ) ```c++ #include #include "paddle2onnx/mapper/tensor/roll.h" namespace paddle2onnx { -REGISTER_MAPPER(roll, RollMapper) +REGISTER_PIR_MAPPER(roll, RollMapper) } ``` @@ -354,10 +354,10 @@ Paddle2ONNX 已经实现了大量 OP 的单测,可以参考 Paddle2ONNX/test/* 1. 进入[Paddle2ONNX 官方 Repo](https://github.com/PaddlePaddle/Paddle2ONNX),点击右上角的 Star 关注 Repo 的最新动向,然后点击 Fork 将代码克隆到自己的代码库中。 2. 返回自己的主页,使用 git clone 将 Fork 的代码克隆到本地,然后在克隆代码的根目录下运行 pre-commit install 安装 pre-commit 钩子,以在提交代码时完成代码风格的检查。 3. 按照要求进行开发,开发中请依次完成 OP 转换和单测,并多写英文注释,便于代码更容易让人理解。 - 4. 开发完成后将本地修改 git commit 到本地仓库,然后 git push origin XXX 到远端仓库,此时回到 github 中 Fork 的 Repo 可以看到为如下提示: - ![图片](https://user-images.githubusercontent.com/30516196/231718803-d2b3c940-144e-44e3-8b2b-ae93cc01f8f2.png) - 点击 compare&pull request 按钮,然后出现如下界面,这里需要写言简意赅的标题和详细的修改内容。认真填写完成之后点击 creat pull request 完成 PR。 - ![图片](https://user-images.githubusercontent.com/30516196/231719191-7fcf812a-e0b4-4db0-b66e-fade3e5be5bc.png) + 4. 开发完成后将本地修改 git commit 到本地仓库,然后 git push origin XXX 到远端仓库,此时回到 github 中 Fork 的 Repo + 点击 compare&pull request 按钮,这里需要写言简意赅的标题和详细的修改内容。认真填写完成之后点击 creat pull request 完成 PR。 5. 进入到 Paddle2ONNX 的官方 Repo 可以在[Pull Request](https://github.com/PaddlePaddle/Paddle2ONNX/pulls) 中可以看到提交的 PR,PR 中有 CI 测试,如果 CI 测试没有通过,请点击没有通过 CI 后的 Details 查看详情并修改,通过 CI 之后会有专人进行 code review 和 merge。 -![图片](https://user-images.githubusercontent.com/30516196/231719335-d61c433f-70f3-4cc1-b7f5-29f2bab7e69a.png) - 6. 更详细的资料请参考[Paddle 的 PR 指南](https://www.paddlepaddle.org.cn/documentation/docs/zh/guides/10_contribution/submit_pr_guide_cn.html) + 6. 更详细的资料请参考[Paddle 的 PR 指南](https://www.paddlepaddle.org.cn/documentation/docs/zh/guides/10_contribution/submit_pr_guide_cn.html)。 + + ## 5 其它参考资料 + * [Paddle2ONNX 算子完善参考](https://github.com/PaddlePaddle/Paddle2ONNX/issues/1399) diff --git a/docs/zh/compile_local.md b/docs/zh/compile_local.md index 4482891ca..c4c808932 100644 --- a/docs/zh/compile_local.md +++ b/docs/zh/compile_local.md @@ -2,8 +2,8 @@ Paddle2ONNX 的编译安装至少需要确保环境满足以下需求: -- cmake >= 3.18.0 -- protobuf == 3.16.0 +- cmake >= 3.16.0 +- protobuf == 4.22.0 ## 在 Linux/Mac 下编译并安装 @@ -12,25 +12,29 @@ Paddle2ONNX 的编译安装至少需要确保环境满足以下需求: ```bash git clone https://github.com/protocolbuffers/protobuf.git cd protobuf -git checkout v3.16.0 +git checkout v4.22.0 +git submodule update --init mkdir build_source && cd build_source -cmake ../cmake -DCMAKE_INSTALL_PREFIX=${PWD}/installed_protobuf_lib -Dprotobuf_BUILD_SHARED_LIBS=OFF -DCMAKE_POSITION_INDEPENDENT_CODE=ON -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=Release -make -j8 +cmake ../cmake -DCMAKE_INSTALL_PREFIX=`pwd`/installed_protobuf_lib -Dprotobuf_BUILD_SHARED_LIBS=OFF -DCMAKE_POSITION_INDEPENDENT_CODE=ON -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_STANDARD=14 +make -j make install # 将编译目录加入环境变量 export PATH=${PWD}/installed_protobuf_lib/bin:${PATH} ``` +### 安装PaddlePaddle +```bash +python -m pip install --pre paddlepaddle -i https://www.paddlepaddle.org.cn/packages/nightly/cpu/ +``` + ### 安装Paddle2ONNX ```bash -git clone https://github.com/PaddlePaddle/Paddle2ONNX.git +git clone -b test_pir https://github.com/PaddlePaddle/Paddle2ONNX.git cd Paddle2ONNX -git submodule init -git submodule update - -pip install setuptools wheel auditwheel auditwheel-symbols build +git submodule update --init +export PIP_EXTRA_INDEX_URL="https://www.paddlepaddle.org.cn/packages/nightly/cpu/" python -m build pip install dist/*.whl ``` @@ -52,24 +56,23 @@ pip install dist/*.whl ```bash git clone https://github.com/protocolbuffers/protobuf.git cd protobuf -git checkout v3.16.0 -cd cmake -cmake -G "Visual Studio 16 2019" -A x64 -DCMAKE_INSTALL_PREFIX=D:\Paddle\installed_protobuf_lib -Dprotobuf_MSVC_STATIC_RUNTIME=OFF -Dprotobuf_BUILD_SHARED_LIBS=OFF -Dprotobuf_BUILD_TESTS=OFF -Dprotobuf_BUILD_EXAMPLES=OFF . -msbuild protobuf.sln /m /p:Configuration=Release /p:Platform=x64 -msbuild INSTALL.vcxproj /p:Configuration=Release /p:Platform=x64 - -# 将protobuf加入环境变量 -set PATH=D:\Paddle\installed_protobuf_lib\bin;%PATH% +git checkout v4.22.0 +git submodule update --init --recursive +mkdir build +cd build +cmake -G "Visual Studio 16 2019" -DCMAKE_INSTALL_PREFIX=%CD%\protobuf_install -Dprotobuf_MSVC_STATIC_RUNTIME=OFF -Dprotobuf_BUILD_SHARED_LIBS=OFF -Dprotobuf_BUILD_TESTS=OFF -Dprotobuf_BUILD_EXAMPLES=OFF .. +cmake --build . --config Release --target install +# 设置环境变量 +set PATH=%CD%\protobuf_install\bin;%PATH% ``` ### 安装Paddle2ONNX ```bash -git clone https://github.com/PaddlePaddle/Paddle2ONNX.git +git clone -b test_pir https://github.com/PaddlePaddle/Paddle2ONNX.git cd Paddle2ONNX -git submodule init -git submodule update - +git submodule update --init +set PIP_EXTRA_INDEX_URL=https://www.paddlepaddle.org.cn/packages/nightly/cpu/ pip install setuptools wheel auditwheel auditwheel-symbols build python -m build pip install dist/*.whl