diff --git a/mindspore/ccsrc/transform/express_ir/mindir_exporter.cc b/mindspore/ccsrc/transform/express_ir/mindir_exporter.cc index 45c81448b63..67efef1a085 100644 --- a/mindspore/ccsrc/transform/express_ir/mindir_exporter.cc +++ b/mindspore/ccsrc/transform/express_ir/mindir_exporter.cc @@ -246,6 +246,8 @@ bool IrExportBuilder::BuildPrimitives() { prim = real_prim; } + prim_proto->set_instance_name(prim->instance_name()); + // Set primitive attributes for (const auto &attr : prim->attrs()) { MS_LOG(DEBUG) << "attr: " << attr.first << " " << attr.second->DumpText() << " " << attr.second->type_name(); diff --git a/mindspore/core/load_mindir/anf_model_parser.cc b/mindspore/core/load_mindir/anf_model_parser.cc index 084ddeb7cea..9e42781f55e 100644 --- a/mindspore/core/load_mindir/anf_model_parser.cc +++ b/mindspore/core/load_mindir/anf_model_parser.cc @@ -2009,16 +2009,16 @@ bool MSANFModelParser::BuildPrimitiveNode(const mind_ir::PrimitiveProto &primiti if (prim_type.compare(0, strlen(kDoSignaturePrimitivePrefix), kDoSignaturePrimitivePrefix) == 0) { auto op_name = prim_type.substr(strlen(kDoSignaturePrimitivePrefix)); prim = std::make_shared(op_name, std::make_shared(op_name)); - MS_EXCEPTION_IF_NULL(prim); - prim->set_instance_name(op_name); } else { MS_LOG(DEBUG) << "Special node_type: " << prim_type; prim = std::make_shared(prim_type); - MS_EXCEPTION_IF_NULL(prim); - prim->set_instance_name(prim_type); } } + if (primitive_proto.has_instance_name()) { + prim->set_instance_name(primitive_proto.instance_name()); + } + // Set primitive attributes auto prim_to_add_attr = GetValueWithoutDoSignature(prim)->cast(); MS_EXCEPTION_IF_NULL(prim_to_add_attr); diff --git a/mindspore/core/proto/mind_ir.proto b/mindspore/core/proto/mind_ir.proto index 282e73915b8..554138bca4c 100644 --- a/mindspore/core/proto/mind_ir.proto +++ b/mindspore/core/proto/mind_ir.proto @@ -222,4 +222,5 @@ message PrimitiveProto { optional string name = 1; optional string op_type = 2; repeated AttributeProto attribute = 3; + optional string instance_name = 4; }