Skip to content

Commit a3d4144

Browse files
committed
feat(//core/conversion): Adding a check to detect programs that will
result in empty engines and error out Signed-off-by: Naren Dasan <[email protected]> Signed-off-by: Naren Dasan <[email protected]>
1 parent 00d2d0c commit a3d4144

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

Diff for: core/conversion/conversion.cpp

+37-1
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,30 @@ std::set<std::string> GetUnsupportedOpsInBlock(const torch::jit::Block* b) {
433433
return unsupported_ops;
434434
}
435435

436+
std::set<std::string> ConvertableOpsInBlock(const torch::jit::Block* b) {
437+
std::set<std::string> convertable_ops;
438+
for (const auto n : b->nodes()) {
439+
if (n->kind() == torch::jit::prim::Loop || n->kind() == torch::jit::prim::If || converters::node_is_convertable(n)) {
440+
if (n->blocks().size() > 0) {
441+
for (const auto sub_b : n->blocks()) {
442+
auto sub_b_convertable_ops = ConvertableOpsInBlock(sub_b);
443+
convertable_ops.insert(sub_b_convertable_ops.begin(), sub_b_convertable_ops.end());
444+
}
445+
}
446+
if (converters::node_is_convertable(n)) {
447+
auto schema = n->maybeSchema();
448+
TRTORCH_CHECK(
449+
schema,
450+
"Unable to get schema for Node " << util::node_info(n) << " (conversion.CheckForConvertableOps)");
451+
std::stringstream ss;
452+
ss << *schema;
453+
convertable_ops.insert(ss.str());
454+
}
455+
}
456+
}
457+
return convertable_ops;
458+
}
459+
436460
bool VerifyConverterSupportForBlock(const torch::jit::Block* b) {
437461
auto unsupported_ops = GetUnsupportedOpsInBlock(b);
438462

@@ -448,7 +472,19 @@ bool VerifyConverterSupportForBlock(const torch::jit::Block* b) {
448472
unsupported_msg << "https://www.github.com/nvidia/TRTorch/issues" << std::endl;
449473
LOG_ERROR(unsupported_msg.str());
450474
return false;
451-
} else {
475+
}
476+
477+
if (ConvertableOpsInBlock(b).size() == 0) {
478+
std::stringstream unsupported_msg;
479+
unsupported_msg << "Method requested cannot be compiled by TRTorch.\nThere is no work to be done since the resulting compiled program will contain an engine that is empty."
480+
<< std::endl;
481+
unsupported_msg << "This may be because there are no operators that can be added to the TensorRT graph or all operators have a resolved compile time value."
482+
<< std::endl;
483+
LOG_ERROR(unsupported_msg.str());
484+
return false;
485+
}
486+
487+
else {
452488
return true;
453489
}
454490
}

0 commit comments

Comments
 (0)