Skip to content

Conversation

@Sunny-bot1
Copy link
Contributor

@Sunny-bot1 Sunny-bot1 commented Mar 29, 2024

PR Category

Inference

PR Types

New features

Description

  • 新IR支持inference的register input/output hook功能
  • 控制流while op和if op的内部op支持register input/output hook功能
  • 为predictor添加了RegisterInputHook接口,用法同RegisterOutputHook

Python示例:

def output_hook(op_name: str, output_name: str, tensor: paddle.Tensor):
        print("================output====================")
        print(op_name, output_name, tensor)

def input_hook(op_name: str, input_name: str, tensor: paddle.Tensor):
        print("================Input====================")
        print(op_name, input_name, tensor)

predictor.register_output_hook(output_hook)
predictor.register_input_hook(input_hook)

predictor会在每个op调用时打印op的input信息和output信息
输出结果示例(op name:op id 、tensor name 、tensor value):
image

@paddle-bot
Copy link

paddle-bot bot commented Mar 29, 2024

你的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.

@paddle-bot
Copy link

paddle-bot bot commented Mar 29, 2024

❌ The PR is not created using PR's template. You can refer to this Demo.
Please use PR's template, it helps save our maintainers' time so that more developers get helped.

Comment on lines 38 to 39
using PirHookFunc =
std::function<void(InstructionBase*, ValueExecutionInfo*, Scope*)>;
Copy link
Contributor

Choose a reason for hiding this comment

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

这个和上面的IfInstruction里的不需要重复写这个using,paddle/fluid/framework/new_executor/new_executor_defs.h里写过之后,应该都是可以直接用的

Comment on lines 31 to 33
using HookFunc = std::function<void(OperatorBase*, Scope*)>;
using PirHookFunc =
std::function<void(InstructionBase*, ValueExecutionInfo*, Scope*)>;
Copy link
Contributor

Choose a reason for hiding this comment

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

这里尝试下能不能也删去,包含paddle/fluid/framework/new_executor/new_executor_defs.h头文件

if (op.isa<paddle::dialect::IfOp>()) { // NOLINT
vec_instruction_base_.emplace_back(std::make_unique<IfInstruction>(
op_idx++, place_, &op, value_exe_info_.get(), execution_config_));
std::unique_ptr<IfInstruction> ifInstrPtr =
Copy link
Contributor

Choose a reason for hiding this comment

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

变量的命名我们一般都是小写+下划线,其他地方一并改下

Comment on lines 104 to 111
void SetOutputHooks(const std::vector<PirHookFunc>& hookfuncs) override {
pir_output_hookfuncs_ = hookfuncs;
}

void SetInputHooks(const std::vector<PirHookFunc>& hookfuncs) override {
pir_input_hookfuncs_ = hookfuncs;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

这个文件的修改是完全不需要的哈,这是旧IR相关的

Comment on lines 250 to 252
std::vector<PirHookFunc> pir_output_hookfuncs_;
std::vector<PirHookFunc> pir_input_hookfuncs_;

Copy link
Contributor

Choose a reason for hiding this comment

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

同上

Copy link
Contributor

@yuanlehome yuanlehome left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@sunzhongkai588 sunzhongkai588 left a comment

Choose a reason for hiding this comment

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

LGTM

@yuanlehome yuanlehome merged commit f280f8e into PaddlePaddle:develop Apr 1, 2024
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