From c384df5e5835ad3a78b70d3476d0b559f70d4bfc Mon Sep 17 00:00:00 2001 From: wxl Date: Wed, 7 Apr 2021 15:22:26 +0800 Subject: [PATCH] fix optional input bug --- ge/generator/ge_generator.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ge/generator/ge_generator.cc b/ge/generator/ge_generator.cc index feff7d21..a800c415 100644 --- a/ge/generator/ge_generator.cc +++ b/ge/generator/ge_generator.cc @@ -69,6 +69,10 @@ bool ContainsDynamicInpus(const ge::OpDesc &op_desc) { } return false; } +// if optional in/out, format is format_reserved and dtype is dt_undefined +bool IsOptional(const ge::GeTensorDesc &tensor_desc) { + return tensor_desc.GetFormat() == ge::FORMAT_RESERVED && tensor_desc.GetDataType() == ge::DT_UNDEFINED; +} } // namespace namespace ge { @@ -746,7 +750,8 @@ void GeGenerator::RemoveConst(const vector &inputs, vector & GeTensorDesc input_desc = input.GetTensorDesc(); bool is_const = false; (void)AttrUtils::GetBool(input_desc, CONST_ATTR_NAME_INPUT, is_const); - if (!is_const) { + bool is_optional = IsOptional(input_desc); + if (!is_optional && !is_const) { outputs.emplace_back(input); } }