CARVIEW |
Navigation Menu
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
add cinn arrcuracy check #63829
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
add cinn arrcuracy check #63829
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
|
||
bool MatchAndRewrite(cinn::dialect::FusionOp fusion_op, | ||
pir::PatternRewriter& rewriter) const override { | ||
auto op_list = fusion_op.GetOperators(); |
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.
变量应尽量使用 const 限定符
auto group_info = fusion_op.attribute("group_info") | ||
.dyn_cast<cinn::dialect::GroupInfoAttribute>() | ||
.data(); | ||
auto fn_name = group_info.fn_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.
auto fn_name = group_info.fn_name; | |
const auto& fn_name = group_info.fn_name; |
若接口和方法返回的是引用类型,应尽可能使用引用
if (op->isa<::pir::YieldOp>()) { | ||
rewriter.SetInsertionPointAfter(fusion_op); | ||
for (size_t i = 0; i < op->num_operands(); ++i) { | ||
rewriter.Build<paddle::dialect::AccuracyCheckOp>( |
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.
每个if分支内部建议使用 lambda 函数单独定义,提升可读性,也可降低for-if-for的嵌套层级。
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.
const auto& InsertAccuaryCheckOp = [&]() -> decltype(auto) {};
for (auto op : op_list) {
if (op->isa<::pir::YieldOp>()) {
InsertAccuaryCheckOp();
}
|
||
class AccuarcyCheckPass : public pir::Pass { | ||
public: | ||
AccuarcyCheckPass() : pir::Pass("accuarcy_check_pass", /*opt_level=*/1) {} |
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.
建议了解下op_level不同取值的表达的意义
#include "paddle/pir/include/pass/pass.h" | ||
|
||
namespace cinn { | ||
namespace dialect { |
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.
namespace dialect { | |
namespace cinn::dialect::ir { |
可以这样写
return op_transformers[op->name()](op, builder); | ||
} | ||
|
||
void RewriteCinnOpToPdOp(::pir::Block* src_block, ::pir::Block* target_block) { |
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.
void RewriteCinnOpToPdOp(::pir::Block* src_block, ::pir::Block* target_block) { | |
void RewriteCinnOpToPdOp(const ::pir::Block& src_block, ::pir::Block* target_block) { |
void RewriteCinnOpToPdOp(::pir::Block* src_block, ::pir::Block* target_block) { | ||
VLOG(8) << "Rewrite CinnOp to PdOp for block."; | ||
if (src_block == nullptr || target_block == nullptr) { | ||
return; |
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.
ENFORCE_NOT_NULL(target_block)
|
||
auto x_numel = x.numel(); | ||
for (int64_t i = 0; i < x_numel; ++i) { | ||
if (!allclose(x_cpu.data<T>()[i], y_cpu.data<T>()[i])) { |
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 输出两个值
#include "paddle/phi/core/kernel_registry.h" | ||
#include "paddle/phi/core/tensor_utils.h" | ||
|
||
const float atol_v = 1e-5; |
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.
const float atol_v = 1e-5; | |
constexpr float kAtolValue = 1e-5; |
DenseTensor* out) { | ||
PADDLE_ENFORCE_EQ(x.dims(), | ||
y.dims(), | ||
phi::errors::PreconditionNotMet("input Dim must equal")); |
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.
phi::errors::PreconditionNotMet("input Dim must equal")); | |
phi::errors::PreconditionNotMet("input Dim must be equal")); |
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
|
||
const auto& handler_reduce_max_op = | ||
[&](::pir::Operation* op, | ||
const ::pir::Builder& builder) -> ::pir::Operation* { |
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.
const ::pir::Builder& builder) -> ::pir::Operation* { | |
::pir::Builder& builder // NOLINT | |
) -> ::pir::Operation* { |
|
||
} // namespace cinn::dialect::details | ||
|
||
REGISTER_TRANSFORM_RULES(reduce_max_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.
这个宏是不是可以精简为两个参数就可以了?
* add cinn arrcuracy check * update * update date * AccuracyCheckPass * update * Refine as commented * update * update * update --------- Co-authored-by: phlrain <phliuhongyu@126.com>
* add cinn arrcuracy check * update * update date * AccuracyCheckPass * update * Refine as commented * update * update * update --------- Co-authored-by: phlrain <phliuhongyu@126.com>
* add cinn arrcuracy check * update * update date * AccuracyCheckPass * update * Refine as commented * update * update * update --------- Co-authored-by: phlrain <phliuhongyu@126.com>
* add cinn arrcuracy check * update * update date * AccuracyCheckPass * update * Refine as commented * update * update * update --------- Co-authored-by: phlrain <phliuhongyu@126.com>
* add cinn arrcuracy check * update * update date * AccuracyCheckPass * update * Refine as commented * update * update * update --------- Co-authored-by: phlrain <phliuhongyu@126.com>
PR Category
Others
PR Types
Others
Description
Pcard-67164