diff --git a/paddle/fluid/framework/operator.cc b/paddle/fluid/framework/operator.cc index 9f48b8cb9e72e7b826156502d2b89bd576388108..e4bbcabea71ec9aa7ebff9d5371a0f49e3f6f7b7 100644 --- a/paddle/fluid/framework/operator.cc +++ b/paddle/fluid/framework/operator.cc @@ -926,12 +926,7 @@ void OperatorWithKernel::RunImpl(const Scope& scope, dev_ctx = pool.Get(expected_kernel_key.place_); } - // If Op has attribute all_kernels_must_compute_runtime_shape, - // all the kernels of this Op would compute runtime shape, - // and skip infershape in runtime for speedup. - // TODO(luotao): Note that it is a temporal attribute, after all ops - // implement computing runtime shape, this attribute would be deleted. - if (!HasAttr("all_kernels_must_compute_runtime_shape")) { + if (!HasAttr(kAllKernelsMustComputeRuntimeShape)) { RuntimeInferShapeContext infer_shape_ctx(*this, exec_scope, ctx); this->InferShape(&infer_shape_ctx); } diff --git a/paddle/fluid/framework/operator.h b/paddle/fluid/framework/operator.h index 55629636a816982c4debe4b5b7138558ac309eb5..822bf5c9ceaa31e1283fa3cf1dbe42a43894a5dd 100644 --- a/paddle/fluid/framework/operator.h +++ b/paddle/fluid/framework/operator.h @@ -62,6 +62,15 @@ constexpr char kZeroVarSuffix[] = "@ZERO"; /// Variables with this suffix are the new Gradient. constexpr char kNewGradSuffix[] = "@NEWGRAD@"; +/// If an Op has this attribute, all its kernels should calculate output +/// variable's shape in the corresponding Compute() function. And +/// OperatorWithKernel::RunImpl() would skip call this Op's InferShape() +/// function in its runtime for speedup. +/// TODO(luotao): Note that this temporal attribute would be deleted after all +/// ops contain it. +constexpr char kAllKernelsMustComputeRuntimeShape[] = + "@ALL_KERNELS_MUST_COMPUTE_RUNTIME_SHAPE@"; + // define some kernel priority /* Define multiple kernel type fallback order*/ extern std::vector> kKernelPriority; diff --git a/paddle/fluid/operators/fused/fused_embedding_seq_pool_op.cc b/paddle/fluid/operators/fused/fused_embedding_seq_pool_op.cc index 17a81d3e8805a5ed9fc9bb5310227df78eefa056..a0026427e2514735711f7eba26fcf861cb498d5e 100644 --- a/paddle/fluid/operators/fused/fused_embedding_seq_pool_op.cc +++ b/paddle/fluid/operators/fused/fused_embedding_seq_pool_op.cc @@ -88,13 +88,7 @@ class FusedEmbeddingSeqPoolOpMaker : public framework::OpProtoAndCheckerMaker { "(boolean, default false) " "Sparse update.") .SetDefault(false); - AddAttr( - "all_kernels_must_compute_runtime_shape", - "(boolean, default true) " - "An attribute to speed up OperatorWithKernel::RunImpl." - "If true, all the kernels of this Op would compute runtime " - "shape, but skip infershape in runtime. Note that it is a temporal " - "attribute, please do DOT set it in python layer.") + AddAttr(framework::kAllKernelsMustComputeRuntimeShape, "") .SetDefault(true); AddComment(R"DOC( FusedEmbeddingSeqPool Operator. diff --git a/paddle/fluid/operators/hash_op.cc b/paddle/fluid/operators/hash_op.cc index b39eba081ec32ed50ac78a0ea5b3aff3ed4045d2..f6395fb32feac175976cb96e1c0bee7347cb3ea8 100644 --- a/paddle/fluid/operators/hash_op.cc +++ b/paddle/fluid/operators/hash_op.cc @@ -54,13 +54,7 @@ $$Out = scale * X$$ )DOC"); AddAttr("num_hash", "").SetDefault(1); AddAttr("mod_by", "").SetDefault(100000); - AddAttr( - "all_kernels_must_compute_runtime_shape", - "(boolean, default true) " - "An attribute to speed up OperatorWithKernel::RunImpl." - "If true, all the kernels of this Op would compute runtime " - "shape, but skip infershape in runtime. Note that it is a temporal " - "attribute, please do DOT set it in python layer.") + AddAttr(framework::kAllKernelsMustComputeRuntimeShape, "") .SetDefault(true); } }; diff --git a/paddle/fluid/operators/sequence_ops/sequence_enumerate_op.cc b/paddle/fluid/operators/sequence_ops/sequence_enumerate_op.cc index 63e95e8654412048ff54fc6407984949152f58d4..f357c9c08d042b69259f229955922f2f11b52c63 100644 --- a/paddle/fluid/operators/sequence_ops/sequence_enumerate_op.cc +++ b/paddle/fluid/operators/sequence_ops/sequence_enumerate_op.cc @@ -59,13 +59,7 @@ class SequenceEnumerateOpMaker : public framework::OpProtoAndCheckerMaker { }); AddAttr("pad_value", "(int) The enumerate sequence padding value.") .SetDefault(0); - AddAttr( - "all_kernels_must_compute_runtime_shape", - "(boolean, default true) " - "An attribute to speed up OperatorWithKernel::RunImpl." - "If true, all the kernels of this Op would compute runtime " - "shape, but skip infershape in runtime. Note that it is a temporal " - "attribute, please do DOT set it in python layer.") + AddAttr(framework::kAllKernelsMustComputeRuntimeShape, "") .SetDefault(true); AddComment(R"DOC( Sequence Enumerate Operator.