Skip to content

Commit f461f7a

Browse files
JerryShihzrphercule
authored andcommitted
Show the op's type and name when the shape inference is failed. (#1623)
1 parent ab8aaf9 commit f461f7a

1 file changed

Lines changed: 34 additions & 28 deletions

File tree

‎onnx/shape_inference/implementation.cc‎

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -152,38 +152,44 @@ static void InferShapesImpl(
152152
}
153153
}
154154

155-
for (int i = 0; i < n.output_size(); ++i) {
156-
if (!ctx.getOutputType(i)->has_tensor_type()) {
157-
continue;
158-
}
159-
const auto& inferredType = ctx.getOutputType(i)->tensor_type();
155+
try {
156+
for (int i = 0; i < n.output_size(); ++i) {
157+
if (!ctx.getOutputType(i)->has_tensor_type()) {
158+
continue;
159+
}
160+
const auto& inferredType = ctx.getOutputType(i)->tensor_type();
160161

161-
// Bail out early if shape inference does nothing useful.
162-
if (inferredType.elem_type() == TensorProto::UNDEFINED &&
163-
!inferredType.has_shape()) {
164-
continue;
165-
}
162+
// Bail out early if shape inference does nothing useful.
163+
if (inferredType.elem_type() == TensorProto::UNDEFINED &&
164+
!inferredType.has_shape()) {
165+
continue;
166+
}
166167

167-
// Find any pre-existing type and shape info. If there is such,
168-
// then check for compatibility with the inferred
169-
// information. Otherwise, initialize it in an empty state.
170-
auto iter = valueTypesByName.find(n.output(i));
171-
TypeProto* existingType = nullptr;
172-
if (iter != valueTypesByName.end()) {
173-
existingType = iter->second;
174-
checkShapesAndTypes(inferredType, existingType->tensor_type());
175-
} else {
176-
auto vi = g->add_value_info();
177-
vi->set_name(n.output(i));
178-
existingType = vi->mutable_type();
179-
}
168+
// Find any pre-existing type and shape info. If there is such,
169+
// then check for compatibility with the inferred
170+
// information. Otherwise, initialize it in an empty state.
171+
auto iter = valueTypesByName.find(n.output(i));
172+
TypeProto* existingType = nullptr;
173+
if (iter != valueTypesByName.end()) {
174+
existingType = iter->second;
175+
checkShapesAndTypes(inferredType, existingType->tensor_type());
176+
} else {
177+
auto vi = g->add_value_info();
178+
vi->set_name(n.output(i));
179+
existingType = vi->mutable_type();
180+
}
180181

181-
// Now we can merge pre-existing and inferred info, without
182-
// further need for error-checking.
183-
mergeShapesAndTypes(inferredType, existingType->mutable_tensor_type());
182+
// Now we can merge pre-existing and inferred info, without
183+
// further need for error-checking.
184+
mergeShapesAndTypes(inferredType, existingType->mutable_tensor_type());
184185

185-
// Make merged info available to further inference.
186-
valueTypesByName[n.output(i)] = existingType;
186+
// Make merged info available to further inference.
187+
valueTypesByName[n.output(i)] = existingType;
188+
}
189+
} catch (const std::runtime_error& err) {
190+
std::string op_name = n.has_name() ? n.name() : "no name";
191+
std::cerr << "(op_type:" << n.op_type() << ", name:" << n.name() << "): " << err.what() << '\n';
192+
throw;
187193
}
188194
}
189195
}

0 commit comments

Comments
 (0)