-
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
[Phi] Change the output format of C++ backward api (Part2) #42545
Changes from 14 commits
2a248c5
a181c1b
004e791
6d5fdf4
7ea2b71
25eba8d
a12b2ff
c8c2fe2
388dedd
2c3e6f3
8395a96
8bed60d
2cbc708
0ace82d
6d0913d
53bb812
2ab5b82
28d45b1
4390cd0
fdfd6eb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -218,6 +218,8 @@ void GradNodeBase::SetGradOutMeta(const paddle::experimental::Tensor& fwd_in, | |
// Set Stop_gradient | ||
if (fwd_in_meta) { | ||
meta.SetStopGradient(fwd_in_meta->StopGradient()); | ||
} else { | ||
meta.SetStopGradient(true); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. default value is true There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
// Set Adj Edges | ||
if (fwd_in_meta && !fwd_in_meta->StopGradient()) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -165,12 +165,14 @@ void EagerUtils::SetHistory(std::vector<AutogradMeta*>* autograd_metas, | |
|
||
void EagerUtils::SetHistory(AutogradMeta* autograd_meta, | ||
const std::shared_ptr<GradNodeBase>& grad_node) { | ||
if (autograd_meta->GradNode()) { | ||
VLOG(7) << "Should not set grad node twice, original node is:" | ||
<< autograd_meta->GradNode()->name() | ||
<< "current is: " << grad_node->name(); | ||
if (autograd_meta) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will this be nullptr? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 剪枝后输出的Tensor可能没有AutogradMeta |
||
if (autograd_meta->GradNode()) { | ||
VLOG(7) << "Should not set grad node twice, original node is:" | ||
<< autograd_meta->GradNode()->name() | ||
<< "current is: " << grad_node->name(); | ||
} | ||
autograd_meta->SetGradNode(grad_node); | ||
} | ||
autograd_meta->SetGradNode(grad_node); | ||
} | ||
|
||
void EagerUtils::SetOutRankWithSlot(std::vector<AutogradMeta*>* targets, | ||
|
@@ -181,7 +183,7 @@ void EagerUtils::SetOutRankWithSlot(std::vector<AutogradMeta*>* targets, | |
} | ||
} | ||
void EagerUtils::SetOutRankWithSlot(AutogradMeta* target, size_t slot_id) { | ||
target->SetSingleOutRankWithSlot(slot_id, 0); | ||
if (target) target->SetSingleOutRankWithSlot(slot_id, 0); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 同上 |
||
} | ||
|
||
std::shared_ptr<egr::EagerVariable> EagerUtils::TrySyncToVar( | ||
|
@@ -450,17 +452,13 @@ void EagerUtils::FillZeroForEmptyGradInputs( | |
paddle::experimental::Tensor& grad = (*in_grads)[i][j]; | ||
if (!grad.initialized()) { | ||
const GradSlotMeta& grad_in_meta = grad_in_metas[i][j]; | ||
PADDLE_ENFORCE( | ||
grad_in_meta.HasTensorMeta(), | ||
paddle::platform::errors::Fatal( | ||
"Unable to fill empty grad inputs due to empty GradSlotMeta")); | ||
|
||
const auto& tensor_meta = grad_in_meta.GetTensorMeta(); | ||
phi::Place place = grad_in_meta.GetPlace(); | ||
|
||
auto tensor_with_zero = paddle::experimental::full( | ||
phi::vectorize(tensor_meta.dims), 0.0, tensor_meta.dtype, place); | ||
grad.set_impl(tensor_with_zero.impl()); | ||
if (grad_in_meta.HasTensorMeta()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why remove this check There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 反向计算经过剪枝后,在高阶导的计算中可能会出现一些不需要的输入Tensor,这里原来的check逻辑会将这些Tensor拦截,导致不能往下计算。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 根据昨天的结论做了调整:
|
||
const auto& tensor_meta = grad_in_meta.GetTensorMeta(); | ||
auto tensor_with_zero = paddle::experimental::full( | ||
phi::vectorize(tensor_meta.dims), 0.0, tensor_meta.dtype, | ||
grad_in_meta.GetPlace()); | ||
grad.set_impl(tensor_with_zero.impl()); | ||
} | ||
} | ||
} | ||
} | ||
|
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.
maybe only one for loop can do this all, because we have the same size for
out_metas
,returns
,api_output
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. thx