### Issue
Currently, StructInfo can use a local variable to express shape information.
However, this causes a visibility problem when we output with such StructInfo
to the outer scope of the current block.
### Reproducible Example
`Reshape` is the representative example.
```
# from tvm.script import ir as I
# from tvm.script import relax as R
@I.ir_module
class Mod:
@R.function
def main(x: R.Tensor((16, 16), "float32")):
with R.dataflow():
lv = relax.Var("s", R.Shape((4, 4, 4, 4)))
gv = relax.op.reshape(x, lv)
R.output(gv)
return gv
assert relax.analysis.well_formed(Mod)
```
When we conduct StructInfo deduction with normalizer, we get the following:
```
# from tvm.script import ir as I
# from tvm.script import relax as R
@I.ir_module
class Module:
@R.function
def main(
x: R.Tensor((16, 16), dtype="float32")
) -> R.Tensor(dtype="float32", ndim=4):
s: R.Shape([4, 4, 4, 4])
with R.dataflow():
lv: R.Shape([4, 4, 4, 4]) = s
gv: R.Tensor(lv, dtype="float32") = R.reshape(x, lv)
R.output(gv)
return gv
```
This fails `well_formed` checker because when we outputs `gv`, we escalate its
StructInfo together. Since `lv` is not visible to the outer scope of dataflow
block, we get the following errors:
```
[11:36:43] /home/spark/tvm/src/relax/analysis/well_formed.cc:116: Warning: This
IR is not well formed: Var s is not defined.
[11:36:43] /home/spark/tvm/src/relax/analysis/well_formed.cc:116: Warning: This
IR is not well formed: DataflowVar lv is used outside DataflowBlock.
[11:36:43] /home/spark/tvm/src/relax/analysis/well_formed.cc:116: Warning: This
IR is not well formed: DataflowVar lv is not defined.
```
### Ideas
In our internal discussion with @psrivas2 @slyubomirsky @yongwww, we could come
up with three options:
O1: insert `R.output` implicitly for those local variables
O2: require explicit `R.output` annotation
O3: remove lv from tensor struct info (e.g., folding, match_cast)
We would like to hear more thoughts from the community on this matter.
Thank you in advance!
--
Reply to this email directly or view it on GitHub:
https://github.com/apache/tvm/issues/14287
You are receiving this because you are subscribed to this thread.
Message ID: <apache/tvm/issues/[email protected]>