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

Support trt engine auto build in runtime for dynamic shape #52162

Merged
merged 12 commits into from
Apr 17, 2023

Conversation

JZZ-NOTE
Copy link
Contributor

@JZZ-NOTE JZZ-NOTE commented Mar 27, 2023

PR types

Others

PR changes

Others

Describe

添加配置Paddle-Trt动态Shape的新方式:

  1. 接口 EnableTunedTensorRtDynamicShape() ,不传任何参数时,表明在运行时构建 trt engine。
  2. 不再需要先收集再运行,但为了避免运行时的重新构建,需要在前几次运行时,覆盖最小及最大Shape的情况。

两个可改进的点:

  1. 序列化文件反序列化为engine后,目前没有从engine中获取min、max、opt信息的功能。后续开发后,可以考虑不再保存"shape_range_info.pbtxt"文件
  2. 收集 tensor shape 的代码与 collect_shape_range_info 相同(拷贝过来的)。后续可考虑是否需要抽离出来

@paddle-bot
Copy link

paddle-bot bot commented Mar 27, 2023

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@@ -199,7 +199,7 @@ void IRPassManager::CreatePasses(Argument *argument,
optim_cache_dir));
}
pass->Set("model_opt_cache_dir", new std::string(optim_cache_dir));
} else if (use_static_engine || enable_int8) {
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

去掉这两个判断条件的原因?

&min_shape_tensor,
&max_shape_tensor,
&opt_shape_tensor);
if (shape_range_info_path != "") {
Copy link
Contributor

Choose a reason for hiding this comment

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

string.empty()?

&max_shape_tensor,
&opt_shape_tensor);
} else {
int fd =
Copy link
Contributor

Choose a reason for hiding this comment

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

文件打开读写这一块c++有封装好的api吧,用c?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

这个其他文件里也在用。就沿用了。
image

void EnableTunedTensorRtDynamicShape(const std::string& shape_range_info_path,
bool allow_build_at_runtime = true);
void EnableTunedTensorRtDynamicShape(
const std::string shape_range_info_path = "",
Copy link
Contributor

Choose a reason for hiding this comment

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

有引用不能给默认值?

@@ -441,6 +441,9 @@ class TensorRTEngine {
void SetUseDLA(bool use_dla) { use_dla_ = use_dla; }
void SetDLACore(int dla_core) { dla_core_ = dla_core; }
void SetWithErnie(bool with_ernie) { with_ernie_ = with_ernie; }
void SetWithDynamicShape(bool with_dynamic_shape) {
Copy link
Contributor

Choose a reason for hiding this comment

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

新增了这个接口,第250行附近的逻辑可以给删了

@@ -1434,7 +1434,7 @@ bool AnalysisConfig::shape_range_info_collected() const {
}

void AnalysisConfig::EnableTunedTensorRtDynamicShape(
const std::string &shape_range_info_path, bool allow_build_at_runtime) {
Copy link
Contributor

Choose a reason for hiding this comment

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

保留&

@@ -14,6 +14,7 @@
// limitations under the License.

#include "paddle/fluid/inference/analysis/ir_passes/tensorrt_subgraph_pass.h"
#include <fcntl.h>
Copy link
Contributor

Choose a reason for hiding this comment

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

这个头文件有啥用吗?

@@ -224,6 +224,7 @@ class TensorRTEngine {
AnalysisConfig::Precision precision = AnalysisConfig::Precision::kFloat32,
TRTInt8Calibrator* calibrator = nullptr,
int device_id = 0,
bool with_dynamic_shape = false,
Copy link
Contributor

Choose a reason for hiding this comment

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

为什么要加上这一个选项呢?
以前是根据啥来区分是动态shape还是静态shape呢?

leiqing1
leiqing1 previously approved these changes Apr 13, 2023
Copy link

@leiqing1 leiqing1 left a comment

Choose a reason for hiding this comment

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

沟通后,确定 明天补文档

jiweibo
jiweibo previously approved these changes Apr 14, 2023
Copy link
Contributor

@jiweibo jiweibo left a comment

Choose a reason for hiding this comment

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

LGTM

@JZZ-NOTE
Copy link
Contributor Author

沟通后,确定 明天补文档

@JZZ-NOTE JZZ-NOTE closed this Apr 14, 2023
@JZZ-NOTE JZZ-NOTE reopened this Apr 14, 2023
@JZZ-NOTE
Copy link
Contributor Author

PaddlePaddle/Paddle-Inference-Demo#439 API文档已更新

Copy link
Contributor

@jiweibo jiweibo left a comment

Choose a reason for hiding this comment

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

LGTM

@jiweibo jiweibo merged commit ebc5854 into PaddlePaddle:develop Apr 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants