sum op support empty selected rows as input

revert-15207-remove_op_handle_lock_and_fix_var
Qiao Longfei 6 years ago
parent e77f54734b
commit 25d44d40ac

@ -195,6 +195,10 @@ struct SelectedRowsAddToTensor<platform::CPUDeviceContext, T> {
void operator()(const platform::CPUDeviceContext& context,
const framework::SelectedRows& input1,
framework::Tensor* input2) {
if (input1.rows().size() == 0) {
LOG(WARNING) << "input selected rows is empty!";
return;
}
auto in1_height = input1.height();
auto in2_dims = input2->dims();
PADDLE_ENFORCE_EQ(in1_height, in2_dims[0]);

@ -41,7 +41,9 @@ class SumOp : public framework::OperatorWithKernel {
return; // skip runtime infershape when is tensor array;
}
auto x_var_types = ctx->GetInputsVarType("X");
auto x_dims = ctx->GetInputsDim("X");
size_t N = x_dims.size();
PADDLE_ENFORCE_GT(N, 0, "Input tensors count should > 0.");
if (N == 1) {
@ -49,7 +51,11 @@ class SumOp : public framework::OperatorWithKernel {
}
framework::DDim in_dim({0});
for (auto& x_dim : x_dims) {
for (size_t i = 0; i < x_dims.size(); ++i) {
if (x_var_types[i] == framework::proto::VarType::SELECTED_ROWS) {
continue;
}
auto& x_dim = x_dims[i];
if (framework::product(x_dim) == 0) {
continue;
}

Loading…
Cancel
Save