-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Closed
Description
To reproduce the problem:
>>> from tvm import tir
>>> int_1, bool_t = tir.const(1), tir.const(True)
>>> s = {int_1, bool_t}
~tvm/python/tvm/tir/expr.py in __nonzero__(self)
171 def __nonzero__(self):
172 raise ValueError(
--> 173 "Cannot use and / or / not operator to Expr, hint: "
174 + "use tvm.tir.all / tvm.tir.any instead"
175 )
ValueError: Cannot use and / or / not operator to Expr, hint: use tvm.tir.all / tvm.tir.any insteadAfter some inspection, I guess I could elaborate on the steps leading to this issue:
- During the construction of
s, the__hash__ofint_1andbool_tare compared, which are both1. - Since they have the same hash value, Python needs to further consider whether the two objects are the same before finishing set construction, which in turn concerns the
__eq__operator. __eq__oftir.IntImmcalls_ffi_api._OpEQ, which returns atir.EQ(int_1, bool_t)given that constant folding doesn’t happen.- Python wants to convert the this
tir.EQtobool, which calls__bool__oftir.EQthat inherits__bool__oftir.ExprOp, which calls__nonzero__, which finally raisesValueError.
I’m not sure whether this problem can be solved through simple fix since it involves the design of the operator sugar of TIR in Python-level.
Metadata
Metadata
Assignees
Labels
No labels