Skip to content

Commit

Permalink
fix bug of slice_grad using use_mkldnn attr (#37584)
Browse files Browse the repository at this point in the history
slice_grad op在选择kernel过程中出现错误,问题原因是在获取use_mkldnn属性时,map中未找到该键值,所以抛出out_of_range异常
本PR在map获取use_mkldnn属性数据前增加了是否存在该键值的判断逻辑,从而避免出现上述异常
  • Loading branch information
zyfncg authored Nov 26, 2021
1 parent 3a81805 commit 14fd53d
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions paddle/fluid/framework/operator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool>("use_mkldnn") && platform::is_cpu_place(ctx.GetPlace());
bool use_mkldnn_ctx = ctx.HasAttr("use_mkldnn") &&
ctx.Attr<bool>("use_mkldnn") &&
platform::is_cpu_place(ctx.GetPlace());
return use_mkldnn_ctx && this->SupportsMKLDNN(data_type);
}

Expand Down

0 comments on commit 14fd53d

Please sign in to comment.