-
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
Support 0-size tensor in parameter creating, forward and backward #70504
Support 0-size tensor in parameter creating, forward and backward #70504
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
8fc5483
to
7b396b4
Compare
@@ -65,7 +65,7 @@ static void CopyOrAddTensor(paddle::Tensor* tensor, | |||
*reinterpret_cast<phi::DenseTensor*>(tensor->impl().get()), | |||
*reinterpret_cast<phi::DenseTensor*>(t.impl().get()), | |||
reinterpret_cast<phi::DenseTensor*>(tensor->impl().get())); | |||
} else { | |||
} else if (t.initialized() && tensor->initialized()) { | |||
paddle::imperative::TensorAdd<paddle::Tensor>(t, tensor); | |||
} |
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分支
paddle/fluid/eager/backward.cc
Outdated
@@ -354,7 +355,8 @@ std::vector<paddle::Tensor> RunBackward( | |||
paddle::Tensor& grad_output_tensor = grad_output_tensors[i][j]; | |||
|
|||
if ((!grad_output_tensor.defined() || | |||
!grad_output_tensor.initialized())) { | |||
!(grad_output_tensor.defined() && | |||
grad_output_tensor.has_allocation()))) { |
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.
- 已将所有
paddle::Tensor
相关的defined() && has_allocation()
改为has_allocation()
- 移除了几处分布式相关的修改(本PR只修改单机,暂不修改分布式相关逻辑)
38adde9
to
942f58b
Compare
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
PR Category
Operator Mechanism
PR Types
New features
Description
Pcard-75624
相关issue:deepmodeling/deepmd-kit#4514 (comment)
0-size Tensor的支持需要满足前反向机制改造 + 前反向 Kernel 改造,本PR在框架的前反向相关机制上进行了适配:“放宽”了部分代码执行分支的判断条件,将0-size视为正常Tensor而不是非法Tensor抛出异常,从而让0-size Tensor能够进入某些分支进行一些预期的操作。前向、反向kernel适配见相关PR集合:paddle Tensor 规范化第二期
从端到端的角度来看,本PR的改动体现在以下三个方面:
tanh_grad
,那么需要tanh_grad kernel支持0-size输入)