From 3f1ed2b3bd13c12c803a074fa27aa0156e1b2eda Mon Sep 17 00:00:00 2001 From: chenfei Date: Thu, 15 Sep 2022 17:24:35 +0800 Subject: [PATCH] addn infer fix --- mindspore/core/ops/addn.cc | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/mindspore/core/ops/addn.cc b/mindspore/core/ops/addn.cc index 713a7ef7b9c..c9b42448493 100644 --- a/mindspore/core/ops/addn.cc +++ b/mindspore/core/ops/addn.cc @@ -76,23 +76,24 @@ abstract::ShapePtr AddNInferShape(const PrimitivePtr &primitive, const std::vect for (size_t i = 0; i < elements.size(); ++i) { auto shape = elements[i]->BuildShape(); if (!shape->isa()) { - MS_LOG(EXCEPTION) << "For '" << primitive->name() << "', input[" << i - << "] should be a Tensor, but got:" << elements[i]->ToString(); + MS_EXCEPTION(ValueError) << "For '" << primitive->name() << "', input[" << i + << "] should be a Tensor, but got:" << elements[i]->ToString(); } const auto &shape_vec = shape->cast()->shape(); + // If any shape is dynamic rank, return a dynamic rank. + if (IsDynamicRank(shape_vec)) { + return std::make_shared(ShapeVector({UNKNOWN_RANK})); + } // Record input0's shape. if (i == 0) { output_shape = shape_vec; continue; } - // If any shape is dynamic rank, return a dynamic rank. - if (IsDynamicRank(shape_vec)) { - return std::make_shared(ShapeVector({UNKNOWN_RANK})); - } // Join input[i] with input[0] if (!AddNDynShapeJoin(&output_shape, &shape_vec)) { - MS_LOG(EXCEPTION) << "For '" << primitive->name() << "', input[" << i << "]:" << shape->ToString() - << " is not compatible with input0:" << shape_0->ToString(); + MS_EXCEPTION(ValueError) << "For '" << primitive->name() << "', input shape must be same, but got shape of input[" + << i << "]: " << shape->ToString() << ", shape of input[0]: " << shape_0->ToString() + << "."; } } return std::make_shared(output_shape);