-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
[Inference] Support constant_folding_pass on PIR #58753
Conversation
860d464
to
a30a22a
Compare
pir::Program* new_program) const { | ||
pir::Builder builder = pir::Builder(ir_context(), new_program->block()); | ||
std::string output_var_name = | ||
"constant_folding@" + std::to_string((*counter_)++); |
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.
用counter做唯一标识输出var name感觉不是很安全
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.
提醒了我,这里有个潜在问题,随着折叠的深度,name拼接后会越来越长,我修一下
// pm.EnableIRPrinting(std::make_unique<pir::PassManager::IRPrinterOption>( | ||
// [](pir::Pass *pass, pir::Operation *op) { | ||
// return pass->name() == "constant_folding_pass"; | ||
// }, | ||
// [](pir::Pass *pass, pir::Operation *op) { | ||
// return pass->name() == "constant_folding_pass"; | ||
// }, | ||
// true, | ||
// true)); |
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.
留着吧,给其他用户的使用示例~
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.
swintransformer模型上op折叠率42%(4907/11470),折叠前后性能提升25.7%(70ms/52ms)
这里有没有原先的常量折叠Pass的折叠率数据作为对比?
你说旧IR的实现吧,这比起来其实没有意义,旧模型转换到pir模型后,总op数量和被折叠的数量都不一样。算一下旧的折叠率的话,37% |
从op数量看这个数据确实意义不大,我刚才把折叠率理解成权重数量在折叠前后的对比,新旧IR的权重数量是一致的,如果折叠逻辑对齐的话折叠掉的参数数量应该是相同的,在不相同的时候这里数据或许一定的参考价值。 |
auto* param_var = scope_->FindVar(param_name); | ||
PADDLE_ENFORCE_NOT_NULL( | ||
param_var, | ||
phi::errors::InvalidArgument("Parameter var not in scope.")); | ||
deleted_vars_->push_back(param_name); |
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.
这里需不需要判断下param有没有被其他op使用?
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, thanks!
32c5076
to
b4e4a1c
Compare
* fix shadow_output_op * update * rewrite constant_folding_pass * update * update * fix compile * fix dce * enhance judgement
* fix shadow_output_op * update * rewrite constant_folding_pass * update * update * fix compile * fix dce * enhance judgement
PR types
Performance optimization
PR changes
Others
Description
前置PR: #58732
针对PIR,实现常量折叠pass并在swintransformer模型上跑通:
TODO:
Others
Pcard-71500