未验证 提交 43d70bcc 编写于 作者: J Jiabin Yang 提交者: GitHub

Speed up sr accumulation (#42658)

* Support Gradient Accumulation for sr

* add ut

* change ut to fit small vector

* speed up accumulation
上级 35c7c835
...@@ -34,22 +34,9 @@ static void CopyOrAddTensor(paddle::experimental::Tensor* tensor, ...@@ -34,22 +34,9 @@ static void CopyOrAddTensor(paddle::experimental::Tensor* tensor,
*tensor = t; *tensor = t;
} else { } else {
// Accumulation // Accumulation
PADDLE_ENFORCE_EQ(t.initialized(), true, if (LIKELY(t.is_dense_tensor())) {
paddle::platform::errors::Fatal( if (LIKELY(tensor->is_dense_tensor())) {
"We can only accumulate initialized tensor, but we "
"got tensor: %s is empty please check you network "
"and make sure it creates grads.",
t.name()));
PADDLE_ENFORCE_NOT_NULL(
tensor, paddle::platform::errors::Fatal(
"We can only accumulate initialized tensor to non-nullptr "
"tensor but we got nullptr please check you network "
"and make sure it creates grads."));
if (t.is_dense_tensor()) {
if (tensor->is_dense_tensor()) {
paddle::imperative::TensorAdd<paddle::experimental::Tensor>(t, tensor); paddle::imperative::TensorAdd<paddle::experimental::Tensor>(t, tensor);
} else { } else {
// TODO(jiabin): Support Other TensorBase later // TODO(jiabin): Support Other TensorBase later
// TODO(zhanlve): Replace SelectedRowsAddTensor with // TODO(zhanlve): Replace SelectedRowsAddTensor with
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册