From f178fb4222628d09e609fc98670aa5740756054a Mon Sep 17 00:00:00 2001 From: Liuyinfeng <30849840+gitliuyf@users.noreply.github.com> Date: Thu, 11 Jan 2024 10:16:30 +0800 Subject: [PATCH] [xpu]: check op is null (#60656) --- .../framework/ir/graph_pattern_detector.cc | 3 ++- .../framework/ir/xpu/link_xpu_op_max_pass.cc | 25 ++++++++++--------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/paddle/fluid/framework/ir/graph_pattern_detector.cc b/paddle/fluid/framework/ir/graph_pattern_detector.cc index ac9f4e51068453..aa043803e5d2a3 100644 --- a/paddle/fluid/framework/ir/graph_pattern_detector.cc +++ b/paddle/fluid/framework/ir/graph_pattern_detector.cc @@ -448,7 +448,8 @@ PDNode *PDNode::assert_is_not_ctrl_var() { PDNode *PDNode::assert_var_not_persistable() { assert_is_var(); - asserts_.emplace_back([](Node *x) { return !x->Var()->Persistable(); }); + asserts_.emplace_back( + [](Node *x) { return x->Var() && !x->Var()->Persistable(); }); return this; } diff --git a/paddle/fluid/framework/ir/xpu/link_xpu_op_max_pass.cc b/paddle/fluid/framework/ir/xpu/link_xpu_op_max_pass.cc index 9b552bac36f2d1..db7e8ba2eebeb7 100644 --- a/paddle/fluid/framework/ir/xpu/link_xpu_op_max_pass.cc +++ b/paddle/fluid/framework/ir/xpu/link_xpu_op_max_pass.cc @@ -242,19 +242,20 @@ void LinkXPUOpMaxPass::LinkFcMax(ir::Graph* graph) const { if (IsQuant(w)) return; auto* fusion_op_desc = fusion_op->Op(); - auto* x_pre_op = x->inputs[0]->Op(); - if (x->inputs.size() > 0 && x->inputs[0]->IsOp() && - x_pre_op->HasOutput("out_max")) { - auto preop_max_var_name = x_pre_op->Output("out_max"); - for (auto max_node : x->inputs[0]->outputs) { - if (preop_max_var_name[0] == max_node->Name()) { - if (fusion_op_desc->HasInput("x_max")) { - auto x_max_old_name = fusion_op_desc->Input("x_max")[0]; - fusion_op_desc->RenameInput(x_max_old_name, max_node->Name()); - } else { - fusion_op_desc->SetInput("x_max", {max_node->Name()}); + if (x->inputs.size() > 0) { + auto* x_pre_op = x->inputs[0]->Op(); + if (x->inputs[0]->IsOp() && x_pre_op->HasOutput("out_max")) { + auto preop_max_var_name = x_pre_op->Output("out_max"); + for (auto max_node : x->inputs[0]->outputs) { + if (preop_max_var_name[0] == max_node->Name()) { + if (fusion_op_desc->HasInput("x_max")) { + auto x_max_old_name = fusion_op_desc->Input("x_max")[0]; + fusion_op_desc->RenameInput(x_max_old_name, max_node->Name()); + } else { + fusion_op_desc->SetInput("x_max", {max_node->Name()}); + } + IR_NODE_LINK_TO(max_node, fusion_op); } - IR_NODE_LINK_TO(max_node, fusion_op); } } }