Hi @lixiaoquan .
Thank you very much for giving us advice again! I agree with you that it is quite important to indicate which relay expression generates the output tensor of its original frontend layer. But we encounter some problems and we remove the suffix string totally. Therefore we would like to ask for advices in this RFC. So far we have two possible ways to handle this issue.
- Like what you said, patch a suffix to indicate to the expression which generates the output tensor.
- Leverage the var thing said by @areusch to handle to tag the output result.
The most straightforward way should be the first one, adding the suffix. And perhaps it is an
acceptable compromise. In the following phrase I would like to detail the problem and the solution 1.
Because solution 2 still needs time to design. Note that we have pushed the very first
PR of this RFC. It would be great if you have time to
take a look at it.
Problem
In the previous version we set the _PART_{idx}
as suffix. However, once we process to pass
transformation, this suffix becomes annoying, and really hard to deal with. Even worse, after
invoking several passes, these suffixs seems to be meaningless.
Solution1
Adding a suffix _OUTPUT
to indicate we are generating the output expression of a frontend layer. To
be more precisely here is the modfication we can make in our PR:
-
Now we invoke
set_span
in several place for the parameter sources. Those frontend source will be converted to Constant or Var, and no need to indicate output. Therefore we would add one more parameter to the common API:def set_span(expr, span, is_output)
-
Control
is_output
flag to make the final epxrssion be tagged likeSOURCE_NAME_OUTPUT
. Take the TFLite OP for example again. It would look like:def @main (%input: Tensor[(?, ?, 3, 1), float32]) { %0 = shape_of(%input, dtype="int32") /* Shape_OUTPUT */; %1 = strided_slice(%0, …) /* strided_slice */; %2 = squeeze(%1) /* strided_slice_OUTPUT */; %3 = expand_dims(%2, axis=0) /* stack */; %4 = expand_dims(3, axis=0) /* stack */; %5 = expand_dims(3, axis=0) /* stack */; %6 = (%3, %4, %5) /* stack */; %7 = concatenate(%6) /* stack_OUTPUT */; }
We could consider to set the span of output expr like “stack_OUTPUT” or “stack FINAL_OUTPUT”. Or make one more parameter to let user customize it. Not sure whether it is good to spec the string or not.
-
Personally I would like to set the
is_output
toFalse
as default. The reason is that most of time, we will then process the build command, or leverages the pass transformation. At this stage theOUTPUT
suffix could become meaningless as mentioned above. We can write some more documentation at bothset_span
API, and each frontend conversion to tell user where and when to turn this parameter on. So that user will have a flexibility to obtain the more precise result (the output location), and will not be confused when approach to the pass transformation or even the lowering process.
Thank you for reading such long description. Hope it could provide you more context. It is great to
have a conversion about issue.