-
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
[NewIR] Support Ir run program node #56791
[NewIR] Support Ir run program node #56791
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
|
||
VLOG(4) << "global_inner_scope:" << global_inner_scope; | ||
|
||
auto input_values = |
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.
这些 fx、fo、fm 是什么?建议取个更可读的名字
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.
好,后续会更换,这个只是最初的版本。
|
||
auto output_grad_values = | ||
PADDLE_GET_CONST(std::vector<::ir::Value>, attrs.at("bo_g")); | ||
auto forward_input_values = |
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.
同上
@@ -0,0 +1,1150 @@ | |||
# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved. |
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.
这里建立一个exprimental_ir 目录,统一放新IR的适配逻辑,类似 partial_program.py 的文件都可以是同名的,后续我们切换上线时,可以统一替换,然后删除ir目录就可以了
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.
目前影响可控,等后面如果发现有大量的侵入代码,会换其他的策略来方便后续的替换。
@@ -1156,6 +1166,106 @@ def __init__( | |||
self.name_generator = name_generator | |||
self.kwargs = kwargs | |||
|
|||
@staticmethod | |||
@switch_to_static_graph | |||
def newir_from_func_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.
这个函数定义是不是也可以放到 exprimental_ir 里,通过动态patch 的形式来实现新旧ir的切换?
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 for print
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 overall,由于下游工作的强依赖,可以考虑特殊先合入,但请尽快提后续的Fix TODO 的优化PR,包括:
- 避免引入过多缩写的Attribute,解耦run_program_op Maker
- 部分函数名称需要优化下,并按照「大写+驼峰」的规则,且为动宾结构
- VLOG的级别要提升,避免任何时候都会打印输出
- 函数代码中不应该出现 newir,现在已经正式化为 pir了
@@ -174,3 +175,107 @@ inline void run_program_ad_func( | |||
egr::EagerUtils::SetHistory(&p_autograd_outs, grad_node); | |||
} | |||
} | |||
|
|||
inline void newir_run_program_ad_func( |
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.
inline void newir_run_program_ad_func( | |
inline void pir_run_program_ad_func( |
std::vector<paddle::Tensor*>& dout, // NOLINT | ||
const paddle::framework::AttributeMap& attrs) { | ||
// Prepare Autograd Meta | ||
VLOG(2) << "start run newir run_program ad function."; |
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.
VLOG(2) << "start run newir run_program ad function."; | |
VLOG(2) << "start run pir run_program ad function."; |
|
||
// Create Middle Output for GradNode. | ||
auto middle_size = | ||
PADDLE_GET_CONST(std::vector<::pir::Value>, attrs.at("fm")).size(); |
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.
这里后续需要解耦run_program_op maker
|
||
if (require_any_grad) { | ||
// Create GradOpNode (1 means [out_grad], 2 means [x_grad, paramx_grad]) | ||
grad_node = std::make_shared<NewIRGradNodeRunProgram>(1, 2); |
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.
grad_node = std::make_shared<NewIRGradNodeRunProgram>(1, 2); | |
grad_node = std::make_shared<GradNodeRunProgramPir>(1, 2); |
这里或许可以使用namespace 来隔离,pir::GradNodeRunProgram
name = | ||
op->attributes().at("name").dyn_cast<pir::StrAttribute>().AsString(); | ||
value2name[op->results()[0].Value::impl()] = name; | ||
} else if (op->name() == "builtin.set_parameter") { |
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.
} else if (op->name() == "builtin.set_parameter") { | |
} else if (op->isa<pir::SetParameterOp) { |
return middle_values; | ||
} | ||
|
||
void mapping_value(const std::vector<pir::Value> &origin, |
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.
同上
return pir::OpResult(nullptr); | ||
} | ||
|
||
SplitedResult ForwardBackwardSplit( |
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.
函数命名应该是「动宾」结构,如SplitForwardBackward
auto *cloned_op = BuildOpFrom(op, forward_value_map); | ||
forward_program->block()->push_back(cloned_op); | ||
}); | ||
VLOG(1) << "After Forward Construct."; |
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.
建议 VLOG(4)
@@ -170,6 +172,34 @@ def args_to_input_spec(self, args, kwargs): | |||
|
|||
return args_with_spec, kwargs_with_spec | |||
|
|||
@switch_to_static_graph | |||
def newir_to_static_inputs_with_spec(self, input_with_spec, main_program): |
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 newir_to_static_inputs_with_spec(self, input_with_spec, main_program): | |
def pir_to_static_inputs_with_spec(self, input_with_spec, main_program): |
def run_function(to_static=True): | ||
import paddle | ||
|
||
# 设置随机种子 |
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.
LGTM
This reverts commit 97442d3.
* support build model in python * fix ci bugs * fix ci bugs * fix compile bugs * fix ci bugs * add infermeta for data * fix ci bugs * fix ci bugs * fix ci bugs * fix bugs when run ir program mutiple times * perfect code * frontend demo debugging * support program split and go into run program node. * simple run the dy2static test in newir_api mode. * remove frame.proto changes * merge * fix ir-run-program-node * fix some code * fix output error * fix some errors * fix * fix * fix * fix conflict * fix files * fix some errors * merge and solve conflict --------- Co-authored-by: YuanRisheng <yuanrisheng@baidu.com>
* [NewIR] Support Ir run program node (#56791) * support build model in python * fix ci bugs * fix ci bugs * fix compile bugs * fix ci bugs * add infermeta for data * fix ci bugs * fix ci bugs * fix ci bugs * fix bugs when run ir program mutiple times * perfect code * frontend demo debugging * support program split and go into run program node. * simple run the dy2static test in newir_api mode. * remove frame.proto changes * merge * fix ir-run-program-node * fix some code * fix output error * fix some errors * fix * fix * fix * fix conflict * fix files * fix some errors * merge and solve conflict --------- Co-authored-by: YuanRisheng <yuanrisheng@baidu.com> * new pr * fix * fix * fix segment error * fix * add dependences * fix * fix link error. * fix some cmake problem * fix * fix * fix dependecy * fix * fix * fix circle dependence * fix * fix * fix rocm * fix * add python library * fix cmake * merge * fix * fix * fix conflict --------- Co-authored-by: YuanRisheng <yuanrisheng@baidu.com>
* [NewIR] Support Ir run program node (PaddlePaddle#56791) * support build model in python * fix ci bugs * fix ci bugs * fix compile bugs * fix ci bugs * add infermeta for data * fix ci bugs * fix ci bugs * fix ci bugs * fix bugs when run ir program mutiple times * perfect code * frontend demo debugging * support program split and go into run program node. * simple run the dy2static test in newir_api mode. * remove frame.proto changes * merge * fix ir-run-program-node * fix some code * fix output error * fix some errors * fix * fix * fix * fix conflict * fix files * fix some errors * merge and solve conflict --------- Co-authored-by: YuanRisheng <yuanrisheng@baidu.com> * new pr * fix * fix * fix segment error * fix * add dependences * fix * fix link error. * fix some cmake problem * fix * fix * fix dependecy * fix * fix * fix circle dependence * fix * fix * fix rocm * fix * add python library * fix cmake * merge * fix * fix * fix conflict --------- Co-authored-by: YuanRisheng <yuanrisheng@baidu.com>
* [NewIR] Support Ir run program node (PaddlePaddle#56791) * support build model in python * fix ci bugs * fix ci bugs * fix compile bugs * fix ci bugs * add infermeta for data * fix ci bugs * fix ci bugs * fix ci bugs * fix bugs when run ir program mutiple times * perfect code * frontend demo debugging * support program split and go into run program node. * simple run the dy2static test in newir_api mode. * remove frame.proto changes * merge * fix ir-run-program-node * fix some code * fix output error * fix some errors * fix * fix * fix * fix conflict * fix files * fix some errors * merge and solve conflict --------- Co-authored-by: YuanRisheng <yuanrisheng@baidu.com> * new pr * fix * fix * fix segment error * fix * add dependences * fix * fix link error. * fix some cmake problem * fix * fix * fix dependecy * fix * fix * fix circle dependence * fix * fix * fix rocm * fix * add python library * fix cmake * merge * fix * fix * fix conflict --------- Co-authored-by: YuanRisheng <yuanrisheng@baidu.com>
* [NewIR] Support Ir run program node (PaddlePaddle#56791) * support build model in python * fix ci bugs * fix ci bugs * fix compile bugs * fix ci bugs * add infermeta for data * fix ci bugs * fix ci bugs * fix ci bugs * fix bugs when run ir program mutiple times * perfect code * frontend demo debugging * support program split and go into run program node. * simple run the dy2static test in newir_api mode. * remove frame.proto changes * merge * fix ir-run-program-node * fix some code * fix output error * fix some errors * fix * fix * fix * fix conflict * fix files * fix some errors * merge and solve conflict --------- Co-authored-by: YuanRisheng <yuanrisheng@baidu.com> * new pr * fix * fix * fix segment error * fix * add dependences * fix * fix link error. * fix some cmake problem * fix * fix * fix dependecy * fix * fix * fix circle dependence * fix * fix * fix rocm * fix * add python library * fix cmake * merge * fix * fix * fix conflict --------- Co-authored-by: YuanRisheng <yuanrisheng@baidu.com>
* support build model in python * fix ci bugs * fix ci bugs * fix compile bugs * fix ci bugs * add infermeta for data * fix ci bugs * fix ci bugs * fix ci bugs * fix bugs when run ir program mutiple times * perfect code * frontend demo debugging * support program split and go into run program node. * simple run the dy2static test in newir_api mode. * remove frame.proto changes * merge * fix ir-run-program-node * fix some code * fix output error * fix some errors * fix * fix * fix * fix conflict * fix files * fix some errors * merge and solve conflict --------- Co-authored-by: YuanRisheng <yuanrisheng@baidu.com>
* [NewIR] Support Ir run program node (PaddlePaddle#56791) * support build model in python * fix ci bugs * fix ci bugs * fix compile bugs * fix ci bugs * add infermeta for data * fix ci bugs * fix ci bugs * fix ci bugs * fix bugs when run ir program mutiple times * perfect code * frontend demo debugging * support program split and go into run program node. * simple run the dy2static test in newir_api mode. * remove frame.proto changes * merge * fix ir-run-program-node * fix some code * fix output error * fix some errors * fix * fix * fix * fix conflict * fix files * fix some errors * merge and solve conflict --------- Co-authored-by: YuanRisheng <yuanrisheng@baidu.com> * new pr * fix * fix * fix segment error * fix * add dependences * fix * fix link error. * fix some cmake problem * fix * fix * fix dependecy * fix * fix * fix circle dependence * fix * fix * fix rocm * fix * add python library * fix cmake * merge * fix * fix * fix conflict --------- Co-authored-by: YuanRisheng <yuanrisheng@baidu.com>
PR types
New features
PR changes
Others
Description
support dy2static in new ir api mode.
目前这个PR只是一个基础PR,还有很多的分支没有支持:
PCard-66972