[DISCUSS] Unify Relay::Value with Relay VM object

Previous, we use relay::Value to hold objects in the interpreter, and use relay::vm::Object to hold the objects in VM.

As we are moving toward a unified runtime object protocol, it would be really nice to unify these objects. So we no long have to say that “hey this object is specific for VM”, they are just normal tvm runtime objects.

Of course, we know that some of these objects need additional fields to hold reference to interpreter. These can be done via sub-classing (e.g. make TensorValue a sub-class of NDArray, perhaps we also want to bring a better name) so that from users’ perspective, they can treat them as runtime data structure.

Please share your thoughts and see if you are interested in help to push for this change.

cc @jroesch @MarisaKirisame @wweic @haichen @zhiics @frozengene

This probably would help us unify the objects used in VM and interpreter as well. We currently have separate Tensor objects even in VM and interpreter.

I like the unification of Value and VMObject. Only thing we need to solve is how to handle closure value node.

would sub-classing suffice for the case? e.g. ClosureValue sub-class vm::closure, this of course depends on the common fields that they need to reuse

1 Like

I can take a look. I remember they have quite different members. BTW, TensorValue and TensorObj should be safely replaced by NDArray, right?

Yes, closure requires some unification. The variable environment in interpreter is a compile time container Map, vm is std::vector. And function body in interpreter is the Function expression(with Stmt or PackedFunction, vm is a index to the compiled function(either sequence of bytecode or PackedFunction).

The environment maybe we can unify with runtime container. For function body I think they will have to diverge. Or we move the specific function body implementation into private area internal to interpreter or vm, in the closure we just store a reference(could be an integer).

In that case, perhaps we can start with a common base class that both vm and closureValue can sub-class.

Should we directly remove TensorObj and TensorValue, and use NDArray directly? I spent some time on it this afternoon. If so, I can finish that first.