Packed Function Argument Issue in new Object system

In new Object node system, if we define a packed func which requires Map<std::string, Arrayrelay::Expr> type argument, we cannot pass normal python dict such as {“data”: (relay.Any(), 3, 224, 224)} into it.

TVMError: Check failed: ObjectTypeChecker<TObjectRef>: :Check(ptr): Expected type Map[str,List[relay.Expr]] but get StrMap

This check failed due to the checking for Array element type returned false. Before new object system, this method is valid. Do we want to add it back or switch to new method?

@tqchen @sjr @yzhliu

1 Like

There are probably many use cases that we probably need to mixrture scalars and relay expressions together via packed function. For example, [1, 1, relay.Any()] as Yao has already mentioned.

Then I looked into the ObjectTypeChecker, the conversion from tvm::IntImm to relay::Expr failed, because this is un-supported.

A potential workaround would be avoid Map<String, Array<relay::Expr>> but use Map<String, Array<ObjectRef>>, in which ObjectRef serves as the top type, and we call Downcast<XXX>() to lower it to either tvm::Integer or relay::Any.

However, there are two things I am still wondering:

  1. Before the object protocol, how could the conversion work?
  2. Could we improve the object protocol to make it work again?

In this case, what you really wanted was Array<IndexExpr> aka Array<tvm::Expr> instead of relay.Expr, because Any is a IndexExpr. So the type checker was doing the right thing

Thank you for this suggestion. I have another issue. When I tried to use Array as packed func return type, in ffi convert_to_node I got an error " ValueError: key of map must already been a container type". The integer value here is type int instead of container type. Should I try a different method here?