Skip to content

[BugFix][TVMScript] Parser crash#13629

Closed
lightzhan-intellif wants to merge 2 commits intoapache:mainfrom
lightzhan-intellif:meta_programming_bug_fix
Closed

[BugFix][TVMScript] Parser crash#13629
lightzhan-intellif wants to merge 2 commits intoapache:mainfrom
lightzhan-intellif:meta_programming_bug_fix

Conversation

@lightzhan-intellif
Copy link
Copy Markdown
Contributor

@lightzhan-intellif lightzhan-intellif commented Dec 16, 2022

This PR tries to fix the crash of parser when the old value of a var is an array but the new value is not. For example:

from tvm.script import tir as T
def func_wrapper(shape, dtype):
    @T.prim_func
    def test_case():
        a = T.alloc_buffer(shape, dtype=dtype)
    
    return test_case


if __name__ == "__main__":
    a = np.zeros((10, 10), dtype="int8")
    print(func_wrapper((256, 256), dtype="int8").script())

In the above code, there are two assignment to var 'a'. In the global scope, its value is a numpy array. But it is a Buffer in the prim function. There is a table named 'name2value' to track the value of vars like 'a' here.
When the parser wants to update its value, it will compare the value between the new and the old assignment. Here the problem comes. When we use '==' to compare an array with a value, the result is an array too, which can not be used as a condition of a if stmt directly. So, the code above will emit an error:

error: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
 --> /workspace/code_newest/tvm/private_test/test_meta_programming.py:16:9
    |  
 16 |          a = T.alloc_buffer(shape, dtype=dtype)
    |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

This PR fixes this by change "==" to "is".

@tvm-bot
Copy link
Copy Markdown
Collaborator

tvm-bot commented Dec 16, 2022

Thanks for contributing to TVM! Please refer to the contributing guidelines https://tvm.apache.org/docs/contribute/ for useful information and tips. Please request code reviews from Reviewers by @-ing them in a comment.

  • No users to tag found in teams: bugfix, tvmscript See #10317 for details

Generated by tvm-bot

@lightzhan-intellif lightzhan-intellif deleted the meta_programming_bug_fix branch December 16, 2022 04:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants