From 14fd53d5840fb1bdce6b8d3fad04087982824f06 Mon Sep 17 00:00:00 2001 From: zyfncg Date: Fri, 26 Nov 2021 16:32:58 +0800 Subject: [PATCH] fix bug of slice_grad using use_mkldnn attr (#37584) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit slice_grad op在选择kernel过程中出现错误,问题原因是在获取use_mkldnn属性时,map中未找到该键值,所以抛出out_of_range异常 本PR在map获取use_mkldnn属性数据前增加了是否存在该键值的判断逻辑,从而避免出现上述异常 --- paddle/fluid/framework/operator.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/paddle/fluid/framework/operator.cc b/paddle/fluid/framework/operator.cc index c847467294d..cb459f3834b 100644 --- a/paddle/fluid/framework/operator.cc +++ b/paddle/fluid/framework/operator.cc @@ -1066,8 +1066,9 @@ bool OperatorWithKernel::SupportsMKLDNN( bool OperatorWithKernel::CanMKLDNNBeUsed(const framework::ExecutionContext& ctx, proto::VarType::Type data_type) const { - bool use_mkldnn_ctx = - ctx.Attr("use_mkldnn") && platform::is_cpu_place(ctx.GetPlace()); + bool use_mkldnn_ctx = ctx.HasAttr("use_mkldnn") && + ctx.Attr("use_mkldnn") && + platform::is_cpu_place(ctx.GetPlace()); return use_mkldnn_ctx && this->SupportsMKLDNN(data_type); } -- GitLab