diff --git a/paddle/fluid/API.spec b/paddle/fluid/API.spec index 40301b119cf22529b9d74fd8b6203a222580f48d..6d58d5914adf9a4a3abb041db3202ae68a4dc7c0 100644 --- a/paddle/fluid/API.spec +++ b/paddle/fluid/API.spec @@ -143,7 +143,7 @@ paddle.fluid.layers.group_norm (ArgSpec(args=['input', 'groups', 'epsilon', 'par paddle.fluid.layers.spectral_norm (ArgSpec(args=['weight', 'dim', 'power_iters', 'eps', 'name'], varargs=None, keywords=None, defaults=(0, 1, 1e-12, None)), ('document', '3f536aafba30d793287b52d231baff1b')) paddle.fluid.layers.softmax_with_cross_entropy (ArgSpec(args=['logits', 'label', 'soft_label', 'ignore_index', 'numeric_stable_mode', 'return_softmax'], varargs=None, keywords=None, defaults=(False, -100, True, False)), ('document', 'bce1b75e3d95b75cacd1099655cbb3c3')) paddle.fluid.layers.smooth_l1 (ArgSpec(args=['x', 'y', 'inside_weight', 'outside_weight', 'sigma'], varargs=None, keywords=None, defaults=(None, None, None)), ('document', 'c6b175d253c55baf4b9c0eca9b1dda88')) -paddle.fluid.layers.one_hot (ArgSpec(args=['input', 'depth'], varargs=None, keywords=None, defaults=None), ('document', '6148b6a555cbfb62fdcd030d8982c18c')) +paddle.fluid.layers.one_hot (ArgSpec(args=['input', 'depth'], varargs=None, keywords=None, defaults=None), ('document', 'c87f620c15573442be7c84b50223b567')) paddle.fluid.layers.autoincreased_step_counter (ArgSpec(args=['counter_name', 'begin', 'step'], varargs=None, keywords=None, defaults=(None, 1, 1)), ('document', '3f6c828594720c9b2da89c464be94478')) paddle.fluid.layers.reshape (ArgSpec(args=['x', 'shape', 'actual_shape', 'act', 'inplace', 'name'], varargs=None, keywords=None, defaults=(None, None, False, None)), ('document', '323c019f257e55ddea4a824a362de62f')) paddle.fluid.layers.squeeze (ArgSpec(args=['input', 'axes', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', '3229d06517f794e86ca3da14c38b1465')) diff --git a/paddle/fluid/operators/bilinear_tensor_product_op.cc b/paddle/fluid/operators/bilinear_tensor_product_op.cc index 8d261a118a75ee16027faf60341cefd30c3cdbba..5ba4646a003914312d1a5ca74d452959d6372b90 100644 --- a/paddle/fluid/operators/bilinear_tensor_product_op.cc +++ b/paddle/fluid/operators/bilinear_tensor_product_op.cc @@ -38,9 +38,11 @@ class BilinearTensorProductOp : public framework::OperatorWithKernel { PADDLE_ENFORCE_EQ(y_dims.size(), 2UL, "The input(Y) must be a 2D Tensor."); PADDLE_ENFORCE_EQ(weight_dims.size(), 3UL, "The input(Weight) must be a 3D tensor."); - PADDLE_ENFORCE_EQ(x_dims[0], y_dims[0], - "The first dimension(batch_size) of input(X) must be " - "equal to the first dimension of the input(Y)."); + if (ctx->IsRuntime() || (x_dims[0] > 0 && y_dims[0] > 0)) { + PADDLE_ENFORCE_EQ(x_dims[0], y_dims[0], + "The first dimension(batch_size) of input(X) must be " + "equal to the first dimension of the input(Y)."); + } PADDLE_ENFORCE_EQ(x_dims[1], weight_dims[1], "The second dimension of input(X) must be equal to " "the second dimension of the input(Weight)."); diff --git a/paddle/fluid/operators/crf_decoding_op.cc b/paddle/fluid/operators/crf_decoding_op.cc index e053ae57739d3d96209e9ca180cc041f8b55396e..c701e895af00baffe49838d130d451319ae42c46 100644 --- a/paddle/fluid/operators/crf_decoding_op.cc +++ b/paddle/fluid/operators/crf_decoding_op.cc @@ -95,20 +95,23 @@ class CRFDecodingOp : public framework::OperatorWithKernel { transition_dims[0] - 2, transition_dims[1], "An invalid dimension for the Input(Transition), which should " "be a 2-D tensor with shape [(D + 2) x D]."); - PADDLE_ENFORCE_EQ( - emission_dims[1], transition_dims[1], - "The 2nd dimension of the Input(Emission) and the Input(Transition) " - "should be equal to the tag number."); - + if (ctx->IsRuntime() || (emission_dims[1] > 0 && transition_dims[1] > 0)) { + PADDLE_ENFORCE_EQ( + emission_dims[1], transition_dims[1], + "The 2nd dimension of the Input(Emission) and the Input(Transition) " + "should be equal to the tag number."); + } if (ctx->HasInput("Label")) { auto label_dims = ctx->GetInputDim("Label"); PADDLE_ENFORCE(label_dims.size() == 2UL && label_dims[1] == 1UL, "The Input(Label) should be a 2-D tensor with the 2nd " "dimensions fixed to 1."); - PADDLE_ENFORCE_EQ( - emission_dims[0], label_dims[0], - "The height of Input(Emission) and the height of Input(Label) " - "should be the same."); + if (ctx->IsRuntime() || (emission_dims[0] > 0 && label_dims[0] > 0)) { + PADDLE_ENFORCE_EQ( + emission_dims[0], label_dims[0], + "The height of Input(Emission) and the height of Input(Label) " + "should be the same."); + } } ctx->ShareLoD("Emission", /*->*/ "ViterbiPath"); diff --git a/paddle/fluid/operators/log_loss_op.cc b/paddle/fluid/operators/log_loss_op.cc index e8850a1e582dc5c0a9ad64d26ba9b824349ee4e3..0048c75ccf04687b42f990dc5aa79541359645c1 100644 --- a/paddle/fluid/operators/log_loss_op.cc +++ b/paddle/fluid/operators/log_loss_op.cc @@ -31,14 +31,18 @@ class LogLossOp : public framework::OperatorWithKernel { auto pred_dims = ctx->GetInputDim("Predicted"); auto label_dims = ctx->GetInputDim("Labels"); - PADDLE_ENFORCE_EQ(pred_dims, label_dims); + if (ctx->IsRuntime() || (framework::product(pred_dims) > 0 && + framework::product(label_dims) > 0)) { + PADDLE_ENFORCE_EQ(pred_dims, label_dims); + } PADDLE_ENFORCE_EQ(pred_dims.size(), 2, "The rank of Input(Predicted) must be 2 and the shape is " "[batch_size, 1]."); - PADDLE_ENFORCE_EQ(pred_dims[1], 1, - "Each row of Input(Predicted) contains a real value, " - "so the 2nd dimension of Input(X) must be 1."); - + if (ctx->IsRuntime()) { + PADDLE_ENFORCE_EQ(pred_dims[1], 1, + "Each row of Input(Predicted) contains a real value, " + "so the 2nd dimension of Input(X) must be 1."); + } ctx->SetOutputDim("Loss", {pred_dims[0], 1}); ctx->ShareLoD("Predicted", "Loss"); } diff --git a/paddle/fluid/operators/nce_op.cc b/paddle/fluid/operators/nce_op.cc index fa7cc58c08455457dd129afd130067704ec72c7c..d7d9de17a4038b7c602536c5cfde4a3528bf7b29 100644 --- a/paddle/fluid/operators/nce_op.cc +++ b/paddle/fluid/operators/nce_op.cc @@ -36,7 +36,9 @@ class NCEOp : public framework::OperatorWithKernel { auto x_dims = ctx->GetInputDim("Input"); auto label_dims = ctx->GetInputDim("Label"); - PADDLE_ENFORCE_EQ(x_dims[0], label_dims[0]); + if (ctx->IsRuntime() || (x_dims[0] > 0 && label_dims[0] > 0)) { + PADDLE_ENFORCE_EQ(x_dims[0], label_dims[0]); + } int num_true_classes = label_dims.size() == 2 ? label_dims[1] : 1; if (ctx->HasInput("Bias")) { PADDLE_ENFORCE_EQ(ctx->GetInputDim("Weight")[0], @@ -60,7 +62,8 @@ class NCEOp : public framework::OperatorWithKernel { // set dims of output(SampleOut) std::vector sample_out_dims; sample_out_dims.push_back(x_dims[0]); - sample_out_dims.push_back(num_neg_samples + num_true_classes); + sample_out_dims.push_back( + (num_true_classes == -1) ? -1 : (num_neg_samples + num_true_classes)); ctx->SetOutputDim("SampleLogits", framework::make_ddim(sample_out_dims)); ctx->SetOutputDim("SampleLabels", framework::make_ddim(sample_out_dims)); } diff --git a/paddle/fluid/operators/one_hot_op.cc b/paddle/fluid/operators/one_hot_op.cc index 4fcb1d69935175c3f643db7a4da04db34492f8fb..626895f49d8d4347f1e9a40526943cf00c73d034 100644 --- a/paddle/fluid/operators/one_hot_op.cc +++ b/paddle/fluid/operators/one_hot_op.cc @@ -30,9 +30,10 @@ class OneHotOp : public framework::OperatorWithKernel { auto x_dims = ctx->GetInputDim("X"); PADDLE_ENFORCE_GE(x_dims.size(), 2, "Rank of Input(X) should be at least 2."); - PADDLE_ENFORCE_GE(x_dims[x_dims.size() - 1], 1U, - "Last dimension of Input(X) should be 1."); - + if (ctx->IsRuntime() || x_dims[x_dims.size() - 1] > 0) { + PADDLE_ENFORCE_GE(x_dims[x_dims.size() - 1], 1U, + "Last dimension of Input(X) should be 1."); + } int depth = ctx->Attrs().Get("depth"); PADDLE_ENFORCE_GT(depth, 0, "Should provide a positive depth (%d).", depth); diff --git a/paddle/fluid/operators/random_crop_op.cc b/paddle/fluid/operators/random_crop_op.cc index cd3bd32adb4df0f8d8ab15de6a52ec2f1fbbddf2..dad46ec6683349b9d383368a85411a39750e3e2f 100644 --- a/paddle/fluid/operators/random_crop_op.cc +++ b/paddle/fluid/operators/random_crop_op.cc @@ -60,7 +60,9 @@ class RandomCropOpInferShape : public framework::InferShapeBase { for (size_t i = 1; i <= shape.size(); ++i) { size_t x_i = x_dim.size() - i; size_t shape_i = shape.size() - i; - PADDLE_ENFORCE_GE(x_dim[x_i], shape[shape_i]); + if (ctx->IsRuntime() || (x_dim[x_i] > 0 && shape[shape_i] > 0)) { + PADDLE_ENFORCE_GE(x_dim[x_i], shape[shape_i]); + } out_dim[x_i] = shape[shape_i]; } ctx->SetOutputDim("Out", framework::make_ddim(out_dim)); diff --git a/python/paddle/fluid/layers/nn.py b/python/paddle/fluid/layers/nn.py index 13ae3f0f6c19bdde564f516092c6f8ebcd59a795..275b485e1fba6c0f638f6377a04fce8165e29165 100644 --- a/python/paddle/fluid/layers/nn.py +++ b/python/paddle/fluid/layers/nn.py @@ -6261,7 +6261,7 @@ def one_hot(input, depth): Examples: .. code-block:: python - label = layers.data(name="label", shape=[1], dtype="float32") + label = layers.data(name="label", shape=[1], dtype="int64") one_hot_label = layers.one_hot(input=label, depth=10) """ helper = LayerHelper("one_hot", **locals())