|
|
@ -42,15 +42,29 @@ class MaxSeqPoolFunctor {
|
|
|
|
auto out_dims = output->dims();
|
|
|
|
auto out_dims = output->dims();
|
|
|
|
auto idx_dims = index->dims();
|
|
|
|
auto idx_dims = index->dims();
|
|
|
|
PADDLE_ENFORCE_GT(in_dims.size(), 1,
|
|
|
|
PADDLE_ENFORCE_GT(in_dims.size(), 1,
|
|
|
|
"The rank of input shall be greater than 1.");
|
|
|
|
platform::errors::InvalidArgument(
|
|
|
|
|
|
|
|
"The rank of input shall be greater than 1, but got "
|
|
|
|
|
|
|
|
"the rank is %ld. Please check the input value",
|
|
|
|
|
|
|
|
in_dims.size()));
|
|
|
|
PADDLE_ENFORCE_GT(out_dims.size(), 1,
|
|
|
|
PADDLE_ENFORCE_GT(out_dims.size(), 1,
|
|
|
|
"The rank of output shall be greater than 1.");
|
|
|
|
platform::errors::InvalidArgument(
|
|
|
|
|
|
|
|
"The rank of output shall be greater than 1, but got "
|
|
|
|
|
|
|
|
"the rank is %ld. Please check the input value",
|
|
|
|
|
|
|
|
out_dims.size()));
|
|
|
|
for (int64_t i = 1; i < in_dims.size(); ++i) {
|
|
|
|
for (int64_t i = 1; i < in_dims.size(); ++i) {
|
|
|
|
PADDLE_ENFORCE_EQ(in_dims[i], out_dims[i],
|
|
|
|
PADDLE_ENFORCE_EQ(
|
|
|
|
"The dimension of input and output shall be same.");
|
|
|
|
in_dims[i], out_dims[i],
|
|
|
|
|
|
|
|
platform::errors::InvalidArgument(
|
|
|
|
|
|
|
|
"The dimension of input and output shall be same. Expected %ld "
|
|
|
|
|
|
|
|
"== %ld, but got %ld != %ld. Please check the input value.",
|
|
|
|
|
|
|
|
in_dims[i], out_dims[i], in_dims[i], out_dims[i]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
PADDLE_ENFORCE_EQ(idx_dims, out_dims,
|
|
|
|
PADDLE_ENFORCE_EQ(
|
|
|
|
"The dimension of index and output shall be same.");
|
|
|
|
idx_dims, out_dims,
|
|
|
|
|
|
|
|
platform::errors::InvalidArgument(
|
|
|
|
|
|
|
|
"The dimension of index and output shall be same. Expected %ld == "
|
|
|
|
|
|
|
|
"%ld, but got %ld != %ld. Please check the input value.",
|
|
|
|
|
|
|
|
idx_dims, out_dims, idx_dims, out_dims));
|
|
|
|
|
|
|
|
|
|
|
|
auto lod_level = input.lod().size();
|
|
|
|
auto lod_level = input.lod().size();
|
|
|
|
auto starts = input.lod()[lod_level - 1];
|
|
|
|
auto starts = input.lod()[lod_level - 1];
|
|
|
@ -94,12 +108,22 @@ class MaxSeqPoolFunctor<T, true> {
|
|
|
|
auto in_dims = input.dims();
|
|
|
|
auto in_dims = input.dims();
|
|
|
|
auto out_dims = output->dims();
|
|
|
|
auto out_dims = output->dims();
|
|
|
|
PADDLE_ENFORCE_GT(in_dims.size(), 1,
|
|
|
|
PADDLE_ENFORCE_GT(in_dims.size(), 1,
|
|
|
|
"The rank of input shall be greater than 1.");
|
|
|
|
platform::errors::InvalidArgument(
|
|
|
|
|
|
|
|
"The rank of input shall be greater than 1, but got "
|
|
|
|
|
|
|
|
"%ld <= 1. Please check the input value.",
|
|
|
|
|
|
|
|
in_dims.size()));
|
|
|
|
PADDLE_ENFORCE_GT(out_dims.size(), 1,
|
|
|
|
PADDLE_ENFORCE_GT(out_dims.size(), 1,
|
|
|
|
"The rank of output shall be greater than 1.");
|
|
|
|
platform::errors::InvalidArgument(
|
|
|
|
|
|
|
|
"The rank of output shall be greater than 1, but got "
|
|
|
|
|
|
|
|
"%ld <= 1. Please check the input value.",
|
|
|
|
|
|
|
|
out_dims.size()));
|
|
|
|
for (int64_t i = 1; i < in_dims.size(); ++i) {
|
|
|
|
for (int64_t i = 1; i < in_dims.size(); ++i) {
|
|
|
|
PADDLE_ENFORCE_EQ(in_dims[i], out_dims[i],
|
|
|
|
PADDLE_ENFORCE_EQ(
|
|
|
|
"The dimension of input and output shall be same.");
|
|
|
|
in_dims[i], out_dims[i],
|
|
|
|
|
|
|
|
platform::errors::InvalidArgument(
|
|
|
|
|
|
|
|
"The dimension of input and output shall be same. Expected %ld "
|
|
|
|
|
|
|
|
"== %ld, but got %ld != %ld. Please check the input value.",
|
|
|
|
|
|
|
|
in_dims[i], out_dims[i], in_dims[i], out_dims[i]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
auto lod_level = input.lod().size();
|
|
|
|
auto lod_level = input.lod().size();
|
|
|
@ -139,16 +163,29 @@ class MaxSeqPoolGradFunctor {
|
|
|
|
auto ig_dims = in_grad->dims();
|
|
|
|
auto ig_dims = in_grad->dims();
|
|
|
|
auto idx_dims = index.dims();
|
|
|
|
auto idx_dims = index.dims();
|
|
|
|
PADDLE_ENFORCE_GT(og_dims.size(), 1,
|
|
|
|
PADDLE_ENFORCE_GT(og_dims.size(), 1,
|
|
|
|
"The rank of output@Grad shall be greater than 1.");
|
|
|
|
platform::errors::InvalidArgument(
|
|
|
|
|
|
|
|
"The rank of output@Grad shall be greater than 1, "
|
|
|
|
|
|
|
|
"but got %ld <= 1. Please check the input value.",
|
|
|
|
|
|
|
|
og_dims.size()));
|
|
|
|
PADDLE_ENFORCE_GT(ig_dims.size(), 1,
|
|
|
|
PADDLE_ENFORCE_GT(ig_dims.size(), 1,
|
|
|
|
"The rank of input@Grad shall be greater than 1.");
|
|
|
|
platform::errors::InvalidArgument(
|
|
|
|
|
|
|
|
"The rank of input@Grad shall be greater than 1, but "
|
|
|
|
|
|
|
|
"got %ld <= 1. Please check the input value.",
|
|
|
|
|
|
|
|
ig_dims.size()));
|
|
|
|
for (int64_t i = 1; i < og_dims.size(); ++i) {
|
|
|
|
for (int64_t i = 1; i < og_dims.size(); ++i) {
|
|
|
|
PADDLE_ENFORCE_EQ(
|
|
|
|
PADDLE_ENFORCE_EQ(og_dims[i], ig_dims[i],
|
|
|
|
og_dims[i], ig_dims[i],
|
|
|
|
platform::errors::InvalidArgument(
|
|
|
|
"The dimension of input@Grad and output@Grad shall be same.");
|
|
|
|
"The dimension of input@Grad and output@Grad shall "
|
|
|
|
|
|
|
|
"be same. Expected %ld == %ld, but got %ld != %ld. "
|
|
|
|
|
|
|
|
"Please check the input value.",
|
|
|
|
|
|
|
|
og_dims[i], ig_dims[i], og_dims[i], ig_dims[i]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
PADDLE_ENFORCE_EQ(idx_dims, og_dims,
|
|
|
|
PADDLE_ENFORCE_EQ(
|
|
|
|
"The dimension of index and output@Grad shall be same.");
|
|
|
|
idx_dims, og_dims,
|
|
|
|
|
|
|
|
platform::errors::InvalidArgument(
|
|
|
|
|
|
|
|
"The dimension of index and output@Grad shall be same. Expected "
|
|
|
|
|
|
|
|
"%ld == %ld, but got %ld != %ld. Please check the input value.",
|
|
|
|
|
|
|
|
idx_dims, og_dims, idx_dims, og_dims));
|
|
|
|
|
|
|
|
|
|
|
|
const T* og_data = out_grad.data<T>();
|
|
|
|
const T* og_data = out_grad.data<T>();
|
|
|
|
const int* max_index = index.data<int>();
|
|
|
|
const int* max_index = index.data<int>();
|
|
|
@ -244,9 +281,12 @@ class SumSeqPoolGradFunctor {
|
|
|
|
auto lod = in_grad->lod()[lod_level - 1];
|
|
|
|
auto lod = in_grad->lod()[lod_level - 1];
|
|
|
|
int64_t out_w = out_grad.numel() / out_grad.dims()[0];
|
|
|
|
int64_t out_w = out_grad.numel() / out_grad.dims()[0];
|
|
|
|
int64_t in_w = in_grad->numel() / in_grad->dims()[0];
|
|
|
|
int64_t in_w = in_grad->numel() / in_grad->dims()[0];
|
|
|
|
PADDLE_ENFORCE_EQ(
|
|
|
|
PADDLE_ENFORCE_EQ(in_w, out_w,
|
|
|
|
in_w, out_w,
|
|
|
|
platform::errors::InvalidArgument(
|
|
|
|
"The feature size of input@Grad and output@Grad shall be same.");
|
|
|
|
"The feature size of input@Grad and output@Grad "
|
|
|
|
|
|
|
|
"shall be same. Expected %ld == %ld, but got %ld != "
|
|
|
|
|
|
|
|
"%ld. Please check the input value.",
|
|
|
|
|
|
|
|
in_w, out_w, in_w, out_w));
|
|
|
|
const T* out_g_data = out_grad.data<T>();
|
|
|
|
const T* out_g_data = out_grad.data<T>();
|
|
|
|
T* in_g_data = in_grad->mutable_data<T>(context.GetPlace());
|
|
|
|
T* in_g_data = in_grad->mutable_data<T>(context.GetPlace());
|
|
|
|
auto blas = math::GetBlas<platform::CPUDeviceContext, T>(context);
|
|
|
|
auto blas = math::GetBlas<platform::CPUDeviceContext, T>(context);
|
|
|
@ -298,7 +338,8 @@ class SequencePoolFunctor<platform::CPUDeviceContext, T> {
|
|
|
|
auto place = context.GetPlace();
|
|
|
|
auto place = context.GetPlace();
|
|
|
|
PADDLE_ENFORCE_EQ(
|
|
|
|
PADDLE_ENFORCE_EQ(
|
|
|
|
platform::is_cpu_place(place), true,
|
|
|
|
platform::is_cpu_place(place), true,
|
|
|
|
"Sequence_pool should run on CPU Device when pooltype is SUM");
|
|
|
|
platform::errors::InvalidArgument(
|
|
|
|
|
|
|
|
"Sequence_pool should run on CPU Device when pooltype is SUM"));
|
|
|
|
const T* src = input.data<T>();
|
|
|
|
const T* src = input.data<T>();
|
|
|
|
T* dst = output->mutable_data<T>(place);
|
|
|
|
T* dst = output->mutable_data<T>(place);
|
|
|
|
jit::seq_pool_attr_t attr(
|
|
|
|
jit::seq_pool_attr_t attr(
|
|
|
@ -342,7 +383,10 @@ class SequencePoolFunctor<platform::CPUDeviceContext, T> {
|
|
|
|
out_e.device(place) = in_e.sum(Eigen::array<int, 1>({{0}})) /
|
|
|
|
out_e.device(place) = in_e.sum(Eigen::array<int, 1>({{0}})) /
|
|
|
|
std::sqrt(static_cast<T>(h));
|
|
|
|
std::sqrt(static_cast<T>(h));
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
PADDLE_THROW("unsupported pooling pooltype");
|
|
|
|
PADDLE_THROW(platform::errors::InvalidArgument(
|
|
|
|
|
|
|
|
"unsupported pooling pooltype: %s. Only support \"AVERAGE\" and "
|
|
|
|
|
|
|
|
"\"SQRT\"",
|
|
|
|
|
|
|
|
pooltype));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -400,7 +444,10 @@ class SequencePoolGradFunctor<platform::CPUDeviceContext, T> {
|
|
|
|
} else if (pooltype == "FIRST") {
|
|
|
|
} else if (pooltype == "FIRST") {
|
|
|
|
in_g_e.chip(0, 0).device(place) = out_g_e_v;
|
|
|
|
in_g_e.chip(0, 0).device(place) = out_g_e_v;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
PADDLE_THROW("unsupported pooling pooltype");
|
|
|
|
PADDLE_THROW(platform::errors::InvalidArgument(
|
|
|
|
|
|
|
|
"unsupported pooling pooltype: %s. Only support \"AVERAGE\", "
|
|
|
|
|
|
|
|
"\"SQRT\", \"LAST\" and \"FIRST\"",
|
|
|
|
|
|
|
|
pooltype));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|