diff --git a/paddle/fluid/framework/operator.cc b/paddle/fluid/framework/operator.cc index 040f669f2b..1723a9a78a 100644 --- a/paddle/fluid/framework/operator.cc +++ b/paddle/fluid/framework/operator.cc @@ -884,6 +884,8 @@ void OperatorWithKernel::RunImpl(const Scope& scope, // result of HasAttr. if (!enable_cache_runtime_context && HasAttr(kEnableCacheRuntimeContext)) enable_cache_runtime_context = true; + if (!enable_cache_expected_kernel && HasAttr(kEnableCacheExpectedKernel)) + enable_cache_expected_kernel = true; if (!all_kernels_must_compute_runtime_shape && HasAttr(kAllKernelsMustComputeRuntimeShape)) all_kernels_must_compute_runtime_shape = true; @@ -906,7 +908,7 @@ void OperatorWithKernel::RunImpl(const Scope& scope, platform::DeviceContextPool& pool = platform::DeviceContextPool::Instance(); auto* dev_ctx = pool.Get(place); - if (!HasAttr(kEnableCacheExpectedKernel) || !kernel_type_) { + if (!enable_cache_expected_kernel || !kernel_type_) { ChooseKernel(*runtime_ctx, scope, place); } diff --git a/paddle/fluid/framework/operator.h b/paddle/fluid/framework/operator.h index 2e733badb8..489b660996 100644 --- a/paddle/fluid/framework/operator.h +++ b/paddle/fluid/framework/operator.h @@ -507,6 +507,7 @@ class OperatorWithKernel : public OperatorBase { mutable std::unique_ptr runtime_ctx_; mutable const Scope* pre_scope_ = nullptr; mutable bool enable_cache_runtime_context = false; + mutable bool enable_cache_expected_kernel = false; mutable bool all_kernels_must_compute_runtime_shape = false; };