How convert from OpNode to FunctionNode in Relay IR?

Hi,

At frontend, how to convert OpNode to FunctionNode? Facing the below error when trying to set function attributes with “func.with_attr” at frontend

  File "/data1/workspace//incubator-tvm/src/relay/backend/graph_runtime_codegen.cc", line 407
TVMError: Operators should be transformed away; try applying the fuse_ops transformation to the expression.

Could see the testcases are using relay.Call(), can anyone please help me on how to do this at the frontend file (eg: tflite.py) ?

You may use eta expansion to convert a primitive op to a function.

Could you please give me a sample code?

In most cases, we cannot simply convert opnode to function nodes, as they are primitive ops, you can however, wrap the op with function that calls into this op.

@tqchen, i will explain my specific problem. I am trying to use the external c codegen from tflite frontend. I tried to check with below method as shown in some testcases shown on external codegen.

    func = _function.Function(analysis.free_vars(outputs), outputs)             
                                                                                
    func = func.with_attr("Primitive", tvm.tir.IntImm("int32", 1))              
    func = func.with_attr("Compiler", "my_compiler")                            
    func = func.with_attr("global_symbol", "my_compiler_0")                     
                                                                                
    #mod = IRModule.from_expr(call)                                             
    mod = IRModule.from_expr(func)              

But the relay.Call() call is not able to perform at this stage and am facing the issue with OpNode. Can you please suggest a method to resolve this issue?

cc @zhiics might have a suggestion, what is the content of the function? a function must contain a sub-graph/expression, if you want to use an op you must call it with inputs.