-
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
【pir】deal with if build stop gradient #59585
【pir】deal with if build stop gradient #59585
Conversation
for (size_t i = 0; i < op.num_operands(); ++i) { | ||
argument.AddOutput(op.operand(i).type()); | ||
bool input_stop_gradient = true; | ||
auto input = op.operand_source(i).dyn_cast<pir::OpResult>(); |
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.
如果input不是OpResult,而是BlockArgument的话,这句返回的是空的OpResult。 下一句的defining_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
input_stop_gradient = | ||
attrs[input.index()].dyn_cast<pir::BoolAttribute>().data(); | ||
} | ||
outs_stop_gradient.push_back(pir::BoolAttribute::get( |
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.
outs_stop_gradient.push_back(pir::BoolAttribute::get( | |
outs_stop_gradient.push_back(builder.bool_attr(input_stop_gradient)); |
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
} | ||
|
||
argument.AddAttribute(kStopGradientAttrName, | ||
pir::ArrayAttribute::get(pir::IrContext::Instance(), |
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.
pir::ArrayAttribute::get(pir::IrContext::Instance(), | |
pir::ArrayAttribute::get(builder.ir_context(), |
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
|
||
auto cond_ = cond.dyn_cast<pir::OpResult>(); | ||
auto cond_op = cond_.owner(); | ||
if (cond_op->HasAttribute(kStopGradientAttrName)) { |
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.
同理,如果这儿的cond是BlockArgument, 而不是OpResult, 这儿也会崩溃,且没有提示。
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
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
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
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
* merge * add stop gradient * comment
PR types
others
PR changes
others
Description
pcard-67164
TODO