diff --git a/src/printer/relay_text_printer.cc b/src/printer/relay_text_printer.cc index 076339d774b45..ad16f862ac2bc 100644 --- a/src/printer/relay_text_printer.cc +++ b/src/printer/relay_text_printer.cc @@ -91,7 +91,8 @@ Doc RelayTextPrinter::PrintScope(const ObjectRef& node) { } Doc RelayTextPrinter::PrintFinal(const ObjectRef& node) { - if (node->IsInstance() && !node->IsInstance()) { + if (node.defined() && node->IsInstance() && + !node->IsInstance()) { // Temporarily skip non-relay functions. // TODO(tvm-team) enhance the code to work for all functions } else if (node.as()) { @@ -105,8 +106,8 @@ Doc RelayTextPrinter::PrintFinal(const ObjectRef& node) { } Doc RelayTextPrinter::Print(const ObjectRef& node, bool meta, bool try_inline) { - bool is_non_relay_func = - node->IsInstance() && !node->IsInstance(); + bool is_non_relay_func = node.defined() && node->IsInstance() && + !node->IsInstance(); if (node.as() && !is_non_relay_func) { return PrintExpr(Downcast(node), meta, try_inline); } else if (node.as()) {