diff --git a/paddle/fluid/operators/matmul_op.cc b/paddle/fluid/operators/matmul_op.cc index e226ab532884446490d292c656c53c853327576d..988a6c4f7da997277635ab3955dd62b9c93c9171 100644 --- a/paddle/fluid/operators/matmul_op.cc +++ b/paddle/fluid/operators/matmul_op.cc @@ -232,7 +232,9 @@ class MatMulGradKernel : public framework::OpKernel { int head_number = 1; #if defined(PADDLE_WITH_MKLML) && !defined(PADDLE_WITH_CUDA) && \ !defined(PADDLE_WITH_HIP) - head_number = context.Attr("head_number"); + if (context.HasAttr("head_number")) { + head_number = context.Attr("head_number"); + } #endif if (head_number <= 1 && a.dims().size() == 3 && b.dims().size() <= 2) {