Skip to content
This repository has been archived by the owner on May 22, 2023. It is now read-only.

[Bug] left-hand side variable type not deducted automatically with call_tir. #209

Closed
ganler opened this issue Aug 8, 2022 · 4 comments
Closed
Labels
bug Something isn't working

Comments

@ganler
Copy link
Collaborator

ganler commented Aug 8, 2022

from __future__ import annotations
from tvm.script import relax as R, tir as T

@R.function
def bug(x: Tensor((32, 32), "float32")) -> Tensor:
    with R.dataflow():
        lv0 = R.call_tir(my_relu, (x,), (32, 32), dtype="float32")
        R.output(lv0)
    return lv0

bug.body.blocks[0].bindings[0].var.checked_type

image

cc: @yongwww @YuchenJin

@yongwww
Copy link
Collaborator

yongwww commented Aug 8, 2022

thanks for filing this bug! the checked_type of var lv0 should be filled. Now we can manually add the annotation for the var as a workaround. Will fix it in the new parser.

@YuchenJin
Copy link
Collaborator

The Normalization pass only applies when parsing an IRModule: https://github.com/tlc-pack/relax/blob/relax/python/tvm/script/parser.py#L1386, so if you wrap the relax.Function in an IRModule, it will be normalized (type/shape deduced). I think when parsing a standalone relax.Function, we should also do type/shape auto deduction. cc @yongwww.

This following code works:

from __future__ import annotations
from tvm.script import relax as R, tir as T

@tvm.script.ir_module
class MyModule:
    @R.function
    def func(x: Tensor((32, 32), "float32")) -> Tensor:
        with R.dataflow():
            lv0 = R.call_tir(my_relu, (x,), (32, 32), dtype="float32")
            R.output(lv0)
        return lv0


print(MyModule["func"].body.blocks[0].bindings[0].var.checked_type)

@ganler
Copy link
Collaborator Author

ganler commented Aug 9, 2022

@YuchenJin Thanks for the clarification! Yes, I strongly agree that we should do such deduction function-wise. It will benefit the IR rewriting a lot (where users need to create a function first and then replace it on an IRModule).

@tqchen
Copy link
Contributor

tqchen commented Jan 6, 2023

Should be fixed in the latest version

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants