[Relay] how to get value of tvm.relay.expr.Var

Hi tvm community,

I am working on the implementation of the operator for frontend/onnx.py, and I need to extract the value(tuple) from tvm.relay.expr.Var. I would appreciate if you can point me in the direction.

many thanks,

Hi, I don’t think it is possible, actually if you look at the tir.Var class, it only contains the shape information, the weight value (I meant conv op for example) is actually stored in tvm_params dict (refer to func from_pytorch() in relay/frontend/pytorch.py)

A Relay variable is represents a value which will later be around at runtime, during compilation you can’t directly treat it as a value. For example if you want to build a program which will get out a runtime component of a tuple you can do.

v = relay.var(...)
z = relay.TupleGetItem(v, 0) # this will build a program which will compute the tuple's first component.

You need to then compile and execute this program and provide a value to get it out.