Lunderberg commented on PR #16642:
URL: https://github.com/apache/tvm/pull/16642#issuecomment-1989472731
This PR needs an additional test case before merging. On the main branch,
the following IRModule is valid. However, with this PR, it fails during
parsing.
```python
@I.ir_module
class Module:
@R.function
def main(A: R.Tensor) -> R.Prim("bool"):
return Module.is_bfloat16_dtype(A)
@T.prim_func(private=True)
def is_bfloat16_dtype(tensor: T.handle) -> T.bool:
T.func_attr({"tir.is_scheduled": True, "tir.is_host_func": True})
# From #include <tvm/tir/builtin.h>
kArrTypeCode = T.meta_var(5)
kArrTypeBits = T.meta_var(6)
kArrTypeLanes = T.meta_var(7)
# From #include <dlpack/dlpack.h>
kDLBfloat = T.meta_var(4)
type_code = T.tvm_struct_get(tensor, 0, kArrTypeCode, dtype="uint8")
type_bits = T.tvm_struct_get(tensor, 0, kArrTypeBits, dtype="uint8")
type_lanes = T.tvm_struct_get(tensor, 0, kArrTypeLanes,
dtype="uint16")
is_bfloat16: T.bool = (
(type_code == kDLBfloat) and (type_bits == 16) and (type_lanes
== 1)
)
return is_bfloat16
```
The failure occurs due to the inferred struct info of
`R.Callable([R.Prim("handle")], R.Prim("bool"))`. When the function is passed
a `R.Tensor`, it fails relax's type check as `R.Tensor` is not compatible with
`R.Prim("handle")`.
I think the fix will be to update `StructInfoBaseCheck` to recognize that
`R.Prim("handle")` is a valid TIR representation of a `DLTensor*`, but I want
to think on it first.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]